summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorTar Committer <tar@ocjtech.us>2005-07-07 01:14:43 +0000
committerTar Committer <tar@ocjtech.us>2005-07-07 01:14:43 +0000
commit96dc4026054df77affedfe50380a661dcdba732a (patch)
tree0c8de7e68e7f316bf312cecce0b76e1f76b63020 /bin
parent4d684aecaacc9a59e7e9c0661934aeba0b16efec (diff)
downloadrancid-96dc4026054df77affedfe50380a661dcdba732a.tar.gz
rancid-96dc4026054df77affedfe50380a661dcdba732a.tar.xz
rancid-96dc4026054df77affedfe50380a661dcdba732a.zip
Imported from rancid-2.3.2a2.tar.gz.rancid-2.3.2a2
Diffstat (limited to 'bin')
-rw-r--r--bin/Makefile.in32
-rw-r--r--bin/alogin.in269
-rw-r--r--bin/arancid.in94
-rw-r--r--bin/blogin.in46
-rw-r--r--bin/brancid.in62
-rw-r--r--bin/cat5rancid.in112
-rw-r--r--bin/clogin.in29
-rw-r--r--bin/control_rancid.in63
-rw-r--r--bin/cssrancid.in57
-rw-r--r--bin/elogin.in33
-rw-r--r--bin/erancid.in63
-rw-r--r--bin/f10rancid.in125
-rw-r--r--bin/flogin.in64
-rw-r--r--bin/fnrancid.in66
-rw-r--r--bin/francid.in69
-rw-r--r--bin/hlogin.in20
-rw-r--r--bin/hpuifilter.c12
-rw-r--r--bin/hrancid.in66
-rw-r--r--bin/htlogin.in33
-rw-r--r--bin/htrancid.in56
-rw-r--r--bin/jerancid.in65
-rw-r--r--bin/jlogin.in28
-rw-r--r--bin/jrancid.in101
-rw-r--r--bin/mrancid.in52
-rw-r--r--bin/nlogin.in265
-rw-r--r--bin/nrancid.in109
-rw-r--r--bin/nslogin.in29
-rw-r--r--bin/nsrancid.in60
-rw-r--r--bin/par.in6
-rwxr-xr-xbin/prancid.in61
-rw-r--r--bin/rancid-fe.in4
-rw-r--r--bin/rancid-run.in4
-rw-r--r--bin/rancid.in215
-rw-r--r--bin/rivlogin.in151
-rw-r--r--bin/rivrancid.in79
-rw-r--r--bin/rrancid.in75
-rw-r--r--bin/tntlogin.in50
-rw-r--r--bin/tntrancid.in78
-rw-r--r--bin/xrancid.in67
-rwxr-xr-xbin/zrancid.in50
40 files changed, 1646 insertions, 1274 deletions
diff --git a/bin/Makefile.in b/bin/Makefile.in
index 99a55ca..2bcfa3e 100644
--- a/bin/Makefile.in
+++ b/bin/Makefile.in
@@ -1,8 +1,8 @@
-# Makefile.in generated by automake 1.8.4 from Makefile.am.
+# Makefile.in generated by automake 1.9.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004 Free Software Foundation, Inc.
+# 2003, 2004, 2005 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -80,7 +80,6 @@ SCRIPTS = $(bin_SCRIPTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
-@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/hpuifilter.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
@@ -175,6 +174,8 @@ am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
bindir = @bindir@
build_alias = @build_alias@
datadir = @datadir@
@@ -198,15 +199,12 @@ target_alias = @target_alias@
#AUTOMAKE_OPTIONS=foreign no-dependencies
AUTOMAKE_OPTIONS = foreign
-bin_SCRIPTS = cat5rancid control_rancid \
- alogin arancid clogin blogin brancid cssrancid \
- elogin erancid f10rancid flogin francid fnrancid \
- jlogin jrancid jerancid \
- hlogin hrancid htlogin htrancid \
- mrancid nlogin nrancid nslogin nsrancid par prancid \
- rancid rancid-fe rivlogin rivrancid rrancid \
- tntlogin tntrancid xrancid zrancid\
-lg.cgi lgform.cgi rancid-cvs rancid-run
+bin_SCRIPTS = cat5rancid control_rancid alogin arancid clogin blogin \
+ brancid cssrancid elogin erancid f10rancid flogin francid \
+ fnrancid jlogin jrancid jerancid hlogin hrancid htlogin \
+ htrancid mrancid nlogin nrancid nslogin nsrancid par prancid \
+ rancid rancid-fe rivlogin rivrancid rrancid tntlogin tntrancid \
+ xrancid zrancid lg.cgi lgform.cgi rancid-cvs rancid-run
EXTRA_DIST = lg.cgi.in lgform.cgi.in rancid-cvs.in rancid-run.in
#dist_bin_SCRIPTS= $(bin_SCRIPTS:%=%.in)
CLEANFILES = lg.cgi lgform.cgi rancid-cvs rancid-run
@@ -403,16 +401,14 @@ distclean-compile:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
uninstall-info-am:
@@ -437,7 +433,7 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
- test -z "$$unique" && unique=$$empty_fix; \
+ test -n "$$unique" || unique=$$empty_fix; \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique; \
fi
@@ -518,7 +514,7 @@ clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
- -rm -f $(CONFIG_CLEAN_FILES)
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
diff --git a/bin/alogin.in b/bin/alogin.in
index c0e5c40..537c506 100644
--- a/bin/alogin.in
+++ b/bin/alogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
-#
-## $Id: alogin.in,v 1.24 2004/12/24 21:00:31 tex Exp $
+##
+## $Id: alogin.in,v 1.30 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -24,13 +24,247 @@
# alogin - Alteon WebOS switch login
#
# afort@choqolat.org is responsible for this particular mess
-# (andrew fort)
+# (andrew fort)
+#
+
+# Usage line
+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:
+# x == do not set xterm banner or name
+
+# Password file
+set password_file $env(HOME)/.cloginrc
+# Default is to login to the router
+set do_command 0
+set do_script 0
+# The default is to automatically enable
+set avenable 1
+# The default is that you login non-enabled (tacacs can have you login already
+# enabled)
+set avautoenable 0
+# The default is to look in the password file to find the passwords. This
+# tracks if we receive them on the command line.
+set do_passwd 1
+
+# Find the user in the ENV, or use the unix userid.
+if {[ info exists env(CISCO_USER) ]} {
+ set default_user $env(CISCO_USER)
+} elseif {[ info exists env(USER) ]} {
+ set default_user $env(USER)
+} elseif {[ info exists env(LOGNAME) ]} {
+ set default_user $env(LOGNAME)
+} else {
+ # This uses "id" which I think is portable. At least it has existed
+ # (without options) on all machines/OSes I've been on recently -
+ # unlike whoami or id -nu.
+ if [ catch {exec id} reason ] {
+ send_error "\nError: could not exec id: $reason\n"
+ exit 1
+ }
+ regexp {\(([^)]*)} "$reason" junk default_user
+}
+
+# Sometimes routers take awhile to answer (the default is 10 sec)
+set timeout 45
+
+# Process the command line
+for {set i 0} {$i < $argc} {incr i} {
+ set arg [lindex $argv $i]
+
+ switch -glob -- $arg {
+ # Username
+ -u* -
+ -U* {
+ if {! [ regexp .\[uU\](.+) $arg ignore user]} {
+ incr i
+ set username [ lindex $argv $i ]
+ }
+ # VTY Password
+ } -v* -
+ -v* {
+ if {! [ regexp .\[vV\](.+) $arg ignore passwd]} {
+ incr i
+ set passwd [ lindex $argv $i ]
+ }
+ set do_passwd 0
+ # Enable Username
+ } -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 "\nError: invalid format for -E in $arg\n"
+ exit 1
+ }
+ # Enable Password
+ } -e*
+ {
+ # ignore -e
+ # Command to run.
+ } -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* {
+ if {! [ regexp .\[sS\](.+) $arg ignore sfile]} {
+ incr i
+ set sfile [ lindex $argv $i ]
+ }
+ if { ! [ file readable $sfile ] } {
+ send_user "\nError: Can't read $sfile\n"
+ exit 1
+ }
+ set do_script 1
+ # 'ssh -c' cypher type
+ } -y* -
+ -Y* {
+ if {! [ regexp .\[eE\](.+) $arg ignore cypher]} {
+ incr i
+ set cypher [ lindex $argv $i ]
+ }
+ # alternate cloginrc file
+ } -f* -
+ -F* {
+ if {! [ regexp .\[fF\](.+) $arg ignore password_file]} {
+ incr i
+ set password_file [ lindex $argv $i ]
+ }
+ # Timeout
+ } -t* -
+ -T* {
+ if {! [ regexp .\[tT\](.+) $arg ignore timeout]} {
+ incr i
+ set timeout [ lindex $argv $i ]
+ }
+ # Command file
+ } -x* -
+ -X {
+ if {! [ regexp .\[xX\](.+) $arg ignore cmd_file]} {
+ incr i
+ set cmd_file [ lindex $argv $i ]
+ }
+ 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] \;]
+ set do_command 1
+ # Do we enable?
+ } -noenable {
+ # ignore -noenable
+ # Does tacacs automatically enable us?
+ } -autoenable {
+ # ignore -autoenable
+ } -* {
+ send_user "\nError: Unknown argument! $arg\n"
+ send_user $usage
+ exit 1
+ } default {
+ break
+ }
+ }
+}
+# Process routers...no routers listed is an error.
+if { $i == $argc } {
+ send_user "\nError: $usage"
+}
+
+# Only be quiet if we are running a script (it can log its output
+# on its own)
+if { $do_script } {
+ log_user 0
+} else {
+ log_user 1
+}
+
+#
+# Done configuration/variable setting. Now run with it...
#
-# alogin: doesn't understand enable. It will just ignore the enable options.
-@INCLUDE login.top@
+# Sets Xterm title if interactive...if its an xterm and the user cares
+proc label { host } {
+ global env
+ # if CLOGIN has an 'x' in it, don't set the xterm name/banner
+ if [info exists env(CLOGIN)] {
+ if {[string first "x" $env(CLOGIN)] != -1} { return }
+ }
+ # take host from ENV(TERM)
+ if [info exists env(TERM)] {
+ if [regexp \^(xterm|vs) $env(TERM) ignore ] {
+ send_user "\033]1;[lindex [split $host "."] 0]\a"
+ send_user "\033]2;$host\a"
+ }
+ }
+}
+
+# This is a helper function to make the password file easier to
+# maintain. Using this the password file has the form:
+# add password sl* pete cow
+# add password at* steve
+# add password * hanky-pie
+proc add {var args} { global int_$var ; lappend int_$var $args}
+proc include {args} {
+ global env
+ regsub -all "(^{|}$)" $args {} args
+ if { [ regexp "^/" $args ignore ] == 0 } {
+ set args $env(HOME)/$args
+ }
+ source_password_file $args
+}
+
+proc find {var router} {
+ upvar int_$var list
+ if { [info exists list] } {
+ foreach line $list {
+ if { [string match [lindex $line 0] $router ] } {
+ return [lrange $line 1 end]
+ }
+ }
+ }
+ return {}
+}
+
+# Loads the password file. Note that as this file is tcl, and that
+# it is sourced, the user better know what to put in there, as it
+# could install more than just password info... I will assume however,
+# that a "bad guy" could just as easy put such code in the clogin
+# script, so I will leave .cloginrc as just an extention of that script
+proc source_password_file { password_file } {
+ global env
+ if { ! [file exists $password_file] } {
+ send_user "\nError: password file ($password_file) does not exist\n"
+ exit 1
+ }
+ file stat $password_file fileinfo
+ if { [expr ($fileinfo(mode) & 007)] != 0000 } {
+ send_user "\nError: $password_file must not be world readable/writable\n"
+ exit 1
+ }
+ if [ catch {source $password_file} reason ] {
+ send_user "\nError: $reason\n"
+ exit 1
+ }
+}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd prompt cmethod cyphertype } {
global spawn_id in_proc do_command do_script
global u_prompt p_prompt sshcmd
@@ -40,6 +274,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -49,23 +284,23 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
- } elseif ![string compare $prog "ssh"] {
+ } elseif ![string compare $prog "ssh"] {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
- }
- } elseif ![string compare $prog "rsh"] {
- if [ catch {spawn rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ return 1
}
- } else {
- puts "\nError: unknown connection method: $prog"
+ } elseif ![string compare $prog "rsh"] {
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
+ }
+ continue;
+ } else {
+ send_user "\nError: unknown connection method: $prog\n"
return 1
- }
- incr progs -1
+ }
sleep 0.3
# This helps cleanup each expect clause.
diff --git a/bin/arancid.in b/bin/arancid.in
index a2bf1ef..4c843b2 100644
--- a/bin/arancid.in
+++ b/bin/arancid.in
@@ -1,8 +1,8 @@
#! @PERLV_PATH@
##
-## $Id: arancid.in,v 1.14 2004/01/11 03:49:13 heas Exp $
+## $Id: arancid.in,v 1.19 2005/06/15 20:55:12 heas Exp $
##
-## Hacked version of rancid for Alteon WebOS switches
+## Hacked version of rancid for Alteon WebOS switches
## tested with: ad3 v8.1.18
## afort@choqolat.org (andrew fort)
##
@@ -24,7 +24,7 @@
##
#
# RANCID - Really Awesome New Cisco confIg Differ
-#
+#
# arancid - Alteon WebOS plugin for rancid
#
# usage: arancid [-d] [-l] [-f filename | $host]
@@ -38,13 +38,16 @@ $host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
$prompt = "#";
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # alogin timeout in seconds
+
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -66,10 +69,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -79,10 +82,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -92,10 +95,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -105,9 +108,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -121,7 +124,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -134,7 +137,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -142,23 +145,23 @@ sub sortbyipaddr {
# This routine parses "/info/sys" (cf. show version)
sub ShowVersion {
- print STDERR " In ShowVersion: $_" if ($debug);
+ print STDERR " In ShowVersion: $_" if ($debug);
+
+ while (<INPUT>) {
+ tr/\015//d;
+ last if (/^>>.*$prompt/);
+ next if(/^(\s*|\s*$cmd\s*)$/);
- while (<INPUT>) {
- tr/\015//d;
- last if (/^>>.*$prompt/);
- next if(/^(\s*|\s*$cmd\s*)$/);
-
- /^(ACEdirector.*|ACEswitch.*|Alteon.*)/i &&
+ /^(ACEdirector.*|ACEswitch.*|Alteon.*)/i &&
ProcessHistory("COMMENTS","keysort","A1", "\/\*Model: $1\n") && next;
/^Software Version\s+(.*?)\s\((.*)\)/i &&
ProcessHistory("COMMENTS","keysort","B1", "\/\*Image: Software: $1 ($2)\n") && next;
/^Hardware Part No:\s+(.*?)\s+/i &&
ProcessHistory("COMMENTS","keysort","A2", "\/\*Hardware part no: $1\n") && next;
/^MAC address:\s+([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})/i &&
- ProcessHistory("COMMENTS","keysort","C1", "\/\*Base MAC address: $1\n") && next;
- }
- return(0);
+ ProcessHistory("COMMENTS","keysort","C1", "\/\*Base MAC address: $1\n") && next;
+ }
+ return(0);
}
# This routine processes a "/cfg/dump"
@@ -170,10 +173,10 @@ sub WriteTerm {
# now just copy it verbatim to the history file
while (<INPUT>) {
- tr/\015//d;
- last if(/^>>.*$prompt/);
+ tr/\015//d;
+ last if(/^>>.*$prompt/);
chop;
- if (/(rcomm|wcomm|t1com|t2com)(\s+)(.*)/ &&
+ if (/(rcomm|wcomm|t1com|t2com)(\s+)(.*)/ &&
defined($ENV{'NOCOMMSTR'})) {
ProcessHistory("","","","\/\*\t$1$2\"<removed>\"\n") && next;
}
@@ -183,8 +186,8 @@ sub WriteTerm {
next if (/^\/\* Configuration dump taken/i);
next if (/^\/\* Version.*Base MAC.*/i);
- if (/^\/?script end/) {
- $found_end = 1;
+ if (/^\/?script end/) {
+ $found_end = 1;
ProcessHistory("","","","$_\n");
return(1);
}
@@ -198,16 +201,15 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- '/info/sys' => "ShowVersion",
- '/cfg/dump' => "WriteTerm",
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "/info/sys",
- "/cfg/dump",
+@commandtable = (
+ {'/info/sys' => 'ShowVersion'},
+ {'/cfg/dump' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -237,13 +239,13 @@ ProcessHistory("COMMENTS","keysort","F0","\/\*\n");
TOP: while(<INPUT>) {
tr/\015//d;
if (/^>>.*$prompt exit/) {
- $clean_run=1;
- last;
+ $clean_run=1;
+ last;
}
while (/>>.*$prompt\s*($cmds_regexp)\s*$/) {
- $cmd = $1;
- if (!defined($prompt)) {
+ $cmd = $1;
+ if (!defined($prompt)) {
$prompt = ($_ =~ /^([^#]+#)/)[0];
$prompt =~ s/([][}{)(\\])/\\$1/g;
print STDERR ("PROMPT MATCH: $prompt\n") if ($debug);
@@ -252,7 +254,7 @@ TOP: while(<INPUT>) {
if (!defined($commands{$cmd})) {
print STDERR "$host: found unexpected command - \"$cmd\"\n";
$clean_run = 0;
- last TOP;
+ last TOP;
}
$rval = &{$commands{$cmd}};
delete($commands{$cmd});
diff --git a/bin/blogin.in b/bin/blogin.in
index 90843ed..63dae4c 100644
--- a/bin/blogin.in
+++ b/bin/blogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: blogin.in,v 1.23 2004/02/02 17:38:36 heas Exp $
+## $Id: blogin.in,v 1.28 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -56,7 +56,7 @@ set do_passwd 1
set do_enapasswd 0
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -112,14 +112,14 @@ for {set i 0} {$i < $argc} {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 {
send_user "\nError: invalid format for -E in $arg\n"
exit 1
- }
+ }
# Enable Password
} -e*
{
@@ -237,25 +237,25 @@ proc label { host } {
# add password * hanky-pie
proc add {var args} { global int_$var ; lappend int_$var $args}
proc include {args} {
- global env
- regsub -all "(^{|}$)" $args {} args
+ global env
+ regsub -all "(^{|}$)" $args {} args
if { [ regexp "^/" $args ignore ] == 0 } {
set args $env(HOME)/$args
- }
+ }
source_password_file $args
-}
-
+}
+
proc find {var router} {
- upvar int_$var list
+ upvar int_$var list
if { [info exists list] } {
foreach line $list {
if { [string match [lindex $line 0] $router ] } {
return [lrange $line 1 end]
- }
- }
- }
- return {}
-}
+ }
+ }
+ }
+ return {}
+}
# Loads the password file. Note that as this file is tcl, and that
# it is sourced, the user better know what to put in there, as it
@@ -280,6 +280,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd enapasswd prompt cmethod cyphertype } {
global spawn_id in_proc do_command do_script
global u_prompt p_prompt e_prompt sshcmd
@@ -288,6 +289,7 @@ proc login { router user userpswd passwd enapasswd prompt cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -297,23 +299,23 @@ proc login { router user userpswd passwd enapasswd prompt cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "ssh"] {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "rsh"] {
- if [ catch {spawn rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue;
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
diff --git a/bin/brancid.in b/bin/brancid.in
index c2e602e..8cb3e69 100644
--- a/bin/brancid.in
+++ b/bin/brancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: brancid.in,v 1.16 2004/01/11 03:49:13 heas Exp $
+## $Id: brancid.in,v 1.21 2005/06/15 20:55:13 heas Exp $
## hacked version of Hank's rancid - this one tries to deal with Bay's.
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
@@ -32,15 +32,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # blogin timeout in seconds
+$timeo = 90; # blogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -62,10 +63,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -75,10 +76,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -88,10 +89,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -101,9 +102,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -117,7 +118,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -130,7 +131,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -158,8 +159,8 @@ sub ShowConfig {
}
# ProcessHistory("","","","!$_");
if (/exit$/) {
- $found_end = 1;
- return(1);
+ $found_end = 1;
+ return(1);
}
return(0);
}
@@ -186,20 +187,17 @@ sub RunCommand {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'bcc' => "RunCommand",
- 'show config' => "ShowConfig",
- 'show config -all' => "ShowConfig",
- 'exit' => "RunCommand"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "bcc",
- "show config",
- "show config -all",
- "exit"
+@commandtable = (
+ {'bcc' => 'RunCommand'},
+ {'show config' => 'ShowConfig'},
+ {'show config -all' => 'ShowConfig'},
+ {'exit' => 'RunCommand'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -225,7 +223,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/cat5rancid.in b/bin/cat5rancid.in
index 174aead..bea31bb 100644
--- a/bin/cat5rancid.in
+++ b/bin/cat5rancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: cat5rancid.in,v 1.37 2005/03/20 22:15:35 heas Exp $
+## $Id: cat5rancid.in,v 1.43 2005/06/20 21:24:30 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -31,16 +31,17 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
my(%modules); # module info (part from sh ver, part from sh module)
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -62,10 +63,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -75,10 +76,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -88,10 +89,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -101,9 +102,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -117,7 +118,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -130,7 +131,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -671,8 +672,8 @@ sub ShowModule {
print STDERR " In ShowModule: $_" if ($debug);
OUTER:while (<INPUT>) {
- tr/\015//d;
- last if(/^$prompt/);
+ tr/\015//d;
+ last if(/^$prompt/);
# stuff module type into %module
if (/^Mod\s+Slot\s+Ports/) {
<INPUT>;
@@ -696,7 +697,7 @@ OUTER:while (<INPUT>) {
}
next;
}
- # one does it one way... pita
+ # one does it one way... pita
if (/^Mod\s+Module-Name\s+Ports/) {
<INPUT>;
#my($slot);
@@ -713,7 +714,7 @@ OUTER:while (<INPUT>) {
}
next;
}
- # daughter boards
+ # daughter boards
if (/^Mod\s+Sub-Type/) {
<INPUT>;
my($slot, $board);
@@ -767,7 +768,7 @@ OUTER:while (<INPUT>) {
ProcessHistory("MODS","","",$model);
if ($dboards) {ProcessHistory("MODS","","",$dboards);}
}
-}
+}
# This routine processes a "show port ifindex"
sub ShowPortIfindex {
@@ -790,7 +791,10 @@ sub ShowPortIfindex {
sub WriteTerm {
print STDERR " In WriteTerm: $_" if ($debug);
- ProcessHistory("","","","!\n");
+ if (! $found_end) {
+ ProcessHistory("","","","!\n");
+ }
+
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
@@ -822,9 +826,9 @@ sub WriteTerm {
/^#Time: / && next;
# Dog gone Cool matches to process the rest of the config
- /^#time: / && next; # kill time:
- /^tftp-server flash / && next; # kill any tftp remains
- /^ntp clock-period / && next; # kill ntp clock-period
+ /^#time: / && next; # kill time:
+ /^tftp-server flash / && next; # kill any tftp remains
+ /^ntp clock-period / && next; # kill ntp clock-period
/^ length / && next; # kill length on serial lines
/^ width / && next; # kill width on serial lines
if (/^enable password / && $filter_pwds >= 1) {
@@ -925,15 +929,15 @@ sub WriteTerm {
# order logging statements
/^set logging server (\d+\.\d+\.\d+\.\d+)/ &&
ProcessHistory("LOGGING","ipsort","$1","$_") && next;
- # order/prune snmp-server host statements
- # we only prune lines of the form
- # snmp-server host a.b.c.d <community>
+ # order/prune snmp-server host statements
+ # we only prune lines of the form
+ # snmp-server host a.b.c.d <community>
if (/^set snmp trap (\d+\.\d+\.\d+\.\d+) /) {
if (defined($ENV{'NOCOMMSTR'})) {
ProcessHistory("SNMPSERVERHOST","ipsort","$1","!set snmp trap $1 <removed>\n");
} else {
ProcessHistory("SNMPSERVERHOST","ipsort","$1","$_");
- }
+ }
next;
}
if (/^(set snmp community) (\S+) (\S+)/) {
@@ -991,38 +995,26 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'show boot' => "ShowBoot",
- 'show flash' => "ShowFlash",
- 'dir bootflash:' => "DirSlotN",
- 'dir slot0:' => "DirSlotN",
- 'dir slot1:' => "DirSlotN",
- 'dir sup-bootflash:' => "DirSlotN",
- 'dir sup-microcode:' => "DirSlotN",
- 'show module' => "ShowModule",
- 'show port ifindex' => "ShowPortIfindex",
- 'write term all' => "WriteTerm",
- 'write term' => "WriteTerm",
- 'show running-config' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version",
- "show boot",
- "show flash",
- "dir bootflash:",
- "dir slot0:",
- "dir slot1:",
- "dir sup-bootflash:",
- "dir sup-microcode:",
- "show module",
- "show port ifindex",
- "write term all",
- "write term",
- "show running-config"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'show boot' => 'ShowBoot'},
+ {'show flash' => 'ShowFlash'},
+ {'dir bootflash:' => 'DirSlotN'},
+ {'dir slot0:' => 'DirSlotN'},
+ {'dir slot1:' => 'DirSlotN'},
+ {'dir sup-bootflash:' => 'DirSlotN'},
+ {'dir sup-microcode:' => 'DirSlotN'},
+ {'show module' => 'ShowModule'},
+ {'show port ifindex' => 'ShowPortIfindex'},
+ {'write term all' => 'WriteTerm'},
+ {'write term' => 'WriteTerm'},
+ {'show running-config' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
diff --git a/bin/clogin.in b/bin/clogin.in
index 92bb2f8..d4f27db 100644
--- a/bin/clogin.in
+++ b/bin/clogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: clogin.in,v 1.79 2004/05/27 21:57:52 heas Exp $
+## $Id: clogin.in,v 1.85 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -59,7 +59,7 @@ set do_enapasswd 1
set platform ""
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -286,6 +286,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
global spawn_id in_proc do_command do_script platform
global prompt u_prompt p_prompt e_prompt sshcmd
@@ -295,6 +296,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -304,7 +306,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif [string match "ssh*" $prog] {
regexp {ssh(:([^[:space:]]+))*} $prog command suffix port
@@ -316,18 +318,23 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "rsh"] {
+ if { ! $do_command } {
+ if { $progs == 0 } {
+ return 1
+ }
+ continue;
+ }
if [ catch {spawn rsh -l $user $router} reason ] {
send_user "\nError: rsh failed: $reason\n"
- exit 1
+ return 1
}
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
@@ -617,10 +624,10 @@ foreach router [lrange $argv $i end] {
set router [string tolower $router]
send_user "$router\n"
- # Figure out prompt.
- # Since autoenable is off by default, if we have it defined, it
- # was done on the command line. If it is not specifically set on the
- # command line, check the password file.
+ # Figure out the prompt.
+ # autoenable is off by default. If we have it defined, it was done
+ # on the command line. If it is not specifically set on the command
+ # line, check the password file.
if $avautoenable {
set autoenable 1
set enable 0
diff --git a/bin/control_rancid.in b/bin/control_rancid.in
index bcfd316..c33411e 100644
--- a/bin/control_rancid.in
+++ b/bin/control_rancid.in
@@ -1,6 +1,6 @@
#! /bin/sh
##
-## $Id: control_rancid.in,v 1.64 2004/03/12 23:13:09 heas Exp $
+## $Id: control_rancid.in,v 1.69 2005/07/07 01:09:08 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -81,13 +81,23 @@ DIR=$BASEDIR/$GROUP
TMP=${TMPDIR:=/tmp}/rancid.$GROUP.$$
trap 'rm -fr $TMP;' 1 2 15
-# the receipient(s) of diffs
+# the receipient(s) of diffs & mail options
mailrcpt=${mailrcpt:-"@MAILPLUS@${GROUP}${MAILDOMAIN}"}; export mailrcpt
-adminmailrcpt=${mailrcpt:-"@ADMINMAILPLUS@${GROUP}${MAILDOMAIN}"};
+adminmailrcpt=${adminmailrcpt:-"@ADMINMAILPLUS@${GROUP}${MAILDOMAIN}"};
export adminmailrcpt
+set | grep MAILHEADERS= > /dev/null 2>&1
+if [ $? -ne 0 ] ; then
+ MAILHEADERS="Precedence: bulk\n"; export MAILHEADERS
+fi
# Number of things par should run in parallel.
PAR_COUNT=${PAR_COUNT:-5}
+# Number of times failed collections should be retried. Minimum 1.
+MAX_ROUNDS=${MAX_ROUNDS:-4}
+if [ $MAX_ROUNDS -lt 1 ] ; then
+ echo "Error: MAX_ROUNDS must be at least 1."
+ MAX_ROUNDS=1
+fi
# Bail if we do not have the necessary info to run
if [ ! -d $DIR ]
@@ -97,7 +107,7 @@ then
(
echo "To: $adminmailrcpt"
echo "Subject: no $GROUP directory"
- echo "Precedence: bulk"
+ echo "$MAILHEADERS" | awk '{gsub(/\\n/,"\n");print;}'
echo ""
echo "$DIR does not exist."
echo "Run bin/rancid-cvs $GROUP to make all of the needed directories."
@@ -123,7 +133,7 @@ then
(
echo "To: $adminmailrcpt"
echo "Subject: no $GROUP/router.db file"
- echo "Precedence: bulk"
+ echo "$MAILHEADERS" | awk '{gsub(/\\n/,"\n");print;}'
echo ""
echo "$DIR/router.db does not exist."
) | sendmail -t
@@ -134,7 +144,7 @@ fi
cd $DIR
trap 'rm -fr routers.db routers.all.new routers.down.new routers.up.new \
routers.mail routers.added routers.deleted $TMP;' 1 2 15
-sed -e '/^#/d' -e 's/^ *//' -e 's/ *$//' -e 's/ *: */:/g' router.db |
+sed -e '/^#/d' -e 's/^ *//' -e 's/ *$//' -e 's/ *: */:/g' router.db |
sort -u > routers.db
cut -d: -f1,2 routers.db > routers.all.new
if [ ! -f routers.all ] ; then touch routers.all; fi
@@ -175,10 +185,10 @@ then
WCDOWN=`comm -13 routers.down routers.down.new | wc -l | \
sed -e 's/^ *\([^ ]*\)/\1/'`
if [ $WCDOWN -eq 1 ] ; then
- echo Routers changed to down:
- comm -13 routers.down routers.down.new | \
+ echo Routers changed to down:
+ comm -13 routers.down routers.down.new | \
sed -e 's/^/ /'
- echo
+ echo
fi
fi
fi
@@ -193,14 +203,14 @@ then
if [ $WCADDED -gt 0 ]
then
- echo Added routers:
- cat routers.added
+ echo Added routers:
+ cat routers.added
echo
fi
if [ $WCDELETED -gt 0 ]
then
- echo Deleted routers:
- cat routers.deleted
+ echo Deleted routers:
+ cat routers.deleted
echo
fi
@@ -212,7 +222,7 @@ then
(
echo "To: $adminmailrcpt"
echo "Subject: changes in $GROUP routers"
- echo "Precedence: bulk"
+ echo "$MAILHEADERS" | awk '{gsub(/\\n/,"\n");print;}'
echo ""
cat routers.mail
) | sendmail -t
@@ -309,7 +319,7 @@ par -q -n $PAR_COUNT -c "rancid-fe \{}" $devlistfile
# This section will generate a list of missed routers
# and try to grab them again. It will run through
# $pass times.
-pass=4
+pass=$MAX_ROUNDS
round=1
if [ -f $DIR/routers.up.missed ]; then
rm -f $DIR/routers.up.missed
@@ -347,10 +357,10 @@ echo
# Make sure that no empty configs are accepted. Those that are non-empty
# are renamed from device_name.new -> device_name.
for router in `cat $devlistfile`
-do
+do
OFS=$IFS
IFS=':'
- set $router
+ set $router
IFS=$OFS
router=$1;
@@ -386,14 +396,15 @@ else
fi
# Mail out the diffs (if there are any).
-if [ -s $TMP.diff ]; then
- sendmail -t <<EMAIL
-To: $mailrcpt
-Subject: $subject
-Precedence: bulk
-
-`cat $TMP.diff`
-EMAIL
+if [ -s $TMP.diff ]
+then
+ (
+ echo "To: $mailrcpt"
+ echo "Subject: $subject"
+ echo "$MAILHEADERS" | awk '{gsub(/\\n/,"\n");print;}'
+ echo ""
+ cat $TMP.diff
+ ) | sendmail -t
fi
# If any machines have not been reached within the last $OLDTIME
@@ -410,7 +421,7 @@ then
(
echo "To: $adminmailrcpt"
echo "Subject: config fetcher problems - $GROUP"
- echo "Precedence: bulk"
+ echo "$MAILHEADERS" | awk '{gsub(/\\n/,"\n");print;}'
echo ""
echo "The following routers have not been successfully contacted for"
echo "more than $OLDTIME hours."
diff --git a/bin/cssrancid.in b/bin/cssrancid.in
index b737a4d..4b6afae 100644
--- a/bin/cssrancid.in
+++ b/bin/cssrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: cssrancid.in,v 1.5 2004/08/02 15:56:27 heas Exp $
+## $Id: cssrancid.in,v 1.10 2005/06/15 20:55:13 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -31,15 +31,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,7 +65,7 @@ sub numerically { $a <=> $b; }
# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,7 +78,7 @@ sub keynsort {
# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,7 +91,7 @@ sub keysort {
# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -102,7 +103,7 @@ sub valsort{
# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -116,7 +117,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -129,7 +130,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -293,9 +294,9 @@ sub ShowBoot {
}
if ($type !~ /^(12[04]|7)/) {
if ($type !~ /^(29|35)00/) {
- ProcessHistory("COMMENTS","keysort","H2","!BootFlash: $_");
+ ProcessHistory("COMMENTS","keysort","H2","!BootFlash: $_");
} else {
- ProcessHistory("COMMENTS","keysort","H1","!Variable: $_");
+ ProcessHistory("COMMENTS","keysort","H1","!Variable: $_");
}
} elsif (/variable/) {
ProcessHistory("COMMENTS","keysort","H1","!Variable: $_");
@@ -548,22 +549,18 @@ sub ShowRun {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'term length 65535' => "TermLength",
- 'copy profile user-profile' => "CopyProfile",
- 'show version' => "ShowVersion",
- 'show boot' => "ShowBoot",
- 'show run' => "ShowRun"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and show run last). pita
-@commands=(
- "term length 65535",
- "copy profile user-profile",
- "show version",
- "show boot",
- "show run"
+@commandtable = (
+ {'term length 65535' => 'TermLength'},
+ {'copy profile user-profile' => 'CopyProfile'},
+ {'show version' => 'ShowVersion'},
+ {'show boot' => 'ShowBoot'},
+ {'show run' => 'ShowRun'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -588,7 +585,7 @@ if ($file) {
}
# determine password filtering mode
-if ($ENV{"FILTER_PWDS"} =~ /no/i) {
+if ($ENV{"FILTER_PWDS"} =~ /no/i) {
$filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
diff --git a/bin/elogin.in b/bin/elogin.in
index 0a41285..e58f149 100644
--- a/bin/elogin.in
+++ b/bin/elogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: elogin.in,v 1.28 2004/02/02 17:38:36 heas Exp $
+## $Id: elogin.in,v 1.33 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -49,7 +49,7 @@ set avautoenable 0
set do_passwd 1
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -62,9 +62,9 @@ if {[ info exists env(CISCO_USER) ] } {
if [ catch {exec id} reason ] {
send_error "\nError: could not exec id: $reason\n"
exit 1
- }
+ }
regexp {\(([^)]*)} "$reason" junk default_user
-}
+}
# Sometimes routers take awhile to answer (the default is 10 sec)
set timeout 45
@@ -268,31 +268,44 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd prompt cmethod cyphertype } {
global spawn_id in_proc do_command do_script
global u_prompt p_prompt
set in_proc 1
- set uprompt_seen 0
+ set uprompt_seen 0
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
- set retval [ catch {spawn telnet $router} reason ]
- } else {
+ set retval [ catch {spawn telnet $router} reason ]
+ } else {
set retval [ catch {spawn telnet $router $port} reason ]
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
+ }
+ } elseif ![string compare $prog "ssh"] {
+ send_error "\nError: unsupported method: ssh\n"
+ if { $progs == 0 } {
+ return 1
+ }
+ continue
+ } elseif ![string compare $prog "rsh"] {
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
diff --git a/bin/erancid.in b/bin/erancid.in
index 20da43d..8f08721 100644
--- a/bin/erancid.in
+++ b/bin/erancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: erancid.in,v 1.18 2004/01/11 03:49:13 heas Exp $
+## $Id: erancid.in,v 1.23 2005/06/15 20:54:40 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -31,15 +31,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # elogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -61,10 +62,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -74,10 +75,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -87,10 +88,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -100,9 +101,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -116,7 +117,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -129,7 +130,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -168,8 +169,8 @@ sub ShowModule {
# now just copy it verbatim to the history file
while (<INPUT>) {
- tr/\015//d;
- last if(/Active\) >/);
+ tr/\015//d;
+ last if(/Active\) >/);
last if(/^$/);
chop;
ProcessHistory("SLOT","","","-$_\n");
@@ -186,8 +187,8 @@ sub WriteTerm {
# now just copy it verbatim to the history file
while (<INPUT>) {
- tr/\015//d;
- last if(/Active\) >/);
+ tr/\015//d;
+ last if(/Active\) >/);
chop;
if (/^\s*snmp/ && defined($ENV{'NOCOMMSTR'})) {
/snmp (getcomm|setcomm|trapcomm)(\s+)(\S*)/ &&
@@ -204,18 +205,16 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'version' => "ShowVersion",
- 'equipment' => "ShowModule",
- 'config' => "WriteTerm",
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "version",
- "equipment",
- "config",
+@commandtable = (
+ {'version' => 'ShowVersion'},
+ {'equipment' => 'ShowModule'},
+ {'config' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -241,7 +240,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/f10rancid.in b/bin/f10rancid.in
index 2c4e485..56ef691 100644
--- a/bin/f10rancid.in
+++ b/bin/f10rancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: f10rancid.in,v 1.11 2004/01/11 03:49:13 heas Exp $
+## $Id: f10rancid.in,v 1.16 2005/06/15 20:54:40 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -33,15 +33,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -63,10 +64,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -76,10 +77,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -89,10 +90,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -102,9 +103,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -118,7 +119,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -131,7 +132,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -416,9 +417,9 @@ sub ShowBoot {
}
if ($type !~ /^(12[04]|7)/) {
if ($type !~ /^(29|35)00/) {
- ProcessHistory("COMMENTS","keysort","H2","!BootFlash: $_");
+ ProcessHistory("COMMENTS","keysort","H2","!BootFlash: $_");
} else {
- ProcessHistory("COMMENTS","keysort","H1","!Variable: $_");
+ ProcessHistory("COMMENTS","keysort","H1","!Variable: $_");
}
} elsif (/variable/) {
ProcessHistory("COMMENTS","keysort","H1","!Variable: $_");
@@ -1109,62 +1110,38 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'show install active' => "ShowInstallActive",
- 'show env all' => "ShowEnv",
- 'show gsr chassis' => "ShowGSR",
- 'show boot' => "ShowBoot",
- 'show bootvar' => "ShowBoot",
- 'show variables boot' => "ShowBoot",
- 'show flash' => "ShowFlash",
- 'dir /all nvram:' => "DirSlotN",
- 'dir /all bootflash:' => "DirSlotN",
- 'dir /all slot0:' => "DirSlotN",
- 'dir /all disk0:' => "DirSlotN",
- 'dir /all slot1:' => "DirSlotN",
- 'dir /all disk1:' => "DirSlotN",
- "dir /all sup-bootflash:"=> "DirSlotN", # cat 6500-ios
- "dir /all sup-microcode:"=> "DirSlotN", # cat 6500-ios
- 'show controllers' => "ShowContAll",
- 'show controllers cbus' => "ShowContCbus",
- 'show diagbus' => "ShowDiagbus",
- 'show diag' => "ShowDiag",
- 'show module' => "ShowModule", # cat 6500-ios
- 'show c7200' => "ShowC7200",
- 'show vtp status' => "ShowVTP",
- 'show vlan' => "ShowVLAN",
- 'show running' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version",
- "show install active",
- "show env all",
- "show gsr chassis",
- "show boot",
- "show bootvar",
- "show variables boot",
- "show flash",
- "dir /all nvram:",
- "dir /all bootflash:",
- "dir /all slot0:",
- "dir /all disk0:",
- "dir /all slot1:",
- "dir /all disk1:",
- "dir /all sup-bootflash:",
- "dir /all sup-microcode:",
- "show controllers",
- "show controllers cbus",
- "show diagbus",
- "show diag",
- "show module",
- "show c7200",
- "show vtp status",
- "show vlan",
- "show running"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'show install active' => 'ShowInstallActive'},
+ {'show env all' => 'ShowEnv'},
+ {'show gsr chassis' => 'ShowGSR'},
+ {'show boot' => 'ShowBoot'},
+ {'show bootvar' => 'ShowBoot'},
+ {'show variables boot' => 'ShowBoot'},
+ {'show flash' => 'ShowFlash'},
+ {'dir /all nvram:' => 'DirSlotN'},
+ {'dir /all bootflash:' => 'DirSlotN'},
+ {'dir /all slot0:' => 'DirSlotN'},
+ {'dir /all disk0:' => 'DirSlotN'},
+ {'dir /all slot1:' => 'DirSlotN'},
+ {'dir /all disk1:' => 'DirSlotN'},
+ {'dir /all sup-bootflash:' => 'DirSlotN'},
+ {'dir /all sup-microcode:' => 'DirSlotN'},
+ {'show controllers' => 'ShowContAll'},
+ {'show controllers cbus' => 'ShowContCbus'},
+ {'show diagbus' => 'ShowDiagbus'},
+ {'show diag' => 'ShowDiag'},
+ {'show module' => 'ShowModule'},
+ {'show c7200' => 'ShowC7200'},
+ {'show vtp status' => 'ShowVTP'},
+ {'show vlan' => 'ShowVLAN'},
+ {'show running' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -1189,7 +1166,7 @@ if ($file) {
}
# determine password filtering mode
-if ($ENV{"FILTER_PWDS"} =~ /no/i) {
+if ($ENV{"FILTER_PWDS"} =~ /no/i) {
$filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
diff --git a/bin/flogin.in b/bin/flogin.in
index fd4cf93..49f057e 100644
--- a/bin/flogin.in
+++ b/bin/flogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: flogin.in,v 1.34 2004/10/27 21:33:08 heas Exp $
+## $Id: flogin.in,v 1.39 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -60,7 +60,7 @@ set do_passwd 1
set do_enapasswd 1
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -73,9 +73,9 @@ if {[ info exists env(CISCO_USER) ] } {
if [ catch {exec id} reason ] {
send_error "\nError: could not exec id: $reason\n"
exit 1
- }
+ }
regexp {\(([^)]*)} "$reason" junk default_user
-}
+}
# Sometimes routers take awhile to answer (the default is 10 sec)
set timeout 45
@@ -244,9 +244,9 @@ proc include {args} {
regsub -all "(^{|}$)" $args {} args
if { [ regexp "^/" $args ignore ] == 0 } {
set args $env(HOME)/$args
- }
+ }
source_password_file $args
-}
+}
proc find {var router} {
upvar int_$var list
@@ -264,7 +264,7 @@ proc find {var router} {
# it is sourced, the user better know what to put in there, as it
# could install more than just password info... I will assume however,
# that a "bad guy" could just as easy put such code in the clogin
-# script, so I will leave .cloginrc as just an extention of that script
+# script, so I will leave .cloginrc as just an extention of that script
proc source_password_file { password_file } {
global env
if { ! [file exists $password_file] } {
@@ -283,6 +283,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
global spawn_id in_proc do_command do_script platform
global prompt u_prompt p_prompt e_prompt sshcmd
@@ -292,6 +293,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -301,23 +303,23 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "ssh"] {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "rsh"] {
- if [ catch {spawn rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue;
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
@@ -354,15 +356,15 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
if !$progs {
send_user "\nError: Connection Refused ($prog): $router\n"
return 1
- }
+ }
}
-re "(Connection closed by|Connection to \[^\n\r]+ closed)" {
catch {close}; wait
if !$progs {
send_user "\nError: Connection closed ($prog): $router\n"
return 1
- }
- }
+ }
+ }
-re "Telnet server disabled" {
catch {close}; wait
if !$progs {
@@ -546,7 +548,7 @@ foreach router [lrange $argv $i end] {
if { [llength $pswd] == 0 } {
send_user "\nError: no password for $router in $password_file.\n"
continue
- }
+ }
if { $enable && $do_enapasswd && $autoenable == 0 && [llength $pswd] < 2 } {
send_user "\nError: no enable password for $router in $password_file.\n"
continue
@@ -556,13 +558,13 @@ foreach router [lrange $argv $i end] {
}
# Figure out username
- if {[info exists username]} {
+ if {[info exists username]} {
# command line username
set ruser $username
} else {
set ruser [join [find user $router] ""]
if { "$ruser" == "" } { set ruser $default_user }
- }
+ }
# Figure out username's password (if different from the vty password)
if {[info exists userpasswd]} {
@@ -570,17 +572,17 @@ foreach router [lrange $argv $i end] {
set userpswd $userpasswd
} else {
set userpswd [join [find userpassword $router] ""]
- if { "$userpswd" == "" } { set userpswd $passwd }
- }
-
+ if { "$userpswd" == "" } { set userpswd $passwd }
+ }
+
# Figure out enable username
- if {[info exists enausername]} {
+ if {[info exists enausername]} {
# command line enausername
set enauser $enausername
} else {
set enauser [join [find enauser $router] ""]
- if { "$enauser" == "" } { set enauser $ruser }
- }
+ if { "$enauser" == "" } { set enauser $ruser }
+ }
# Figure out prompts
set u_prompt [find userprompt $router]
@@ -615,15 +617,15 @@ foreach router [lrange $argv $i end] {
set cmethod [find method $router]
if { "$cmethod" == "" } { set cmethod {{telnet} {ssh}} }
- # Figure out the SSH executable name
- set sshcmd [find sshcmd $router]
- if { "$sshcmd" == "" } { set sshcmd {ssh} }
+ # Figure out the SSH executable name
+ set sshcmd [find sshcmd $router]
+ if { "$sshcmd" == "" } { set sshcmd {ssh} }
# Login to the router
if {[login $router $ruser $userpswd $passwd $enapasswd $cmethod $cyphertype]} {
continue
}
- if { $enable } {
+ if { $enable } {
if {[do_enable $enauser $enapasswd]} {
if { $do_command || $do_script } {
close; wait
@@ -643,7 +645,7 @@ foreach router [lrange $argv $i end] {
source $sfile
close
} else {
- label $router
+ label $router
log_user 1
interact
}
diff --git a/bin/fnrancid.in b/bin/fnrancid.in
index 815227b..6965f7b 100644
--- a/bin/fnrancid.in
+++ b/bin/fnrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: fnrancid.in,v 1.3 2004/01/11 03:49:13 heas Exp $
+## $Id: fnrancid.in,v 1.8 2005/06/15 20:54:40 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -20,7 +20,7 @@
##
#
# A library built on Stephen Gill's Netscreen stuff to accomodate
-# the Fortinet product line. [d_pfleger@juniper.net]
+# the Fortinet product line. [d_pfleger@juniper.net]
#
# RANCID - Really Awesome New Cisco confIg Differ
#
@@ -34,15 +34,16 @@ $debug = $opt_d;
$file = $opt_f;
$host = $ARGV[0];
$found_end = 0;
-$timeo = 90; # nlogin timeout in seconds
+$timeo = 90; # nlogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,10 +65,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,10 +78,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,22 +91,22 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
- $sorted_lines[$i] = $key;
- $i++;
+ $sorted_lines[$i] = $key;
+ $i++;
}
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -119,7 +120,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -132,7 +133,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -146,7 +147,7 @@ sub GetSystem {
tr/\015//d;
next if /^\s*$/;
last if(/$prompt/);
- ProcessHistory("","","","$_");
+ ProcessHistory("","","","$_");
#print STDOUT "$_";
}
print STDOUT "Vendor: $vendor";
@@ -170,9 +171,9 @@ sub GetConf {
next if /^\s*$/;
last if(/$prompt/);
if (/(^set.*)('Enc .*')(.*)/) {
- ProcessHistory("ENC","","","!$1 'Enc **encoding removed**' $3\n");
- next;
- }
+ ProcessHistory("ENC","","","!$1 'Enc **encoding removed**' $3\n");
+ next;
+ }
ProcessHistory("","","","$_");
#print STDOUT "$_";
}
@@ -184,16 +185,15 @@ sub GetConf {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'get system status' => "GetSystem",
- 'get conf' => "GetConf"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important. pita
-@commands=(
- "get system status",
- "get conf"
+@commandtable = (
+ {'get system status' => 'GetSystem'},
+ {'get conf' => 'GetConf'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -218,7 +218,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/francid.in b/bin/francid.in
index 31977b9..78bdc62 100644
--- a/bin/francid.in
+++ b/bin/francid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: francid.in,v 1.29 2004/04/14 21:38:12 heas Exp $
+## $Id: francid.in,v 1.34 2005/06/15 20:54:40 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -34,15 +34,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # flogin timeout in seconds
+$timeo = 90; # flogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,10 +65,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,10 +78,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,22 +91,22 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
- $sorted_lines[$i] = $key;
- $i++;
+ $sorted_lines[$i] = $key;
+ $i++;
}
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -119,7 +120,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -132,7 +133,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -241,8 +242,8 @@ sub WriteTerm {
/^module \d+ / && next;
/^ntp clock-period / && next; # kill ntp clock-period
- /^ length / && next; # kill length on serial lines
- /^ width / && next; # kill width on serial lines
+ /^ length / && next; # kill length on serial lines
+ /^ width / && next; # kill width on serial lines
# filter out any RCS/CVS tags to avoid confusing local CVS storage
s/\$(Revision|Id):/ $1:/;
# order access-lists
@@ -346,22 +347,18 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'show chassis' => "ShowChassis",
- 'show module' => "ShowModule",
- 'show flash' => "ShowFlash",
- 'write term' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important. pita
-@commands=(
- "show version",
- "show chassis",
- "show module",
- "show flash",
- "write term"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'show chassis' => 'ShowChassis'},
+ {'show module' => 'ShowModule'},
+ {'show flash' => 'ShowFlash'},
+ {'write term' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -387,7 +384,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/hlogin.in b/bin/hlogin.in
index 2e3636d..ab02f4f 100644
--- a/bin/hlogin.in
+++ b/bin/hlogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: hlogin.in,v 1.24 2004/10/14 17:53:57 heas Exp $
+## $Id: hlogin.in,v 1.28 2005/06/13 03:11:45 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -59,7 +59,7 @@ set do_enapasswd 1
set platform ""
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -287,6 +287,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
global spawn_id in_proc do_command do_script platform
global prompt u_prompt p_prompt e_prompt sshcmd
@@ -295,6 +296,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
regexp {(telnet|ssh)(:([^[:space:]]+))*} $prog command suffix junk port
if [string match "telnet*" $prog] {
if {"$port" == ""} {
@@ -304,7 +306,7 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif [string match "ssh*" $prog] {
if {"$port" == ""} {
@@ -314,18 +316,18 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "rsh"] {
- if [ catch {spawn hpuifilter rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue;
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
diff --git a/bin/hpuifilter.c b/bin/hpuifilter.c
index cc94fec..4747299 100644
--- a/bin/hpuifilter.c
+++ b/bin/hpuifilter.c
@@ -1,5 +1,5 @@
/*
- * $Id: hpuifilter.c,v 1.20 2005/03/30 07:27:15 heas Exp $
+ * $Id: hpuifilter.c,v 1.21 2005/06/14 20:20:43 heas Exp $
*
* Copyright (C) 1997-2004 by Terrapin Communications, Inc.
* All rights reserved.
@@ -296,7 +296,7 @@ filter(buf, len)
static char reg[N_REG][50] = { /* vt100/220 escape codes */
"\e7\e\\[1;24r\e8", /* ds */
"\e8", /* fs */
-
+
"\e\\[2J",
"\e\\[2K", /* kE */
@@ -366,22 +366,22 @@ filter(buf, len)
return(strlen(buf));
}
-RETSIGTYPE
+RETSIGTYPE
reapchild(void)
{
int status;
pid_t pid;
-
+
/* XXX this needs to deal with/without wait3 via HAVE_WAIT3 */
while ((pid = wait3(&status, WNOHANG, 0)) > 0)
if (debug)
fprintf(stderr, "reap child %d\n", pid);
-
+
/*exit(1);*/
return;
/* not reached */
-}
+}
void
usage(void)
diff --git a/bin/hrancid.in b/bin/hrancid.in
index d53cad0..4eb77e1 100644
--- a/bin/hrancid.in
+++ b/bin/hrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: hrancid.in,v 1.18 2005/01/27 00:01:10 heas Exp $
+## $Id: hrancid.in,v 1.22 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -33,16 +33,17 @@ $debug = $opt_d;
$file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
-$found_end = 0; # unused - hp lacks an end-of-config tag.
-$timeo = 90; # clogin timeout in seconds
+$found_end = 0; # unused - hp lacks an end-of-config tag
+$timeo = 90; # hlogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,10 +65,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,10 +78,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,10 +91,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -103,9 +104,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -119,7 +120,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -132,7 +133,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -426,24 +427,19 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'show flash' => "ShowFlash",
- 'show system-information' => "ShowSystem",
- 'show module' => "ShowModule",
- 'show stack' => "ShowStack",
- 'write term' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version",
- "show flash",
- "show system-information",
- "show module",
- "show stack",
- "write term"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'show flash' => 'ShowFlash'},
+ {'show system-information' => 'ShowSystem'},
+ {'show module' => 'ShowModule'},
+ {'show stack' => 'ShowStack'},
+ {'write term' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -469,7 +465,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/htlogin.in b/bin/htlogin.in
index 01de69c..c95733b 100644
--- a/bin/htlogin.in
+++ b/bin/htlogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: htlogin.in,v 1.8 2004/02/02 17:38:36 heas Exp $
+## $Id: htlogin.in,v 1.13 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -51,7 +51,7 @@ set avautoenable 0
set do_passwd 1
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -64,9 +64,9 @@ if {[ info exists env(CISCO_USER) ] } {
if [ catch {exec id} reason ] {
send_error "\nError: could not exec id: $reason\n"
exit 1
- }
+ }
regexp {\(([^)]*)} "$reason" junk default_user
-}
+}
# Sometimes routers take awhile to answer (the default is 10 sec)
set timeout 45
@@ -270,31 +270,44 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd prompt cmethod cyphertype } {
global spawn_id in_proc do_command do_script
global u_prompt p_prompt
set in_proc 1
- set uprompt_seen 0
+ set uprompt_seen 0
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
- set retval [ catch {spawn telnet $router} reason ]
- } else {
+ set retval [ catch {spawn telnet $router} reason ]
+ } else {
set retval [ catch {spawn telnet $router $port} reason ]
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
+ }
+ } elseif ![string compare $prog "ssh"] {
+ send_error "\nError: unsupported method: ssh\n"
+ if { $progs == 0 } {
+ return 1
+ }
+ continue
+ } elseif ![string compare $prog "rsh"] {
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
diff --git a/bin/htrancid.in b/bin/htrancid.in
index 2b2eaaa..5f05a00 100644
--- a/bin/htrancid.in
+++ b/bin/htrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: htrancid.in,v 1.5 2004/01/11 03:49:13 heas Exp $
+## $Id: htrancid.in,v 1.10 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -33,15 +33,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # blogin timeout in seconds
+$timeo = 90; # htlogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -63,10 +64,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -76,10 +77,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -89,10 +90,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -102,9 +103,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -118,7 +119,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -131,7 +132,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -166,16 +167,15 @@ sub ShowVersion {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'version -a' => "ShowVersion",
- 'cat /config/router.cnf' => "ShowConfig"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "version -a",
- "cat /config/router.cnf"
+@commandtable = (
+ {'version -a' => 'ShowVersion'},
+ {'cat /config/router.cnf' => 'ShowConfig'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -201,7 +201,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
@@ -224,8 +224,8 @@ TOP: while(<INPUT>) {
while (/command:\s*($cmds_regexp)\s*$/) {
$cmd = $1;
if (!defined($prompt)) {
- $prompt = ($_ =~ /^([^:]+:)/)[0];
- }
+ $prompt = ($_ =~ /^([^:]+:)/)[0];
+ }
print STDERR ("HIT COMMAND:$_") if ($debug);
if (! defined($commands{$cmd})) {
print STDERR "$host: found unexpected command - \"$cmd\"\n";
diff --git a/bin/jerancid.in b/bin/jerancid.in
index 4d51964..7455b1d 100644
--- a/bin/jerancid.in
+++ b/bin/jerancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: jerancid.in,v 1.30 2004/10/15 21:20:49 heas Exp $
+## $Id: jerancid.in,v 1.33 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -33,15 +33,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -63,10 +64,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -76,10 +77,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -89,10 +90,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -102,9 +103,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -118,7 +119,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -131,7 +132,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -536,26 +537,20 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'show redundancy' => "ShowRedundancy",
- 'show boot' => "ShowBoot",
- 'show environment all' => "ShowEnv",
- 'dir' => "DirSlotN",
- 'show hardware' => "ShowHardware",
- 'show configuration' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version",
- "show redundancy",
- "show boot",
- "show environment all",
- "dir",
- "show hardware",
- "show configuration"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'show redundancy' => 'ShowRedundancy'},
+ {'show boot' => 'ShowBoot'},
+ {'show environment all' => 'ShowEnv'},
+ {'dir' => 'DirSlotN'},
+ {'show hardware' => 'ShowHardware'},
+ {'show configuration' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$jnxe_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
diff --git a/bin/jlogin.in b/bin/jlogin.in
index afa860e..e6c4a01 100644
--- a/bin/jlogin.in
+++ b/bin/jlogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: jlogin.in,v 1.46 2004/03/11 19:36:25 heas Exp $
+## $Id: jlogin.in,v 1.51 2005/06/14 20:20:43 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -48,7 +48,7 @@ set avenable 1
set do_passwd 1
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -252,6 +252,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user passwd cmethod cyphertype identfile} {
global spawn_id in_proc do_command do_script passphrase prompt
global sshcmd
@@ -260,6 +261,7 @@ proc login { router user passwd cmethod cyphertype identfile} {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -269,7 +271,7 @@ proc login { router user passwd cmethod cyphertype identfile} {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "ssh"] {
# ssh to the router & try to login with or without an identfile.
@@ -278,24 +280,24 @@ proc login { router user passwd cmethod cyphertype identfile} {
if {$identfile != ""} {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user -i $identfile $router} reason ] {
send_user "\nError: failed to $sshcmd: $reason\n"
- exit 1
+ return 1
}
} else {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
send_user "\nError: failed to $sshcmd: $reason\n"
- exit 1
+ return 1
}
}
} elseif ![string compare $prog "rsh"] {
- if [ catch {spawn rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
@@ -493,9 +495,9 @@ foreach router [lrange $argv $i end] {
set cmethod [find method $router]
if { "$cmethod" == "" } { set cmethod {{telnet} {ssh}} }
- # Figure out the SSH executable name
- set sshcmd [find sshcmd $router]
- if { "$sshcmd" == "" } { set sshcmd {ssh} }
+ # Figure out the SSH executable name
+ set sshcmd [find sshcmd $router]
+ if { "$sshcmd" == "" } { set sshcmd {ssh} }
# Login to the router
if {[login $router $loginname $passwd $cmethod $cyphertype $identfile]} {
diff --git a/bin/jrancid.in b/bin/jrancid.in
index 8432671..8b7f2bf 100644
--- a/bin/jrancid.in
+++ b/bin/jrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: jrancid.in,v 1.63 2004/12/08 00:31:46 asp Exp $
+## $Id: jrancid.in,v 1.68 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -36,13 +36,14 @@ $host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,10 +65,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,10 +78,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,22 +91,22 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
- $sorted_lines[$i] = $key;
- $i++;
+ $sorted_lines[$i] = $key;
+ $i++;
}
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -119,7 +120,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -132,7 +133,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -488,7 +489,7 @@ sub ShowConfiguration {
while (<INPUT>) {
tr/\015//d;
next if (/^\s*$/);
- # end of config - hopefully. juniper does not have a reliable
+ # end of config - hopefully. juniper does not have a reliable
# end-of-config tag. appears to end with "\nPROMPT>", but not sure.
if(/^$prompt/) {
$found_end++;
@@ -559,46 +560,30 @@ sub ShowConfiguration {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- "show chassis clocks" => "ShowChassisClocks",
- "show chassis environment" => "ShowChassisEnvironment",
- "show chassis firmware" => "ShowChassisFirmware",
- "show chassis fpc detail" => "ShowChassisFpcDetail",
- "show chassis hardware detail" => "ShowChassisHardware",
- "show chassis routing-engine" => "ShowChassisRoutingEngine",
- "show chassis scb" => "ShowChassisSCB",
- "show chassis sfm detail" => "ShowChassisSCB",
- "show chassis ssb" => "ShowChassisSCB",
- "show chassis feb" => "ShowChassisSCB",
- "show chassis cfeb" => "ShowChassisSCB",
- "show chassis alarms" => "ShowChassisAlarms",
-# "show system autoinstallation status" => "ShowSystemAutoinstall",
- "show system license" => "ShowSystemLicense",
-# "show system license keys" => "ShowSystemLicenseKeys",
- "show system boot-messages" => "ShowSystemBootMessages",
- "show version detail" => "ShowVersion",
- "show configuration" => "ShowConfiguration"
-);
-@commands=(
- "show chassis clocks",
- "show chassis environment",
- "show chassis firmware",
- "show chassis fpc detail",
- "show chassis hardware detail",
- "show chassis routing-engine",
- "show chassis scb",
- "show chassis sfm detail",
- "show chassis ssb",
- "show chassis feb",
- "show chassis cfeb",
- "show chassis alarms",
-# "show system autoinstallation status",
- "show system license",
-# "show system license keys",
- "show system boot-messages",
- "show version detail",
- "show configuration"
+@commandtable = (
+ {'show chassis clocks' => 'ShowChassisClocks'},
+ {'show chassis environment' => 'ShowChassisEnvironment'},
+ {'show chassis firmware' => 'ShowChassisFirmware'},
+ {'show chassis fpc detail' => 'ShowChassisFpcDetail'},
+ {'show chassis hardware detail' => 'ShowChassisHardware'},
+ {'show chassis routing-engine' => 'ShowChassisRoutingEngine'},
+ {'show chassis scb' => 'ShowChassisSCB'},
+ {'show chassis sfm detail' => 'ShowChassisSCB'},
+ {'show chassis ssb' => 'ShowChassisSCB'},
+ {'show chassis feb' => 'ShowChassisSCB'},
+ {'show chassis cfeb' => 'ShowChassisSCB'},
+ {'show chassis alarms' => 'ShowChassisAlarms'},
+# {'show system autoinstallation status' => 'ShowSystemAutoinstall'},
+ {'show system license' => 'ShowSystemLicense'},
+# {'show system license keys' => 'ShowSystemLicenseKeys'},
+ {'show system boot-messages' => 'ShowSystemBootMessages'},
+ {'show version detail' => 'ShowVersion'},
+ {'show configuration' => 'ShowConfiguration'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
$jnx_commands=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -627,7 +612,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/mrancid.in b/bin/mrancid.in
index 8d52c27..80bc206 100644
--- a/bin/mrancid.in
+++ b/bin/mrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: mrancid.in,v 1.11 2004/01/11 03:49:13 heas Exp $
+## $Id: mrancid.in,v 1.15 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -34,15 +34,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,10 +65,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,10 +78,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,10 +91,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -103,9 +104,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -119,7 +120,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -132,7 +133,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -305,16 +306,15 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'show config' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version",
- "show config"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'show config' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -340,7 +340,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/nlogin.in b/bin/nlogin.in
index 9754367..e10db1e 100644
--- a/bin/nlogin.in
+++ b/bin/nlogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: nlogin.in,v 1.20 2004/12/24 21:00:32 tex Exp $
+## $Id: nlogin.in,v 1.26 2005/06/14 20:20:44 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -30,14 +30,224 @@
# netscreen does not have the concept of "enable", once logged in, a
# users permissions can not change.
+# Usage line
+set usage "Usage: $argv0 \[-c command\] \[-Evar=x\] \[-f cloginrc-file\] \
+\[-p user-password\] \
+\[-s script-file\] \[-t timeout\] \[-u username\] \
+\[-v vty-password\] \[-x command-file\] \
+\[-y ssh_cypher_type\] router \[router...\]\n"
-@INCLUDE login.top@
-# Enable password isn't understood but is used in script.
-# enable settings mostly ignored, but set this:
-set do_enapasswd 0
-# just in case
+# env(CLOGIN) may contain:
+# x == do not set xterm banner or name
+
+# Password file
+set password_file $env(HOME)/.cloginrc
+# Default is to login to the firewall
+set do_command 0
+set do_script 0
+# The default is to look in the password file to find the passwords. This
+# tracks if we receive them on the command line.
+set do_passwd 1
+set do_enapasswd 1
+
+# Find the user in the ENV, or use the unix userid.
+if {[ info exists env(CISCO_USER) ]} {
+ set default_user $env(CISCO_USER)
+} elseif {[ info exists env(USER) ]} {
+ set default_user $env(USER)
+} elseif {[ info exists env(LOGNAME) ]} {
+ set default_user $env(LOGNAME)
+} else {
+ # This uses "id" which I think is portable. At least it has existed
+ # (without options) on all machines/OSes I've been on recently -
+ # unlike whoami or id -nu.
+ if [ catch {exec id} reason ] {
+ send_error "\nError: could not exec id: $reason\n"
+ exit 1
+ }
+ regexp {\(([^)]*)} "$reason" junk default_user
+}
+
+# Sometimes firewall take awhile to answer (the default is 10 sec)
+set timeout 45
+
+# Process the command line
+for {set i 0} {$i < $argc} {incr i} {
+ set arg [lindex $argv $i]
+
+ switch -glob -- $arg {
+ # Username
+ -u* -
+ -U* {
+ if {! [ regexp .\[uU\](.+) $arg ignore user]} {
+ incr i
+ set username [ lindex $argv $i ]
+ }
+ # VTY Password
+ } -p* -
+ -P* {
+ if {! [ regexp .\[pP\](.+) $arg ignore userpasswd]} {
+ incr i
+ set userpasswd [ lindex $argv $i ]
+ }
+ set do_passwd 0
+ # Environment variable to pass to -s scripts
+ } -E*
+ {
+ if {[ regexp .\[E\](.+)=(.+) $arg ignore varname varvalue]} {
+ set E$varname $varvalue
+ } else {
+ send_user "\nError: invalid format for -E in $arg\n"
+ exit 1
+ }
+ # Command to run.
+ } -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* {
+ if {! [ regexp .\[sS\](.+) $arg ignore sfile]} {
+ incr i
+ set sfile [ lindex $argv $i ]
+ }
+ if { ! [ file readable $sfile ] } {
+ send_user "\nError: Can't read $sfile\n"
+ exit 1
+ }
+ set do_script 1
+ # cypher type
+ } -y* -
+ -Y* {
+ if {! [ regexp .\[eE\](.+) $arg ignore cypher]} {
+ incr i
+ set cypher [ lindex $argv $i ]
+ }
+ # alternate cloginrc file
+ } -f* -
+ -F* {
+ if {! [ regexp .\[fF\](.+) $arg ignore password_file]} {
+ incr i
+ set password_file [ lindex $argv $i ]
+ }
+ } -t* -
+ -T* {
+ incr i
+ set timeout [ lindex $argv $i ]
+ } -x* -
+ -X {
+ if {! [ regexp .\[xX\](.+) $arg ignore cmd_file]} {
+ incr i
+ set cmd_file [ lindex $argv $i ]
+ }
+ 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] \;]
+ set do_command 1
+ # Does tacacs automatically enable us?
+ } -autoenable {
+ # ignore autoenable
+ } -* {
+ send_user "\nError: Unknown argument! $arg\n"
+ send_user $usage
+ exit 1
+ } default {
+ break
+ }
+ }
+}
+# Process firewalls...no firewalls listed is an error.
+if { $i == $argc } {
+ send_user "\nError: $usage"
+}
+
+# Only be quiet if we are running a script (it can log its output
+# on its own)
+if { $do_script } {
+ log_user 0
+} else {
+ log_user 1
+}
+
+#
+# Done configuration/variable setting. Now run with it...
+#
+
+# Sets Xterm title if interactive...if its an xterm and the user cares
+proc label { host } {
+ global env
+ # if CLOGIN has an 'x' in it, don't set the xterm name/banner
+ if [info exists env(CLOGIN)] {
+ if {[string first "x" $env(CLOGIN)] != -1} { return }
+ }
+ # take host from ENV(TERM)
+ if [info exists env(TERM)] {
+ if [regexp \^(xterm|vs) $env(TERM) ignore ] {
+ send_user "\033]1;[lindex [split $host "."] 0]\a"
+ send_user "\033]2;$host\a"
+ }
+ }
+}
+
+# This is a helper function to make the password file easier to
+# maintain. Using this the password file has the form:
+# add password sl* pete cow
+# add password at* steve
+# add password * hanky-pie
+proc add {var args} { global int_$var ; lappend int_$var $args}
+proc include {args} {
+ global env
+ regsub -all "(^{|}$)" $args {} args
+ if { [ regexp "^/" $args ignore ] == 0 } {
+ set args $env(HOME)/$args
+ }
+ source_password_file $args
+}
+
+proc find {var firewall} {
+ upvar int_$var list
+ if { [info exists list] } {
+ foreach line $list {
+ if { [string match [lindex $line 0] $firewall ] } {
+ return [lrange $line 1 end]
+ }
+ }
+ }
+ return {}
+}
+
+# Loads the password file. Note that as this file is tcl, and that
+# it is sourced, the user better know what to put in there, as it
+# could install more than just password info... I will assume however,
+# that a "bad guy" could just as easy put such code in the clogin
+# script, so I will leave .cloginrc as just an extention of that script
+proc source_password_file { password_file } {
+ global env
+ if { ! [file exists $password_file] } {
+ send_user "\nError: password file ($password_file) does not exist\n"
+ exit 1
+ }
+ file stat $password_file fileinfo
+ if { [expr ($fileinfo(mode) & 007)] != 0000 } {
+ send_user "\nError: $password_file must not be world readable/writable\n"
+ exit 1
+ }
+ if [ catch {source $password_file} reason ] {
+ send_user "\nError: $reason\n"
+ exit 1
+ }
+}
# Log into the firewall.
+# returns: 0 on success, 1 on failure
proc login { firewall user userpswd passwd enapasswd prompt cmethod
cyphertype } {
global spawn_id in_proc do_command do_script sshcmd
@@ -47,6 +257,7 @@ cyphertype } {
# Telnet to the firewall & try to login.
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -56,23 +267,23 @@ cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
} elseif ![string compare $prog "ssh"] {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $firewall} reason ] {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
- }
+ return 1
+ }
} elseif ![string compare $prog "rsh"] {
- if [ catch {spawn rsh -l $user $firewall} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
}
+ continue;
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
@@ -105,10 +316,10 @@ cyphertype } {
# then it will just send the passwd.
# if telnet fails with connection refused, try ssh
expect {
- "Connection refused" {
+ "Connection refused" {
send_user "\nError: Connection Refused\n"; wait; return 1
} eof { send_user "\nError: Couldn't login\n"; wait; return 1
- } "Unknown host\r\n" {
+ } "Unknown host\r\n" {
expect eof
send_user "\nError: Unknown host\n"; wait; return 1
} "Host is unreachable" {
@@ -134,7 +345,7 @@ cyphertype } {
send "no\r"
send_user "\nError: host key mismatch for $firewall. Update the SSH known_hosts file accordingly.\n"
return 1 }
- denied { send_user "\nError: Check your passwd for $firewall\n"
+ denied { send_user "\nError: Check your passwd for $firewall\n"
catch {close}; wait; return 1
}
" ### Login failed" {send_user "\nError: Check your passwd for $firewall\n"; return 1 }
@@ -235,19 +446,19 @@ foreach firewall [lrange $argv $i end] {
if { [llength $pswd] == 0 } {
send_user "\nError: no password for $firewall in $password_file.\n"
continue
- }
+ }
set passwd [join [lindex $pswd 0] ""]
set enapasswd [join [lindex $pswd 1] ""]
}
# Figure out username
- if {[info exists username]} {
+ if {[info exists username]} {
# command line username
set ruser $username
} else {
set ruser [join [find user $firewall] ""]
if { "$ruser" == "" } { set ruser $default_user }
- }
+ }
# Figure out username's password (if different from the vty password)
if {[info exists userpasswd]} {
@@ -255,9 +466,9 @@ foreach firewall [lrange $argv $i end] {
set userpswd $userpasswd
} else {
set userpswd [join [find userpassword $firewall] ""]
- if { "$userpswd" == "" } { set userpswd $passwd }
- }
-
+ if { "$userpswd" == "" } { set userpswd $passwd }
+ }
+
# Figure out cypher type
if {[info exists cypher]} {
@@ -272,9 +483,9 @@ foreach firewall [lrange $argv $i end] {
set cmethod [find method $firewall]
if { "$cmethod" == "" } { set cmethod {{telnet} {ssh}} }
- # Figure out the SSH executable name
- set sshcmd [find sshcmd $firewall]
- if { "$sshcmd" == "" } { set sshcmd {ssh} }
+ # Figure out the SSH executable name
+ set sshcmd [find sshcmd $firewall]
+ if { "$sshcmd" == "" } { set sshcmd {ssh} }
# Login to the firewall
if {[login $firewall $ruser $userpswd $passwd $enapasswd $prompt $cmethod $cyphertype]} {
@@ -302,7 +513,7 @@ foreach firewall [lrange $argv $i end] {
source $sfile
close
} else {
- label $firewall
+ label $firewall
log_user 1
interact
}
diff --git a/bin/nrancid.in b/bin/nrancid.in
index 3f2b224..b7305e5 100644
--- a/bin/nrancid.in
+++ b/bin/nrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: nrancid.in,v 1.17 2004/10/15 08:56:01 afort Exp $
+## $Id: nrancid.in,v 1.23 2005/06/24 16:01:19 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -21,7 +21,7 @@
#
# Amazingly hacked version of Hank's rancid - this one tries to
# deal with Netscreen firewalls
-#
+#
# Original Netscreen hacks implemented by Stephen Gill [gillsr@yahoo.com]
#
# RANCID - Really Awesome New Cisco confIg Differ
@@ -35,15 +35,16 @@ $debug = $opt_d;
$file = $opt_f;
$host = $ARGV[0];
$found_end = 0;
-$timeo = 90; # nlogin timeout in seconds
+$timeo = 90; # nlogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
-# This routine is used to print out the firewall configuration
+# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -65,10 +66,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -78,10 +79,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -91,22 +92,22 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
- $sorted_lines[$i] = $key;
- $i++;
+ $sorted_lines[$i] = $key;
+ $i++;
}
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -120,7 +121,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -133,7 +134,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -150,20 +151,20 @@ sub GetSystem {
# throw away the pager lines
next if /^--- more ---/;
- /^Serial Number: (\d+), Control Number: \d+$/ &&
- ProcessHistory("SYSTEM","","", "!SN: $1\n") && next;
- /^Product Name: (\S+)$/ &&
- ProcessHistory("SYSTEM","","", "!Product: $1\n") && next;
- /^Hardware Version: (\S+), / &&
- ProcessHistory("SYSTEM","","", "!HW: $1\n") && next;
- /^Software Version: (\S+), Type: (\S+)$/ &&
- ProcessHistory("SYSTEM","","", "!Netscreen Type: $2\n!Software Version: $1\n") && next;
- /^Image: (\S+), / &&
- ProcessHistory("SYSTEM","","", "!Image: $1\n") && next;
- /^Feature: (\S+)$/ &&
- ProcessHistory("SYSTEM","","", "!Feature: $1\n") && next;
- /^File Name: (\S+), Checksum: (\S+)$/ &&
- ProcessHistory("SYSTEM","","", "!File Name: $1, Checksum: $2\n") && next;
+ /^Serial Number: (\d+), Control Number: \d+$/ &&
+ ProcessHistory("SYSTEM","","", "!SN: $1\n") && next;
+ /^Product Name: (\S+)$/ &&
+ ProcessHistory("SYSTEM","","", "!Product: $1\n") && next;
+ /^Hardware Version: (\S+), / &&
+ ProcessHistory("SYSTEM","","", "!HW: $1\n") && next;
+ /^Software Version: (\S+), Type: (\S+)$/ &&
+ ProcessHistory("SYSTEM","","", "!Netscreen Type: $2\n!Software Version: $1\n") && next;
+ /^Image: (\S+), / &&
+ ProcessHistory("SYSTEM","","", "!Image: $1\n") && next;
+ /^Feature: (\S+)$/ &&
+ ProcessHistory("SYSTEM","","", "!Feature: $1\n") && next;
+ /^File Name: (\S+), Checksum: (\S+)$/ &&
+ ProcessHistory("SYSTEM","","", "!File Name: $1, Checksum: $2\n") && next;
}
ProcessHistory("SYSTEM","","","!\n");
@@ -190,18 +191,23 @@ sub GetConf {
next if /^--- more ---/;
if (/^set admin name "(\S+)"$/ && $filter_pwds >= 1) {
- ProcessHistory("ADMIN","","","!set admin name <removed>\n");
- next;
- }
+ ProcessHistory("ADMIN","","","!set admin name <removed>\n");
+ next;
+ }
if (/^set admin password (\S+)$/ && $filter_pwds >= 1) {
- ProcessHistory("ADMIN","","","!set admin password <removed>\n");
- next;
- }
+ ProcessHistory("ADMIN","","","!set admin password <removed>\n");
+ next;
+ }
if (/^set admin user (\S+) password (\S+) privilege (\S+)$/ &&
$filter_pwds >= 1) {
- ProcessHistory("ADMIN","","",
+ ProcessHistory("ADMIN","","",
"!set admin user $1 password <removed> privilege $3\n");
- next;
+ next;
+ }
+ if (/^set auth-server (\S+) radius secret / && $filter_pwds >= 1 ) {
+ ProcessHistory("ADMIN","","",
+ "!set auth-server $1 radius secret <removed>\n");
+ next;
}
ProcessHistory("","","","$_");
}
@@ -213,16 +219,15 @@ sub GetConf {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'get system' => "GetSystem",
- 'get conf' => "GetConf"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important. pita
-@commands=(
- "get system",
- "get conf"
+@commandtable = (
+ {'get system' => 'GetSystem'},
+ {'get conf' => 'GetConf'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -248,7 +253,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/nslogin.in b/bin/nslogin.in
index c4b8e8a..b48004d 100644
--- a/bin/nslogin.in
+++ b/bin/nslogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: nslogin.in,v 1.11 2004/02/02 17:38:36 heas Exp $
+## $Id: nslogin.in,v 1.17 2005/06/14 22:23:44 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -61,7 +61,7 @@ set do_enapasswd 1
set platform ""
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -288,6 +288,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
global spawn_id in_proc do_command do_script platform
global prompt u_prompt p_prompt e_prompt sshcmd
@@ -297,16 +298,28 @@ proc login { router user userpswd passwd enapasswd cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if ![string compare $prog "ssh"] {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
+ return 1
}
+ } elseif ![string compare $prog "telnet"] {
+ send_error "\nError: unsupported method: telnet\n"
+ if { $progs == 0 } {
+ return 1
+ }
+ continue
+ } elseif ![string compare $prog "rsh"] {
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
+ }
+ continue
} else {
- puts "\nError: unknown connection method: $prog"
+ send_user "\nError: unknown connection method: $prog\n"
return 1
}
- incr progs -1
sleep 0.3
# This helps cleanup each expect clause.
@@ -589,9 +602,9 @@ foreach router [lrange $argv $i end] {
set cmethod [find method $router]
if { "$cmethod" == "" } { set cmethod {{telnet} {ssh}} }
- # Figure out the SSH executable name
- set sshcmd [find sshcmd $router]
- if { "$sshcmd" == "" } { set sshcmd {ssh} }
+ # Figure out the SSH executable name
+ set sshcmd [find sshcmd $router]
+ if { "$sshcmd" == "" } { set sshcmd {ssh} }
# Login to the router
if {[login $router $ruser $userpswd $passwd $enapasswd $cmethod $cyphertype]} {
diff --git a/bin/nsrancid.in b/bin/nsrancid.in
index 40a286f..c0a9a73 100644
--- a/bin/nsrancid.in
+++ b/bin/nsrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: nsrancid.in,v 1.7 2004/01/11 03:49:13 heas Exp $
+## $Id: nsrancid.in,v 1.11 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -34,20 +34,20 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # nslogin timeout in seconds
+$timeo = 90; # nslogin timeout in seconds
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
@temp1 = split (/\./,$host);
$prompt = "$temp1[0]#";
$prompt = "netscaler#";
-my(%filter_pwds); # password filtering mode
-
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -69,10 +69,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -82,10 +82,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -95,10 +95,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -108,9 +108,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -124,7 +124,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -137,7 +137,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -165,9 +165,9 @@ sub ShowConfig {
}
if (/exit$/) {
- $found_end = 1;
- $clean_run = 1;
- return(1);
+ $found_end = 1;
+ $clean_run = 1;
+ return(1);
}
return(0);
}
@@ -205,17 +205,15 @@ sub RunCommand {
sub DoNothing {print STDOUT;}
# Main
-#--------------------------------------------------
-%commands=(
- 'cat /etc/ns.conf' => "ShowConfig",
- 'get log setting' => "GetLogSet"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "cat /etc/ns.conf",
- "get log setting"
+@commandtable = (
+ {'cat /etc/ns.conf' => 'ShowConfig'},
+ {'get log setting' => 'GetLogSet'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -261,7 +259,7 @@ TOP: while(<INPUT>) {
# if ( (/netscaler#/) || $found_end ) {
#print STDOUT "\n\nhere1\n";
-# $clean_run=1;
+# $clean_run=1;
# last;
# }
diff --git a/bin/par.in b/bin/par.in
index b50bd05..ae94eae 100644
--- a/bin/par.in
+++ b/bin/par.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: par.in,v 1.10 2004/01/11 03:49:13 heas Exp $
+## $Id: par.in,v 1.11 2005/06/14 20:20:44 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -59,7 +59,7 @@ if ($opt_q && ($opt_x || $opt_l)) {
$signalled=0;
-sub handler {
+sub handler {
$signalled++;
print STDERR "Received signal - ending run ($signalled).\n";
if($signalled>1) {
@@ -145,4 +145,4 @@ $procs=$i if ($i<$procs);
while($procs) {
$procs-- if(finish);
}
-print STDERR "Complete\n" if ($debug);
+print STDERR "Complete\n" if ($debug);
diff --git a/bin/prancid.in b/bin/prancid.in
index 7ded178..d3e71a4 100755
--- a/bin/prancid.in
+++ b/bin/prancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: prancid.in,v 1.29 2004/01/11 03:49:13 heas Exp $
+## $Id: prancid.in,v 1.32 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -33,16 +33,17 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my($platform); # platform/cpu type
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
+my($platform); # platform/cpu type
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,10 +65,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,10 +78,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,10 +91,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -103,9 +104,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -119,7 +120,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -132,7 +133,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -460,22 +461,18 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version all' => "ShowVersion",
- 'show package' => "ShowPackage",
- 'show hardware' => "ShowHardware",
- 'show inventory' => "ShowInventory",
- 'write term' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version all",
- "show package",
- "show hardware",
- "show inventory",
- "write term"
+@commandtable = (
+ {'show version all' => 'ShowVersion'},
+ {'show package' => 'ShowPackage'},
+ {'show hardware' => 'ShowHardware'},
+ {'show inventory' => 'ShowInventory'},
+ {'write term' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
diff --git a/bin/rancid-fe.in b/bin/rancid-fe.in
index b80a194..3976253 100644
--- a/bin/rancid-fe.in
+++ b/bin/rancid-fe.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: rancid-fe.in,v 1.36 2004/01/11 03:49:13 heas Exp $
+## $Id: rancid-fe.in,v 1.37 2005/06/14 20:20:44 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -19,7 +19,7 @@
## Henry Kilmer, John Heasley, Andrew Partan, Pete Whiting, and Austin Schutz.
##
#
-# rancid-FE - front-end to rancid/jrancid/etc. for use with par.
+# rancid-FE - front-end to rancid/jrancid/etc. for use with par.
#
# usage: rancid-fe <router>:<vendor>
#
diff --git a/bin/rancid-run.in b/bin/rancid-run.in
index 02093bc..9197117 100644
--- a/bin/rancid-run.in
+++ b/bin/rancid-run.in
@@ -1,6 +1,6 @@
#! /bin/sh
##
-## $Id: rancid-run.in,v 1.31 2004/12/24 00:55:26 tex Exp $
+## $Id: rancid-run.in,v 1.32 2005/06/14 20:20:44 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -143,5 +143,5 @@ END
echo
echo ending: `date`
- ) >$LOGDIR/$GROUP.`date +%Y%m%d.%H%M%S` 2>&1
+ ) >$LOGDIR/$GROUP.`date +%Y%m%d.%H%M%S` 2>&1
done
diff --git a/bin/rancid.in b/bin/rancid.in
index 0841594..915be60 100644
--- a/bin/rancid.in
+++ b/bin/rancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: rancid.in,v 1.185 2005/03/29 23:38:41 heas Exp $
+## $Id: rancid.in,v 1.190 2005/06/24 16:07:00 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -34,15 +34,16 @@ $found_end = 0;
$found_version = 0;
$found_env = 0;
$found_diag = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -64,10 +65,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -77,10 +78,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -90,10 +91,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -103,9 +104,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -119,7 +120,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -132,7 +133,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -1235,8 +1236,8 @@ sub WriteTerm {
$lineauto = 1 if /^ modem auto/;
/^ speed / && $lineauto && next; # kill speed on serial lines
/^ clockrate / && next; # kill clockrate on serial interfaces
- if (/^(enable )?(password|passwd) / && $filter_pwds >= 1) {
- ProcessHistory("ENABLE","","","!$1$2 <removed>\n");
+ if (/^(enable )?(password|passwd)( level \d+)? / && $filter_pwds >= 1) {
+ ProcessHistory("ENABLE","","","!$1$2$3 <removed>\n");
next;
}
if (/^(enable secret) / && $filter_pwds >= 2) {
@@ -1315,7 +1316,7 @@ sub WriteTerm {
ProcessHistory("","","","!$1 <removed> $'"); next;
}
# filter HSRP passwords
- if (/^(\s+standby \d authentication) / && $filter_pwds >= 1) {
+ if (/^(\s+standby \d+ authentication) / && $filter_pwds >= 1) {
ProcessHistory("","","","!$1 <removed>\n"); next;
}
# this appears in "measurement/sla" images
@@ -1499,122 +1500,68 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'admin show version' => "ShowVersion",
- 'show version' => "ShowVersion",
- 'show redundancy secondary' => "ShowRedundancy",
- 'show idprom backplane', => "ShowIDprom",
- 'show install active' => "ShowInstallActive",
- 'admin show env all' => "ShowEnv",
- 'show env all' => "ShowEnv",
- 'show rsp chassis-info',=> "ShowRSP",
- 'show gsr chassis' => "ShowGSR",
- 'show boot' => "ShowBoot",
- 'show bootvar' => "ShowBoot",
- 'show variables boot' => "ShowBoot",
- 'show flash' => "ShowFlash",
- 'dir /all nvram:' => "DirSlotN",
- 'dir /all bootflash:' => "DirSlotN",
- 'dir /all slot0:' => "DirSlotN",
- 'dir /all disk0:' => "DirSlotN",
- 'dir /all slot1:' => "DirSlotN",
- 'dir /all disk1:' => "DirSlotN",
- 'dir /all slot2:' => "DirSlotN",
- 'dir /all disk2:' => "DirSlotN",
- 'dir /all harddisk:' => "DirSlotN",
- 'dir /all harddiska:' => "DirSlotN",
- 'dir /all harddiskb:' => "DirSlotN",
- "dir /all sup-bootflash:"=> "DirSlotN", # cat 6500-ios
- "dir /all sup-microcode:"=> "DirSlotN", # cat 6500-ios
- 'dir /all slavenvram:' => "DirSlotN",
- 'dir /all slavebootflash:' => "DirSlotN",
- 'dir /all slaveslot0:' => "DirSlotN",
- 'dir /all slavedisk0:' => "DirSlotN",
- 'dir /all slaveslot1:' => "DirSlotN",
- 'dir /all slavedisk1:' => "DirSlotN",
- 'dir /all slaveslot2:' => "DirSlotN",
- 'dir /all slavedisk2:' => "DirSlotN",
- "dir /all slavesup-bootflash:"=> "DirSlotN", # cat 7609
- 'dir /all sec-nvram:' => "DirSlotN",
- 'dir /all sec-bootflash:' => "DirSlotN",
- 'dir /all sec-slot0:' => "DirSlotN",
- 'dir /all sec-disk0:' => "DirSlotN",
- 'dir /all sec-slot1:' => "DirSlotN",
- 'dir /all sec-disk1:' => "DirSlotN",
- 'dir /all sec-slot2:' => "DirSlotN",
- 'dir /all sec-disk2:' => "DirSlotN",
- 'show controllers' => "ShowContAll",
- 'show controllers cbus' => "ShowContCbus",
- 'show diagbus' => "ShowDiagbus",
- 'admin show diag' => "ShowDiag",
- 'show diag' => "ShowDiag",
- 'show module' => "ShowModule", # cat 6500-ios
- 'show spe version' => "ShowSpeVersion",
- 'show c7200' => "ShowC7200",
- 'show vtp status' => "ShowVTP",
- 'show vlan' => "ShowVLAN",
- 'show running-config' => "WriteTerm",
- 'write term' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "admin show version",
- "show version",
- "show redundancy secondary",
- "show idprom backplane",
- "show install active",
- "admin show env all",
- "show env all",
- "show rsp chassis-info",
- "show gsr chassis",
- "show boot",
- "show bootvar",
- "show variables boot",
- "show flash",
- "dir /all nvram:",
- "dir /all bootflash:",
- "dir /all slot0:",
- "dir /all disk0:",
- "dir /all slot1:",
- "dir /all disk1:",
- "dir /all slot2:",
- "dir /all disk2:",
- "dir /all harddisk:",
- "dir /all harddiska:",
- "dir /all harddiskb:",
- "dir /all sup-bootflash:",
- "dir /all sup-microcode:",
- "dir /all slavenvram:",
- "dir /all slavebootflash:",
- "dir /all slaveslot0:",
- "dir /all slavedisk0:",
- "dir /all slaveslot1:",
- "dir /all slavedisk1:",
- "dir /all slaveslot2:",
- "dir /all slavedisk2:",
- "dir /all slavesup-bootflash:",
- "dir /all sec-nvram:",
- "dir /all sec-bootflash:",
- "dir /all sec-slot0:",
- "dir /all sec-disk0:",
- "dir /all sec-slot1:",
- "dir /all sec-disk1:",
- "dir /all sec-slot2:",
- "dir /all sec-disk2:",
- "show controllers",
- "show controllers cbus",
- "show diagbus",
- "admin show diag",
- "show diag",
- "show module",
- "show spe version",
- "show c7200",
- "show vtp status",
- "show vlan",
- "show running-config",
- "write term"
+@commandtable = (
+ {'admin show version' => 'ShowVersion'},
+ {'show version' => 'ShowVersion'},
+ {'show redundancy secondary' => 'ShowRedundancy'},
+ {'show idprom backplane', => 'ShowIDprom'},
+ {'show install active' => 'ShowInstallActive'},
+ {'admin show env all' => 'ShowEnv'},
+ {'show env all' => 'ShowEnv'},
+ {'show rsp chassis-info', => 'ShowRSP'},
+ {'show gsr chassis' => 'ShowGSR'},
+ {'show boot' => 'ShowBoot'},
+ {'show bootvar' => 'ShowBoot'},
+ {'show variables boot' => 'ShowBoot'},
+ {'show flash' => 'ShowFlash'},
+ {'dir /all nvram:' => 'DirSlotN'},
+ {'dir /all bootflash:' => 'DirSlotN'},
+ {'dir /all slot0:' => 'DirSlotN'},
+ {'dir /all disk0:' => 'DirSlotN'},
+ {'dir /all slot1:' => 'DirSlotN'},
+ {'dir /all disk1:' => 'DirSlotN'},
+ {'dir /all slot2:' => 'DirSlotN'},
+ {'dir /all disk2:' => 'DirSlotN'},
+ {'dir /all harddisk:' => 'DirSlotN'},
+ {'dir /all harddiska:' => 'DirSlotN'},
+ {'dir /all harddiskb:' => 'DirSlotN'},
+ {'dir /all sup-bootflash:' => 'DirSlotN'}, # cat 6500-ios
+ {'dir /all sup-microcode:' => 'DirSlotN'}, # cat 6500-ios
+ {'dir /all slavenvram:' => 'DirSlotN'},
+ {'dir /all slavebootflash:' => 'DirSlotN'},
+ {'dir /all slaveslot0:' => 'DirSlotN'},
+ {'dir /all slavedisk0:' => 'DirSlotN'},
+ {'dir /all slaveslot1:' => 'DirSlotN'},
+ {'dir /all slavedisk1:' => 'DirSlotN'},
+ {'dir /all slaveslot2:' => 'DirSlotN'},
+ {'dir /all slavedisk2:' => 'DirSlotN'},
+ {'dir /all slavesup-bootflash:' => 'DirSlotN'}, # cat 7609
+ {'dir /all sec-nvram:' => 'DirSlotN'},
+ {'dir /all sec-bootflash:' => 'DirSlotN'},
+ {'dir /all sec-slot0:' => 'DirSlotN'},
+ {'dir /all sec-disk0:' => 'DirSlotN'},
+ {'dir /all sec-slot1:' => 'DirSlotN'},
+ {'dir /all sec-disk1:' => 'DirSlotN'},
+ {'dir /all sec-slot2:' => 'DirSlotN'},
+ {'dir /all sec-disk2:' => 'DirSlotN'},
+ {'show controllers' => 'ShowContAll'},
+ {'show controllers cbus' => 'ShowContCbus'},
+ {'show diagbus' => 'ShowDiagbus'},
+ {'admin show diag' => 'ShowDiag'},
+ {'show diag' => 'ShowDiag'},
+ {'show module' => 'ShowModule'}, # cat 6500-ios
+ {'show spe version' => 'ShowSpeVersion'},
+ {'show c7200' => 'ShowC7200'},
+ {'show vtp status' => 'ShowVTP'},
+ {'show vlan' => 'ShowVLAN'},
+ {'show running-config' => 'WriteTerm'},
+ {'write term' => 'WriteTerm'},
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
diff --git a/bin/rivlogin.in b/bin/rivlogin.in
index bbfa9b5..e0de6b2 100644
--- a/bin/rivlogin.in
+++ b/bin/rivlogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: rivlogin.in,v 1.18 2004/07/19 00:06:08 afort Exp $
+## $Id: rivlogin.in,v 1.19 2005/06/14 20:20:44 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -24,8 +24,8 @@
# rivlogin - Riverstone (and Enterasys SSR) login
#
# Based upon rscmd (see nmops.org)
-# rscmd - Riverstone Networks Automated login
-# by Mike MacFaden, Kiran Addepalli
+# rscmd - Riverstone Networks Automated login
+# by Mike MacFaden, Kiran Addepalli
# Riverstone Networks, 2000
#
# Returned to the RANCID crowd by andrew fort
@@ -36,12 +36,12 @@
set verbose 0
set success 1
set config 0
-
+
# in seconds to wait for data back from device
set timeout 10
set tempfile "/tmp/rivlogin.[exec date]"
-# cli command prompt
+# cli command prompt
set my_prompt ">"
set enable_prompt "\#"
@@ -105,27 +105,27 @@ proc label { host } {
# add password at* steve
# add password * hanky-pie
-proc add { var args } {
+proc add { var args } {
global $var
lappend $var $args
-}
+}
# Loads the password file. Note that as this file is tcl, and that
# it is sourced, the user better know what to put in there, as it
# could install more than just password info... I will assume however,
# that a "bad guy" could just as easy put such code in the clogin
-# script, so I will leave .cloginrc as just an extention of that script
+# script, so I will leave .cloginrc as just an extention of that script
proc source_password_file { } {
global env password_file read_password_file
- if { [info exists read_password_file] } {
+ if { [info exists read_password_file] } {
return 1
}
- if { [info exists password_file] == 0 } {
+ if { [info exists password_file] == 0 } {
set password_file $env(HOME)/.cloginrc
}
@@ -149,8 +149,8 @@ proc find { var router } {
return {}
}
- upvar $var list
- if { [info exists list] } {
+ upvar $var list
+ if { [info exists list] } {
foreach line $list {
if { [string match [lindex $line 0] $router ] } {
return [lrange $line 1 end]
@@ -166,7 +166,7 @@ proc find { var router } {
proc auto_exit { } {
- global telnet_id
+ global telnet_id
if { $verbose == 1 } {
puts "DEBUG: auto_exit closing connection to pid $telnet_id\n"
@@ -179,7 +179,7 @@ proc auto_exit { } {
# post: return 0 on successful login, else 1
#
# NOTE: a number of globals are setup: my_prompt, telnet_id are key
-# and paging of cli output is disabled
+# and paging of cli output is disabled
proc login { router user userpswd passwd enapasswd } {
@@ -212,7 +212,7 @@ proc login { router user userpswd passwd enapasswd } {
expect "*"
send "\r"
- # If password fails 3 times then expect again
+ # If password fails 3 times then expect again
set pass_attempt 0
expect {
@@ -220,7 +220,7 @@ proc login { router user userpswd passwd enapasswd } {
-re ".*> " { }
"Password:" {
- incr pass_attempt
+ incr pass_attempt
send "$passwd\r"
exp_continue
}
@@ -232,13 +232,13 @@ proc login { router user userpswd passwd enapasswd } {
send "$user\r"
expect {
- "Password: " {
+ "Password: " {
incr pattempt
if {$pattempt == 1} {
- send "$userpswd\r";
- } else {
- send "$enapasswd\r";
+ send "$userpswd\r";
+ } else {
+ send "$enapasswd\r";
}
exp_continue
}
@@ -246,8 +246,8 @@ proc login { router user userpswd passwd enapasswd } {
-re ".*> " { exp_continue;}
}
}
-
- "%TELNETD-W-BADPASSWD" {
+
+ "%TELNETD-W-BADPASSWD" {
puts "ERROR: bad userid or password to telnet."
return 1
}
@@ -266,7 +266,7 @@ proc login { router user userpswd passwd enapasswd } {
return 1
}
- "Connection closed *" {
+ "Connection closed *" {
if {$pass_attempt == 3} {
puts "ERROR: Maximum attempts for password reached. Check password. Exiting.";
puts $expect_out(0,string);
@@ -279,7 +279,7 @@ proc login { router user userpswd passwd enapasswd } {
return 1
}
- eof {
+ eof {
puts "ERROR: device closed telnet connection during login"
return 1
}
@@ -322,9 +322,9 @@ proc disable_cmd_autocomplete { } {
$my_prompt { }
- timeout {
+ timeout {
puts "ERROR:disable_cmd_autocomplete(TIMEOUT)";
- return 0;
+ return 0;
}
}
@@ -333,7 +333,7 @@ proc disable_cmd_autocomplete { } {
}
# pre: login returned 0, do_enable returned 0, cli is in enable or config mode
-# post: issues logout cli to device, returns 0
+# post: issues logout cli to device, returns 0
proc logout { prompt } {
global config_mode enable_prompt
@@ -342,7 +342,7 @@ proc logout { prompt } {
# verify top level prompt state, move to it if necessary
if { $config_mode == 1 } {
-
+
send "exit\r"
expect {
@@ -382,22 +382,22 @@ proc do_enable { enauser enapasswd userpswd } {
}
set uses_username 0;
-
+
send "enable\r"
expect {
- Username: {
+ Username: {
set uses_username 1;
- send "$enauser\r";
- exp_continue
+ send "$enauser\r";
+ exp_continue
}
- Password: {
+ Password: {
if {$uses_username == 1} {
send "$userpswd\r";
} else {
send "$enapasswd\r";
}
- exp_continue
+ exp_continue
}
"$my_prompt" {
@@ -405,7 +405,7 @@ proc do_enable { enauser enapasswd userpswd } {
return 1
}
- "CONS-W-AUTH_PASSWD" { send "$enapasswd\r"; }
+ "CONS-W-AUTH_PASSWD" { send "$enapasswd\r"; }
"$enable_prompt " { }
"%SYS-W-NOPASSWD*" { }
@@ -415,7 +415,7 @@ proc do_enable { enauser enapasswd userpswd } {
return 1
}
}
-
+
set my_prompt $enable_prompt
return 0
}
@@ -432,7 +432,7 @@ proc do_configure { } {
if { $verbose == 1 } {
puts "DEBUG: do_config: my_prompt = $my_prompt cfg_prompt = $config_prompt"
}
-
+
send "configure\r"
expect {
"$config_prompt " { }
@@ -453,13 +453,13 @@ proc do_configure { } {
# post: logfile open, global var logging == 1, return 0 , else 1
proc start_logfile { output_file } {
- global logging
+ global logging
if { [ string length $output_file ] != 0 } {
- set rc [ catch {
+ set rc [ catch {
log_file -noappend $output_file
} errMsg ]
-
+
if { $rc != 0 } {
puts "ERROR: open file $output_file for write access failed. $errMsg\n"
return 1
@@ -471,7 +471,7 @@ proc start_logfile { output_file } {
}
proc run_commands { prompt cmdstring } {
- global sendstring
+ global sendstring
set commands [split $cmdstring \;]
set num_commands [llength $cmdstring]
@@ -511,7 +511,7 @@ proc run_single_command { prompt cmdstring } {
set need_ays 1
set delay 1
if {$verbose == 1} {
- puts "DEBUG: save startup cmd seen, set need_ays = 1"
+ puts "DEBUG: save startup cmd seen, set need_ays = 1"
}
}
@@ -524,7 +524,7 @@ proc run_single_command { prompt cmdstring } {
if { $delay == 1} {
sleep 1
- }
+ }
expect {
@@ -555,7 +555,7 @@ proc run_single_command { prompt cmdstring } {
"want to overwrite " {
send "yes\r"
if {$verbose == 1} {
- puts "DEBUG: got overwrite question, set need_ays to 0"
+ puts "DEBUG: got overwrite question, set need_ays to 0"
}
set need_ays 0
}
@@ -564,7 +564,7 @@ proc run_single_command { prompt cmdstring } {
"%CONFIG-E-DUPLICATE,*" {
}
- "$prompt" {
+ "$prompt" {
if { $seen_prompt == 0 } {
set seen_prompt 1
}
@@ -584,7 +584,7 @@ proc run_single_command { prompt cmdstring } {
}
- timeout {
+ timeout {
if {$verbose == 1} {
puts "DEBUG: timeout occured for the $seen_time time\n"
}
@@ -599,8 +599,8 @@ proc run_single_command { prompt cmdstring } {
set rc 1
}
- eof {
- puts "ERROR:run_commands(connection closed by device)\n"
+ eof {
+ puts "ERROR:run_commands(connection closed by device)\n"
set rc 1
}
@@ -622,8 +622,8 @@ proc init_userid { } {
if {[ info exists env(RSTONE_USER) ] } {
set default_user $env(RSTONE_USER)
} else {
- # This uses "id" which I think is portable. At least it has existed
- # (without options) on all machines/OSes I've been on recently -
+ # This uses "id" which I think is portable. At least it has existed
+ # (without options) on all machines/OSes I've been on recently -
# unlike whoami or id -nu.
regexp {\(([^)]*)} [exec id] junk default_user
}
@@ -651,7 +651,7 @@ proc process_script_file { filename } {
set rc 0
set ifile ""
- set rc [ catch {
+ set rc [ catch {
set ifile [ open $filename r]
} errMsg ]
@@ -663,16 +663,16 @@ proc process_script_file { filename } {
set line_cnt 0
while { [eof $ifile] != 1 } {
-
+
set bytes [ gets $ifile cmd ]
incr line_cnt
- if { $bytes < 0 } {
- break
+ if { $bytes < 0 } {
+ break
} elseif { $bytes == 0 } {
continue
}
-
+
if { $verbose == 1 } {
puts "DEBUG: line:$line_cnt cmd = $cmd\n"
}
@@ -711,7 +711,7 @@ proc strip_log { filename router } {
global tempfile
- set rc [ catch {
+ set rc [ catch {
set ifile [ open $filename r]
} errMsg ]
@@ -719,7 +719,7 @@ proc strip_log { filename router } {
puts "ERROR: strip_log: open script file $filename for read access failed. $errMsg\n"
return 1
}
- set rc [ catch {
+ set rc [ catch {
set ofile [ open $tempfile w]
} errMsg ]
@@ -731,12 +731,11 @@ proc strip_log { filename router } {
set nl 0
puts $ofile "rscmd: $router : [exec date]"
-
+
while { [eof $ifile] != 1 } {
-
set bytes [ gets $ifile cmd ]
- if { $bytes <= 0 } {
- break
+ if { $bytes <= 0 } {
+ break
}
incr nl
if { $nl <= 2 } {
@@ -894,24 +893,24 @@ set router [string tolower $router]
if { [llength $pswd] == 0 } {
puts "ERROR: - no password for $router in $password_file.\n"
exit 1
- }
+ }
if { $do_enapasswd && [llength $pswd] < 2 } {
puts "ERROR: no enable password found for $router in $password_file."
exit 1
}
-
+
set passwd [join [lindex $pswd 0] ""]
set enapasswd [join [lindex $pswd 1] ""]
}
# Figure out user to login with if necessary
- if {[info exists username]} {
+ if {[info exists username]} {
# command line username
set user $username
} else {
set user [join [find user $router] ""]
if { "$user" == "" } { set user $default_user }
- }
+ }
# Figure out username's password
if {[info exists userpasswd]} {
@@ -919,17 +918,17 @@ set router [string tolower $router]
set userpswd $userpasswd
} else {
set userpswd [join [find userpassword $router] ""]
- if { "$userpswd" == "" } { set userpswd $passwd }
- }
+ if { "$userpswd" == "" } { set userpswd $passwd }
+ }
# Figure out enable username
- if {[info exists enausername]} {
+ if {[info exists enausername]} {
# command line enausername
set enauser $enausername
} else {
set enauser [join [find enauser $router] ""]
- if { "$enauser" == "" } { set enauser $user }
- }
+ if { "$enauser" == "" } { set enauser $user }
+ }
# Login to the router, set my_prompt to router's cmd prompt
if {[login $router $user $userpswd $passwd $enapasswd ]} {
@@ -956,13 +955,13 @@ set router [string tolower $router]
if { $do_command } {
disable_cmd_autocomplete
disable_cli_paging
-
+
if { [start_logfile $output_file] != 0 } {
exit 1
}
if {[ run_commands $my_prompt $command ]} {
- log_file
+ log_file
exit 1
} else {
logout $my_prompt
@@ -970,7 +969,7 @@ set router [string tolower $router]
} elseif { $do_script } {
disable_cmd_autocomplete
disable_cli_paging
-
+
if {[ start_logfile $output_file] != 0 } {
exit 1
}
@@ -985,14 +984,14 @@ set router [string tolower $router]
logout $my_prompt
} else {
- label $router
+ label $router
log_user 1
if {[ start_logfile $output_file] != 0 } {
exit 1
}
interact
- log_file
+ log_file
}
if { $verbose == 1 } {
@@ -1000,7 +999,7 @@ set router [string tolower $router]
}
if { $logging == 1} {
- log_file
+ log_file
strip_log $output_file $router
}
}
diff --git a/bin/rivrancid.in b/bin/rivrancid.in
index 8b9ae03..6d5f869 100644
--- a/bin/rivrancid.in
+++ b/bin/rivrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: rivrancid.in,v 1.9 2004/01/11 03:49:13 heas Exp $
+## $Id: rivrancid.in,v 1.14 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -21,9 +21,9 @@
#
# Amazingly hacked version of Hank's rancid - this one tries to
# deal with Cabletron, Riverstone and Enterasys routers/switches
-#
+#
# 10/23/2002 -- Initial changes for Riverstone/Cabletron support
-# Jim Meehan -- jmeehan@vpizza.org
+# Jim Meehan -- jmeehan@vpizza.org
#
# RANCID - Really Awesome New Cisco confIg Differ
#
@@ -37,15 +37,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # flogin timeout in seconds
+$timeo = 90; # rivlogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -67,10 +68,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -80,10 +81,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -93,22 +94,22 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
- $sorted_lines[$i] = $key;
- $i++;
+ $sorted_lines[$i] = $key;
+ $i++;
}
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -122,7 +123,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -135,7 +136,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -179,7 +180,7 @@ sub ShowUptime {
tr/\015//d;
last if(/^$prompt/);
next if /^\s*$/;
- next if /System up/;
+ next if /System up/;
ProcessHistory("UPTIME","","","!UPTIME: $_");
}
ProcessHistory("","","","!\n");
@@ -197,13 +198,13 @@ sub ShowActive {
s/^\s*(\d+\D: )*//;
# Riverstone/Cabletron doesn't have an "end" line, so
- # we need to set $clean_run here
+ # we need to set $clean_run here
if (/^$prompt/) {
- $clean_run = 1;
- last;
- }
+ $clean_run = 1;
+ last;
+ }
- next if (/Running system configuration/);
+ next if (/Running system configuration/);
# filter out any RCS/CVS tags to avoid confusing local CVS storage
s/\$(Revision|Id):/ $1:/;
@@ -227,22 +228,16 @@ sub ShowActive {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'system show uptime' => "ShowUptime",
- 'system show version' => "ShowVersion",
- 'system show hardware' => "ShowHardware",
- 'system show active-config' => "ShowActive"
-);
-
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important. pita
-
-@commands=(
- "system show uptime",
- "system show version",
- "system show hardware",
- "system show active-config"
+@commandtable = (
+ {'system show uptime' => 'ShowUptime'},
+ {'system show version' => 'ShowVersion'},
+ {'system show hardware' => 'ShowHardware'},
+ {'system show active-config' => 'ShowActive'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -269,7 +264,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/rrancid.in b/bin/rrancid.in
index 7674452..fdfb39c 100644
--- a/bin/rrancid.in
+++ b/bin/rrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: rrancid.in,v 1.18 2004/01/11 03:49:13 heas Exp $
+## $Id: rrancid.in,v 1.23 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -33,15 +33,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -63,10 +64,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -76,10 +77,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -89,22 +90,22 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
- $sorted_lines[$i] = $key;
- $i++;
+ $sorted_lines[$i] = $key;
+ $i++;
}
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -118,7 +119,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -131,7 +132,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -245,7 +246,7 @@ sub WriteTerm {
s/\$(Revision|Id):/ $1:/;
# order access-lists
/^access-list\s+(\d\d?)\s+(\S+)\s+(\S+)/ &&
- ProcessHistory("ACL $1 $2","ipsort","$3","$_") && next;
+ ProcessHistory("ACL $1 $2","ipsort","$3","$_") && next;
# prune snmp community statements
if (/^snmp (group|community) (\S+)/) {
if (defined($ENV{'NOCOMMSTR'})) {
@@ -255,7 +256,7 @@ sub WriteTerm {
}
}
ProcessHistory("","","","$_");
- # end of config
+ # end of config
if (/^end$/) {
$found_end = 1;
last;
@@ -283,26 +284,20 @@ sub FlailHelplessly {
}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- "dir /flash" => "DirFlash",
- "dir /pcmcia0" => "DirFlash",
- "dir /pcmcia1" => "DirFlash",
- 'show hardware' => "ShowHardware",
- 'show chassis' => "ShowChassis",
- 'show slot table' => "ShowSlotTable",
- 'show config' => "WriteTerm"
-);
-@commands=(
- "show version",
- "dir /flash",
- "dir /pcmcia0",
- "dir /pcmcia1",
- "show hardware",
- "show chassis",
- "show slot table",
- "show config"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'dir /flash' => 'DirFlash'},
+ {'dir /pcmcia0' => 'DirFlash'},
+ {'dir /pcmcia1' => 'DirFlash'},
+ {'show hardware' => 'ShowHardware'},
+ {'show chassis' => 'ShowChassis'},
+ {'show slot table' => 'ShowSlotTable'},
+ {'show config' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
$redback_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -330,7 +325,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/tntlogin.in b/bin/tntlogin.in
index 2eae6e3..027be07 100644
--- a/bin/tntlogin.in
+++ b/bin/tntlogin.in
@@ -1,6 +1,6 @@
#! @EXPECT_PATH@ --
##
-## $Id: tntlogin.in,v 1.12 2004/02/02 17:38:36 heas Exp $
+## $Id: tntlogin.in,v 1.17 2005/06/14 20:20:44 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -39,16 +39,16 @@ set password_file $env(HOME)/.cloginrc
set do_command 0
set do_script 0
# The default is to automatically enable
-set avenable 0
+set avenable 0
# The default is that you login non-enabled (tacacs can have you login already
# enabled)
-set avautoenable 1
+set avautoenable 1
# The default is to look in the password file to find the passwords. This
# tracks if we receive them on the command line.
set do_passwd 1
# Find the user in the ENV, or use the unix userid.
-if {[ info exists env(CISCO_USER) ] } {
+if {[ info exists env(CISCO_USER) ]} {
set default_user $env(CISCO_USER)
} elseif {[ info exists env(USER) ]} {
set default_user $env(USER)
@@ -61,9 +61,9 @@ if {[ info exists env(CISCO_USER) ] } {
if [ catch {exec id} reason ] {
send_error "\nError: could not exec id: $reason\n"
exit 1
- }
+ }
regexp {\(([^)]*)} "$reason" junk default_user
-}
+}
# Sometimes routers take awhile to answer (the default is 10 sec)
set timeout 45
@@ -260,6 +260,7 @@ proc source_password_file { password_file } {
}
# Log into the router.
+# returns: 0 on success, 1 on failure
proc login { router user userpswd passwd prompt cmethod cyphertype } {
global spawn_id in_proc do_command do_script
global u_prompt p_prompt sshcmd
@@ -269,6 +270,7 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
# try each of the connection methods in $cmethod until one is successful
set progs [llength $cmethod]
foreach prog [lrange $cmethod 0 end] {
+ incr progs -1
if [string match "telnet*" $prog] {
regexp {telnet(:([^[:space:]]+))*} $prog command suffix port
if {"$port" == ""} {
@@ -278,24 +280,24 @@ proc login { router user userpswd passwd prompt cmethod cyphertype } {
}
if { $retval } {
send_user "\nError: telnet failed: $reason\n"
- exit 1
+ return 1
}
- } elseif ![string compare $prog "ssh"] {
+ } elseif ![string compare $prog "ssh"] {
if [ catch {spawn $sshcmd -c $cyphertype -x -l $user $router} reason ] {
send_user "\nError: $sshcmd failed: $reason\n"
- exit 1
- }
- } elseif ![string compare $prog "rsh"] {
- if [ catch {spawn rsh -l $user $router} reason ] {
- send_user "\nError: rsh failed: $reason\n"
- exit 1
+ return 1
}
- } else {
- puts "\nError: unknown connection method: $prog"
+ } elseif ![string compare $prog "rsh"] {
+ send_error "\nError: unsupported method: rsh\n"
+ if { $progs == 0 } {
+ return 1
+ }
+ continue;
+ } else {
+ send_user "\nError: unknown connection method: $prog\n"
return 1
- }
- incr progs -1
- sleep 0.3
+ }
+ sleep 0.3
# This helps cleanup each expect clause.
expect_after {
@@ -387,7 +389,7 @@ proc run_commands { prompt command } {
send "lines 0\r"
expect -re $prompt {}
regsub -all "\[)(]" $prompt {\\&} reprompt
-
+
# Is this a multi-command?
if [ string match "*\;*" "$command" ] {
set commands [split $command \;]
@@ -409,7 +411,7 @@ proc run_commands { prompt command } {
-re "\[\n\r]+" { exp_continue }
}
}
-
+
send "quit\r"
# expect {
# -re "^WARNING: the current user has insufficient rights to view password fields. A configuration saved under this circumstance should not be used to restore profiles containing passwords. Save anyway? [y/n]"
@@ -496,9 +498,9 @@ foreach router [lrange $argv $i end] {
set cmethod [find method $router]
if { "$cmethod" == "" } { set cmethod {{telnet} {ssh}} }
- # Figure out the SSH executable name
- set sshcmd [find sshcmd $router]
- if { "$sshcmd" == "" } { set sshcmd {ssh} }
+ # Figure out the SSH executable name
+ set sshcmd [find sshcmd $router]
+ if { "$sshcmd" == "" } { set sshcmd {ssh} }
# Login to the router
if {[login $router $ruser $userpswd $passwd $prompt $cmethod $cyphertype]} {
diff --git a/bin/tntrancid.in b/bin/tntrancid.in
index 88520fd..ac3bbee 100644
--- a/bin/tntrancid.in
+++ b/bin/tntrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: tntrancid.in,v 1.8 2004/01/11 03:49:13 heas Exp $
+## $Id: tntrancid.in,v 1.14 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -34,19 +34,19 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # tntlogin timeout in seconds
+$timeo = 90; # tntlogin timeout in seconds
$prompt = "admin> ";
-$always_y = "y"; # cause its a pain.
+$always_y = "y"; # cause its a pain.
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
- print eval "$always_y \%history";
undef %history;
}
if (($new_hist_tag) && ($new_command) && ($command_string)) {
@@ -67,10 +67,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -80,10 +80,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -93,10 +93,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -106,9 +106,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -122,7 +122,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -135,45 +135,40 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
}
-
# This routine processes a "save con"
sub SaveConf {
print STDERR " In SaveConf: $_" if ($debug);
- my($comment) = 1; # strip extra comments, esp to preserve chassis type
while (<INPUT>) {
tr/\015//d;
last if(/^$prompt/);
-# next if(/^\s*$/);
-
-### s/^\s*$/;/;
-
-# Leave software revision, but strip out saved date,
-# which causes rancid to think it changes each poll
+ # Leave software revision, but strip out saved date,
+ # which causes rancid to think it changes each poll
if (/^; saved from /) {
- ProcessHistory("","","","$_");
- next;
+ ProcessHistory("","","","$_");
+ next;
}
/^; saved / && next;
# catch anything that wasnt match above.
ProcessHistory("","","","$_");
+
# end of config
-# if (/^# End of configuration file/i) {
if (/; profiles saved$/) {
printf STDERR " End SaveConf: $_" if ($debug);
$found_end = 1;
print STDOUT "$found_end = found_end within test\n";
- return(1);
+ return(1);
}
- $found_end = 1;
+ # XXX what is the purpose of this?
+ $found_end = 1;
#### print STDOUT "$found_end = found_end at test\n";
}
$found_end = 1;
@@ -189,17 +184,16 @@ print STDOUT "$found_end = found_end at end test\n";
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'save con' => "SaveConf"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "save con"
+@commandtable = (
+ {'save con' => 'SaveConf'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$tnt_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
-$tnt_cmds="save con";
open(OUTPUT,">$host.new") || die "Can't open $host.new for writing: $!\n";
select(OUTPUT);
@@ -223,7 +217,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
@@ -234,8 +228,8 @@ ProcessHistory("","","","#RANCID-CONTENT-TYPE: tnt\n#\n");
ProcessHistory("COMMENTS","keysort","X0",";\n");
TOP: while(<INPUT>) {
tr/\015//d;
-
- if (/^Error:/) {
+
+ if (/^Error:/) {
print STDOUT ("$host tntlogin error: $_");
print STDERR ("$host tntlogin error: $_") if ($debug);
$clean_run=0;
diff --git a/bin/xrancid.in b/bin/xrancid.in
index b415c86..718c699 100644
--- a/bin/xrancid.in
+++ b/bin/xrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: xrancid.in,v 1.33 2004/01/13 01:56:50 asp Exp $
+## $Id: xrancid.in,v 1.37 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -31,15 +31,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -61,10 +62,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -74,10 +75,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -87,10 +88,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -100,9 +101,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -116,7 +117,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -129,7 +130,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -373,26 +374,20 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'show memory' => "ShowMemory",
- 'show diag' => "ShowDiag",
- 'show switch' => "ShowSwitch",
- 'show slot' => "ShowSlot",
- 'show configuration detail' => "WriteTerm",
- 'show configuration' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version",
- "show memory",
- "show diag",
- "show switch",
- "show slot",
- "show configuration detail",
- "show configuration"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'show memory' => 'ShowMemory'},
+ {'show diag' => 'ShowDiag'},
+ {'show switch' => 'ShowSwitch'},
+ {'show slot' => 'ShowSlot'},
+ {'show configuration detail' => 'WriteTerm'},
+ {'show configuration' => 'WriteTerm'},
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);
@@ -418,7 +413,7 @@ if ($file) {
# determine password filtering mode
if ($ENV{"FILTER_PWDS"} =~ /no/i) {
- $filter_pwds = 0;
+ $filter_pwds = 0;
} elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
$filter_pwds = 2;
} else {
diff --git a/bin/zrancid.in b/bin/zrancid.in
index a969553..0eae9ef 100755
--- a/bin/zrancid.in
+++ b/bin/zrancid.in
@@ -1,6 +1,6 @@
#! @PERLV_PATH@
##
-## $Id: zrancid.in,v 1.8 2004/01/11 03:49:13 heas Exp $
+## $Id: zrancid.in,v 1.11 2005/06/15 20:54:41 heas Exp $
##
## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
## All rights reserved.
@@ -33,15 +33,16 @@ $file = $opt_f;
$host = $ARGV[0];
$clean_run = 0;
$found_end = 0;
-$timeo = 90; # clogin timeout in seconds
+$timeo = 90; # clogin timeout in seconds
-my(%filter_pwds); # password filtering mode
+my(@commandtable, %commands, @commands);# command lists
+my(%filter_pwds); # password filtering mode
# This routine is used to print out the router configuration
sub ProcessHistory {
- my($new_hist_tag,$new_command,$command_string,@string)=(@_);
- if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
- && defined %history) {
+ my($new_hist_tag,$new_command,$command_string,@string) = (@_);
+ if ((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
+ && defined %history) {
print eval "$command \%history";
undef %history;
}
@@ -63,10 +64,10 @@ sub ProcessHistory {
sub numerically { $a <=> $b; }
-# This is a sort routing that will sort numerically on the
+# This is a sort routine that will sort numerically on the
# keys of a hash as if it were a normal array.
sub keynsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort numerically keys(%lines)) {
@@ -76,10 +77,10 @@ sub keynsort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# keys of a hash as if it were a normal array.
sub keysort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort keys(%lines)) {
@@ -89,10 +90,10 @@ sub keysort {
@sorted_lines;
}
-# This is a sort routing that will sort on the
+# This is a sort routine that will sort on the
# values of a hash as if it were a normal array.
sub valsort{
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $key (sort values %lines) {
@@ -102,9 +103,9 @@ sub valsort{
@sorted_lines;
}
-# This is a numerical sort routing (ascending).
+# This is a numerical sort routine (ascending).
sub numsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $num (sort {$a <=> $b} keys %lines) {
@@ -118,7 +119,7 @@ sub numsort {
# ip address when the ip address is anywhere in
# the strings.
sub ipsort {
- local(%lines)=@_;
+ local(%lines) = @_;
local($i) = 0;
local(@sorted_lines);
foreach $addr (sort sortbyipaddr keys %lines) {
@@ -131,7 +132,7 @@ sub ipsort {
# These two routines will sort based upon IP addresses
sub ipaddrval {
my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
- $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
+ $a[3] + 256 * ($a[2] + 256 * ($a[1] +256 * $a[0]));
}
sub sortbyipaddr {
&ipaddrval($a) <=> &ipaddrval($b);
@@ -306,16 +307,15 @@ sub WriteTerm {
sub DoNothing {print STDOUT;}
# Main
-%commands=(
- 'show version' => "ShowVersion",
- 'write term' => "WriteTerm"
-);
-# keys() doesnt return things in the order entered and the order of the
-# cmds is important (show version first and write term last). pita
-@commands=(
- "show version",
- "write term"
+@commandtable = (
+ {'show version' => 'ShowVersion'},
+ {'write term' => 'WriteTerm'}
);
+# Use an array to preserve the order of the commands and a hash for mapping
+# commands to the subroutine and track commands that have been completed.
+@commands = map(keys(%$_), @commandtable);
+%commands = map(%$_, @commandtable);
+
$cisco_cmds=join(";",@commands);
$cmds_regexp=join("|",@commands);