home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / steward8.zip / Errors.cmd < prev    next >
OS/2 REXX Batch file  |  1996-06-27  |  14KB  |  487 lines

  1. /* Steward Version 1.1 Build 8 */
  2. /* Errors Module */
  3. /*
  4.  * A mailing list processor in Rexx by Paul Hethmon
  5.  *
  6.  */
  7.  
  8. /* variable declarations */
  9.  
  10. Steward = 'Steward'
  11. StewardVersion = 'Version 1.1 Build 8'
  12. StewardDate = '26 June 1996'
  13. uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  14. lowercase = 'abcdefghijklmnopqrstuvwxyz'
  15. Env = 'OS2ENVIRONMENT'
  16. FALSE = 0
  17. TRUE = 1
  18.  
  19. /* Set to 1 to enable debug output */
  20. Debug = TRUE
  21. /* Set to 1 to enable logging */
  22. Log = TRUE
  23. LogFile = ''
  24. ETime1 = 0
  25. ETime2 = 0
  26. Author = ''
  27. AdminFile = ''
  28. AdminSubject = ''
  29. AdminTo = ''
  30.  
  31. /* Variables normally read from the configuration file */
  32. /* These values are provided as defaults only */
  33. HomeDir = 'c:'
  34. LogDir = 'c:'
  35. ListDir = 'c:'
  36. Mailer = 'hmailer'
  37. WhereAmI = 'hostname'
  38. WhoAmI = Steward
  39. WhoAmIOwner = 'postmaster@'WhereAmI
  40. MasterPassword = 'steward'
  41.  
  42. /* The following are set on a per list basis */
  43. AdminPassword = 'steward-list'
  44. Administrivia = 0
  45. ListOwner = WhoAmIOwner
  46. Advertise = '*'
  47. ApprovePassword = 'steward-pass'
  48. DoArchive = 0
  49. Moderated = 0
  50. NoList = 0
  51. Precedence = 1
  52. ListHeader = 1
  53. DoDigest = 0
  54. DigestVolume = 0
  55. DigestIssue = 0
  56. DigestName = ''
  57. DigestRmHeader = 1
  58. DigestFronter = ''
  59. DigestFooter = ''
  60. DigestSubs = TRUE
  61. SubscribePolicy = 'open'
  62. ReplyTo = ''
  63. SubjectPrefix = 'Steward-List: '
  64. OpenPosting = FALSE
  65. WelcomeFile = ''
  66. CaseInsensitive = FALSE
  67.  
  68. /* Some other global variables */
  69. HeadFrom = ''
  70. HeadTo = ''
  71. HeadReplyTo = ''
  72. HeadSubject = ''
  73. HeadDate = ''
  74. HeadCc = ''
  75. HeadSender = ''
  76. HeadEmail = ''
  77. Email = ''
  78. Approved = FALSE
  79. PassWord = ''
  80.  
  81. /* The external functions we need */
  82. call RxFuncAdd 'SysTempFileName', 'RexxUtil', 'SysTempFileName'
  83. call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  84. call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  85. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  86.  
  87. /* start main function */
  88. /* The first arg is who the message was sent to.
  89.  * The second is the filename. We're responsible
  90.  * for cleaning up the file if needed.
  91.  */
  92. parse arg ListName MsgFile
  93.  
  94. if Debug = TRUE then say 'ListName =' ListName 'MsgFile =' MsgFile
  95.  
  96. call on error name ErrHandler
  97.  
  98. say 'Reading Master Configuration File Now.'
  99.  
  100. /* Read the master configuration file now */
  101. rc = ReadMasterCf()
  102. if rc = FALSE then
  103.   do
  104.   say 'Unable to read master configuration file. Failing.'
  105.   ErrFile = SysTempFileName('?????.err', '?')
  106.   rc = stream(ErrFile, 'C', 'OPEN WRITE')
  107.   rc = lineout(ErrFile, 'Steward Error File', )
  108.   rc = lineout(ErrFile, 'You must rerun Steward with the recipient name and', )
  109.   rc = lineout(ErrFile, 'message file name listed below in order to process', )
  110.   rc = lineout(ErrFile, 'this message.', )
  111.   rc = lineout(ErrFile, 'ListName =' ListName, )
  112.   rc = lineout(ErrFile, 'MsgFile =', MsgFile, )
  113.   rc = stream(ErrFile, 'C', 'CLOSE')
  114.   exit
  115.   end
  116.  
  117. /* change to the Steward Home Directory */
  118. Junk = directory(HomeDir)
  119.  
  120. if ListName = WhoAmI then
  121.   ListOwner = WhoAmIOwner
  122. else
  123.   call ReadListCf(ListName) /* Read the per list configuration file */
  124.  
  125. say 'ListOwner =' ListOwner
  126.  
  127. if Debug = TRUE then
  128.   do
  129.   say 'LogDir =' LogDir
  130.   say 'HomeDir = ' HomeDir
  131.   say 'ListDir =' ListDir
  132.   say 'Junk =' Junk
  133.   end
  134.  
  135. if Log = TRUE then do
  136.   ETime1 = time('E')
  137.   call StartLog
  138.   call WriteLog('ListName =' ListName)
  139.   call WriteLog('MsgFile =' MsgFile)
  140.   end
  141.  
  142. call DoErrors
  143.  
  144. /* Make sure the tmp file is deleted */
  145. rc = SysFileDelete(MsgFile)
  146.  
  147. if Log = TRUE then do
  148.   ETime2 = time('E')
  149.   call StopLog
  150.   end
  151.  
  152. exit
  153.  
  154. /* ------------------------------------------------------------------ */
  155.  
  156. DoErrors:
  157.  
  158. rc = stream(MsgFile, 'C', 'OPEN READ')  /* open the file for reading */
  159. if rc <> 'READY:' then do
  160.   call WriteLog('Cannot open message file.')
  161.   return
  162.   end
  163.  
  164. /* create a temp file for the outgoing message */
  165. OutFile = SysTempFileName('f?????.tmp', '?');
  166. rc = stream(OutFile, 'C', 'OPEN WRITE')  /* open the file for writing */
  167. if rc <> 'READY:' then do
  168.   call WriteLog('Cannot create temp file for outgoing message.')
  169.   return
  170.   end
  171.  
  172. /* write the headers first */
  173. AdminSubject = 'Error message from' WhoAmI
  174. AdminTo = ListOwner
  175. AdminFile = OutFile
  176. call WriteAdminHeaders
  177.  
  178. rc = lineout(Outfile, WhoAmI 'has received the following error message:', )
  179. rc = lineout(OutFile, '----- begin message ------------------------------', )
  180.  
  181. /* now copy the rest of the message */
  182. do while lines(MsgFile) <> 0         /* until end of file */
  183.   Line = linein(MsgFile)             /* get a line of the file */
  184.   rc = lineout(OutFile, Line, )      /* write it to the outfile */
  185.   end
  186.  
  187. rc = lineout(OutFile, '----- end message --------------------------------', )
  188.  
  189. rc = stream(MsgFile, 'C', 'CLOSE')   /* close both files */
  190. rc = stream(OutFile, 'C', 'CLOSE')
  191.  
  192. EmailFile = SysTempFileName('e?????.tmp', '?')
  193. rc = stream(EmailFile, 'C', 'OPEN WRITE')  /* open the file for writing */
  194. if rc <> 'READY:' then do
  195.   call WriteLog('Cannot create email file.')
  196.   rc = SysFileDelete(OutFile)
  197.   return
  198.   end
  199. rc = lineout(EmailFile, ListOwner, )
  200. rc = stream(EmailFile, 'C', 'CLOSE')
  201.  
  202. say 'Sending message to' ListOwner
  203.  
  204. /* now mail it to the moderator */
  205. Mailer ListName'-owner@'WhereAmI EmailFile OutFile
  206.  
  207. return
  208.  
  209. /* ------------------------------------------------------------------ */
  210. /*
  211.  * Read the master configuration file
  212.  *
  213.  */
  214.  
  215. ReadMasterCf: procedure expose HomeDir LogDir ListDir Mailer WhereAmI WhoAmI ,
  216.               WhoAmIOwner MasterPassword Env TRUE FALSE Debug
  217.  
  218. if Debug = TRUE then say 'Reading Steward configuration file.'
  219.  
  220. /* Find out where the configuration file should be */
  221. StewardCf = value('steward_cf',,Env)
  222. /* StewardCf = value('steward_cf_test',,Env) */
  223.  
  224. /* If its not defined then assume wherever we are */
  225. if StewardCf = '' then do
  226.   StewardCf = '.'
  227.   end
  228.  
  229. FileName = StewardCf'\steward.cf'
  230.  
  231. rc = LockOpen(FileName 'READ')  /* open the file locking it */
  232. if rc = FALSE then
  233.   return FALSE                   /* return FALSE if cannot open */
  234.  
  235. /* now read the configuration file */
  236. do while lines(FileName) <> 0         /* until end of file */
  237.   Line = linein(FileName)             /* get a line of the file */
  238.   parse var Line Line '#' Comment     /* separate out any comments */
  239.   if Line <> '' then do               /* if not null */
  240.     parse var Line Key '=' Val        /* find the key and value */
  241.     if Key <> '' then do
  242.       Val = strip(Val, 'B', ' ')      /* remove any blanks */
  243.       Key = strip(Key, 'B', ' ')
  244.       select
  245.         when Key = 'HomeDir' then
  246.           HomeDir = Val
  247.         when Key = 'LogDir' then
  248.           LogDir = Val
  249.         when Key = 'ListDir' then
  250.           ListDir = Val
  251.         when Key = 'Mailer' then
  252.           Mailer = Val
  253.         when Key = 'WhereAmI' then
  254.           WhereAmI = Val
  255.         when Key = 'WhoAmI' then
  256.           WhoAmI = Val
  257.         when Key = 'WhoAmIOwner' then
  258.           WhoAmIOwner = Val
  259.         when Key = 'MasterPassword' then
  260.           MasterPassword = Val
  261.         otherwise nop
  262.         end   /* select */
  263.       end     /* if Key <> '' */
  264.     end       /* if Line <> '' */
  265.  
  266.   Key = ''
  267.  
  268. end /* end do while */
  269.  
  270. rc = LockClose(FileName)
  271.  
  272. if Debug = TRUE then say 'Steward.cf file read.'
  273.  
  274. return TRUE
  275.  
  276. /* ------------------------------------------------------------------ */
  277.  
  278. ErrHandler:
  279.  
  280. SIGerrCode = RC
  281. StewardErrLog = 'Steward.err'
  282.  
  283. if Debug = TRUE then say 'Identified error while executing line #'Sigl'   RC = ['SIGerrCode']'
  284. if Debug = TRUE then say '['SourceLine(Sigl)']'
  285. rc = lineout( StewardErrLog, '     -----', )
  286. rc = lineout( StewardErrLog, 'Error ['SIGerrCode'] while executing line #'Sigl, )
  287. rc = lineout( StewardErrLog, '['SourceLine(Sigl)']')
  288.  
  289. return
  290.  
  291.  
  292. /* ------------------------------------------------------------------ */
  293. /*
  294.  * Read the per list configuration file
  295.  *
  296.  */
  297.  
  298. ReadListCf: procedure expose ListDir AdminPassword ListOwner Administrivia,
  299.             Advertise ApprovePassword DoArchive Moderated NoList Precedence,
  300.             ListHeader SubscribePolicy ReplyTo SubjectPrefix TRUE FALSE,
  301.             DoDigest DigestRmHeader DigestVolume DigestIssue DigestFronter,
  302.             DigestFooter DigestName Debug Log LogFile OpenPosting WelcomeFile,
  303.             DigestSubs CaseInsensitive
  304.  
  305. parse arg ListName
  306.  
  307. if Debug = TRUE then say 'Reading list configuration file for' ListName
  308.  
  309. /* First check to see if this is a digest request */
  310. parse var ListName List '-' Digest
  311. Digest = translate(Digest, lowercase, uppercase)
  312. if Digest = 'digest' then
  313.   FileName = ListDir'\'List'\'List'.cf'
  314. else  
  315.   FileName = ListDir'\'ListName'\'ListName'.cf'
  316.  
  317. if Debug = TRUE then say 'Reading filename "'FileName'"'
  318.  
  319. rc = LockOpen(FileName 'READ')  /* open the file locking it */
  320. if rc = FALSE then
  321.   return FALSE                   /* return FALSE if cannot open */
  322.  
  323. /* now read the configuration file */
  324. do while lines(FileName) <> 0         /* until end of file */
  325.   Line = linein(FileName)             /* get a line of the file */
  326.   parse var Line Line '#' Comment     /* separate out any comments */
  327.   if Line <> '' then do               /* if not null */
  328.     parse var Line Key '=' Val        /* find the key and value */
  329.     if Key <> '' then do
  330.       Val = strip(Val, 'B', ' ')      /* remove any blanks */
  331.       Key = strip(Key, 'B', ' ')
  332. /*      say Key '=' Val */
  333.       select
  334.         when Key = 'AdminPassword' then
  335.           AdminPassword = Val
  336.         when Key = 'ListOwner' then
  337.           ListOwner = Val
  338.         when Key = 'Administrivia' then
  339.           Administrivia = Val
  340.         when Key = 'Advertise' then
  341.           Advertise = Val
  342.         when Key = 'ApprovePassword' then
  343.           ApprovePassword = Val
  344.         when Key = 'DoArchive' then
  345.           DoArchive = Val
  346.         when Key = 'Moderated' then
  347.           Moderated = Val
  348.         when Key = 'NoList' then
  349.           NoList = Val
  350.         when Key = 'Precedence' then
  351.           Precedence = Val
  352.         when Key = 'ListHeader' then
  353.           ListHeader = Val
  354.         when Key = 'SubscribePolicy' then
  355.           SubscribePolicy = Val
  356.         when Key = 'ReplyTo' then
  357.           ReplyTo = Val
  358.         when Key = 'SubjectPrefix' then
  359.           SubjectPrefix = Val
  360.         when Key = 'DoDigest' then
  361.           DoDigest = Val
  362.         when Key = 'DigestRmHeader' then
  363.           DigestRmHeader = Val
  364.         when Key = 'DigestVolume' then
  365.           DigestVolume = Val
  366.         when Key = 'DigestIssue' then
  367.           DigestIssue = Val
  368.         when Key = 'DigestName' then
  369.           DigestName = Val
  370.         when Key = 'DigestFronter' then
  371.           DigestFronter = Val
  372.         when Key = 'DigestFooter' then
  373.           DigestFooter = Val
  374.         when Key = 'OpenPosting' then
  375.           OpenPosting = Val
  376.         when Key = 'WelcomeFile' then
  377.           WelcomeFile = Val
  378.         when Key = 'DigestSubs' then
  379.           DigestSubs = Val
  380.         when Key = 'CaseInsensitive' then
  381.           CaseInsensitive = Val
  382.         otherwise nop
  383.         end   /* select */
  384.       end     /* if Key <> '' */
  385.     end       /* if Line <> '' */
  386.  
  387.   Key = ''
  388.  
  389. end /* end do while */
  390.  
  391. rc = LockClose(FileName)
  392.  
  393. return TRUE
  394.  
  395. /* ------------------------------------------------------------------ */
  396.  
  397. StartLog: procedure expose LogDir LogFile ETime1 ETime2 Debug FALSE TRUE
  398.  
  399. FileName = LogDir'\?????.log'
  400. LogFile = SysTempFileName(FileName, '?')
  401.  
  402. if LogFile = '' then
  403.   do
  404.   say 'Cannot create temporary file.'
  405.   say 'Setting logfile to NUL'
  406.   LogFile = 'NUL'
  407.   Log = FALSE
  408.   return
  409.   end
  410.  
  411. if Debug = TRUE then say 'LogFile =' LogFile
  412.  
  413. rc = stream(LogFile, 'C', 'OPEN WRITE')
  414.  
  415. TmpTime = time('N')
  416. TmpDate = date('N')
  417.  
  418. rc = lineout(LogFile, 'Date:' TmpDate, )
  419. rc = lineout(LogFile, 'Time:' TmpTime, )
  420.  
  421. return
  422.  
  423. /* ------------------------------------------------------------------ */
  424.  
  425. StopLog: procedure expose LogFile LogDir ETime1 ETime2 Debug FALSE TRUE
  426.  
  427. ETime = ETime2 - Etime1
  428.  
  429. if Debug= TRUE then say 'Elapsed Time =' ETime
  430.  
  431. call WriteLog('Elapsed Time:' ETime)
  432. call WriteLog('')
  433. call WriteLog('=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=')
  434. call WriteLog('')
  435.  
  436. rc = stream(LogFile, 'C', 'CLOSE')
  437.  
  438. PermLog = LogDir'\steward.log'
  439.  
  440. call AppendLock(LogFile PermLog)
  441.  
  442. rc = SysFileDelete(LogFile)
  443.  
  444. return
  445.  
  446. /* ------------------------------------------------------------------ */
  447.  
  448. WriteLog: procedure expose LogFile
  449.  
  450. parse arg String
  451.  
  452. rc = lineout(LogFile, String, )
  453.  
  454. return
  455.   
  456. /* ------------------------------------------------------------------ */
  457. /*
  458.  * Write out our standard headers for an admin message
  459.  *
  460.  */
  461.  
  462. WriteAdminHeaders: procedure expose AdminTo WhoAmI WhereAmI AdminSubject AdminFile,
  463.                    Env
  464.  
  465. TimeZone = value( 'TZ', , Env)
  466. TmpTime = time('N')
  467. DayOfWeek = date('W')
  468. DayOfWeek = left(DayOfWeek, 3)
  469. TmpDate = date('N')
  470. rc = lineout(AdminFile, 'Date:' DayOfWeek',' TmpDate TmpTime TimeZone, )
  471. rc = lineout(AdminFile, 'Sender:' WhoAmI'-owner <'WhoAmI'-owner@'WhereAmI'>', )
  472. rc = lineout(AdminFile, 'From:' WhoAmI'-owner <'WhoAmI'-owner@'WhereAmI'>', )
  473. rc = lineout(AdminFile, 'Reply-To:' WhoAmI '<'WhoAmI'@'WhereAmI'>', )
  474. rc = lineout(AdminFile, 'To:' AdminTo, )
  475. rc = lineout(AdminFile, 'Subject:' AdminSubject, )
  476. rc = lineout(AdminFile, '', )
  477.  
  478. return
  479.  
  480. /* ------------------------------------------------------------------ */
  481. /* ------------------------------------------------------------------ */
  482. /* ------------------------------------------------------------------ */
  483.  
  484.  
  485.  
  486.  
  487.