]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/status.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
13 # enable only the following on debugging purpose
15 use CGI
::Carp
'fatalsToBrowser';
17 require '/var/ipfire/general-functions.pl';
18 require "${General::swroot}/lang.pl";
19 require "${General::swroot}/header.pl";
21 #workaround to suppress a warning when a variable is used only once
22 my @dummy = ( ${Header
::colourred
} );
26 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
29 # Maps a nice printable name to the changing part of the pid file, which
30 # is also the name of the program
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'
47 if (open(FILE
, "${General::swroot}/red/iface"))
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'}";
58 if ($netsettings{'BLUE_DEV'} ne '') {
59 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
68 &General
::readhash
("${General::swroot}/dhcp/settings", \
%dhcpsettings);
69 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
70 &General
::readhash
("${General::swroot}/ppp/settings", \
%pppsettings);
72 &Header
::showhttpheaders
();
74 &Header
::getcgihash
(\
%cgiparams);
76 &Header
::openpage
($Lang::tr
{'status information'}, 1, '');
78 &Header
::openbigbox
('100%', 'left');
80 &Header
::openbox
('100%', 'left', $Lang::tr
{'services'});
84 <table width='60%' cellspacing='0' border='0'>
90 foreach $key (sort keys %servicenames)
93 print "<tr bgcolor='${Header::table1colour}'>\n"; }
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);
105 print "</table></div>\n";
109 &Header
::openbox
('100%', 'center', $Lang::tr
{'memory'});
110 print "<table><tr><td><table>";
119 open(FREE
,'/usr/bin/free |');
122 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
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>
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%/;
140 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
141 <td align='right'>$size</td>
144 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
145 ($size,$used,$free) = ($1,$2,$3);
148 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
154 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
155 <td align='right'>$size</td>
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>"
164 <td align='right'>$used</td>
165 <td align='right'>$free</td>
169 &percentbar
($percent);
172 <td align='right'>$percent</td>
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>
191 &Header
::openbox
('100%', 'center', $Lang::tr
{'disk usage'});
192 print "<table width=66%>\n";
193 open(DF
,'/bin/df -B M -x rootfs|');
196 if ($_ =~ m/^Filesystem/ )
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>
212 my ($device,$size,$used,$free,$percent,$mount) = split;
217 <td align='right'>$size</td>
218 <td align='right'>$used</td>
219 <td align='right'>$free</td>
223 &percentbar
($percent);
226 <td align='right'>$percent</td>
233 print "<tr><td colspan='6'> \n<tr><td colspan='6'><h2>Inodes</h2>\n";
235 open(DF
,'/bin/df -i -x rootfs|');
238 if ($_ =~ m/^Filesystem/ )
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>
254 my ($device,$size,$used,$free,$percent,$mount) = split;
259 <td align='right'>$size</td>
260 <td align='right'>$used</td>
261 <td align='right'>$free</td>
265 &percentbar
($percent);
268 <td align='right'>$percent</td>
278 &Header
::openbox
('100%', 'left', $Lang::tr
{'interfaces'});
279 $output = `/sbin/ifconfig`;
280 $output = &Header
::cleanhtml
($output,"y");
282 my @itfs = ('ORANGE','BLUE','GREEN');
283 foreach my $itf (@itfs) {
286 my $dev = $netsettings{"${itf}_DEV"};
288 $ColorName = "${lc_itf}"; #dereference variable name...
289 $output =~ s/$dev/<b><font color="$ColorName">$dev<\/font
><\
/b>/ ;
293 if (open(REDIFACE
, "${General::swroot}/red/iface")) {
295 my $reddev = <REDIFACE
>;
298 $output =~ s/$reddev/<b><font color='red'>${reddev}<\/font
><\
/b>/;
300 print "<pre>$output</pre>\n";
304 if ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq "DHCP") {
306 print "<a name='reddhcp'/>\n";
307 &Header
::openbox
('100%', 'left', "RED $Lang::tr{'dhcp configuration'}");
308 if (-s
"${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info") {
310 &General
::readhash
("${General::swroot}/dhcpc/dhcpcd-$netsettings{'RED_DEV'}.info", \
%dhcpinfo);
312 my $DNS1=`echo $dhcpinfo{'DNS'} | cut -f 1 -d ,`;
313 my $DNS2=`echo $dhcpinfo{'DNS'} | cut -f 2 -d ,`;
317 if ($dhcpinfo{'LEASETIME'} ne "") {
318 $lsetme=$dhcpinfo{'LEASETIME'};
319 $lsetme=($lsetme/60);
321 $lsetme=($lsetme/60); $leasetime=$lsetme." Hour";
323 $leasetime=$lsetme." Minute";
326 $leasetime=$leasetime."s";
331 if ($dhcpinfo{'RENEWALTIME'} ne "") {
332 $rentme=$dhcpinfo{'RENEWALTIME'};
333 $rentme=($rentme/60);
335 $rentme=($rentme/60); $rnwltime=$rentme." Hour";
337 $rnwltime=$rentme." Minute";
340 $rnwltime=$rnwltime."s";
345 if ($dhcpinfo{'REBINDTIME'} ne "") {
346 $maxtme=$dhcpinfo{'REBINDTIME'};
347 $maxtme=($maxtme/60);
349 $maxtme=($maxtme/60); $maxtime=$maxtme." Hour";
351 $maxtime=$maxtme." Minute";
354 $maxtime=$maxtime."s";
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";
362 print "<tr><td width='30%'>$Lang::tr{'domain'}</td><td>$dhcpinfo{'DOMAIN'}</td></tr>\n";
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>
378 print "$Lang::tr{'no dhcp lease'}";
383 if ($dhcpsettings{'ENABLE_GREEN'} eq 'on' || $dhcpsettings{'ENABLE_BLUE'} eq 'on') {
385 print "<a name='leases'/>";
386 &Header
::CheckSortOrder
;
387 &Header
::PrintActualLeases
;
390 &Header
::openbox
('100%', 'left', $Lang::tr
{'routing table entries'});
391 $output = `/sbin/route -n`;
392 $output = &Header
::cleanhtml
($output,"y");
393 print "<pre>$output</pre>\n";
396 &Header
::openbox
('100%', 'left', $Lang::tr
{'arp table entries'});
397 $output = `/sbin/arp -n`;
398 $output = &Header
::cleanhtml
($output,"y");
399 print "<pre>$output</pre>\n";
402 &Header
::openbox
('100%', 'left', $Lang::tr
{'loaded modules'});
403 my $module = qx(/bin/lsmod | awk
-F
" " '{print \$1}');
404 my $size = qx(/bin/lsmod | awk
-F
" " '{print \$2}');
405 my $used = qx(/bin/lsmod | awk
-F
" " '{print \$3}');
406 my @usedby = qx(/bin/lsmod | awk
-F
" " '{print \$4}');
410 foreach $usedbyline(@usedby)
412 my $laenge = length($usedbyline);
416 my $usedbylinef=substr($usedbyline,0,30);
417 $usedbyline="$usedbylinef ...\n";
418 push(@usedbyf,$usedbyline);
421 {push(@usedbyf,$usedbyline);}
424 <table cellspacing=25><tr>
425 <td><pre>$module</pre></td>
426 <td><pre>$size</pre></td>
427 <td><pre>$used</pre></td>
428 <td><pre>@usedbyf</pre></td>
436 &Header
::closebigbox
();
438 &Header
::closepage
();
443 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
451 if (open(FILE
, "/var/run/${cmd}.pid"))
453 $pid = <FILE
>; chomp $pid;
455 if (open(FILE
, "/proc/${pid}/status"))
459 if (/^Name:\W+(.*)/) {
463 if ($testcmd =~ /$exename/)
465 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
479 if ($percent =~ m/^(\d+)%$/ )
482 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
486 if ($percent eq "100%") {
487 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
488 } elsif ($percent eq "0%") {
489 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
491 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'>"
494 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>