home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / iglou.cmd < prev    next >
OS/2 REXX Batch file  |  1996-02-07  |  14KB  |  359 lines

  1. /*--------------------------------------------------------------------------*\
  2. |  IgLouIAK.cmd                                                              |
  3. |                                                                            |
  4. |  PPP Login Script for IgLou and OS/2 Warp Internet Access Kit              |
  5. |                                                                            |
  6. |  Copy this script into C:\TCPIP\BIN. Modify the modem init strings for     |
  7. |  your modem (the strings in the unmodified program are for a U.S. Robotics |
  8. |  Sportster 28.8). In the "Dial Other Provider" program, enter the          |
  9. |  following as your login sequence:                                         |
  10. |                                                                            |
  11. |    iglouiak.cmd atdt968-8228 <userid> <password> 15 25 24000               |
  12. |                                                                            |
  13. |  This gives you 25 redials with a 15-second pause in between attempts.     |
  14. |  If the baud rate when connecting is less than 24000, the program will     |
  15. |  hang up and redial. You can, of course, change the last three numbers.    |
  16. |  Make sure there are no blank lines after this one-line command.           |
  17. |                                                                            |
  18. |  If you have questions about this script, please give me a holler...       |
  19. |  Doug Happel, dhappel@iglou.com or 72772.323@compuserve.com                |
  20. |                                                                            |
  21. |  This program is freeware-- distribute freely                              |
  22. \*--------------------------------------------------------------------------*/
  23.  
  24. PARSE ARG interface, ppp_com, ppp_cmd, dialcmd, userid, password, nRedialPause, nRedials, nMinBaud
  25. SIGNAL ON Syntax
  26.  
  27. /*--------------------------------------------------------------------------*\
  28. |  User-defined constants                                                    |
  29. \*--------------------------------------------------------------------------*/
  30. nMinBaudDefault = 14400
  31. mdm_str. = ''
  32. mdm_str.0 = 2   /* number of modem init strings */
  33. mdm_str.1 = 'ATB0E1F1M3Q0V1X4&A3&B1&C1&D2'
  34. mdm_str.2 = 'AT&H1&I0&K1&M4&N0&R2&S1S0=2'
  35. hangupcmd = 'ATH0'
  36. nBadBaudPause = 3
  37. nRedialPauseDefault = 10
  38. nRedialsDefault = 20
  39. nMdmInitWait = 3
  40. nMdmEscapeWait = 5
  41. nMdmHangupWait = 15
  42.  
  43. /*--------------------------------------------------------------------------*\
  44. |  Constants                                                                 |
  45. \*--------------------------------------------------------------------------*/
  46. cr='0d'x
  47. crlf='0d0a'x
  48. szPrompt_ID = 'gin:'
  49. szPrompt_Password = 'sword:'
  50. szPrompt_Service = 'ice:'
  51. szService = 'PPP'
  52.  
  53. /*--------------------------------------------------------------------------*\
  54. |  Initialization                                                            |
  55. \*--------------------------------------------------------------------------*/
  56. IF RxFuncQuery('SysLoadFuncs') <> 0 THEN DO
  57.   rcy = RxFuncAdd('SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs')
  58.   CALL Sysloadfuncs
  59.   END
  60.   
  61. PARSE SOURCE . . szPgm
  62. szPgm = FileSpec('Name', szPgm)
  63.  
  64. SAY ''
  65. SAY 'IgLou - PPP Connection Script by (c) Doug Happel, 1995',
  66. '(interface' interface')'
  67.  
  68. /*--------------------------------------------------------------------------*\
  69. |  Check for missing information                                             |
  70. \*--------------------------------------------------------------------------*/
  71. IF dialcmd = '' | dialcmd = 'DIALCMD' THEN DO
  72.   SAY szPgm || ': Dial command missing'
  73.   EXIT -1
  74.   END
  75.  
  76. IF userid = '' | userid = '*' | userid = 'USERID' THEN DO
  77.   SAY szPgm || ': Userid missing'
  78.   EXIT -1
  79.   END
  80. ELSE DO
  81.   SAY szPgm || ': Userid:' userid
  82.   END
  83.  
  84. IF password = '' | password = '*' | password = 'PASSWORD' THEN DO
  85.   SAY szPgm || ': Password missing'
  86.   EXIT -1
  87.   END
  88.  
  89. IF nRedialPause = '' | nRedialPause = 'NREDIALPAUSE' THEN
  90.   nRedialPause = nRedialPauseDefault
  91.   
  92. IF nRedials = '' | nRedials = 'NREDIALS' THEN
  93.   nRedials = nRedialsDefault
  94.   
  95. IF nMinBaud = '' | nMinBaud = 'NMINBAUD' THEN
  96.   nMinBaud = nMinBaudDefault
  97.  
  98. /*--------------------------------------------------------------------------*\
  99. |  Flush any stuff left over from previous COM activity                      |
  100. \*--------------------------------------------------------------------------*/
  101. CALL FlushRcvBuf
  102.  
  103. /*--------------------------------------------------------------------------*\
  104. |  Initialize the modem                                                      |
  105. \*--------------------------------------------------------------------------*/
  106. SAY szPgm || ': Initializing Modem...' || crlf
  107. DO i = 1 TO mdm_str.0
  108.   IF mdm_str.i \= '' THEN DO
  109.     CALL Send mdm_str.i || cr
  110.     rsp = WaitFor('OK', nMdmInitWait)
  111.     IF rsp \= 1 THEN DO
  112.       SAY szPgm || ': Modem not responding'
  113.       EXIT -1
  114.       END
  115.     CALL FlushRcvBuf 'echo'
  116.     END
  117.   END i
  118.  
  119. /*--------------------------------------------------------------------------*\
  120. |  Dial the remote server                                                    |
  121. \*--------------------------------------------------------------------------*/
  122. fSuccess = 0
  123. nOrgRedials = nRedials
  124. nRedials = nRedials + 1
  125.  
  126. DO WHILE nRedials > 0
  127.   nRedials = nRedials - 1
  128.   SAY szPgm || ': Dialing...(attempt nr.' nOrgRedials - nRedials + 1 ,
  129.         || ' of' nOrgRedials || ')'
  130.   CALL Send dialcmd || cr
  131.   CALL FlushRcvBuf 'echo'
  132.   rsp = WaitFor_m(2, 'CONNECT' || '00'x || 'BUSY')
  133.   SELECT
  134.     WHEN rsp = 1 THEN DO
  135.       /*
  136.        * We have connected, but make sure baud rate is acceptable.
  137.        */
  138.       baud_buffer = WaitFor_buffer
  139.       CALL WaitFor crlf, 10
  140.       baud_buffer = baud_buffer || WaitFor_buffer
  141.       PARSE VAR baud_buffer . 'CONNECT ' nBaud '/' .
  142.       SAY szPgm || ': Baud Rate is "' || nBaud || '"'
  143.       IF Datatype(nBaud, 'N') = 0 THEN DO
  144.         SAY szPgm || ': Non-numeric Baud Rate "' || nBaud || '".'
  145.         CALL Hangup
  146.         ITERATE
  147.         END
  148.       IF nBaud < nMinBaud THEN DO
  149.         SAY szPgm || ': Unacceptable baud rate.'
  150.         CALL Hangup
  151.         ITERATE
  152.         end
  153.       fSuccess = 1
  154.       LEAVE
  155.       END
  156.     WHEN rsp = 2 THEN DO
  157.       SAY szPgm || ': Busy signal detected-- Redial in' nRedialPause 'seconds'
  158.       CALL SysSleep nRedialPause
  159.       END
  160.     OTHERWISE DO
  161.       SAY szPgm || ': Unable to connect'
  162.       EXIT -1
  163.       END
  164.     END
  165.   END
  166.  
  167. CALL FlushRcvBuf 'echo'
  168.  
  169. IF fSuccess = 0 THEN DO
  170.   SAY szPgm || ': Unable to connect after' nOrgRedials 'attempts'
  171.   EXIT -1
  172.   END
  173.  
  174. /*--------------------------------------------------------------------------*\
  175. |  Negotiate the login with IgLou.                                           |
  176. \*--------------------------------------------------------------------------*/
  177. CALL Send  cr
  178. CALL WaitFor szPrompt_ID
  179. CALL FlushRcvBuf 'echo'
  180. CALL Send userid || cr
  181. CALL WaitFor szPrompt_Password
  182. CALL FlushRcvBuf 'echo'
  183. CALL Send password || cr
  184. CALL FlushRcvBuf 'echo'
  185. CALL WaitFor szPrompt_Service
  186. CALL FlushRcvBuf 'echo'
  187. CALL Send szService || cr
  188. CALL FlushRcvBuf 'echo'
  189.  
  190. /*--------------------------------------------------------------------------*\
  191. |  Clean up and exit                                                         |
  192. \*--------------------------------------------------------------------------*/
  193. EXIT 0
  194.  
  195. /*--------------------------------------------------------------------------*\
  196. |  Send ( sendstring )                                                       |
  197. |                                                                            |
  198. |  Send a string to the host.                                                |
  199. \*--------------------------------------------------------------------------*/
  200. Send:
  201.   PARSE ARG sendstring
  202.   CALL ppp_com_output interface , sendstring
  203.   RETURN
  204.  
  205. /*--------------------------------------------------------------------------*\
  206. |  WaitFor_m ( argcount, args, [timeout] )                                   |
  207. |                                                                            |
  208. |  waits for one of the specified strings to show up in the COM input. All   |
  209. |  input from the time this function is called until one of the strings      |
  210. |  shows up is accumulated in the "WaitFor_buffer" variable.                 |
  211. |                                                                            |
  212. |  the format of the "args" is a single string of all concatenated target    |
  213. |  strings, separated by a single null character.                            |
  214. |                                                                            |
  215. |  If timeout is specified, it says how long to wait if data stops showing   |
  216. |  up on the COM port (in seconds).                                          |
  217. |                                                                            |
  218. |  RETURNS: index of the string that was matched, or zero if no match.       |
  219. \*--------------------------------------------------------------------------*/
  220. WaitFor_m:
  221.  
  222.   PARSE ARG argcount, waitstring , timeout
  223.   match = 0
  224.   
  225.   /*
  226.    *  Pick off each target string
  227.    */
  228.   wf_idx = 1
  229.   DO WHILE wf_idx < argcount
  230.     PARSE VAR waitstring waits.wf_idx '00'x waitstring
  231.     wf_idx = wf_idx + 1
  232.     END
  233.   waits.wf_idx = waitstring
  234.   waits.0 = wf_idx
  235.   
  236.   IF timeout = '' THEN
  237.     timeout = 5000    /* L O N G   delay IF not specified */
  238.     
  239.   WaitFor_buffer = ''
  240.   done = -1
  241.   curpos = 1
  242.   ORI_TIME=TIME('E')
  243.     
  244.   IF (remain_buffer = 'REMAIN_BUFFER') THEN DO
  245.     remain_buffer = ''
  246.     END
  247.   
  248.   DO WHILE (done = -1)
  249.     IF (remain_buffer \= '') THEN DO
  250.       line = remain_buffer
  251.       remain_buffer = ''
  252.       END
  253.     ELSE DO
  254.       line = ppp_com_input(interface,,10)
  255.       END
  256.     WaitFor_buffer = WaitFor_buffer || line
  257.     DO wf_idx = 1 TO waits.0
  258.       index = Pos(waits.wf_idx, WaitFor_buffer)
  259.       IF index > 0 THEN DO
  260.         match = wf_idx
  261.         LEAVE
  262.         END
  263.       END
  264.     IF (index > 0) THEN DO
  265.       remain_buffer = substr(WaitFor_buffer,index+length(waits.match))
  266.       WaitFor_buffer = delstr(WaitFor_buffer,index+length(waits.match))
  267.       done = 0
  268.       END
  269.     CALL charout , substr(WaitFor_buffer,curpos)
  270.     x_val = '[' || C2X(substr(WaitFor_buffer,curpos)) || ']'
  271.     curpos = length(WaitFor_buffer)+1
  272.     IF ((done \= 0) & (TIME('E')>timeout)) THEN DO
  273.       SAY szPgm || ': Timeout waiting for text'
  274.       match = 0
  275.       done = 0
  276.       END
  277.     END
  278.   
  279.   timeout=0
  280.   RC=match
  281.   RETURN RC
  282.  
  283. /*--------------------------------------------------------------------------*\
  284. |  WaitFor ( waitstring, [timeout] )                                         |
  285. |                                                                            |
  286. |  Shorthand call to wait for a single string. Just calls WaitFor_m.         |
  287. \*--------------------------------------------------------------------------*/
  288. WaitFor:
  289.   PARSE ARG waitstring , timeout
  290.   rc2 = WaitFor_m(1, waitstring, timeout)
  291.   RETURN rc2
  292.  
  293. /*--------------------------------------------------------------------------*\
  294. |  FlushRcvBuf ()                                                            |
  295. |                                                                            |
  296. |  Routine to flush any pending characters to be read from the COM port.     |
  297. |  Reads everything it can until nothing new shows up for 100ms, at which    |
  298. |  point it returns.                                                         |
  299. |                                                                            |
  300. |  The optional echo argument, if 1, says to echo flushed information.       |
  301. \*--------------------------------------------------------------------------*/
  302. FlushRcvBuf:
  303.   PARSE ARG echo
  304.   /*
  305.    *  If echo requested, display contents of WaitFor buffer.
  306.    */
  307.   IF (echo \= '') & (length(remain_buffer) > 0) THEN DO
  308.     CALL charout , remain_buffer
  309.     remain_buffer = ''
  310.     END
  311.   /*
  312.    *  Eat anything left in the modem or COM buffers. Stop when nothing new
  313.    *  appears for 100 ms.
  314.    */
  315.   DO UNTIL line = ''
  316.     line = ppp_com_input(interface,,100)
  317.     IF echo \= '' THEN
  318.       CALL charout , line
  319.     END
  320.     
  321.   RETURN
  322.  
  323. /*--------------------------------------------------------------------------*\
  324. |  Hangup ()                                                                 |
  325. |                                                                            |
  326. |  Hang up after connection made with host.                                  |
  327. \*--------------------------------------------------------------------------*/
  328. Hangup:
  329.   CALL Send '+++'
  330.   rsp = WaitFor('OK', nMdmEscapeWait)
  331.   CALL FlushRcvBuf 'echo'
  332.   IF rsp \= 1 THEN DO
  333.     SAY szPgm || ': Modem escape failure'
  334.     EXIT -1
  335.     END
  336.   CALL send hangupcmd || cr
  337.   rsp = WaitFor('OK', nMdmHangupWait)
  338.   CALL FlushRcvBuf 'echo'
  339.   IF rsp \= 1 THEN DO
  340.     SAY szPgm || ': Modem hangup failure'
  341.     EXIT -1
  342.     END
  343.   SAY szPgm || ': Connection terminated-- Redial in' nBadBaudPause 'seconds'
  344.   CALL SysSleep nBadBaudPause
  345.   RETURN
  346.  
  347. /*--------------------------------------------------------------------------*\
  348. |  Syntax ()                                                                 |
  349. |                                                                            |
  350. |  Routine to trap syntax errors.                                            |
  351. \*--------------------------------------------------------------------------*/
  352. Syntax:
  353.   err = rc
  354.   SAY szPgm || ': Syntax error on line' sigl || ':'
  355.   SAY SourceLine(sigl)
  356.   SAY ErrorText(err)
  357.   EXIT -1
  358.  
  359.