#!/usr/bin/perl -w
use strict;
#
# Petr Simandl, www.simandl.cz
#require "/home/www/cgi-bi"/home/www/cgi-bin/switches_definitions.pl"n/switches_definitions.pl";
my %map = do("/etc/switches_definitions.conf");
my $snmpwalk = "/usr/bin/snmpwalk";
my @ports = ();
my @sw = ();
my %sw_d = ();
my $portlist = "";
my $p = 0;
my $d = "";
my ($fnc,$mac,$if,$ver,$bin,$geom,$desc);
print "Content-type: text/html\n\n";
print "
\n\n\n";
print "\n";
print "\n";
print "\n";
#nocache!
print "";
#print "here";
open(CONF,"< /etc/switches.conf") || die("can't open datafile: $!");
while () {
chomp;
next if (/^#/);
next if (/^$/);
if (/^draw_/) { push @sw, $_; next; }
if (/^([0-9a-fA-F]{2}:[0-9a-fA-F]{2}:)|(([0-9]{1,3}\.){3}[0-9]{1,3})/) {
($mac, $portlist) = split(/\|/, $_, 2);
@ports = ();
foreach ( split(/\|/, $portlist) ) {
($p, $d) = split /;/;
$ports[$p] = $d;
}
$sw_d{$mac} = [ @ports ];
}
}
close CONF;
foreach (@sw) {
($fnc, $mac, $if, $ver, $bin, $geom, $desc) = split /\|/;
SWITCH: {
if ($fnc eq "draw_rrcp_switch") {
draw_rrcp_switch($mac,$if,$bin,$desc,$map{$geom},\%sw_d);
last SWITCH;
}
if ($fnc eq "draw_snmp_switch") {
draw_snmp_switch($mac,$if,$ver,$bin,$desc,$map{$geom},\%sw_d);
last SWITCH;
}
}
print " \n";
}
my $date = `date`;
print " $date\n ";
print "";
################################################################################
sub print_port_graph {
my $ip = shift(@_);
my $page = shift(@_);
my $graph = shift(@_);
my $caption = shift(@_);
my $text = shift(@_);
print "$text";
} # end print_port_graph
sub draw_rrcp_switch {
my $mac = shift(@_);
my $if = shift(@_);
my $bin = shift(@_);
my $desc = shift(@_);
my @map = @{shift(@_)};
my $sw_d = shift(@_);
my $w = scalar( @{$map[0]} );
my $h = scalar @map;
my $hmac = "";
my $x = 0;
my $y = 0;
my $e = "";
my $f = "";
my $sirka = 70;
my $label = "";
my $bg = "";
my $enab = "";
my $mod = "";
my $stat = "";
my $link = "";
my $flow = "";
my $port = 0;
my @row = ();
my @pole = ();
my $porty=`sudo $bin $mac\@$if show int | grep ^$if | sed 's/://g' | sed 's/$if\\///g'`;
print "$desc $mac";
# print "