#!/usr/bin/perl ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2008 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### use strict; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/graphs.pl"; my %color = (); my %mainsettings = (); &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); #workaround to suppress a warning when a variable is used only once my @dummy = ( ${Header::colourred} ); undef (@dummy); my %cgiparams=(); my @querry = split(/\?/,$ENV{'QUERY_STRING'}); $querry[0] = '' unless defined $querry[0]; $querry[1] = 'hour' unless defined $querry[1]; my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`; if ( $querry[0] =~ "sd?" || $querry[0] =~ "hd?" || $querry[0] =~ "xvd??"){ print "Content-type: image/png\n\n"; binmode(STDOUT); &Graphs::updatediskgraph($querry[0],$querry[1]); }else{ &Header::showhttpheaders(); &Header::openpage($Lang::tr{'media information'}, 1, ''); &Header::openbigbox('100%', 'left'); foreach (@devices) { my $device = $_; chomp($device); my @array = split(/\//,$device); &Header::openbox('100%', 'center', "$array[$#array] $Lang::tr{'graph'}"); diskbox($array[$#array]); &Graphs::makegraphbox("media.cgi",$array[$#array],"day"); &Header::closebox(); } &Header::openbox('100%', 'center', $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 " END ; }else{ my ($device,$size,$used,$free,$percent,$mount) = split; print < END ; } } close DF; my @iostat1 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$1}'); my @iostat2 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$5}'); my @iostat3 = qx(/usr/bin/iostat -dm -p | grep -v "Linux" | awk '{print \$6}'); print ""; my $i=0; for(my $i = 1; $i <= $#iostat1; $i++){ if ( $i eq '1' ){ print ""; }else{ print ""; } } 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

Inodes

\n"; open(DF,'/bin/df -i -x rootfs|'); while(){ if ($_ =~ m/^Filesystem/ ){ 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

transfers

DeviceMB readMB writen
$iostat1[$i]$iostat2[$i]$iostat3[$i]
\n"; &Header::closebox(); &Header::closebigbox(); &Header::closepage(); } sub percentbar { my $percent = $_[0]; my $fg = '#a0a0a0'; my $bg = '#e2e2e2'; if ($percent =~ m/^(\d+)%$/ ) { print < END ; if ($percent eq "100%") { print "" } elsif ($percent eq "0%") { print "" } else { print "" } print < END ; } } sub diskbox { my $disk = $_[0]; chomp $disk; my @status; if (-e "/var/run/hddstatus"){ open(DATEI, "; close(DATEI); foreach (@diskstate){ if ( $_ =~/$disk/ ){@status = split(/-/,$_);} } if ( $status[1]=~/standby/){ my $ftime = localtime((stat("/var/run/hddshutdown-$disk"))[9]); print"Disk $disk status:".$status[1]." (since $ftime)"; }else{ print"Disk $disk status:".$status[1].""; } } my $smart = `/usr/local/bin/smartctrl $disk`; $smart = &Header::cleanhtml($smart); print < END ; }