#!/usr/bin/perl # # SmoothWall CGIs # # This code is distributed under the terms of the GPL # # (c) The SmoothWall Team # # $Id: status.cgi,v 1.6.2.7 2005/02/24 07:44:35 gespinasse Exp $ # use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require 'CONFIG_ROOT/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; #workaround to suppress a warning when a variable is used only once my @dummy = ( ${Header::colourred} ); undef (@dummy); my %netsettings=(); &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); my %cgiparams=(); # Maps a nice printable name to the changing part of the pid file, which # is also the name of the program my %servicenames = ( $Lang::tr{'dhcp server'} => 'dhcpd', $Lang::tr{'web server'} => 'httpd', $Lang::tr{'cron server'} => 'fcron', $Lang::tr{'dns proxy server'} => 'dnsmasq', $Lang::tr{'logging server'} => 'syslogd', $Lang::tr{'kernel logging server'} => 'klogd', $Lang::tr{'ntp server'} => 'ntpd', $Lang::tr{'secure shell server'} => 'sshd', $Lang::tr{'vpn'} => 'pluto', $Lang::tr{'web proxy'} => 'squid', $Lang::tr{'openvpn'} => 'openvpn' ); my $iface = ''; if (open(FILE, "${General::swroot}/red/iface")) { $iface = ; close FILE; chomp $iface; } $servicenames{"$Lang::tr{'intrusion detection system'} (RED)"} = "snort_${iface}"; $servicenames{"$Lang::tr{'intrusion detection system'} (GREEN)"} = "snort_$netsettings{'GREEN_DEV'}"; if ($netsettings{'ORANGE_DEV'} ne '') { $servicenames{"$Lang::tr{'intrusion detection system'} (ORANGE)"} = "snort_$netsettings{'ORANGE_DEV'}"; } if ($netsettings{'BLUE_DEV'} ne '') { $servicenames{"$Lang::tr{'intrusion detection system'} (BLUE)"} = "snort_$netsettings{'BLUE_DEV'}"; } &Header::showhttpheaders(); &Header::getcgihash(\%cgiparams); &Header::openpage($Lang::tr{'status information'}, 1, ''); &Header::openbigbox('100%', 'left'); print < $Lang::tr{'services'} | $Lang::tr{'memory'} | $Lang::tr{'disk usage'} | $Lang::tr{'uptime and users'} | $Lang::tr{'loaded modules'} | $Lang::tr{'kernel version'} END ; print "\n"; &Header::openbox('100%', 'left', $Lang::tr{'services'}); print < END ; my $lines = 0; my $key = ''; foreach $key (sort keys %servicenames) { if ($lines % 2) { print "\n"; } else { print "\n"; } print "\n"; my $shortname = $servicenames{$key}; my $status = &isrunning($shortname); print "$status\n"; print "\n"; $lines++; } print "
$key
\n"; &Header::closebox(); print "
\n"; &Header::openbox('100%', 'left', $Lang::tr{'memory'}); print ""; my $pid = ''; my $testcmd = ''; my $exename; $cmd =~ /(^[a-z]+)/; $exename = $1; if (open(FILE, "/var/run/${cmd}.pid")) { $pid = ; chomp $pid; close FILE; if (open(FILE, "/proc/${pid}/status")) { while () { if (/^Name:\W+(.*)/) { $testcmd = $1; } } close FILE; if ($testcmd =~ /$exename/) { $status = ""; } } } return $status; } sub percentbar { my $percent = $_[0]; my $fg = '#a0a0a0'; my $bg = '#e2e2e2'; if ($percent =~ m/^(\d+)%$/ ) { print < END ; if ($percent eq "100%") { print "
"; my $ram=0; my $size=0; my $used=0; my $free=0; my $percent=0; my $shared=0; my $buffers=0; my $cached=0; open(FREE,'/usr/bin/free |'); while() { if ($_ =~ m/^\s+total\s+used\s+free\s+shared\s+buffers\s+cached$/ ) { print < END ; } else { if ($_ =~ m/^Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) { ($ram,$size,$used,$free,$shared,$buffers,$cached) = ($1,$1,$2,$3,$4,$5,$6); ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; print < END ; } elsif ($_ =~ m/^Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/) { ($size,$used,$free) = ($1,$2,$3); if ($size != 0) { ($percent = ($used/$size)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; } else { ($percent = ''); } print < END ; } elsif ($ram and $_ =~ m/^-\/\+ buffers\/cache:\s+(\d+)\s+(\d+)$/ ) { ($used,$free) = ($1,$2); ($percent = ($used/$ram)*100) =~ s/^(\d+)(\.\d+)?$/$1%/; print "" } print <$used END ; } } close FREE; print <
  $Lang::tr{'size'} $Lang::tr{'used'} $Lang::tr{'free'} $Lang::tr{'percentage'}
$Lang::tr{'ram'} $size$Lang::tr{'swap'} $size
$Lang::tr{'excluding buffers and cache'}$free END ; &percentbar($percent); print < $percent
$Lang::tr{'shared'}$shared
$Lang::tr{'buffers'}$buffers
$Lang::tr{'cached'}$cached
END ; &Header::closebox(); print "\n"; &Header::openbox('100%', 'left', $Lang::tr{'disk usage'}); print "\n"; open(DF,'/bin/df -B M -x rootfs|'); while() { if ($_ =~ m/^Filesystem/ ) { print < END ; } else { my ($device,$size,$used,$free,$percent,$mount) = split; print < END ; } } close DF; print "
$Lang::tr{'device'} $Lang::tr{'mounted on'} $Lang::tr{'size'} $Lang::tr{'used'} $Lang::tr{'free'} $Lang::tr{'percentage'}
$device $mount $size $used $free END ; &percentbar($percent); print < $percent
\n"; &Header::closebox(); print "
\n"; &Header::openbox('100%', 'left', $Lang::tr{'uptime and users'}); my $output = `/usr/bin/w`; $output = &Header::cleanhtml($output,"y"); print "
$output
\n"; &Header::closebox(); print "
\n"; &Header::openbox('100%', 'left', $Lang::tr{'loaded modules'}); $output = qx+/sbin/lsmod+; ($output = &Header::cleanhtml($output,"y")) =~ s/\[.*\]//g; print "
\n$output\n
\n"; &Header::closebox(); print "
\n"; &Header::openbox('100%', 'left', $Lang::tr{'kernel version'}); print "
\n";
print `/bin/uname -a`;
print "
\n"; &Header::closebox(); &Header::closebigbox(); &Header::closepage(); sub isrunning { my $cmd = $_[0]; my $status = "
$Lang::tr{'stopped'}$Lang::tr{'running'}
" } elsif ($percent eq "0%") { print "" } else { print "" } print <
END ; } }