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

  1. /* HOMESRV.CMD
  2. Handles SLIP login and routing
  3. Put this file in \TCPIP\BIN on the home machine.
  4. This file is called from HOMESRV.CFG, which is called from HOMESRVD.CMD
  5.  
  6. Configuration: set the Rexx variables below:
  7. */
  8. /* Serial Port Configuration and modem strings */
  9. comport   = 'COM2'
  10. comparms  = '115200,n,8,1'   /* com port mode command parameters   */
  11. initcmd   = 'ATZ'         /* modem reset string           */
  12. anscmd      = 'ATS0=1'         /* set modem into autoanswer mode       */
  13. connectstring='CONNECT'      /* Adjust this to your brand of modem.*/
  14.  
  15.  
  16.  
  17. /* Internet addresses, machine names */
  18. ipaddress  = '199.99.99.99'     /* Home PC's IP address for sl0 interface */
  19. ipdest       = '199.99.99.88'     /* Work PC's IP address for sl0 interface */
  20. netmask    = '255.255.255.0'
  21. /* The parms below are only used if you have a Home Ethernet           */
  22. desthostname = 'workmachine'       /* Work PC's name. Must be known to DNS */
  23. macaddress   = '00:00:c0:55:66:77:88' /* Home PC's hardware MAC address       */
  24.  
  25. /* Users */
  26. username = 'yourname'        /* ID for logging into work machine       */
  27. password = 'secret'        /* Password for logging into work machine */
  28.  
  29. /* If the Home machine is on a home Ethernet, change Ethercard='F' to Ethercard='T'.*/
  30. Ethercard = 'F'
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. /****************************************************************************/
  39.  
  40. /* Define routines for errorhandling */
  41. signal on error name errorhandler
  42. signal on failure name errorhandler
  43. signal on halt name errorhandler
  44. /* signal on novalue name errorhandler */
  45. signal on syntax name errorhandler
  46. signal on notready name errorhandler
  47.  
  48. /* Load RexxUtility functions */
  49. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  50.  
  51.  
  52. parse arg interface
  53.  
  54. /*--------------------------------------------------------------------------*/
  55. /*                   Initialization and Main Script Code                    */
  56. /*--------------------------------------------------------------------------*/
  57.  
  58. /* Set some definitions for easier COM strings */
  59. cr='0d'x
  60. crlf='0d0a'x
  61. timeout = 0
  62.  
  63. say ''
  64. say ' OS/2 Slip Server (interface 'interface')'
  65.  
  66. /* Initialize com port:     mode com2 57600,n,8,1,buffer=on  */
  67. 'mode 'comport comparms
  68.  
  69. /* Do this until SLIP command was sent */
  70. do until connect
  71.  
  72.    /* Flush any stuff left over from previous COM activity */
  73.    call flush_receive
  74.  
  75.    /* Init modem */
  76.    call lineout , 'Reset modem...'
  77.    call send initcmd || cr
  78.    call waitfor 'OK', 5 ; call flush_receive 'echo'
  79.      if RC = 1 then do
  80.        call lineout , 'Modem not resetting... Try again'
  81.        call send '+++'
  82.        exit 1
  83.      end
  84.  
  85.    /* Set modem into auto-answer mode */
  86.    call lineout , 'Set auto answer...'
  87.    call send anscmd || cr
  88.    call waitfor 'OK', 40 ; call waitfor crlf , 2
  89.     if RC = 1 then do
  90.        call lineout , ' Modem not responding... Try again '
  91.        exit 2
  92.      end
  93.  
  94.    /* Flush anything else */
  95.    call flush_receive 'echo'
  96.  
  97.    /* Wait for call */
  98.    say 'Waiting for connection started on' date() 'at' time()'.'
  99.    do while waitfor(connectstring,1)\=0
  100.       call SysSleep 3
  101.    end
  102.    call waitfor crlf , 2
  103.    say 'Login process started on' date() 'at' time()'.'
  104.  
  105.    call waitfor crlf , 2
  106.  
  107.    /* Send login */
  108.    call send 'OS/2 Slip Server '||cr
  109.    do 2
  110.       call send crlf
  111.    end
  112.  
  113. /* Prompt for User and wait for username */
  114.    call send 'User:'
  115.    call waitfor username, 30, 1
  116.    if rc\=1 then call waitfor cr, 30
  117.    if rc=1 then do
  118.       say 'Unsuccessfull login on' date() 'at' time()'.'
  119.       call SysSleep 1
  120.       call send '+++'
  121.       call SysSleep 2
  122.       call send 'ATH'||cr
  123.       connect = 0
  124.    end
  125.  
  126. /* If User OK, prompt for Password: and wait for PW */
  127.    call send crlf
  128.    call send 'Password:'
  129.    call waitfor password, 30, 1
  130.  
  131.    if rc\=1 then call waitfor cr, 30
  132.  
  133.    if rc=1 then do
  134.       say 'Unsuccessfull login on' date() 'at' time()'.'
  135.       call SysSleep 1
  136.       call send '+++'
  137.       call SysSleep 2
  138.       call send 'ATH'||cr
  139.       connect = 0
  140.    end
  141.    else do
  142.       say 'Successfull login on' date() 'at' time()'.'
  143.       connect = 1
  144.    end
  145.  
  146.    call flush_receive 'echo'
  147. end
  148.  
  149. /* Now configure this machine for the appropriate address, */
  150. 'ifconfig sl0 'ipaddress ipdest' netmask 'netmask
  151. 'route add host 'ipdest ipaddress' 1'
  152.  
  153. /* If you have a Home Ethernet, proxy arp here tells other home machines about Work machine */
  154. if Ethercard='T' then
  155.    'arp -s 'desthostname macaddress 'pub'
  156.  
  157. /* Tell client what to do */
  158. call send crlf
  159. call send 'Entering SLIP mode.'||crlf
  160. call send 'Your IP address is 'ipdest'.  MTU is 1500 bytes'||crlf
  161. call send "VJ Header compression is active."||crlf
  162.  
  163. call flush_receive 'echo'
  164.  
  165. /* Wait to avoid sending of garbage while client is in command mode */
  166. call SysSleep 5
  167.  
  168. exit 0
  169.  
  170. /*--------------------------------------------------------------------------*/
  171.  
  172. /* Errorhandler */
  173. errorhandler:
  174. say copies('=',79)
  175. say 'ERROR OCCURED:'
  176. say '   Condition:' condition('c')
  177. say '   Instruction:' condition('i')
  178. say '   Description:' condition('d')
  179. say '   Status:' condition('s')
  180. say '   Line:' sigl
  181. say copies('=',79)
  182. return 0
  183.  
  184. /*--------------------------------------------------------------------------*/
  185. /*                            send ( sendstring)                            */
  186. /*..........................................................................*/
  187. /*                                                                          */
  188. /* Routine to send a character string off to the modem.                     */
  189. /*                                                                          */
  190. /*--------------------------------------------------------------------------*/
  191.  
  192. send:
  193.  
  194.    parse arg sendstring
  195.    call slip_com_output interface , sendstring
  196.  
  197.    return
  198.  
  199. /*--------------------------------------------------------------------------*/
  200. /*                    waitfor ( waitstring , [timeout] )                    */
  201. /*..........................................................................*/
  202. /*                                                                          */
  203. /* Waits for the supplied string to show up in the COM input.  All input    */
  204. /* from the time this function is called until the string shows up in the   */
  205. /* input is accumulated in the "waitfor_buffer" variable.                   */
  206. /*                                                                          */
  207. /* If timeout is specified, it says how long to wait if data stops showing  */
  208. /* up on the COM port (in seconds).                                       */
  209. /*                                                                          */
  210. /*--------------------------------------------------------------------------*/
  211.  
  212. waitfor:
  213.  
  214.    parse arg waitstring , timeout, doecho .                /* Changed by MW */
  215.  
  216.    if doecho\=1 then doecho=0                              /* Changed by MW */
  217.  
  218.    if timeout = '' then
  219.      timeout = 5000    /* L O N G   delay if not specified */
  220.    waitfor_buffer = '' ; done = -1; curpos = 1
  221.    ORI_TIME=TIME('R')                                      /* Changed by MW */
  222.  
  223.    if (remain_buffer = 'REMAIN_BUFFER') then do
  224.       remain_buffer = ''
  225.    end
  226.  
  227.    do while (done = -1)
  228.       if (remain_buffer \= '') then do
  229.          line = remain_buffer
  230.          remain_buffer = ''
  231.        end
  232.        else do
  233.          line = slip_com_input(interface,,10)
  234.          if doecho=1 then call send line                   /* Changed by MW */
  235.       end
  236.       waitfor_buffer = waitfor_buffer || line
  237.       index = pos(waitstring,waitfor_buffer)
  238.       if (index > 0) then do
  239.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  240.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  241.          done = 0
  242.       end
  243.       call charout , substr(waitfor_buffer,curpos)
  244.       curpos = length(waitfor_buffer)+1
  245.       if ((done \= 0) & (TIME('E')>timeout)) then do
  246. /*        call lineout , ' WAITFOR: timed out ' */         /* Changed by MW */
  247.         done = 1
  248.        end
  249.    end
  250. /*   timeout=0 */                                          /* Changed by MW */
  251.    RC=done
  252.    drop timeout doecho                                     /* Changed by MW */
  253.  return RC
  254.  
  255.  
  256. /*--------------------------------------------------------------------------*/
  257. /*                               readpass ()                                */
  258. /*..........................................................................*/
  259. /*                                                                          */
  260. /* Routine used to read a password from the user without echoing the        */
  261. /* password to the screen.                                                  */
  262. /*                                                                          */
  263. /*--------------------------------------------------------------------------*/
  264.  
  265. readpass:
  266.  
  267.   answer = ''
  268.   do until key = cr
  269.     key = slip_getch()
  270.     if key \= cr then do
  271.       answer = answer || key
  272.     end
  273.   end
  274.   say ''
  275.   return answer
  276.  
  277.  
  278. /*--------------------------------------------------------------------------*/
  279. /*                             flush_receive ()                             */
  280. /*..........................................................................*/
  281. /*                                                                          */
  282. /* Routine to flush any pending characters to be read from the COM port.    */
  283. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  284. /* point it returns.                                                        */
  285. /*                                                                          */
  286. /* The optional echo argument, if 1, says to echo flushed information.      */
  287. /*                                                                          */
  288. /*--------------------------------------------------------------------------*/
  289.  
  290. flush_receive:
  291.  
  292.    parse arg echo
  293.  
  294.    /* If echoing the flush - take care of waitfor remaining buffer */
  295.    if (echo \= '') & (length(remain_buffer) > 0) then do
  296.       call charout , remain_buffer
  297.       remain_buffer = ''
  298.    end
  299.  
  300.    /* Eat anything left in the modem or COM buffers */
  301.    /* Stop when nothing new appears for 100ms.      */
  302.  
  303.    do until line = ''
  304.      line = slip_com_input(interface,,100)
  305.      if echo \= '' then
  306.         call charout , line
  307.    end
  308.  
  309.    return
  310.  
  311. 
  312.