diff options
Diffstat (limited to 'bin/hlogin.in')
-rw-r--r-- | bin/hlogin.in | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/bin/hlogin.in b/bin/hlogin.in index e372fe0..f1cbf51 100644 --- a/bin/hlogin.in +++ b/bin/hlogin.in @@ -3,7 +3,7 @@ ## $Id$ ## ## @PACKAGE@ @VERSION@ -## Copyright (c) 1997-2008 by Terrapin Communications, Inc. +## Copyright (c) 1997-2009 by Terrapin Communications, Inc. ## All rights reserved. ## ## This code is derived from software contributed to and maintained by @@ -53,7 +53,7 @@ # # Usage line -set usage "Usage: $argv0 \[-dV\] \[-autoenable\] \[-noenable\] \[-c command\] \ +set usage "Usage: $argv0 \[-dSV\] \[-autoenable\] \[-noenable\] \[-c command\] \ \[-Evar=x\] \[-e enable-password\] \[-f cloginrc-file\] \[-p user-password\] \ \[-s script-file\] \[-t timeout\] \[-u username\] \ \[-v vty-password\] \[-w enable-username\] \[-x command-file\] \ @@ -78,6 +78,8 @@ set do_passwd 1 set do_enapasswd 1 # attempt at platform switching. set platform "" +# Save config, if prompted +set do_saveconfig 0 # set send_human {.2 .1 .4 .2 1} @@ -114,15 +116,13 @@ for {set i 0} {$i < $argc} {incr i} { -d* { exp_internal 1 # Username - } -u* - - -U* { + } -u* { if {! [ regexp .\[uU\](.+) $arg ignore user]} { incr i set username [ lindex $argv $i ] } # VTY Password - } -p* - - -P* { + } -p* { if {! [ regexp .\[pP\](.+) $arg ignore userpasswd]} { incr i set userpasswd [ lindex $argv $i ] @@ -140,15 +140,13 @@ for {set i 0} {$i < $argc} {incr i} { send_user "@PACKAGE@ @VERSION@\n" exit 0 # Enable Username - } -w* - - -W* { + } -w* { if {! [ regexp .\[wW\](.+) $arg ignore enauser]} { incr i set enausername [ lindex $argv $i ] } # Environment variable to pass to -s scripts - } -E* - { + } -E* { if {[ regexp .\[E\](.+)=(.+) $arg ignore varname varvalue]} { set E$varname $varvalue } else { @@ -156,24 +154,21 @@ for {set i 0} {$i < $argc} {incr i} { exit 1 } # Enable Password - } -e* - { + } -e* { if {! [ regexp .\[e\](.+) $arg ignore enapasswd]} { incr i set enapasswd [ lindex $argv $i ] } set do_enapasswd 0 # Command to run. - } -c* - - -C* { + } -c* { if {! [ regexp .\[cC\](.+) $arg ignore command]} { incr i set command [ lindex $argv $i ] } set do_command 1 # Expect script to run. - } -s* - - -S* { + } -s* { if {! [ regexp .\[sS\](.+) $arg ignore sfile]} { incr i set sfile [ lindex $argv $i ] @@ -183,30 +178,29 @@ for {set i 0} {$i < $argc} {incr i} { exit 1 } set do_script 1 + # save config on exit + } -S* { + set do_saveconfig 1 # 'ssh -c' cypher type - } -y* - - -Y* { + } -y* { if {! [ regexp .\[eE\](.+) $arg ignore cypher]} { incr i set cypher [ lindex $argv $i ] } # alternate cloginrc file - } -f* - - -F* { + } -f* { if {! [ regexp .\[fF\](.+) $arg ignore password_file]} { incr i set password_file [ lindex $argv $i ] } # Timeout - } -t* - - -T* { + } -t* { if {! [ regexp .\[tT\](.+) $arg ignore timeout]} { incr i set timeout [ lindex $argv $i ] } # Command file - } -x* - - -X { + } -x* { if {! [ regexp .\[xX\](.+) $arg ignore cmd_file]} { incr i set cmd_file [ lindex $argv $i ] @@ -413,14 +407,16 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } { send "yes\r" send_user "\nHost $router added to the list of known hosts.\n" exp_continue } - -re "HOST IDENTIFICATION HAS CHANGED.* \(yes\/no\)\?" { + -re "HOST IDENTIFICATION HAS CHANGED.* \(yes\/no\)\?" { send "no\r" send_user "\nError: The host key for $router has changed. Update the SSH known_hosts file accordingly.\n" - return 1 } - -re "Offending key for .* \(yes\/no\)\?" { + return 1 + } + -re "Offending key for .* \(yes\/no\)\?" { send "no\r" send_user "\nError: host key mismatch for $router. Update the SSH known_hosts file accordingly.\n" - return 1 } + return 1 + } eof { send_user "\nError: Couldn't login\n"; wait; return 1 } -nocase "unknown host\r" { catch {close}; catch {wait}; @@ -500,7 +496,7 @@ proc do_enable { enauser enapasswd } { # Run commands given on the command line. proc run_commands { prompt command } { - global in_proc platform + global do_saveconfig in_proc platform set in_proc 1 # Turn off the pager and escape regex meta characters in the $prompt @@ -522,8 +518,7 @@ proc run_commands { prompt command } { send -- "[subst -nocommands [lindex $commands $i]]\r" expect { -re "^\[^\n\r *]*$reprompt" { catch {send_user -- "$expect_out(buffer)"} } - -re "^\[^\n\r]*$reprompt." { catch {send_user -- "$expect_out(buffer)"} - exp_continue } + -re "^\[^\n\r]*$reprompt " { catch {send_user -- "$expect_out(buffer)"} } -re "\[\n\r]+" { catch {send_user -- "$expect_out(buffer)"} exp_continue } -re "\[^\r\n]*Press <SPACE> to cont\[^\r\n]*" { @@ -558,11 +553,19 @@ proc run_commands { prompt command } { send -h "exit\r" expect { "Do you want to save current configuration" { - catch {send "n\r"} + if {$do_saveconfig} { + catch {send "y\r"} + } else { + catch {send "n\r"} + } exp_continue } - "Do you wish to save " { - catch {send "n\r"} + "Do you wish to save " { + if {$do_saveconfig} { + catch {send "y\r"} + } else { + catch {send "n\r"} + } exp_continue } "Do you want to log out" { @@ -701,6 +704,7 @@ foreach router [lrange $argv $i end] { if { "$sshcmd" == "" } { set sshcmd {ssh} } # Adjust our path to find hpuifilter + set hpf_path "" regexp {(.*)/[^/]+} $argv0 junk hpf_path if { "$hpf_path" != "" && "$hpf_path" != "." } { append env(PATH) ":$hpf_path" |