commit d150e4ed35d0ec8db1b942046ab7bc798580f537
Author: Hamish Coleman <hamish@zot.org>
Date:   Mon Mar 2 16:48:37 2009 +1100

    Hide non public objects, rename global items to be more obvious

diff --git a/indexmrtg.cgi b/indexmrtg.cgi
index 2d946e7..750672b 100755
--- a/indexmrtg.cgi
+++ b/indexmrtg.cgi
@@ -32,9 +32,9 @@ my @config_files = (
 my $warnings;
 my $db = {};	# storage for all tests found
 
-$db->{mrtg}{gifdone} = 0; # Scan for newest graph and save info for later
-$db->{mrtg}{global}{postfix}{xsize} = 500;
-$db->{mrtg}{global}{postfix}{ysize} = 135;
+$db->{global}{graph}{mtime} = 0; # Scan for newest graph and save info for later
+$db->{hide}{mrtg}{global}{postfix}{xsize} = 500;
+$db->{hide}{mrtg}{global}{postfix}{ysize} = 135;
 
 sub config_save_val($$$$) {
 	my ($filename,$name,$var,$val) = @_;
@@ -52,11 +52,11 @@ sub config_save_val($$$$) {
 
 	# Save any default initializers
 	if ($name eq '_') {
-		$db->{mrtg}{global}{postfix}{$var} = $val;
+		$db->{hide}{mrtg}{global}{postfix}{$var} = $val;
 		return;
 	}
 	if ($name eq '^') {
-		$db->{mrtg}{global}{prefix}{$var} = $val;
+		$db->{hide}{mrtg}{global}{prefix}{$var} = $val;
 		return;
 	}
 
@@ -74,17 +74,17 @@ sub config_save_val($$$$) {
 
 		#TODO - instantiate new tests from all of the "_"/"^" defaults
 
-		push @{$db->{sequence}}, $unique_name;
+		push @{$db->{hide}{sequence}}, $unique_name;
 
 		$db->{graph}->{$unique_name}->{name} = $name;
 		$db->{graph}->{$unique_name}->{definedby} = $filename;
-		$db->{graph}->{$unique_name}->{sequence} = @{$db->{sequence}};
+		$db->{graph}->{$unique_name}->{sequence} = @{$db->{hide}{sequence}};
 
-		$db->{graph}{$unique_name}{img}{xsize} = $db->{mrtg}{global}{postfix}{xsize};
-		$db->{graph}{$unique_name}{img}{ysize} = $db->{mrtg}{global}{postfix}{ysize};
+		$db->{graph}{$unique_name}{img}{xsize} = $db->{hide}{mrtg}{global}{postfix}{xsize};
+		$db->{graph}{$unique_name}{img}{ysize} = $db->{hide}{mrtg}{global}{postfix}{ysize};
 
 	}
-	$db->{mrtg}{target}{$unique_name}{$var} = $val;
+	$db->{hide}{mrtg}{target}{$unique_name}{$var} = $val;
 }
 
 # Load one or more files
@@ -101,7 +101,7 @@ sub config_load_file(@) {
 		}
 
 		#TODO - multi-line values
-		#TODO - reset the {mrtg}{global} vars
+		#TODO - reset the {hide}{mrtg}{global} vars
 
 		while(<$fh>){
 
@@ -118,7 +118,7 @@ sub config_load_file(@) {
 				my $var=lc $1;
 				my $val=$2;
 
-				$db->{mrtg}{global}{$var}=$val;
+				$db->{hide}{mrtg}{global}{$var}=$val;
 			}
 
 			# TODO - Handle extra statements:
@@ -136,15 +136,15 @@ sub config_load_file(@) {
 sub config_read_filesystem() {
 
 	# TODO - also check the other directory statements
-	if ($db->{mrtg}{global}{workdir}) {
-		chdir $db->{mrtg}{global}{workdir};
+	if ($db->{hide}{mrtg}{global}{workdir}) {
+		chdir $db->{hide}{mrtg}{global}{workdir};
 	}
 
 	# check and update details for all known tests;
 	for my $i (keys %{$db->{graph}}) {
 		my $graph = $db->{graph}->{$i};
 		my $graphname = $graph->{name};
-		my $mrtg = $db->{mrtg}{target}{$i};
+		my $mrtg = $db->{hide}{mrtg}{target}{$i};
 
 		# Default is GIF, unless a PNG file exists
 		$mrtg->{_imagetype} = 'gif';
@@ -176,8 +176,8 @@ sub config_read_filesystem() {
 		$graph->{img}{mtime} = $mtime;
 
 		# find the newest file
-		if ($mtime > $db->{mrtg}{gifdone}) {
-			$db->{mrtg}{gifdone} = $mtime;
+		if ($mtime > $db->{global}{graph}{mtime}) {
+			$db->{global}{graph}{mtime} = $mtime;
 		}
 	}
 }
@@ -222,12 +222,12 @@ sub maketree_find_hosttypes() {
 		}
 
 		$db->{graph}{$name}{tag}{hosttype} = $hosttype;
-		$db->{hosttype}->{$hosttype}->{$host}++;
+		$db->{hide}{hosttype}->{$hosttype}->{$host}++;
 	}
 
-	for my $hosttype (keys %{$db->{hosttype}}) {
-		if ((keys %{$db->{hosttype}->{$hosttype}})<2) {
-			delete $db->{hosttype}->{$hosttype};
+	for my $hosttype (keys %{$db->{hide}{hosttype}}) {
+		if ((keys %{$db->{hide}{hosttype}->{$hosttype}})<2) {
+			delete $db->{hide}{hosttype}->{$hosttype};
 		}
 	}
 }
@@ -256,17 +256,21 @@ maketags();
 # 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 + $db->{mrtg}{gifdone} - time; # predict how long until next update
+my $refresh = $interval + $guardband + $db->{global}{graph}{mtime} - time; # predict how long until next update
 $refresh = $interval if $refresh <= $guardband;
 my $expires = gmtime (time + $interval * 2 + $guardband);
 
-$db->{global}{expires} = "$expires GMT";
-$db->{global}{refresh} = $refresh;
-
-print "\n",JSON->new->utf8(1)->pretty(1)->canonical(1)->encode($db),"\n";
+$db->{global}{graph}{expires} = "$expires GMT";
+$db->{global}{graph}{refresh} = $refresh;
+$db->{global}{sequence} = @{$db->{hide}{sequence}};
 
 if (param('debug')) {
 	print "\n",Dumper(\$db),"\n";
 }
 
+# Remove objects that are not intended to be public
+delete $db->{hide};
+
+print "\n",JSON->new->utf8(1)->pretty(1)->canonical(1)->encode($db),"\n";
+
 
