summaryrefslogtreecommitdiffstats
path: root/util/lg/lgform.cgi.in
diff options
context:
space:
mode:
Diffstat (limited to 'util/lg/lgform.cgi.in')
-rwxr-xr-xutil/lg/lgform.cgi.in200
1 files changed, 200 insertions, 0 deletions
diff --git a/util/lg/lgform.cgi.in b/util/lg/lgform.cgi.in
new file mode 100755
index 0000000..762c9d8
--- /dev/null
+++ b/util/lg/lgform.cgi.in
@@ -0,0 +1,200 @@
+#!@PERLV_PATH@
+# lgform.cgi - Looking glass front-end
+# produces html form for calling lg.cgi
+
+use CGI qw/:standard/;
+
+my(@rtrlist, %rtrlabels);
+my($BASEDIR) = "@prefix@";
+
+
+# read LG configuration file
+sub readconf
+{
+ my($conffile, $cmds);
+ local(*CONF);
+ if (defined($env{LG_CONF})) {
+ $conffile = $env{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(255);
+ }
+
+ return;
+}
+# read router.db file
+sub 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 from
+ # the rancid group's router.db files.
+ local(*DIR);
+ if (! opendir(DIR, $BASEDIR)) {
+ printf(STDERR "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")) {
+ printf(STDERR "ERROR: couldn\'t read $BASEDIR/$dir: $!\n");
+ next;
+ }
+ closedir(DIR);
+ next if (! -f "$BASEDIR/$dir/router.db");
+ 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|juniper)/);
+ push(@rtrlist, join(':', ($record[0], $record[1])));
+ $rtrlabels{join(':', ($record[0], $record[1]))} = $record[0];
+ }
+ close(RTR);
+ } else {
+ printf(STDERR "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|juniper)/);
+ push(@rtrlist, join(':', ($record[0], $record[1])));
+ $rtrlabels{join(':', ($record[0], $record[1]))} = $record[0];
+ }
+ close(RTR);
+ } else {
+ printf(STDERR "ERROR: couldn\'t open the router.db file: $rtrdb: $!\n");
+ exit(255);
+ }
+ }
+
+ return;
+}
+
+# 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_IMAGE
+print $LG_IMAGE;
+
+print <<HEAD ;
+<br>
+<B><FONT SIZE=+2>Looking Glass</FONT></B>
+<br>
+<hr>
+HEAD
+
+# start table, etc here
+print <<DOTABLE ;
+<form action=lg.cgi method=GET>
+<center>
+<table border cellspacing=0 width=575 align=center>
+
+DOTABLE
+
+# available query types here
+print <<QTYPES ;
+<tr valign=top>
+ <TD><B>Query:</B>
+<dd><input type=radio name="query" value="framerelay">show frame-relay pvc [DLCI]</DD>
+<dd><input type=radio name="query" value="interface">show interface &lt;interface&gt;</DD>
+<dd><input type=radio name="query" value="prefix">show ip bgp &lt;prefix&gt; [netmask]</DD>
+<dd><input type=radio name="query" value="regex">show ip bgp regex &lt;reg_exp&gt;</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="prefixlist">show ip prefix-list &lt;list_name&gt;</DD>
+<dd><input type=radio name="query" value="route">show ip route &lt;prefix&gt; [netmask]</DD>
+<dd><input type=radio name="query" value="mbgp">show ip mbgp &lt;prefix&gt; [netmask]</dd>
+<dd><input type=radio name="query" value="mbgpsum">show ip mbgp summary</dd>
+<dd><input type=radio name="query" value="log">show logging [| &lt;match_string&gt;]</DD>
+<dd><input type=radio name="query" value="ping">ping &lt;IP_addr | FQDN&gt;</dd>
+<dd><input type=radio name="query" value="trace">traceroute &lt;IP_addr | FQDN&gt;</DD>
+
+<P><B>Argument(s):</B> <INPUT name="args" size=30></P>
+ </TD>
+ <td ALIGH=left VALIGN=top>
+ <b>Router:</B>
+
+<dd>
+QTYPES
+
+# unimplemented/disabled/removed query types.
+#
+# <dd>show ip bgp neighbor &lt;IP_addr&gt;</dd>
+# <dd>show ip bgp neighbor &lt;IP_addr&gt; advertised routes</dd>
+# <dd>show ip bgp neighbor &lt;IP_addr&gt; flap statistics</dd>
+# <dd>show ip bgp neighbor &lt;IP_addr&gt; received</dd>
+# <dd>show ip bgp neighbor &lt;IP_addr&gt; routes</dd>
+#
+# <dd><input type=radio name="query" value="aspath">sh ip as-path-access-list &lt;list_number&gt;</DD>
+# <dd><input type="radio" name="query" value="acl">sh access-list &lt;list_number&gt;</dd>
+# <dd><input type=radio name="query" value="communitylist">sh ip community-list &lt;list_number&gt;<DD>
+# <dd><input type=radio name="query" value="routemap">sh ip route-map &lt;map_name&gt;</DD>
+
+# read routers table and create the scrolling list
+readrouters();
+print $query->scrolling_list(-name => 'router',
+ -values => \@rtrlist,
+ -size => 20,
+ -labels => \%rtrlabels);
+
+# end
+print <<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>
+TAIL
+
+print <<TAIL ;
+<p>
+</body>
+TAIL
+
+print $query->end_html;
+
+exit 0;