#!/usr/bin/perl # # This code is based on hddGraph and mbmongraph # written by weizen_42 and distributed under the # terms of the GPLv2. # http://www.ban-solms.de/t/IPCop-mbmongraph.html # http://www.ban-solms.de/t/IPCop-hddgraph.html # use strict; # enable only the following on debugging purpose # use warnings; # use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; my %cgiparams=(); my @cgigraphs=(); my @graphs=(); &Header::showhttpheaders(); my $graphdir = "/srv/web/ipfire/html/graphs"; &Header::getcgihash(\%cgiparams); $ENV{'QUERY_STRING'} =~ s/&//g; @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'}); $cgigraphs[1] = '' unless defined $cgigraphs[1]; my %mbmon_settings = (); my %mbmon_values = (); &General::readhash("/var/log/mbmon-values", \%mbmon_values); my $key; if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} ) { $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on'); $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on'); $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on'); $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on'); foreach my $line (sort keys %cgiparams) { if ( index($line, "LINE-") != -1 ) { $mbmon_settings{$line} = 'on'; } if ( index($line, "LABEL-") != -1 ) { $mbmon_settings{$line} = $cgiparams{$line}; } } &General::writehash("${General::swroot}/mbmon/settings", \%mbmon_settings); } else { &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings); } my $selected_temp = ''; my $selected_fan = ''; my $selected_volt = ''; my $selected_hdd = ''; $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 ); $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 ); $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 ); $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 ); my %mbmon_graphs = (); foreach $key ( sort(keys %mbmon_values) ) { $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' ); if ( !defined($mbmon_settings{'LABEL-'.$key}) ) { $mbmon_settings{'LABEL-'.$key} = $key; } } &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, ''); &Header::openbigbox('100%', 'left'); ############### # DEBUG DEBUG #&Header::openbox('100%', 'left', 'DEBUG'); #my $debugCount = 0; #foreach my $line (sort keys %cgiparams) { # print "$line = $cgiparams{$line}
\n"; # $debugCount++; #} #print " Count: $debugCount
\n"; #print " CGIParams: $cgigraphs[1]\n"; #&Header::closebox(); # DEBUG DEBUG ############### if ($cgigraphs[1] =~ /hddtemp/) { my $graph = $cgigraphs[1]; my $graphname = $Lang::tr{"harddisk temperature"}; &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}"); if (-e "$graphdir/${graph}-day.png") { my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]); print "
"; print "$Lang::tr{'the statistics were last updated at'}: $ftime


\n"; print "
"; print "
"; print "
"; print ""; if ( -e "/var/log/smartctl_out_${graph}" ) { my $output = `/bin/cat /var/log/smartctl_out_${graph}`; $output = &Header::cleanhtml($output); print "
$output
\n"; } } else { print $Lang::tr{'no information available'}; } &Header::closebox(); print "
"; print ""; print "$Lang::tr{'back'}
\n"; } elsif ($cgigraphs[1] =~ /(temp|fan|volt)/) { my $graph = $cgigraphs[1]; my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"}; &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}"); if (-e "$graphdir/mbmon-${graph}-day.png") { my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]); print "
"; print "$Lang::tr{'the statistics were last updated at'}: $ftime


\n"; print "
"; print "
"; print "
"; print ""; } else { print $Lang::tr{'no information available'}; } &Header::closebox(); print "
"; print ""; print "$Lang::tr{'back'}
\n"; } else { if ( $mbmon_settings{'GRAPH_TEMP'} == 1 ) { &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}"); if (-e "$graphdir/mbmon-temp-day.png") { my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]); print "
$Lang::tr{'the statistics were last updated at'}: $ftime

\n"; print ""; print ""; print ""; } else { print $Lang::tr{'no information available'}; } print "
\n"; &Header::closebox(); } if ( $mbmon_settings{'GRAPH_FAN'} == 1 ) { &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}"); if (-e "$graphdir/mbmon-fan-day.png") { my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]); print "
$Lang::tr{'the statistics were last updated at'}: $ftime

\n"; print ""; print ""; print ""; } else { print $Lang::tr{'no information available'}; } print "
\n"; &Header::closebox(); } if ( $mbmon_settings{'GRAPH_VOLT'} == 1 ) { &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}"); if (-e "$graphdir/mbmon-volt-day.png") { my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]); print "
$Lang::tr{'the statistics were last updated at'}: $ftime

\n"; print ""; print ""; print ""; } else { print $Lang::tr{'no information available'}; } print "
\n"; &Header::closebox(); } if ( $mbmon_settings{'GRAPH_HDD'} == 1 ) { hddtempbox("hda"); hddtempbox("hdb"); hddtempbox("hdc"); hddtempbox("hdd"); hddtempbox("hde"); hddtempbox("hdf"); hddtempbox("hdg"); hddtempbox("hdh"); } &Header::openbox('100%', 'center', $Lang::tr{'settings'}); print <
 $Lang::tr{'mbmon temp'} $Lang::tr{'graph'}
 $Lang::tr{'mbmon fan'} $Lang::tr{'graph'}
 $Lang::tr{'mbmon volt'} $Lang::tr{'graph'}
 $Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}

END ; my $i = 0; foreach $key ( sort(keys %mbmon_values) ) { if ( $i % 2 ) { print(""); } else { print(""); } $mbmon_settings{'LABEL-'.$key} = &Header::cleanhtml($mbmon_settings{'LABEL-'.$key}); print(""); print("\n"); print("\n"); $i++; } print <
$Lang::tr{'mbmon display'} $Lang::tr{'mbmon value'}$Lang::tr{'mbmon label'}
$key$mbmon_values{$key} 
 
END ; &Header::closebox(); } &Header::closebox(); &Header::closebigbox(); &Header::closepage(); sub hddtempbox { my $disk = $_[0]; if (-e "$graphdir/hddtemp-$disk-day.png") { &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}"); my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]); print "
$Lang::tr{'the statistics were last updated at'}: $ftime

\n"; print ""; print ""; print ""; print "
\n"; &Header::closebox(); } }