From: Stefan Schantl Date: Wed, 1 May 2024 11:05:51 +0000 (+0200) Subject: index.cgi: Use filesystem functions library for diskspace usage warning X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b8af995dbefca505cdb98eaff16a20eb3880851b;p=people%2Fstevee%2Fipfire-2.x.git index.cgi: Use filesystem functions library for diskspace usage warning Signed-off-by: Stefan Schantl --- diff --git a/html/cgi-bin/index.cgi b/html/cgi-bin/index.cgi index 5e32ce038..fed5a522e 100644 --- a/html/cgi-bin/index.cgi +++ b/html/cgi-bin/index.cgi @@ -30,6 +30,7 @@ use Sort::Naturally; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; +require "${General::swroot}/filesystem-functions.pl"; require "/opt/pakfire/lib/functions.pl"; my %cgiparams=(); @@ -559,29 +560,15 @@ if ($used / $mem > 90) { } # Diskspace usage warning -my @temp=(); -my $temp2=(); -my @df = `/bin/df -B M -P -x rootfs`; -foreach my $line (@df) { - next if $line =~ m/^Filesystem/; - next if $line =~ m/^efivarfs/; - if ($line =~ m/root/ ) { - $line =~ m/^.* (\d+)M.*$/; - @temp = split(/ +/,$line); - if ($1<5) { - # available:plain value in MB, and not %used as 10% is too much to waste on small disk - # and root size should not vary during time - $warnmessage .= "
  • $Lang::tr{'filesystem full'}: $temp[0] $Lang::tr{'free'}=$1M !
  • "; - } +my %volumes = &Filesystem::volumes_status(df => "True"); - } else { - # $line =~ m/^.* (\d+)m.*$/; - $line =~ m/^.* (\d+)\%.*$/; - if ($1>90) { - @temp = split(/ /,$line); - $temp2=int(100-$1); - $warnmessage .= "
  • $Lang::tr{'filesystem full'}: $temp[0] $Lang::tr{'free'}=$temp2% !
  • "; - } +foreach my $device (sort keys %volumes) { + # Grab the amount of used space. + my $percent_used = $volumes{$device}{'percent_used'}; + my $percent_free = $volumes{$device}{'percent_free'}; + + if ($percent_used > 90) { + $warnmessage .= "
  • $Lang::tr{'filesystem full'}: $device $Lang::tr{'free'}=$percent_free% !
  • "; } }