]>
git.ipfire.org Git - ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
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";
22 my %mainsettings = ();
23 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
24 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
29 &Header
::showhttpheaders
();
31 my $graphdir = "/srv/web/ipfire/html/graphs";
33 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
37 &Graphs
::updatehddgraph
($disk,"day");&Graphs
::updatehddgraph
($disk,"week");&Graphs
::updatehddgraph
($disk,"month");&Graphs
::updatehddgraph
($disk,"year");
40 &Graphs
::updatetempgraph
("day");
41 &Graphs
::updatefangraph
("day");
42 &Graphs
::updatevoltgraph
("day");
46 &Header
::getcgihash
(\
%cgiparams);
48 $ENV{'QUERY_STRING'} =~ s/&//g;
49 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
50 $cgigraphs[1] = '' unless defined $cgigraphs[1];
52 my %mbmon_settings = ();
53 my %mbmon_values = ();
54 &General
::readhash
("/var/log/mbmon-values", \
%mbmon_values);
57 if ( $cgiparams{'ACTION'} eq $Lang::tr
{'save'} )
59 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
60 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
61 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
62 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
64 foreach my $line (sort keys %cgiparams)
66 if ( index($line, "LINE-") != -1 )
68 $mbmon_settings{$line} = 'on';
71 if ( index($line, "LABEL-") != -1 )
73 $mbmon_settings{$line} = $cgiparams{$line};
77 &General
::writehash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
81 &General
::readhash
("${General::swroot}/mbmon/settings", \
%mbmon_settings);
84 my $selected_temp = '';
85 my $selected_fan = '';
86 my $selected_volt = '';
87 my $selected_hdd = '';
89 $selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
90 $selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
91 $selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
92 $selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
94 my %mbmon_graphs = ();
95 foreach $key ( sort(keys %mbmon_values) )
97 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
98 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
100 $mbmon_settings{'LABEL-'.$key} = $key;
104 &Header
::openpage
($Lang::tr
{'harddisk temperature graphs'}, 1, '');
106 &Header
::openbigbox
('100%', 'left');
110 #&Header::openbox('100%', 'left', 'DEBUG');
112 #foreach my $line (sort keys %cgiparams) {
113 # print "$line = $cgiparams{$line}<br />\n";
116 #print " Count: $debugCount<br />\n";
117 #print " CGIParams: $cgigraphs[1]\n";
118 #&Header::closebox();
122 if ($cgigraphs[1] =~ /hddtemp/)
124 my $graph = $cgigraphs[1];
125 my $graphname = $Lang::tr
{"harddisk temperature"};
126 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
128 if (-e
"$graphdir/${graph}-day.png")
130 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
132 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
133 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
134 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
135 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
136 print "<img src='/graphs/${graph}-year.png' border='0' />";
137 if ( -e
"/var/log/smartctl_out_${graph}" )
139 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
140 $output = &Header
::cleanhtml
($output);
141 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
146 print $Lang::tr
{'no information available'};
149 print "<div align='center'><table width='80%'><tr><td align='center'>";
150 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
151 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
153 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
155 if ($cgigraphs[1] =~ /temp/) {&Graphs
::updatetempgraph
("week");&Graphs
::updatetempgraph
("month");&Graphs
::updatetempgraph
("year");}
156 if ($cgigraphs[1] =~ /fan/) {&Graphs
::updatefangraph
("week");&Graphs
::updatefangraph
("month");&Graphs
::updatefangraph
("year");}
157 if ($cgigraphs[1] =~ /volt/) {&Graphs
::updatevoltgraph
("week");&Graphs
::updatevoltgraph
("month");&Graphs
::updatevoltgraph
("year");}
159 my $graph = $cgigraphs[1];
160 my $graphname = $Lang::tr
{"mbmon $cgigraphs[1]"};
161 &Header
::openbox
('100%', 'center', "$graphname $Lang::tr{'graph'}");
163 if (-e
"$graphdir/mbmon-${graph}-day.png")
165 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
167 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
168 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
169 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
170 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
171 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
175 print $Lang::tr
{'no information available'};
178 print "<div align='center'><table width='80%'><tr><td align='center'>";
179 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
180 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
184 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
186 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
187 if (-e
"$graphdir/mbmon-temp-day.png")
189 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
190 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
191 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
192 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
197 print $Lang::tr
{'no information available'};
203 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
205 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
206 if (-e
"$graphdir/mbmon-fan-day.png")
208 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
209 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
210 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
211 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
216 print $Lang::tr
{'no information available'};
222 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
224 &Header
::openbox
('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
225 if (-e
"$graphdir/mbmon-volt-day.png")
227 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
228 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
229 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
230 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
235 print $Lang::tr
{'no information available'};
241 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
243 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
247 hddtempbox
($device);}
250 &Header
::openbox
('100%', 'center', $Lang::tr
{'settings'});
252 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
254 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp /> $Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
255 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan /> $Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
256 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt /> $Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
257 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd /> $Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
260 <table width='100%' border='0' cellspacing='1' cellpadding='0'>
261 <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>
266 foreach $key ( sort(keys %mbmon_values) )
270 print("<tr bgcolor='$color{'color22'}'>");
274 print("<tr bgcolor='$color{'color20'}'>");
276 $mbmon_settings{'LABEL-'.$key} = &Header
::cleanhtml
($mbmon_settings{'LABEL-'.$key});
277 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
278 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
279 print("<td> <input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
287 <tr><td class='base' valign='top'> </td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
296 &Header
::closebigbox
();
297 &Header
::closepage
();
301 if (-e
"$graphdir/hddtemp-$disk-day.png") {
303 &Header
::openbox
('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
304 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
305 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
306 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
307 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";