The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cpanels Disk Quota Warning BUG and fix

Discussion in 'General Discussion' started by patrickb, Apr 27, 2004.

  1. patrickb

    patrickb Registered

    Joined:
    Dec 8, 2003
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    We have always received reports from some users that they were recieving false email warnings about their disk quota usage. As an example, one user recently has been having this problem. He has 20gigs of HD space alloted to him, and only about 181megs of actual space used, but he kept getting email warnings saying he was using 90% of his space.

    After reviewing how cpanel checks quota usage for these warnings, I found the problem in this section of /scripts/quotacheck

    Code:
       } else {
          if ($quotalines =~ /-/ || $quotalines =~ /\+/) {
             $username = substr($quotalines,0,10);
             if ($username =~ /^#(\d+)/) {
                $username = (getpwuid($1))[0];
             }
             $used = substr($quotalines,12,8);
             $hard = substr($quotalines,28,8);
             $username =~ s/\s//g;
             $used =~ s/\s//g;
             $hard =~ s/\s//g;
             if ($username !~ /^\d*$/) {
                $USED{$username} = $USED{$username} + $used;
                if ($hard > 0) {$LIMIT{$username} = $hard;}
             }
          }
       }
    Now, the problem with that is that /usr/sbin/repquota does not report quotas in a fixed format and length. Cpanel seems to have assumed this would always be set in stone. Anything over 10gigs as reported by repquota would break their substr usage for $hard. Note: This was on a Red Hat 9 box running kernel 2.4.25-ow1. This may or may not apply in other distros.

    Now, for the fix, replace all of the above code with:

    Code:
       } else {
          if ($quotalines =~ /-/ || $quotalines =~ /\+/) {
             @quotasplit = split(/\ +/, $quotalines);
             $username = $quotasplit[0];
             if ($username =~ /^#(\d+)/) {
                $username = (getpwuid($1))[0];
             }
             $used = $quotasplit[2];
             $hard = $quotasplit[4];
             if ($username !~ /^\d*$/) {
                $USED{$username} = $USED{$username} + $used;
                if ($hard > 0) {$LIMIT{$username} = $hard;}
             }
          }
       }
    Again, this may or may not apply to other distros, but maybe someone here running something different can verify this. At SSH type '/usr/sbin/repquota -auv' and see if the lengths of the returned output varies if you have any accounts over the 10gig mark.

    To CPanel: Could you correct this in a future release, like soon!
     
    #1 patrickb, Apr 27, 2004
    Last edited: Oct 6, 2004
  2. apodigm

    apodigm Well-Known Member

    Joined:
    May 12, 2003
    Messages:
    67
    Likes Received:
    0
    Trophy Points:
    6
    This definitely seems to make sense.

    Does this file get overwritten often? I dont like to chattr too much, but it seems like this is one of those files that cpanel likes to change automatically.
     
  3. shiv

    shiv Member

    Joined:
    Jul 26, 2004
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Bangalore
    No luck Please help

    Hi,,

    I was not able to run the script after adding the changes specified. Here is the error:


    root@server1 [~]# /scripts/quotacheck
    Quantifier follows nothing before HERE mark in regex m/+ << HERE / at /scripts/quotacheck line 92.


    Please advise soon.
     
  4. patrickb

    patrickb Registered

    Joined:
    Dec 8, 2003
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    apodigm: So far I don't think this file has changed one bit since my original posting. If you don't want to chattr it, then make a copy of it and stick it somewhere to have on hand when you encounter the problem.

    shiv: That problem is because the forum software here isn't showing the "\" in what I pasted. To fix it, find the line in your file and it should look like "if ($quotalines =~ /-/ || $quotalines =~ /+/) {". Add the backwards slash right before the + sign on that line and it will work again. Sorry, I never caught that in the original post.
     
  5. cPDan

    cPDan cPanel Staff
    Staff Member

    Joined:
    Mar 9, 2004
    Messages:
    711
    Likes Received:
    3
    Trophy Points:
    18
    You have to escape the plus sign so its a plus sign and not a quantifier quantifying nothing.
     
  6. patrickb

    patrickb Registered

    Joined:
    Dec 8, 2003
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Yes, that is the technical explanation for it. :) I changed the original post to use CODE tags instead of the PHP tags and it now displays my original entries properly with the escape included so anyone else wanting to cut-n-paste the code can now without having to worry about the problem pointed out by shiv.
     
  7. cPDan

    cPDan cPanel Staff
    Staff Member

    Joined:
    Mar 9, 2004
    Messages:
    711
    Likes Received:
    3
    Trophy Points:
    18
    Thats fine, I'd just had a couple tickets about it and figured I'd exaplain the error :)
    Yeah, CODE is better than PHP :) PHP always causes problems!
     
  8. richy

    richy Well-Known Member

    Joined:
    Jun 30, 2003
    Messages:
    276
    Likes Received:
    1
    Trophy Points:
    16
Loading...

Share This Page