]>
Commit | Line | Data |
---|---|---|
60cbd6e7 MT |
1 | #!/usr/bin/perl |
2 | # | |
3 | # SmoothWall CGIs | |
4 | # | |
5 | # This code is distributed under the terms of the GPL | |
6 | # | |
7 | # (c) The SmoothWall Team | |
8 | # | |
60cbd6e7 MT |
9 | |
10 | use strict; | |
11 | ||
12 | # enable only the following on debugging purpose | |
52345790 MT |
13 | # use warnings; |
14 | # use CGI::Carp 'fatalsToBrowser'; | |
60cbd6e7 MT |
15 | |
16 | require '/var/ipfire/general-functions.pl'; | |
17 | require "${General::swroot}/lang.pl"; | |
18 | require "${General::swroot}/header.pl"; | |
19 | ||
60cbd6e7 MT |
20 | my %cgiparams=(); |
21 | my @cgigraphs=(); | |
22 | my @graphs=(); | |
23 | ||
24 | &Header::showhttpheaders(); | |
25 | ||
26 | my $graphdir = "/home/httpd/html/graphs"; | |
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 |
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 | ||
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 | #} | |
98 | #print " Count: $debugCount\n"; | |
99 | #&Header::closebox(); | |
100 | # DEBUG DEBUG | |
101 | ############### | |
60cbd6e7 | 102 | |
52345790 MT |
103 | if ($cgigraphs[1] =~ /(temp|fan|volt)/) |
104 | { | |
105 | my $graph = $cgigraphs[1]; | |
106 | my $graphname = $Lang::tr{"mbmon $cgigraphs[1]"}; | |
107 | &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}"); | |
108 | ||
109 | if (-e "$graphdir/mbmon-${graph}-day.png") | |
60cbd6e7 | 110 | { |
52345790 | 111 | my $ftime = localtime((stat("$graphdir/mbmon-${graph}-day.png"))[9]); |
60cbd6e7 MT |
112 | print "<center>"; |
113 | print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n"; | |
52345790 MT |
114 | print "<img src='/graphs/mbmon-${graph}-day.png' border='0' /><hr />"; |
115 | print "<img src='/graphs/mbmon-${graph}-week.png' border='0' /><hr />"; | |
116 | print "<img src='/graphs/mbmon-${graph}-month.png' border='0' /><hr />"; | |
117 | print "<img src='/graphs/mbmon-${graph}-year.png' border='0' />"; | |
60cbd6e7 MT |
118 | } |
119 | else | |
120 | { | |
121 | print $Lang::tr{'no information available'}; | |
122 | } | |
60cbd6e7 | 123 | &Header::closebox(); |
52345790 MT |
124 | print "<div align='center'><table width='80%'><tr><td align='center'>"; |
125 | print "<a href='/cgi-bin/mbmongraph.cgi'>"; | |
126 | print "$Lang::tr{'back'}</a></td></tr></table></div>\n"; | |
127 | } | |
128 | elsif ($cgigraphs[1] =~ /(hdd)/) | |
129 | { | |
130 | my $graph = $cgigraphs[1]; | |
131 | my $graphname = $Lang::tr{"harddisk temperature"}; | |
132 | &Header::openbox('100%', 'center', "$graphname $Lang::tr{'graph'}"); | |
133 | ||
134 | if (-e "$graphdir/hddtemp-day.png") | |
135 | { | |
136 | my $ftime = localtime((stat("$graphdir/hddtemp-day.png"))[9]); | |
137 | print "<center>"; | |
138 | print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n"; | |
139 | print "<img src='/graphs/hddtemp-day.png' border='0' /><hr />"; | |
140 | print "<img src='/graphs/hddtemp-week.png' border='0' /><hr />"; | |
141 | print "<img src='/graphs/hddtemp-month.png' border='0' /><hr />"; | |
142 | print "<img src='/graphs/hddtemp-year.png' border='0' />"; | |
143 | if ( -e "/var/log/hddgraph_smartctl_out" ) | |
144 | { | |
145 | my $output = `/bin/cat /var/log/hddgraph_smartctl_out`; | |
146 | $output = &Header::cleanhtml($output); | |
147 | print "<hr><pre>$output</pre>\n"; | |
148 | } | |
149 | } | |
150 | else | |
151 | { | |
152 | print $Lang::tr{'no information available'}; | |
153 | } | |
154 | &Header::closebox(); | |
155 | print "<div align='center'><table width='80%'><tr><td align='center'>"; | |
156 | print "<a href='/cgi-bin/mbmongraph.cgi'>"; | |
157 | print "$Lang::tr{'back'}</a></td></tr></table></div>\n"; | |
158 | } | |
159 | else | |
160 | { | |
161 | if ( $mbmon_settings{'GRAPH_TEMP'} == 1 ) | |
162 | { | |
163 | &Header::openbox('100%', 'center', "$Lang::tr{'mbmon temp'} $Lang::tr{'graph'}"); | |
164 | if (-e "$graphdir/mbmon-temp-day.png") | |
165 | { | |
166 | my $ftime = localtime((stat("$graphdir/mbmon-temp-day.png"))[9]); | |
167 | print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n"; | |
168 | print "<a href='/cgi-bin/mbmongraph.cgi?graph=temp'>"; | |
169 | print "<img src='/graphs/mbmon-temp-day.png' border='0' />"; | |
170 | print "</a>"; | |
171 | } | |
172 | else | |
173 | { | |
174 | print $Lang::tr{'no information available'}; | |
175 | } | |
176 | print "<br />\n"; | |
177 | &Header::closebox(); | |
178 | } | |
179 | ||
180 | if ( $mbmon_settings{'GRAPH_FAN'} == 1 ) | |
181 | { | |
182 | &Header::openbox('100%', 'center', "$Lang::tr{'mbmon fan'} $Lang::tr{'graph'}"); | |
183 | if (-e "$graphdir/mbmon-fan-day.png") | |
184 | { | |
185 | my $ftime = localtime((stat("$graphdir/mbmon-fan-day.png"))[9]); | |
186 | print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n"; | |
187 | print "<a href='/cgi-bin/mbmongraph.cgi?graph=fan'>"; | |
188 | print "<img src='/graphs/mbmon-fan-day.png' border='0' />"; | |
189 | print "</a>"; | |
190 | } | |
191 | else | |
192 | { | |
193 | print $Lang::tr{'no information available'}; | |
194 | } | |
195 | print "<br />\n"; | |
196 | &Header::closebox(); | |
197 | } | |
198 | ||
199 | if ( $mbmon_settings{'GRAPH_VOLT'} == 1 ) | |
200 | { | |
201 | &Header::openbox('100%', 'center', "$Lang::tr{'mbmon volt'} $Lang::tr{'graph'}"); | |
202 | if (-e "$graphdir/mbmon-volt-day.png") | |
203 | { | |
204 | my $ftime = localtime((stat("$graphdir/mbmon-volt-day.png"))[9]); | |
205 | print "<center><b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br />\n"; | |
206 | print "<a href='/cgi-bin/mbmongraph.cgi?graph=volt'>"; | |
207 | print "<img src='/graphs/mbmon-volt-day.png' border='0' />"; | |
208 | print "</a>"; | |
209 | } | |
210 | else | |
211 | { | |
212 | print $Lang::tr{'no information available'}; | |
213 | } | |
214 | print "<br />\n"; | |
215 | &Header::closebox(); | |
216 | } | |
217 | ||
218 | if ( $mbmon_settings{'GRAPH_HDD'} == 1 ) | |
219 | { | |
220 | &Header::openbox('100%', 'center', $Lang::tr{'harddisk temperature'}); | |
221 | if (-e "$graphdir/hddtemp-day.png") | |
222 | { | |
223 | my $ftime = localtime((stat("$graphdir/hddtemp-day.png"))[9]); | |
224 | print "<center>"; | |
225 | print "<b>$Lang::tr{'the statistics were last updated at'}: $ftime</b></center><br /><hr />\n"; | |
226 | print "<a href='/cgi-bin/hddgraph.cgi?graph=hdd'>"; | |
227 | print "<img src='/graphs/hddtemp-day.png' border='0' /><hr />"; | |
228 | print "</a>"; | |
229 | } | |
230 | else | |
231 | { | |
232 | print $Lang::tr{'no information available'}; | |
233 | } | |
234 | print "<br />\n"; | |
235 | &Header::closebox(); | |
236 | } | |
237 | ||
238 | &Header::openbox('100%', 'center', $Lang::tr{'settings'}); | |
239 | print <<END | |
240 | <form method='post' action='$ENV{'SCRIPT_NAME'}'> | |
241 | <table width='100%'> | |
242 | <tr><td colspan='2'><input type='checkbox' name='TEMP' $selected_temp /> $Lang::tr{'mbmon temp'} $Lang::tr{'graph'}</td></tr> | |
243 | <tr><td colspan='2'><input type='checkbox' name='FAN' $selected_fan /> $Lang::tr{'mbmon fan'} $Lang::tr{'graph'}</td></tr> | |
244 | <tr><td colspan='2'><input type='checkbox' name='VOLT' $selected_volt /> $Lang::tr{'mbmon volt'} $Lang::tr{'graph'}</td></tr> | |
245 | <tr><td colspan='2'><input type='checkbox' name='HDD' $selected_hdd /> $Lang::tr{'harddisk temperature'}-$Lang::tr{'graph'}</td></tr> | |
246 | </table> | |
247 | <hr /> | |
248 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
249 | <tr><td align='center' width='10%'><b>$Lang::tr{'mbmon display'}</b></td><td align='center' width='15%'> </td><td align='center' width='15%'><b>$Lang::tr{'mbmon value'}</b></td><td align='left'><b>$Lang::tr{'mbmon label'}</b></td></tr> | |
250 | END | |
251 | ; | |
252 | ||
253 | my $i = 0; | |
254 | foreach $key ( sort(keys %mbmon_values) ) | |
255 | { | |
256 | if ( $i % 2 ) | |
257 | { | |
258 | print("<tr bgcolor='$Header::table2colour'>"); | |
259 | } | |
260 | else | |
261 | { | |
262 | print("<tr bgcolor='$Header::table1colour'>"); | |
263 | } | |
264 | $mbmon_settings{'LABEL-'.$key} = &Header::cleanhtml($mbmon_settings{'LABEL-'.$key}); | |
265 | print("<td align='center'><input type='checkbox' name='LINE-$key' $mbmon_graphs{$key}/></td>"); | |
266 | print("<td>$key</td><td align='center'>$mbmon_values{$key}</td>\n"); | |
267 | print("<td> <input type='text' name='LABEL-$key' value='$mbmon_settings{'LABEL-'.$key}' size='25' /></td></tr>\n"); | |
268 | $i++; | |
269 | } | |
270 | ||
271 | print <<END | |
272 | </table> | |
273 | ||
274 | <table width='100%'> | |
275 | <tr><td class='base' valign='top'> </td><td width='40%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td></tr> | |
276 | </table> | |
277 | ||
278 | </form> | |
279 | END | |
280 | ; | |
281 | &Header::closebox(); | |
282 | } | |
283 | ||
284 | &Header::closebox(); | |
60cbd6e7 MT |
285 | |
286 | &Header::closebigbox(); | |
287 | &Header::closepage(); |