]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
index.cgi: Use filesystem functions library for diskspace usage warning
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 1 May 2024 11:05:51 +0000 (13:05 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 1 May 2024 11:05:51 +0000 (13:05 +0200)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
html/cgi-bin/index.cgi

index 5e32ce038196058e735e32e44ad65e4461316552..fed5a522e8d9d6a24d332dbc125dc764516c3b89 100644 (file)
@@ -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 .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$1M</b> !</li>";
-               }
+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 .= "<li>$Lang::tr{'filesystem full'}: $temp[0] <b>$Lang::tr{'free'}=$temp2%</b> !</li>";
-               }
+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 .= "<li>$Lang::tr{'filesystem full'}: $device <b>$Lang::tr{'free'}=$percent_free%</b> !</li>";
        }
 }