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