root/mrtg.cgi @ f7fe9beb
| 5b3eb8e6 | Hamish Coleman | #!/usr/bin/perl
 | ||
| 11780c4c | Hamish Coleman | #
 | ||
| # Flexible MRTG index page
 | ||||
| #
 | ||||
| # Based on original work done by mick@lowdown.com, mostly rewritten
 | ||||
| # by Hamish@zot.org
 | ||||
| #
 | ||||
| 5b3eb8e6 | Hamish Coleman | # (c) 1997, Mick Ghazey mick@lowdown.com
 | ||
| # Thanks to Dave Rand, Peter W. Osel and Tobias Oetiker.
 | ||||
| 11780c4c | Hamish Coleman | #
 | ||
| # Requires the CGI package (in mandriva this is perl-CGI)
 | ||||
| f7fe9beb | Hamish Coleman | our $VERSION=5;
 | ||
| 4ee5ba7c | Hamish Coleman | |||
| 11780c4c | Hamish Coleman | use strict;
 | ||
| use warnings;
 | ||||
| 5b3eb8e6 | Hamish Coleman | |||
| f7fe9beb | Hamish Coleman | use FileHandle;
 | ||
| use Data::Dumper;
 | ||||
| $Data::Dumper::Indent = 1;
 | ||||
| $Data::Dumper::Sortkeys = 1;
 | ||||
| 5b3eb8e6 | Hamish Coleman | use CGI ':all';
 | ||
| use CGI::Carp qw(fatalsToBrowser);
 | ||||
| use Sys::Hostname;
 | ||||
| 11780c4c | Hamish Coleman | my @config_files = (
 | ||
| 	'/etc/mrtg.cfg',
 | ||||
| 	'/usr/share/WWW/mrtg/mrtg.cfg',
 | ||||
| );
 | ||||
| # FIXME - globals
 | ||||
| my $gifdone = 0; # Scan for newest graph and save info for later
 | ||||
| my $warnings;
 | ||||
| f7fe9beb | Hamish Coleman | my $db = {};	# storage for all tests found
 | ||
| $db->{default}->{post}->{xsize} = 500;
 | ||||
| $db->{default}->{post}->{ysize} = 135;
 | ||||
| sub config_save_val($$$$) {
 | ||||
| 	my ($filename,$target,$var,$val) = @_;
 | ||||
| 	my $this_ysize;
 | ||||
| 	my $this_xsize;
 | ||||
| 	my $this_title;
 | ||||
| 	# HACK!
 | ||||
| 	if ( $var eq 'ysize' ) {
 | ||||
| 		$val += 35;
 | ||||
| 	} elsif ( $var eq 'xsize' ) {
 | ||||
| 		$val += 100;
 | ||||
| 	}
 | ||||
| 	# Save any default initializers
 | ||||
| 	if ($target eq '_') {
 | ||||
| 		$db->{default}->{post}->{$var} = $val;
 | ||||
| 		return;
 | ||||
| 	}
 | ||||
| 	if ($target eq '^') {
 | ||||
| 		$db->{default}->{pre}->{$var} = $val;
 | ||||
| 		return;
 | ||||
| 	}
 | ||||
| 	# Check for a name collision, and uniqueify
 | ||||
| 	my $unique_target = $target;
 | ||||
| 	my $unique_id = 1;
 | ||||
| 	while (defined $db->{target}->{$unique_target}
 | ||||
| 		 && $db->{target}->{$unique_target}->{_cfgfile} ne $filename) {
 | ||||
| 		$unique_target = $target . '_' . $unique_id;
 | ||||
| 		$unique_id++;
 | ||||
| 	}
 | ||||
| 	if (!defined $db->{target}->{$unique_target}) {
 | ||||
| 		# initialize a new target
 | ||||
| 		#TODO - instantiate new tests from all of the "_"/"^" defaults
 | ||||
| 		push @{$db->{sequence}}, $unique_target;
 | ||||
| 		$db->{target}->{$unique_target}->{_target} = $target;
 | ||||
| 		$db->{target}->{$unique_target}->{_cfgfile} = $filename;
 | ||||
| 		$db->{target}->{$unique_target}->{_sequence} = @{$db->{sequence}};
 | ||||
| 		$db->{target}->{$unique_target}->{xsize} = $db->{default}->{post}->{xsize};
 | ||||
| 		$db->{target}->{$unique_target}->{ysize} = $db->{default}->{post}->{ysize};
 | ||||
| 	}
 | ||||
| 	$db->{target}->{$unique_target}->{$var} = $val;
 | ||||
| }
 | ||||
| # Load one or more files
 | ||||
| #
 | ||||
| sub config_load_file(@) {
 | ||||
| 	while (@_) {
 | ||||
| 		my $filename = shift;
 | ||||
| 		my $fh = new FileHandle $filename,"r";
 | ||||
| 		if (!defined $fh) {
 | ||||
| 			# FIXME globals
 | ||||
| 			$warnings .= "Warning: Could not open $filename $!\n";
 | ||||
| 		}
 | ||||
| 		#TODO - multi-line values
 | ||||
| 		while(<$fh>){
 | ||||
| 			# Is this a standard MRTG setting?
 | ||||
| 			if ( $_ =~ /^([^#[][^[]+)\[(.*)\]:\s*(.+)$/ ) {
 | ||||
| 				my $var=lc $1;
 | ||||
| 				my $target=lc $2;
 | ||||
| 				my $val=$3;
 | ||||
| 				config_save_val($filename,$target,$var,$val);
 | ||||
| 			}
 | ||||
| 			# TODO - Handle extra statements:
 | ||||
| 			#	Include
 | ||||
| 			# 	WorkDir
 | ||||
| 			#	LogDir
 | ||||
| 			#	##HC Magic for baseurl
 | ||||
| 		}
 | ||||
| 	}
 | ||||
| }
 | ||||
| # Itterate through the loaded targets and read their mtime and
 | ||||
| # any other filesystem details for them.
 | ||||
| #
 | ||||
| sub config_read_filesystem() {
 | ||||
| 	# check and update details for all known tests;
 | ||||
| 	for my $i (keys %{$db->{target}}) {
 | ||||
| 		my $target = $db->{target}->{$i};
 | ||||
| 		my $testname = $target->{_target};
 | ||||
| 		# TODO - check workdir and validate it here
 | ||||
| 		# Default is GIF, unless a PNG file exists
 | ||||
| 		$target->{_imagetype} = 'gif';
 | ||||
| 		if ( -e "$testname-day.png" ) {
 | ||||
| 			$target->{_imagetype} = "png";
 | ||||
| 		}
 | ||||
| 		# TODO - change the filename based on the displayed period
 | ||||
| 		my $filename = $testname . "-day." . $target->{_imagetype};
 | ||||
| 		my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
 | ||||
| 			$atime,$mtime,$ctime,$blksize,$blocks)
 | ||||
| 			= stat($filename);
 | ||||
| 		if (!defined $mtime) {
 | ||||
| 			# if we cannot stat the file, skip it
 | ||||
| 			next;
 | ||||
| 		}
 | ||||
| 		$target->{_mtime} = $mtime;
 | ||||
| 		# FIXME - global
 | ||||
| 		# find the newest file
 | ||||
| 		if ($mtime > $gifdone) {
 | ||||
| 			$gifdone = $mtime;
 | ||||
| 		}
 | ||||
| 	}
 | ||||
| }
 | ||||
| sub maketree_grouphosttest($) {
 | ||||
| 	my ($name) = @_;
 | ||||
| 	my $sequence = $db->{target}->{$name}->{_sequence};
 | ||||
| 	# Do not classify any test with no separators in it
 | ||||
| 	if ($name !~ /,/) {
 | ||||
| 		$db->{tree}->{other}->{$name} = $sequence;
 | ||||
| 		return;
 | ||||
| 	}
 | ||||
| 	my ($group,$host,$test) = split ',', $name;
 | ||||
| 	# TODO cope with missing group/host/test parts.
 | ||||
| 	# for now, just assume it is not a group/host/test
 | ||||
| 	if (!defined $group || !defined $host || !defined $test) {
 | ||||
| 		$db->{tree}->{other}->{$name} = $sequence;
 | ||||
| 		return;
 | ||||
| 	}
 | ||||
| 	my $hosttype;
 | ||||
| 	# TODO - this needs to have a better way...
 | ||||
| 	# hosttype is the non digit hostname prefix - thus
 | ||||
| 	# "proxy-1" and "proxy-2" would both end up in the
 | ||||
| 	# "proxy-" hosttype
 | ||||
| 	if ($host =~ m/^(.*[^0-9])(\d+)$/) {
 | ||||
| 		$hosttype = $1.'*';
 | ||||
| 	}
 | ||||
| 	if (defined $hosttype) {
 | ||||
| 		$db->{tree}->{group}->{$group}->{host}->{$hosttype}->{$host}->{$test}->{$name} = $sequence;
 | ||||
| 		$db->{tree}->{group}->{$group}->{host}->{$hosttype}->{test}->{$test}->{$host}->{$name} = $sequence;
 | ||||
| 		$db->{tree}->{host}->{$hosttype}->{$host}->{$test}->{$name} = $sequence;
 | ||||
| 		$db->{tree}->{test}->{$test}->{$hosttype}->{$host}->{$name} = $sequence;
 | ||||
| 		$db->{tree}->{group}->{$group}->{test}->{$test}->{$hosttype}->{$host}->{$name} = $sequence;
 | ||||
| 	} else {
 | ||||
| 		$db->{tree}->{group}->{$group}->{host}->{$host}->{$test}->{$name} = $sequence;
 | ||||
| 		$db->{tree}->{host}->{$host}->{$test}->{$name} = $sequence;
 | ||||
| 		$db->{tree}->{test}->{$test}->{$host}->{$name} = $sequence;
 | ||||
| 		$db->{tree}->{group}->{$group}->{test}->{$test}->{$host}->{$name} = $sequence;
 | ||||
| 	}
 | ||||
| }
 | ||||
| # Look through the target database and create tree entries for each cfgfile
 | ||||
| #
 | ||||
| sub maketree() {
 | ||||
| 	for my $name (keys %{$db->{target}}) {
 | ||||
| 		my $sequence = $db->{target}->{$name}->{_sequence};
 | ||||
| 		# config files
 | ||||
| 		my $cfgfile = $db->{target}->{$name}->{_cfgfile};
 | ||||
| 		$db->{tree}->{config}->{$cfgfile}->{$name} = $sequence;
 | ||||
| 		maketree_grouphosttest($name);
 | ||||
| 	}
 | ||||
| }
 | ||||
| # FIXME - global
 | ||||
| my $node_next = 1;
 | ||||
| sub emit_tree_one($$$) {
 | ||||
| 	my ($parentnode,$path,$dir) = @_;
 | ||||
| 	if (!ref($dir)) {
 | ||||
| 		#print "FIXME !REF $dir\n";
 | ||||
| 		print "insDoc($parentnode, gLnk(\"S\", \"FIXME !REF $dir\", \"?\"))\n";
 | ||||
| 	}
 | ||||
| 	for my $i (sort keys %{$dir}) {
 | ||||
| 		my $val = $dir->{$i};
 | ||||
| 		if (!ref($val)) {
 | ||||
| 			#print "insDoc($parentnode, gLnk(\"S\", \"$i\", \"?page=x&path=$path:$i\"))\n";
 | ||||
| 			next;
 | ||||
| 		}
 | ||||
| 		my $node = 'n'.$node_next++;
 | ||||
| 		print "$node = insFld($parentnode, gFld(\"$i\", \"?page=x&path=$path:$i\"))\n";
 | ||||
| 		emit_tree_one("$node","$path:$i",$val);
 | ||||
| 	}
 | ||||
| }
 | ||||
| sub emit_tree($) {
 | ||||
| 	my ($style) = @_;
 | ||||
| 	my $page = 'list';
 | ||||
| 	my $target = 'R';
 | ||||
| 	print "\n";
 | ||||
| 	if ($style ne 'frame') {
 | ||||
| 		print "USEFRAMES = 0\n";
 | ||||
| 		print "PRESERVESTATE =1\n";
 | ||||
| 		# USEICONS = 0
 | ||||
| 		# WRAPTEXT = 1
 | ||||
| 		$page=$style;	
 | ||||
| 		$target='S';
 | ||||
| 	}
 | ||||
| 	print "USETEXTLINKS = 1\n";
 | ||||
| 	print "STARTALLOPEN = 0\n";
 | ||||
| 	print "HIGHLIGHT = 1\n";
 | ||||
| 	print "ICONPATH = ''\n";
 | ||||
| 	print 'foldersTree = gFld("<i>MRTG Tree</i>", "javascript:undefined")',"\n";
 | ||||
| 	print 'foldersTree.treeID = "Frameless"',"\n";
 | ||||
| 	emit_tree_one('foldersTree',"",$db->{tree});
 | ||||
| }
 | ||||
| sub emit_path_contents($$) {
 | ||||
| 	my ($path,$graph) = @_;
 | ||||
| 	my @path = split /:/,$path;
 | ||||
| 	my @pathfound;
 | ||||
| 	my $node = $db->{tree};
 | ||||
| 	while (@path) {
 | ||||
| 		if (!$path[0]) {
 | ||||
| 			shift @path;
 | ||||
| 			next;
 | ||||
| 		}
 | ||||
| 		if (!ref($node)) {
 | ||||
| 			print "Path Error ($path[0])\n";
 | ||||
| 			return;
 | ||||
| 		}
 | ||||
| 		if (!defined $node->{$path[0]}) {
 | ||||
| 			print "Path Not Found ($path[0])\n";
 | ||||
| 			return;
 | ||||
| 		}
 | ||||
| 		push @pathfound, $path[0];
 | ||||
| 		$node = $node->{$path[0]};
 | ||||
| 		shift @path;
 | ||||
| 	}
 | ||||
| 	my @node;
 | ||||
| 	my %targets;
 | ||||
| 	push @node,$node;
 | ||||
| 	while (@node) {
 | ||||
| 		if (!ref($node[0])) {
 | ||||
| 			print "Descent Error ($node[0])\n";
 | ||||
| 			return;
 | ||||
| 		}
 | ||||
| 		for my $i (keys %{$node[0]}) {
 | ||||
| 			my $val = $node[0]->{$i};
 | ||||
| 			if (!ref($val)) {
 | ||||
| 				$targets{$i}++;
 | ||||
| 			} else {
 | ||||
| 				push @node,$val;
 | ||||
| 			}
 | ||||
| 		}
 | ||||
| 		shift @node;
 | ||||
| 	}
 | ||||
| 	# TODO - sort by sequence numbers
 | ||||
| 	for my $i (keys %targets) {
 | ||||
| 		my $target = $db->{target}->{$i};
 | ||||
| 		# FIXME - what if mtime is undef?
 | ||||
| 		my $time = localtime $target->{_mtime}; # $st_mtime saved in above loop
 | ||||
| 		($time) = $time =~ /(\d+:\d+:\d+)/; # Just the time
 | ||||
| 		my $title = $target->{title} || 'UNTITLED';
 | ||||
| 		print "$time <b>$title</b><br/>";
 | ||||
| 		my ($ysize, $xsize);
 | ||||
| 		$ysize = $target->{ysize};
 | ||||
| 		$xsize = $target->{xsize};
 | ||||
| 		# TODO - use workpath and other info to point to other directories
 | ||||
| 		print a({-href=>$target->{_target}.".html"},
 | ||||
| 			img{
 | ||||
| 				-src=>$target->{_target}."-$graph.".$target->{_imagetype},
 | ||||
| 				-height=>"$ysize",
 | ||||
| 				-width=>"$xsize"
 | ||||
| 			}
 | ||||
| 		);
 | ||||
| 		print br,br,"\n";
 | ||||
| 	}
 | ||||
| 	print "<pre>\n";
 | ||||
| 	print Dumper(\%targets);
 | ||||
| 	print "</pre>\n";
 | ||||
| }
 | ||||
| 11780c4c | Hamish Coleman | |||
| e3f912fb | Hamish Coleman | sub init_tests(@) {
 | ||
| 	my (@config_files) = @_;
 | ||||
| 2361679c | Hamish Coleman | 	my $xsize_default = 500;
 | ||
| f9ec5168 | Hamish Coleman | 	my $ysize_default = 135;
 | ||
| 11780c4c | Hamish Coleman | 	my $testmax=0;
 | ||
| 	my @list;
 | ||||
| 	my %tests;
 | ||||
| 	while(@config_files > 0){
 | ||||
| 		my $cfg;
 | ||||
| 		if (!open(In, $cfg = shift @config_files) ) {
 | ||||
| 			$warnings .= "Warning: Could not open $cfg file\n";
 | ||||
| 			next;
 | ||||
| 		}
 | ||||
| 		while(<In>){
 | ||||
| 			#TODO - parse WorkDir: directives
 | ||||
| 2361679c | Hamish Coleman | 			#TODO - instantiate new tests from the "_" defaults
 | ||
| 11780c4c | Hamish Coleman | |||
| 			if ( $_ =~ /^([^#[][^[]+)\[(.*)\]:\s*(.+)$/ ) {
 | ||||
| 2361679c | Hamish Coleman | 				my $testnr;
 | ||
| 				my $var=lc $1;
 | ||||
| 				my $testname=lc $2;
 | ||||
| 				my $val=$3;
 | ||||
| 				my $this_ysize;
 | ||||
| 				my $this_xsize;
 | ||||
| 				my $this_title;
 | ||||
| 				if ( $var eq 'ysize' ) {
 | ||||
| 					$this_ysize = $val +35;
 | ||||
| 				} elsif ( $var eq 'xsize' ) {
 | ||||
| 					$this_xsize = $val +100;
 | ||||
| 				} elsif ( $var eq 'title' ) {
 | ||||
| 					$this_title = $val;
 | ||||
| 				}
 | ||||
| 				# Skip any default initializers
 | ||||
| 				if ($testname eq '_') {
 | ||||
| f9ec5168 | Hamish Coleman | 					# FIXME - quick-hack
 | ||
| 					if($this_xsize) {
 | ||||
| 						$xsize_default = $this_xsize;
 | ||||
| 					}
 | ||||
| 2361679c | Hamish Coleman | 					next;
 | ||
| 				}
 | ||||
| 				if ($testname eq '^') {
 | ||||
| 					next;
 | ||||
| 				}
 | ||||
| 11780c4c | Hamish Coleman | |||
| 				if (! exists $tests{$testname}) {
 | ||||
| f9ec5168 | Hamish Coleman | 					# initialize
 | ||
| 					$list[$testmax]->{xsize} = $xsize_default;
 | ||||
| 					$list[$testmax]->{ysize} = $ysize_default;
 | ||||
| 11780c4c | Hamish Coleman | 					$tests{$testname}=$testmax;
 | ||
| 					$list[$testmax]->{name} = $testname;
 | ||||
| 					$testnr = $testmax;
 | ||||
| 2361679c | Hamish Coleman | 					# TODO - replace testmax with (scalar @list)
 | ||
| 11780c4c | Hamish Coleman | 					$testmax++;
 | ||
| 				} else {
 | ||||
| 					$testnr=$tests{$testname};
 | ||||
| 				}
 | ||||
| e3f912fb | Hamish Coleman | 				$list[$testnr]->{ysize} = $this_ysize if $this_ysize;
 | ||
| 				$list[$testnr]->{xsize} = $this_xsize if $this_xsize;
 | ||||
| 				$list[$testnr]->{title} = $this_title if $this_title;
 | ||||
| 11780c4c | Hamish Coleman | 			}
 | ||
| 		}
 | ||||
| 		close In;
 | ||||
| f7fe9beb | Hamish Coleman | |||
| 		config_load_file($cfg);
 | ||||
| 5b3eb8e6 | Hamish Coleman | 	}
 | ||
| 11780c4c | Hamish Coleman | |||
| 2361679c | Hamish Coleman | 	# check and update details for all known tests;
 | ||
| 11780c4c | Hamish Coleman | 	for my $i (@list) {
 | ||
| 		my $testname = $i->{name};
 | ||||
| 		if (!exists($i->{title})) {
 | ||||
| 			$i->{title}='UNTITLED';
 | ||||
| 		}
 | ||||
| 		# Default is GIF, unless a PNG file exists
 | ||||
| 		$i->{imagetype} = 'gif';
 | ||||
| 		if ( -e "$testname-day.png" ) {
 | ||||
| 			$i->{imagetype} = "png";
 | ||||
| 		}
 | ||||
| 2361679c | Hamish Coleman | 		# TODO - change the filename based on the displayed period
 | ||
| 11780c4c | Hamish Coleman | 		my $filename = $testname . "-day." . $i->{imagetype};
 | ||
| 		my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
 | ||||
| 			$atime,$mtime,$ctime,$blksize,$blocks)
 | ||||
| 			= stat($filename);
 | ||||
| 		if (!defined $mtime) {
 | ||||
| 2361679c | Hamish Coleman | 			# if we cannot stat the file, skip it
 | ||
| 11780c4c | Hamish Coleman | 			next;
 | ||
| 		}
 | ||||
| 		$i->{mtime} = $mtime;
 | ||||
| 		# find the newest file
 | ||||
| 		if ($mtime > $gifdone) {
 | ||||
| 			$gifdone = $mtime;
 | ||||
| 		}
 | ||||
| 5b3eb8e6 | Hamish Coleman | 	}
 | ||
| 11780c4c | Hamish Coleman | |||
| 	return @list;
 | ||||
| }
 | ||||
| sub init_lists(@) {
 | ||||
| 	my (@tests) = @_;
 | ||||
| e3f912fb | Hamish Coleman | 	my $l;
 | ||
| 11780c4c | Hamish Coleman | |||
| 	my %hostlist;
 | ||||
| 	my %hosttypelist;
 | ||||
| 	my %hosttypecount;
 | ||||
| e3f912fb | Hamish Coleman | 	@{$l->{ALL}->{ALL}}=@tests;
 | ||
| 11780c4c | Hamish Coleman | |||
| 	for my $i (0..$#tests) {
 | ||||
| 		my $testname = $tests[$i]->{name};
 | ||||
| e3f912fb | Hamish Coleman | 		# Do not classify any test with no separators in it
 | ||
| 		if ($testname !~ /,/) {
 | ||||
| 			push @{$l->{OTHER}->{OTHER}}, $tests[$i];
 | ||||
| 11780c4c | Hamish Coleman | 			next;
 | ||
| 		}
 | ||||
| 		my ($group,$host,$test) = split ',', $testname;
 | ||||
| 		if (defined $group) {
 | ||||
| e3f912fb | Hamish Coleman | 			push @{$l->{GROUP}->{$group}}, $tests[$i];
 | ||
| 11780c4c | Hamish Coleman | 		}
 | ||
| 		if (defined $host) {
 | ||||
| e3f912fb | Hamish Coleman | 			push @{$l->{HOST}->{$host}}, $tests[$i];
 | ||
| 11780c4c | Hamish Coleman | 		}
 | ||
| 		if (defined $test) {
 | ||||
| e3f912fb | Hamish Coleman | 			push @{$l->{TEST}->{$test}}, $tests[$i];
 | ||
| 11780c4c | Hamish Coleman | 		}
 | ||
| 		# TODO - this needs to have a better way...
 | ||||
| 		# hosttype is the non digit hostname prefix - thus
 | ||||
| 		# "proxy-1" and "proxy-2" would both end up in the
 | ||||
| 		# "proxy-" hosttype
 | ||||
| 		if ($host =~ m/^(.*[^0-9])(\d+)$/) {
 | ||||
| e3f912fb | Hamish Coleman | 			my $hosttype = $1.'*';
 | ||
| 11780c4c | Hamish Coleman | |||
| e3f912fb | Hamish Coleman | 			# count each host only once
 | ||
| 11780c4c | Hamish Coleman | 			if (!defined $hostlist{$host}) {
 | ||
| 				$hostlist{$host}=1;
 | ||||
| 				$hosttypecount{$hosttype}++;
 | ||||
| 			}
 | ||||
| 			push @{$hosttypelist{$hosttype}}, $tests[$i];
 | ||||
| 		}
 | ||||
| 5b3eb8e6 | Hamish Coleman | 	}
 | ||
| 11780c4c | Hamish Coleman | 	for my $i (keys %hosttypelist) {
 | ||
| 		if ($hosttypecount{$i} >1) {
 | ||||
| e3f912fb | Hamish Coleman | 			push @{$l->{TYPE}->{$i}}, @{$hosttypelist{$i}};
 | ||
| 11780c4c | Hamish Coleman | 		}
 | ||
| 	}
 | ||||
| f7fe9beb | Hamish Coleman | |||
| 	maketree();
 | ||||
| e3f912fb | Hamish Coleman | |||
| 	return $l;
 | ||||
| 5b3eb8e6 | Hamish Coleman | }
 | ||
| 51561547 | Hamish Coleman | sub print_menu_table($$$$) {
 | ||
| 	my ($lists,$style,$target,$page) = @_;
 | ||||
| 90053cde | Hamish Coleman | |||
| b992b8e4 | Hamish Coleman | 	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";
 | ||
| 	if ($style eq 'wide') {
 | ||||
| 		print "<tr>\n";
 | ||||
| 		# print headings
 | ||||
| 		for my $i (sort keys %{$lists}) {
 | ||||
| 			print "<th>$i</th>\n";
 | ||||
| 		}
 | ||||
| 		print "</tr>";
 | ||||
| 	}
 | ||||
| 	if ($style eq 'wide') {
 | ||||
| 		print "<tr>\n";
 | ||||
| 	}
 | ||||
| 	# print contents
 | ||||
| 	for my $i (sort keys %{$lists}) {
 | ||||
| 		if ($style eq 'high') {
 | ||||
| 			print "<tr><th>$i</tr>\n";
 | ||||
| 			print "<tr>";
 | ||||
| 		}
 | ||||
| 		print " <td valign=top>\n";
 | ||||
| 		for my $j (sort keys %{$lists->{$i}}) {
 | ||||
| 51561547 | Hamish Coleman | 			print "  ".a({-href=>"?page=$page&list=$i,$j",-target=>$target},"$j")."<br>\n";
 | ||
| b992b8e4 | Hamish Coleman | 		}
 | ||
| 		print " </td>\n";
 | ||||
| 		if ($style eq 'high') {
 | ||||
| 			print "</tr>\n";
 | ||||
| 		}
 | ||||
| 	}
 | ||||
| 	if ($style eq 'wide') {
 | ||||
| 		print "</tr>";
 | ||||
| 	}
 | ||||
| 	print "</table>\n";
 | ||||
| }
 | ||||
| ebfd527a | Hamish Coleman | sub print_treemenu($$) {
 | ||
| 	my ($style,$lists) = @_;
 | ||||
| 6982850b | Hamish Coleman | |||
| ebfd527a | Hamish Coleman | 	my $page = 'list';
 | ||
| 	my $target = 'R';
 | ||||
| 	if ($style ne 'frame') {
 | ||||
| 		print "USEFRAMES = 0\n";
 | ||||
| 		print "PRESERVESTATE =1\n";
 | ||||
| 		# USEICONS = 0
 | ||||
| 		# WRAPTEXT = 1
 | ||||
| 		$page=$style;	
 | ||||
| 		$target='S';
 | ||||
| 	}
 | ||||
| 6982850b | Hamish Coleman | 	print "USETEXTLINKS = 1\n";
 | ||
| 	print "STARTALLOPEN = 0\n";
 | ||||
| 51561547 | Hamish Coleman | 	print "HIGHLIGHT = 1\n";
 | ||
| 6982850b | Hamish Coleman | 	print "ICONPATH = ''\n";
 | ||
| ebfd527a | Hamish Coleman | |||
| 	print 'foldersTree = gFld("<i>MRTG Tree</i>", "javascript:undefined")',"\n";
 | ||||
| 	print 'foldersTree.treeID = "Frameless"',"\n";
 | ||||
| 6982850b | Hamish Coleman | |||
| 	# print contents
 | ||||
| 	for my $i (sort keys %{$lists}) {
 | ||||
| ebfd527a | Hamish Coleman | 		print "m$i = insFld(foldersTree, gFld(\"$i\", \"javascript:undefined\"))\n";
 | ||
| 6982850b | Hamish Coleman | |||
| 		for my $j (sort keys %{$lists->{$i}}) {
 | ||||
| ebfd527a | Hamish Coleman | 			print "insDoc(m$i, gLnk(\"$target\", \"$j\", \"?page=$page&list=$i,$j\"))\n";
 | ||
| 6982850b | Hamish Coleman | 		}
 | ||
| 	}
 | ||||
| f7fe9beb | Hamish Coleman | |||
| 	emit_tree_one('foldersTree','',$db->{tree});
 | ||||
| 6982850b | Hamish Coleman | }
 | ||
| d259f7b9 | Hamish Coleman | sub print_list($$$$) {
 | ||
| 	my ($lists,$graph,$list,$target) = @_;
 | ||||
| b992b8e4 | Hamish Coleman | |||
| 	if (!defined $list) {
 | ||||
| 		return undef;
 | ||||
| 	}
 | ||||
| 90053cde | Hamish Coleman | 	if (!defined $lists) {
 | ||
| 		return undef;
 | ||||
| 	}
 | ||||
| d259f7b9 | Hamish Coleman | |||
| b992b8e4 | Hamish Coleman | 	my @wantlist = split /,/,$list;
 | ||
| 	my @list = @{$lists->{$wantlist[0]}->{$wantlist[1]}};
 | ||||
| f9ec5168 | Hamish Coleman | 	for my $router_num (0..$#list){
 | ||
| 		my $router = $list[$router_num];
 | ||||
| b992b8e4 | Hamish Coleman | |||
| 		# FIXME - what if mtime is undef?
 | ||||
| f9ec5168 | Hamish Coleman | 		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);
 | ||||
| b992b8e4 | Hamish Coleman | 		$ysize = $router->{ysize};
 | ||
| 		$xsize = $router->{xsize};
 | ||||
| d259f7b9 | Hamish Coleman | 		print a({-href=>$router->{name}.".html",-target=>$target},
 | ||
| f9ec5168 | Hamish Coleman | 			img{
 | ||
| 				-src=>$router->{name}."-$graph.".$router->{imagetype},
 | ||||
| 				-height=>"$ysize",
 | ||||
| 				-width=>"$xsize"
 | ||||
| 			}
 | ||||
| 		);
 | ||||
| fc832040 | Hamish Coleman | 		print br,br,"\n";
 | ||
| b992b8e4 | Hamish Coleman | 	}
 | ||
| 90053cde | Hamish Coleman | 	return 1;
 | ||
| b992b8e4 | Hamish Coleman | }
 | ||
| 51561547 | Hamish Coleman | sub print_graph_chooser($$$$) {
 | ||
| 	my ($this_graph,$list,$page,$changepage) = @_;
 | ||||
| f9ec5168 | Hamish Coleman | |||
| 51561547 | Hamish Coleman | 	my $selfurl = "?page=$page&list=$list&";
 | ||
| 90053cde | Hamish Coleman | |||
| f9ec5168 | Hamish Coleman | 	if ($this_graph eq 'day') {
 | ||
| 		print 'Daily';
 | ||||
| 	} else {
 | ||||
| 51561547 | Hamish Coleman | 		print a({-href=>$selfurl.'graph=day',-target=>'_self'}, 'Daily');
 | ||
| f9ec5168 | Hamish Coleman | 	}
 | ||
| 	print ' ';
 | ||||
| 	if ($this_graph eq 'week') {
 | ||||
| 		print 'Weekly';
 | ||||
| 	} else {
 | ||||
| 51561547 | Hamish Coleman | 		print a({-href=>$selfurl.'graph=week',-target=>'_self'}, 'Weekly')
 | ||
| f9ec5168 | Hamish Coleman | 	}
 | ||
| 	print ' ';
 | ||||
| 	if ($this_graph eq 'month') {
 | ||||
| 		print 'Monthly';
 | ||||
| 	} else {
 | ||||
| 51561547 | Hamish Coleman | 		print a({-href=>$selfurl.'graph=month',-target=>'_self'}, 'Monthly')
 | ||
| f9ec5168 | Hamish Coleman | 	}
 | ||
| 	print ' ';
 | ||||
| 	if ($this_graph eq 'year') {
 | ||||
| 		print 'Yearly';
 | ||||
| 	} else {
 | ||||
| 51561547 | Hamish Coleman | 		print a({-href=>$selfurl.'graph=year',-target=>'_self'}, 'Yearly')
 | ||
| f9ec5168 | Hamish Coleman | 	}
 | ||
| 	print ' ';
 | ||||
| 	print ' ';
 | ||||
| 51561547 | Hamish Coleman | 	if (defined $changepage) {
 | ||
| 		print a({-href=>"?page=$changepage"}, 'Change List'), ' ';
 | ||||
| 	}
 | ||||
| 	print '(This List is ',param('list'),")\n";
 | ||||
| f9ec5168 | Hamish Coleman | }
 | ||
| ebfd527a | Hamish Coleman | sub print_menutypelist() {
 | ||
| 9e6ce1af | Hamish Coleman | 	print a({-href=>"?page=none",-target=>"_top"}, "Menu Across");
 | ||
| ebfd527a | Hamish Coleman | 	print br;
 | ||
| 9e6ce1af | Hamish Coleman | 	print a({-href=>"?page=noframe",-target=>"_top"}, "Menu Down");
 | ||
| ebfd527a | Hamish Coleman | 	print br;
 | ||
| 9e6ce1af | Hamish Coleman | 	print a({-href=>"?page=treenf",-target=>"_top"}, "Tree (NF)");
 | ||
| ebfd527a | Hamish Coleman | 	print br;
 | ||
| 9e6ce1af | Hamish Coleman | 	print a({-href=>"?page=treeview",-target=>"_top"}, "Tree (Frames)");
 | ||
| ebfd527a | Hamish Coleman | }
 | ||
| 32359a23 | Hamish Coleman | my $page = param('page') || 'treenf';
 | ||
| 5b3eb8e6 | Hamish Coleman | my $this_host = hostname;
 | ||
| 90053cde | Hamish Coleman | my @tests;
 | ||
| my $lists;
 | ||||
| 9e6ce1af | Hamish Coleman | if($page eq 'treeview') {
 | ||
| 6982850b | Hamish Coleman | 	print "Content-type: text/html\n\n";
 | ||
| 	print "<html><head><title>$this_host MRTG Index (V$VERSION)</title></head>\n";
 | ||||
| 	print "<script>\n";
 | ||||
| 	print "function op() { }\n";
 | ||||
| 	print "</script>\n";
 | ||||
| 	print '<frameset cols="200,*">'; # FIXME onresize if navigator.family==nn4
 | ||||
| 	print '<frame src="?page=treemenu" name=treeframe>';
 | ||||
| 1519ec69 | Hamish Coleman | 	print '<frame src="javascript:parent.op()" name=basefrm>';
 | ||
| 6982850b | Hamish Coleman | 	print "</frameset>\n";
 | ||
| 	print "</html>\n";
 | ||||
| 90053cde | Hamish Coleman | |||
| } elsif($page eq 'list') {
 | ||||
| 	print header,
 | ||||
| 		start_html(-TITLE=>"$this_host MRTG Index (V$VERSION)", -BGCOLOR=>'#e6e6e6'),
 | ||||
| 		"\n";
 | ||||
| 	@tests = init_tests(@config_files);
 | ||||
| 	$lists = init_lists(@tests);
 | ||||
| 	# Time the next update to occur a little while after the next interval completes
 | ||||
| 	my $interval = 300; # 5 min update interval
 | ||||
| 	my $guardband = 15; # updates occur this many seconds after predicted gif completion
 | ||||
| 	my $refresh = $interval + $guardband + $gifdone - time; # predict how long until next update
 | ||||
| 	$refresh = $interval if $refresh <= $guardband;
 | ||||
| 	my $expires = gmtime (time + $interval * 2 + $guardband);
 | ||||
| 11780c4c | Hamish Coleman | |||
| 51561547 | Hamish Coleman | 	my $list = param('list');
 | ||
| 90053cde | Hamish Coleman | 	my $graph = param('graph') || 'day';
 | ||
| 11780c4c | Hamish Coleman | |||
| 	print
 | ||||
| 		"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
 | ||||
| 		"<meta http-equiv=\"refresh\" content=$refresh>\n";
 | ||||
| 51561547 | Hamish Coleman | 	if ($list) {
 | ||
| 		print_graph_chooser($graph,$list,$page,'none');
 | ||||
| 		print "<br/>";
 | ||||
| d259f7b9 | Hamish Coleman | 		print_list($lists,$graph,$list,'basefrm');
 | ||
| 51561547 | Hamish Coleman | 	}
 | ||
| 90053cde | Hamish Coleman | 	print end_html;
 | ||
| 6982850b | Hamish Coleman | } elsif($page eq 'treemenu') {
 | ||
| 	print header,
 | ||||
| 		start_html(-TITLE=>"$this_host MRTG Index (V$VERSION)", -BGCOLOR=>'#e6e6e6'),
 | ||||
| 		"\n";
 | ||||
| 	@tests = init_tests(@config_files);
 | ||||
| 	$lists = init_lists(@tests);
 | ||||
| ebfd527a | Hamish Coleman | |||
| 	print <<EOF;
 | ||||
|   <STYLE>
 | ||||
|     BODY {
 | ||||
|       background-color: white;}
 | ||||
|     TD {
 | ||||
|       font-size: 10pt; 
 | ||||
|       font-family: verdana,helvetica; 
 | ||||
|       text-decoration: none;
 | ||||
|       white-space:nowrap;}
 | ||||
|     A {
 | ||||
|       text-decoration: none;
 | ||||
|       color: black;}
 | ||||
|     .specialClass {
 | ||||
|       font-family:garamond; 
 | ||||
|       font-size:12pt;
 | ||||
|       color:green;
 | ||||
|       font-weight:bold;
 | ||||
|       text-decoration:underline}
 | ||||
|   </STYLE>
 | ||||
| EOF
 | ||||
| 6982850b | Hamish Coleman | 	print '<script src="ua.js"></script>';
 | ||
| 	print '<script src="ftiens4.js"></script>';
 | ||||
| 	print '<script>';
 | ||||
| ebfd527a | Hamish Coleman | 	print_treemenu('frame',$lists);
 | ||
| 6982850b | Hamish Coleman | 	print '</script>';
 | ||
| 	print '<DIV style="position:absolute; top:0; left:0;"><TABLE border=0><TR><TD><FONT size=-2><A style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank>Javascript Tree Menu</A></FONT></TD></TR></TABLE></DIV>';
 | ||||
| 	print '<script>initializeDocument()</script>';
 | ||||
| 	print '<NOSCRIPT>A tree for site navigation will open here if you enable JavaScript in your browser.</NOSCRIPT>';
 | ||||
| f723f5b3 | Hamish Coleman | 	print hr;
 | ||
| ebfd527a | Hamish Coleman | 	print_menutypelist();
 | ||
| 	print end_html;
 | ||||
| } elsif($page eq 'treenf') {
 | ||||
| 	print header,
 | ||||
| 		start_html(-TITLE=>"$this_host MRTG Index (V$VERSION)",
 | ||||
| 			-bgcolor=>"white",
 | ||||
| 			-leftmargin=>"0", -topmargin=>"0",
 | ||||
| 			-marginheight=>"0", -marginwidth=>"0",
 | ||||
| 			-onResize=>"if (navigator.family == 'nn4') window.location.reload()" ),
 | ||||
| 		"\n";
 | ||||
| 	@tests = init_tests(@config_files);
 | ||||
| 	$lists = init_lists(@tests);
 | ||||
| 	print <<EOF;
 | ||||
|   <STYLE>
 | ||||
|    /*                                                          */
 | ||||
|    /* Styles for the tree.                                     */
 | ||||
|    /*                                                          */
 | ||||
|    SPAN.TreeviewSpanArea A {
 | ||||
|      font-size: 10pt; 
 | ||||
|      font-family: verdana,helvetica; 
 | ||||
|      text-decoration: none;
 | ||||
|      color: black;}
 | ||||
|    SPAN.TreeviewSpanArea A:hover {
 | ||||
|      color: '#820082';}
 | ||||
|    /*                                                          */
 | ||||
|    /* Styles for the remainder of the document.                */
 | ||||
|    /*                                                          */
 | ||||
|    BODY {
 | ||||
|      background-color: white;}
 | ||||
|    TD {
 | ||||
|      font-size: 10pt; 
 | ||||
|      font-family: verdana,helvetica;}
 | ||||
|   </STYLE>
 | ||||
| EOF
 | ||||
| 	print '<script src="ua.js"></script>';
 | ||||
| 	print '<script src="ftiens4.js"></script>';
 | ||||
| 	print '<script>';
 | ||||
| 	print_treemenu('treenf',$lists);
 | ||||
| 	print '</script>';
 | ||||
| 	print <<EOF;
 | ||||
|  <TABLE cellpadding="0" cellspacing="0" border="0" width="772">
 | ||||
|   <TR>
 | ||||
|    <TD width="178" valign="top">
 | ||||
|     <TABLE cellpadding="4" cellspacing="0" border="0" width="100%">
 | ||||
|      <TR>
 | ||||
|       <TD bgcolor="#ECECD9">
 | ||||
|         <TABLE cellspacing="0" cellpadding="2" border="0" width="100%">
 | ||||
|          <TR>
 | ||||
| bc24f7db | Hamish Coleman | 	  <td width="200" valign="top" bgcolor="#efefef" style="border-right: 1px solid rgb(170, 170, 170); padding: 5px;">
 | ||
| ebfd527a | Hamish Coleman | |||
| bc24f7db | Hamish Coleman |  <TABLE border=0><TR><TD><FONT size=-2><A style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank /></FONT></TD></TR></TABLE>
 | ||
| ebfd527a | Hamish Coleman | |||
|  <SPAN class=TreeviewSpanArea>
 | ||||
|   <SCRIPT>initializeDocument()</SCRIPT>
 | ||||
|   <NOSCRIPT>
 | ||||
|    A tree for site navigation will open here if you enable JavaScript in your browser.
 | ||||
|   </NOSCRIPT>
 | ||||
|  </SPAN>
 | ||||
| EOF
 | ||||
| 	print hr;
 | ||||
| 	print_menutypelist();
 | ||||
| 	print <<EOF;
 | ||||
|           </TD>
 | ||||
|          </TR>
 | ||||
|         </TABLE>
 | ||||
|        </TD>
 | ||||
|       </TR>
 | ||||
|      </TABLE>
 | ||||
|     </TD>
 | ||||
|     <TD bgcolor="white" valign="top">
 | ||||
|      <TABLE cellpadding="10" cellspacing="0" border="0" width="100%">
 | ||||
|       <TR>
 | ||||
|        <TD>
 | ||||
| EOF
 | ||||
| 	# Time the next update to occur a little while after the next interval completes
 | ||||
| 	my $interval = 300; # 5 min update interval
 | ||||
| 	my $guardband = 15; # updates occur this many seconds after predicted gif completion
 | ||||
| 	my $refresh = $interval + $guardband + $gifdone - time; # predict how long until next update
 | ||||
| 	$refresh = $interval if $refresh <= $guardband;
 | ||||
| 	my $expires = gmtime (time + $interval * 2 + $guardband);
 | ||||
| 	my $list = param('list');
 | ||||
| 	my $graph = param('graph') || 'day';
 | ||||
| 	print
 | ||||
| 		"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
 | ||||
| 		"<meta http-equiv=\"refresh\" content=$refresh>\n";
 | ||||
| 	if ($list) {
 | ||||
| 		print_graph_chooser($graph,$list,$page,'none');
 | ||||
| 		print "<br/>";
 | ||||
| bc24f7db | Hamish Coleman | 		print_list($lists,$graph,$list,'_self');
 | ||
| ebfd527a | Hamish Coleman | 	}
 | ||
| 	print <<EOF;
 | ||||
|        </TD>
 | ||||
|       </TR>
 | ||||
|      </TABLE>
 | ||||
| f7fe9beb | Hamish Coleman |     </TD>
 | ||
|    </TR>
 | ||||
|   </TABLE>
 | ||||
| EOF
 | ||||
| 	print end_html;
 | ||||
| } elsif($page eq 'x') {
 | ||||
| 	print header,
 | ||||
| 		start_html(-TITLE=>"$this_host MRTG Index (V$VERSION)",
 | ||||
| 			-bgcolor=>"white",
 | ||||
| 			-leftmargin=>"0", -topmargin=>"0",
 | ||||
| 			-marginheight=>"0", -marginwidth=>"0",
 | ||||
| 			-onResize=>"if (navigator.family == 'nn4') window.location.reload()" ),
 | ||||
| 		"\n";
 | ||||
| 	config_load_file(@config_files);
 | ||||
| 	config_read_filesystem();
 | ||||
| 	maketree();
 | ||||
| 	print <<EOF;
 | ||||
|   <STYLE>
 | ||||
|    /*                                                          */
 | ||||
|    /* Styles for the tree.                                     */
 | ||||
|    /*                                                          */
 | ||||
|    SPAN.TreeviewSpanArea A {
 | ||||
|      font-size: 10pt; 
 | ||||
|      font-family: verdana,helvetica; 
 | ||||
|      text-decoration: none;
 | ||||
|      color: black;}
 | ||||
|    SPAN.TreeviewSpanArea A:hover {
 | ||||
|      color: '#820082';}
 | ||||
|    /*                                                          */
 | ||||
|    /* Styles for the remainder of the document.                */
 | ||||
|    /*                                                          */
 | ||||
|    BODY {
 | ||||
|      background-color: white;}
 | ||||
|    TD {
 | ||||
|      font-size: 10pt; 
 | ||||
|      font-family: verdana,helvetica;}
 | ||||
|   </STYLE>
 | ||||
| EOF
 | ||||
| 	print '<script src="ua.js"></script>';
 | ||||
| 	print '<script src="ftiens4.js"></script>';
 | ||||
| 	print '<script>';
 | ||||
| 	emit_tree('treenf');
 | ||||
| 	print '</script>';
 | ||||
| 	print <<EOF;
 | ||||
|  <TABLE cellpadding="0" cellspacing="0" border="0" width="772">
 | ||||
|   <TR>
 | ||||
|    <TD width="178" valign="top">
 | ||||
|     <TABLE cellpadding="4" cellspacing="0" border="0" width="100%">
 | ||||
|      <TR>
 | ||||
|       <TD bgcolor="#ECECD9">
 | ||||
|         <TABLE cellspacing="0" cellpadding="2" border="0" width="100%">
 | ||||
|          <TR>
 | ||||
| 	  <td width="200" valign="top" bgcolor="#efefef" style="border-right: 1px solid rgb(170, 170, 170); padding: 5px;">
 | ||||
|  <TABLE border=0><TR><TD><FONT size=-2><A style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank /></FONT></TD></TR></TABLE>
 | ||||
|  <SPAN class=TreeviewSpanArea>
 | ||||
|   <SCRIPT>initializeDocument()</SCRIPT>
 | ||||
|   <NOSCRIPT>
 | ||||
|    A tree for site navigation will open here if you enable JavaScript in your browser.
 | ||||
|   </NOSCRIPT>
 | ||||
|  </SPAN>
 | ||||
|           </TD>
 | ||||
|          </TR>
 | ||||
|         </TABLE>
 | ||||
|        </TD>
 | ||||
|       </TR>
 | ||||
|      </TABLE>
 | ||||
|     </TD>
 | ||||
|     <TD bgcolor="white" valign="top">
 | ||||
|      <TABLE cellpadding="10" cellspacing="0" border="0" width="100%">
 | ||||
|       <TR>
 | ||||
|        <TD>
 | ||||
| EOF
 | ||||
| 	# Time the next update to occur a little while after the next interval completes
 | ||||
| 	my $interval = 300; # 5 min update interval
 | ||||
| 	my $guardband = 15; # updates occur this many seconds after predicted gif completion
 | ||||
| 	my $refresh = $interval + $guardband + $gifdone - time; # predict how long until next update
 | ||||
| 	$refresh = $interval if $refresh <= $guardband;
 | ||||
| 	my $expires = gmtime (time + $interval * 2 + $guardband);
 | ||||
| 	my $path = param('path');
 | ||||
| 	my $graph = param('graph') || 'day';
 | ||||
| 	print
 | ||||
| 		"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
 | ||||
| 		"<meta http-equiv=\"refresh\" content=$refresh>\n";
 | ||||
| 	if ($path) {
 | ||||
| 		print_graph_chooser($graph,'FIXME',$page,'none');
 | ||||
| 		print "<br/>";
 | ||||
| 		emit_path_contents($path,$graph);
 | ||||
| 	}
 | ||||
| 	print <<EOF;
 | ||||
|        </TD>
 | ||||
|       </TR>
 | ||||
|      </TABLE>
 | ||||
| ebfd527a | Hamish Coleman |     </TD>
 | ||
|    </TR>
 | ||||
|   </TABLE>
 | ||||
| EOF
 | ||||
| 6982850b | Hamish Coleman | |||
| 90053cde | Hamish Coleman | 	print end_html;
 | ||
| } elsif($page eq 'noframe') {
 | ||||
| 	print header,
 | ||||
| 		start_html(-TITLE=>"$this_host MRTG Index (V$VERSION)", -BGCOLOR=>'#e6e6e6'),
 | ||||
| 		"\n";
 | ||||
| 	@tests = init_tests(@config_files);
 | ||||
| 	$lists = init_lists(@tests);
 | ||||
| 	# FIXME - duplicated time calculations from above
 | ||||
| 	# Time the next update to occur a little while after the next interval completes
 | ||||
| 	my $interval = 300; # 5 min update interval
 | ||||
| 	my $guardband = 15; # updates occur this many seconds after predicted gif completion
 | ||||
| 	my $refresh = $interval + $guardband + $gifdone - time; # predict how long until next update
 | ||||
| 	$refresh = $interval if $refresh <= $guardband;
 | ||||
| 	my $expires = gmtime (time + $interval * 2 + $guardband);
 | ||||
| b992b8e4 | Hamish Coleman | |||
| 51561547 | Hamish Coleman | 	my $list = param('list');
 | ||
| 90053cde | Hamish Coleman | 	my $graph = param('graph') || 'day';
 | ||
| f9ec5168 | Hamish Coleman | |||
| 90053cde | Hamish Coleman | 	print
 | ||
| 		"<meta http-equiv=\"expires\" content=\"$expires GMT\">\n",
 | ||||
| 		"<meta http-equiv=\"refresh\" content=$refresh>\n";
 | ||||
| 	print "<table cellpadding=2 cellspacing=0>\n";
 | ||||
| 	print "<tr><td valign=top>";
 | ||||
| 51561547 | Hamish Coleman | 	print_menu_table($lists,'high','_self','noframe');
 | ||
| 11780c4c | Hamish Coleman | |||
| 90053cde | Hamish Coleman | 	print "<td valign=top>\n";
 | ||
| 51561547 | Hamish Coleman | 	if ($list) {
 | ||
| 		print_graph_chooser($graph,$list,$page,'noframe');
 | ||||
| 		print "<br/>";
 | ||||
| d259f7b9 | Hamish Coleman | 		print_list($lists,$graph,param('list'),'_self');
 | ||
| 51561547 | Hamish Coleman | 	}
 | ||
| b992b8e4 | Hamish Coleman | |||
| 	print "</table>\n";
 | ||||
| 90053cde | Hamish Coleman | 	print end_html;
 | ||
| 6982850b | Hamish Coleman | } elsif($page eq 'none') {
 | ||
| 	print header,
 | ||||
| 		start_html(-TITLE=>"$this_host MRTG Index (V$VERSION)", -BGCOLOR=>'#e6e6e6'),
 | ||||
| 		"\n";
 | ||||
| 	@tests = init_tests(@config_files);
 | ||||
| 	$lists = init_lists(@tests);
 | ||||
| 	print table(
 | ||||
| 		{-width=>"100\%"},
 | ||||
| 		TR(td("Select which list to show"))
 | ||||
| 	);
 | ||||
| 51561547 | Hamish Coleman | 	print_menu_table($lists,'wide','_self','list');
 | ||
| 6982850b | Hamish Coleman | 	print "\n","Direct questions and feedback to ",
 | ||
| 		a({-href=>"mailto:hamish\@zot.org"}, "Hamish"),
 | ||||
| 		" (Version $VERSION)",
 | ||||
| 		end_html;
 | ||||
| 11780c4c | Hamish Coleman | }
 | ||
| 5b3eb8e6 | Hamish Coleman | |||
| 51561547 | Hamish Coleman | if ($warnings && param('debug')) {
 | ||
| 11780c4c | Hamish Coleman | 	print "<pre>\n", "$warnings", "</pre>\n";
 | ||
| 5b3eb8e6 | Hamish Coleman | }
 | ||
| f7fe9beb | Hamish Coleman | print "<pre>\n";
 | ||
| print Dumper(\$db),"\n";
 | ||||
| #emit_tree('treenf');
 | ||||
| print "</pre>";
 |