]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
makegraphs umgebaut, sodass nurnoch rrd daten geschrieben werden die graphen
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / hardwaregraphs.cgi
1 #!/usr/bin/perl
2 #
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
8 #
9
10 use strict;
11
12 # enable only the following on debugging purpose
13 # use warnings;
14 # use CGI::Carp 'fatalsToBrowser';
15
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";
20
21 my %cgiparams=();
22 my @cgigraphs=();
23
24 &Header::showhttpheaders();
25
26 my $graphdir = "/srv/web/ipfire/html/graphs";
27
28 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
29 foreach (@disks){
30 my $disk = $_;
31 chomp $disk;
32 &Graphs::updatehddgraph ($disk,"day");
33 &Graphs::updatehddgraph ($disk,"week");
34 &Graphs::updatehddgraph ($disk,"month");
35 &Graphs::updatehddgraph ($disk,"year");
36 }
37
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");
50
51 my @graphs=();
52
53 &Header::getcgihash(\%cgiparams);
54
55 $ENV{'QUERY_STRING'} =~ s/&//g;
56 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
57 $cgigraphs[1] = '' unless defined $cgigraphs[1];
58
59 my %mbmon_settings = ();
60 my %mbmon_values = ();
61 &General::readhash("/var/log/mbmon-values", \%mbmon_values);
62 my $key;
63
64 if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} )
65 {
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');
70
71 foreach my $line (sort keys %cgiparams)
72 {
73 if ( index($line, "LINE-") != -1 )
74 {
75 $mbmon_settings{$line} = 'on';
76 }
77
78 if ( index($line, "LABEL-") != -1 )
79 {
80 $mbmon_settings{$line} = $cgiparams{$line};
81 }
82 }
83
84 &General::writehash("${General::swroot}/mbmon/settings", \%mbmon_settings);
85 }
86 else
87 {
88 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
89 }
90
91 my $selected_temp = '';
92 my $selected_fan = '';
93 my $selected_volt = '';
94 my $selected_hdd = '';
95
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 );
100
101 my %mbmon_graphs = ();
102 foreach $key ( sort(keys %mbmon_values) )
103 {
104 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
105 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
106 {
107 $mbmon_settings{'LABEL-'.$key} = $key;
108 }
109 }
110
111 &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
112
113 &Header::openbigbox('100%', 'left');
114
115 ###############
116 # DEBUG DEBUG
117 #&Header::openbox('100%', 'left', 'DEBUG');
118 #my $debugCount = 0;
119 #foreach my $line (sort keys %cgiparams) {
120 # print "$line = $cgiparams{$line}<br />\n";
121 # $debugCount++;
122 #}
123 #print "&nbsp;Count: $debugCount<br />\n";
124 #print "&nbsp;CGIParams: $cgigraphs[1]\n";
125 #&Header::closebox();
126 # DEBUG DEBUG
127 ###############
128
129 if ($cgigraphs[1] =~ /hddtemp/)
130 {
131 my $graph = $cgigraphs[1];
132 my $graphname = $Lang::tr{"harddisk temperature"};
133 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
134
135 if (-e "$graphdir/${graph}-day.png")
136 {
137 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
138 print "<center>";
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}" )
145 {
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";
149 }
150 }
151 else
152 {
153 print $Lang::tr{'no information available'};
154 }
155 &Header::closebox();
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";
159 }
160 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
161 {
162 my $graph = $cgigraphs[1];
163 my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"};
164 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
165
166 if (-e "$graphdir/mbmon-${graph}-day.png")
167 {
168 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
169 print "<center>";
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' />";
175 }
176 else
177 {
178 print $Lang::tr{'no information available'};
179 }
180 &Header::closebox();
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";
184 }
185 else
186 {
187 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
188 {
189 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
190 if (-e "$graphdir/mbmon-temp-day.png")
191 {
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' />";
196 print "</a>";
197 }
198 else
199 {
200 print $Lang::tr{'no information available'};
201 }
202 print "<br />\n";
203 &Header::closebox();
204 }
205
206 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
207 {
208 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
209 if (-e "$graphdir/mbmon-fan-day.png")
210 {
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' />";
215 print "</a>";
216 }
217 else
218 {
219 print $Lang::tr{'no information available'};
220 }
221 print "<br />\n";
222 &Header::closebox();
223 }
224
225 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
226 {
227 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
228 if (-e "$graphdir/mbmon-volt-day.png")
229 {
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' />";
234 print "</a>";
235 }
236 else
237 {
238 print $Lang::tr{'no information available'};
239 }
240 print "<br />\n";
241 &Header::closebox();
242 }
243
244 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
245 {
246 hddtempbox("hda");
247 hddtempbox("hdb");
248 hddtempbox("hdc");
249 hddtempbox("hdd");
250 hddtempbox("hde");
251 hddtempbox("hdf");
252 hddtempbox("hdg");
253 hddtempbox("hdh");
254 }
255
256 &Header::openbox('100%', 'center', $Lang::tr{'settings'});
257 print <<END
258 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
259 <table width='100%'>
260 <tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp />&nbsp;$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
261 <tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan />&nbsp;$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
262 <tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt />&nbsp;$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
263 <tr><td colspan='2' align='left'><input type='checkbox' name='HDD' $selected_hdd />&nbsp;$Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr>
264 </table>
265 <hr />
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%'>&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>
268 END
269 ;
270
271 my $i = 0;
272 foreach $key ( sort(keys %mbmon_values) )
273 {
274 if ( $i % 2 )
275 {
276 print("<tr bgcolor='$Header::table2colour'>");
277 }
278 else
279 {
280 print("<tr bgcolor='$Header::table1colour'>");
281 }
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>&nbsp;<input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
286 $i++;
287 }
288
289 print <<END
290 </table>
291
292 <table width='100%'>
293 <tr><td class='base' valign='top'>&nbsp;</td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
294 </table>
295
296 </form>
297 END
298 ;
299 &Header::closebox();
300 }
301
302 &Header::closebigbox();
303 &Header::closepage();
304
305 sub hddtempbox {
306 my $disk = $_[0];
307 if (-e "$graphdir/hddtemp-$disk-day.png") {
308
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' />";
314 print "</a>";
315 print "<br />\n";
316 &Header::closebox();
317 }
318 }