home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / wrpdis20.zip / DIS2.CMD < prev    next >
OS/2 REXX Batch file  |  1996-04-21  |  11KB  |  360 lines

  1. /****************************************************************************/
  2. /*  DIS2.CMD - control program for warpdis package                          */
  3. /*  Copyright (C) 1995,1996 Alex Chapman <alex@budgetweb.com>               */
  4. /*                                                                          */
  5. /*  This program is free software; you can redistribute it and/or modify    */
  6. /*  it under the terms of the GNU General Public License as published by    */
  7. /*  the Free Software Foundation; either version 2 of the License, or       */
  8. /*  (at your option) any later version.                                     */
  9. /*                                                                          */
  10. /*  This program is distributed in the hope that it will be useful,         */
  11. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of          */
  12. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
  13. /*  GNU General Public License for more details.                            */
  14. /*                                                                          */
  15. /*  You should have received a copy of the GNU General Public License       */
  16. /*  along with this program; if not, write to the Free Software             */
  17. /*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               */
  18. /*                                                                          */
  19. /*  Requires killem.exe                                                     */
  20. /*  <ftp://hobbes.nmsu.edu/os2/sysutils/kill21.zip>                         */
  21. /*                                                                          */
  22. /*  Last Modified: 18th September, 1995                                     */
  23.     Version = 0.4
  24. /****************************************************************************/
  25.  
  26. /************************************************************/
  27. /* Change History                                           */
  28. /************************************************************/
  29. /* 0.1  950909  First version                               */
  30. /* 0.2  950909  Added more options                          */
  31. /* 0.3  950910  Added notify option                         */
  32. /* 0.4  950918  Add user exits                              */
  33. /************************************************************/
  34.  
  35. arg gnu .
  36.  
  37. crlf     = d2c(13)||d2c(10)                         /* CR + LF         */
  38. ControlQ = ''                                       /* Control Queue   */
  39. CurrentQ = ''                                       /* Current Queue   */
  40. inifile  = 'DIS2.INI'                               /* INI file        */
  41. killslip = 1                                        /* Do kill slip    */
  42. delaytime = ''                                      /* Start immediate */
  43. starttime = ''                                      /* Start immediate */
  44.  
  45. Say 'DIS2.CMD - OS/2 control program (version' version')'
  46. Say 'Copyright (C) 1995 Alex Chapman'
  47. Say "DIS2 comes with ABSOLUTELY NO WARRANTY; for details type 'DIS2 w'."
  48. Say 'This is free software, and you are welcome to redistribute it under certain'
  49. Say "conditions; type `DIS2 c' for details."
  50. Say
  51.  
  52. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  53. call SysLoadFuncs
  54.  
  55. Select
  56.   When gnu = 'C' Then Do
  57.     Call ShowConditions
  58.     Exit 0
  59.   End
  60.   When gnu = 'W' Then Do
  61.     Call ShowWarranty
  62.     Exit 0
  63.   End
  64.   When gnu = 'H' | gnu = '?' Then Do
  65.     Say 'DIS2 [C|W|H|?|I<inifile>|=<starttime>|+<delaytime>|!|GO]'
  66.     Say
  67.     Exit 0
  68.   End
  69.   When Left(gnu, 1) = 'I' Then Do
  70.     inifile = Substr(gnu, 2)
  71.   End
  72.   When Left(gnu, 1) = '=' Then Do
  73.     starttime = Substr(gnu, 2)
  74.   End
  75.   When Left(gnu, 1) = '+' Then Do
  76.     delaytime = Substr(gnu, 2)
  77.   End
  78.   When gnu = 'GO' | gnu = '!' Then Do
  79.     killslip = 0
  80.   End
  81.   When gnu<>'' Then Do
  82.     Say 'Invalid parameter.  Process terminated.'
  83.     Exit 0
  84.   End
  85.   Otherwise
  86. End
  87.  
  88. signal on halt
  89.  
  90. Call ReadINIFile inifile, 'DIS2'
  91. Call CheckParameters
  92.  
  93. If killslip = 1 Then Do
  94.   Say 'SLIP will be killed'
  95. End
  96. Else Do
  97.   Say 'SLIP will be left running'
  98. End
  99.  
  100. Call Log '-------------------------------------------------------------'
  101. Call Log 'DIS2 version' version 'started' date() time()
  102.  
  103. If delaytime <> '' Then Do
  104.   Call Log 'Waiting for' delaytime 'minutes...'
  105.   Say 'Waiting for' delaytime 'minutes...'
  106.   Call SysSleep (60*delaytime)
  107. End
  108.  
  109. If starttime <> '' Then Do
  110.   Parse var starttime hh':'mm':'ss
  111.   If ss='' Then ss=0
  112.   If hh<0 | hh>24 Then Do
  113.     Call Log 'Invalid time, must be entered as hh:mm:ss or hh:mm'
  114.     Say 'Invalid time, must be entered as hh:mm:ss or hh:mm'
  115.     Exit 1
  116.   End
  117.   If mm<0 | mm>59 Then Do
  118.     Call Log 'Invalid time, must be entered as hh:mm:ss or hh:mm'
  119.     Say 'Invalid time, must be entered as hh:mm:ss or hh:mm'
  120.     Exit 1
  121.   End
  122.   If ss<0 | ss>59 Then Do
  123.     Call Log 'Invalid time, must be entered as hh:mm:ss or hh:mm'
  124.     Say 'Invalid time, must be entered as hh:mm:ss or hh:mm'
  125.     Exit 1
  126.   End
  127.   Call Log 'Waiting until' hh':'mm':'ss
  128.   Say 'Waiting until' hh':'mm':'ss
  129.   goseconds = hh*3600 + mm*60 + ss
  130.   numseconds = time('S')   /* Number of seconds since midnight */
  131.   If numseconds > goseconds Then Do
  132.     waitsecs = (60 * 60 * 24) - numseconds + goseconds
  133.   End
  134.   Else Do
  135.     waitsecs = goseconds - numseconds
  136.   End
  137.   hh = Trunc(waitsecs / 3600)
  138.   mm = Trunc((waitsecs - (3600*hh)) / 60)
  139.   ss = waitsecs - (3600*hh) - (60*mm)
  140.   Call SysSleep waitsecs
  141. End
  142.  
  143. ControlQ = queue_name
  144. Call Log 'Queue' ControlQ
  145. CurrentQ = RXQUEUE('Set', ControlQ)
  146. Do While Queued() <> 0
  147.   Pull junk
  148. End
  149.  
  150. Call Log 'Starting GETMAIL...'
  151. Say 'Starting GETMAIL...'
  152. '@START /C "GETMAIL - smtp daemon" GETMAIL.CMD'
  153.  
  154. Call UserExit 1
  155.  
  156. Call Log 'Starting SLIP...'
  157. Say 'Starting SLIP...'
  158. '@START /C SLIP.EXE'
  159. '@SLIPWAIT' slip_wait
  160. If RC=1 Then Do
  161.   Call Log 'SLIP failed to start'
  162.   '@KILLEM SLIP.EXE'
  163.   Say
  164.   Exit 1
  165. End
  166. Say 'SLIP started...'
  167. Call Log 'SLIP started...'
  168.  
  169. Call UserExit 2
  170.  
  171. If notify = 1 Then Do
  172.   Call Beep 900, 200
  173.   Call Beep 1000, 200
  174.   Call Beep 1100, 200
  175. End
  176.  
  177. sendit  = -1      /* started */
  178. newnews = -1      /* started */
  179. alive = 1         /* SLIP is alive */
  180.  
  181. Call Log 'Starting SENDIT...'
  182. Say 'Starting SENDIT...'
  183. '@START /C "SENDIT - smtp client" SENDIT.CMD'
  184.  
  185. Call Log 'Starting NEWNEWS...'
  186. Say 'Starting NEWNEWS...'
  187. '@START /C "NEWNEWS - nntp client" NEWNEWS.CMD'
  188.  
  189. Do Until alive = 0
  190.   Do While Queued() = 0 & time('E') < slip_timeout
  191.     Call SysSleep 10
  192.   End
  193.   If Queued() <> 0 Then Do
  194.     Pull message
  195.     Say message
  196.     Call Log message
  197.     Parse var message '<'source'>' command reason code
  198.     Select
  199.       When source = 'SENDIT' Then Do
  200.         Call time 'R' /* Reset elapsed time counter */
  201.         Select
  202.           When command = 'START' Then Do
  203.             sendit = 1 /* Running */
  204.           End
  205.           When command = 'STOP' Then Do
  206.             sendit = 0 /* Stopped */
  207.           End
  208.           When command = 'FAIL' Then Do
  209.             sendit = 0 /* Failed */
  210.           End
  211.         End
  212.       End
  213.       When source = 'NEWNEWS' Then Do
  214.         Call time 'R' /* Reset elapsed time counter */
  215.         Select
  216.           When command = 'START' Then Do
  217.             newnews = 1
  218.           End
  219.           When command = 'STOP' Then Do
  220.             newnews = 0
  221.           End
  222.           When command = 'FAIL' Then Do
  223.             newnews = 0
  224.           End
  225.         End
  226.       End
  227.       Otherwise
  228.         Call Log 'Unknown source' source
  229.     End
  230.     If newnews = 0 & sendit = 0 Then Do
  231.       alive = 0
  232.     End
  233.   End
  234.   Else Do
  235.     Say '*TIMEOUT* program terminating...'
  236.     Call Log slip_timeout 'seconds elapsed since last message'
  237.     alive = 0
  238.   End
  239. End
  240. Call UserExit 3
  241.  
  242. If killslip = 1 Then Do
  243.   Say 'Killing SLIP in 'kill_delay' seconds...'
  244.   Call Log 'KILLING SLIP in 'kill_delay' seconds...'
  245.   Call SysSleep kill_delay
  246.   '@KILLEM SLIP.EXE'
  247.   Call UserExit 4
  248.   Say
  249. End
  250. Else Do
  251.   Say 'Not killing SLIP...'
  252. End
  253.  
  254. Call Log 'Deleting control queue'
  255. Call RXQUEUE 'Set', oq
  256. Call RXQUEUE 'Delete', ControlQ
  257.  
  258. Exit 0
  259.  
  260. halt:
  261.   Say 'Program terminated by CTRL+C'
  262.   Exit 0
  263.  
  264. Log: Procedure expose logfile ControlQ CurrentQ
  265.  
  266.   Parse arg line
  267.   retcode = Stream(logfile, 'c', 'open write')
  268.   retcode = LINEOUT(logfile, line)
  269.   retcode = Stream(logfile, 'c', 'close')
  270.   Return
  271.  
  272. CheckParameters:
  273.   Return
  274.  
  275. UserExit:
  276.  
  277.   arg exit
  278.   userexit = Value('userexit_'exit)
  279.   file = Stream(userexit, 'c', 'query exists')
  280.   If file = '' Then Do
  281.     Call Log 'User Exit' exit 'missing or not enabled ['userexit']'
  282.   End
  283.   Else Do
  284.     Call Log 'Calling User Exit' exit '['userexit']'
  285.     Interpret 'Call "'file'"'
  286.   End
  287.   Return
  288.  
  289. ReadINIFile:
  290.  
  291.   arg inifile, application
  292.   file = Stream(inifile, 'c', 'query exists')
  293.   If file = '' Then Do
  294.     file = SysSearchPath('PATH',inifile)
  295.   End
  296.   If file = '' Then Do
  297.     Say 'Unable to find' inifile
  298.     Exit 1
  299.   End
  300.   Say 'inifile' file
  301.   app = ''
  302.   ini. = 0
  303.   retcode = Stream(file, 'c', 'open read')
  304.   If retcode <> 'READY:' Then Do
  305.     Say 'Unable to open' file
  306.     Exit 2
  307.   End
  308.   Do While Lines(file) <> 0
  309.     line = LINEIN(file)
  310.     If Left(line, 1) = '[' Then Do
  311.       Parse Upper var line '[' app ']' .
  312.     End
  313.     Else Do
  314.       If line <> '' & Left(line, 1) <> '#' Then Do
  315.         If app = '' Then Do
  316.           Say 'Invalid line in' file 'expected [application_name]'
  317.           Exit 1
  318.         End
  319.         If app = application | app = 'DEFAULT' Then Do
  320.           Parse var line varname '=' varvalue
  321.           Parse Upper var varname varname
  322.           varname = Strip(varname)
  323.           varvalue = Strip(varvalue)
  324.           If ini.varname = 0 | app = application Then Do
  325.             retcode = Value(varname, varvalue)
  326.             ini.varname = 1
  327.           End
  328.         End
  329.       End
  330.     End
  331.   End
  332.   retcode = Stream(file, 'c', 'close')
  333.   Return
  334.  
  335. ShowWarranty:
  336.   Say 'Because the program is licensed free of charge, there is no warranty'
  337.   Say 'for the program, to the extent permitted by applicable law.  Except when'
  338.   Say 'otherwise stated in writing the copyright holders and/or other parties'
  339.   Say 'provide the program "as is" without warranty of any kind, either expressed'
  340.   Say 'or implied, including, but not limited to, the implied warranties of'
  341.   Say 'merchantability and fitness for a particular purpose.  The entire risk as'
  342.   Say 'to the quality and performance of the program is with you.  Should the'
  343.   Say 'program prove defective, you assume the cost of all necessary servicing,'
  344.   Say 'repair or correction.'
  345.   Say
  346.   Say 'Read the GNU PUBLIC LICENSE for full details'
  347.   Return
  348.  
  349. ShowConditions:
  350.   Say 'You may copy and distribute verbatim copies of the Program''s'
  351.   Say 'source code as you receive it, in any medium, provided that you'
  352.   Say 'conspicuously and appropriately publish on each copy an appropriate'
  353.   Say 'copyright notice and disclaimer of warranty; keep intact all the'
  354.   Say 'notices that refer to this License and to the absence of any warranty;'
  355.   Say 'and give any other recipients of the Program a copy of this License'
  356.   Say 'along with the Program.'
  357.   Say
  358.   Say 'Read the GNU PUBLIC LICENSE for full details'
  359.   Return
  360.