diff options
author | unknown <unknown@unknown> | 2008-02-13 20:34:57 +0000 |
---|---|---|
committer | unknown <unknown@unknown> | 2008-02-13 20:34:57 +0000 |
commit | b73f299e731fbddae095c0b5eff04717b6dce1af (patch) | |
tree | d8ca33707e5504dfd33714c39900160f3a2598f7 /bin/rancid.in | |
parent | ac54243f382e817c08c1f895ccfdc05dcacdb044 (diff) | |
download | rancid-b73f299e731fbddae095c0b5eff04717b6dce1af.tar.gz rancid-b73f299e731fbddae095c0b5eff04717b6dce1af.tar.xz rancid-b73f299e731fbddae095c0b5eff04717b6dce1af.zip |
Imported from rancid-2.3.2a8.tar.gz.HEADrancid-2.3.2a8master
Diffstat (limited to 'bin/rancid.in')
-rw-r--r-- | bin/rancid.in | 227 |
1 files changed, 161 insertions, 66 deletions
diff --git a/bin/rancid.in b/bin/rancid.in index 4b5b12a..45baa5c 100644 --- a/bin/rancid.in +++ b/bin/rancid.in @@ -1,25 +1,45 @@ #! @PERLV_PATH@ ## -## $Id: rancid.in,v 1.218 2006/10/05 04:27:43 heas Exp $ +## $Id$ ## ## @PACKAGE@ @VERSION@ -## Copyright (C) 1997-2006 by Terrapin Communications, Inc. +## Copyright (c) 1997-2007 by Terrapin Communications, Inc. ## All rights reserved. ## -## This software may be freely copied, modified and redistributed -## without fee for non-commerical purposes provided that this license -## remains intact and unmodified with any RANCID distribution. +## This code is derived from software contributed to and maintained by +## Terrapin Communications, Inc. by Henry Kilmer, John Heasley, Andrew Partan, +## Pete Whiting, Austin Schutz, and Andrew Fort. ## -## There is no warranty or other guarantee of fitness of this software. -## It is provided solely "as is". The author(s) disclaim(s) all -## responsibility and liability with respect to this software's usage -## or its effect upon hardware, computer systems, other software, or -## anything else. +## Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions +## are met: +## 1. Redistributions of source code must retain the above copyright +## notice, this list of conditions and the following disclaimer. +## 2. Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in the +## documentation and/or other materials provided with the distribution. +## 3. All advertising materials mentioning features or use of this software +## must display the following acknowledgement: +## This product includes software developed by Terrapin Communications, +## Inc. and its contributors for RANCID. +## 4. Neither the name of Terrapin Communications, Inc. nor the names of its +## contributors may be used to endorse or promote products derived from +## this software without specific prior written permission. +## 5. It is requested that non-binding fixes and modifications be contributed +## back to Terrapin Communications, Inc. ## -## Except where noted otherwise, rancid was written by and is maintained by -## Henry Kilmer, John Heasley, Andrew Partan, Pete Whiting, and Austin Schutz. -## -# +## THIS SOFTWARE IS PROVIDED BY Terrapin Communications, INC. AND CONTRIBUTORS +## ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +## TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COMPANY OR CONTRIBUTORS +## BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +## POSSIBILITY OF SUCH DAMAGE. +# # RANCID - Really Awesome New Cisco confIg Differ # # usage: rancid [-dV] [-l] [-f filename | hostname] @@ -34,6 +54,7 @@ $log = $opt_l; $debug = $opt_d; $file = $opt_f; $host = $ARGV[0]; +$ios = "IOS"; $clean_run = 0; $found_end = 0; $found_version = 0; @@ -42,7 +63,9 @@ $found_diag = 0; $timeo = 90; # clogin timeout in seconds my(@commandtable, %commands, @commands);# command lists -my(%filter_pwds); # password filtering mode +my($aclsort) = ("ipsort"); # ACL sorting mode +my($filter_commstr); # SNMP community string filtering +my($filter_pwds); # password filtering mode # This routine is used to print out the router configuration sub ProcessHistory { @@ -155,8 +178,8 @@ sub ShowVersion { next if (/^(\s*|\s*$cmd\s*)$/); return(1) if /Line has invalid autocommand /; return(1) if /(Invalid input detected|Type help or )/; - return(-1) if (/command authorization failed/i); return(0) if ($found_version); # Only do this routine once + return(-1) if (/command authorization failed/i); # the pager can not be disabled per-session on the PIX if (/^(<-+ More -+>)/) { my($len) = length($1); @@ -168,6 +191,7 @@ sub ShowVersion { $slaveslot = ", slot $1"; next; } + if (/cisco ios xr /i) { $ios = "XR"; } if (/^Application and Content Networking Software/) { $type="CE"; } /^Application and Content Networking Software Release /i && ProcessHistory("COMMENTS","keysort","F1", "!Image: $_") && next; @@ -177,7 +201,7 @@ sub ShowVersion { # license." PIX 7 as "his platform has ..." /^This (PIX|platform) has an?\s+(.*)$/ && ProcessHistory("COMMENTS","keysort","D1", "!$_") && next; - /^(Cisco )?IOS .* Software,? \(([A-Za-z-0-9_]*)\), .*Version\s+(.*)$/ && + /^(Cisco )?IOS .* Software,? \(([A-Za-z0-9_-]*)\), .*Version\s+(.*)$/ && ProcessHistory("COMMENTS","keysort","F1", "!Image:$slave Software: $2, $3\n") && next; /^([A-Za-z-0-9_]*) Synced to mainline version: (.*)$/ && @@ -276,30 +300,13 @@ sub ShowVersion { $type = "AGS"; } elsif ($proc eq "CSC4") { $type = "AGS+"; + } elsif ($proc =~ /1900/) { + $type = "1900"; + $device = "switch"; } elsif ($proc =~ /^(AS)?25[12][12]/) { $type = "2500"; } elsif ($proc =~ /261[01]/ || $proc =~ /262[01]/ ) { $type = "2600"; - } elsif ($proc =~ /^36[0246][0-9]/) { - $type = "3600"; - } elsif ($proc =~ /^37/) { - $type = "3700"; - } elsif ($proc =~ /^38/) { - $type = "3800"; - } elsif ($proc eq "RSP7000") { - $type = "7500"; - } elsif ($proc =~ /RSP\d/) { - $type = "7500"; - } elsif ($proc eq "RP1") { - $type = "7000"; - } elsif ($proc eq "RP") { - $type = "7000"; - } elsif ($proc =~ /720[246]/) { - $type = "7200"; - } elsif ($proc =~ /1200[48]\/GRP/ || $proc =~ /1201[26]\/GRP/) { - $type = "12000"; - } elsif ($proc =~ /1201[26]-8R\/GRP/) { - $type = "12000"; } elsif ($proc =~ /WS-C29/) { $type = "2900XL"; $device = "switch"; @@ -309,23 +316,52 @@ sub ShowVersion { } elsif ($proc =~ /WS-C35/) { $type = "3500XL"; $device = "switch"; + } elsif ($proc =~ /^36[0246][0-9]/) { + $type = "3600"; + } elsif ($proc =~ /^37/) { + $type = "3700"; + } elsif ($proc =~ /^38/) { + $type = "3800"; } elsif ($proc =~ /WS-C45/) { $type = "4500"; $device = "switch"; + } elsif ( $proc =~ /^AS5300/) { + $type = "AS5300"; + } elsif ( $proc =~ /^AS5350/) { + $type = "AS5350"; + } elsif ( $proc =~ /^AS5400/) { + $type = "AS5400"; } elsif ($proc =~ /6000/) { $type = "6000"; $device = "switch"; - } elsif ($proc =~ /CISCO76/) { - $type = "7600"; - $device = "router"; - } elsif ($proc =~ /1900/) { - $type = "1900"; - $device = "switch"; + } elsif ($proc eq "WK-C65") { + $type = "6500"; + } elsif ($proc eq "RP") { + $type = "7000"; + } elsif ($proc eq "RP1") { + $type = "7000"; + } elsif ($proc =~ /720[246]/) { + $type = "7200"; } elsif ( $proc =~ /^73/) { $type = "7300"; + } elsif ($proc eq "RSP7000") { + $type = "7500"; + } elsif ($proc =~ /RSP\d/) { + $type = "7500"; + } elsif ($proc =~ /OSR-76/) { + $type = "7600"; + } elsif ($proc =~ /CISCO76/) { + $type = "7600"; + } elsif ($proc =~ /1200[48]\/(GRP|PRP)/ || $proc =~ /1201[26]\/(GRP|PRP)/) { + $type = "12000"; + } elsif ($proc =~ /1201[26]-8R\/(GRP|PRP)/) { + $type = "12000"; + } elsif ($proc =~ /1240[48]\/(GRP|PRP)/ || $proc =~ /1241[06]\/(GRP|PRP)/) { + $type = "12400"; } else { $type = $proc; } + print STDERR "TYPE = $type\n" if ($debug); ProcessHistory("COMMENTS","keysort","A1", "!Chassis type:$slave $proc - a $type $device\n"); @@ -401,7 +437,13 @@ sub ShowRedundancy { s/^$1\s{$len}//; } - /^IOS .* Software \(([A-Za-z-0-9_]*)\), .*Version\s+(.*)$/ && + if (/^Version information for secondary in slot (\d+):/) { + $slave = " Slave:"; + $slaveslot = ", slot $1"; + next; + } + + /^IOS .* Software \(([A-Za-z0-9_-]*)\), .*Version\s+(.*)$/ && ProcessHistory("COMMENTS","keysort","F1", "!Image:$slave Software: $1, $2\n") && next; /^Compiled (.*)$/ && @@ -480,8 +522,8 @@ sub ShowEnv { #return(1) if ($type !~ /^7/); return(1) if /Line has invalid autocommand /; return(1) if /(Invalid input detected|Type help or )/; - return(-1) if (/command authorization failed/i); return(0) if ($found_env); # Only do this routine once + return(-1) if (/command authorization failed/i); # the pager can not be disabled per-session on the PIX if (/^(<-+ More -+>)/) { my($len) = length($1); @@ -526,6 +568,7 @@ sub ShowRSP { tr/\015//d; last if (/^$prompt/); next if (/^(\s*|\s*$cmd\s*)$/); + return(1) if /(Invalid input detected|Type help or )/; return(-1) if (/command authorization failed/i); # return(1) if ($type !~ /^12[40]/); # the pager can not be disabled per-session on the PIX @@ -558,6 +601,7 @@ sub ShowGSR { tr/\015//d; last if (/^$prompt/); next if (/^(\s*|\s*$cmd\s*)$/); + return(1) if /(Invalid input detected|Type help or )/; return(-1) if (/command authorization failed/i); # return(1) if ($type !~ /^12[40]/); # the pager can not be disabled per-session on the PIX @@ -620,7 +664,7 @@ sub ShowBoot { } else { ProcessHistory("COMMENTS","keysort","H1","!Variable: $_"); } - } elsif (/variable/) { + } elsif (/(variable|register)/) { ProcessHistory("COMMENTS","keysort","H1","!Variable: $_"); } } @@ -678,6 +722,10 @@ sub DirSlotN { return(-1) if /(: device being squeezed|ATA_Status time out)/i; # busy return(-1) if (/command authorization failed/i); return(1) if /(Open device \S+ failed|Error opening \S+:)/; + if (/.*\((\d+) bytes free\)/ && $ios eq "XR") { + my($tmp) = int($1 / (1024 * 1024)); + s/$1 bytes free/$tmp MB free/; + } # the pager can not be disabled per-session on the PIX if (/^(<-+ More -+>)/) { my($len) = length($1); @@ -699,6 +747,7 @@ sub ShowContAll { tr/\015//d; last if (/^$prompt/); next if (/^(\s*|\s*$cmd\s*)$/); + return(1) if /(Invalid input detected|Type help or )/; # return(1) if ($type =~ /^(12[40]|7[05])/); return(-1) if (/command authorization failed/i); # the pager can not be disabled per-session on the PIX @@ -763,6 +812,7 @@ sub ShowContCbus { tr/\015//d; last if (/^$prompt/); next if (/^(\s*|\s*$cmd\s*)$/); + return(1) if /(Invalid input detected|Type help or )/; #return(1) if ($type !~ /^7[05]0/); return(-1) if (/command authorization failed/i); # the pager can not be disabled per-session on the PIX @@ -939,8 +989,8 @@ REDUX: tr/\015//d; # return(1) if ($type !~ /^(12[40]|720|36|26)/); return(1) if /Line has invalid autocommand /; return(1) if /(Invalid input detected|Type help or )/; - return(-1) if (/command authorization failed/i); return(0) if ($found_diag); # Only do this routine once + return(-1) if (/command authorization failed/i); /^$/ && next; # the pager can not be disabled per-session on the PIX if (/^(<-+ More -+>)/) { @@ -1119,14 +1169,26 @@ REDUX: tr/\015//d; ProcessHistory("SLOT","","","!\n"); /\s+(.*) port adapter,?\s+(\d+)\s+/i && - ProcessHistory("SLOT","keysort","B","!Slot $slot: type $1, $2 ports\n") && next; + ProcessHistory("SLOT","keysort","B", + "!Slot $slot: type $1, $2 ports\n") && next; # I/O controller with no interfaces /\s+(.*)\s+port adapter\s*$/i && - ProcessHistory("SLOT","keysort","B","!Slot $slot: type $1, 0 ports\n") && next; + ProcessHistory("SLOT","keysort","B", + "!Slot $slot: type $1, 0 ports\n") && next; /\s+(.*)\s+daughter card(.*)$/ && - ProcessHistory("SLOT","keysort","B","!Slot $slot$WIC: type $1$2\n") && next; + ProcessHistory("SLOT","keysort","B", + "!Slot $slot$WIC: type $1$2\n") && next; /\s+(FT1)$/ && - ProcessHistory("SLOT","keysort","B","!Slot $slot$WIC: type $1\n") && next; + ProcessHistory("SLOT","keysort","B", + "!Slot $slot$WIC: type $1\n") && next; + # AS5300/5400 handling + /^Hardware is\s+(.*)$/i && + ProcessHistory("SLOT","keysort","B","!Slot $slot: type $1\n") + && next; + /^DFC type is\s+(.*)$/i && + ProcessHistory("SLOT","keysort","B","!Slot $slot: type $1\n") + && next; + # # handle WICs lacking "daughter card" in the 2nd line of their # show diag o/p if (defined($WIC)) { @@ -1165,8 +1227,18 @@ REDUX: tr/\015//d; if (/part number\s+:\s+(\S+)/i) { $pn = $1; } if (/board revision\s+:\s+(\S+)/i) { $rev = $1; } if (/pcb serial number\s+:\s+(\S+)/i) { $sn = $1; } + # fru/pid bits, true Cisco evolving "standard", hopefully + # "show inventory" will be "the way" soon. + # + if (/product \(fru\) number\s+:\s+(\S+)/i) { $fn = $1; } + if (/product number\s+:\s+(\S+)/i) { $fn = $1; } + if (/product\s+identifier\s+\(PID\)\s+:\s+(\S+)/i) { $fn = $1; } + if (/fru\s+part\s+number\s+(\S+)/i) { $fn = $1; } } PerlSucks: + # fru/pid bits + ProcessHistory("SLOT","keysort","AG","!Slot $slot$WIC: fru $fn\n"); + # ProcessHistory("SLOT","keysort","B","!Slot $slot$WIC: hvers $hw rev $rev\n"); ProcessHistory("SLOT","keysort","C","!Slot $slot$WIC: part $pn, serial $sn\n"); } @@ -1176,6 +1248,17 @@ PerlSucks: /number\s+(\S+)\s+Part number\s+(\S+)/ && ProcessHistory("SLOT","keysort","D","!Slot $slot$WIC: part $2, serial $1\n") && next; + # AS5x00 bits + /^\ Board Revision\s+(\S+),\s+Serial Number\s+(\S+),/ && + ProcessHistory("SLOT","keysort","D", + "!Slot $slot$WIC: rev $1, serial $2\n") && next; + /^\ Board Hardware Version\s+(\S+),\s+Item Number\s+(\S+),/ && + ProcessHistory("SLOT","keysort","D", + "!Slot $slot$WIC: hvers $1, part $2\n") && next; + /^Motherboard Info:/ && + ProcessHistory("SLOT","keysort","D", + "!Slot $slot$WIC: Motherboard\n") && next; + # } ProcessHistory("SLOT","","","!\n"); return(0); @@ -1301,6 +1384,7 @@ sub ShowC7200 { tr/\015//d; last if (/^$prompt/); next if (/^(\s*|\s*$cmd\s*)$/); + return(1) if /(Invalid input detected|Type help or )/; #return(1) if ($type !~ /^72/); return(-1) if (/command authorization failed/i); /^$/ && next; @@ -1374,7 +1458,7 @@ sub ShowVTP { sub ShowVLAN { print STDERR " In ShowVLAN: $_" if ($debug); - ($_=<INPUT>,return(1)) if (!$DO_SHOW_VLAN); + ($_ = <INPUT>, return(1)) if (!$DO_SHOW_VLAN); while (<INPUT>) { tr/\015//d; @@ -1386,7 +1470,7 @@ sub ShowVLAN { return(1) if /Ambiguous command/i; # newer releases (~12.1(9)) place the vlan config in the normal # configuration (write term). - return(1) if ($type =~ /^(3550|4500|7600)$/); + return(1) if ($type =~ /^(3550|4500)$/); #return(1) if ($type !~ /^(2900XL|3500XL|6000)$/); return(-1) if (/command authorization failed/i); # the pager can not be disabled per-session on the PIX @@ -1411,6 +1495,7 @@ sub WriteTerm { last if (/^$prompt/); return(1) if /Line has invalid autocommand /; return(1) if (/(Invalid input detected|Type help or )/i); + return(0) if ($found_end); # Only do this routine once return(-1) if (/command authorization failed/i); # the pager can not be disabled per-session on the PIX if (/^(<-+ More -+>)/) { @@ -1419,7 +1504,6 @@ sub WriteTerm { } /Non-Volatile memory is in use/ && return(-1); # NvRAM is locked - return(0) if ($found_end); # Only do this routine once $linecnt++; $lineauto = 0 if (/^[^ ]/); # skip the crap @@ -1605,19 +1689,19 @@ 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","$aclsort","$3","$_") && next; # order extended access-lists /^access-list\s+(\d\d\d)\s+(\S+)\s+ip\s+host\s+(\S+)/ && - ProcessHistory("EACL $1 $2","ipsort","$3","$_") && next; + ProcessHistory("EACL $1 $2","$aclsort","$3","$_") && next; /^access-list\s+(\d\d\d)\s+(\S+)\s+ip\s+(\d\S+)/ && - ProcessHistory("EACL $1 $2","ipsort","$3","$_") && next; + ProcessHistory("EACL $1 $2","$aclsort","$3","$_") && next; /^access-list\s+(\d\d\d)\s+(\S+)\s+ip\s+any/ && - ProcessHistory("EACL $1 $2","ipsort","0.0.0.0","$_") && next; + ProcessHistory("EACL $1 $2","$aclsort","0.0.0.0","$_") && next; # order arp lists /^arp\s+(\d+\.\d+\.\d+\.\d+)\s+/ && - ProcessHistory("ARP","ipsort","$1","$_") && next; + ProcessHistory("ARP","$aclsort","$1","$_") && next; /^ip prefix-list\s+(\S+)\s+seq\s+(\d+)\s+(permit|deny)\s+(\d\S+)(\/.*)$/ && - ProcessHistory("PACL $1 $3","ipsort","$4","ip prefix-list $1 $3 $4$5\n") + ProcessHistory("PACL $1 $3","$aclsort","$4","ip prefix-list $1 $3 $4$5\n") && next; # order logging statements /^logging (\d+\.\d+\.\d+\.\d+)/ && @@ -1626,7 +1710,7 @@ sub WriteTerm { # we only prune lines of the form # snmp-server host a.b.c.d <community> if (/^snmp-server host (\d+\.\d+\.\d+\.\d+) /) { - if (defined($ENV{'NOCOMMSTR'})) { + if ($filter_commstr) { my($ip) = $1; my($line) = "snmp-server host $ip"; my(@tokens) = split(' ', $'); @@ -1653,15 +1737,15 @@ sub WriteTerm { next; } if (/^(snmp-server community) (\S+)/) { - if (defined($ENV{'NOCOMMSTR'})) { + if ($filter_commstr) { ProcessHistory("SNMPSERVERCOMM","keysort","$_","!$1 <removed>$'") && next; } else { ProcessHistory("SNMPSERVERCOMM","keysort","$_","$_") && next; } } # prune tacacs/radius server keys - if (/^((tacacs-server|radius-server)\s(\w*[-\s(\s\S+])*\s?key) \d \w+/ - && $filter_pwds >= 1) { + if (/^((tacacs|radius)-server\s(\w*[-\s(\s\S+])*\s?key) (\d )?\w+/ + && $filter_pwds >= 1) { ProcessHistory("","","","!$1 <removed>$'"); next; } # order clns host statements @@ -1705,7 +1789,7 @@ sub WriteTerm { # end of config. the ": " game is for the PIX if (/^(: +)?end$/) { $found_end = 1; - return(1); + return(0); } } # The ContentEngine lacks a definitive "end of config" marker. If we @@ -1713,7 +1797,7 @@ sub WriteTerm { # o/p, we can be reasonably sure that we got the config. if ($type =~ /^CE$/ && $linecnt > 5) { $found_end = 1; - return(1); + return(0); } return(0); @@ -1822,6 +1906,17 @@ if ($file) { } } +# determine ACL sorting mode +if ($ENV{"ACLSORT"} =~ /no/i) { + $aclsort = ""; +} +# determine community string filtering mode +if (defined($ENV{"NOCOMMSTR"}) && + ($ENV{"NOCOMMSTR"} =~ /yes/i || $ENV{"NOCOMMSTR"} =~ /^$/)) { + $filter_commstr = 1; +} else { + $filter_commstr = 0; +} # determine password filtering mode if ($ENV{"FILTER_PWDS"} =~ /no/i) { $filter_pwds = 0; |