home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sliphw.zip / homecli.cmd < prev    next >
OS/2 REXX Batch file  |  1995-10-02  |  10KB  |  275 lines

  1. /* HOMECLI.CMD
  2. Connects to work SLIP server. Handles login and routing.
  3. Put this file in \TCPIP\BIN on the home machine.
  4. This file is called from HOMECLI.CFG, which is called from HOMECLID.CMD
  5.  
  6. Configuration: set the Rexx variables below:
  7. */
  8. /* Serial Port Configuration and modem strings */
  9. modeminit     = 'AT&F2'        /* modem init command */
  10. modemsetparms = 'ATL1M'        /* speaker low volume */
  11. modemreset    = 'ATZ'           /* modem reset string */
  12. phonenumber   = '4991111'       /* number of work SLIP server */
  13.  
  14. /* Internet addresses, machine names */
  15. ipaddress  = '199.99.99.99'     /* Home PC's IP address for sl0 interface */
  16. gateway    = '199.99.99.88'     /* Work PC's IP address for sl0 interface */
  17. netmask    = '255.255.255.0'
  18. /* The parms below are only used if the Home machine is on a Home Ethernet */
  19. desthostname = 'workmachine'       /* Work PC's name. Must be known to DNS */
  20. macaddress   = '00:00:c0:55:66:77:88' /* Home PC's hardware MAC address       */
  21.  
  22. /* Users */
  23. username = 'yourname'        /* ID for logging into Work machine */
  24. password = 'secret'        /* PW for logging into Work machine */
  25.  
  26. /* If Home machine is on a Home Ethernet, change Ethercard='F' to Ethercard='T'.*/
  27. Ethercard = 'F'         /* NO Home Ethernet */
  28.  
  29. /* Sounds play when connect */
  30. playsounds = '1'           /* set to '0' if no sound card      */
  31. wavdir       = 'k:\mm\wav\'          /* where *.WAV files are kept       */
  32. wavconnect = wavdir'wild4.wav'       /* wave file to play when connected */
  33. wavinit    = wavdir'drumroll.wav'  /* wave file to play when starting  */
  34.  
  35. /****************************************************************************/
  36.  
  37. /* Define routines for errorhandling */
  38. signal on error name errorhandler
  39. signal on failure name errorhandler
  40. signal on halt name errorhandler
  41. /* signal on novalue name errorhandler */
  42. signal on syntax name errorhandler
  43. signal on notready name errorhandler
  44.  
  45. /* Load RexxUtility functions */
  46. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  47. call SysLoadFuncs
  48.  
  49. parse arg interface
  50.  
  51. /*--------------------------------------------------------------------------*/
  52. /*                   Initialization and Main Script Code                    */
  53. /*--------------------------------------------------------------------------*/
  54.  
  55. dialcmd = 'atdt'phonenumber
  56. say 'Dial command is:' dialcmd
  57. try=0
  58.  
  59. /* Set some definitions for easier COM strings */
  60. cr='0d'x
  61. crlf='0d0a'x
  62.  
  63. say ''
  64. say 'OS/2 SLIP Client (interface' interface')'
  65.  
  66. goback:
  67.  
  68. /* Flush any stuff left over from previous COM activity */
  69. call flush_receive
  70. if playsounds='1' then 'start /min/c play file='wavinit
  71.  
  72.  
  73. /* Reset the modem here */
  74. /* You may need to customize this for your modem make and model */
  75. call lineout , 'Resetting modem...'
  76. call send modeminit || cr
  77. call waitfor 'OK', 5 ; call flush_receive 'echo'
  78. call send modemsetparms || cr
  79. call waitfor 'OK', 5 ; call flush_receive 'echo'
  80.  if RC = 1 then do
  81.     call lineout , 'Modem not resetting... Trying again'
  82.     call send '+++'
  83.     call waitfor 'OK',3
  84.     call send modemreset || cr
  85.     call waitfor 'OK', 3
  86.   end
  87.  
  88. tryagain:
  89.  
  90. /* Dial the remote server */
  91. try=try+1
  92. call charout , try' Dialing...   '
  93.  
  94. call send dialcmd || cr
  95. call waitfor 'BUSY', 12
  96.  
  97. if(RC > 0) then do
  98.    say 'Possible Connection' || cr
  99.    signal GoOn
  100. end
  101. call SysSleep(3)
  102. say cr
  103. signal TryAgain
  104.  
  105. GoOn:
  106. /* Handle login.  We wait for standard strings, and then flush anything */
  107. /* else to take care of trailing spaces, etc..                          */
  108. /* call send cr */
  109. call waitfor 'User:',70 ; call flush_receive 'echo'
  110.  if RC = 1 then do
  111.     call lineout , 'Server not responding... Trying again'
  112.     signal TryAgain
  113.   end
  114. call send username || cr
  115. call waitfor 'Password:' ; call flush_receive 'echo'
  116. call send password || cr
  117. say ''
  118.  
  119. /* Now configure this machine for the appropriate address, */
  120. 'ifconfig sl0' ipaddress gateway 'netmask 'netmask
  121. 'route add default 'gateway' 1'
  122.  
  123. /* If Home machine is on a Home Ethernet, proxy arp handles packets going to Work machine */
  124. if Ethercard='T' then
  125.    'arp -s 'desthostname macaddress 'pub'
  126.  
  127. say 'IP address: 'ipaddress
  128. say 'gateway: 'gateway
  129.  
  130. /* Play a tune to indicate connection is established */
  131. if playsounds='1' then 'start /min/c play file='wavconnect
  132.  
  133. /* All done */
  134. exit 0
  135.  
  136. /*--------------------------------------------------------------------------*/
  137.  
  138. /* Errorhandler */
  139. errorhandler:
  140. say copies('=',79)
  141. say 'ERROR OCCURED:'
  142. say '   Condition:' condition('c')
  143. say '   Instruction:' condition('i')
  144. say '   Description:' condition('d')
  145. say '   Status:' condition('s')
  146. say '   Line:' sigl
  147. say copies('=',79)
  148. return 0
  149.  
  150. /*--------------------------------------------------------------------------*/
  151. /*                            send ( sendstring)                            */
  152. /*..........................................................................*/
  153. /*                                                                          */
  154. /* Routine to send a character string off to the modem.                     */
  155. /*                                                                          */
  156. /*--------------------------------------------------------------------------*/
  157.  
  158. send:
  159.  
  160.    parse arg sendstring
  161.    call slip_com_output interface , sendstring
  162.  
  163.    return
  164.  
  165.  
  166. /*--------------------------------------------------------------------------*/
  167. /*                    waitfor ( waitstring , [timeout] )                    */
  168. /*..........................................................................*/
  169. /*                                                                          */
  170. /* Waits for the supplied string to show up in the COM input.  All input    */
  171. /* from the time this function is called until the string shows up in the   */
  172. /* input is accumulated in the "waitfor_buffer" variable.                   */
  173. /*                                                                          */
  174. /* If timeout is specified, it says how long to wait if data stops showing  */
  175. /* up on the COM port (in seconds).                                         */
  176. /*                                                                          */
  177. /*--------------------------------------------------------------------------*/
  178.  
  179. waitfor:
  180.  
  181.    parse arg waitstring , timeout
  182.  
  183.    if timeout = '' then
  184.      timeout = 5000    /* L O N G   delay if not specified */
  185.    waitfor_buffer = '' ; done = -1; curpos = 1
  186.    ORI_TIME=TIME('E')
  187.  
  188.    if (remain_buffer = 'REMAIN_BUFFER') then do
  189.       remain_buffer = ''
  190.    end
  191.  
  192.    do while (done = -1)
  193.       if (remain_buffer \= '') then do
  194.          line = remain_buffer
  195.          remain_buffer = ''
  196.        end
  197.        else do
  198.          line = slip_com_input(interface,,10)
  199.       end
  200.       waitfor_buffer = waitfor_buffer || line
  201.       index = pos(waitstring,waitfor_buffer)
  202.       if (index > 0) then do
  203.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  204.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  205.          done = 0
  206.       end
  207.       call charout , substr(waitfor_buffer,curpos)
  208.       curpos = length(waitfor_buffer)+1
  209.       if ((done \= 0) & (TIME('E')>timeout)) then do
  210.         call lineout , ' WAITFOR: timed out '
  211.         done = 1
  212.        end
  213.    end
  214.    timeout=0
  215.    RC=done
  216.  return RC
  217.  
  218.  
  219.  
  220. /*--------------------------------------------------------------------------*/
  221. /*                               readpass ()                                */
  222. /*..........................................................................*/
  223. /*                                                                          */
  224. /* Routine used to read a password from the user without echoing the        */
  225. /* password to the screen.                                                  */
  226. /*                                                                          */
  227. /*--------------------------------------------------------------------------*/
  228.  
  229. readpass:
  230.  
  231.   answer = ''
  232.   do until key = cr
  233.     key = slip_getch()
  234.     if key \= cr then do
  235.       answer = answer || key
  236.     end
  237.   end
  238.   say ''
  239.   return answer
  240.  
  241.  
  242. /*--------------------------------------------------------------------------*/
  243. /*                             flush_receive ()                             */
  244. /*..........................................................................*/
  245. /*                                                                          */
  246. /* Routine to flush any pending characters to be read from the COM port.    */
  247. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  248. /* point it returns.                                                        */
  249. /*                                                                          */
  250. /* The optional echo argument, if 1, says to echo flushed information.      */
  251. /*                                                                          */
  252. /*--------------------------------------------------------------------------*/
  253.  
  254. flush_receive:
  255.  
  256.    parse arg echo
  257.  
  258.    /* If echoing the flush - take care of waitfor remaining buffer */
  259.    if (echo \= '') & (length(remain_buffer) > 0) then do
  260.       call charout , remain_buffer
  261.       remain_buffer = ''
  262.    end
  263.  
  264.    /* Eat anything left in the modem or COM buffers */
  265.    /* Stop when nothing new appears for 100ms.      */
  266.  
  267.    do until line = ''
  268.      line = slip_com_input(interface,,100)
  269.      if echo \= '' then
  270.         call charout , line
  271.    end
  272.  
  273.    return
  274. 
  275.