home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / newgrp14.zip / newgrps.cmd < prev    next >
OS/2 REXX Batch file  |  1995-06-18  |  8KB  |  313 lines

  1. /* NEWGROUPS.CMD V1.4 */
  2.  
  3. settings.version   = "NEWGROUPS V1.4 (C) 1995 M.F. van Loon (mfvl@xs4all.nl)";
  4. settings.target    = "YARN";
  5. /* settings.target    = "SOUP2SQ"; */
  6.  
  7. /*
  8.  
  9. Written by Michiel van Loon (C) 1995
  10. Based on rnr.cmd by Patrick J. Muller
  11.  
  12. V1.4 SOUP2SQ support added with thanks to Joost Vocke)
  13.      All groups listed if no newsdate file is found.
  14. V1.3 Footer added
  15. V1.2 Correct reaction if initial statuscode <> 200
  16. V1.1 Small modification when host does not accept connection
  17. V1.0 First release
  18.  
  19. This program is freeware. This program can be freely copied and changed as
  20. long as credits for the original program are given to me.
  21.  
  22. I can be reached for comments, suggestions for improvement, bugs and cheers at
  23.  
  24.             mfvl@xs4all.nl
  25.  
  26. This Command script is written to be used with SOUPER  and YARN and has been 
  27. tested only with SOUPER version 12 and Yarn version 0.83. 
  28. By uncommenting the settings.target = "SOUP2SQ" line the support will be for 
  29. SOUP2SQ (tested only for version 1.0).
  30.  
  31. This program connects to the newsserver and issues the NEWGROUPS command. If 1 
  32. or more newsgroups are reported a message is posted in a newsgroup named
  33. 'control.newgroups' (This name can be changed by the user by changing the line
  34. starting with
  35.  
  36. settings.newsgroup =
  37.  
  38. A special setting can be Email in whoich case the message is treated as an 
  39. Email message.
  40.  
  41. After creating the message the YARN import utility is used to make the
  42. message available.
  43.  
  44. This program requires RxSOCK which can be downloaded from many OS/2 software 
  45. archives.
  46.  
  47. Call: NEWGROUPS
  48.  
  49. Required environment variables:
  50. ETC         --  pointing to the TCPIP\ETC directory (already set by IAK)
  51. YARN        --  pointing to the YARN directory (must be set for YARN)
  52. NNTPSERVER  --  the name of the news host (must be set for SOUPER to
  53.                 retrieve news)
  54.  
  55. The SOUP2SQ requires the following settings too
  56.  
  57. USER        --  your UserId
  58. REALNAME    --  your Full Name
  59. MAILER      --  sendmail -t -f UserId@organisation
  60. POSTER      --  inews
  61.  
  62. Required files:
  63. %ETC%\newsdate -- This file contains 1 line with date and time of last query. 
  64.                   e.g. 950516 081330 This file gets updated after every run. 
  65.                   Change this file on your own risk.
  66.                   If this file is missing then a complete list of NEWSGROUPS 
  67.                   will be loaded.
  68.  
  69.  
  70. Some temporary files are created in the current directory, but should be cleaned
  71. up after finishing. Just in 1 case of normal execution a file may be left over. 
  72. This will happen when YARN is active while this script is running. In that case 
  73. IMPORT shall not be able to add the message to YARN message base. In a future (?)
  74. version I will change that, for now make sure that when this happens you do this 
  75. yourself with the command
  76.  
  77. IMPORT soup.zip
  78.  
  79. in the case of YARN or
  80.  
  81. soup2sq -r
  82.  
  83. in the case of SOUP2SQ
  84.  
  85. in the same directory as this script was running. The temporary files that can
  86. be removed have the form X???.TMP and Y???.TMP.
  87.  
  88. */
  89.  
  90. "@echo off";
  91.  
  92. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  93. call SysLoadFuncs
  94.  
  95. host = value( 'nntpserver',,'OS2ENVIRONMENT');
  96. if host ='' then do /* Do */
  97.   say 'You have to set environment variable NNTPSERVER to the name or address'
  98.   say 'of your USENET news server'
  99.   exit -1
  100. end  /* Do */
  101.  
  102. settings.server    = host;
  103. settings.port      = 119;
  104. settings.newsgroup = 'control.newgroups';
  105.  
  106. cr='0d'x
  107. lf='0a'x
  108. crlf='0d0a'x
  109. tab='09'x
  110.  
  111. if settings.target = "YARN" then do
  112.   yarn = value( 'yarn',,'OS2ENVIRONMENT');
  113.   if yarn = '' then do
  114.     say 'The YARN environment variable should be set. It should point to the'
  115.     say 'directory where the YARN programs are located'
  116.     exit -1;
  117.   end
  118. end
  119.  
  120. etcDrivePath = value( 'etc',,'OS2ENVIRONMENT');
  121. if etcDrivePath = '' then do
  122.   say 'The ETC environment variable should be set. Normally this variable is'
  123.   say 'set by the TCPIP or IAK package'
  124.   exit -1
  125. end  /* Do */
  126.  
  127. say settings.version
  128.  
  129. DateFile = etcDrivePath || '\newsdate';
  130. DF = DateFile;
  131.  
  132. DateFile = stream( DateFile, 'C', 'QUERY EXISTS' )
  133. if DateFile = '' then do
  134.     say 'DateFile not found.'
  135.     say 'All known groups are loaded'
  136.     opdracht = 'LIST';
  137.     dateline = 'beginning';
  138. end 
  139. else do
  140.     dateline = linein(DateFile);
  141.     call stream DateFile,'C','CLOSE'
  142.     opdracht = 'NEWGROUPS '||dateline;
  143. end
  144.  
  145. if RXFuncQuery("SockLoadFuncs") then
  146.   do
  147.   rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  148.   if rc\= 0 then
  149.     do
  150.       say "NEWGROUPS needs RxSock to make the connection with the Internet."
  151.       say "RxSock can be found at hobbes.nmsu.edu"
  152.       exit -1
  153.     end
  154.   rc = SockLoadFuncs(0);
  155.   end
  156.  
  157. say 'Connecting to' settings.server 'on port' settings.port
  158.  
  159. rc = SockGetHostByName(settings.server,"host.!");
  160. if  rc = 0 then
  161.   do 
  162.   say "Unable to resolve servername: " settings.server
  163.   exit -1
  164.   end
  165.  
  166. server = host.!addr
  167.  
  168. sock = SockSocket("AF_INET","SOCK_STREAM",0)
  169. if (sock = -1) then
  170.   do
  171.   say "Unable to create socket. Error =" errno
  172.   exit -1
  173.   end
  174.  
  175. server.!family = "AF_INET"
  176. server.!port   = settings.port
  177. server.!addr   = server
  178.  
  179. rc = SockConnect(sock,"server.!")
  180. if (rc = -1) then
  181.   Error(sock,rc,"Connection to news server failed. Error = "||errno)
  182.  
  183. l = GetResponse(sock);
  184. say l;
  185. if substr(l,1,3) \= '200' then
  186.   do
  187.   say "Exiting....."
  188.   exit 0
  189.   end
  190.  
  191. say opdracht;
  192. rc = SendMessage(sock,opdracht)
  193.  
  194. count = 0;
  195. line = GetResponse(sock);
  196. if substr(line,1,1)='2' then
  197. do
  198.   xf = SysTempFileName('X???.TMP')
  199.   call charout xf,'Newsgroups: '||settings.newsgroup||lf,1;
  200.   call charout xf,'From: nobody'||lf;
  201.   call charout xf,'Path: localhost'||lf;
  202.   call charout xf,'NNTP-Posting-Host: localhost'||lf
  203.   call charout xf,'Subject: New groups since '||dateline||lf;
  204.   call charout xf,'Message-Id: <newgroups.'||date('s')||'.'||time('s')||'>'||lf;
  205.   call charout xf,'Date: '||date('n')||' '||time('n')||lf||lf;
  206.   do forever
  207.     line = GetResponse(sock)
  208.     if line = "." then
  209.       leave
  210.     say line
  211.     call charout xf,line||lf
  212.     count = count + 1;
  213.   end
  214. end
  215. call charout xf,lf||lf||'List compiled by '||settings.version||lf
  216. call charout xf,lf||lf
  217. call stream xf,'C','CLOSE'
  218.  
  219. if count>0 then do
  220.   rc = SendMessage(sock,'DATE');
  221.   line = GetResponse(sock);
  222.  
  223.   d = substr(line,7,6);
  224.   t1 = substr(line,13,6);
  225.  
  226.   call lineout DF,d||' '||t1||' GMT',1
  227.   call stream DF,'C','CLOSE'
  228. end
  229.  
  230. rc = SendMessage(sock,'QUIT');
  231. rc = SockSoClose(sock)
  232.  
  233. if count > 0 then do
  234.   size = stream(xf,'C','QUERY SIZE');
  235.  
  236.   yf = SysTempFileName('Y???.TMP')
  237.   call charout yf,'#! rnews '||size||lf
  238.   call stream yf,'C','CLOSE'
  239.  
  240.   'copy/b'||yf||'+'||xf||' 0000000.MSG'
  241.   call lineout AREAS,'0000000'||tab||settings.newsgroup||tab||'un',1
  242.   call stream AREAS,'C','CLOSE';
  243.   'del '||yf;
  244.   if settings.target = "YARN" then do
  245.       'zip -0m soup.zip areas 0000000.msg';
  246.       import = yarn||'\import.exe'
  247.       import 'soup.zip';
  248.   end
  249.   else do /* implies SOUP2SQ */
  250.       'Soup2Sq -r'
  251.   end  /* Do */
  252. end
  253. else
  254.   say 'No new groups'
  255.  
  256. 'del '||xf;
  257. exit 0
  258.  
  259. GetResponse: procedure expose !. closed
  260.   sock = arg(1)
  261.   
  262.   crlf = d2c(13) || d2c(10)
  263.  
  264.   if (symbol('!.buff') = "LIT") then
  265.     !.buff = ""
  266.  
  267.   do while (pos(crlf,!.buff) = 0)
  268.     rc = SockRecv(sock,"data",8000)
  269.     if errno <> 0 then
  270.       do
  271.       closed = 1
  272.       return ""
  273.       end
  274.     !.buff = !.buff || data
  275.   end
  276.  
  277.   p = pos(crlf,!.buff)
  278.  
  279.   line = substr(!.buff,1,p-1)
  280.   !.buff = substr(!.buff,p+2)
  281.  
  282.   return line
  283.  
  284. SendMessage: procedure expose !.
  285.   sock = arg(1)
  286.   data = arg(2) || d2c(13) || d2c(10)
  287.  
  288.   len = length(data)
  289.   do while (len > 0)
  290.     i = SockSend(sock,data)
  291.     if (errno <> 0) then
  292.       Error(-1,rc,"Sending data to server failed")
  293.  
  294.     if (i <= 0) then
  295.       Error(sock,100,"Connection closed by server")
  296.  
  297.     data = substr(data,len+1)
  298.     len  = length(data)
  299.   end
  300.   return 0
  301.  
  302.  
  303. Error: procedure
  304.   sock = arg(1)
  305.   retc = arg(2)
  306.   msg  = arg(3)
  307.  
  308.   if sock <> -1 then
  309.     rc = SockSoClose(sock)
  310.  
  311.   say msg
  312.   exit retc
  313.