home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / snpprexx.zip / SNPP.CMD
OS/2 REXX Batch file  |  2002-03-30  |  8KB  |  298 lines

  1. /*------------------------------------------------------------------
  2.  * SNPP Client. Autor unknown, modified by Igor Vaskov 2:5020/207.27.
  3.  * Usage: SNPP.CMD <IP_SNPPSERVER> <USERID> <PASSWORD> <PAGERID> <MESSAGE>
  4.  * Example:
  5.  * SNPP.CMD 127.0.0.1 userid password 12 Hello World.
  6. --------------------------------------------------------------------*/
  7. /*pull*/
  8. TimeOut=60
  9. port = 444
  10. userid = "userid"
  11. password = "password"
  12. Cove = "128"
  13. debug=0
  14. log_file="snpp_out.log"
  15. dt=DATE('S')
  16. tm=TIME('N')
  17.  
  18. koi_itable=' !""#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~└┴┬├─┼╞╟╚╔╩╦╠══╧╨╤╥╙╘╒╓╫╪┘┌H▄▌▐▀                ░▒▓│┤╡╢╖╕╣║╗╝╜╛┐εáíµñÑΣúσ¿⌐¬½¼¡«»∩pßΓπªó∞δºΦφΘτΩ₧ÇüûäàöâòêëèïîHÄŃÉæÆôå飢çÿ¥ÖùÜ'
  19. koi_otable=' !""#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ '
  20. endl='0D'x'0A'x
  21.  
  22. parse arg server userid password pager mess
  23.  
  24. log_buf=dt tm server pager length(mess) mess
  25. mess=TRANSLATE(mess,koi_otable,koi_itable) /* óßÑ ñ«½ª¡« íδΓ∞ ó ¬«¿-8 */
  26.  
  27. /*------------------------------------------------------------------
  28.  * initialize socket package
  29.  *------------------------------------------------------------------*/
  30.    if RxFuncQuery("SockLoadFuncs") then
  31.       do
  32.       rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  33.       rc = SockLoadFuncs()
  34.       end
  35. /*------------------------------------------------------------------
  36.  * get server name
  37.  *------------------------------------------------------------------*/
  38.    rc = SockGetHostByName(server,"host.!")
  39.    if (rc = 0) then
  40.         do
  41.         say "Error" h_errno "calling SockGetHostByName("server")"
  42.         call log_store 'Error 'h_errno
  43.         exit
  44.         end
  45.  
  46.    server = host.!addr;
  47.  
  48. /*---------------------------------------------------------------
  49.  * open socket
  50.  *---------------------------------------------------------------*/
  51. socket  = SockSocket("AF_INET","SOCK_STREAM",0)
  52. if (socket = -1) then
  53.         do
  54.         say "Error on SockSocket:" errno
  55.         call log_store errno
  56.         exit
  57.         end
  58.  
  59. /*------------------------------------------------------------------
  60.  * catch breaks
  61.  *------------------------------------------------------------------*/
  62. signal on halt
  63.  
  64. /*---------------------------------------------------------------
  65.  * connect socket
  66.  *---------------------------------------------------------------*/
  67. server.!family = "AF_INET"
  68. server.!port   = port
  69. server.!addr   = server
  70. if debug=1 then say 'Connect ------>>'
  71. rc = SockConnect(socket,"server.!")
  72. if (rc = -1) then
  73.    do
  74.    call log_store errno h_errno
  75.    say "Error on SockConnect:" errno h_errno
  76.    exit
  77.    end
  78.  
  79. /*------------------------------------------------------------------
  80.  * receive the result from the server
  81.  *------------------------------------------------------------------*/
  82. rc = snpp_get("newData")
  83. if (rc = -1) then
  84.    do
  85.         call log_store errno
  86.    say "Error on SockRecv:" errno
  87.    exit
  88.    end
  89. newData=STRIP(newData,L,'0d'x)
  90. newData=STRIP(newData,L,'0a'x)
  91. newData=STRIP(newData,L,'0d'x)
  92. if debug=1 then say '<<----'newData
  93. if substr(newData,1,3)<>220 then
  94.         do
  95.         call log_store newData
  96.         rc=snpp_close()
  97.         exit
  98.         end
  99.  
  100. /*------------------------------------------------------------------
  101.  * send the login/password
  102.  *------------------------------------------------------------------*/
  103. if debug=1 then say 'Userid/password ------->>'
  104. rc = SockSend(socket,'LOGI 'userid' 'password''endl)
  105. if (rc = -1) then
  106.    do
  107.         call log_store errno
  108.    say "Error on SockSend:" errno
  109.    exit
  110.    end
  111. rc = snpp_get("newData")
  112. newData=STRIP(newData,L,'0d'x)
  113. newData=STRIP(newData,L,'0a'x)
  114. newData=STRIP(newData,L,'0d'x)
  115.  
  116. if debug=1 then say '<<----'newData
  117. if substr(newData,1,3)<>250 then
  118.         do
  119.         call log_store newData
  120.         rc=snpp_close()
  121.         exit
  122.         end
  123.  
  124. /*------------------------------------------------------------------
  125.  * send the coverage
  126.  *------------------------------------------------------------------*/
  127. if debug=1 then say 'COVERAGE ------->>'
  128. rc = SockSend(socket,'COVE 'cove''endl)
  129. if (rc = -1) then
  130.    do
  131.         call log_store errno
  132.    say "Error on SockSend:" errno
  133.    exit
  134.    end
  135. rc = snpp_get("newData")
  136. newData=STRIP(newData,L,'0d'x)
  137. newData=STRIP(newData,L,'0a'x)
  138. newData=STRIP(newData,L,'0d'x)
  139.  
  140. if debug=1 then say '<<----'newData
  141. if substr(newData,1,3)<>250 then
  142.         do
  143.         call log_store newData
  144.         rc=snpp_close()
  145.         exit
  146.         end
  147.  
  148. /*------------------------------------------------------------------
  149.  * send the pagerid
  150.  *------------------------------------------------------------------*/
  151. if debug=1 then say 'Pager ID ------->>'
  152. rc = SockSend(socket,'PAGE 'pager''endl)
  153. if (rc = -1) then
  154.    do
  155.         call log_store errno
  156.    say "Error on SockSend:" errno
  157.    exit
  158.    end
  159. rc = snpp_get("newData")
  160. newData=STRIP(newData,L,'0d'x)
  161. newData=STRIP(newData,L,'0a'x)
  162. newData=STRIP(newData,L,'0d'x)
  163.  
  164. if debug=1 then say '<<----'newData
  165. if substr(newData,1,3)<>250 then
  166.         do
  167.         call log_store newData
  168.         rc=snpp_close()
  169.         exit
  170.         end
  171.  
  172.  
  173. /*------------------------------------------------------------------
  174.  * send mess
  175.  *------------------------------------------------------------------*/
  176. if debug=1 then say 'Mess ------->>'
  177. rc = SockSend(socket,'MESS 'mess''endl)
  178. if (rc = -1) then
  179.    do
  180.         call log_store errno
  181.    say "Error on SockSend:" errno
  182.    exit
  183.    end
  184.  
  185. rc = snpp_get("newData")
  186. newData=STRIP(newData,L,'0d'x)
  187. newData=STRIP(newData,L,'0a'x)
  188. newData=STRIP(newData,L,'0d'x)
  189.  
  190. if debug=1 then say '<<----'newData
  191. if substr(newData,1,3)<>250 then
  192.         do
  193.         call log_store newData
  194.         rc=snpp_close()
  195.         exit
  196.         end
  197.  
  198. /*------------------------------------------------------------------
  199. * send SEND
  200.  *------------------------------------------------------------------*/
  201. if debug=1 then say 'Send ------->>'
  202. rc = SockSend(socket,'SEND 'endl)
  203. if (rc = -1) then
  204.    do
  205.         call log_store errno
  206.    say "Error on SockSend:" errno
  207.    exit
  208.    end
  209.  
  210. rc = snpp_get("newData")
  211. newData=STRIP(newData,L,'0d'x)
  212. newData=STRIP(newData,L,'0a'x)
  213. newData=STRIP(newData,L,'0d'x)
  214.  
  215. if debug=1 then say '<<----'newData
  216. if substr(newData,1,3)<>250 then
  217.         do
  218.         call log_store newData
  219.         rc=snpp_close()
  220.         exit
  221.         end
  222. /*------------------------------------------------------------------
  223. * send QUIT
  224.  *------------------------------------------------------------------*/
  225. if debug=1 then say 'Quit ------->>'
  226. rc = SockSend(socket,'QUIT 'endl)
  227. if (rc = -1) then
  228.    do
  229.         call log_store errno
  230.    say "Error on SockSend:" errno
  231.    exit
  232.    end
  233.  
  234. rc = snpp_get("newData")
  235. newData=STRIP(newData,L,'0d'x)
  236. newData=STRIP(newData,L,'0a'x)
  237. newData=STRIP(newData,L,'0d'x)
  238.  
  239. if debug=1 then say '<<----'newData
  240. if substr(newData,1,3)<>250 then
  241.         do
  242.         call log_store newData
  243.         rc=snpp_close()
  244.         exit
  245.         end
  246.  
  247. call log_store 'OK'
  248. rc = SockSoClose(socket)
  249. exit
  250. /*------------------------------------------------------------------
  251.  * close socket (and catch signals)
  252.  *------------------------------------------------------------------*/
  253.  
  254. halt:
  255.  
  256. rc = SockSoClose(socket)
  257. if (rc = -1) then
  258.    do
  259.    say "Error on SockSoClose:" errno
  260.    exit
  261.    end
  262.  
  263. exit
  264.  
  265. snpp_get:
  266. arg rcbuf
  267. rc=0
  268. elapsed=0
  269. tm=time('r')
  270. DO WHILE rc<3 | elapsed > TimeOut
  271. if debug=1 then say recieved loop
  272. rc = SockRecv(socket,rcbuf,256)
  273. if (rc = -1) then
  274.    do
  275.    say "Error on SockRecv:" errno
  276.    rc = SockSoClose(socket)
  277.    exit
  278.    end
  279. elapsed=time('e')
  280. END
  281. if (rc = 0) then
  282.    do
  283.    say "TimeOut on SockRecv"
  284.    rc = SockSoClose(socket)
  285.    exit
  286.    end
  287.  
  288. return rc
  289. snpp_close:
  290. rc = SockSend(socket,'QUIT 'endl)
  291. rc = SockSoClose(socket)
  292. return 0
  293.  
  294. log_store:
  295. arg note
  296. call lineout log_file, log_buf note
  297. call lineout log_file
  298. return 0