home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.rainsoft.?
/
ftp.rainsoft.zip
/
rainsoft
/
os2
/
rainslip.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
2012-12-05
|
13KB
|
405 lines
/* REXX ---- RAINSLIP.CMD ------------------------------------------*/
/* OS/2 IAK SLIP RAIN ACCESS REXX file */
/* Heavily modified from slipup.cmd for SLIP access provider */
/* This rexx wil redial rain every 5 seconds if busy */
/* user setup variables */
/* Modified INIT string for Default Modem */
ModemInit='ATZ' /*** EDIT ModemInit TO SUPPORT YOUR MODEM */
/* set the comport you use */
ComPort='com1' /*** EDIT ComPort FOR COM1-4 YOUR MODEM IS ON */
/* unique string for command prompt */
CommandKey=''
/* options for the "mode" system call */
ModeOptions='57600,n,8,1,buffer=on,rts=hs,dtr=on'
/* does your host ask you what terminal you use? */
/* 1 if it does, 0 if not */
AskTerm=0
/* delay after BUSY */
BusyDelay=0
MaxBusy=60 /* ATTEMPTS REDAIL 60 TIMES BEFORE GIVING UP */
ElapseSecs = 0
DialtimeOut = 45 /* wait for connect secs */
/* delay after NO CARRIER */
NoCDelay=2
Wdialcmd='xxxxxxxxxxxxxxxxxxxx'
/* Login COMMAND */
LoginCMD='slip:'
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysloadFuncs'
call SysLoadFuncs
parse arg interface , dialcmd username password
/*----------------------------------------------------------------*/
/* Initialization and Main Script Code */
/*----------------------------------------------------------------*/
/* Set some definitions for easier COM strings */
cr='0d'x
crlf='0d0a'x
say ''
say 'REXX SLIP Script (interface' interface')'
Wdialcmd = dialcmd
'mode 'ComPort||':' ModeOptions /* set comport speed */
call flush_receive /* Flush any stuff left over from previous COM activity */
/* dial the number and login */
connected=0
nBusy = 0
DO FOREVER UNTIL connected
CALL SetModem
rc = Dial()
call lineout , 'rc=' rc ' Dial Elapse ' ElapseSecs 'secs'
IF rc \=0 THEN DO
if rc = 1 then do
nBusy = nBusy + 1
if (nBusy > MaxBusy) then do
call lineout , 'Line BUSY ' MaxBusy 'Times -- Aborting...'
EXIT 1
end
call lineout , 'Busy #' nBusy ', Retry in ' BusyDelay ' secs.'
CALL SysSleep BusyDelay
ITERATE
end
if rc = 2 then do
SAY 'Something wrong - NO CARRIER - Retry in ' BusyDelay ' secs.'
CALL SysSleep BusyDelay
ITERATE
end
if rc = 7 then do
SAY 'No Connection Time Out -- Retry in ' BusyDelay ' secs.'
CALL SysSleep BusyDelay
ITERATE
end
SAY 'Something wrong, either VOICE or ERROR returned after - Aborting...'
EXIT 3
END
SAY 'Doing Login'
IF Login()=1 THEN DO
/* hang up */
'mode '||ComPort||':dtr=off > \dev\nul'
'mode '||ComPort||':dtr=on > \dev\nul'
SAY 'Retrying connection after ' BusyDelay ' sec delay.'
CALL SysSleep BusyDelay
END
ELSE DO
connected = 1
END
END
/* Parse the results of the SLIP LOGIN to determine our address. */
/* We use the "waitfor_buffer" variable from the waitfor routine */
/* to parse the stuff we get from the Annex after waiting for an */
/* appropriate point in the data stream. */
call waitfor 'beginning'
parse var waitfor_buffer . 'from (' a '.' b '.' c '.' d ')' .
annex_address = a||'.'||b||'.'||c||'.'||d
parse var waitfor_buffer . 'to ' a '.' b '.' c '.' d ' ' .
os2_address = a||'.'||b||'.'||c||'.'||d
call flush_receive 'echo'
/* Now configure this host for the appropriate address, */
/* and for a default route through the Annex. */
say cr || 'SLIP Connection Established'
say 'Configuring local address =' os2_address
say 'R.A.I.N address =' annex_address
'ifconfig sl0' os2_address annex_address 'netmask 255.255.255.0'
'route -f add default' annex_address '1'
/* All done */
exit 0
/*-------------------------------------------------------------*/
/* SetModem() */
/*.........................................................................*/
/* Sets the modem and hopefully everybody is happy when done... */
/* We have to be very paranoid with "waitfor" or we hang the dialer. */
/*-------------------------------------------------------------*/
SetModem:
successful=0
DO UNTIL successful=1
call send ModemInit || cr
if waitfor('OK', 5) = 1 then DO
call flush_receive 'echo'
call lineout , 'Modem not resetting... Trying again'
call send '+++'
IF waitfor('OK' ,5) = 1 THEN DO
CALL LineOut , 'could not reset modem. Check your modem settings!'
EXIT
END
END
ELSE DO
CALL flush_receive 'echo'
successful=1
END
END
RETURN 1
/*-----------------------------------------------------------*/
/* dial() */
/*.........................................................................*/
/* Dials the number with some extra error handling above and beyond the */
/* normal stuff- */
/*------------------------------------------------------------*/
dial:
/* Dial the remote server */
call charout , 'Now Dialing...'
call send Wdialcmd || cr
/* catch first cr from modem after dialing */
rc=waitfor(cr , 10);
CALL flush_receive 'echo'
/* now parse the return from the modem, give time to return code */
/* rc=waitfor(cr, 60); */
rc = 0
waitfor_buffer = '' ; curpos = 1
ElapseSecs = TIME('R')
do forever
ElapseSecs = TIME('E')
if (ElapseSecs > DialtimeOut) then do
CALL flush_receive 'echo'
rc = 7
RETURN rc
end
line = slip_com_input(interface,,10)
waitfor_buffer = waitfor_buffer || line
call charout , substr(waitfor_buffer,curpos)
curpos = length(waitfor_buffer)+1
rc = what()
IF rc = 0 THEN DO
CALL flush_receive 'echo'
RETURN rc
END
IF rc < 8 THEN DO
/* call lineout , waitfor_buffer */
CALL flush_receive 'echo'
RETURN rc
END
END /* end forever */
RETURN 8 /* SHOULD NEVER GET HERE */
what:
SELECT;
WHEN Pos('CONNECT', waitfor_buffer) \= 0 THEN DO
RETURN 0
END
WHEN Pos('BUSY', waitfor_buffer) \= 0 THEN DO
RETURN 1
END
WHEN Pos('NO CARRIER', waitfor_buffer) \= 0 THEN DO
RETURN 2
END
WHEN Pos('ERROR', waitfor_buffer) \= 0 THEN DO
RETURN 3
END
WHEN Pos('NO DIALTONE', waitfor_buffer) \= 0 THEN DO
RETURN 4
END
WHEN Pos('VOICE', waitfor_buffer) \= 0 THEN DO
RETURN 5
END
OTHERWISE DO
RETURN 8
END
/*---------------------------------------------------------------*/
/* login() */
/*.........................................................................*/
/* Handle the login process with the proper error checking and all that. */
/*---------------------------------------------------------------*/
login:
/* Handle login. We wait for standard strings, and then flush anything */
/* else to take care of trailing spaces, etc.. */
/* call send cr */
IF waitfor('ogin:',60)=1 THEN DO
call flush_receive 'echo'
SAY crlf||'No login RQ.'
RETURN 1
END
ELSE DO
call flush_receive 'echo'
call send LoginCMD || username || cr
IF waitfor('Password:',15)=1 THEN DO
SAY crlf||'No Password RQ.'
RETURN 1
END
ELSE DO
call flush_receive 'echo'
call send password || cr
END
END
RETURN 0
/*----------------------------------------------------------*/
/* send ( sendstring) */
/*..........................................................................*/
/* */
/* Routine to send a character string off to the modem. */
/* */
/*-----------------------------------------------------*/
send:
parse arg sendstring
call slip_com_output interface , sendstring
return
/*------------------------------------------------------*/
/* waitfor ( waitstring , [timeout] ) */
/*..........................................................................*/
/* */
/* Waits for the supplied string to show up in the COM input. All input */
/* from the time this function is called until the string shows up in the */
/* input is accumulated in the "waitfor_buffer" variable. */
/* */
/* If timeout is specified, it says how long to wait if data stops showing */
/* up on the COM port (in seconds).
*/
/* */
/*-------------------------------------------------------*/
waitfor:
parse arg waitstring , timeout
if timeout = '' then
timeout = 5000 /* L O N G delay if not specified */
waitfor_buffer = '' ; done = -1; curpos = 1
ORI_TIME=TIME('E')
if (remain_buffer = 'REMAIN_BUFFER') then do
remain_buffer = ''
end
do while (done = -1)
if (remain_buffer \= '') then do
line = remain_buffer
remain_buffer = ''
end
else do
line = slip_com_input(interface,,10)
end
waitfor_buffer = waitfor_buffer || line
index = pos(waitstring,waitfor_buffer)
if (index > 0) then do
remain_buffer = substr(waitfor_buffer,index+length(waitstring))
waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
done = 0
end
call charout , substr(waitfor_buffer,curpos)
curpos = length(waitfor_buffer)+1
if ((done \= 0) & (TIME('E')>timeout)) then do
call lineout , ' WAITFOR: timed out '
done = 1
end
end
timeout=0
RC=done
return RC
/*-----------------------------------------------------*/
/* readpass () */
/*..........................................................................*/
/* */
/* Routine used to read a password from the user without echoing the */
/* password to the screen. */
/* */
/*---------------------------------------------------------*/
readpass:
answer = ''
do until key = cr
key = slip_getch()
if key \= cr then do
answer = answer || key
end
end
say ''
return answer
/*-----------------------------------------------------*/
/* flush_receive () */
/*..........................................................................*/
/* */
/* Routine to flush any pending characters to be read from the COM port. */
/* Reads everything it can until nothing new shows up for 100ms, at which */
/* point it returns. */
/* */
/* The optional echo argument, if 1, says to echo flushed information. */
/* */
/*----------------------------------------------------------------*/
flush_receive:
parse arg echo
/* If echoing the flush - take care of waitfor remaining buffer */
if (echo \= '') & (length(remain_buffer) > 0) then do
call charout , remain_buffer
remain_buffer = ''
end
/* Eat anything left in the modem or COM buffers */
/* Stop when nothing new appears for 100ms. */
do until line = ''
line = slip_com_input(interface,,100)
if echo \= '' then
call charout , line
end
return
/* --------------End of rainslip.cmd file---------------------------*/