]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/status.cgi
"Update Booster" fertiggestellt und getestet.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / status.cgi
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 #
9 #
10
11 use strict;
12
13 # enable only the following on debugging purpose
14 use warnings;
15 use CGI::Carp 'fatalsToBrowser';
16
17 require '/var/ipfire/general-functions.pl';
18 require "${General::swroot}/lang.pl";
19 require "${General::swroot}/header.pl";
20
21 #workaround to suppress a warning when a variable is used only once
22 my @dummy = ( ${Header::colourred} );
23 undef (@dummy);
24
25 my %netsettings=();
26 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
27
28 my %cgiparams=();
29 # Maps a nice printable name to the changing part of the pid file, which
30 # is also the name of the program
31 my %servicenames =
32 (
33 $Lang::tr{'dhcp server'} => 'dhcpd',
34 $Lang::tr{'web server'} => 'httpd',
35 $Lang::tr{'cron server'} => 'fcron',
36 $Lang::tr{'dns proxy server'} => 'dnsmasq',
37 $Lang::tr{'logging server'} => 'syslogd',
38 $Lang::tr{'kernel logging server'} => 'klogd',
39 $Lang::tr{'ntp server'} => 'ntpd',
40 $Lang::tr{'secure shell server'} => 'sshd',
41 $Lang::tr{'vpn'} => 'pluto',
42 $Lang::tr{'web proxy'} => 'squid',
43 'OpenVPN' => 'openvpn'
44 );
45
46 my $iface = '';
47 if (open(FILE, "${General::swroot}/red/iface"))
48 {
49 $iface = <FILE>;
50 close FILE;
51 chomp $iface;
52 }
53 $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
54 $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
55 if ($netsettings{'ORANGE_DEV'} ne '') {
56 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
57 }
58 if ($netsettings{'BLUE_DEV'} ne '') {
59 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
60 }
61
62 my %dhcpsettings=();
63 my %netsettings=();
64 my %dhcpinfo=();
65 my %pppsettings=();
66 my $output='';
67
68 &General::readhash("${General::swroot}/dhcp/settings", \%dhcpsettings);
69 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
70 &General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
71
72 &Header::showhttpheaders();
73
74 &Header::getcgihash(\%cgiparams);
75
76 &Header::openpage($Lang::tr{'status information'}, 1, '');
77
78 &Header::openbigbox('100%', 'left');
79
80 &Header::openbox('100%', 'left', $Lang::tr{'services'});
81
82 print <<END
83 <div align='center'>
84 <table width='60%' cellspacing='0' border='0'>
85 END
86 ;
87
88 my $lines = 0;
89 my $key = '';
90 foreach $key (sort keys %servicenames)
91 {
92 if ($lines % 2) {
93 print "<tr bgcolor='${Header::table1colour}'>\n"; }
94 else {
95 print "<tr bgcolor='${Header::table2colour}'>\n"; }
96 print "<td align='left'>$key</td>\n";
97 my $shortname = $servicenames{$key};
98 my $status = &isrunning($shortname);
99 print "$status\n";
100 print "</tr>\n";
101 $lines++;
102 }
103
104
105 print "</table></div>\n";
106
107 &Header::closebox();
108
109 &Header::openbox('100%', 'center', $Lang::tr{'memory'});
110 print "<table width='95%' cellspacing='5'>";
111 my $ram=0;
112 my $size=0;
113 my $used=0;
114 my $free=0;
115 my $percent=0;
116 my $shared=0;
117 my $buffers=0;
118 my $cached=0;
119 open(FREE,'/usr/bin/free |');
120 while(<FREE>)
121 {
122 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
123 {
124 print <<END
125 <tr>
126 <td align='center'>&nbsp;</td>
127 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
128 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
129 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
130 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
131 </tr>
132 END
133 ;
134 } else {
135 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
136 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
137 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
138 print <<END
139 <tr>
140 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
141 <td align='right'>$size</td>
142 END
143 ;
144 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
145 ($size,$used,$free) = ($1,$2,$3);
146 if ($size != 0)
147 {
148 ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
149 } else {
150 ($percent = '');
151 }
152 print <<END
153 <tr>
154 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
155 <td align='right'>$size</td>
156 END
157 ;
158 } elsif ($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ) {
159 ($used,$free) = ($1,$2);
160 ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
161 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
162 }
163 print <<END
164 <td align='right'>$used</td>
165 <td align='right'>$free</td>
166 <td>
167 END
168 ;
169 &percentbar($percent);
170 print <<END
171 </td>
172 <td align='right'>$percent</td>
173 </tr>
174 END
175 ;
176 }
177 }
178 close FREE;
179 print <<END
180 <tr><td class='boldbase' colspan='2'><br /></td></tr>
181 <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='right'>$shared</td></tr>
182 <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='right'>$buffers</td></tr>
183 <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='right'>$cached</td></tr>
184 </table>
185 END
186 ;
187 &Header::closebox();
188
189 &Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
190 print "<table width='95%' cellspacing='5'>\n";
191 open(DF,'/bin/df -B M -x rootfs|');
192 while(<DF>)
193 {
194 if ($_ =~ m/^Filesystem/ )
195 {
196 print <<END
197 <tr>
198 <td align='left' class='boldbase'><b>$Lang::tr{'device'}</b></td>
199 <td align='left' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
200 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
201 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
202 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
203 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
204 </tr>
205 END
206 ;
207 }
208 else
209 {
210 my ($device,$size,$used,$free,$percent,$mount) = split;
211 print <<END
212 <tr>
213 <td>$device</td>
214 <td>$mount</td>
215 <td align='right'>$size</td>
216 <td align='right'>$used</td>
217 <td align='right'>$free</td>
218 <td>
219 END
220 ;
221 &percentbar($percent);
222 print <<END
223 </td>
224 <td align='right'>$percent</td>
225 </tr>
226 END
227 ;
228 }
229 }
230 close DF;
231 print "<tr><td colspan='6'>&nbsp;\n<tr><td colspan='6'><h3>Inodes</h3>\n";
232
233 open(DF,'/bin/df -i -x rootfs|');
234 while(<DF>)
235 {
236 if ($_ =~ m/^Filesystem/ )
237 {
238 print <<END
239 <tr>
240 <td align='left' class='boldbase'><b>$Lang::tr{'device'}</b></td>
241 <td align='left' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
242 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
243 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
244 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
245 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
246 </tr>
247 END
248 ;
249 }
250 else
251 {
252 my ($device,$size,$used,$free,$percent,$mount) = split;
253 print <<END
254 <tr>
255 <td>$device</td>
256 <td>$mount</td>
257 <td align='right'>$size</td>
258 <td align='right'>$used</td>
259 <td align='right'>$free</td>
260 <td>
261 END
262 ;
263 &percentbar($percent);
264 print <<END
265 </td>
266 <td align='right'>$percent</td>
267 </tr>
268 END
269 ;
270 }
271 }
272 close DF;
273 print "</table>\n";
274 &Header::closebox();
275
276 &Header::openbox('100%', 'left', $Lang::tr{'interfaces'});
277 $output = `/sbin/ip link show`;
278 $output = &Header::cleanhtml($output,"y");
279
280 my @itfs = ('ORANGE','BLUE','GREEN');
281 foreach my $itf (@itfs) {
282 my $ColorName='';
283 my $lc_itf=lc($itf);
284 my $dev = $netsettings{"${itf}_DEV"};
285 if ($dev){
286 $ColorName = "${lc_itf}"; #dereference variable name...
287 $output =~ s/$dev/<b><font color="$ColorName">$dev<\/font><\/b>/ ;
288 }
289 }
290
291 if (open(REDIFACE, "${General::swroot}/red/iface")) {
292 my $lc_itf='red';
293 my $reddev = <REDIFACE>;
294 close(REDIFACE);
295 chomp $reddev;
296 $output =~ s/$reddev/<b><font color='red'>${reddev}<\/font><\/b>/;
297 }
298 print "<pre>$output</pre>\n";
299 &Header::closebox();
300
301
302 if ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq "DHCP") {
303
304 &Header::openbox('100%', 'left', "RED $Lang::tr{'dhcp configuration'}");
305 if (-s "${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info") {
306
307 &General::readhash("${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info", \%dhcpinfo);
308
309 my $DNS1=`echo $dhcpinfo{'DNS'} | cut -f 1 -d ,`;
310 my $DNS2=`echo $dhcpinfo{'DNS'} | cut -f 2 -d ,`;
311
312 my $lsetme=0;
313 my $leasetime="";
314 if ($dhcpinfo{'LEASETIME'} ne "") {
315 $lsetme=$dhcpinfo{'LEASETIME'};
316 $lsetme=($lsetme/60);
317 if ($lsetme > 59) {
318 $lsetme=($lsetme/60); $leasetime=$lsetme." Hour";
319 } else {
320 $leasetime=$lsetme." Minute";
321 }
322 if ($lsetme > 1) {
323 $leasetime=$leasetime."s";
324 }
325 }
326 my $rentme=0;
327 my $rnwltime="";
328 if ($dhcpinfo{'RENEWALTIME'} ne "") {
329 $rentme=$dhcpinfo{'RENEWALTIME'};
330 $rentme=($rentme/60);
331 if ($rentme > 59){
332 $rentme=($rentme/60); $rnwltime=$rentme." Hour";
333 } else {
334 $rnwltime=$rentme." Minute";
335 }
336 if ($rentme > 1){
337 $rnwltime=$rnwltime."s";
338 }
339 }
340 my $maxtme=0;
341 my $maxtime="";
342 if ($dhcpinfo{'REBINDTIME'} ne "") {
343 $maxtme=$dhcpinfo{'REBINDTIME'};
344 $maxtme=($maxtme/60);
345 if ($maxtme > 59){
346 $maxtme=($maxtme/60); $maxtime=$maxtme." Hour";
347 } else {
348 $maxtime=$maxtme." Minute";
349 }
350 if ($maxtme > 1) {
351 $maxtime=$maxtime."s";
352 }
353 }
354
355 print "<table width='100%'>";
356 if ($dhcpinfo{'HOSTNAME'}) {
357 print "<tr><td width='30%'>$Lang::tr{'hostname'}</td><td>$dhcpinfo{'HOSTNAME'}.$dhcpinfo{'DOMAIN'}</td></tr>\n";
358 } else {
359 print "<tr><td width='30%'>$Lang::tr{'domain'}</td><td>$dhcpinfo{'DOMAIN'}</td></tr>\n";
360 }
361 print <<END
362 <tr><td>$Lang::tr{'gateway'}</td><td>$dhcpinfo{'GATEWAY'}</td></tr>
363 <tr><td>$Lang::tr{'primary dns'}</td><td>$DNS1</td></tr>
364 <tr><td>$Lang::tr{'secondary dns'}</td><td>$DNS2</td></tr>
365 <tr><td>$Lang::tr{'dhcp server'}</td><td>$dhcpinfo{'DHCPSIADDR'}</td></tr>
366 <tr><td>$Lang::tr{'def lease time'}</td><td>$leasetime</td></tr>
367 <tr><td>$Lang::tr{'default renewal time'}</td><td>$rnwltime</td></tr>
368 <tr><td>$Lang::tr{'max renewal time'}</td><td>$maxtime</td></tr>
369 </table>
370 END
371 ;
372 }
373 else
374 {
375 print "$Lang::tr{'no dhcp lease'}";
376 }
377 &Header::closebox();
378 }
379
380 if ($dhcpsettings{'ENABLE_GREEN'} eq 'on' || $dhcpsettings{'ENABLE_BLUE'} eq 'on') {
381 &Header::CheckSortOrder;
382 &Header::PrintActualLeases;
383 }
384
385 &Header::openbox('100%', 'left', $Lang::tr{'routing table entries'});
386 $output = `/sbin/ip route show`;
387 $output = &Header::cleanhtml($output,"y");
388 print "<pre>$output</pre>\n";
389 &Header::closebox();
390
391 &Header::openbox('100%', 'left', $Lang::tr{'arp table entries'});
392 $output = `/sbin/ip neigh show`;
393 $output = &Header::cleanhtml($output,"y");
394 print "<pre>$output</pre>\n";
395 &Header::closebox();
396
397 &Header::openbox('100%', 'left', $Lang::tr{'loaded modules'});
398 my $module = qx(/bin/lsmod | awk -F" " '{print \$1}');
399 my $size = qx(/bin/lsmod | awk -F" " '{print \$2}');
400 my $used = qx(/bin/lsmod | awk -F" " '{print \$3}');
401 my @usedby = qx(/bin/lsmod | awk -F" " '{print \$4}');
402 my @usedbyf;
403 my $usedbyline;
404
405 foreach $usedbyline(@usedby)
406 {
407 my $laenge = length($usedbyline);
408
409 if ( $laenge > 30)
410 {
411 my $usedbylinef=substr($usedbyline,0,30);
412 $usedbyline="$usedbylinef ...\n";
413 push(@usedbyf,$usedbyline);
414 }
415 else
416 {push(@usedbyf,$usedbyline);}
417 }
418 print <<END
419 <table cellspacing=25><tr>
420 <td><pre>$module</pre></td>
421 <td><pre>$size</pre></td>
422 <td><pre>$used</pre></td>
423 <td><pre>@usedbyf</pre></td>
424 </tr></table>
425 END
426 ;
427
428 print "";
429 &Header::closebox();
430
431 &Header::closebigbox();
432
433 &Header::closepage();
434
435 sub isrunning
436 {
437 my $cmd = $_[0];
438 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
439 my $pid = '';
440 my $testcmd = '';
441 my $exename;
442
443 $cmd =~ /(^[a-z]+)/;
444 $exename = $1;
445
446 if (open(FILE, "/var/run/${cmd}.pid"))
447 {
448 $pid = <FILE>; chomp $pid;
449 close FILE;
450 if (open(FILE, "/proc/${pid}/status"))
451 {
452 while (<FILE>)
453 {
454 if (/^Name:\W+(.*)/) {
455 $testcmd = $1; }
456 }
457 close FILE;
458 if ($testcmd =~ /$exename/)
459 {
460 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
461 }
462 }
463 }
464
465 return $status;
466 }
467
468 sub percentbar
469 {
470 my $percent = $_[0];
471 my $fg = '#a0a0a0';
472 my $bg = '#e2e2e2';
473
474 if ($percent =~ m/^(\d+)%$/ )
475 {
476 print <<END
477 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
478 <tr>
479 END
480 ;
481 if ($percent eq "100%") {
482 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
483 } elsif ($percent eq "0%") {
484 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
485 } else {
486 print "<td width='$percent' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td width='" . (100-$1) . "%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
487 }
488 print <<END
489 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
490 END
491 ;
492 }
493 }