X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Fhardwaregraphs.cgi;h=dabdfd1aeeeed3af82f9f4c384890de0b622e1d0;hp=ad3ff59dc1ad7e7083b447fcf4ed68a8d78d69f6;hb=fac92c6d25038f61430a4e872e720ba00b539385;hpb=a8239982ac7e33e4623b30b8f0d35ceee4ad2b9c diff --git a/html/cgi-bin/hardwaregraphs.cgi b/html/cgi-bin/hardwaregraphs.cgi index ad3ff59dc1..dabdfd1aee 100644 --- a/html/cgi-bin/hardwaregraphs.cgi +++ b/html/cgi-bin/hardwaregraphs.cgi @@ -1,287 +1,173 @@ #!/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 -# +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2008 Michael Tremer & Christian Schmidt # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### use strict; # enable only the following on debugging purpose -# use warnings; -# use CGI::Carp 'fatalsToBrowser'; +#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); +require "${General::swroot}/graphs.pl"; + +my %color = (); +my %mainsettings = (); +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); + +my %sensorsettings = (); + +my @sensorsgraphs = (); +my @sensorsdir = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/`; +foreach (@sensorsdir){ + chomp($_);chop($_); + foreach (`ls $_/*`){ + chomp($_); + push(@sensorsgraphs,$_); + } } -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 @querry = split(/\?/,$ENV{'QUERY_STRING'}); +$querry[0] = '' unless defined $querry[0]; +$querry[1] = 'hour' unless defined $querry[1]; + +if ( $querry[0] =~ "hwtemp"){ + print "Content-type: image/png\n\n"; + binmode(STDOUT); + &Graphs::updatehwtempgraph($querry[1]); +}elsif ( $querry[0] =~ "hwfan"){ + print "Content-type: image/png\n\n"; + binmode(STDOUT); + &Graphs::updatehwfangraph($querry[1]); +}elsif ( $querry[0] =~ "hwvolt"){ + print "Content-type: image/png\n\n"; + binmode(STDOUT); + &Graphs::updatehwvoltgraph($querry[1]); +}elsif ( $querry[0] =~ "thermaltemp"){ + print "Content-type: image/png\n\n"; + binmode(STDOUT); + &Graphs::updatethermaltempgraph($querry[1]); +}elsif ( $querry[0] =~ "sd?" || $querry[0] =~ "hd?" || $querry[0] =~ "xvd??" ){ + print "Content-type: image/png\n\n"; + binmode(STDOUT); + &Graphs::updatehddgraph($querry[0],$querry[1]); +}else{ + &Header::showhttpheaders(); + &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, ''); + &Header::openbigbox('100%', 'left'); + + &Header::getcgihash(\%sensorsettings); + + if ( $sensorsettings{'ACTION'} eq $Lang::tr{'save'} ) { + foreach(@sensorsgraphs){ + chomp($_); + $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; + my $label = $2.$3;$label=~ s/-//g; + if ( $sensorsettings{'LINE-'.$label} ne "on" ){ + $sensorsettings{'LINE-'.$label} = 'off'; + } elsif ($sensorsettings{'LINE-'.$label} eq "on" ){ + $sensorsettings{'LINE-'.$label} = 'checked'; + } + $sensorsettings{'LABEL-'.$label} =~ s/\W//g; + } + &General::writehash("${General::swroot}/sensors/settings", \%sensorsettings); + } + + my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`; + + foreach (@disks){ + my $disk = $_; + chomp $disk; + my @array = split(/\//,$disk); + + &Header::openbox('100%', 'center', "$array[$#array] $Lang::tr{'graph'}"); + &Graphs::makegraphbox("hardwaregraphs.cgi",$array[$#array],"day"); + &Header::closebox(); + } + + if ( `ls $mainsettings{'RRDLOG'}/collectd/localhost/thermal-thermal_zone*` ) { + &Header::openbox('100%', 'center', "ACPI Thermal-Zone Temp $Lang::tr{'graph'}"); + &Graphs::makegraphbox("hardwaregraphs.cgi","thermaltemp","day"); + &Header::closebox(); + } + + if ( `ls $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/temperature-*` ) { + &Header::openbox('100%', 'center', "hwtemp $Lang::tr{'graph'}"); + &Graphs::makegraphbox("hardwaregraphs.cgi","hwtemp","day","375"); + Header::closebox(); + } + + if ( `ls $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/fanspeed-*` ) { + &Header::openbox('100%', 'center', "hwfan $Lang::tr{'graph'}"); + &Graphs::makegraphbox("hardwaregraphs.cgi","hwfan","day"); + &Header::closebox(); + } + + if ( `ls $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/voltage-*` ) { + &Header::openbox('100%', 'center', "hwvolt $Lang::tr{'graph'}"); + &Graphs::makegraphbox("hardwaregraphs.cgi","hwvolt","day","435"); + &Header::closebox(); + } + + if ( `ls $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*` ) { + sensorsbox(); + } + &Header::closebigbox(); + &Header::closepage(); -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'); +sub sensorsbox { + &Header::openbox('100%', 'center', "$Lang::tr{'mbmon settings'}"); -############### -# 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"; -#&Header::closebox(); -# DEBUG DEBUG -############### - -if ($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"; -} -elsif ($cgigraphs[1] =~ /(hdd)/) -{ - my $graph = $cgigraphs[1]; - my $graphname = $Lang::tr{"harddisk temperature"}; - &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}"); - - if (-e "$graphdir/hddtemp-day.png") - { - my $ftime = localtime((stat("$graphdir/hddtemp-day.png"))[9]); - print "
"; - print "$Lang::tr{'the statistics were last updated at'}: $ftime


\n"; - print "
"; - print "
"; - print "
"; - print ""; - if ( -e "/var/log/hddgraph_smartctl_out" ) - { - my $output = `/bin/cat /var/log/hddgraph_smartctl_out`; - $output = &Header::cleanhtml($output); - print "
$output
\n"; - } - } - 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 ) - { - &Header::openbox('100%', 'center', $Lang::tr{'harddisk temperature'}); - if (-e "$graphdir/hddtemp-day.png") - { - my $ftime = localtime((stat("$graphdir/hddtemp-day.png"))[9]); - print "
"; - 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(); - } - - &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'}
-
- - +
$Lang::tr{'mbmon display'} $Lang::tr{'mbmon value'}$Lang::tr{'mbmon label'}
+ + + + 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 label'}
$key$mbmon_values{$key} 
- + foreach (@sensorsgraphs){ + $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/; + my $label = $2.$3;$label=~ s/-//g; + $sensorsettings{'LABEL-'.$label}="$label"; + $sensorsettings{'LINE-'.$label}="checked"; + &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings); + print(""); + print("\n"); + } + + print < + +
 
- END ; - &Header::closebox(); + &Header::closebox(); } - -&Header::closebox(); - -&Header::closebigbox(); -&Header::closepage();