home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / autodial.zip / autodial.cmd < prev    next >
OS/2 REXX Batch file  |  1997-04-04  |  6KB  |  169 lines

  1. /* auto dialup */
  2. /* By Jeff Jackowski       */
  3. /*    jeffj@ro.com         */
  4. /*    http://ro.com/~jeffj */
  5. /* This script will make the computer remotely dial up an ISP on demand */
  6. /* Sequence of events:
  7.     If the "S" paramter is given, call the suspend script (seporate process)
  8.         The computer will enter suspend mode in 10 seconds
  9.         AutoDial will continue to run before then
  10.         See the instructions for the suspend script to make it work
  11.     Wait for the phone to ring
  12.     Wait for a person to leave a message on an answering machine
  13.         75 seconds
  14.     Spawn the OS/2 dialer to connect to the network
  15.         The dialer is a text based dialer that the graphical dialer uses
  16.         The dialer is included with Warp Connect and Warp v4.
  17.     Wait for the dialer to connect
  18.         75 seconds (mine is slow)
  19.     Check the connection
  20.     Dial again until connection is made
  21.     Send an email with computer's IP address
  22.         use "SENDIP21"
  23.     Check connection every 15 minutes
  24.         Dialer is set to disconnect after 12 minutes of inactivity
  25.     After loss of connection, wait again for the phone to ring.
  26.    This works great with the telnetd and ftpd programs included in Warp v4.
  27. */
  28.  
  29. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  30. Call SysLoadFuncs
  31. signal on halt
  32.  
  33. SerialPort = "com3:"  /* use the port your modem is attached to */
  34. TestConnect = "@ping ro.com 1 1 | RxQueue"
  35.   /* change "ro.com" to the domain name of your service provider */
  36. SuspendWait = 900   /* number of seconds to wait until suspending
  37.                        computer after a disconnect is noticed */
  38.  
  39. /* initialize a few variables */
  40. Suspend = 0
  41. argin.0 = 2
  42. /* get arguments */
  43. parse arg argin.1 argin.2
  44. /* loop to decipher arguments */
  45. do argstart = 1 to 2
  46.   if (argin.argstart = "s") | (argin.argstart = "-s") | (argin.argstart = "/s")
  47.     then Suspend = 1      /* when true, causes the suspend script to run just
  48.                              before the serial port is opened */
  49.   else if (argin.argstart <> "") then do
  50.     if ((argstart = 2) & (Suspend = 0)) then  /* command with arguments */
  51.       ConnectCommand = ConnectCommand || ' ' || argin.argstart
  52.     else ConnectCommand = argin.argstart
  53.   end
  54. end
  55. say 'Suspend =' Suspend
  56. say 'ConnectCommand =' ConnectCommand
  57.  
  58. newq = RxQueue("create")
  59. Call RxQueue 'set', newq
  60. call lineout SerialPort, 'ATS0=0'   /* no auto answer */
  61. conn = 0
  62. do forever
  63.  
  64.   /***** Wait for connection request *****/
  65.   req = 0
  66.   attempts = 0
  67.   do until req = 1
  68.     ring = linein(SerialPort)
  69.     parse upper var ring stat
  70.     if stat = 'RING' then req = 1
  71.     else do
  72.       call SysSleep 2
  73.       attempts = attempts + 1
  74.       /***** Check connection *****/
  75.       if (attempts > 615) & (conn = 1) then do /* check network every 1230 seconds */
  76.         attempts = 0         /* reset attempts to allow check again */
  77.         TestConnect newq
  78.         parse upper pull appname stat host hname
  79.         call Flush
  80.         if stat = 'UNKNOWN' then do
  81.           conn = 0
  82.           call StatusOut 'Connection lost'
  83.           call lineout SerialPort, 'ATS0=0'   /* no auto answer */
  84.           /***** Begin task to Suspend system *****/
  85.           if Suspend = 1 then do
  86.             call SysFileDelete 'SuspChk'  /* allow suspension of computer */
  87.             '@start /win suspend' SuspendWait 'SuspChk'
  88.           end  /* suspend */
  89.         end    /* net disconnect */
  90.       end      /* net check */
  91.     end        /* no ring */
  92.   end          /* do until ring */
  93.   call StatusOut 'Receved a ring'
  94.   call lineout SerialPort   /* disconnect from serial port */
  95.   if Suspend = 1 then do
  96.     call lineout 'SuspChk', 'NoSuspend'  /* prevent suspension of computer */
  97.     call lineout 'SuspChk'
  98.   end
  99.  
  100.   /***** Connection loop *****/
  101.   call lineout SerialPort   /* disconnect from serial port */
  102.   /* wait for person to leave a message */
  103.   call SysSleep 75
  104.   conn = 0
  105.   do until conn = 1
  106.     /* connect to ISP */
  107.     call StatusOut 'Dialing network'
  108.     '@detach runppp'  /* runppp is separate from this script because it has a long line */
  109.     /* wait for connection */
  110.     call SysSleep 75
  111.     /* test connection */
  112.     TestConnect newq
  113.     parse upper pull appname stat host hname
  114.     call Flush
  115.     if stat = 'UNKNOWN' then do
  116.       conn = 0
  117.       call StatusOut 'Connection not made, trying again'
  118.       call SysSleep 120  /* wait for PPP dialer to terminate */
  119.     end
  120.     else do
  121.       conn = 1
  122.       call StatusOut 'Connected to network'
  123.     end
  124.     call SysSleep 10
  125.   end
  126.  
  127.   /***** Connected *****/
  128.   /* run connection command to send IP address */
  129.   call StatusOut 'Running command: 'ConnectCommand
  130.   '@detach 'ConnectCommand
  131.  
  132. end
  133. Call RXQueue "delete", newq
  134. exit
  135.  
  136. StatusOut: arg statStr
  137.   /* Print out the current time and a message */
  138.   Parse Value Date() With Today Month Year
  139.   Parse Value Time('L') With Hour':'Minutes':'Seconds'.'Hundredths
  140.  
  141.   Message = '[' || Today Month Year || ', ' || Hour || ':' || Minutes || ':' ||,
  142.             Seconds || ']  ' || statStr
  143.   say Message
  144.   return
  145.  
  146. Flush:
  147.   /* flush queue */
  148.   Do While Queued() > 0
  149.     Parse Pull .
  150.   end
  151.   return
  152.  
  153. halt:
  154.    Call RXQueue "delete", newq
  155.    call lineout SerialPort
  156.    Exit  /* Rexx */
  157.  
  158. checkcon:
  159.   do until conn = 0
  160.     call SysSleep 735                /* check every 12 minutes + 15 seconds */
  161.     TestConnect newq
  162.     parse upper pull appname stat host hname
  163.     call Flush
  164.     if stat = 'UNKNOWN' then do
  165.       conn = 0
  166.       call StatusOut 'Connection lost'
  167.     end
  168.   end
  169.