]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
9cbaf12be2e7127617a9159ad69c1db16e0d53cb
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");
35 &Graphs
::updatetempgraph
("day");
36 &Graphs
::updatefangraph
("day");
37 &Graphs
::updatevoltgraph
("day");
41 &Header
::getcgihash
(\
%cgiparams);
43 $ENV{'QUERY_STRING'} =~ s/&//g;
44 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
45 $cgigraphs[1] = '' unless defined $cgigraphs[1];
47 my %mbmon_settings = ();
48 my %mbmon_values = ();
49 &General
::readhash
("/var/log/mbmon-values", \
%mbmon_values);
52 if ( $cgiparams{'ACTION'} eq $Lang::tr
{'save'} )
54 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
55 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
56 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
57 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
59 foreach my $line (sort keys %cgiparams)
61 if ( index($line, "LINE-") != -1 )
63 $mbmon_settings{$line} = 'on';
66 if ( index($line, "LABEL-") != -1 )
68 $mbmon_settings{$line} = $cgiparams{$line};
72 &General
::writehash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
76 &General
::readhash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
79 my $selected_temp = '';
80 my $selected_fan = '';
81 my $selected_volt = '';
82 my $selected_hdd = '';
84 $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
85 $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
86 $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
87 $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
89 my %mbmon_graphs = ();
90 foreach $key ( sort(keys %mbmon_values) )
92 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
93 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
95 $mbmon_settings{'LABEL-'.$key} = $key;
99 &Header
::openpage
($Lang::tr
{'harddisk temperature graphs'}, 1, '');
101 &Header
::openbigbox
('100%', 'left');
105 #&Header::openbox('100%', 'left', 'DEBUG');
107 #foreach my $line (sort keys %cgiparams) {
108 # print "$line = $cgiparams{$line}<br />\n";
111 #print " Count: $debugCount<br />\n";
112 #print " CGIParams: $cgigraphs[1]\n";
113 #&Header::closebox();
117 if ($cgigraphs[1] =~ /hddtemp/)
119 my $graph = $cgigraphs[1];
120 my $graphname = $Lang::tr
{"harddisk temperature"};
121 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
123 if (-e
"$graphdir/${graph}-day.png")
125 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
127 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
128 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
129 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
130 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
131 print "<img src='/graphs/${graph}-year.png' border='0' />";
132 if ( -e
"/var/log/smartctl_out_${graph}" )
134 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
135 $output = &Header
::cleanhtml
($output);
136 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
141 print $Lang::tr
{'no information available'};
144 print "<div align='center'><table width='80%'><tr><td align='center'>";
145 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
146 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
148 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
150 if ($cgigraphs[1] =~ /temp/) {&Graphs
::updatetempgraph
("week");&Graphs
::updatetempgraph
("month");&Graphs
::updatetempgraph
("year");}
151 if ($cgigraphs[1] =~ /fan/) {&Graphs
::updatefangraph
("week");&Graphs
::updatefangraph
("month");&Graphs
::updatefangraph
("year");}
152 if ($cgigraphs[1] =~ /volt/) {&Graphs
::updatevoltgraph
("week");&Graphs
::updatevoltgraph
("month");&Graphs
::updatevoltgraph
("year");}
153 if ($cgigraphs[1] =~ /hddtemp/){
154 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
159 &Graphs
::updatehddgraph
($disk,"week");
160 &Graphs
::updatehddgraph
($disk,"month");
161 &Graphs
::updatehddgraph
($disk,"year");}}
163 my $graph = $cgigraphs[1];
164 my $graphname = $Lang::tr
{"mbmon $cgigraphs[1]"};
165 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
167 if (-e
"$graphdir/mbmon-${graph}-day.png")
169 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
171 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
172 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
173 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
174 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
175 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
179 print $Lang::tr
{'no information available'};
182 print "<div align='center'><table width='80%'><tr><td align='center'>";
183 print "<a href='/cgi-bin/mbmongraph.cgi'>";
184 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
188 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
190 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
191 if (-e
"$graphdir/mbmon-temp-day.png")
193 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
194 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
195 print "<a href='/cgi-bin/mbmongraph.cgi?graph=temp'>";
196 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
201 print $Lang::tr
{'no information available'};
207 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
209 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
210 if (-e
"$graphdir/mbmon-fan-day.png")
212 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
213 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
214 print "<a href='/cgi-bin/mbmongraph.cgi?graph=fan'>";
215 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
220 print $Lang::tr
{'no information available'};
226 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
228 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
229 if (-e
"$graphdir/mbmon-volt-day.png")
231 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
232 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
233 print "<a href='/cgi-bin/mbmongraph.cgi?graph=volt'>";
234 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
239 print $Lang::tr
{'no information available'};
245 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
257 &Header
::openbox
('100%', 'center', $Lang::tr
{'settings'});
259 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
261 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp /> $Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
262 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan /> $Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
263 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt /> $Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
264 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd /> $Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
267 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
268 <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>
273 foreach $key ( sort(keys %mbmon_values) )
277 print("<tr bgcolor='$Header::table2colour'>");
281 print("<tr bgcolor='$Header::table1colour'>");
283 $mbmon_settings{'LABEL-'.$key} = &Header
::cleanhtml
($mbmon_settings{'LABEL-'.$key});
284 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
285 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
286 print("<td> <input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
294 <tr><td class='base' valign='top'> </td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
303 &Header
::closebigbox
();
304 &Header
::closepage
();
308 if (-e
"$graphdir/hddtemp-$disk-day.png") {
310 &Header
::openbox
('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
311 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
312 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
313 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
314 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";