!
	This script will log in using a Hayes AT command set or DEC
	Scholar (DF224) command set on the local modem, which dials
	into a DECserver-like device or log in with direct connect to
	either a DECserver device or straight to VMS with or without
	DECserver password protection. It connects to the desired node,
	logs in, and enables SSU on the VAX.

	Copyright  Digital Equipment Corporation 1992,1994
;
!
	What follows is the actual script for autologin.  It shouldn't
	need to be edited by the end user, except for enhancements.

	Start by setting the special name used by the setup script
	menu item to a script string that obtains everything you need.
;
$setup:
!
	Default values for autologin setup strings
;
DEFINE ONCE SAVE user "";
DEFINE ONCE SAVE pass "";
DEFINE ONCE SAVE $hostname "";
DEFINE ONCE SAVE phone "";
DEFINE ONCE SAVE modempassword "";
DEFINE ONCE SAVE serveruser "Whack autologin";
DEFINE ONCE SAVE latpassword "";
DEFINE ONCE SAVE WATNusername "";
DEFINE ONCE SAVE WATNpass "";
DEFINE ONCE SAVE modeminit "Z";
DEFINE ONCE SAVE latprompt "Local>";
DEFINE ONCE SAVE vmsprompt "$ ";
DEFINE ONCE SAVE serverinit "";
DEFINE ONCE SAVE systeminit "";

OBTAIN
	CENTER MESSAGE "This is the first of three setup screens."
		MESSAGE "Enter or change your basic login parameters. The"
		MESSAGE "initial values are learned as needed during login."
	SAVE user "Username: "
	NOECHO SAVE pass "System Password: "
	SAVE $hostname "Node name: "
	SAVE phone "Phone number: "
	SAVE modempassword "Modem Password: "
	SAVE serveruser "Server username: "
	SAVE latpassword "Server Password: "
	SAVE WATNusername "X.25 username: "
	SAVE WATNpass "X.25 password: ";
    OBTAIN
    	CENTER MESSAGE "This is the second of three setup screens."
    		MESSAGE "Your modem may need a configuration string to set"
		MESSAGE "compatibility with the host modem, to enable XON/XOFF"
		MESSAGE "flow control, enable speed buffering, or adjust"
		MESSAGE "user preferences such as speaker volume."
		MESSAGE "Consult your modem manual for the correct settings"
		MESSAGE "for your modem."
	SAVE modeminit "Modem init string: "
		MESSAGE "For Rockwell-chip based modems, the suggested"
		MESSAGE "string is '&F0M1&K4E1X4L3W1'.  For better"
		MESSAGE "copatiblity with Digital V.32 modem s, add 'F8\N5'";
    OBTAIN
    	CENTER	MESSAGE "This is the third of three setup screens."
    		MESSAGE "System managers and users often change prompts"
    		MESSAGE "from the system default.  The AutoLogin script"
    		MESSAGE "needs correct values here to guide it."
	SAVE latprompt "Server prompt, usually 'Local>': "
	SAVE vmsprompt "System prompt, usually '$ ': "
		MESSAGE "To use multiple sessions on a serial line, you may"
		MESSAGE "need to configure an init string to start the host"
		MESSAGE "side of the protocol.  If using server based sessions,"
		MESSAGE "set the server init to 'SET MULTI ENABLE'.  If using"
		MESSAGE "VAX SSU, set the system init to 'MCR SSU ENABLE'."
	SAVE serverinit "Server init string: "
	SAVE systeminit "System init string: ";
EXIT;

$startup:
DEFINE LOCAL reattach "NO";
GOTO start;
$newsession:
DEFINE LOCAL reattach "YES";
start:
!
	Default values for autologin setup strings
;
DEFINE ONCE SAVE user "";
DEFINE ONCE SAVE pass "";
DEFINE ONCE SAVE $hostname "";
DEFINE ONCE SAVE phone "";
DEFINE ONCE SAVE modempassword "";
DEFINE ONCE SAVE serveruser "Whack autologin";
DEFINE ONCE SAVE latpassword "";
DEFINE ONCE SAVE WATNusername "";
DEFINE ONCE SAVE WATNpass "";
DEFINE ONCE SAVE modeminit "";
DEFINE ONCE SAVE latprompt "Local>";
DEFINE ONCE SAVE vmsprompt "$ ";
DEFINE ONCE SAVE serverinit "";
DEFINE ONCE SAVE systeminit "";

GOTO skipcountdown;

	PROGRESS "Countdown 10";
	WAIT 1000;
	PROGRESS "Countdown 9";
	WAIT 1000;
	PROGRESS "Countdown 8";
	WAIT 1000;
	PROGRESS "Countdown 7";
	WAIT 1000;
	PROGRESS "Countdown 6";
	WAIT 1000;
	PROGRESS "Countdown 5";
	WAIT 1000;
	PROGRESS "Countdown 4";
	WAIT 1000;
	PROGRESS "Countdown 3";
	WAIT 1000;
	PROGRESS "Countdown 2";
	WAIT 1000;
	PROGRESS "Countdown 1";
	WAIT 1000;
skipcountdown:

!
	Attempt to determine what we are connected to.
;
PROGRESS "Login script AUTOLOG.VTS running. Determining what we are connected to.  Press CANCEL to log in manually.";
        
!
	This delay sequence is used between cr's while attempting to get
	the attention of the host.  The varying delays are to wake up
	Tymnet, which seems to be very picky about this.
;
                  
DEFINE LOCAL attn1 "4000"; 
DEFINE LOCAL attn2 "1000"; 
DEFINE LOCAL attn3 "350"; 
DEFINE LOCAL attn4 "250"; 
DEFINE LOCAL attn5 "100"; 
DEFINE LOCAL attn6 "1000"; 
DEFINE LOCAL attn7 "500"; 
DEFINE LOCAL attn8 "800";        
        
whereami:
    WAIT 4000
	"Ready" scholardial
	"OK" hayesdial
	"-70" latconnect
	"~x07#" dolatpassword
	"Enter user" latuser
	"Username:" loginuser
	"ogin:" loginuser
	latprompt latconnect
	"Local>" latconnect
	"user name: " watnuser
	"please log in: " watnuser
	vmsprompt ready;
    SEND "~r";
    WAIT 500
	"Ready" scholardial
	"OK" hayesdial
	"-70" latconnect
	"~x07#" dolatpassword
	"Enter user" latuser
	"Username:" loginuser
	"ogin:" loginuser
	latprompt latconnect
	"Local>" latconnect
	"user name: " watnuser
	"please log in: " watnuser
	vmsprompt ready;
    SEND "~r";
    WAIT 250
	"Ready" scholardial
	"OK" hayesdial
	"-70" latconnect
	"~x07#" dolatpassword
	"Enter user" latuser
	"Username:" loginuser
	"ogin:" loginuser
	latprompt latconnect
	"Local>" latconnect
	"user name: " watnuser
	"please log in: " watnuser
	vmsprompt ready;
    SEND "+";
    WAIT 250;
    SEND "+";
    WAIT 250;
    SEND "+";
    WAIT 250;
    SEND "AT~r";
    GOTO whereami;
!
	Set up dial string for old-style scholar (DF224) modems
;
scholardial:
    DEFINE initstring "";
    DEFINE dialprefix "T";
    DEFINE dialsuffix "!";
    GOTO autodial;
!
	Set up dial string for hayes-style (AT) modems
;
hayesdial:
    DEFINE initstring "AT" modeminit "~r";
    DEFINE dialprefix "ATDT";
    DEFINE dialsuffix "~r";
    GOTO autodial;
trysimpler:
    DEFINE initstring "";
    DEFINE dialprefix "ATDT";
    GOTO autodial;
!
	Attempt to dial out with correct instructions, dispatch
	if we detect messages from previous partial progress.
;
autodial:
    OBTAIN ONCE phone "Phone number? ";
    PROGRESS "Dialing the modem.";
    SEND initstring;
    WAIT 250;
    SEND dialprefix phone dialsuffix;
    WAIT 60000
	"Attached" autobaud
	"Busy" redial
	"rror" whereami
	"-70" latconnect
	"PASSWORD ?" domodempwd
	"CONNECT" autobaud
	"NO CARRIER" badnumber
	"ERROR" trysimpler
	"BUSY" redial;
badnumber:
    OBTAIN phone "Phone number? ";
    GOTO autodial;
!
	Try dialing again after a waiting 5 seconds
;
redial:
    PROGRESS "Dial failed, waiting to try again.";
    WAIT 5000;
    GOTO autodial;
!
	Pound on carriage return repeatedly until the autobaud mechanism
	kicks in and recognizes our speed.
;
autobaud:
    PROGRESS "Connection established.";
    WAIT 4000
	"#" dolatpassword
	"Local>" latconnect
	latprompt latconnect
	"NO" autodial
	"Disconnected" autodial
	"ogin:" loginuser
	"PASSWORD ?" domodempwd
	"Enter user" latuser
	"terminal identifier" watnterm  
	"ietifier" watnterm
	"" watnterm
	"please log in: " watnuser
	"user name: " watnuser
	"password: " watnpass
	"Username:" loginuser;
    SEND "~r";
autobaud1:
    PROGRESS "Getting the attention of the remote site. " attn1;
    WAIT attn1
	"#" dolatpassword
	"Local>" latconnect
	latprompt latconnect
	"NO" autodial
	"Disconnected" autodial
	"ogin:" loginuser
	"PASSWORD ?" domodempwd
	"Enter user" latuser
	"terminal identifier" watnterm 
	"ietifier" watnterm
	"" watnterm
	"please log in: " watnuser
	"user name: " watnuser
	"password: " watnpass
	"Username:" loginuser;
    SEND "~r";
!
		Cycle through the delays
;	
	DEFINE LOCAL temp attn1;  
	DEFINE attn1 attn2;  
	DEFINE attn2 attn3;  
	DEFINE attn3 attn4;  
	DEFINE attn4 attn5;  
	DEFINE attn5 attn6;  
	DEFINE attn6 attn7;  
	DEFINE attn7 attn8;  
	DEFINE attn8 temp;  
	    
    GOTO autobaud1;

watnterm:	! WATN network terminal type code is O;
	SEND "O";
	GOTO autobaud;
watnuser:
	OBTAIN
		ONCE WATNusername "WATN username? "
		ONCE WATNpass "WATN password?";
    PROGRESS "Logging into WATN.";
	SEND WATNusername "~r";
	GOTO autobaud;
watnpass:
	SEND WATNpass "~r";
	GOTO autobaud;
!
	Issue the lat password.  Ask again if current value was incorrect
;
dolatpassword:
    OBTAIN ONCE latpassword "LAT Password? ";
    PROGRESS "Logging into terminal server.";
    SEND latpassword "~r";
    WAIT 10000
	"Local>" latconnect
	latprompt latconnect
	"NO" autodial
	"Disconnected" autodial
	"ogin:" loginuser
	"PASSWORD ?" domodempwd
	"Enter user" latuser
	"Username:" loginuser
	"#" wrongpassword;
    GOTO autodial;
wrongpassword:
    OBTAIN latpassword "LAT Password? ";
    GOTO dolatpassword;
!
	Issue the modem password.  Ask again if current value was incorrect
;
domodempwd:
    OBTAIN ONCE modempassword "Modem Password? ";
    PROGRESS "Issuing modem password.";
    SEND modempassword "~r";
    GOTO autobaud;
!
	Issue an arbitrary username to the DECserver and connect to the
	desired node.  Get a new node name if the server issues a 702 error.
;
latuser:
    PROGRESS "Issuing terminal server username.";
    SEND serveruser "~r";
    WAIT 3000
	"Local>" latconnect
	latprompt latconnect;
latconnect:
    ! HACK 1;
    PROGRESS "Issuing terminal server init string.";
    SEND serverinit "~r";
latloop:
    PROGRESS "Waiting for init string command completion.";
    WAIT 2000
	"Username:" loginuser
	"ogin:" loginuser
	latprompt lat1
	"Local>" lat1;
    SEND " ";			! Send something that will create the first session ;
    GOTO latloop;
lat1:
    OBTAIN ONCE $hostname "Node name?";
    PROGRESS "Connecting to node " $hostname ".";
    SEND "C " $hostname "~r";
    WAIT 3000
	"Username:" loginuser
	"ogin:" loginuser
	latprompt latagain
	"Local>" latagain;
    EXIT;
latagain:
    OBTAIN $hostname "Node name? ";
    GOTO lat1;

loginuser:
    OBTAIN ONCE user "Username: " NOECHO ONCE pass "Password: ";
    PROGRESS "Logging in.";
    SEND user "~r";
    WAIT 5000
	"Password:" dohostpassword
	"Username:" loginuser
	"ogin:" loginuser
	"-702-" latconnect;
loginfailure:
    OBTAIN user "Username: " NOECHO pass "Password: ";
    SEND "~r";
    PROGRESS "Trying login again.";
    WAIT 5000
	"Password:" dohostpassword
	"Username:" loginuser
	"ogin:" loginuser
	"-702-" latconnect;
    GOTO loginuser;
!
	Issue the pasword and see what the system comes back with. 
	Login failures are detected.  We should also check for hung
	up modems.  VMS disconnected processes are detected, and we
	get passed the prompt for reconnecting.
;
dohostpassword:
    WAIT 250;
    SEND pass "~r";
    WAIT 3000
	"failure" loginfailure
	"Last" loginokay
	"isconnect" logindis;
loginokay:
    PROGRESS "Waiting for final prompt.";
    WAIT 40000
    	vmsprompt ready
    	"> " ready
    	"Attempting to enable multiple sessions" done;
ready:
    SEND systeminit "~r";
done:
    EXIT;

logindis: !	Disconnected session prompt, say NO and proceed. ;
    SEND reattach "~r";
    GOTO loginokay;
