| Line 37... |
Line 37... |
| 37 |
return '' unless $time;
|
37 |
return '' unless $time;
|
| 38 |
return strftime '%Y-%m-%d %H:%M:%S', localtime( $time );
|
38 |
return strftime '%Y-%m-%d %H:%M:%S', localtime( $time );
|
| 39 |
}
|
39 |
}
|
| 40 |
|
40 |
|
| 41 |
sub dumpLine {
|
41 |
sub dumpLine {
|
| - |
|
42 |
my $startTag = shift;
|
| - |
|
43 |
my $endTag = shift;
|
| 42 |
# read in values, defaulting to empty string if undef
|
44 |
# read in values, defaulting to empty string if undef
|
| 43 |
my @values = map{ $_ ? $_ : '' } @_;
|
45 |
my @values = map{ $_ ? $_ : '' } @_;
|
| 44 |
return '<tr><td>' . join( '</td><td>', @values ) . "</td></tr>\n";
|
46 |
return "<tr>$startTag" . join( $endTag . $startTag, @values ) . "$endTag</tr>\n";
|
| 45 |
}
|
47 |
}
|
| 46 |
|
48 |
|
| 47 |
|
49 |
|
| 48 |
# read the saved state into memory if it exists
|
50 |
# read the saved state into memory if it exists
|
| 49 |
die "no state file found, looking at $STATEFILE\n" unless -e $STATEFILE;
|
51 |
die "no state file found, looking at $STATEFILE\n" unless -e $STATEFILE;
|
| Line 57... |
Line 59... |
| 57 |
|
59 |
|
| 58 |
my $yaml = YAML::Tiny->read( $STATEFILE );
|
60 |
my $yaml = YAML::Tiny->read( $STATEFILE );
|
| 59 |
%switchports = %{ $yaml->[0] };
|
61 |
%switchports = %{ $yaml->[0] };
|
| 60 |
|
62 |
|
| 61 |
print "<html>\n<body>\n";
|
63 |
print "<html>\n<body>\n";
|
| 62 |
print "<h1>MapSwitches</h1><h2>Generated: " . &prettyTime(now()) . "</h2>\n";
|
64 |
print "<h1>MapSwitches</h1><h2>Generated: " . &prettyTime(time) . "</h2>\n";
|
| 63 |
print "<table border='1'>\n";
|
65 |
print "<table border='1'>\n";
|
| 64 |
|
66 |
|
| 65 |
foreach my $switch ( sort keys %switchports ) {
|
67 |
foreach my $switch ( sort keys %switchports ) {
|
| 66 |
print "$switchports{$switch}{'name'} Located at $switchports{$switch}{'location'}\n";
|
68 |
print "<tr><td colspan='8' align='center'>$switchports{$switch}{'name'} Located at $switchports{$switch}{'location'}</td></tr>\n";
|
| 67 |
# print the header
|
69 |
# print the header
|
| 68 |
print &dumpLine( 'Switch','Port','Alias','Description','MAC','IP','Host Name','Last Seen' );
|
70 |
print &dumpLine( '<th>', '</th>', 'Switch','Port','Alias','Description','MAC','IP','Host Name','Last Seen' );
|
| 69 |
foreach my $port ( sort {$a<=>$b} keys %{$switchports{$switch}{'ports'}} ) {
|
71 |
foreach my $port ( sort {$a<=>$b} keys %{$switchports{$switch}{'ports'}} ) {
|
| 70 |
foreach my $connection ( keys %{$switchports{$switch}{'ports'}{$port} } ) {
|
72 |
foreach my $connection ( keys %{$switchports{$switch}{'ports'}{$port} } ) {
|
| 71 |
next if $connection eq 'alias' or $connection eq 'description';
|
73 |
next if $connection eq 'alias' or $connection eq 'description';
|
| 72 |
print &dumpLine (
|
74 |
print &dumpLine ( '<td>', '</td>',
|
| 73 |
$switch,
|
75 |
$switch,
|
| 74 |
$port,
|
76 |
$port,
|
| 75 |
$switchports{$switch}{'ports'}{$port}{'alias'},
|
77 |
$switchports{$switch}{'ports'}{$port}{'alias'},
|
| 76 |
$switchports{$switch}{'ports'}{$port}{'description'},
|
78 |
$switchports{$switch}{'ports'}{$port}{'description'},
|
| 77 |
&prettyMAC( $switchports{$switch}{'ports'}{$port}{$connection}{'mac'}),
|
79 |
&prettyMAC( $switchports{$switch}{'ports'}{$port}{$connection}{'mac'}),
|