home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / DATACOM / INTERNET / IAK-DDS / BIN / DDS.CMD
Encoding:
Text File  |  1995-02-05  |  13.0 KB  |  307 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*        OS/2 2.1 / WARP REX Driver for IBM TCP/IP version 2.0 / IAK       */
  4. /*                                                                          */
  5. /*                                ANNEX.CMD                                 */
  6. /*                                                                          */
  7. /*            ..................................................            */
  8. /*                                                                          */
  9. /* Sample attachment script for dialing into a Xylogics Annex terminal      */
  10. /* server in order to establish a SLIP connection.  This script should be   */
  11. /* specified on page 1 in the Login Script field for connections via SlipPM */
  12. /* or using the -connect option if executing slip directly.                 */
  13. /*                                                                          */
  14. /*        NOTE: This file is supplied as a sample connection script, and    */
  15. /*              does not constitute the endorsement of a particular         */
  16. /*              Internet provider on the part of IBM.                       */
  17. /*              Internet providers periodically change their connection     */
  18. /*              procedures; please refer to the latest information provided */
  19. /*              by the service provider.                                    */
  20. /*                                                                          */
  21. /*              This script may be modified to suit the needs of the user   */
  22. /*              and is written to process dialogs similar to those          */
  23. /*              used by many Annex type service providers.                  */
  24. /*                                                                          */
  25. /* The script parameters specify the command to send to the modem to dial   */
  26. /* the remote site and the username/password combination to use to log into */
  27. /* the terminal server.  If any of the parameters are omitted, or are       */
  28. /* specified as an asterix (*), the script will prompt for them (Refer      */
  29. /* to caveate below).  This is most useful with the password parameter to   */
  30. /* avoid storing the password in a text file on the disk.                   */
  31. /*                                                                          */
  32. /* For example, the following might be used in SlipPM:                      */
  33. /*              Login Script: annex.cmd atdt999-9999 loginid password       */
  34. /*                                                                          */
  35. /* which would then feed the "atdt999-9999" command to the modem, followed  */
  36. /* by the login id and password once the connection is established.         */
  37. /*                                                                          */
  38. /* From slip directly the annex script supports:                            */
  39. /*              -connect "dds.cmd atdt999-9999 loginid *"                   */
  40. /*                                                                          */
  41. /* which would cause dds.cmd to initially prompt for the password. It       */
  42. /* would then feed the "atdt999-9999" command to the modem, and when the    */
  43. /* Annex answered, it would use "loginid" as a username and the password    */
  44. /* specified.                                                               */
  45. /*                                                                          */
  46. /* NOTE: You must pass the phone number, and both login id and password     */
  47. /*       to dds.cmd from the Dialer.  The Dialer will NOT allow for the     */
  48. /*       input of a phone number, login or password from the keyboard.      */
  49. /*            - - - - - - - - - - - - - - - - - - - - - - - - -             */
  50. /*                                                                          */
  51. /* When the script runs, it is automatically passed the interface name for  */
  52. /* the interface it is running on as the first argument, followed by the    */
  53. /* user arguments.                                                          */
  54. /*                                                                          */
  55. /* The script sends the dial string to the modem and then logs into the     */
  56. /* terminal server using the username/password.  It then issues the SLIP    */
  57. /* command to start SLIP, and parses the resulting output to determine the  */
  58. /* appropriate addresses to use.  Lastly, it issues ifconfig and route      */
  59. /* commands to configure the OS/2 system appropriately.  Note that the      */
  60. /* configuration assumes a class C netmask for the SLIP interface.          */
  61. /*                                                                          */
  62. /*--------------------------------------------------------------------------*/
  63.  
  64. parse arg interface , dialcmd username password
  65.  
  66. /*--------------------------------------------------------------------------*/
  67. /*                   Initialization and Main Script Code                    */
  68. /*--------------------------------------------------------------------------*/
  69.  
  70. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  71. call SysLoadFuncs
  72.  
  73. /* enable this when using SIO */
  74. 'mode com1,dtr=on'
  75.  
  76. /* Set some definitions for easier COM strings */
  77. cr='0d'x
  78. crlf='0d0a'x
  79.  
  80. say ''
  81. say 'dds.nl - SLIP ANNEX Connection Script ',
  82.     '(interface' interface')'
  83.  
  84. /* Prompt for missing information */
  85. if dialcmd = '' then do
  86.    call charout , 'Dial Command: '
  87.    parse pull dialcmd
  88. end
  89. if username = '' | username = '*' then do
  90.    call charout , 'User Name: '
  91.    parse pull username
  92. end
  93. else do
  94.    say 'User:' username
  95. end
  96. if password = '' | password = '*' then do
  97.    call charout , 'Password: '
  98.    password = readpass()
  99. end
  100.  
  101. /* Flush any stuff left over from previous COM activity */
  102. call flush_receive
  103.  
  104. /* Reset the modem here */
  105. /* You may need to customize this for your modem make and model */
  106. call lineout , 'Reset modem...'
  107. call send 'ATZ' || cr
  108. call waitfor 'OK', 5 ; call flush_receive 'echo'
  109.  if RC = 1 then do
  110.     call lineout , 'Modem not resetting... Trying again'
  111.     call send '+++'
  112.     call waitfor 'OK'
  113.     call send 'ATHZ' || cr
  114.     call waitfor 'OK', 3
  115.   end
  116.  
  117. retry:
  118. /* Dial the remote server */
  119. call charout, 'Now Dialing: '
  120. call send dialcmd || cr
  121.  
  122. /* Wait for connection */
  123. RC = waitfor('CONNECT', 60)
  124.  
  125. /* act on no connect, i.e. infinite 10 second loop */
  126. if (RC = 2) then
  127.   do
  128.     call SysSleep(10)
  129.     signal retry
  130.   end
  131.  
  132. /* handle rest of failures, i.e. time-outs */
  133. if (RC > 0) then
  134.   do
  135.     say 'Connect: TIMED OUT'
  136.     exit 1
  137.   end
  138.  
  139. /* Handle login.  We wait for standard strings, and then flush anything */
  140. /* else to take care of trailing spaces, etc..                          */
  141. /* call send cr */
  142. call waitfor 'login:' ; call flush_receive 'echo'
  143. call send 'slip' || cr
  144. call waitfor 'sliplogin:' ; call flush_receive 'echo'
  145. call send username || cr
  146. call waitfor 'Password:' ; call flush_receive 'echo'
  147. call send password || cr
  148.  
  149. /* Parse the results of the SLIP command to determine our address. */
  150. /* We use the "waitfor_buffer" variable from the waitfor routine   */
  151. /* to parse the stuff we get from the Annex after waiting for an   */
  152. /* appropriate point in the data stream.                           */
  153. call waitfor 'SMTP server:' 
  154. parse var waitfor_buffer . 'slip for address ' a '.' b '.' c '.' d .
  155. os2_address = a||'.'||b||'.'||c||'.'||d
  156. parse var waitfor_buffer . 'Gateway: ' a '.' b '.' c '.' d .
  157. annex_address = a||'.'||b||'.'||c||'.'||d
  158.  
  159. /* Flush anything else */
  160. call flush_receive 'echo'
  161.  
  162. /* Now configure this host for the appropriate address, */
  163. /* and for a default route through the Annex.           */
  164.  
  165. say 'SLIP Connection Established'
  166. say 'Configuring local address =' os2_address ', Annex =' annex_address
  167.  
  168. 'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
  169. 'route -f add default' annex_address '1'
  170. 'copy %etc%\RESOLV.dds %etc%\*.'
  171.  
  172. /* All done */
  173. exit 0
  174.  
  175.  
  176. /*--------------------------------------------------------------------------*/
  177. /*                            send ( sendstring)                            */
  178. /*..........................................................................*/
  179. /*                                                                          */
  180. /* Routine to send a character string off to the modem.                     */
  181. /*                                                                          */
  182. /*--------------------------------------------------------------------------*/
  183.  
  184. send:
  185.  
  186.    parse arg sendstring
  187.    call slip_com_output interface , sendstring
  188.  
  189.    return
  190.  
  191.  
  192. /*--------------------------------------------------------------------------*/
  193. /*                    waitfor ( waitstring , [timeout] )                    */
  194. /*..........................................................................*/
  195. /*                                                                          */
  196. /* Waits for the supplied string to show up in the COM input.  All input    */
  197. /* from the time this function is called until the string shows up in the   */
  198. /* input is accumulated in the "waitfor_buffer" variable.                   */
  199. /*                                                                          */
  200. /* If timeout is specified, it says how long to wait if data stops showing  */
  201. /* up on the COM port (in seconds).                                                         */
  202. /*                                                                          */
  203. /*--------------------------------------------------------------------------*/
  204.  
  205. waitfor:
  206.  
  207.    parse arg waitstring , timeout
  208.  
  209.    if timeout = '' then
  210.      timeout = 5000    /* L O N G   delay if not specified */
  211.    waitfor_buffer = '' ; done = -1; curpos = 1
  212.    ORI_TIME=TIME('E')
  213.  
  214.    if (remain_buffer = 'REMAIN_BUFFER') then do
  215.       remain_buffer = ''
  216.    end
  217.  
  218.    do while (done = -1)
  219.       if (remain_buffer \= '') then do
  220.          line = remain_buffer
  221.          remain_buffer = ''
  222.        end
  223.        else do
  224.          line = slip_com_input(interface,,10)
  225.       end
  226.       waitfor_buffer = waitfor_buffer || line
  227.  
  228.       if (pos('NO CARRIER',waitfor_buffer) > 0) | (pos('BUSY',waitfor_buffer) > 0) then do
  229.         call charout , substr(waitfor_buffer,curpos) 
  230.         RC = 2
  231.         return RC
  232.       end
  233.  
  234.       index = pos(waitstring,waitfor_buffer)
  235.       if (index > 0) then do
  236.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  237.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  238.          done = 0
  239.       end
  240.       call charout , substr(waitfor_buffer,curpos) 
  241.       curpos = length(waitfor_buffer)+1
  242.       if ((done \= 0) & (TIME('E')>timeout)) then do
  243.         call lineout , ' WAITFOR: timed out '
  244.         done = 1
  245.        end
  246.    end
  247.    timeout=0
  248.    RC=done
  249.  return RC
  250.  
  251.  
  252.  
  253. /*--------------------------------------------------------------------------*/
  254. /*                               readpass ()                                */
  255. /*..........................................................................*/
  256. /*                                                                          */
  257. /* Routine used to read a password from the user without echoing the        */
  258. /* password to the screen.                                                  */
  259. /*                                                                          */
  260. /*--------------------------------------------------------------------------*/
  261.  
  262. readpass:
  263.  
  264.   answer = ''
  265.   do until key = cr
  266.     key = slip_getch()
  267.     if key \= cr then do
  268.       answer = answer || key
  269.     end
  270.   end
  271.   say ''
  272.   return answer
  273.  
  274.  
  275. /*--------------------------------------------------------------------------*/
  276. /*                             flush_receive ()                             */
  277. /*..........................................................................*/
  278. /*                                                                          */
  279. /* Routine to flush any pending characters to be read from the COM port.    */
  280. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  281. /* point it returns.                                                        */
  282. /*                                                                          */
  283. /* The optional echo argument, if 1, says to echo flushed information.      */
  284. /*                                                                          */
  285. /*--------------------------------------------------------------------------*/
  286.  
  287. flush_receive:
  288.  
  289.    parse arg echo
  290.  
  291.    /* If echoing the flush - take care of waitfor remaining buffer */
  292.    if (echo \= '') & (length(remain_buffer) > 0) then do
  293.       call charout , remain_buffer
  294.       remain_buffer = ''
  295.    end
  296.  
  297.    /* Eat anything left in the modem or COM buffers */
  298.    /* Stop when nothing new appears for 100ms.      */
  299.  
  300.    do until line = ''
  301.      line = slip_com_input(interface,,100)
  302.      if echo \= '' then
  303.         call charout , line
  304.    end
  305.  
  306.    return
  307.