]>
git.ipfire.org Git - people/teissler/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 &Graphs
::updatehddgraph
($disk,"day");&Graphs
::updatehddgraph
($disk,"week");&Graphs
::updatehddgraph
($disk,"month");&Graphs
::updatehddgraph
($disk,"year");
52 &Graphs
::updatetempgraph
("day");
53 &Graphs
::updatefangraph
("day");
54 &Graphs
::updatevoltgraph
("day");
58 &Header
::getcgihash
(\
%cgiparams);
60 $ENV{'QUERY_STRING'} =~ s/&//g;
61 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
62 $cgigraphs[1] = '' unless defined $cgigraphs[1];
64 my %mbmon_settings = ();
65 my %mbmon_values = ();
66 &General
::readhash
("/var/log/mbmon-values", \
%mbmon_values);
69 if ( $cgiparams{'ACTION'} eq $Lang::tr
{'save'} )
71 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
72 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
73 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
74 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
76 foreach my $line (sort keys %cgiparams)
78 if ( index($line, "LINE-") != -1 )
80 $mbmon_settings{$line} = 'on';
83 if ( index($line, "LABEL-") != -1 )
85 $mbmon_settings{$line} = $cgiparams{$line};
89 &General
::writehash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
93 &General
::readhash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
96 my $selected_temp = '';
97 my $selected_fan = '';
98 my $selected_volt = '';
99 my $selected_hdd = '';
101 $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
102 $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
103 $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
104 $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
106 my %mbmon_graphs = ();
107 foreach $key ( sort(keys %mbmon_values) )
109 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
110 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
112 $mbmon_settings{'LABEL-'.$key} = $key;
116 &Header
::openpage
($Lang::tr
{'harddisk temperature graphs'}, 1, '');
118 &Header
::openbigbox
('100%', 'left');
122 #&Header::openbox('100%', 'left', 'DEBUG');
124 #foreach my $line (sort keys %cgiparams) {
125 # print "$line = $cgiparams{$line}<br />\n";
128 #print " Count: $debugCount<br />\n";
129 #print " CGIParams: $cgigraphs[1]\n";
130 #&Header::closebox();
134 if ($cgigraphs[1] =~ /hddtemp/)
136 my $graph = $cgigraphs[1];
137 my $graphname = $Lang::tr
{"harddisk temperature"};
138 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
140 if (-e
"$graphdir/${graph}-day.png")
142 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
144 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
145 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
146 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
147 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
148 print "<img src='/graphs/${graph}-year.png' border='0' />";
149 if ( -e
"/var/log/smartctl_out_${graph}" )
151 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
152 $output = &Header
::cleanhtml
($output);
153 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
158 print $Lang::tr
{'no information available'};
161 print "<div align='center'><table width='80%'><tr><td align='center'>";
162 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
163 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
165 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
167 if ($cgigraphs[1] =~ /temp/) {&Graphs
::updatetempgraph
("week");&Graphs
::updatetempgraph
("month");&Graphs
::updatetempgraph
("year");}
168 if ($cgigraphs[1] =~ /fan/) {&Graphs
::updatefangraph
("week");&Graphs
::updatefangraph
("month");&Graphs
::updatefangraph
("year");}
169 if ($cgigraphs[1] =~ /volt/) {&Graphs
::updatevoltgraph
("week");&Graphs
::updatevoltgraph
("month");&Graphs
::updatevoltgraph
("year");}
171 my $graph = $cgigraphs[1];
172 my $graphname = $Lang::tr
{"mbmon $cgigraphs[1]"};
173 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
175 if (-e
"$graphdir/mbmon-${graph}-day.png")
177 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
179 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
180 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
181 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
182 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
183 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
187 print $Lang::tr
{'no information available'};
190 print "<div align='center'><table width='80%'><tr><td align='center'>";
191 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
192 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
196 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
198 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
199 if (-e
"$graphdir/mbmon-temp-day.png")
201 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
202 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
203 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
204 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
209 print $Lang::tr
{'no information available'};
215 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
217 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
218 if (-e
"$graphdir/mbmon-fan-day.png")
220 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
221 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
222 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
223 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
228 print $Lang::tr
{'no information available'};
234 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
236 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
237 if (-e
"$graphdir/mbmon-volt-day.png")
239 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
240 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
241 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
242 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
247 print $Lang::tr
{'no information available'};
253 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
255 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
259 hddtempbox
($device);}
262 &Header
::openbox
('100%', 'center', $Lang::tr
{'settings'});
264 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
266 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp /> $Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
267 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan /> $Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
268 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt /> $Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
269 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd /> $Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
272 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
273 <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>
278 foreach $key ( sort(keys %mbmon_values) )
282 print("<tr bgcolor='$color{'color22'}'>");
286 print("<tr bgcolor='$color{'color20'}'>");
288 $mbmon_settings{'LABEL-'.$key} = &Header
::cleanhtml
($mbmon_settings{'LABEL-'.$key});
289 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
290 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
291 print("<td> <input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
299 <tr><td class='base' valign='top'> </td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
308 &Header
::closebigbox
();
309 &Header
::closepage
();
313 if (-e
"$graphdir/hddtemp-$disk-day.png") {
315 &Header
::openbox
('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
316 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
317 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
318 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
319 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";