Revision f9ec5168
Added by Hamish Coleman over 17 years ago
- ID f9ec51680e6e87fc43e1d9cb549d63eb6ecedb9d
mrtg.cgi | ||
---|---|---|
my (@config_files) = @_;
|
||
|
||
my $xsize_default = 500;
|
||
my $ysize_default = 135;
|
||
|
||
my $testmax=0;
|
||
my @list;
|
||
my %tests;
|
||
... | ... | |
$this_ysize = $val +35;
|
||
} elsif ( $var eq 'xsize' ) {
|
||
$this_xsize = $val +100;
|
||
# FIXME - quick-hack
|
||
if ( $testname eq '_' ) {
|
||
$xsize_default = $this_xsize;
|
||
}
|
||
} elsif ( $var eq 'title' ) {
|
||
$this_title = $val;
|
||
}
|
||
|
||
# Skip any default initializers
|
||
if ($testname eq '_') {
|
||
# FIXME - quick-hack
|
||
if($this_xsize) {
|
||
$xsize_default = $this_xsize;
|
||
}
|
||
next;
|
||
}
|
||
if ($testname eq '^') {
|
||
... | ... | |
}
|
||
|
||
if (! exists $tests{$testname}) {
|
||
# initialize
|
||
$list[$testmax]->{xsize} = $xsize_default;
|
||
$list[$testmax]->{ysize} = $ysize_default;
|
||
|
||
$tests{$testname}=$testmax;
|
||
$list[$testmax]->{name} = $testname;
|
||
$list[$testmax]->{xsize} = $xsize_default;
|
||
$testnr = $testmax;
|
||
# TODO - replace testmax with (scalar @list)
|
||
$testmax++;
|
||
... | ... | |
return $l;
|
||
}
|
||
|
||
sub print_table($$) {
|
||
sub print_menu_table($$) {
|
||
my ($lists,$style) = @_;
|
||
|
||
print "\n<table border=2 cellpadding=2 cellspacing=0 style=\"margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;\">\n";
|
||
... | ... | |
$selfurl.='graph='.$graph.'&';
|
||
}
|
||
|
||
my @display_order = (0..$#list);
|
||
@display_order = split /:/, param('ord') if defined param('ord');
|
||
for my $router_num (0..$#list){
|
||
my $router = $list[$router_num];
|
||
|
||
for my $index (0..$#list){
|
||
my @spliced = @display_order;
|
||
my $router_num = splice @spliced, $index, 1; # Router removed
|
||
my $router = $list[$router_num];
|
||
# FIXME - what if mtime is undef?
|
||
my $time = localtime $router->{mtime}; # $st_mtime saved in above loop
|
||
($time) = $time =~ /(\d+:\d+:\d+)/; # Just the time
|
||
print hr, "\n";
|
||
|
||
print a({-name=>$index});
|
||
# Print re-ordering links top, bot, up, dn
|
||
my $mv_dn = "";
|
||
my $mv_up = "";
|
||
$" = ':';
|
||
if($index > 0){
|
||
my @top = ($router_num, @spliced);
|
||
my @up = @spliced;
|
||
my $indxup = $index - 1;
|
||
splice @up, $indxup, 0, $router_num;
|
||
|
||
# FIXME - need a way to append this correctly ..
|
||
$mv_up = sprintf "%s %s ", a({-href=>$selfurl."ord=@top#0"}, "Top"), # move to top
|
||
a({-href=>$selfurl."ord=@up#$indxup"}, "Up"); # move up
|
||
}
|
||
if($index < $#list){
|
||
my @bot = (@spliced, $router_num);
|
||
my @down = @spliced;
|
||
my $indxdn = $index + 1;
|
||
splice @down, $indxdn, 0, $router_num;
|
||
|
||
my $indxbot = @list - 3;
|
||
while($indxbot < 0){$indxbot += 1}
|
||
$mv_dn = sprintf "%s %s ", a({-href=>$selfurl."ord=@down#$indxdn"}, "Down"), # move down
|
||
a({-href=>$selfurl."ord=@bot#$indxbot"}, "Bot"); # move to bottom
|
||
}
|
||
undef $";
|
||
|
||
print table({-width=>"100\%"},
|
||
TR(
|
||
td({-align=>"left",-width=>"20\%"}, "$mv_up $mv_dn"),
|
||
td({-align=>"left"},
|
||
b($router->{title}),
|
||
" $time")
|
||
)
|
||
);
|
||
|
||
my ($ysize, $xsize);
|
||
if ( exists $router->{ysize} ) {
|
||
my $time = localtime $router->{mtime}; # $st_mtime saved in above loop
|
||
($time) = $time =~ /(\d+:\d+:\d+)/; # Just the time
|
||
|
||
print "$time <b>$router->{title}</b><br/>";
|
||
|
||
my ($ysize, $xsize);
|
||
$ysize = $router->{ysize};
|
||
} else {
|
||
$ysize = "135";
|
||
}
|
||
if ( exists $router->{xsize} ) {
|
||
$xsize = $router->{xsize};
|
||
} else {
|
||
$xsize = "400";
|
||
}
|
||
print a({-href=>$router->{name}.".html"}, img{-src=>$router->{name}."-$graph.".$router->{imagetype}, -height=>"$ysize", -width=>"$xsize"});
|
||
|
||
print a({-href=>$router->{name}.".html"},
|
||
img{
|
||
-src=>$router->{name}."-$graph.".$router->{imagetype},
|
||
-height=>"$ysize",
|
||
-width=>"$xsize"
|
||
}
|
||
);
|
||
print hr,"\n";
|
||
}
|
||
}
|
||
|
||
sub print_graph_chooser($$) {
|
||
my ($this_graph,$selfurl) = @_;
|
||
|
||
if ($this_graph eq 'day') {
|
||
print 'Daily';
|
||
} else {
|
||
print a({-href=>$selfurl.'graph=day&'}, 'Daily');
|
||
}
|
||
print ' ';
|
||
if ($this_graph eq 'week') {
|
||
print 'Weekly';
|
||
} else {
|
||
print a({-href=>$selfurl.'graph=week&'}, 'Weekly')
|
||
}
|
||
print ' ';
|
||
if ($this_graph eq 'month') {
|
||
print 'Monthly';
|
||
} else {
|
||
print a({-href=>$selfurl.'graph=month&'}, 'Monthly')
|
||
}
|
||
print ' ';
|
||
if ($this_graph eq 'year') {
|
||
print 'Yearly';
|
||
} else {
|
||
print a({-href=>$selfurl.'graph=year&'}, 'Yearly')
|
||
}
|
||
print ' ';
|
||
|
||
print ' ';
|
||
print a({-href=>'?'}, 'Change List'),
|
||
' ',
|
||
'(Current List is ',param('list'),")\n";
|
||
}
|
||
|
||
my @tests = init_tests(@config_files);
|
||
my $lists = init_lists(@tests);
|
||
|
||
... | ... | |
{-width=>"100\%"},
|
||
TR(td("Select which list to show"))
|
||
);
|
||
print_table($lists,'wide');
|
||
print_menu_table($lists,'wide');
|
||
} elsif (!defined $lists->{$wantlist[0]}->{$wantlist[1]}) {
|
||
#FIXME
|
||
print table({-width=>"100\%"}, TR(td("That list is unavailable")));
|
||
} elsif(defined param('test')) {
|
||
print_list($lists,'day',param('list'));
|
||
} else {
|
||
my @list = @{$lists->{$wantlist[0]}->{$wantlist[1]}};
|
||
$selfurl.='list='.param('list').'&';
|
||
my $graph = param('graph') || 'day';
|
||
|
||
my $graph='day';
|
||
my $graph_unchecked='day';
|
||
if (defined param('graph')) {
|
||
$graph_unchecked=param('graph');
|
||
}
|
||
$selfurl.='list='.param('list').'&';
|
||
|
||
print
|
||
"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
|
||
... | ... | |
|
||
print "<table cellpadding=2 cellspacing=0>\n",
|
||
"<tr><td colspan=2>";
|
||
if ($graph_unchecked ne 'day') {
|
||
print a({-href=>$selfurl.'graph=day&'}, 'Daily')
|
||
} else {
|
||
print 'Daily';
|
||
}
|
||
print ' ';
|
||
if ($graph_unchecked ne 'week') {
|
||
print a({-href=>$selfurl.'graph=week&'}, 'Weekly')
|
||
} else {
|
||
print 'Weekly';
|
||
$graph = $graph_unchecked;
|
||
}
|
||
print ' ';
|
||
if ($graph_unchecked ne 'month') {
|
||
print a({-href=>$selfurl.'graph=month&'}, 'Monthly')
|
||
} else {
|
||
print 'Monthly';
|
||
$graph = $graph_unchecked;
|
||
}
|
||
print ' ';
|
||
if ($graph_unchecked ne 'year') {
|
||
print a({-href=>$selfurl.'graph=year&'}, 'Yearly')
|
||
} else {
|
||
print 'Yearly';
|
||
$graph = $graph_unchecked;
|
||
}
|
||
print ' ';
|
||
print a({-href=>'?'}, 'Change List'),
|
||
' ',
|
||
'(Current List is ',param('list'),")\n";
|
||
|
||
print_graph_chooser($graph,$selfurl);
|
||
|
||
print "</tr><tr><td valign=top>";
|
||
print_table($lists,'high');
|
||
print_menu_table($lists,'high');
|
||
print "</td><td valign=top>\n";
|
||
|
||
if ($graph ne 'day') {
|
||
$selfurl.='graph='.$graph.'&';
|
||
}
|
||
|
||
print "Click graph for more info\n";
|
||
print_list($lists,$graph,param('list'));
|
||
|
||
my @display_order = (0..$#list);
|
||
@display_order = split /:/, param('ord') if defined param('ord');
|
||
|
||
for my $index (0..$#list){
|
||
my @spliced = @display_order;
|
||
my $router_num = splice @spliced, $index, 1; # Router removed
|
||
my $router = $list[$router_num];
|
||
# FIXME - what if mtime is undef?
|
||
my $time = localtime $router->{mtime}; # $st_mtime saved in above loop
|
||
($time) = $time =~ /(\d+:\d+:\d+)/; # Just the time
|
||
print hr, "\n";
|
||
|
||
print a({-name=>$index});
|
||
# Print re-ordering links top, bot, up, dn
|
||
my $mv_dn = "";
|
||
my $mv_up = "";
|
||
$" = ':';
|
||
if($index > 0){
|
||
my @top = ($router_num, @spliced);
|
||
my @up = @spliced;
|
||
my $indxup = $index - 1;
|
||
splice @up, $indxup, 0, $router_num;
|
||
|
||
# FIXME - need a way to append this correctly ..
|
||
$mv_up = sprintf "%s %s ", a({-href=>$selfurl."ord=@top#0"}, "Top"), # move to top
|
||
a({-href=>$selfurl."ord=@up#$indxup"}, "Up"); # move up
|
||
}
|
||
if($index < $#list){
|
||
my @bot = (@spliced, $router_num);
|
||
my @down = @spliced;
|
||
my $indxdn = $index + 1;
|
||
splice @down, $indxdn, 0, $router_num;
|
||
|
||
my $indxbot = @list - 3;
|
||
while($indxbot < 0){$indxbot += 1}
|
||
$mv_dn = sprintf "%s %s ", a({-href=>$selfurl."ord=@down#$indxdn"}, "Down"), # move down
|
||
a({-href=>$selfurl."ord=@bot#$indxbot"}, "Bot"); # move to bottom
|
||
}
|
||
undef $";
|
||
|
||
print table({-width=>"100\%"},
|
||
TR(
|
||
td({-align=>"left",-width=>"20\%"}, "$mv_up $mv_dn"),
|
||
td({-align=>"left"},
|
||
b($router->{title}),
|
||
" $time")
|
||
)
|
||
);
|
||
|
||
my ($ysize, $xsize);
|
||
if ( exists $router->{ysize} ) {
|
||
$ysize = $router->{ysize};
|
||
} else {
|
||
$ysize = "135";
|
||
}
|
||
if ( exists $router->{xsize} ) {
|
||
$xsize = $router->{xsize};
|
||
} else {
|
||
$xsize = "400";
|
||
}
|
||
print a({-href=>$router->{name}.".html"}, img{-src=>$router->{name}."-$graph.".$router->{imagetype}, -height=>"$ysize", -width=>"$xsize"});
|
||
|
||
}
|
||
print "</table>\n";
|
||
}
|
||
|
||
... | ... | |
print "<pre>\n", "$warnings", "</pre>\n";
|
||
}
|
||
|
||
#print "\n",hr,"Direct questions and feedback to Mick Ghazey: ",
|
||
# a({-href=>"mailto:mick\@lowdown.com"}, "mick\@lowdown.com"),
|
||
# end_html;
|
||
print "\n",hr,"Direct questions and feedback to ",
|
||
print "\n","Direct questions and feedback to ",
|
||
a({-href=>"mailto:hamish\@zot.org"}, "Hamish"),
|
||
" (Version $VERSION)",
|
||
end_html;
|
Also available in: Unified diff
More functionalisation, remove re-ordering capability