]>
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');
72 <table width='100%' cellspacing='0' cellpadding='5'border='0'>
73 <tr><td style="background-color: #EAE9EE;" align='left'>
74 <a href='#services'>$Lang::tr{'services'}</a> |
75 <a href='#memory'>$Lang::tr{'memory'}</a> |
76 <a href='#disk'>$Lang::tr{'disk usage'}</a> |
77 <a href='#uptime'>$Lang::tr{'uptime and users'}</a> |
78 <a href='#modules'>$Lang::tr{'loaded modules'}</a> |
79 <a href='#kernel'>$Lang::tr{'kernel version'}</a>
84 print "<a name='services'/>\n";
85 &Header
::openbox
('100%', 'left', $Lang::tr
{'services'});
89 <table width='60%' cellspacing='0' border='0'>
95 foreach $key (sort keys %servicenames)
98 print "<tr bgcolor='${Header::table1colour}'>\n"; }
100 print "<tr bgcolor='${Header::table2colour}'>\n"; }
101 print "<td align='left'>$key</td>\n";
102 my $shortname = $servicenames{$key};
103 my $status = &isrunning
($shortname);
110 print "</table></div>\n";
114 print "<a name='memory'/>\n";
115 &Header
::openbox
('100%', 'left', $Lang::tr
{'memory'});
116 print "<table><tr><td><table>";
125 open(FREE
,'/usr/bin/free |');
128 if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
133 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
134 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
135 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
136 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
141 if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
142 ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
143 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
146 <td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
147 <td align='right'>$size</td>
150 } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
151 ($size,$used,$free) = ($1,$2,$3);
154 ($percent = ($used/$size)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
160 <td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
161 <td align='right'>$size</td>
164 } elsif ($ram and $_ =~ m/^-\/\
+ buffers\
/cache:\s+(\d+)\s+(\d+)$/ ) {
165 ($used,$free) = ($1,$2);
166 ($percent = ($used/$ram)*100) =~ s/^(\d
+)(\
.\d
+)?
$/$1%/;
167 print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
170 <td align='right'>$used</td>
171 <td align='right'>$free</td>
175 &percentbar
($percent);
178 <td align='right'>$percent</td>
188 <tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='right'>$shared</td></tr>
189 <tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='right'>$buffers</td></tr>
190 <tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='right'>$cached</td></tr>
197 print "<a name='disk'/>\n";
198 &Header
::openbox
('100%', 'left', $Lang::tr
{'disk usage'});
200 open(DF
,'/bin/df -B M -x rootfs|');
203 if ($_ =~ m/^Filesystem/ )
207 <td align='left' class='boldbase'><b>$Lang::tr{'device'}</b></td>
208 <td align='left' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
209 <td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
210 <td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
211 <td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
212 <td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
219 my ($device,$size,$used,$free,$percent,$mount) = split;
224 <td align='right'>$size</td>
225 <td align='right'>$used</td>
226 <td align='right'>$free</td>
230 &percentbar
($percent);
233 <td align='right'>$percent</td>
243 print "<a name='uptime'/>\n";
244 &Header
::openbox
('100%', 'left', $Lang::tr
{'uptime and users'});
245 my $output = `/usr/bin/w`;
246 $output = &Header
::cleanhtml
($output,"y");
247 print "<pre>$output</pre>\n";
250 print "<a name='modules'/>\n";
251 &Header
::openbox
('100%', 'left', $Lang::tr
{'loaded modules'});
252 $output = qx+/sbin/lsmod+;
253 ($output = &Header
::cleanhtml
($output,"y")) =~ s/\[.*\]//g;
254 print "<pre>\n$output\n</pre>\n";
257 print "<a name='kernel'/>\n";
258 &Header
::openbox
('100%', 'left', $Lang::tr
{'kernel version'});
260 print `/bin/uname -a`;
264 &Header
::closebigbox
();
266 &Header
::closepage
();
271 my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
279 if (open(FILE
, "/var/run/${cmd}.pid"))
281 $pid = <FILE
>; chomp $pid;
283 if (open(FILE
, "/proc/${pid}/status"))
287 if (/^Name:\W+(.*)/) {
291 if ($testcmd =~ /$exename/)
293 $status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
307 if ($percent =~ m/^(\d+)%$/ )
310 <table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
314 if ($percent eq "100%") {
315 print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
316 } elsif ($percent eq "0%") {
317 print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
319 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'>"
322 <img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>