]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/hardwaregraphs.cgi
Viele kleine Schnheitsfehler in einigen CGIs angepasst
[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
20 my %cgiparams=();
21 my @cgigraphs=();
22 my @graphs=();
23
24 &Header::showhttpheaders();
25
26 my $graphdir = "/srv/web/ipfire/html/graphs";
27
28 &Header::getcgihash(\%cgiparams);
29
30 $ENV{'QUERY_STRING'} =~ s/&//g;
31 @cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
32 $cgigraphs[1] = '' unless defined $cgigraphs[1];
33
34 my %mbmon_settings = ();
35 my %mbmon_values = ();
36 &General::readhash("/var/log/mbmon-values", \%mbmon_values);
37 my $key;
38
39 if ( $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 }
61 else
62 {
63 &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
64 }
65
66 my $selected_temp = '';
67 my $selected_fan = '';
68 my $selected_volt = '';
69 my $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
76 my %mbmon_graphs = ();
77 foreach $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
86 &Header::openpage($Lang::tr{'harddisk temperature graphs'}, 1, '');
87
88 &Header::openbigbox('100%', 'left');
89
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 #}
98 #print "&nbsp;Count: $debugCount<br />\n";
99 #print "&nbsp;CGIParams: $cgigraphs[1]\n";
100 #&Header::closebox();
101 # DEBUG DEBUG
102 ###############
103
104 if ($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 }
135 elsif ($cgigraphs[1] =~ /(temp|fan|volt)/)
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")
142 {
143 my $ftime = localtime((stat("$graphdir/mbmon-${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/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' />";
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/mbmongraph.cgi'>";
158 print "$Lang::tr{'back'}</a></td></tr></table></div>\n";
159 }
160 else
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 {
221 hddtempbox("hda");
222 hddtempbox("hdb");
223 hddtempbox("hdc");
224 hddtempbox("hdd");
225 hddtempbox("hde");
226 hddtempbox("hdf");
227 hddtempbox("hdg");
228 hddtempbox("hdh");
229 }
230
231 &Header::openbox('100%', 'center', $Lang::tr{'settings'});
232 print <<END
233 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
234 <table width='100%'>
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>
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>
243 END
244 ;
245
246 my $i = 0;
247 foreach $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
264 print <<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>
272 END
273 ;
274 &Header::closebox();
275 }
276
277 &Header::closebigbox();
278 &Header::closepage();
279
280 sub hddtempbox {
281 my $disk = $_[0];
282 if (-e "$graphdir/hddtemp-$disk-day.png") {
283
284 &Header::openbox('100%', 'center', "Disk /dev/$disk $Lang::tr{'graph'}");
285 my $ftime = localtime((stat("$graphdir/hddtemp-$disk-day.png"))[9]);
286 print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n";
287 print "<a href='/cgi-bin/hardwaregraphs.cgi?graph=hddtemp-$disk'>";
288 print "<img src='/graphs/hddtemp-$disk-day.png' border='0' />";
289 print "</a>";
290 print "<br />\n";
291 &Header::closebox();
292 }
293 }