summaryrefslogtreecommitdiffstats
path: root/bin/alogin.in
diff options
context:
space:
mode:
Diffstat (limited to 'bin/alogin.in')
-rwxr-xr-xbin/alogin.in57
1 files changed, 35 insertions, 22 deletions
diff --git a/bin/alogin.in b/bin/alogin.in
index fe55787..8ccf37b 100755
--- a/bin/alogin.in
+++ b/bin/alogin.in
@@ -1,7 +1,7 @@
#!@EXPECT_PATH@ --
##
##
-## Copyright (C) 1997 by Henry Kilmer, Erik Sherk and Pete Whiting.
+## Copyright (C) 1997-2001 by Henry Kilmer, Erik Sherk and Pete Whiting.
## All rights reserved.
##
## This software may be freely copied, modified and redistributed without
@@ -23,10 +23,10 @@
#
# Usage line
-set usage "Usage: $argv0 \[-c command\]\
-\[-f cloginrc-file\]\
-\[-s script-file\] \[-t timeout\] \[-u username\]\
-\[-v vty-password\] \[-x command-file\]\
+set usage "Usage: $argv0 \[-c command\] \
+\[-Evar=x\] \[-f cloginrc-file\] \
+\[-s script-file\] \[-t timeout\] \[-u username\] \
+\[-v vty-password\] \[-x command-file\] \
\[-y ssh_cypher_type\] router \[router...\]\n"
# env(CLOGIN) may contain:
@@ -88,9 +88,19 @@ for {set i 0} {$i < $argc} {incr i} {
} -w* -
-W* {
# ignore -w
+ # Environment variable to pass to -s scripts
+ } -E*
+ {
+ if {[ regexp .\[E\](.+)=(.+) $arg ignore varname varvalue]} {
+ incr i
+ set E$varname $varvalue
+ } else {
+ send_user "Error: invalid format for -E in $arg\n"
+ exit 1
+ }
# Enable Password
- } -e* -
- -E* {
+ } -e*
+ {
# ignore -e
# Command to run.
} -c* -
@@ -140,7 +150,10 @@ for {set i 0} {$i < $argc} {incr i} {
incr i
set cmd_file [ lindex $argv $i ]
}
- set cmd_fd [open $cmd_file r]
+ if [ catch {set cmd_fd [open $cmd_file r]} reason ] {
+ send_user "\nError: $reason\n"
+ exit 1
+ }
set cmd_text [read $cmd_fd]
close $cmd_fd
set command [join [split $cmd_text \n] \;]
@@ -320,7 +333,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
catch {close}; wait; return 1 }
eof { send_user "Error: Couldn't login\n"; wait; return 1 }
-re "$p_prompt" { send "$userpswd\r" }
- "$prompt" { set in_proc 0; return 0 }
+ -re "$prompt" { set in_proc 0; return 0 }
}
exp_continue
}
@@ -329,7 +342,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
"Password incorrect" { send_user "Error: Couldn't login\n";
catch {close}; wait; return 1 }
eof { send_user "Error: Couldn't login\n"; wait; return 1 }
- "$prompt" { set in_proc 0; return 0 }
+ -re "$prompt" { set in_proc 0; return 0 }
"Confirm seeing above note" { send "y\r" }
}
exp_continue
@@ -337,7 +350,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
-re "^Confirm seeing above note" { send "y\r" }
"Password incorrect" { send_user "Error: Check your password for $router\n";
catch {close}; wait; return 1 }
- "$prompt" { }
+ -re "$prompt" { }
denied { send_user "Error: Check your passwd for $router\n"
if { $do_command || $do_script } {
send "exit\r"
@@ -347,7 +360,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
return 1
}
}
- "\r\n" { exp_continue; }
+ "\r\n" { exp_continue; }
}
set in_proc 0
return 0
@@ -360,7 +373,7 @@ proc run_commands { prompt command } {
set in_proc 1
send "lines 0\r"
- expect $prompt {}
+ expect -re $prompt {}
regsub -all "\[)(]" $prompt {\\&} reprompt
@@ -368,21 +381,20 @@ proc run_commands { prompt command } {
if [ string match "*\;*" "$command" ] {
set commands [split $command \;]
set num_commands [llength $commands]
-
for {set i 0} {$i < $num_commands} { incr i} {
send "[subst -nocommands [lindex $commands $i]]\r"
expect {
- -re "^\[^\n\r]*$reprompt." {}
+ -re "^\[^\n\r]*$reprompt" {}
-re "^\[^\n\r ]*>>.*$reprompt" { exp_continue }
- -re "\[\n\r]" { exp_continue }
+ -re "\[\n\r]+" { exp_continue }
}
}
} else {
send "[subst -nocommands $command]\r"
expect {
- -re "^\[^\n\r]*$reprompt." {}
+ -re "^\[^\n\r]*$reprompt" {}
-re "^\[^\n\r ]*>>.*$reprompt" { exp_continue }
- -re "\[\n\r]" { exp_continue }
+ -re "\[\n\r]+" { exp_continue }
}
}
send "exit\r"
@@ -410,9 +422,10 @@ foreach router [lrange $argv $i end] {
send_user "$router\n"
# Figure out prompt.
- set prompt "#"
- set autoenable 1
- set enable 0
+ set prompt ">> \[^\r\n]*\[#|>] "
+ # alteon only "enables" based on the password used at login time
+ set autoenable 1
+ set enable 0
# Figure out passwords
if { $do_passwd } {
@@ -472,7 +485,7 @@ foreach router [lrange $argv $i end] {
}
} elseif { $do_script } {
send "lines 0\r"
- expect $prompt {}
+ expect -re $prompt {}
source $sfile
close
} else {