rewrite the pid file when using updetach
[ppp.git] / scripts / secure-card
1 #!/usr/local/bin/expect -f
2 #
3 # This  script was  written  by  Jim Isaacson  <jcisaac@crl.com>.  It is
4 # designed to work  as a script to use the  SecureCARD(tm) device.  This
5 # little device is mated with a central controller. The number displayed
6 # on this card changes every so often and  you need to enter  the number
7 # along with your user account name in order to gain access.  Since chat
8 # is based upon fixed strings this procedure will not work with chat.
9 #
10 # It is included by permission. An excellent reference for the expect
11 # program used by this script is in the book:
12 #
13 # "Exploring Expect"
14 # by Don Libes
15 # Published by O'Rielly and Associates
16 #
17
18 send_user "hello, starting ppp\n"
19
20 system "stty 19200 -echoe -echo raw < /dev/cua3 > /dev/cua3"
21
22 #
23 # These are the parameters for the program.
24 #
25 set user      Pxxxxxx
26 set password  xxxxxxx 
27 set modem     /dev/cua3
28 set dialup    <put phone number here>
29 set timeout   60
30
31 spawn -noecho -open [open $modem "r+"]
32
33 send "AT&F\r"
34 expect "OK"
35
36 send "ATe0v1x4&c1q0&d2&c1s2=128s0=0DT $dialup\r"
37 set timeout 15
38 set counter 0
39
40 set still_connecting 1
41
42 expect {
43         -re ".*CONNECT.*\n" {
44                 set timeout 5
45                 set still_connecting 0
46                 continue -expect
47         }
48         -re ".*CONNECT.*\r" {
49                 set timeout 5
50                 set still_connecting 0
51                 continue -expect
52         }
53         -re ".*NO.*CARRIER" {
54                 send_user "Failed to Connect, exiting...\n"
55                 exit
56         }
57         -re ".*NO.*DIAL.*TONE" {
58                 send_user "Failed to Connect, exiting...\n"
59                 exit
60         }
61         -re ".*VOICE" {
62                 send_user "Failed to Connect, exiting...\n"
63                 exit
64         }
65         -re ".*sscode:.*\n" {
66                 continue -expect
67         }
68         -re ".*sscode:" {
69                 set timeout -1
70                 expect_user -re "(.*)\n"
71                 send "$expect_out(1,string)\r"
72                 set timeout 30
73                 continue -expect
74         }
75         -re ".*Next.*:" {
76                 set timeout -1
77                 expect_user -re "(.*)\n"
78                 send "$expect_out(1,string)\r"
79                 set timeout 30
80                 continue -expect
81         }
82         -re "Your.*" {
83                 send "\r"
84                 continue -expect
85         }
86         -re ".*in:" {
87                 send "$user\r"
88                 continue -expect
89         }
90         -re ".*word:" {
91                 send "$password\r"
92         }
93
94         timeout {
95                 if { $still_connecting > 0 } {
96                         continue -expect 
97                         }
98                 set timeout 15
99                 send "\r"
100                 incr counter
101                 if { $counter > 8 } {
102                         send_user "Cannot Connect\n"
103                         exit
104                 } else {
105                         continue -expect
106                 }
107         }
108 }
109
110 overlay -0 $spawn_id -1 $spawn_id pppd /dev/cua3 19200 192.111.187.215: \
111         crtscts modem defaultroute debug