home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / wCNews_1.0.30.lha / rexx / newsexec.rexx
Encoding:
OS/2 REXX Batch file  |  1993-05-11  |  6.9 KB  |  257 lines

  1. /* rexx:newsexec.rexx, (c) Thu, 18 Mar 1993 02:58:10 +0100 by "Kai 'wusel' Siering" <wusel@hactar.hanse.de> */
  2. /* based on */
  3. /* ARexx-NewsExec (c)1991 by Friedrich Gentner E-Mail: fgent@gentle.nbg.sub.org */
  4.  
  5. mailfile = 't:execmail.file'
  6.  
  7. accessfalid = 0
  8. from = ''
  9. exec = ''
  10. checkgroups. = ''
  11. checkline. = ''
  12. orggroups. = ''
  13. orgflag. = ''
  14. news     = "news"
  15. name     = "USENET Daemon"
  16. autoexec = "newsexec"
  17.  
  18. if ~exists('t:') then do
  19.   say 'T: has not been assigned, aborting!'
  20.   exit(25)
  21. end
  22.  
  23. say 'newsexec engaged'
  24.  
  25. /* Config scannen */
  26.  
  27. if (open(conf,"uulib:config",r)) then do
  28.   do while ~eof(conf)
  29.     in=readln(conf)
  30.  
  31.     in2 = Translate(in, ' ', D2C(9))
  32.     parse var in2 key cont
  33.  
  34.     select
  35.       when upper(key)="USERNAME"   then user=strip(cont)
  36.       when upper(key)="NEWSMASTER" then news=strip(cont)
  37. /*      when upper(key)="NODENAME" then node=strip(cont)
  38.       when upper(key)="DOMAINNAME" then domain=strip(cont)
  39.       when upper(key)="TIMEZONE" then tzone=strip(cont)  */
  40.       otherwise nop
  41.     end
  42.   end
  43.   err=close(conf)
  44. end
  45. else do
  46.   say 'Configuration file (UUlib:config) not found, aborting!'
  47.   exit(20)
  48. end
  49.  
  50. root = strip(user)
  51.  
  52. /* Achja hier wird das aktuelle Datum generiert */
  53.  
  54. /* curdate=left(date(w),3)", "date(n) time() tzone */
  55.  
  56.  
  57. do while ~eof(stdin)
  58.   inline = readln(stdin)
  59.   parse var inline '#exec#' exec
  60.   parse var inline 'From ' from senddate
  61.   if (from ~= '') then
  62.   do
  63.     if (from ~= root & from ~= news) then exit 0
  64.     else say 'access validation complete'
  65.     accessvalid = 1
  66.   end
  67.   if (exec ~= '') then
  68.   do
  69.     exec = strip(exec)
  70.     if (accessvalid ~= 1) then exit 0
  71.  
  72.     parse var exec cmd group comment
  73.     select
  74.       when cmd = 'newgroup' then
  75.       do
  76.         addnewgroup(group,'uulib:.grouplist',':',':')
  77.         addnewgroup(group,'uulib:news/newsgroups',' ', ' '||comment)
  78.         if (index(upper(comment), 'MODERATED') ~= 0) then
  79.           addnewgroup(group,'uulib:news/active',' ',' 0000000000 0000000001 m')
  80.         else
  81.           addnewgroup(group,'uulib:news/active',' ',' 0000000000 0000000001 y')
  82.       end
  83.       when cmd = 'rmgroup' then
  84.       do
  85.         removegroup(group,'uulib:.grouplist',':')
  86.         removegroup(group,'uulib:news/newsgroups',' ')
  87.         removegroup(group,'uulib:news/active',' ')
  88.       end
  89.       when cmd = 'checkgroups' then
  90.       do
  91.         say 'checking groups'
  92.         /* to get some speed at first both list are read in compounds */
  93.         c = 0
  94.         do while ~eof(stdin)
  95.           inline = readln(stdin)
  96.           parse var inline group comment
  97.           /* This line could cause trouble because also other */
  98.           /* words might contain points */
  99.           if (index(group,'.') ~= 0) then
  100.           do
  101.             c = c + 1
  102.             checkline.c = inline             /* for #exec#-line */
  103.             checkgroups.c = strip(group)     /* for comparison  */
  104.           end
  105.         end
  106.         n = 0
  107.         if open(infile, 'uulib:news/active', 'read') then
  108.         do
  109.           do while ~eof(infile)
  110.             inline = readln(infile)
  111.             parse var inline group bla1 bla2 flag
  112.             n = n + 1
  113.             orggroups.n = strip(group)       /* for comparison  */
  114.             orgflags.n = flag                /* for m-check     */
  115.           end
  116.           close(infile)
  117.         end
  118.  
  119.         /* Now every group in both lists are compared with each other. */
  120.         /* Groups which are in both liste get deleted.                 */
  121.         /* The remaining groups in orggroups are obsolet and the grous */
  122.         /* in checkgroups are missing.                                 */
  123.         do i = 1 to n
  124.           do j = 1 to c
  125.             if (orggroups.i = checkgroups.j) then
  126.             do
  127.               orggroups.i = ''
  128.               checkgroups.j = ''
  129.             end
  130.           end
  131.         end
  132.  
  133.         /* Now generate an apropriate Mail for USENET */
  134.         if open(outfile, mailfile, 'write') then
  135.         do
  136.           writeln( outfile, 'To: 'news)
  137.           writeln( outfile, 'Reply-To: 'autoexec)
  138.           writeln( outfile, 'From: 'news' ('name')')
  139.           writeln( outfile, 'Subject: checkgroup results')
  140.           writeln( outfile, '')
  141.           writeln( outfile, 'Please check the following commands, delete')
  142.           writeln( outfile, 'unconvenient lines and confirm by replying')
  143.           writeln( outfile, '')
  144.           writeln( outfile, 'The following groups are obsolet')
  145.           do i = 1 to n
  146.             if (orggroups.i ~= '') then
  147.               writeln( outfile, '#exec# rmgroup' orggroups.i)
  148.           end
  149.           writeln( outfile, 'The following groups are missing')
  150.           do j = 1 to c
  151.             if (checkgroups.j ~= '') then
  152.               writeln( outfile, '#exec# newgroup' checkline.j)
  153.           end
  154.           close(outfile)
  155.  
  156.           address COMMAND 'sendmail <'mailfile
  157.           address COMMAND 'delete 'mailfile' quiet'
  158.         end
  159.  
  160.         /* Checkgroup needs a moderated-flag comparison.  */
  161.         /* Therefore, 2 #exec# commands need to be added  */
  162.         /* For example 'setmoderated' and 'rmmoderated'   */
  163.         /* Maybe next time.                               */
  164.       end
  165.       otherwise say 'don''t know how to handle 'cmd
  166.     end
  167.   end
  168. end
  169.  
  170. exit 0
  171.  
  172. addnewgroup: procedure
  173. /* The groupend ist necessary because of main-groups. */
  174. /* For example if you search for 'comp.sys.amiga' and */
  175. /* comp.sys.amiga.programmer already exists you will  */
  176. /* find the string comp.sys.amiga.                    */
  177. /* Because the separation char need not to be ' ' it  */
  178. /* is passed by argument.                             */
  179.  
  180. group     = arg(1)
  181. filename  = arg(2)
  182. groupend  = arg(3)
  183. extension = arg(4)
  184.  
  185. success = open( infile, filename, "read")
  186. if (~success) then
  187. do
  188.   say 'Can''t access to' filename
  189.   exit
  190. end
  191.  
  192. ok = 0
  193. do while (~eof(infile) & (ok = 0))
  194.   inline = readln(infile)
  195.   ok = index(inline, group||groupend)
  196. end
  197. close(infile)
  198.  
  199. if (ok = 1) then return 0      /* this group already exists */
  200.  
  201. address COMMAND 'copy 'filename' to 'filename'.old'   /* for safetiness */
  202. address COMMAND 'copy 'filename' to t:news.work'
  203.  
  204. success = open( outfile, 't:news.work', "append")
  205. if (~success) then
  206. do
  207.   say 'Can''t access to t:news.work'
  208.   exit
  209. end
  210.  
  211. writeln( outfile, group || extension)
  212. close(outfile)
  213.  
  214. address COMMAND 'sort t:news.work to 'filename
  215. address COMMAND 'delete t:news.work quiet'
  216.  
  217. return 0
  218.  
  219. removegroup: procedure
  220. /* Here is groupend also necessary ... see addnewgroup */
  221. group     = arg(1)
  222. filename  = arg(2)
  223. groupend  = arg(3)
  224.  
  225. address COMMAND 'copy 'filename' to 'filename'.old'  /* for saftiness */
  226.  
  227. success = open( infile, filename, "read")
  228. if (~success) then
  229. do
  230.   say 'Can''t access to' filename
  231.   exit
  232. end
  233.  
  234. success = open( outfile, 't:news.work', "write")
  235. if (~success) then
  236. do
  237.   say 'Can''t access to t:news.work'
  238.   exit
  239. end
  240.  
  241. do while ~eof(infile)
  242.   inline = readln(infile)
  243.   ok = index(inline, group||groupend)
  244.   if ((ok ~= 1) & (inline ~= '')) then writeln(outfile,inline)
  245. end
  246. close(infile)
  247. close(outfile)
  248.  
  249. address COMMAND 'copy t:news.work to 'filename' clone'
  250. address COMMAND 'delete t:news.work quiet'
  251.  
  252. return 0
  253.  
  254. /* end */
  255.  
  256.  
  257.