home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Extra 1997 #5
/
AmigaPlus_Extra-CD_5-97.iso
/
online-tools
/
mail
/
ems
/
rexx
/
areafix.ems
next >
Wrap
Text File
|
1993-08-30
|
25KB
|
887 lines
/****************************/
/* Handles AreaFix requests */
/***************************************/
/* $VER: AreaFix.ems 1.0 (29.08.93) */
/***************************************/
options results
signal on error
signal on syntax
if( ~show( 'l', "ems_rexx.library" ) ) then
do
if( ~addlib( "ems_rexx.library", 0, -30, 0 ) )then
do
say "Could not open ems_rexx.library"
exit 10
end
end
/* Checks if the system uses another AreaFix program */
if EMS_Switch_Local( 'USE_INTERNAL_AREAFIX' ) ~= 'ON' then call QuitAreafix
/****************************/
/* Initialize some stuff... */
/****************************/
aliases.0 = 0
areas_mail.0 = 0
areas_doexport.0 = 0
forwards.0 = 0
writeback.0 = 'NO' /* Links */
writeback.1 = 'NO' /* Nodes */
writeback.2 = 'NO' /* Areas */
delete_msg = EMS_Switch_Local( 'NO_KEEP_AREAFIX' )
call EMS_Nodes( 'nodes' )
/*
** Split the AREAFIX_NAME.
*/
name_1 = EMS_Var_Local( 'AREAFIX_NAME' )
do while length( name_1 ) ~= 0
parse var name_1 name_2 name_1
if length( name_2 ) ~= 0 then call EMS_Add_To_Stem( 'aliases', name_2 )
end
/*
** Search for areas of type MAIL
*/
call EMS_Areas_Mail( 'a' )
do i=1 to a.0
addr = EMS_Area_Address( a.i )
if EMS_Address_IsPOINT( addr ) = 'FALSE' then call EMS_Add_To_Stem( 'areas_mail', a.i )
end
drop a.
do i=1 to areas_mail.0
call FindAreaFixMsgs( areas_mail.i )
if msgs.0 ~= 0 then call EMS_Log_Print( 2, 'AreaFix: found' msgs.0 'unprocessed request(s)' )
do j=1 to msgs.0
msg_pwd = ''
msg_addr = ''
msg_addr_real = ''
msg_subject = ''
msg_requests.0 = 0
msg_reports.0 = 0
msg_actions.0 = 'OFF' /* Help */
msg_actions.1 = 'OFF' /* Rescan */
msg_actions.2 = 'OFF' /* List */
msg_actions.3 = 'OFF' /* Query */
msg_actions.4 = 'OFF' /* Unlinked */
msg_actions.5 = '' /* Compress */
msg_actions.6 = '' /* PWD */
msg_actions.7 = 'OFF' /* Pause */
msg_actions.8 = 'OFF' /* Resume */
msg_actions.9 = '' /* Notify */
/* Filter: */
msg_rescan.0 = '' /* From */
msg_rescan.1 = '' /* To */
msg_rescan.2 = '' /* Subject */
msg_rescan.3 = '' /* Date */
msg_rescan.4 = 'OFF' /* ALL */
/* Reads requests */
if ParseMsg( areas_mail.i, msgs.j ) = 1 then
do
call EMS_Log_Print( 2, 'AreaFix: processing request from' msg_addr_real 'for' msg_addr )
if EMS_Node_Check( msg_addr ) ~= 'OK' then
do
call EMS_Log_Print( 2, 'AreaFix: unknown system' )
call WrongPassword()
call SendReport( i, 'NO' )
iterate
end
/* Checks password */
node_pwd = EMS_Node_Areafix_Pwd_In( msg_addr )
if node_pwd ~= '' & upper( node_pwd ) ~= upper( msg_pwd ) then
do
call EMS_Log_Print( 2, 'AreaFix: wrong password' )
call WrongPassword()
call SendReport( i, 'NO' )
iterate
end
if msg_actions.5 ~= '' & msg_actions.5 ~= '?' then
do
call EMS_Archivers( 'packers' )
do k=1 to packers.0
if packers.k = msg_actions.5 then
do
call EMS_Node_Archiver( msg_addr, packers.k ); writeback.1 = 'YES'
leave
end
end
drop packers.
end
if msg_actions.6 ~= '' then do; call EMS_Node_Areafix_Pwd_In( msg_addr, msg_actions.6 ); writeback.1 = 'YES'; end
if msg_actions.7 = 'ON' then do; call EMS_Areafix_Passivate( msg_addr ); writeback.0 = 'YES'; end
if msg_actions.8 = 'ON' then do; call EMS_Areafix_Activate( msg_addr ); writeback.0 = 'YES'; end
if msg_actions.9 ~= '' then do; call EMS_Node_Areafix_Notify( msg_addr, msg_actions.9 ); writeback.1 = 'YES'; end
do k=1 to msg_requests.0
name = msg_requests.k
if left( name, 1 ) = '-' then
do
name = delstr( name, 1, 1 )
if EMS_Search_In_Stem( 'areas_mail', name ) ~= 0 then
do
msg_reports.k = 'Hard link: not removed'
iterate
end
linked = EMS_Areafix_Node_IsLinked( msg_addr, name )
if linked = 'NO' then
do
msg_reports.k = 'Not linked'
iterate
end
call EMS_Areafix_Node_Delete( msg_addr, name )
msg_reports.k = 'Removed'
writeback.0 = 'YES'
iterate
end
linked = EMS_Areafix_Node_IsLinked( msg_addr, name )
if linked = 'NO' then
do
if EMS_Area_Check( name ) = 'UNKNOWN' then
do
if EMS_Node_CanCreateAreas( msg_addr ) = 'TRUE' then
do
call EMS_Area_Create( name, 'ECHO' )
call FindAreaOnOtherSystems( name )
writeback.2 = 'YES'
end
else
do
msg_reports.k = 'Not found'
iterate
end
end
/*
** Verify access permission.
*/
if EMS_Areafix_Node_MatchGroup( msg_addr, name ) = 'FALSE' then
do
msg_reports.k = 'Not found'
iterate
end
call EMS_Areafix_Node_Add( msg_addr, name )
msg_reports.k = 'Linked'
writeback.0 = 'YES'
end
if linked = 'PASSIVE' then
do
call EMS_Areafix_Activate( msg_addr, name )
msg_reports.k = 'Reactivated'
writeback.0 = 'YES'
end
if linked = 'ACTIVE' then
do
msg_reports.k = 'Yet linked'
end
if msg_actions.1 = 'ON' then call DoRescan( name, k )
end
if EMS_Node_Areafix_Notify( msg_addr ) = 'FALSE' then iterate
call SendReport( i, 'YES' )
if delete_msg = 'ON' then call EMS_Area_Item_Delete( areas_mail.i, 'MSG', msgs.j )
end
end
end
call SendForward()
areas_to_export = ''
do i=1 to areas_mail.0
if areas_doexport.i = 'YES' then areas_to_export = areas_to_export areas_mail.i
end
if areas_to_export ~= '' then call EMS_Tosser_Export( areas_to_export )
QuitAreafix:
if writeback.0 = 'YES' then call EMS_Cfg_Write( 'cfg_link_ems' )
if writeback.1 = 'YES' then call EMS_Cfg_Write( 'cfg_node_ems' )
if writeback.2 = 'YES' then call EMS_Cfg_Write( 'cfg_area_ems' )
call EMS_FreeScriptData()
return 0
error:
syntax:
error_text = EMS_LastError()
if error_text = '' then error_text = rc ErrorText( rc )
say '| ***BREAK: error at' sigl error_text
call EMS_FreeScriptData()
exit rc
FindAreaFixMsgs: procedure EXPOSE aliases. msgs.
parse arg area
/* Set the search on every message and only on field TOUSER */
call EMS_Switch_Local( 'SEARCH_ALL' , 'ON' )
call EMS_Switch_Local( 'SEARCH_ON_TO' , 'ON' )
call EMS_Switch_Local( 'IGNORE_FROM' , 'ON' )
call EMS_Switch_Local( 'IGNORE_SUBJECT', 'ON' )
call EMS_Switch_Local( 'IGNORE_DATE' , 'ON' )
call EMS_Switch_Local( 'IGNORE_TEXT' , 'ON' )
drop msgs.
msgs.0 = 0
/*
** Searches all messages addressed to AreaFix (or aliases) and
** without the RCV flag set (not already processed).
*/
do i=1 to aliases.0
call EMS_Database_Search( area, 'MSG', 'a', aliases.i )
do j=1 to a.0
if EMS_Area_Item_Flag( area, 'MSG', a.j, 'RCV' ) ~= 'ON' then call EMS_Add_To_Stem( 'msgs', a.j )
end
end
return 0
DoRescan: procedure EXPOSE msg_addr msg_reports. msg_rescan.
parse arg name , req_num
msg_reports.req_num = msg_reports.req_num 'and rescanned'
if msg_rescan.4 = 'ON' then opt = 'FORCE'
else opt = ''
call EMS_Tosser_Rescan( name, msg_addr, opt, msg_rescan.0, msg_rescan.1, msg_rescan.2, msg_rescan.3 )
return 0
WrongPassword: procedure EXPOSE msg_requests. msg_reports.
do i=1 to msg_requests.0
msg_reports.i = 'Wrong password'
end
return 0
SendReport: procedure EXPOSE msg_from msg_addr msg_addr_real areas_mail. areas_doexport. ,
msg_requests. msg_reports. msg_actions.
parse arg area_num , ok
area = areas_mail.area_num
if EMS_Address_Compare( msg_addr, msg_addr_real ) = 'TRUE' then subject = 'Report about your requests'
else subject = 'Report about requests for' msg_addr
call EMS_Areas( 'areas' )
call EMS_Item_Alloc( 'reply', area, 'MSG' )
call EMS_Item_Header_From( 'reply', 'AreaFix Robot' )
call EMS_Item_Header_Address_From( 'reply', EMS_Area_Address( area ) )
call EMS_Item_Header_To( 'reply', msg_from )
call EMS_Item_Header_Address_To( 'reply', msg_addr_real )
call EMS_Item_Header_Subject( 'reply', subject )
if msg_requests.0 ~= 0 then
do
max1 = 0
max2 = 0
do i=1 to msg_requests.0
name = msg_requests.i
len = length( name ) + 1
if left( name, 1 ) ~= '-' then len = len + 1
if len > max1 then max1 = len
len = length( msg_reports.i ) + 1
if len > max2 then max2 = len
end
if max1 < 27 then max1 = 27
if max2 < 27 then max2 = 27
call PrintMsg( ' AREA:' || copies( ' ', max1 - 4 ) || 'STATUS:' )
call PrintMsg( copies( '-', max1 ) || ' ' || copies( '-', max2 ) )
do i=1 to msg_requests.0
area_report = msg_requests.i || ' '
if left( area_report, 1 ) ~= '-' then area_report = ' ' || area_report
call PrintMsg( area_report || copies( '.', max1 - length( area_report ) ) || ' ' || msg_reports.i || '.' )
end
call PrintMsg( '' )
call PrintMsg( '' )
end
/*
** Help: send a list of available ArexFix commands.
*/
if msg_actions.0 = 'ON' then
do
call PrintMsgUnderline( 'Help on AreaFix commands:' )
call PrintMsg( '[+]<areaname> Connect an area.' )
call PrintMsg( '-<areaname> Disconnect an area.' )
call PrintMsg( '%HELP Request this help text.' )
call PrintMsg( '%RESCAN Rescan requested areas.' )
call PrintMsg( '%LIST Request a list of areas available to you.' )
call PrintMsg( '%QUERY Request a list of areas to which you are connected.' )
call PrintMsg( '%UNLINKED Request a list of areas to which you are not connected.' )
call PrintMsg( '%COMPRESS <method> Change the compression program.' )
call PrintMsg( '%COMPRESS ? Request a list of available compression programs.' )
call PrintMsg( '%PWD <password> Change AreaFix password.' )
call PrintMsg( '%PAUSE Temporary suspend all connected areas.' )
call PrintMsg( '%RESUME Resume all temporary suspended areas.' )
call PrintMsg( '%NOTIFY [ON/OFF] Enable/disable notify messages.' )
call PrintMsg( '%FROM <address> Remote maintenance.' )
call PrintMsg( '+F <pattern> Rescan filter on FROM field of messages.' )
call PrintMsg( '+T <pattern> Rescan filter on TO field of messages.' )
call PrintMsg( '+S <pattern> Rescan filter on SUBJECT field of messages.' )
call PrintMsg( '+D <num of days> Rescan filter on age of messages.' )
call PrintMsg( '+R Rescan all the messages, not only unread.' )
call PrintMsg( '[---] Everything below the tear line is ignored.' )
call PrintMsg( '' )
call PrintMsg( '' )
end
/*
** List: send a list with description of available areas for 'msg_addr'
*/
if msg_actions.2 = 'ON' then
do
drop list_areas.
drop list_desc.
list_areas.0 = 0
list_desc.0 = 0
len_name = 0
do i=1 to areas.0
if upper( EMS_Area_Type( areas.i ) ) = 'MAIL' then iterate
if EMS_Areafix_Node_MatchGroup( msg_addr, areas.i ) ~= 'TRUE' then iterate
desc = EMS_Area_Msg_Description( areas.i )
if desc ~= '' then
do
call EMS_Add_To_Stem( 'list_areas', areas.i )
call EMS_Add_To_Stem( 'list_desc' , desc )
end
end
if list_areas.0 ~= 0 then
do
call PrintMsgUnderline( 'Short description of areas:' )
call EMS_Calc_Stem_Width( 'list_areas', 'ADAPT' )
do i=1 to list_areas.0
list_areas.i = ' ' list_areas.i ':' list_desc.i
end
call EMS_Sort_Stem( 'list_areas' )
do i=1 to list_areas.0
call PrintMsg( list_areas.i )
end
call PrintMsg( '' )
call PrintMsg( 'Total found:' list_areas.0 )
call PrintMsg( '' )
call PrintMsg( '' )
end
end
/*
** Query: send a list of active or linkable areas.
*/
if msg_actions.3 = 'ON' then
do
drop list_areas.
list_areas.0 = 0
do i=1 to areas.0
if upper( EMS_Area_Type( areas.i ) ) = 'MAIL' then iterate
linked = EMS_Areafix_Node_IsLinked( msg_addr, areas.i )
match = EMS_Areafix_Node_MatchGroup( msg_addr, areas.i )
if linked ~= 'NO' | match = 'TRUE' then call EMS_Add_To_Stem( 'list_areas', areas.i )
end
call PrintMsgUnderline( 'List of available areas for' msg_addr ':' )
call EMS_Sort_Stem( 'list_areas' )
do i=1 to list_areas.0
if EMS_Areafix_Node_IsLinked( msg_addr, list_areas.i ) ~= 'NO' then pre = ' *'
else pre = ' '
call PrintMsg( pre list_areas.i )
end
call PrintMsg( '' )
call PrintMsg( 'Total found:' list_areas.0 )
call PrintMsg( "Note: a '*' indicates you're already active for that echo." )
call PrintMsg( '' )
call PrintMsg( '' )
end
/*
** Unlinked: send a list of linkable but unlinked areas.
*/
if msg_actions.4 = 'ON' then
do
drop list_areas.
list_areas.0 = 0
do i=1 to areas.0
if upper( EMS_Area_Type( areas.i ) ) = 'MAIL' then iterate
if EMS_Areafix_Node_IsLinked( msg_addr, areas.i ) ~= 'NO' then iterate
if EMS_Areafix_Node_MatchGroup( msg_addr, areas.i ) ~= 'TRUE' then iterate
call EMS_Add_To_Stem( 'list_areas', areas.i )
end
call PrintMsgUnderline( 'List of unlinked available areas for' msg_addr ':' )
call EMS_Sort_Stem( 'list_areas' )
do i=1 to list_areas.0
call PrintMsg( ' ' list_areas.i )
end
call PrintMsg( '' )
call PrintMsg( 'Total found:' list_areas.0 )
call PrintMsg( '' )
call PrintMsg( '' )
end
/*
** Compress: send a list of available archivers.m
*/
if msg_actions.5 = '?' then
do
active = upper( EMS_Node_Archiver( msg_addr ) )
call EMS_Archivers( 'list_packers' )
call PrintMsgUnderline( 'List of available compression programs:' )
do i=1 to list_packers.0
if upper( list_packers.i ) = active then pre = ' *'
else pre = ' '
call PrintMsg( pre list_packers.i )
end
call PrintMsg( '' )
call PrintMsg( "Note: a '*' indicates active selection." )
call PrintMsg( '' )
call PrintMsg( '' )
end
if ok = 'YES' & msg_actions.7 = 'ON' then
do
call EMS_Areafix_Node_Links_Get( msg_addr, '', 'list_areas' )
call PrintMsgUnderline( 'Paused all the areas:' )
call EMS_Sort_Stem( 'list_areas' )
do i=1 to list_areas.0
call PrintMsg( ' ' list_areas.i )
end
call PrintMsg( '' )
end
if ok = 'YES' & msg_actions.8 = 'ON' then
do
call EMS_Areafix_Node_Links_Get( msg_addr, 'list_areas', '' )
call PrintMsgUnderline( 'Resumed all the areas:' )
call EMS_Sort_Stem( 'list_areas' )
do i=1 to list_areas.0
call PrintMsg( ' ' list_areas.i )
end
call PrintMsg( '' )
end
call PrintMsg( '--- EMS AreaFix v1.0' )
call EMS_Item_Header_Flag( 'reply', 'PVT', 'TRUE' )
call EMS_Item_Write( 'reply' )
call EMS_Item_Free( 'reply' )
areas_doexport.area_num = 'YES'
return 0
SendForward: procedure EXPOSE forwards. areas_doexport. aliases.
do i=1 to forwards.0
forward_name = EMS_Node_Areafix_Name( forwards.i.0 )
if forward_name = '' then forward_name = aliases.0
aka_addr = EMS_Aka_Nearer( forwards.i.0 )
area_name = EMS_Area_Address( areas_mail.1 )
do j=1 to areas_mail.0
area_addr = EMS_Area_Address( areas_mail.j )
if EMS_Address_Compare( area_addr, aka_addr ) = 'TRUE' then area_name = areas_mail.j
end
area_addr = EMS_Area_Address( area_name )
call EMS_Item_Alloc( 'forward', area_name, 'MSG' )
call EMS_Item_Header_From( 'forward', 'AreaFix on' area_addr )
call EMS_Item_Header_Address_From( 'forward', area_addr )
call EMS_Item_Header_To( 'forward', forward_name )
call EMS_Item_Header_Address_To( 'forward', forwards.i.0 )
call EMS_Item_Header_Subject( 'forward', EMS_Node_Areafix_Pwd_Out( forwards.i.0 ) )
call EMS_Item_Header_Flag( 'forward', 'PVT', 'ON' )
call EMS_Item_Lines_Set( 'forward', 'TEXT', 'forwards.' || i || '.1' )
call EMS_Item_Line_Add_Tail( 'forward', 'TEXT', '---' )
call EMS_Item_Write( 'forward' )
call EMS_Item_Free( 'forward' )
call EMS_Add_To_Stem( 'areas_doexport', area_name, 'UNIQUE' )
end
return 0
PrintMsgUnderline: procedure
parse arg line
if length( line ) = 0 then return 0
call PrintMsg( line )
call PrintMsg( copies( '-', length( line ) ) )
call PrintMsg( '' )
return 0
PrintMsg: procedure
parse arg line
call EMS_Item_Line_Add_Tail( 'reply', 'TEXT', line )
return 0
ParseMsg: procedure EXPOSE msg_from msg_addr msg_addr_real msg_subject msg_pwd ,
msg_requests. msg_reports. msg_actions. msg_rescan.
parse arg area , num
call EMS_Area_Item_Flag( area, 'MSG', num, 'RCV', 'ON' )
call EMS_Item_Alloc( 'msg', area, 'MSG', num )
call EMS_Item_Lines_Get( 'msg', 'TEXT', 'lines' )
msg_from = EMS_Item_Header_From( 'msg' )
msg_addr_real = EMS_Item_Header_Address_From( 'msg' ); msg_addr = msg_addr_real
msg_subject = EMS_Item_Header_Subject( 'msg' )
call EMS_Item_Free( 'msg' )
if EMS_Aka_Check( msg_addr ) = 'OK' then return 0
/* Splits password from modifiers */
parse var msg_subject msg_pwd msg_subject
do while length( msg_subject ) ~= 0
parse var msg_subject opt msg_subject
opt = upper( opt )
select
when opt = '-R' then msg_actions.1 = 'ON'
when opt = '-L' then msg_actions.2 = 'ON'
when opt = '-Q' then msg_actions.3 = 'ON'
otherwise nop
end
end
do i=1 to lines.0
line = strip( lines.i, 'B' )
do while length( line ) ~= 0
parse var line name line
name = upper( name )
if left( name, 3 ) = '---' then leave i
if left( name, 1 ) = '+' then
do
select
when name = '+F' then do; parse var line msg_rescan.0 line ; msg_actions.1 = 'ON'; iterate; end
when name = '+T' then do; parse var line msg_rescan.1 line ; msg_actions.1 = 'ON'; iterate; end
when name = '+S' then do; parse var line msg_rescan.2 line ; msg_actions.1 = 'ON'; iterate; end
when name = '+D' then do; parse var line msg_rescan.3 line ; msg_actions.1 = 'ON'; iterate; end
when name = '+R' then do; msg_rescan.4 = 'ON'; msg_actions.1 = 'ON'; iterate; end
otherwise nop
end
end
if left( name, 1 ) = '%' then
do
select
when name = '%HELP' then do; msg_actions.0 = 'ON'; iterate; end
when name = '%RESCAN' then do; msg_actions.1 = 'ON'; iterate; end
when name = '%LIST' then do; msg_actions.2 = 'ON'; iterate; end
when name = '%QUERY' then do; msg_actions.3 = 'ON'; iterate; end
when name = '%UNLINKED' then do; msg_actions.4 = 'ON'; iterate; end
when name = '%COMPRESS' then do; parse var line msg_actions.5 line; iterate; end
when name = '%PWD' then do; parse var line msg_actions.6 line; iterate; end
when name = '%PAUSE' then do; msg_actions.7 = 'ON'; iterate; end
when name = '%RESUME' then do; msg_actions.8 = 'ON'; iterate; end
when name = '%NOTIFY' then do; parse var line msg_actions.9 line; iterate; end
when name = '%FROM' then do; parse var line msg_addr line; iterate; end
otherwise nop
end
end
if left( name, 1 ) = '+' then name = substr( name, 2 )
call EMS_Add_To_Stem( 'msg_requests', name, 'UNIQUE' )
end
end
msg_addr = EMS_FullAddress( area, msg_addr ); if msg_addr = '' then msg_addr = msg_addr_real
msg_actions.9 = upper( msg_actions.9 ); if msg_actions.9 ~= 'ON' & msg_actions.9 ~= 'OFF' then msg_actions.9 = ''
return 1
FindAreaOnOtherSystems: procedure EXPOSE nodes. forwards.
parse arg name
do i=1 to nodes.0
list = EMS_Node_Areafix_EchoList( nodes.i )
if list ~= '' & ScanFileForName( list, name ) = 1 then leave
list = EMS_Node_Areafix_FileList( nodes.i )
if list ~= '' & ScanFileForName( list, name ) = 1 then leave
end
if i > nodes.0 then return 0
do j=1 to forwards.0
if EMS_Address_Compare( forwards.j.0, nodes.i ) = 'TRUE' then leave
end
if j > forwards.0 then
do
forwards.0 = j
forwards.j.0 = nodes.i
forwards.j.1.0 = 0
end
call EMS_Areafix_Node_Add( forwards.j.0, name )
call EMS_Add_To_Stem( 'forwards.' || j || '.1', name, 'UNIQUE' )
return 0
ScanFileForName: procedure
parse arg file , match
if ~open( 'file', file ) then return 0
match = upper( match )
do while ~eof( 'file' )
line = readln( 'file' )
do while length( line ) ~= 0
parse var line name line
if match = upper( name ) then
do
call close( 'file' )
return 1
end
end
end
call close( 'file' )
return 0