home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / D-G / DialScript / Examples / cs.ds < prev    next >
Encoding:
Text File  |  1991-11-04  |  6.8 KB  |  184 lines  |  [TEXT/dIsR]

  1. -- UTexas CS Dept. 2400 Baud login script.                vers. 11/4/91
  2.  
  3. -- To use 1200 bps, remove the "send break", and set speed to 1200
  4.  
  5. -- The script tries to get the modem's attention and dial, even if it has
  6. -- to hang up to do it.  It uses timeouts to recover from problems.
  7. -- Problems after connect are assumed to be due to line noise, so it
  8. -- hangs up and dials again in hope of a cleaner line.  It assumes you have
  9. -- a Hayes type modem set for English commands and responses.
  10.  
  11. -- You need to set the variable for your username in state init and fix up
  12. -- state FinishUp (optional).
  13.  
  14. script cs             -- scripts must begin with the word "script" and a name.
  15.                       -- Keywords like script must be in lower case.
  16.  
  17.  
  18.    -- Execution will begin with the first state in the file.  In this case,
  19.    -- the state named init.  Every state must have a unique name.  Identifiers
  20.    -- (names) in DialScript are sequences of any length of letters, digits,
  21.    -- and underscore characters.  They must begin with a letter.
  22.  
  23.    state init
  24.  
  25.       -- The display statement displays characters on the Mac terminal window
  26.       -- without sending them.  Use it for informative messages.  The variable
  27.       -- date contains the current date and time.  A newline is not auto-
  28.       -- matically included.  Hence the display "\r" at the end.
  29.  
  30.       display "Beginning UT CS login script on ";
  31.       display date;
  32.       display "\r";  --   <-- Don't forget semicolons at the end of statements.
  33.  
  34.       set port modem;  -- The set statements is used to set communications
  35.       set speed 2400;  -- parameters.  These values are the defaults, so these
  36.       set databits 8;  -- statements are not really necessary.
  37.  
  38.       set online on;   -- Be sure DialScript is online so that it will talk to
  39.                        -- the serial port.  This is also the default.
  40.  
  41.       -- setvar is used to give a value to a variable.  All variables hold
  42.       -- string values, never numbers, i.e. "67" not 67.  It is convenient
  43.       -- to use variables to hold parameters that you may wish to change
  44.       -- later.
  45.  
  46.       setvar USERNAME "newton\r";   -- You need to change this, of course.
  47.       setvar PHONE "ATDT4718454\r"; -- It's MY username, not yours.
  48.       setvar Modem_Escape_String "+++";  -- Some people like to change this.
  49.  
  50.       -- input prompts the user for a value for a variable.  The noecho
  51.       -- keyword causes what the user types to not be displayed.  Good for
  52.       -- passwords.
  53.  
  54.       input PASSWORD noecho;   -- You could use a setvar here.
  55.  
  56.       next ModemReady;         -- Branch to the state named ModemReady.
  57.  
  58.    end; -- init
  59.  
  60.  
  61.    -- This state makes sure we have the (Hayes-type) modem's attention.
  62.    -- It sends a carriage return to it and expects it to reply with OK.
  63.  
  64.    state ModemReady
  65.  
  66.       -- The repeat repeats the statements before its end a fixed number of
  67.       -- times, twice in this case.
  68.       repeat 2
  69.  
  70.          -- send sends characters out over the serial port.  Note that
  71.          -- carriage return is not included automatically.  Use \r for it.
  72.          send "\r"; send "AT\r";
  73.  
  74.          -- select waits for one of several conditions.
  75.          select
  76.             "OK":          -- If OK is received, go to state Dial.
  77.                 next Dial;
  78.             timeout 3:     -- If 3 seconds pass without a condition matching,
  79.                            -- display a warning message and leave the select.
  80.                 display "ModemReady timeout!\r";
  81.          end; -- select
  82.  
  83.          end; -- repeat
  84.  
  85.       -- If we get here, the select has timed out in both iterations of the
  86.       -- repeat.  The modem is not responding.  Try hanging up.
  87.  
  88.          next HangUp;  -- failed again, maybe hangup
  89.  
  90.    end; -- ModemReady
  91.  
  92.  
  93.    -- The state hangs up a Hayes modem by sending +++, waiting for OK,
  94.    -- and then sending ATH.
  95.  
  96.    state HangUp
  97.  
  98.       repeat 2
  99.          -- Note that send pauses for one second before sending.
  100.          -- The delay does nothing for 1 second to give an even greater
  101.          -- pause before sending the escape string.
  102.          delay 1; send Modem_Escape_String;
  103.          select
  104.             "OK"      : send "ATH\r"; next ModemReady;
  105.             timeout 3 : display "HangUp timeout!\r";
  106.          end;
  107.       end;
  108.       
  109.       -- If we reach this point, we have not received the ack for the
  110.       -- escape string.  We are confused and so try hanging up.
  111.       -- Control really should not reach this point.
  112.  
  113.       send "\r"; send "ATH\r";
  114.       next ModemReady;
  115.  
  116.    end; -- HangUp
  117.  
  118.  
  119.    -- This state dials the phone number and awaits the CONNECT message.
  120.    -- The select causes a redial if the line is busy, the modem responds
  121.    -- with NO CARRIER, or the modem does not respond with 25 seconds.
  122.  
  123.    state Dial
  124.       send PHONE;     -- The system's phone number
  125.       select
  126.          "CONNECT"    : next GotIt;
  127.          "BUSY"       : next ModemReady;
  128.          "NO CARRIER" : next ModemReady;
  129.          timeout 25   : display "Dial timeout!\r"; next ModemReady;
  130.       end; 
  131.    end; -- Dial
  132.  
  133.  
  134.    -- This state enters the username and the password in reponse to
  135.    -- the appropriate prompts.  If there is no prompt within 60 seconds,
  136.    -- the script hangs up and redials.
  137.  
  138.    state GotIt
  139.  
  140.       -- Here we have a bit of a trick.  The machine we are calling requires
  141.       -- that we send a break.  It will then switch to 2400 baud and prompt
  142.       -- for login.  The delay 1 gives a little time between the modem
  143.       -- connect and sending the break.  It is probably not necessary.
  144.       delay 1;
  145.       send break;   -- UNIX host needs a break to switch to 2400 baud
  146.  
  147.       select 
  148.          "login:"   : send USERNAME;
  149.          timeout 60 : display "login timeout!\r"; next HangUp;
  150.       end;
  151.  
  152.       select
  153.          "Password:" : send PASSWORD; send "\r"; -- Your password and return
  154.          timeout 60  : display "password timeout!\r"; next HangUp;
  155.       end;
  156.  
  157.       next FinishUp;
  158.    end; -- GotIt
  159.  
  160.  
  161.    -- This state is used to answer the terminal type prompt.  The nature
  162.    -- of this prompt depends on your .login file on UNIX.  You need to
  163.    -- to customize this state for your circumstances.  I enter return
  164.    -- to confirm that I will use a vt100 emulator and then switch to
  165.    -- the emulator I use (MacLayers) by means of the transfer.  "RunLayers"
  166.    -- is my settings file for MacLayers.  This script has to be in the
  167.    -- same folder as MacLayers and RunLayers in order for the transfer to
  168.    -- succeed.  The transfer quits DialScript and runs MacLayers with
  169.    -- settings file RunLayers (as though I had double clicked on RunLayers
  170.    -- from the finder).
  171.  
  172.    state FinishUp   -- You need to customize this.  What's here is weak.
  173.  
  174.       -- wait "(vt100)";                      -- Terminal type prompt
  175.       -- send "\r";                           -- Yes to vt100
  176.       -- transfer "MacLayers" "RunLayers";    -- Run real terminal emulator
  177.  
  178.    end;  -- FinishUp
  179.  
  180.  
  181.    -- FInally, the script ends with "end;" 
  182.  
  183. end; -- cs
  184.