]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/hardwaregraphs.cgi
kleine fixes in den firewalllogs
[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
52345790
MT
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";
19
60cbd6e7
MT
20my %cgiparams=();
21my @cgigraphs=();
22my @graphs=();
23
24&Header::showhttpheaders();
25
fd0763dc 26my $graphdir = "/srv/web/ipfire/html/graphs";
60cbd6e7 27
52345790
MT
28&Header::getcgihash(\%cgiparams);
29
60cbd6e7
MT
30$ENV{'QUERY_STRING'} =~ s/&//g;
31@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
32$cgigraphs[1] = '' unless defined $cgigraphs[1];
33
52345790
MT
34my %mbmon_settings = ();
35my %mbmon_values = ();
36&General::readhash("/var/log/mbmon-values", \%mbmon_values);
37my $key;
38
39if ( $cgiparams{'ACTION'} eq $Lang::tr{'save'} )
40{
41 $mbmon_settings{'GRAPH_TEMP'} = ($cgiparams{'TEMP'} eq 'on');
42 $mbmon_settings{'GRAPH_FAN'} = ($cgiparams{'FAN'} eq 'on');
43 $mbmon_settings{'GRAPH_VOLT'} = ($cgiparams{'VOLT'} eq 'on');
44 $mbmon_settings{'GRAPH_HDD'} = ($cgiparams{'HDD'} eq 'on');
45
46 foreach my $line (sort keys %cgiparams)
47 {
48 if ( index($line, "LINE-") != -1 )
49 {
50 $mbmon_settings{$line} = 'on';
51 }
52
53 if ( index($line, "LABEL-") != -1 )
54 {
55 $mbmon_settings{$line} = $cgiparams{$line};
56 }
57 }
58
59 &General::writehash("${General::swroot}/mbmon/settings", \%mbmon_settings);
60}
61else
62{
63 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
64}
65
66my $selected_temp = '';
67my $selected_fan = '';
68my $selected_volt = '';
69my $selected_hdd = '';
70
71$selected_temp = "checked='checked'" if ( $mbmon_settings{'GRAPH_TEMP'} == 1 );
72$selected_fan = "checked='checked'" if ( $mbmon_settings{'GRAPH_FAN'} == 1 );
73$selected_volt = "checked='checked'" if ( $mbmon_settings{'GRAPH_VOLT'} == 1 );
74$selected_hdd = "checked='checked'" if ( $mbmon_settings{'GRAPH_HDD'} == 1 );
75
76my %mbmon_graphs = ();
77foreach $key ( sort(keys %mbmon_values) )
78{
79 $mbmon_graphs{$key} = "checked='checked'" if ( $mbmon_settings{'LINE-'.$key} eq 'on' );
80 if ( !defined($mbmon_settings{'LABEL-'.$key}) )
81 {
82 $mbmon_settings{'LABEL-'.$key} = $key;
83 }
84}
85
60cbd6e7
MT
86&Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
87
88&Header::openbigbox('100%', 'left');
89
52345790
MT
90###############
91# DEBUG DEBUG
92#&Header::openbox('100%', 'left', 'DEBUG');
93#my $debugCount = 0;
94#foreach my $line (sort keys %cgiparams) {
95# print "$line = $cgiparams{$line}<br />\n";
96# $debugCount++;
97#}
9217f236
MT
98#print "&nbsp;Count: $debugCount<br />\n";
99#print "&nbsp;CGIParams: $cgigraphs[1]\n";
52345790
MT
100#&Header::closebox();
101# DEBUG DEBUG
102###############
60cbd6e7 103
9217f236
MT
104if ($cgigraphs[1] =~ /hddtemp/)
105{
106 my $graph = $cgigraphs[1];
107 my $graphname = $Lang::tr{"harddisk temperature"};
108 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
109
110 if (-e "$graphdir/${graph}-day.png")
111 {
112 my $ftime = localtime((stat("$graphdir/${graph}-day.png"))[9]);
113 print "<center>";
114 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
115 print "<img src='/graphs/${graph}-day.png' border='0' /><hr />";
116 print "<img src='/graphs/${graph}-week.png' border='0' /><hr />";
117 print "<img src='/graphs/${graph}-month.png' border='0' /><hr />";
118 print "<img src='/graphs/${graph}-year.png' border='0' />";
119 if ( -e "/var/log/smartctl_out_${graph}" )
120 {
121 my $output = `/bin/cat /var/log/smartctl_out_${graph}`;
122 $output = &Header::cleanhtml($output);
123 print "<hr><table border=0><tr><td align=left><pre>$output</pre></table>\n";
124 }
125 }
126 else
127 {
128 print $Lang::tr{'no information available'};
129 }
130 &Header::closebox();
131 print "<div align='center'><table width='80%'><tr><td align='center'>";
132 print "<a href='/cgi-bin/hardwaregraphs.cgi'>";
133 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
134}
135elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
52345790
MT
136{
137 my $graph = $cgigraphs[1];
138 my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"};
139 &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}");
140
141 if (-e "$graphdir/mbmon-${graph}-day.png")
60cbd6e7 142 {
52345790 143 my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]);
60cbd6e7
MT
144 print "<center>";
145 print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n";
52345790
MT
146 print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />";
147 print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />";
148 print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />";
149 print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />";
60cbd6e7
MT
150 }
151 else
152 {
153 print $Lang::tr{'no information available'};
154 }
60cbd6e7 155 &Header::closebox();
52345790
MT
156 print "<div align='center'><table width='80%'><tr><td align='center'>";
157 print "<a href='/cgi-bin/mbmongraph.cgi'>";
158 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
159}
52345790
MT
160else
161{
162 if ( $mbmon_settings{'GRAPH_TEMP'} == 1 )
163 {
164 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}");
165 if (-e "$graphdir/mbmon-temp-day.png")
166 {
167 my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]);
168 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
169 print "<a href='/cgi-bin/mbmongraph.cgi?graph=temp'>";
170 print "<img src='/graphs/mbmon-temp-day.png' border='0' />";
171 print "</a>";
172 }
173 else
174 {
175 print $Lang::tr{'no information available'};
176 }
177 print "<br />\n";
178 &Header::closebox();
179 }
180
181 if ( $mbmon_settings{'GRAPH_FAN'} == 1 )
182 {
183 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}");
184 if (-e "$graphdir/mbmon-fan-day.png")
185 {
186 my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]);
187 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
188 print "<a href='/cgi-bin/mbmongraph.cgi?graph=fan'>";
189 print "<img src='/graphs/mbmon-fan-day.png' border='0' />";
190 print "</a>";
191 }
192 else
193 {
194 print $Lang::tr{'no information available'};
195 }
196 print "<br />\n";
197 &Header::closebox();
198 }
199
200 if ( $mbmon_settings{'GRAPH_VOLT'} == 1 )
201 {
202 &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}");
203 if (-e "$graphdir/mbmon-volt-day.png")
204 {
205 my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]);
206 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
207 print "<a href='/cgi-bin/mbmongraph.cgi?graph=volt'>";
208 print "<img src='/graphs/mbmon-volt-day.png' border='0' />";
209 print "</a>";
210 }
211 else
212 {
213 print $Lang::tr{'no information available'};
214 }
215 print "<br />\n";
216 &Header::closebox();
217 }
218
219 if ( $mbmon_settings{'GRAPH_HDD'} == 1 )
220 {
9217f236
MT
221 hddtempbox("hda");
222 hddtempbox("hdb");
223 hddtempbox("hdc");
224 hddtempbox("hdd");
225 hddtempbox("hde");
226 hddtempbox("hdf");
227 hddtempbox("hdg");
228 hddtempbox("hdh");
52345790
MT
229 }
230
231 &Header::openbox('100%', 'center', $Lang::tr{'settings'});
232print <<END
233<form method='post' action='$ENV{'SCRIPT_NAME'}'>
234<table width='100%'>
9217f236
MT
235<tr><td colspan='2' align='left'><input type='checkbox' name='TEMP' $selected_temp />&nbsp;$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr>
236<tr><td colspan='2' align='left'><input type='checkbox' name='FAN' $selected_fan />&nbsp;$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr>
237<tr><td colspan='2' align='left'><input type='checkbox' name='VOLT' $selected_volt />&nbsp;$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr>
238<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
239</table>
240<hr />
241<table width='100%' border='0' cellspacing='1' cellpadding='0'>
242<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>
243END
244;
245
246my $i = 0;
247foreach $key ( sort(keys %mbmon_values) )
248{
249 if ( $i % 2 )
250 {
251 print("<tr bgcolor='$Header::table2colour'>");
252 }
253 else
254 {
255 print("<tr bgcolor='$Header::table1colour'>");
256 }
257 $mbmon_settings{'LABEL-'.$key} = &Header::cleanhtml($mbmon_settings{'LABEL-'.$key});
258 print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>");
259 print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n");
260 print("<td>&nbsp;<input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n");
261 $i++;
262}
263
264print <<END
265</table>
266
267<table width='100%'>
268<tr><td class='base' valign='top'>&nbsp;</td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr>
269</table>
270
271</form>
272END
273;
274 &Header::closebox();
275}
276
277&Header::closebox();
60cbd6e7
MT
278
279&Header::closebigbox();
280&Header::closepage();
9217f236
MT
281
282sub hddtempbox {
283 my $disk = $_[0];
284 if (-e "$graphdir/hddtemp-$disk-day.png") {
285
286 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
287 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
288 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
289 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
290 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";
291 print "</a>";
292 print "<br />\n";
293 &Header::closebox();
294 }
295}