📄 lgform.cgi
字号:
#!/usr/bin/perl## Copyright (C) 1997-2001 by Henry Kilmer.## All rights reserved.#### This software may be freely copied, modified and redistributed without## fee for non-commerical purposes provided that this copyright notice is## preserved intact on all copies and modified copies.#### 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.## lgform.cgi - Looking glass front-end# produces html form for calling lg.cgiuse CGI qw/:standard/;my(@rtrlist, %rtrlabels);my($BASEDIR) = "/nmis/rancid/";# note: the following functions are duplicated between lgform.cgi and lg.cgi# to avoid the need for module inclusion headaches from within a httpd context.# it is just easier to be self-contained.# SO, ANY CHANGES HERE SHOULD BE REFLECTED IN THE OTHER .cgi.# loggingsub dolog{ my($level, $msg) = @_; if (defined($LG_LOG) && $LG_LOG !~ /\//) { openlog($me, "pid", $LG_LOG); syslog($level, "%s", $msg); closelog; } else { local(*LOG); my($file); if (defined($LG_LOG)) { $file = $LG_LOG; } else { $file = "$cache_dir/lg.log"; } # log date, hostname, query, addr if (open(LOG, ">>$file") == 0) { # stderr, if all else fails printf(STDERR "[" . strftime("%a %b %e %H:%M:%S %Y", gmtime) . "] could not open log file $file: $!\n"); printf(STDERR $msg); } else { printf(LOG $msg); close(LOG); } } return;}# read LG configuration filesub readconf{ my($conffile, $cmds); 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"; } if (! -f $conffile) { return; } if (open(CONF, "< $conffile")) { while (<CONF>) { next if (/^\s*(#|$)/); $cmds .= $_; } close(CONF); eval $cmds; } else { printf(STDERR "ERROR: couldn\'t open the configuration file: $conffile: $!\n"); exit(1); } return;}# read router.db filesub readrouters{ my($rtrdb); local(*RTR); if (defined($LG_ROUTERDB)) { $rtrdb = $LG_ROUTERDB; } else { $rtrdb = "$BASEDIR/util/lg/router.db"; } if (! -f $rtrdb) { my(@dirs, $dir); # if the router.db file does not exist, try to compile the list from # the rancid group router.db files. local(*DIR); if (! opendir(DIR, $BASEDIR)) { dolog(LOG_ERR, "ERROR: couldn\'t read $BASEDIR: $!\n"); } else { while ($dir = readdir(DIR)) { next if ($dir =~ /^(\.|\.\.|CVS|bin|logs|util)$/); push(@dirs, $dir) if (-d "$BASEDIR/$dir"); } closedir(DIR); foreach $dir (@dirs) { if (! opendir(DIR, "$BASEDIR/$dir")) { dolog(LOG_ERR, "ERROR: couldn\'t read $BASEDIR/$dir: $!\n"); next; } closedir(DIR); next if (! -f "$BASEDIR/$dir/router.db"); next if ( $dir =~ /$LG_SKIPGROUP/i ); # skip this rancid group if (open(RTR, "< $BASEDIR/$dir/router.db")) { while (<RTR>) { next if (/^\s*(#|$)/); # fqdn:mfg:state @record = split('\:', $_); next if ($record[2] !~ /up/i || $record[1] !~ /(cisco|foundry|juniper)/); push(@rtrlist, join(':', ($record[0], $record[1]))); $rtrlabels{join(':', ($record[0], $record[1]))} = $record[0]; } close(RTR); } else { dolog(LOG_ERR, "ERROR: couldn\'t open the router.db file: $BASEDIR/$dir/router.db: $!\n"); } } } } else { if (open(RTR, "< $rtrdb")) { while (<RTR>) { next if (/^\s*(#|$)/); # fqdn:mfg:state @record = split('\:', $_); next if ($record[2] !~ /up/i || $record[1] !~ /(cisco|foundry|juniper)/); push(@rtrlist, join(':', ($record[0], $record[1]))); $rtrlabels{join(':', ($record[0], $record[1]))} = $record[0]; } close(RTR); } else { dolog(LOG_ERR, "ERROR: couldn\'t open the router.db file: $rtrdb: $!\n"); exit(1); } } return;}# Main()# read the configuration file if it exists.readconf();$query = new CGI;print $query->header;print $query->start_html("LookingGlass form");print "<BODY>";# add the company image, LG_IMAGEprint $LG_IMAGE;print <<HEAD ;<br><B><FONT SIZE=+2>Looking Glass</FONT></B><br><hr>HEAD# start table, etc hereprint <<DOTABLE ;<form action=lg.cgi method=GET><center><table border cellspacing=0 width=700 align=center>DOTABLE# available query types hereprint <<QTYPES ;<tr valign=top> <TD><B>Query:</B><dd><input type=radio name="query" value="version">show version</DD><dd><input type=radio name="query" value="intbrief">show ip interface brief</DD><dd><input type=radio name="query" value="interface">show interface <interface></DD><dd><input type=radio name="query" value="intstat">show interface status</DD><dd><input type=radio name="query" value="arp">show arp</DD><dd><input type=radio name="query" value="mac">show mac-address-table</DD><dd><input type=radio name="query" value="cpu">show processes cpu | e 0.00</DD><dd><input type=radio name="query" value="flow">show ip cache flow</DD><dd><input type=radio name="query" value="nat">show ip nat translations</DD><dd><input type=radio name="query" value="cdp">show cdp neighbor detail</DD><dd><input type=radio name="query" value="eigrp">show ip eigrp neighbors</DD><dd><input type=radio name="query" value="route">show ip route <prefix> [netmask]</DD><dd><input type=radio name="query" value="log">show logging [ | <match_string>]</DD><dd><input type=radio name="query" value="ping">ping <IP_addr | FQDN></dd><dd><input type=radio name="query" value="trace">traceroute <IP_addr | FQDN></DD><P><B>Argument(s):</B> <INPUT name="args" size=30></P> </TD> <td ALIGH=left VALIGN=top> <b>Router:</B><dd>QTYPES#<dd><input type=radio name="query" value="prefixlist">show ip prefix-list <list_name></DD>#<dd><input type=radio name="query" value="mac">show mac-address-table</DD>#<dd><input type=radio name="query" value="interface">show interface status <interface></DD>#<dd><input type=radio name="query" value="mbgp">show ip mbgp <prefix> [netmask]</dd>#<dd><input type=radio name="query" value="mbgpsum">show ip mbgp summary</dd>#<dd><input type=radio name="query" value="routemap">show route-map <map_name></DD>#<dd><input type=radio name="query" value="neighbor">show ip bgp neighbor <IP_addr></DD>#<dd><input type=radio name="query" value="regex">show ip bgp regex <reg_exp></DD>#<dd><input type=radio name="query" value="summary">show ip bgp summary</DD>#<dd><input type=radio name="query" value="damp">show ip bgp dampened-paths</DD>#<dd><input type=radio name="query" value="prefix">show ip bgp <prefix> [netmask]</DD>#<dd><input type=radio name="query" value="framerelay">show frame-relay pvc [DLCI]</DD># <dd><input type=radio name="query" value="aspath">sh ip as-path-access-list <list_number></DD># <dd><input type="radio" name="query" value="acl">sh access-list <list_number></dd># <dd><input type=radio name="query" value="communitylist">sh ip community-list <list_number><DD># <dd><input type=radio name="query" value="routemap">sh ip route-map <map_name></DD># read routers table and create the scrolling listreadrouters();# sort the resulting list@rtrlist = sort { lc($a) cmp lc($b) } @rtrlist;# print $query->scrolling_list(-name => 'router', -values => \@rtrlist, -size => 20, -labels => \%rtrlabels);# endprint <<TAIL ;</dd></td></TABLE><p><input type=submit value=Submit> <INPUT type=reset value=Reset></FORM></center><br><a href=lgnotes.html>Looking Glass notes</a>TAILprint <<TAIL ;<p>$LG_INFO</body>TAILprint $query->end_html;exit(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -