]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/hardwaregraphs.cgi
Rudimentaere ISDN-Erkennung erstellt.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / hardwaregraphs.cgi
CommitLineData
60cbd6e7
MT
1#!/usr/bin/perl
2#
0e199a22
MT
3# This code is based on hddGraph and mbmongraph
4# written by weizen_42 and distributed under the
5# terms of the GPLv2.
6# http://www.ban-solms.de/t/IPCop-mbmongraph.html
7# http://www.ban-solms.de/t/IPCop-hddgraph.html
60cbd6e7 8#
60cbd6e7
MT
9
10use strict;
11
12# enable only the following on debugging purpose
cb5e9c6c
CS
13# use warnings;
14# use CGI::Carp 'fatalsToBrowser';
60cbd6e7
MT
15
16require '/var/ipfire/general-functions.pl';
17require "${General::swroot}/lang.pl";
18require "${General::swroot}/header.pl";
350b52c5 19require "${General::swroot}/graphs.pl";
60cbd6e7 20
fe6cda92
CS
21my %color = ();
22my %mainsettings = ();
23&General::readhash("${General::swroot}/main/settings", \%mainsettings);
24&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
25
60cbd6e7
MT
26my %cgiparams=();
27my @cgigraphs=();
60cbd6e7
MT
28
29&Header::showhttpheaders();
30
fd0763dc 31my $graphdir = "/srv/web/ipfire/html/graphs";
60cbd6e7 32
350b52c5
CS
33my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
34foreach (@disks){
35 my $disk = $_;
36 chomp $disk;
a28fdc01 37 &Graphs::updatehddgraph ($disk,"day");&Graphs::updatehddgraph ($disk,"week");&Graphs::updatehddgraph ($disk,"month");&Graphs::updatehddgraph ($disk,"year");
350b52c5
CS
38}
39
40 &Graphs::updatetempgraph ("day");
350b52c5 41 &Graphs::updatefangraph ("day");
350b52c5 42 &Graphs::updatevoltgraph ("day");
350b52c5
CS
43
44my @graphs=();
45
52345790
MT
46&Header::getcgihash(\%cgiparams);
47
60cbd6e7
MT
48$ENV{'QUERY_STRING'} =~ s/&//g;
49@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
50$cgigraphs[1] = '' unless defined $cgigraphs[1];
51
52345790
MT
52my %mbmon_settings = ();
53my %mbmon_values = ();
54&General::readhash("/var/log/mbmon-values", \%mbmon_values);
55my $key;
56
57if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} )
58{
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');
63
64 foreach my $line (sort keys %cgiparams)
65 {
66 if ( index($line, "LINE-") != -1 )
67 {
68 $mbmon_settings{$line} = 'on';
69 }
70
71 if ( index($line, "LABEL-") != -1 )
72 {
73 $mbmon_settings{$line} = $cgiparams{$line};
74 }
75 }
76
77 &General::writehash("${General::swroot}/mbmon/settings", \%mbmon_settings);
78}
79else
80{
81 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
82}
83
84my $selected_temp = '';
85my $selected_fan = '';
86my $selected_volt = '';
87my $selected_hdd = '';
88
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 );
93
94my %mbmon_graphs = ();
95foreach $key ( sort(keys %mbmon_values) )
96{
97 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
98 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
99 {
100 $mbmon_settings{'LABEL-'.$key} = $key;
101 }
102}
103
60cbd6e7
MT
104&Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
105
106&Header::openbigbox('100%', 'left');
107
52345790
MT
108###############
109# DEBUG DEBUG
110#&Header::openbox('100%', 'left', 'DEBUG');
111#my $debugCount = 0;
112#foreach my $line (sort keys %cgiparams) {
113# print "$line = $cgiparams{$line}<br />\n";
114# $debugCount++;
115#}
9217f236
MT
116#print "&nbsp;Count: $debugCount<br />\n";
117#print "&nbsp;CGIParams: $cgigraphs[1]\n";
52345790
MT
118#&Header::closebox();
119# DEBUG DEBUG
120###############
60cbd6e7 121
9217f236
MT
122if ($cgigraphs[1] =~ /hddtemp/)
123{
124 my $graph = $cgigraphs[1];
125 my $graphname = $Lang::tr{"harddisk temperature"};
126 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
127
128 if (-e "$graphdir/${graph}-day.png")
129 {
130 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
131 print "<center>";
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}" )
138 {
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";
142 }
143 }
144 else
145 {
146 print $Lang::tr{'no information available'};
147 }
148 &Header::closebox();
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";
152}
153elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
52345790 154{
b05768be
CS
155if ($cgigraphs[1] =~ /temp/) {&Graphs::updatetempgraph ("week");&Graphs::updatetempgraph ("month");&Graphs::updatetempgraph ("year");}
156if ($cgigraphs[1] =~ /fan/) {&Graphs::updatefangraph ("week");&Graphs::updatefangraph ("month");&Graphs::updatefangraph ("year");}
157if ($cgigraphs[1] =~ /volt/) {&Graphs::updatevoltgraph ("week");&Graphs::updatevoltgraph ("month");&Graphs::updatevoltgraph ("year");}
b05768be 158
52345790
MT
159 my $graph = $cgigraphs[1];
160 my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"};
161 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
162
163 if (-e "$graphdir/mbmon-${graph}-day.png")
60cbd6e7 164 {
52345790 165 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
60cbd6e7
MT
166 print "<center>";
167 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
52345790
MT
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' />";
60cbd6e7
MT
172 }
173 else
174 {
175 print $Lang::tr{'no information available'};
176 }
60cbd6e7 177 &Header::closebox();
52345790 178 print "<div align='center'><table width='80%'><tr><td align='center'>";
fe6cda92 179 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
52345790
MT
180 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
181}
52345790
MT
182else
183{
184 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
185 {
186 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
187 if (-e "$graphdir/mbmon-temp-day.png")
188 {
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";
18322edf 191 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=temp'>";
52345790
MT
192 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
193 print "</a>";
194 }
195 else
196 {
197 print $Lang::tr{'no information available'};
198 }
199 print "<br />\n";
200 &Header::closebox();
201 }
202
203 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
204 {
205 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
206 if (-e "$graphdir/mbmon-fan-day.png")
207 {
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";
18322edf 210 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=fan'>";
52345790
MT
211 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
212 print "</a>";
213 }
214 else
215 {
216 print $Lang::tr{'no information available'};
217 }
218 print "<br />\n";
219 &Header::closebox();
220 }
221
222 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
223 {
224 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
225 if (-e "$graphdir/mbmon-volt-day.png")
226 {
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";
18322edf 229 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=volt'>";
52345790
MT
230 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
231 print "</a>";
232 }
233 else
234 {
235 print $Lang::tr{'no information available'};
236 }
237 print "<br />\n";
238 &Header::closebox();
239 }
240
241 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
242 {
a28fdc01
CS
243 my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
244 foreach (@devices) {
245 my $device = $_;
246 chomp($device);
247 hddtempbox($device);}
52345790
MT
248 }
249
250 &Header::openbox('100%', 'center', $Lang::tr{'settings'});
251print <<END
252<form method='post' action='$ENV{'SCRIPT_NAME'}'>
253<table width='100%'>
9217f236
MT
254<tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp />&nbsp;$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
255<tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan />&nbsp;$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
256<tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt />&nbsp;$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
257<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
258</table>
259<hr />
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%'>&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>
262END
263;
264
265my $i = 0;
266foreach $key ( sort(keys %mbmon_values) )
267{
268 if ( $i % 2 )
269 {
fe6cda92 270 print("<tr bgcolor='$color{'color22'}'>");
52345790
MT
271 }
272 else
273 {
fe6cda92 274 print("<tr bgcolor='$color{'color20'}'>");
52345790
MT
275 }
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>&nbsp;<input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
280 $i++;
281}
282
283print <<END
284</table>
285
286<table width='100%'>
287<tr><td class='base' valign='top'>&nbsp;</td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
288</table>
289
290</form>
291END
292;
293 &Header::closebox();
294}
295
60cbd6e7
MT
296&Header::closebigbox();
297&Header::closepage();
9217f236
MT
298
299sub hddtempbox {
300 my $disk = $_[0];
301 if (-e "$graphdir/hddtemp-$disk-day.png") {
302
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' />";
308 print "</a>";
309 print "<br />\n";
310 &Header::closebox();
311 }
312}