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 'CONFIG_ROOT/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'
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'}";
62
&Header::showhttpheaders();
64
&Header::getcgihash(\%cgiparams);
66
&Header::openpage($Lang::tr{'status information'}, 1, '');
68
&Header::openbigbox('100%', 'left');
71
<table width='100%' cellspacing='0' cellpadding='5'border='0'>
72
<tr><td style="background-color: #EAE9EE;" align='left'>
73
<a href='#services'>$Lang::tr{'services'}</a> |
74
<a href='#memory'>$Lang::tr{'memory'}</a> |
75
<a href='#disk'>$Lang::tr{'disk usage'}</a> |
76
<a href='#uptime'>$Lang::tr{'uptime and users'}</a> |
77
<a href='#modules'>$Lang::tr{'loaded modules'}</a> |
78
<a href='#kernel'>$Lang::tr{'kernel version'}</a>
83
print "<a name='services'/>\n";
84
&Header::openbox('100%', 'left', $Lang::tr{'services'});
88
<table width='60%' cellspacing='0' border='0'>
94
foreach $key (sort keys %servicenames)
97
print "<tr bgcolor='${Header::table1colour}'>\n"; }
99
print "<tr bgcolor='${Header::table2colour}'>\n"; }
100
print "<td align='left'>$key</td>\n";
101
my $shortname = $servicenames{$key};
102
my $status = &isrunning($shortname);
109
print "</table></div>\n";
113
print "<a name='memory'/>\n";
114
&Header::openbox('100%', 'left', $Lang::tr{'memory'});
115
print "<table><tr><td><table>";
124
open(FREE,'/usr/bin/free |');
127
if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ )
132
<td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
133
<td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
134
<td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
135
<td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
140
if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
141
($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6);
142
($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
145
<td class='boldbase'><b>$Lang::tr{'ram'}</b></td>
146
<td align='right'>$size</td>
149
} elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) {
150
($size,$used,$free) = ($1,$2,$3);
153
($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
159
<td class='boldbase'><b>$Lang::tr{'swap'}</b></td>
160
<td align='right'>$size</td>
163
} elsif ($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ) {
164
($used,$free) = ($1,$2);
165
($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/;
166
print "<tr><td colspan='2' class='boldbase'><b>$Lang::tr{'excluding buffers and cache'}</b></td>"
169
<td align='right'>$used</td>
170
<td align='right'>$free</td>
174
&percentbar($percent);
177
<td align='right'>$percent</td>
187
<tr><td class='boldbase'><b>$Lang::tr{'shared'}</b></td><td align='right'>$shared</td></tr>
188
<tr><td class='boldbase'><b>$Lang::tr{'buffers'}</b></td><td align='right'>$buffers</td></tr>
189
<tr><td class='boldbase'><b>$Lang::tr{'cached'}</b></td><td align='right'>$cached</td></tr>
196
print "<a name='disk'/>\n";
197
&Header::openbox('100%', 'left', $Lang::tr{'disk usage'});
199
open(DF,'/bin/df -B M -x rootfs|');
202
if ($_ =~ m/^Filesystem/ )
206
<td align='left' class='boldbase'><b>$Lang::tr{'device'}</b></td>
207
<td align='left' class='boldbase'><b>$Lang::tr{'mounted on'}</b></td>
208
<td align='center' class='boldbase'><b>$Lang::tr{'size'}</b></td>
209
<td align='center' class='boldbase'><b>$Lang::tr{'used'}</b></td>
210
<td align='center' class='boldbase'><b>$Lang::tr{'free'}</b></td>
211
<td align='left' class='boldbase' colspan='2'><b>$Lang::tr{'percentage'}</b></td>
218
my ($device,$size,$used,$free,$percent,$mount) = split;
223
<td align='right'>$size</td>
224
<td align='right'>$used</td>
225
<td align='right'>$free</td>
229
&percentbar($percent);
232
<td align='right'>$percent</td>
242
print "<a name='uptime'/>\n";
243
&Header::openbox('100%', 'left', $Lang::tr{'uptime and users'});
244
my $output = `/usr/bin/w`;
245
$output = &Header::cleanhtml($output,"y");
246
print "<pre>$output</pre>\n";
249
print "<a name='modules'/>\n";
250
&Header::openbox('100%', 'left', $Lang::tr{'loaded modules'});
251
$output = qx+/sbin/lsmod+;
252
($output = &Header::cleanhtml($output,"y")) =~ s/\[.*\]//g;
253
print "<pre>\n$output\n</pre>\n";
256
print "<a name='kernel'/>\n";
257
&Header::openbox('100%', 'left', $Lang::tr{'kernel version'});
259
print `/bin/uname -a`;
263
&Header::closebigbox();
265
&Header::closepage();
270
my $status = "<td bgcolor='${Header::colourred}'><font color='white'><b>$Lang::tr{'stopped'}</b></font></td>";
278
if (open(FILE, "/var/run/${cmd}.pid"))
280
$pid = <FILE>; chomp $pid;
282
if (open(FILE, "/proc/${pid}/status"))
286
if (/^Name:\W+(.*)/) {
290
if ($testcmd =~ /$exename/)
292
$status = "<td bgcolor='${Header::colourgreen}'><font color='white'><b>$Lang::tr{'running'}</b></font></td>";
306
if ($percent =~ m/^(\d+)%$/ )
309
<table width='100' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100px;height:10px;'>
313
if ($percent eq "100%") {
314
print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
315
} elsif ($percent eq "0%") {
316
print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
318
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'>"
321
<img src='/images/null.gif' width='1' height='1' alt='' /></td></tr></table>