; ~jhs/bin/kermit.isp.common --> personal/kermit.isp.common
;	by Julian H. Stacey
; DO NOT EDIT kermit.isp.wall & kermit.isp.desk, they are made by Makefile

; Warning: Timing problem:
;	Kermit takes considerable time to process lines with semi colons (;)
;	so if you remove a load of comments the script will run faster,
;	and you may need to add a sleep instead !

run ls -l	/var/log/slip/ibm/debugging.log
log debugging	/var/log/slip/ibm/debugging.log

run ls -l	/var/log/slip/ibm/session.log
log session	/var/log/slip/ibm/session.log

; -----------------------------------------------------------------------------

echo \13calling ../../../private/bin/kermit.isp.private \13
take ../../../private/bin/kermit.isp.private
; ../../../private/bin/kermit.isp.private contains personal data such as:
;	assign \%n 123456
;	assign \%u username
;	assign \%v pass1
;	assign \%w pass2
echo kermit.isp.{desk,wall} resumed\13

; -----------------------------------------------------------------------------

echo Phone number is \%n, (If this is long distance it will be Expensive).\13
echo Login and 2 passwords are: \%u \%v \%w\13

; -----------------------------------------------------------------------------

set line /dev/cuaa1
assign \%s 57600
set speed \%s
set flow rts/cts

; -----------------------------------------------------------------------------

output ate1\13
input 2 OK
if success goto OK_ate1
echo Failed ate1\13
quit
:OK_ate1

; -----------------------------------------------------------------------------

; Log which modem being used.
output ati3\13
; Supra:	V1.80-05 TR14-Jxxx-001 191
; Escom		AT-1496SA-EUR 06/01/1993 FOR GERMANY

input 2 OK
if success goto OK_ati3
echo Failed ati3\13
quit
:OK_ati3

; -----------------------------------------------------------------------------

output atz\13
input 2 OK
if success goto OK_atz
echo Failed atz\13
quit
:OK_atz

sleep 2
; Modem manuals says wait 2 seconds after a reset.

; -----------------------------------------------------------------------------

; Initialise
{S
; Supra
output \13at&f2e0b0l2m1n1&c0&d0&q5&q9&t5%g1s2=43s10=254s12=50s37=0&w1\13
sleep 4
;	Supra manual says at&f2 == \n3 &k3 w0 &q5 &d2 &c1
}S
{E
; for escom white, works for slip downloads, but not uploads
clear

;	White Escom does not allow &f2
output at&f\13
input 2 OK
if failure goto failed

output ate0\13
input 2 OK
if failure goto failed

output at&k3\13
input 2 OK
if failure goto failed

; causes kermit to stop talking to the modem
; output at\\n3\13
; input 2 OK
; if failure goto failed

output atw0\13
input 2 OK
if failure goto failed

output at\\q3\13
input 2 OK
if failure goto failed

output atm1\13
input 2 OK
if failure goto failed

; white escom does not allow atn	(redial is regulated for german modems)

output atl1\13
input 2 OK
if failure goto failed

output at&c0\13
input 2 OK
if failure goto failed

output at&d0\13
input 2 OK
if failure goto failed
; white escom does not allow at&q	(in supra it asserts async reliable)

output at&t5\13
input 2 OK
if failure goto failed

; %G rate renogiation is done by supra but not discovery & white escom

output ats2=43\13
input 2 OK
if failure goto failed

output ats10=254\13
input 2 OK
if failure goto failed

output ats12=50\13
input 2 OK
if failure goto failed

output ats37=0\13
input 2 OK
if failure goto failed

output at&w0\13
input 2 OK
if failure goto failed

; output at&w1\13
; input 2 OK
; if failure goto failed

; escom white fails to hold line after saying INTERNET \13at&f2e0b0l2m1n1&c1&d2&q5&q9&t5%g1s2=43s10=254s12=50s37=0&w1\13
}E

; -----------------------------------------------------------------------------

output atdt\%n\13
; Example output atdt123456\13
; sja prefixes 089 even though he's in Munich call area, to get a better line.

minput 60 {CONNECT 14400/V42BIS} {CONNECT 14400} {CONNECT \%s}
if success goto OK_connect
echo Failed to connect\13
goto hang_up
:OK_connect

; -----------------------------------------------------------------------------

;	&	(single char, no return must be issued within about 3 seconds)
output &

; -----------------------------------------------------------------------------

input 20 ersion ==>
if success goto OK_version
echo Failed to receive: Enter dial script version ==>\13
goto hang_up
:OK_version

echo 1.1\13
output 1.1\13

; -----------------------------------------------------------------------------

; Gateway:DE05L Chassis:1 Port:3
; Select one of the following services:
; INTERNET
; SECUREIP
; DUALACCESS
; Enter service ==>

input 5 ervice ==>
if success goto OK_service
echo Failed to receive: Enter Service ==>\13
goto hang_up
:OK_service

echo INTERNET\13
output INTERNET\13

; -----------------------------------------------------------------------------

input 5 ==>
if success goto skip_word
echo Failed to receive: Enter account userID password [/new_password]==>\13
goto hang_up
:skip_word

; echo \10Emiting Login and 2 passwords: \%u \%v \%w\13
; It accepts both upper & lower case.

; output u1234 p1234 p5678\13
output \%u \%v \%w\13

; -----------------------------------------------------------------------------

input 60 ddress
if success goto OK_local_ip
echo Failed to receive: 139.92.4.122 is your IP address\13
goto failed_ip
:OK_local_ip

; \Feval(expr)		evaluate arithmetic expression
; \Findex(a1,a2,a3)	position of string a2 in a1, starting at pos a3
; the above description of findex comes from man kermit from cku190.tar.gz )
;	HOWEVER the above doesnt work, whereas sja's order does !
;	assign \%o \Findex(139,\v(input),1)
; \Fsubstr(a1,a2,a3)	substring of a1, starts at a2, length a3

; clear	; try this next
assign \%o \Findex(139,\v(input),0)
echo \10
; echo JHS 139 is at \%o in buffer
assign \%x \Findex(\32,\v(input),\%o)
; echo JHS space is at \%x
assign \%m \Feval(\%x-\%o)
; echo JHS address string length is \%m
assign \%a \Fsubstr(\v(input),\%o,\%m)
; echo JHS Your Local Address is \%a
assign \%l \%a

clear
;	139.92.18.170	(return your dynamically assigned local address)
output \%a\13

; -----------------------------------------------------------------------------

input 60 ddress
if success goto OK_remote_ip
echo Failed to receive: 152.158.4.33 is the Gateway IP address\13
goto failed_ip
:OK_remote_ip

assign \%o \Findex(152,\v(input),0)
echo \10
; echo JHS 152 is at \%o in buffer
assign \%x \Findex(\32,\v(input),\%o)
; echo JHS space is at \%x
assign \%m \Feval(\%x-\%o)
; echo JHS address string length is \%m
assign \%a \Fsubstr(\v(input),\%o,\%m)
; echo JHS Destination Remote Address is \%a
assign \%r \%a


; -----------------------------------------------------------------------------

; Maybe next bits will fail on exclusive open.

echo Calling	slattach -h -s \%s /dev/cuaa1
; -h	Turn on cts/rts, else by default none.
;	slattach -h -s 57600 /dev/cuaa1
run	slattach -h -s \%s /dev/cuaa1

echo Calling	ifconfig sl0 \%l \%r up
;	ifconfig sl0 139.92.18.170 152.158.16.43 up
run	ifconfig sl0 \%l \%r up

; -----------------------------------------------------------------------------

echo Calling	route delete default
run	route delete default

echo Calling	route add default \%r
run	route add default \%r

echo Calling	netstat -r
run	netstat -r

echo Calling	~jhs/bin/.sh/net
run ~jhs/bin/.sh/net

; On the following `quit' Kermit warns:
;	 A serial connection might still be active on /dev/cuaa1. OK to exit?
; I'd like to find some way of quietly suppresing that warning.
quit

; =============================================================================
; Subroutines

:failed_ip
reinput 1 ailable
if failure goto hang_up
echo \13No IP addresses are available\13
echo Why can't it tell you before it's cost a unit ?
goto hang_up

; -----------------------------------------------------------------------------

:hang_up
; drop the line
echo \13kermit.isp.common calling kermit.hup \13
take kermit.hup
echo kermit.isp.common resumed\13

quit

; =============================================================================
