-#!/usr/bin/perl\r
-###############################################################################\r
-# #\r
-# IPFire.org - A linux based firewall #\r
-# Copyright (C) 2007 Michael Tremer & Christian Schmidt #\r
-# #\r
-# This program is free software: you can redistribute it and/or modify #\r
-# it under the terms of the GNU General Public License as published by #\r
-# the Free Software Foundation, either version 3 of the License, or #\r
-# (at your option) any later version. #\r
-# #\r
-# This program is distributed in the hope that it will be useful, #\r
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #\r
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #\r
-# GNU General Public License for more details. #\r
-# #\r
-# You should have received a copy of the GNU General Public License #\r
-# along with this program. If not, see <http://www.gnu.org/licenses/>. #\r
-# #\r
-###############################################################################\r
-\r
-use strict;\r
-\r
-# enable only the following on debugging purpose\r
-#use warnings;\r
-#use CGI::Carp 'fatalsToBrowser';\r
-\r
-require '/var/ipfire/general-functions.pl';\r
-require "${General::swroot}/lang.pl";\r
-require "${General::swroot}/header.pl";\r
-require "${General::swroot}/graphs.pl";\r
-\r
-my %sensorsettings = ();\r
-my %cgiparams=();\r
-my @cgigraphs=();\r
-my $rrdlog = "/var/log/rrd";\r
-\r
-&Header::showhttpheaders();\r
-\r
-my $graphdir = "/srv/web/ipfire/html/graphs";\r
-\r
-$ENV{'QUERY_STRING'} =~ s/&//g;\r
-@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});\r
-$cgigraphs[1] = '' unless defined $cgigraphs[1];\r
-\r
-my @sensorsgraphs = ();\r
-my @sensorsdir = `ls -dA $rrdlog/collectd/localhost/sensors-*/`;\r
-foreach (@sensorsdir)\r
-{\r
- chomp($_);chop($_);\r
- foreach (`ls $_/*`){\r
- chomp($_);\r
- push(@sensorsgraphs,$_);\r
- }\r
-}\r
-\r
-&Header::getcgihash(\%sensorsettings);\r
-\r
-if ( $sensorsettings{'ACTION'} eq $Lang::tr{'save'} ) {\r
- foreach(@sensorsgraphs){\r
- chomp($_);\r
- $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;\r
- my $label = $2.$3;$label=~ s/-//g;\r
- if ( $sensorsettings{'LINE-'.$label} ne "on" ){$sensorsettings{'LINE-'.$label} = 'off';}\r
- elsif ( $sensorsettings{'LINE-'.$label} eq "on" ){$sensorsettings{'LINE-'.$label} = 'checked';}\r
- }\r
- &General::writehash("${General::swroot}/sensors/settings", \%sensorsettings);\r
-}\r
-\r
-my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;\r
-\r
-&Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');\r
-&Header::openbigbox('100%', 'left');\r
-\r
-if ($cgigraphs[1] =~ /hwtemp/) {&Graphs::updatehwtempgraph ("hour");&Graphs::updatehwtempgraph ("week");&Graphs::updatehwtempgraph ("month");&Graphs::updatehwtempgraph ("year");graphbox("hwtemp");}\r
-elsif ($cgigraphs[1] =~ /hwfan/) {&Graphs::updatehwfangraph ("hour");&Graphs::updatehwfangraph ("week");&Graphs::updatehwfangraph ("month");&Graphs::updatehwfangraph ("year");graphbox("hwfan");}\r
-elsif ($cgigraphs[1] =~ /hwvolt/) {&Graphs::updatehwvoltgraph ("hour");&Graphs::updatehwvoltgraph ("week");&Graphs::updatehwvoltgraph ("month");&Graphs::updatehwvoltgraph ("year");graphbox("hwvolt");}\r
-elsif ($cgigraphs[1] =~ /hddtemp/) {\r
- foreach (@disks){\r
- my $disk = $_;\r
- chomp $disk;\r
- my @array = split(/\//,$disk);\r
- &Graphs::updatehddgraph ($array[$#array],"week");&Graphs::updatehddgraph ($array[$#array],"month");&Graphs::updatehddgraph ($array[$#array],"year");\r
- hddtempbox($array[$#array]);\r
- }\r
-}\r
-else\r
-{\r
- &Graphs::updatehwtempgraph ("day");&Graphs::updatehwfangraph ("day");&Graphs::updatehwvoltgraph ("day");\r
- foreach (@disks){\r
- my $disk = $_;\r
- chomp $disk;\r
- my @array = split(/\//,$disk);\r
- &Graphs::updatehddgraph ($array[$#array],"day");\r
- if (-e "$graphdir/hddtemp-$disk-day.png") {\r
-\r
- &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
- my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);\r
- print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp'>";\r
- print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";\r
- print "</a>";\r
- print "<br />\n";\r
- &Header::closebox();\r
- }\r
- }\r
-\r
- my @graphs = ("hwtemp","hwfan","hwvolt");\r
- foreach (@graphs){\r
- &Header::openbox('100%', 'center', "$_ $Lang::tr{'graph'}");\r
- if (-e "$graphdir/sensors-$_-day.png"){\r
- my $ftime = localtime((stat("$graphdir/sensors-$_-day.png"))[9]);\r
- print "<center>";\r
- print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=$_'>";\r
- print "<img src='/graphs/sensors-$_-day.png' border='0' />";\r
- print "</a><hr />";\r
- }\r
- else{print $Lang::tr{'no information available'};}\r
- &Header::closebox();\r
- }\r
- sensorsbox();\r
-}\r
-\r
-&Header::closebigbox();\r
-&Header::closepage();\r
-\r
-sub hddtempbox {\r
- my $disk = $_[0];\r
- if (-e "$graphdir/hddtemp-$disk-week.png") {\r
-\r
- &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
- my $ftime = localtime((stat("$graphdir/hddtemp-$disk-week.png"))[9]);\r
- print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<img src='/graphs/hddtemp-$disk-week.png' border='0' />";\r
- print "<br />\n";\r
- &Header::closebox();\r
- }\r
- if (-e "$graphdir/hddtemp-$disk-month.png") {\r
-\r
- &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
- my $ftime = localtime((stat("$graphdir/hddtemp-$disk-month.png"))[9]);\r
- print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<img src='/graphs/hddtemp-$disk-month.png' border='0' />";\r
- print "<br />\n";\r
- &Header::closebox();\r
- }\r
- if (-e "$graphdir/hddtemp-$disk-year.png") {\r
-\r
- &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");\r
- my $ftime = localtime((stat("$graphdir/hddtemp-$disk-year.png"))[9]);\r
- print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<img src='/graphs/hddtemp-$disk-year.png' border='0' />";\r
- print "<br />\n";\r
- &Header::closebox();\r
- }\r
-}\r
-\r
-sub graphbox {\r
- my $graph = $_[0];\r
- \r
- &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");\r
- if (-e "$graphdir/sensors-$graph-week.png"){\r
- my $ftime = localtime((stat("$graphdir/sensors-$graph-week.png"))[9]);\r
- print "<center>";\r
- print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<img src='/graphs/sensors-$graph-week.png' border='0' /><hr />";\r
- }\r
- else{print $Lang::tr{'no information available'};}\r
- &Header::closebox();\r
- &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");\r
- if (-e "$graphdir/sensors-$graph-month.png"){\r
- my $ftime = localtime((stat("$graphdir/sensors-$graph-month.png"))[9]);\r
- print "<center>";\r
- print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<img src='/graphs/sensors-$graph-month.png' border='0' /><hr />";\r
- }\r
- else{print $Lang::tr{'no information available'};}\r
- &Header::closebox();\r
- &Header::openbox('100%', 'center', "$graph $Lang::tr{'graph'}");\r
- if (-e "$graphdir/sensors-$graph-year.png"){\r
- my $ftime = localtime((stat("$graphdir/sensors-$graph-year.png"))[9]);\r
- print "<center>";\r
- print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";\r
- print "<img src='/graphs/sensors-$graph-year.png' border='0' /><hr />";\r
- }\r
- else{print $Lang::tr{'no information available'};}\r
- &Header::closebox();\r
-}\r
-\r
-sub sensorsbox{\r
-\r
- &Header::openbox('100%', 'center', "$Lang::tr{'mbmon settings'}");\r
- if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} ){print "Test";}\r
-\r
- print <<END\r
- <form method='post' action='$ENV{'SCRIPT_NAME'}'>\r
- <table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'>\r
- <tr><td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td>\r
- <td align='left'><b>$Lang::tr{'mbmon label'}</b></td>\r
- </tr>\r
-END\r
-;\r
-foreach (@sensorsgraphs){\r
- $_ =~ /\/(.*)sensors-(.*)\/(.*)\.rrd/;\r
- my $label = $2.$3;$label=~ s/-//g;\r
- $sensorsettings{'LABEL-'.$label}="$label";\r
- $sensorsettings{'LINE-'.$label}="checked";\r
- &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);\r
- print("<tr><td align='right'><input type='checkbox' name='LINE-$label' $sensorsettings{'LINE-'.$label} /></td>");\r
- print("<td><input type='text' name='LABEL-$label' value='$sensorsettings{'LABEL-'.$label}' size='25' /></td></tr>\n");\r
-}\r
- print <<END\r
- <tr><td align='center' colspan='2' ><input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td></tr>\r
- </table>\r
- </form>\r
-END\r
-;\r
- &Header::closebox();\r
-}\r
+#!/usr/bin/perl
+###############################################################################
+# #
+# 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 <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+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";
+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,$_);
+ }
+}
+
+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] =~ "sd?" || $querry[0] =~ "hd?" ){
+ 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';}
+ }
+ &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();
+ }
+
+ &Header::openbox('100%', 'center', "hwtemp $Lang::tr{'graph'}");
+ &Graphs::makegraphbox("hardwaregraphs.cgi","hwtemp","day");
+ &Header::closebox();
+
+ &Header::openbox('100%', 'center', "hwfan $Lang::tr{'graph'}");
+ &Graphs::makegraphbox("hardwaregraphs.cgi","hwfan","day");
+ &Header::closebox();
+
+ &Header::openbox('100%', 'center', "hwvolt $Lang::tr{'graph'}");
+ &Graphs::makegraphbox("hardwaregraphs.cgi","hwvolt","day","375");
+ &Header::closebox();
+
+ sensorsbox();
+
+ &Header::closebigbox();
+ &Header::closepage();
+
+}
+
+
+sub sensorsbox {
+ &Header::openbox('100%', 'center', "$Lang::tr{'mbmon settings'}");
+
+ print <<END
+<form method='post' action='$ENV{'SCRIPT_NAME'}'>
+<table width='100%' border='0' cellspacing='5' cellpadding='0' align='center'>
+<tr>
+ <td align='right' width='40%'><b>$Lang::tr{'mbmon display'}</b></td>
+ <td align='left'><b>$Lang::tr{'mbmon label'}</b></td>
+</tr>
+END
+;
+
+ 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("<tr><td align='right'><input type='checkbox' name='LINE-$label' $sensorsettings{'LINE-'.$label} /></td>");
+ print("<td><input type='text' name='LABEL-$label' value='$sensorsettings{'LABEL-'.$label}' size='25' /></td></tr>\n");
+ }
+
+ print <<END
+<tr>
+ <td align='center' colspan='2' ><input type='submit' name='ACTION' value=$Lang::tr{'save'} /></td>
+</tr>
+</table>
+</form>
+END
+;
+ &Header::closebox();
+}