]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/status.cgi
Samba vorbereitet fuer CUPS
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / status.cgi
CommitLineData
ac1cfefa
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#
ac1cfefa
MT
9#
10
11use strict;
12
13# enable only the following on debugging purpose
5fd30232
MT
14use warnings;
15use CGI::Carp 'fatalsToBrowser';
ac1cfefa 16
986e08d9 17require '/var/ipfire/general-functions.pl';
ac1cfefa
MT
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(
5fd30232
MT
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'
ac1cfefa
MT
44);
45
46my $iface = '';
47if (open(FILE, "${General::swroot}/red/iface"))
48{
5fd30232
MT
49 $iface = <FILE>;
50 close FILE;
51 chomp $iface;
ac1cfefa
MT
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 '') {
5fd30232 56 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
ac1cfefa
MT
57}
58if ($netsettings{'BLUE_DEV'} ne '') {
5fd30232 59 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
ac1cfefa
MT
60}
61
5fd30232
MT
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
ac1cfefa
MT
72&Header::showhttpheaders();
73
74&Header::getcgihash(\%cgiparams);
75
76&Header::openpage($Lang::tr{'status information'}, 1, '');
77
78&Header::openbigbox('100%', 'left');
79
ac1cfefa
MT
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{
5fd30232
MT
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++;
ac1cfefa
MT
102}
103
104
105print "</table></div>\n";
106
107&Header::closebox();
108
5fd30232 109&Header::openbox('100%', 'center', $Lang::tr{'memory'});
92004c61 110print "<table width='95%' cellspacing='5'>";
ac1cfefa
MT
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{
5fd30232
MT
122 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
123 {
ac1cfefa
MT
124 print <<END
125<tr>
92004c61 126<td align='center'>&nbsp;</td>
ac1cfefa
MT
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
92004c61 180<tr><td class='boldbase' colspan='2'><br /></td></tr>
ac1cfefa
MT
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>
ac1cfefa
MT
185END
186;
187&Header::closebox();
188
5fd30232 189&Header::openbox('100%', 'center', $Lang::tr{'disk usage'});
92004c61 190print "<table width='95%' cellspacing='5'>\n";
ac1cfefa
MT
191open(DF,'/bin/df -B M -x rootfs|');
192while(<DF>)
193{
5fd30232
MT
194 if ($_ =~ m/^Filesystem/ )
195 {
196 print <<END
ac1cfefa
MT
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>
205END
206;
5fd30232
MT
207 }
208 else
209 {
210 my ($device,$size,$used,$free,$percent,$mount) = split;
211 print <<END
ac1cfefa
MT
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>
219END
220;
5fd30232
MT
221 &percentbar($percent);
222 print <<END
ac1cfefa
MT
223</td>
224<td align='right'>$percent</td>
225</tr>
226END
227;
5fd30232
MT
228 }
229}
230close DF;
498f4839 231print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>Inodes</h3>\n";
5fd30232
MT
232
233open(DF,'/bin/df -i -x rootfs|');
234while(<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>
247END
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>
261END
262;
263 &percentbar($percent);
264 print <<END
265</td>
266<td align='right'>$percent</td>
267</tr>
268END
269;
270 }
ac1cfefa
MT
271}
272close DF;
498f4839
CS
273my $iostat = qx(/usr/bin/iostat -dm -p | grep -v "Linux");
274print "<tr><td colspan='7'>&nbsp;\n<tr><td colspan='7'><h3>transfers</h3></td></tr>\n<tr><td align='center' colspan='7'><pre>$iostat</pre></td></tr>";
275
ac1cfefa
MT
276print "</table>\n";
277&Header::closebox();
278
5fd30232 279&Header::openbox('100%', 'left', $Lang::tr{'interfaces'});
32e2d042 280$output = `/sbin/ip link show`;
5fd30232
MT
281$output = &Header::cleanhtml($output,"y");
282
283my @itfs = ('ORANGE','BLUE','GREEN');
284foreach my $itf (@itfs) {
285 my $ColorName='';
286 my $lc_itf=lc($itf);
287 my $dev = $netsettings{"${itf}_DEV"};
288 if ($dev){
289 $ColorName = "${lc_itf}"; #dereference variable name...
290 $output =~ s/$dev/<b><font color="$ColorName">$dev<\/font><\/b>/ ;
291 }
292}
293
294if (open(REDIFACE, "${General::swroot}/red/iface")) {
295 my $lc_itf='red';
296 my $reddev = <REDIFACE>;
297 close(REDIFACE);
298 chomp $reddev;
299 $output =~ s/$reddev/<b><font color='red'>${reddev}<\/font><\/b>/;
300}
301print "<pre>$output</pre>\n";
302&Header::closebox();
303
304
305if ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq "DHCP") {
306
5fd30232
MT
307 &Header::openbox('100%', 'left', "RED $Lang::tr{'dhcp configuration'}");
308 if (-s "${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info") {
309
310 &General::readhash("${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info", \%dhcpinfo);
311
312 my $DNS1=`echo $dhcpinfo{'DNS'} | cut -f 1 -d ,`;
313 my $DNS2=`echo $dhcpinfo{'DNS'} | cut -f 2 -d ,`;
314
315 my $lsetme=0;
316 my $leasetime="";
317 if ($dhcpinfo{'LEASETIME'} ne "") {
318 $lsetme=$dhcpinfo{'LEASETIME'};
319 $lsetme=($lsetme/60);
320 if ($lsetme > 59) {
321 $lsetme=($lsetme/60); $leasetime=$lsetme." Hour";
322 } else {
323 $leasetime=$lsetme." Minute";
324 }
325 if ($lsetme > 1) {
326 $leasetime=$leasetime."s";
327 }
328 }
329 my $rentme=0;
330 my $rnwltime="";
331 if ($dhcpinfo{'RENEWALTIME'} ne "") {
332 $rentme=$dhcpinfo{'RENEWALTIME'};
333 $rentme=($rentme/60);
334 if ($rentme > 59){
335 $rentme=($rentme/60); $rnwltime=$rentme." Hour";
336 } else {
337 $rnwltime=$rentme." Minute";
338 }
339 if ($rentme > 1){
340 $rnwltime=$rnwltime."s";
341 }
342 }
343 my $maxtme=0;
344 my $maxtime="";
345 if ($dhcpinfo{'REBINDTIME'} ne "") {
346 $maxtme=$dhcpinfo{'REBINDTIME'};
347 $maxtme=($maxtme/60);
348 if ($maxtme > 59){
349 $maxtme=($maxtme/60); $maxtime=$maxtme." Hour";
350 } else {
351 $maxtime=$maxtme." Minute";
352 }
353 if ($maxtme > 1) {
354 $maxtime=$maxtime."s";
355 }
356 }
357
358 print "<table width='100%'>";
359 if ($dhcpinfo{'HOSTNAME'}) {
360 print "<tr><td width='30%'>$Lang::tr{'hostname'}</td><td>$dhcpinfo{'HOSTNAME'}.$dhcpinfo{'DOMAIN'}</td></tr>\n";
361 } else {
362 print "<tr><td width='30%'>$Lang::tr{'domain'}</td><td>$dhcpinfo{'DOMAIN'}</td></tr>\n";
363 }
364 print <<END
365 <tr><td>$Lang::tr{'gateway'}</td><td>$dhcpinfo{'GATEWAY'}</td></tr>
366 <tr><td>$Lang::tr{'primary dns'}</td><td>$DNS1</td></tr>
367 <tr><td>$Lang::tr{'secondary dns'}</td><td>$DNS2</td></tr>
368 <tr><td>$Lang::tr{'dhcp server'}</td><td>$dhcpinfo{'DHCPSIADDR'}</td></tr>
369 <tr><td>$Lang::tr{'def lease time'}</td><td>$leasetime</td></tr>
370 <tr><td>$Lang::tr{'default renewal time'}</td><td>$rnwltime</td></tr>
371 <tr><td>$Lang::tr{'max renewal time'}</td><td>$maxtime</td></tr>
372 </table>
373END
374 ;
375 }
376 else
377 {
378 print "$Lang::tr{'no dhcp lease'}";
379 }
380 &Header::closebox();
381}
382
383if ($dhcpsettings{'ENABLE_GREEN'} eq 'on' || $dhcpsettings{'ENABLE_BLUE'} eq 'on') {
5fd30232
MT
384 &Header::CheckSortOrder;
385 &Header::PrintActualLeases;
386}
387
388&Header::openbox('100%', 'left', $Lang::tr{'routing table entries'});
32e2d042 389$output = `/sbin/ip route show`;
ac1cfefa
MT
390$output = &Header::cleanhtml($output,"y");
391print "<pre>$output</pre>\n";
392&Header::closebox();
393
5fd30232 394&Header::openbox('100%', 'left', $Lang::tr{'arp table entries'});
32e2d042 395$output = `/sbin/ip neigh show`;
5fd30232
MT
396$output = &Header::cleanhtml($output,"y");
397print "<pre>$output</pre>\n";
ac1cfefa
MT
398&Header::closebox();
399
5fd30232
MT
400&Header::openbox('100%', 'left', $Lang::tr{'loaded modules'});
401my $module = qx(/bin/lsmod | awk -F" " '{print \$1}');
402my $size = qx(/bin/lsmod | awk -F" " '{print \$2}');
403my $used = qx(/bin/lsmod | awk -F" " '{print \$3}');
404my @usedby = qx(/bin/lsmod | awk -F" " '{print \$4}');
405my @usedbyf;
406my $usedbyline;
407
408foreach $usedbyline(@usedby)
409{
410my $laenge = length($usedbyline);
411
412if ( $laenge > 30)
413 {
414 my $usedbylinef=substr($usedbyline,0,30);
415 $usedbyline="$usedbylinef ...\n";
416 push(@usedbyf,$usedbyline);
417 }
418else
419 {push(@usedbyf,$usedbyline);}
420}
421print <<END
422<table cellspacing=25><tr>
423<td><pre>$module</pre></td>
424<td><pre>$size</pre></td>
425<td><pre>$used</pre></td>
426<td><pre>@usedbyf</pre></td>
427</tr></table>
428END
429;
430
431print "";
ac1cfefa
MT
432&Header::closebox();
433
434&Header::closebigbox();
435
436&Header::closepage();
437
438sub isrunning
439{
5fd30232
MT
440 my $cmd = $_[0];
441 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
442 my $pid = '';
443 my $testcmd = '';
444 my $exename;
ac1cfefa 445
5fd30232
MT
446 $cmd =~ /(^[a-z]+)/;
447 $exename = $1;
ac1cfefa 448
5fd30232
MT
449 if (open(FILE, "/var/run/${cmd}.pid"))
450 {
451 $pid = <FILE>; chomp $pid;
452 close FILE;
453 if (open(FILE, "/proc/${pid}/status"))
454 {
455 while (<FILE>)
456 {
457 if (/^Name:\W+(.*)/) {
458 $testcmd = $1; }
459 }
460 close FILE;
461 if ($testcmd =~ /$exename/)
462 {
463 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
464 }
465 }
466 }
ac1cfefa 467
5fd30232 468 return $status;
ac1cfefa
MT
469}
470
471sub percentbar
472{
473 my $percent = $_[0];
474 my $fg = '#a0a0a0';
475 my $bg = '#e2e2e2';
476
477 if ($percent =~ m/^(\d+)%$/ )
478 {
479 print <<END
480<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
481<tr>
482END
483;
484 if ($percent eq "100%") {
485 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
486 } elsif ($percent eq "0%") {
487 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
488 } else {
489 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'>"
490 }
491 print <<END
492<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>
493END
494;
495 }
496}