]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/hardwaregraphs.cgi
corrected mpfire stream url
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / hardwaregraphs.cgi
CommitLineData
60cbd6e7 1#!/usr/bin/perl
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
60cbd6e7
MT
21
22use strict;
23
24# enable only the following on debugging purpose
cb5e9c6c
CS
25# use warnings;
26# use CGI::Carp 'fatalsToBrowser';
60cbd6e7
MT
27
28require '/var/ipfire/general-functions.pl';
29require "${General::swroot}/lang.pl";
30require "${General::swroot}/header.pl";
350b52c5 31require "${General::swroot}/graphs.pl";
60cbd6e7 32
fe6cda92
CS
33my %color = ();
34my %mainsettings = ();
35&General::readhash("${General::swroot}/main/settings", \%mainsettings);
36&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
37
60cbd6e7
MT
38my %cgiparams=();
39my @cgigraphs=();
60cbd6e7
MT
40
41&Header::showhttpheaders();
42
fd0763dc 43my $graphdir = "/srv/web/ipfire/html/graphs";
60cbd6e7 44
350b52c5
CS
45my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
46foreach (@disks){
47 my $disk = $_;
48 chomp $disk;
5384809b
CS
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");
350b52c5
CS
51}
52
53 &Graphs::updatetempgraph ("day");
350b52c5 54 &Graphs::updatefangraph ("day");
350b52c5 55 &Graphs::updatevoltgraph ("day");
350b52c5
CS
56
57my @graphs=();
58
52345790
MT
59&Header::getcgihash(\%cgiparams);
60
60cbd6e7
MT
61$ENV{'QUERY_STRING'} =~ s/&//g;
62@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
63$cgigraphs[1] = '' unless defined $cgigraphs[1];
64
52345790
MT
65my %mbmon_settings = ();
66my %mbmon_values = ();
67&General::readhash("/var/log/mbmon-values", \%mbmon_values);
68my $key;
69
70if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} )
71{
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');
76
77 foreach my $line (sort keys %cgiparams)
78 {
79 if ( index($line, "LINE-") != -1 )
80 {
81 $mbmon_settings{$line} = 'on';
82 }
83
84 if ( index($line, "LABEL-") != -1 )
85 {
86 $mbmon_settings{$line} = $cgiparams{$line};
87 }
88 }
89
90 &General::writehash("${General::swroot}/mbmon/settings", \%mbmon_settings);
91}
92else
93{
94 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
95}
96
97my $selected_temp = '';
98my $selected_fan = '';
99my $selected_volt = '';
100my $selected_hdd = '';
101
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 );
106
107my %mbmon_graphs = ();
108foreach $key ( sort(keys %mbmon_values) )
109{
110 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
111 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
112 {
113 $mbmon_settings{'LABEL-'.$key} = $key;
114 }
115}
116
60cbd6e7
MT
117&Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
118
119&Header::openbigbox('100%', 'left');
120
52345790
MT
121###############
122# DEBUG DEBUG
123#&Header::openbox('100%', 'left', 'DEBUG');
124#my $debugCount = 0;
125#foreach my $line (sort keys %cgiparams) {
126# print "$line = $cgiparams{$line}<br />\n";
127# $debugCount++;
128#}
9217f236
MT
129#print "&nbsp;Count: $debugCount<br />\n";
130#print "&nbsp;CGIParams: $cgigraphs[1]\n";
52345790
MT
131#&Header::closebox();
132# DEBUG DEBUG
133###############
60cbd6e7 134
9217f236
MT
135if ($cgigraphs[1] =~ /hddtemp/)
136{
137 my $graph = $cgigraphs[1];
138 my $graphname = $Lang::tr{"harddisk temperature"};
139 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
140
141 if (-e "$graphdir/${graph}-day.png")
142 {
143 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
144 print "<center>";
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}" )
151 {
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";
155 }
156 }
157 else
158 {
159 print $Lang::tr{'no information available'};
160 }
161 &Header::closebox();
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";
165}
166elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
52345790 167{
b05768be
CS
168if ($cgigraphs[1] =~ /temp/) {&Graphs::updatetempgraph ("week");&Graphs::updatetempgraph ("month");&Graphs::updatetempgraph ("year");}
169if ($cgigraphs[1] =~ /fan/) {&Graphs::updatefangraph ("week");&Graphs::updatefangraph ("month");&Graphs::updatefangraph ("year");}
170if ($cgigraphs[1] =~ /volt/) {&Graphs::updatevoltgraph ("week");&Graphs::updatevoltgraph ("month");&Graphs::updatevoltgraph ("year");}
b05768be 171
52345790
MT
172 my $graph = $cgigraphs[1];
173 my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"};
174 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
175
176 if (-e "$graphdir/mbmon-${graph}-day.png")
60cbd6e7 177 {
52345790 178 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
60cbd6e7
MT
179 print "<center>";
180 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
52345790
MT
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' />";
60cbd6e7
MT
185 }
186 else
187 {
188 print $Lang::tr{'no information available'};
189 }
60cbd6e7 190 &Header::closebox();
52345790 191 print "<div align='center'><table width='80%'><tr><td align='center'>";
fe6cda92 192 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
52345790
MT
193 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
194}
52345790
MT
195else
196{
197 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
198 {
199 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
200 if (-e "$graphdir/mbmon-temp-day.png")
201 {
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";
18322edf 204 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
52345790
MT
205 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
206 print "</a>";
207 }
208 else
209 {
210 print $Lang::tr{'no information available'};
211 }
212 print "<br />\n";
213 &Header::closebox();
214 }
215
216 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
217 {
218 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
219 if (-e "$graphdir/mbmon-fan-day.png")
220 {
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";
18322edf 223 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
52345790
MT
224 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
225 print "</a>";
226 }
227 else
228 {
229 print $Lang::tr{'no information available'};
230 }
231 print "<br />\n";
232 &Header::closebox();
233 }
234
235 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
236 {
237 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
238 if (-e "$graphdir/mbmon-volt-day.png")
239 {
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";
18322edf 242 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
52345790
MT
243 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
244 print "</a>";
245 }
246 else
247 {
248 print $Lang::tr{'no information available'};
249 }
250 print "<br />\n";
251 &Header::closebox();
252 }
253
254 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
255 {
a28fdc01
CS
256 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
257 foreach (@devices) {
258 my $device = $_;
259 chomp($device);
5384809b
CS
260 my @array = split(/\//,$device);
261 hddtempbox($array[$#array]);}
52345790
MT
262 }
263
264 &Header::openbox('100%', 'center', $Lang::tr{'settings'});
265print <<END
266<form method='post' action='$ENV{'SCRIPT_NAME'}'>
267<table width='100%'>
9217f236
MT
268<tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp />&nbsp;$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
269<tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan />&nbsp;$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
270<tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt />&nbsp;$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
271<tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd />&nbsp;$Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
52345790
MT
272</table>
273<hr />
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%'>&nbsp;</td><td align='center' width='15%'><b>$Lang::tr{'mbmon value'}</b></td><td align='left'><b>$Lang::tr{'mbmon label'}</b></td></tr>
276END
277;
278
279my $i = 0;
280foreach $key ( sort(keys %mbmon_values) )
281{
282 if ( $i % 2 )
283 {
fe6cda92 284 print("<tr bgcolor='$color{'color22'}'>");
52345790
MT
285 }
286 else
287 {
fe6cda92 288 print("<tr bgcolor='$color{'color20'}'>");
52345790
MT
289 }
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>&nbsp;<input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
294 $i++;
295}
296
297print <<END
298</table>
299
300<table width='100%'>
301<tr><td class='base' valign='top'>&nbsp;</td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
302</table>
303
304</form>
305END
306;
307 &Header::closebox();
308}
309
60cbd6e7
MT
310&Header::closebigbox();
311&Header::closepage();
9217f236
MT
312
313sub hddtempbox {
314 my $disk = $_[0];
315 if (-e "$graphdir/hddtemp-$disk-day.png") {
316
5384809b 317 &Header::openbox('100%', 'center', "Disk $disk $Lang::tr{'graph'}");
9217f236
MT
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' />";
322 print "</a>";
323 print "<br />\n";
324 &Header::closebox();
325 }
326}