diff options
Diffstat (limited to 'util/lg/lg.cgi.in')
-rwxr-xr-x | util/lg/lg.cgi.in | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/util/lg/lg.cgi.in b/util/lg/lg.cgi.in index cf4caa8..714c6cc 100755 --- a/util/lg/lg.cgi.in +++ b/util/lg/lg.cgi.in @@ -34,6 +34,9 @@ my($pingcmd) = "@LG_PING_CMD@"; my($query, $max_time_diff, $cache_dir, $cloginrc, @results); my($type, $router_param, $remote_user, $arg, $router, $mfg); +my($LG_CACHE_DIR, $LG_CLOGINRC, $LG_IMAGE, $LG_LOG, $LG_ROUTERDB, $LG_AS_REG); +my($LG_BGP_RT, $LG_CACHE_TIME, $LG_SINGLE, $LG_STRIP); + if (!defined($ENV{HOME})) { $ENV{HOME} = "."; } # read LG configuration file @@ -43,6 +46,8 @@ sub readconf local(*CONF); if (defined($env{LG_CONF})) { $conffile = $env{LG_CONF}; + } elsif (-e "lg.conf") { + $conffile = "lg.conf"; } else { $conffile = "$BASEDIR/util/lg/lg.conf"; } @@ -119,14 +124,14 @@ sub DoCmd local(*CMD); if ($mfg =~ /foundry/i) { - open(CMD, "sh -c \"flogin -f $cloginrc -c \'$cmd $arg\' $rtr\" 2>&1 |"); $cmd = $foundryCmd{$type}; + open(CMD, "sh -c \"flogin -f $cloginrc -c \'$cmd $arg\' $rtr\" 2>&1 |"); } elsif ($mfg =~ /juniper/i) { - open(CMD, "sh -c \"jlogin -f $cloginrc -c \'$cmd $arg\' $rtr\" 2>&1 |"); $cmd = $juniperCmd{$type}; + open(CMD, "sh -c \"jlogin -f $cloginrc -c \'$cmd $arg\' $rtr\" 2>&1 |"); } else { - open(CMD, "sh -c \"clogin -noenable -f $cloginrc -c \'$cmd $arg\' $rtr\" 2>&1 |"); $cmd = $ciscoCmd{$type}; + open(CMD, "sh -c \"clogin -noenable -f $cloginrc -c \'$cmd $arg\' $rtr\" 2>&1 |"); } while (<CMD>) { tr/\015//d; @@ -168,6 +173,8 @@ sub mask2len { } # create the page and log the transaction... sub print_results { + my($mfg) = @_; + my($cmd); my($timestr) = strftime("%a %b %e %H:%M:%S %Y %Z", gmtime); dolog(LOG_INFO, sprintf("%s %s %s %s\n", @@ -181,6 +188,14 @@ sub print_results { # add the company image, LG_IMAGE print $LG_IMAGE; + if ($mfg =~ /foundry/i) { + $cmd = $foundryCmd{$type}; + } elsif ($mfg =~ /juniper/i) { + $cmd = $juniperCmd{$type}; + } else { + $cmd = $ciscoCmd{$type}; + } + print <<HEAD ; </b></font> <font size=+3><b><h1>Looking Glass Results - $router @@ -190,7 +205,7 @@ sub print_results { <center> <b>Date:</b> $timestr <p> - <b>Query:</b> $cmdDisp{$type} + <b>Query:</b> $cmd <br> HEAD @@ -267,7 +282,7 @@ $arg = ($query->param('args'))[0]; ($router, $mfg) = split(':', $router_param); if (!defined($type) || !defined($router)) { $results[0] = "You must at least choose a Query and a router. Try buying a clue.\n"; - &print_results; + &print_results($mfg); } # conversion of command "type" passed from lgform.cgi to the vendor's syntax. @@ -278,7 +293,7 @@ if (!defined($type) || !defined($router)) { damp => "show ip bgp dampened-paths", framerelay => "show frame-relay pvc", interface => "show interface", - intbrief => "show ip interface", + intbrief => "show ip interface", # switch in {interface} log => "show logging", mbgp => "show ip mbgp", mbgpsum => "show ip mbgp summary", @@ -361,13 +376,13 @@ if (!defined($type) || !defined($router)) { if ($mfg =~ /juniper/) { if (! defined($juniperCmd{$type})) { $results[0] = "$cmdDisp{$type} not implemented for junipers. sorry.\n"; - &print_results; + &print_results($mfg); } $cmd = $juniperCmd{$type}; } elsif ($mfg =~ /foundry/) { if(! defined($foundryCmd{$type})) { $results[0] = "$cmdDisp{$type} not implemented for foundrys. sorry.\n"; - &print_results; + &print_results($mfg); } $cmd = $foundryCmd{$type}; } else { @@ -378,10 +393,10 @@ if ($mfg =~ /juniper/) { if ($type eq "prefix" || $type eq "mbgp" || $type eq "route" ) { if ($arg[0] !~ /^\d+\.\d+\.\d+\.\d+$/) { $results[0] = "The IP address \"$arg[0]\" is not valid and lacking an address would over-burden our router.\n"; - &print_results; + &print_results($mfg); } elsif (defined($arg[1]) && $arg[1] !~ /^\d+\.\d+\.\d+\.\d+$/) { $results[0] = "The IP netmask \"$arg[1]\" is not valid.\n"; - &print_results; + &print_results($mfg); } if ($mfg =~ /juniper/i && defined($arg[1])) { $arg = $arg[0] . "/" . mask2len($arg[1]); @@ -390,7 +405,7 @@ if ($type eq "prefix" || $type eq "mbgp" || $type eq "route" ) { if ($mfg =~ /juniper/) { $results[0] = "Juniper does not have a show frame-relay pvc command. ". "Use show interface.\n"; - &print_results; + &print_results($mfg); } if ($arg[0] > 15 && $arg[0] < 1024) { $arg = $arg[0]; @@ -398,15 +413,31 @@ if ($type eq "prefix" || $type eq "mbgp" || $type eq "route" ) { undef($arg); } } elsif ($type eq "interface") { - if ($arg[1] =~ /[-\/0-9:.]+/) { - $arg = $arg[0] . " " . $arg[1]; - } else { - if ($arg[0] !~ /^b[^ ]+[0-9]/i && $arg[0] =~ /^b/i && $mfg =~ /(cisco|foundry)/i) { + if ($mfg =~ /(cisco|foundry)/) { + if ($arg[0] !~ /^b[^ ]+[0-9]/i && $arg[0] =~ /^b/i) { $type = "intbrief"; $arg = "brief"; } else { $arg = $arg[0]; } + } elsif ($mfg =~ /juniper/) { + my($optind) = 0; + # arg 0 may be an intf name or a display option, but there can + # only be 2 args + $arg = ""; + while ($optind <= $#arg && $optind < 2) { + $arg[$optind] =~ s/brief/terse/; + if ($arg[$optind] =~ /^([a-z0-9]{2}\-\d+\/\d+\/\d+(:\d+)?)/i) { + $arg .= " $1"; + } elsif ($arg[$optind] =~ /^det/i) { + $arg .= " detail"; + } elsif ($arg[$optind] =~ /^ter/i) { + $arg .= " terse"; + } elsif ($arg[$optind] =~ /^ext/i) { + $arg .= " extensive"; + } + $optind += 1; + } } } elsif ($type eq "log") { if ($arg[0] =~ /^\s*\|?$/) { @@ -428,29 +459,29 @@ if ($type eq "prefix" || $type eq "mbgp" || $type eq "route" ) { if ($arg[0] !~ /^\d+\.\d+\.\d+\.\d+$/) { if ($arg[0] !~ /([A-Za-z0-9-]*.)*[A-Za-z0-9-]*.(com|edu|net|org)/) { $results[0] = "That argument ($arg[0]) is not valid.\n"; - &print_results; + &print_results($mfg); } } $arg = $arg[0]; } elsif ($type eq "aspath" || $type eq "communitylist") { if ($arg[0] !~ /^\d+$/ || ($arg[0] < 1 && $arg[0] > 199)) { $results[0] = "That argument ($arg[0]) is not valid.\n"; - &print_results; + &print_results($mfg); } $arg = $arg[0]; } elsif ($type eq "acl") { if ($arg[0] !~ /^\d+$/ || ($arg[0] < 100 && $arg[0] > 199) || ($arg[0] < 1300 && $arg[0] > 2699)) { $results[0] = "That argument ($arg[0]) is not valid.\n"; - &print_results; + &print_results($mfg); } $arg = $arg[0]; # don't show the jewels - &print_results if ($arg == 98 || $arg == 99); + &print_results($mfg) if ($arg == 98 || $arg == 99); } elsif ($type eq "prefixlist" || $type eq "routemap") { if ($arg[0] !~ /^[0-9A-Za-z][^\s\"]*$/) { $results[0] = "That argument ($arg[0]) is not valid.\n"; - &print_results; + &print_results($mfg); } $arg = $arg[0]; } elsif ($type eq "regex") { @@ -462,13 +493,13 @@ if ($type eq "prefix" || $type eq "mbgp" || $type eq "route" ) { $arg =~ s/^\s*//; $arg =~ s/\s*$//; if ($arg !~ /^[0-9_ ^.*+?[\])\(-]*\$?$/ || $arg =~ /^\s*$/) { $results[0] = "That argument ($arg[0]) is not valid.\n"; - &print_results; + &print_results($mfg); } # pathetic excuses for lookups if ($arg =~ /^[_.* ^]*(\*|1|701|1239|1280|1740|3561|5462|10303)+[_\$]*$/ || $arg =~ /^[_.* ^]*(1|701|1239|1280|1740|3561|5462|10303)+[_ .]*[\[*.]/) { $results[0] = "Get real. Such a query has potential to over-burden our router.\nLook that up on your own router.\n"; - &print_results; + &print_results($mfg); } if ($mfg =~ /juniper/) { $arg =~ s/_/ /g; @@ -486,7 +517,7 @@ if ($type eq "prefix" || $type eq "mbgp" || $type eq "route" ) { if ($arg[0] !~ /^\d+\.\d+\.\d+\.\d+$/) { if ($arg[0] !~ /([A-Za-z0-9-]*.)*[A-Za-z0-9-]*.(com|edu|net|org)/) { $results[0] = "That argument ($arg[0]) is not valid.\n"; - &print_results; + &print_results($mfg); } } $arg = $arg[0]; @@ -523,7 +554,7 @@ if ($type eq "prefix" || $type eq "mbgp" || $type eq "route" ) { if ($arg[0] !~ /^\d+\.\d+\.\d+\.\d+$/) { if ($arg[0] !~ /([A-Za-z0-9-]*.)*[A-Za-z0-9-]*.(com|edu|net|org)/) { $results[0] = "That argument ($arg[0]) is not valid.\n"; - &print_results; + &print_results($mfg); } } $arg = $arg[0]; @@ -576,7 +607,7 @@ if ($type eq "summary" || $type eq "mbgpsu" || $type eq "damp" || $type eq "log" while (<CACHE>) { push(@results, $_); } close CACHE ; $seconds = $dtime; - &print_results ; + &print_results($mfg); } } @@ -590,10 +621,10 @@ if ($type eq "summary" || $type eq "mbgpsu" || $type eq "damp" || $type eq "log" } else { @results = &DoRsh($router, $mfg, $cmd, $arg); } - &print_results ; + &print_results($mfg); } # end dampened-paths/flap-statistics @results = &DoRsh($router, $mfg, $cmd, $arg); -&print_results ; +&print_results($mfg); -exit ; +exit; |