]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
24 # enable only the following on debugging purpose
26 # use CGI::Carp 'fatalsToBrowser';
28 require '/var/ipfire/general-functions.pl';
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "${General::swroot}/graphs.pl";
34 my %mainsettings = ();
35 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
36 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
41 &Header
::showhttpheaders
();
43 my $graphdir = "/srv/web/ipfire/html/graphs";
45 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
49 my @array = split(/\//,$disk);
50 &Graphs
::updatehddgraph
($array[$#array],"day");&Graphs
::updatehddgraph
($array[$#array],"week");&Graphs
::updatehddgraph
($array[$#array],"month");&Graphs
::updatehddgraph
($array[$#array],"year");
53 &Graphs
::updatetempgraph
("day");
54 &Graphs
::updatefangraph
("day");
55 &Graphs
::updatevoltgraph
("day");
59 &Header
::getcgihash
(\
%cgiparams);
61 $ENV{'QUERY_STRING'} =~ s/&//g;
62 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
63 $cgigraphs[1] = '' unless defined $cgigraphs[1];
65 my %mbmon_settings = ();
66 my %mbmon_values = ();
67 &General
::readhash
("/var/log/mbmon-values", \
%mbmon_values);
70 if ( $cgiparams{'ACTION'} eq $Lang::tr
{'save'} )
72 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
73 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
74 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
75 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
77 foreach my $line (sort keys %cgiparams)
79 if ( index($line, "LINE-") != -1 )
81 $mbmon_settings{$line} = 'on';
84 if ( index($line, "LABEL-") != -1 )
86 $mbmon_settings{$line} = $cgiparams{$line};
90 &General
::writehash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
94 &General
::readhash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
97 my $selected_temp = '';
98 my $selected_fan = '';
99 my $selected_volt = '';
100 my $selected_hdd = '';
102 $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
103 $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
104 $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
105 $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
107 my %mbmon_graphs = ();
108 foreach $key ( sort(keys %mbmon_values) )
110 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
111 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
113 $mbmon_settings{'LABEL-'.$key} = $key;
117 &Header
::openpage
($Lang::tr
{'harddisk temperature graphs'}, 1, '');
119 &Header
::openbigbox
('100%', 'left');
123 #&Header::openbox('100%', 'left', 'DEBUG');
125 #foreach my $line (sort keys %cgiparams) {
126 # print "$line = $cgiparams{$line}<br />\n";
129 #print " Count: $debugCount<br />\n";
130 #print " CGIParams: $cgigraphs[1]\n";
131 #&Header::closebox();
135 if ($cgigraphs[1] =~ /hddtemp/)
137 my $graph = $cgigraphs[1];
138 my $graphname = $Lang::tr
{"harddisk temperature"};
139 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
141 if (-e
"$graphdir/${graph}-day.png")
143 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
145 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
146 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
147 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
148 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
149 print "<img src='/graphs/${graph}-year.png' border='0' />";
150 if ( -e
"/var/log/smartctl_out_${graph}" )
152 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
153 $output = &Header
::cleanhtml
($output);
154 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
159 print $Lang::tr
{'no information available'};
162 print "<div align='center'><table width='80%'><tr><td align='center'>";
163 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
164 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
166 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
168 if ($cgigraphs[1] =~ /temp/) {&Graphs
::updatetempgraph
("week");&Graphs
::updatetempgraph
("month");&Graphs
::updatetempgraph
("year");}
169 if ($cgigraphs[1] =~ /fan/) {&Graphs
::updatefangraph
("week");&Graphs
::updatefangraph
("month");&Graphs
::updatefangraph
("year");}
170 if ($cgigraphs[1] =~ /volt/) {&Graphs
::updatevoltgraph
("week");&Graphs
::updatevoltgraph
("month");&Graphs
::updatevoltgraph
("year");}
172 my $graph = $cgigraphs[1];
173 my $graphname = $Lang::tr
{"mbmon $cgigraphs[1]"};
174 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
176 if (-e
"$graphdir/mbmon-${graph}-day.png")
178 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
180 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
181 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
182 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
183 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
184 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
188 print $Lang::tr
{'no information available'};
191 print "<div align='center'><table width='80%'><tr><td align='center'>";
192 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
193 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
197 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
199 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
200 if (-e
"$graphdir/mbmon-temp-day.png")
202 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
203 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
204 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
205 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
210 print $Lang::tr
{'no information available'};
216 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
218 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
219 if (-e
"$graphdir/mbmon-fan-day.png")
221 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
222 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
223 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
224 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
229 print $Lang::tr
{'no information available'};
235 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
237 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
238 if (-e
"$graphdir/mbmon-volt-day.png")
240 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
241 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
242 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
243 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
248 print $Lang::tr
{'no information available'};
254 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
256 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
260 my @array = split(/\//,$device);
261 hddtempbox
($array[$#array]);}
264 &Header
::openbox
('100%', 'center', $Lang::tr
{'settings'});
266 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
268 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp /> $Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
269 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan /> $Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
270 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt /> $Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
271 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd /> $Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
274 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
275 <tr><td align='center' width='10%'><b>$Lang::tr{'mbmon display'}</b></td><td align='center' width='15%'> </td><td align='center' width='15%'><b>$Lang::tr{'mbmon value'}</b></td><td align='left'><b>$Lang::tr{'mbmon label'}</b></td></tr>
280 foreach $key ( sort(keys %mbmon_values) )
284 print("<tr bgcolor='$color{'color22'}'>");
288 print("<tr bgcolor='$color{'color20'}'>");
290 $mbmon_settings{'LABEL-'.$key} = &Header
::cleanhtml
($mbmon_settings{'LABEL-'.$key});
291 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
292 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
293 print("<td> <input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
301 <tr><td class='base' valign='top'> </td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
310 &Header
::closebigbox
();
311 &Header
::closepage
();
315 if (-e
"$graphdir/hddtemp-$disk-day.png") {
317 &Header
::openbox
('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
318 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
319 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
320 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
321 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";