]>
git.ipfire.org Git - people/teissler/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
9 # $Id: status.cgi,v 1.6.2.7 2005/02/24 07:44:35 gespinasse Exp $
14 # enable only the following on debugging purpose
16 #use CGI::Carp 'fatalsToBrowser';
18 require '/var/ipfire/general-functions.pl';
19 require "${General::swroot}/lang.pl";
20 require "${General::swroot}/header.pl";
22 #workaround to suppress a warning when a variable is used only once
23 my @dummy = ( ${Header
::colourred
} );
27 &General
::readhash
("${General::swroot}/ethernet/settings", \
%netsettings);
30 # Maps a nice printable name to the changing part of the pid file, which
31 # is also the name of the program
34 $Lang::tr
{'dhcp server'} => 'dhcpd',
35 $Lang::tr
{'web server'} => 'httpd',
36 $Lang::tr
{'cron server'} => 'fcron',
37 $Lang::tr
{'dns proxy server'} => 'dnsmasq',
38 $Lang::tr
{'logging server'} => 'syslogd',
39 $Lang::tr
{'kernel logging server'} => 'klogd',
40 $Lang::tr
{'ntp server'} => 'ntpd',
41 $Lang::tr
{'secure shell server'} => 'sshd',
42 $Lang::tr
{'vpn'} => 'pluto',
43 $Lang::tr
{'web proxy'} => 'squid',
44 'OpenVPN' => 'openvpn'
48 if (open(FILE
, "${General::swroot}/red/iface"))
54 $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}";
55 $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}";
56 if ($netsettings{'ORANGE_DEV'} ne '') {
57 $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}";
59 if ($netsettings{'BLUE_DEV'} ne '') {
60 $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}";
63 &Header
::showhttpheaders
();
65 &Header
::getcgihash
(\
%cgiparams);
67 &Header
::openpage
($Lang::tr
{'status information'}, 1, '');
69 &Header
::openbigbox
('100%', 'left');
71 &Header
::openbox
('100%', 'left', $Lang::tr
{'services'});
75 <table width='60%' cellspacing='0' border='0'>
81 foreach $key (sort keys %servicenames)
84 print "<tr bgcolor='${Header::table1colour}'>\n"; }
86 print "<tr bgcolor='${Header::table2colour}'>\n"; }
87 print "<td align='left'>$key</td>\n";
88 my $shortname = $servicenames{$key};
89 my $status = &isrunning
($shortname);
96 print "</table></div>\n";
100 &Header
::openbox
('100%', 'left', $Lang::tr
{'memory'});
101 print "<table><tr><td><table>";
110 open(FREE
,'/usr/bin/free |');
113 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
118 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
119 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
120 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
121 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
126 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
127 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
128 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
131 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
132 <td align='right'>$size</td>
135 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
136 ($size,$used,$free) = ($1,$2,$3);
139 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
145 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
146 <td align='right'>$size</td>
149 } elsif ($ram and $_ =~ m/^-\/\
+ buffers\
/cache:\s+(\d+)\s+(\d+)$/ ) {
150 ($used,$free) = ($1,$2);
151 ($percent = ($used/$ram)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
152 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
155 <td align='right'>$used</td>
156 <td align='right'>$free</td>
160 &percentbar
($percent);
163 <td align='right'>$percent</td>
173 <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='right'>$shared</td></tr>
174 <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='right'>$buffers</td></tr>
175 <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='right'>$cached</td></tr>
182 &Header
::openbox
('100%', 'left', $Lang::tr
{'disk usage'});
184 open(DF
,'/bin/df -B M -x rootfs|');
187 if ($_ =~ m/^Filesystem/ )
191 <td align='left' class='boldbase'><b>$Lang::tr{'device'}</b></td>
192 <td align='left' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
193 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
194 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
195 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
196 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
203 my ($device,$size,$used,$free,$percent,$mount) = split;
208 <td align='right'>$size</td>
209 <td align='right'>$used</td>
210 <td align='right'>$free</td>
214 &percentbar
($percent);
217 <td align='right'>$percent</td>
227 &Header
::openbox
('100%', 'left', $Lang::tr
{'uptime and users'});
228 my $output = `/usr/bin/who`;
229 $output = &Header
::cleanhtml
($output,"y");
230 print "<pre>$output</pre>\n";
233 &Header
::openbox
('100%', 'left', $Lang::tr
{'loaded modules'});
234 $output = qx+/bin/lsmod+;
235 ($output = &Header
::cleanhtml
($output,"y")) =~ s/\[.*\]//g;
236 print "<pre>\n$output\n</pre>\n";
239 &Header
::openbox
('100%', 'left', $Lang::tr
{'kernel version'});
241 print `/bin/uname -a`;
245 &Header
::closebigbox
();
247 &Header
::closepage
();
252 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
260 if (open(FILE
, "/var/run/${cmd}.pid"))
262 $pid = <FILE
>; chomp $pid;
264 if (open(FILE
, "/proc/${pid}/status"))
268 if (/^Name:\W+(.*)/) {
272 if ($testcmd =~ /$exename/)
274 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
288 if ($percent =~ m/^(\d+)%$/ )
291 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
295 if ($percent eq "100%") {
296 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
297 } elsif ($percent eq "0%") {
298 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
300 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'>"
303 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>