#! /usr/bin/perl -w # { CONFIGURATION SECTION BEGIN ################################################ $stpgraph = '/usr/local/bin/stpgraph'; $fig2dev = '/usr/bin/X11/fig2dev'; $ksh = '/bin/ksh'; $pod2html = '/usr/bin/pod2html'; $mac2vendor = '/usr/local/bin/mac2vendor'; # FIXME - add checkbox to enable mac2vendor translations for PDF and FIG $dotdir = '/usr/local/bin'; # directory in which graphviz dot command resides $community = 'public'; $default_vlan = 1; $default_type = 'application/pdf'; # note: must be one of the types in code below! $default_width = 1; $default_height = 2; $default_showunknown = 1; # boolean $default_exclude = 'access'; $bridgeid_file = '/home/net/cms/bridgeaddress.txt'; $ENV{TMPDIR} = '/tmp/.stpgraph'; use File::Basename; sub devices { foreach () { push(@_, basename($_, ".conf,v")) } @_ } @devices = devices; $dist_url = 'http://net.doit.wisc.edu/~plonka/stpgraph/'; # } CONFIGURATION SECTION END ################################################## use CGI qw(:standard :html3); use CGI::Carp qw(fatalsToBrowser); use FindBin; my $script = basename($FindBin::Script, '.cgi'); $ENV{PATH} = "${dotdir}:" . $ENV{PATH}; chdir($ENV{TMPDIR}) or die "chdir \"$ENV{TMPDIR}\": $!\n"; if (param('help')) { print header; my $command = "${pod2html} ${stpgraph}"; exec $command; die "exec \"$command\": $!"; #NOTREACHED } elsif (param('graph')) { my $type = param('type'); my $vlan = param('vlan')? param('vlan') : $default_vlan; my $Width = param('Width')? param('Width') : $default_width; my $Height = param('Height')? param('Height') : $default_height; my $command = "${stpgraph} -b ${bridgeid_file} -Cc ${community}\@${vlan} -P -s %s_stp${vlan}.obj @devices"; system("${ksh} -xc \"(rm -f *_stp${vlan}.obj; $command)\" 2>stp${vlan}.err"); if (!<$ENV{TMPDIR}/*_stp{$vlan}.obj>) { # print header, "\n", "doh! the following command yielded no spanning-tree information:\n", pre($command), "\n"; print header, "\n", sprintf("Doh! No spanning-tree information found for vlan %s when polling %u device(s) via SNMP!\n", $vlan, scalar(@devices)); exit } print header($type); my @opts = ("-b ${bridgeid_file}"); if (param("showunknown")) { push(@opts, "-u"); if (param("exclude")) { push(@opts, "-X " . param("exclude")) } } if ($type eq "application/pdf") { $command = "$stpgraph -g fig -W${Width} -H${Height} @opts -r *_stp${vlan}.obj |${fig2dev} -L pdf" } elsif ($type eq 'image/png') { $command = "$stpgraph -g png -W${Width} -H${Height} @opts -r *_stp${vlan}.obj" } elsif ($type eq "application/postscript") { $command = "$stpgraph -g ps -W${Width} -H${Height} @opts -r *_stp${vlan}.obj" } else { # dot $command = "$stpgraph -g text -W${Width} -H${Height} @opts -r *_stp${vlan}.obj" } exec "${ksh} -xc \"($command)\" 2>>stp${vlan}.err"; die "exec: $!\n" # NOTREACHED } else { my %typeLabels = ('application/pdf' => 'PDF', 'image/png' => 'PNG image', 'application/postscript' => 'PostScript', 'text/plain' => 'dot (for graphviz)'); my @types = keys(%typeLabels); print CGI::header, "\n", h1($script), "

\n"; print startform('post'), "\n", "\n", "\n", "\n", "\n", "\n", "\n", "", "\n", "
Vlan:", textfield(-name => 'vlan', -default => $default_vlan), "
Output type:", popup_menu(-name => "type", -values => \@types, -labels => \%typeLabels, -default => $default_type), "
Width (in pages):", textfield(-name => 'Width', -default => $default_width), "
Height (in pages):", textfield(-name => 'Height', -default => $default_height), "
", checkbox(-name => 'showunknown', -label => '', -checked => $default_showunknown), "Show unknown", " nodes, exclude:", textfield(-name => 'exclude', -default => $default_exclude), "
 ", submit(-name => 'graph'), "
\n", endform, "

\n"; print hr(), "\n"; my $revision = '$Revision: 1.17 $'; $revision =~ s/\$(revision):\s*(\d+\.\d+)\s*\$/revision $2/i; print("${script} ${FindBin::Script} ${revision}", br(), "\n"); } exit