/* Control Program */ arg starttime comport = 3 call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' call SysLoadFuncs If starttime = 'PROMPT' Then Do Call TimePrompt End nonews = 0 If starttime = 'QUICK' Then Do Call Log 'No news - just a quick logon for mail purposes' nonews = 1 starttime = '' End nokill = 0 If starttime = 'GO' Then Do Call Log 'No kill option set!' nokill = 1 starttime = '' End If Left(starttime, 1) = '+' Then Do mm = Substr(starttime, 2) Call Log 'waiting for' mm 'minutes' Call SysSleep (mm*60) starttime = '' End If starttime<>'' Then Do Parse var starttime hh':'mm':'ss If ss='' Then ss=0 If hh<0 | hh>24 Then Do Call Log 'Invalid time, must be entered as hh:mm:ss or hh:mm' Exit 1 End If mm<0 | mm>59 Then Do Call Log 'Invalid time, must be entered as hh:mm:ss or hh:mm' Exit 1 End If ss<0 | ss>59 Then Do Call Log 'Invalid time, must be entered as hh:mm:ss or hh:mm' Exit 1 End Call Log 'waiting until' hh':'mm':'ss goseconds = hh*3600 + mm*60 + ss numseconds = time('S') /* Number of seconds since midnight */ If numseconds > goseconds Then Do waitsecs = (60 * 60 * 24) - numseconds + goseconds End Else Do waitsecs = goseconds - numseconds End hh = Trunc(waitsecs / 3600) mm = Trunc((waitsecs - (3600*hh)) / 60) ss = waitsecs - (3600*hh) - (60*mm) Call Log 'waiting for 'hh' hours 'mm' minutes 'ss' seconds' Call SysSleep waitsecs End tempdir = Value('TMP',,'OS2ENVIRONMENT') If tempdir = '' Then Do tempdir = Value('TEMP',,'OS2ENVIRONMENT') End Call StartDigest ControlQ = 'WARPDIS' Call Log 'Setting control queue' oq = RXQUEUE('Set', ControlQ) Do While Queued() <> 0 Pull junk End Call StartGETMAIL Call Log 'Checking status of Fax...' faxpid = Running('faxworks.exe') If faxpid = 0 Then Do Call Log 'FaxWorks is not running' faxworks = 0 End Else Do Call Log 'FaxWorks is running...' faxworks = 1 '@KILLP' faxpid Call Log 'waiting 5 seconds to give faxworks a chance...' Call SysSleep 5 faxpid = Running('faxworks.exe') If faxpid <> 0 Then Do Call Log 'FaxWorks will not stop. Giving up.' Exit 1 End Call Log 'FaxWorks has stopped.' End Call Log 'Checking status of internet connection...' slippid = Running('slip.exe') If slippid = '0' Then Do Call Log 'SLIP is not running' retcode = connect() If retcode = 1 Then Do Call Log 'SLIP failed to connect' Exit 1 End End Else Do Call Log 'SLIP is running, with the pid' slippid '@MODE COM'comport End signal on halt sendit = -1 /* started */ newnews = -1 /* started */ getmail = 0 /* Not running */ retries = 0 /* NNTP retries */ timeout = 1200 /* Time out 20 minutes */ comport = 3 /* Modem com port */ alive = 1 /* SLIP is alive */ Call StartSMTP Call StartNNTP slippid = Running('slip.exe') Do Until alive = 0 Do While Queued() = 0 & time('E') < timeout Call SysSleep 10 End If Queued() <> 0 Then Do Pull message Parse var message '<'source'>' command reason code Call Log 'From' source':' command 'with' retcode code Select When source = 'SENDIT' Then Do Call time 'R' /* Reset elapsed time counter */ Select When command = 'START' Then Do Call Log 'SENDIT has started.' sendit = 1 /* Running */ End When command = 'STOP' Then Do Call Log 'SENDIT has stopped.' sendit = 0 /* Stopped */ Call Log 'Fetching list of updates available' Call StartNEWWARP End When command = 'FAIL' Then Do Call Log 'SENDIT has failed.' sendit = 0 /* Failed */ End Otherwise Call Log 'Unknown command from sendit' command End End When source = 'NEWNEWS' Then Do Call time 'R' /* Reset elapsed time counter */ Select When command = 'START' Then Do Call Log 'NEWNEWS has started.' newnews = 1 /* Running */ End When command = 'STOP' Then Do Call Log 'NEWNEWS has stopped.' newnews = 0 /* Stopped */ End When command = 'FAIL' Then Do If reason = 'NNTP' & code = 400 Then Do Call Log 'NNTP server was busy.' retries = retries + 1 If retries < 2 Then Do Call Log 'NEWNEWS retying ('retries')' Call StartNNTP newnews = -1 End Else Do Call Log 'NEWNEWS has failed.' newnews = 0 End End Else Do Call Log 'newnews has failed.' newnews = 0 /* Failed */ End End Otherwise Call Log 'Unknown command from newnews' command End End When source = 'GETMAIL' Then Do Call Log 'GETMAIL' command reason code If command = 'INFO' & reason = 'LISTENING' Then Do socket = code Call Log 'GETMAIL socket' socket End End Otherwise Call Log 'Unknown source' source End If newnews = 0 & sendit = 0 Then Do alive = 0 End End Else Do Call Log timeout 'seconds elapsed since last message on ControlQ' alive = 0 End End If nokill = 0 Then Do Call Log 'KILLING SLIP in 10 seconds...' Call SysSleep 10 Call KillSlip End Else Do Call Log 'NO KILL OPTION SET' Call SysSleep 10 End /* Call Log 'Starting ListServer...' - don't run a list server anymore - */ /* Call ListServer */ /* Call Log 'Unbatching news...' - unbatching done by newnews.cmd */ /* Call Unbatch */ Call Log 'Deleting control queue' Call RXQUEUE 'Set', oq Call RXQUEUE 'Delete', ControlQ If faxworks = 1 Then Do Call Log 'Restarting FaxWorks' Call StartFaxWorks End halt: Say 'Program terminated.' Exit 0 KillSlip: Procedure expose slippid comport tempdir Call Log 'Killing Internet connection...('slippid')' '@KILLP' slippid /* Kill SLIP.EXE */ 'mode com'comport': dtr=on' /* Force line to drop */ Call Log 'Killing Internet connection...('slippid')' Call SysSleep 5 /* Sleeping to give kill a chance */ slippid = Running('slip.exe') If slippid <> 0 Then Do Call Log 'SLIP is still running.... one more try' 'KILLP' slippid 'KILLEM SLIP.EXE' End Return Running: Procedure expose tempdir arg name tempfile = SysTempFileName(tempdir'\WARPDIS.???') '@PSTAT >' tempfile Call SysFileSearch name, tempfile, 'process' Call SysFileDelete tempfile If process.0 = 0 Then Do Return 0 /* Program not running */ End Else Do Parse var process.1 pid . Return pid /* Program running with process id = pid */ End Return /* Should never get here */ connect: Procedure '@START /C E:\TCPIP\BIN\SLIP.EXE' Say 'Current Time:' time() '@SLIPWAIT 300' If RC=1 Then Do /* Slip failed to start */ '@KILLEM SLIP.EXE' Say Return 1 End Return 0 StartSMTP: Procedure expose ControlQ sendit Call SysFileTree 'd:\demon\spool\mqueue\*.wrk', 'outmail', 'FO' If outmail.0 = 0 Then Do Call Log 'No outgoing mail. Not starting smtp client.' sendit = 0 /* finished */ End Else Do Call Log 'Starting smtp client...' '@START /C "SENDIT - smtp client" SENDIT.CMD' End Return StartNNTP: Procedure expose ControlQ newnews nonews If nonews = 1 Then Do Call Log 'Simulating NEWNEWS completion...' newnews = 0 /* simulated completion */ End Else Do Call Log 'Starting nntp client...' '@START /C "NEWNEWS - nntp client" NEWNEWS.CMD' End Return StartNEWWARP: Procedure expose ControlQ Call Log 'Starting NEWWARP...' '@START /C "NEWWARP - check latest warp offerings" NEWWARP.CMD -mp D:\DEMON\SPOOL\MAIL\NEWWARP.TXT' Return StartGETMAIL: Procedure expose ControlQ Call Log 'Starting smtp daemon...' '@START /C "GETMAIL - smtp daemon" GETMAIL.CMD' Return ListServer: Procedure retcode = Stream('d:\demon\spool\mail\listserv.txt', 'c', 'query exists') If retcode <> '' Then Do olddir = Directory() Call Directory 'D:\DEMON\LISTSERV' '@START /C /WIN /DOS "ListServer" LISTSERV.EXE' curdir = Directory(olddir) End Return StartDigest: Procedure expose logfile If date('w')='Friday' Then Do Call Log 'Starting Digest...' olddir = Directory() Call Directory 'D:\DEMON\LISTSERV' '@START /C /WIN /DOS "Digest" DIGEST.EXE' curdir = Directory(olddir) End Else Do Call Log "Not starting Digest ("date('w')")" End Return UnBatch: Procedure expose logfile If Stream('d:\demon\spool\articles\batch.txt', 'c', 'query exists')<>'' Then Do '@COPY D:\DEMON\SPOOL\ARTICLES\BATCH.TXT C:\TEMP\BATCH.TXT' olddir = Directory() /* Call Startrnews */ Call Log "Starting cppbatch..." Call Directory 'd:\demon' '@START /C /WIN /DOS "Unbatch News (cppbatch)" D:\CPPNEWS\CPPBATCH.EXE -d' curdir = Directory(olddir) End Return Startrnews: Procedure expose logfile Call Log "Starting rnews..." Call Directory 'D:\Changi' /* -dahfrw gives full logging */ '@rnews < d:\demon\spool\articles\batch.txt' Return StartFaxWorks: Procedure expose logfile olddir = Directory() Call Directory 'D:\FaxWorks' '@START FAXWORKS' curdir = Directory(olddir) Return Log: Procedure Parse arg message Say message retcode = LINEOUT('d:\demon\warpdis.log', message) Return TimePrompt: Procedure expose starttime Say 'WARPDIS: Control program for NEWNEWS, SENDIT and GETMAIL' Say Say 'Press ENTER to start immediately, or enter time for automatic starting' Say 'Remember that all times must be entered as 24hr clock, e.g. 07:00 or 15:00' Say Say 'If you wish to connect immediately, with no timeout then type GO and press' Say 'enter.' Say Parse Upper Value LINEIN() with starttime Return