]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
4537994852c6cd61966b98f512498af142b2dd49
3 # This code is based on hddGraph and mbmongraph
4 # written by weizen_42 and distributed under the
6 # http://www.ban-solms.de/t/IPCop-mbmongraph.html
7 # http://www.ban-solms.de/t/IPCop-hddgraph.html
12 # enable only the following on debugging purpose
14 # use CGI::Carp 'fatalsToBrowser';
16 require '/var/ipfire/general-functions.pl';
17 require "${General::swroot}/lang.pl";
18 require "${General::swroot}/header.pl";
19 require "${General::swroot}/graphs.pl";
24 &Header
::showhttpheaders
();
26 my $graphdir = "/srv/web/ipfire/html/graphs";
28 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
32 &Graphs
::updatehddgraph
($disk,"day");
33 &Graphs
::updatehddgraph
($disk,"week");
34 &Graphs
::updatehddgraph
($disk,"month");
35 &Graphs
::updatehddgraph
($disk,"year");
38 &Graphs
::updatetempgraph
("day");
39 &Graphs
::updatetempgraph
("week");
40 &Graphs
::updatetempgraph
("month");
41 &Graphs
::updatetempgraph
("year");
42 &Graphs
::updatefangraph
("day");
43 &Graphs
::updatefangraph
("week");
44 &Graphs
::updatefangraph
("month");
45 &Graphs
::updatefangraph
("year");
46 &Graphs
::updatevoltgraph
("day");
47 &Graphs
::updatevoltgraph
("week");
48 &Graphs
::updatevoltgraph
("month");
49 &Graphs
::updatevoltgraph
("year");
53 &Header
::getcgihash
(\
%cgiparams);
55 $ENV{'QUERY_STRING'} =~ s/&//g;
56 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
57 $cgigraphs[1] = '' unless defined $cgigraphs[1];
59 my %mbmon_settings = ();
60 my %mbmon_values = ();
61 &General
::readhash
("/var/log/mbmon-values", \
%mbmon_values);
64 if ( $cgiparams{'ACTION'} eq $Lang::tr
{'save'} )
66 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
67 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
68 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
69 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
71 foreach my $line (sort keys %cgiparams)
73 if ( index($line, "LINE-") != -1 )
75 $mbmon_settings{$line} = 'on';
78 if ( index($line, "LABEL-") != -1 )
80 $mbmon_settings{$line} = $cgiparams{$line};
84 &General
::writehash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
88 &General
::readhash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
91 my $selected_temp = '';
92 my $selected_fan = '';
93 my $selected_volt = '';
94 my $selected_hdd = '';
96 $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
97 $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
98 $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
99 $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
101 my %mbmon_graphs = ();
102 foreach $key ( sort(keys %mbmon_values) )
104 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
105 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
107 $mbmon_settings{'LABEL-'.$key} = $key;
111 &Header
::openpage
($Lang::tr
{'harddisk temperature graphs'}, 1, '');
113 &Header
::openbigbox
('100%', 'left');
117 #&Header::openbox('100%', 'left', 'DEBUG');
119 #foreach my $line (sort keys %cgiparams) {
120 # print "$line = $cgiparams{$line}<br />\n";
123 #print " Count: $debugCount<br />\n";
124 #print " CGIParams: $cgigraphs[1]\n";
125 #&Header::closebox();
129 if ($cgigraphs[1] =~ /hddtemp/)
131 my $graph = $cgigraphs[1];
132 my $graphname = $Lang::tr
{"harddisk temperature"};
133 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
135 if (-e
"$graphdir/${graph}-day.png")
137 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
139 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
140 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
141 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
142 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
143 print "<img src='/graphs/${graph}-year.png' border='0' />";
144 if ( -e
"/var/log/smartctl_out_${graph}" )
146 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
147 $output = &Header
::cleanhtml
($output);
148 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
153 print $Lang::tr
{'no information available'};
156 print "<div align='center'><table width='80%'><tr><td align='center'>";
157 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
158 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
160 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
162 my $graph = $cgigraphs[1];
163 my $graphname = $Lang::tr
{"mbmon $cgigraphs[1]"};
164 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
166 if (-e
"$graphdir/mbmon-${graph}-day.png")
168 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
170 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
171 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
172 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
173 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
174 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
178 print $Lang::tr
{'no information available'};
181 print "<div align='center'><table width='80%'><tr><td align='center'>";
182 print "<a href='/cgi-bin/mbmongraph.cgi'>";
183 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
187 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
189 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
190 if (-e
"$graphdir/mbmon-temp-day.png")
192 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
193 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
194 print "<a href='/cgi-bin/mbmongraph.cgi?graph=temp'>";
195 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
200 print $Lang::tr
{'no information available'};
206 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
208 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
209 if (-e
"$graphdir/mbmon-fan-day.png")
211 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
212 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
213 print "<a href='/cgi-bin/mbmongraph.cgi?graph=fan'>";
214 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
219 print $Lang::tr
{'no information available'};
225 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
227 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
228 if (-e
"$graphdir/mbmon-volt-day.png")
230 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
231 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
232 print "<a href='/cgi-bin/mbmongraph.cgi?graph=volt'>";
233 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
238 print $Lang::tr
{'no information available'};
244 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
256 &Header
::openbox
('100%', 'center', $Lang::tr
{'settings'});
258 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
260 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp /> $Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
261 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan /> $Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
262 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt /> $Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
263 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd /> $Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
266 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
267 <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>
272 foreach $key ( sort(keys %mbmon_values) )
276 print("<tr bgcolor='$Header::table2colour'>");
280 print("<tr bgcolor='$Header::table1colour'>");
282 $mbmon_settings{'LABEL-'.$key} = &Header
::cleanhtml
($mbmon_settings{'LABEL-'.$key});
283 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
284 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
285 print("<td> <input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
293 <tr><td class='base' valign='top'> </td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
302 &Header
::closebigbox
();
303 &Header
::closepage
();
307 if (-e
"$graphdir/hddtemp-$disk-day.png") {
309 &Header
::openbox
('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
310 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
311 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
312 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
313 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";