#1  
Old 9th October 2006, 04:29
jmroth jmroth is offline
ISPConfig Developer
 
Join Date: Sep 2005
Posts: 191
Thanks: 1
Thanked 6 Times in 6 Posts
Default quota on maildirs :)

Hi there,
I have now developed another procmail script to be used for processing quotas on mail delivery (works with my MailDIRS)

Code:
DROPPRIVS=YES

## using repquota will not work because normal users must not use it
PATH="/usr/bin:$PATH:/usr/local/bin"
SHELL=/bin/sh
EMAIL=`formail -zxTo:`

QUOTA=`mailquotacheck.sh`
:0
* > ${QUOTA}
{
        LOG="THIS USER/DOMAIN IS FULL. PLEASE TRY AGAIN AT A LATER TIME!"
        EXITCODE=69
        HOST
}
#end
I put the mailquotacheck.sh script into /usr/local/bin and this is it:
Code:
#!/bin/bash

QUOTA=10000000000 #10GB

GROUP_QUOTA_ENABLED=0
quota -g | grep -q ": none" || GROUP_QUOTA_ENABLED=1
if [ $GROUP_QUOTA_ENABLED -eq 1 ]; then
        FS_GROUP_QUOTA=`quota -g | sed -n 3p | awk '{print $3}'`*1024
        FS_GROUP_QUOTA=$(($FS_GROUP_QUOTA))
        FS_GROUP_QUOTA_USED=`quota -g | sed -n 3p | awk '{print $2}' | sed -n 's/^\([0-9]*\).*$/\1/g p'`*1024
        FS_GROUP_QUOTA_USED=$(($FS_GROUP_QUOTA_USED))
        FS_GROUP_QUOTA_FREE=$(($FS_GROUP_QUOTA-$FS_GROUP_QUOTA_USED))
else
        FS_GROUP_QUOTA=0
fi

USER_QUOTA_ENABLED=0
quota -u | grep -q ": none" || USER_QUOTA_ENABLED=1
if [ $USER_QUOTA_ENABLED -eq 1 ]; then
        FS_USER_QUOTA=`quota -u | sed -n 3p | awk '{print $2}'`*1024
        FS_USER_QUOTA=$(($FS_USER_QUOTA))
        FS_USER_QUOTA_USED=`quota -u | awk '{print $2}' | sed -n 's/^\([0-9]*\).*$/\1/g p'`*1024
        FS_USER_QUOTA_USED=$(($FS_USER_QUOTA_USED))
        FS_USER_QUOTA_FREE=$((FS_USER_QUOTA-$FS_USER_QUOTA_USED)) 
else
        FS_USER_QUOTA=0
fi

if [ $FS_USER_QUOTA == 0 ]; then
        if [ $FS_GROUP_QUOTA != 0 ]; then
        # we have unlimtied user filesystem quota but the group is limited
                if [ $FS_GROUP_QUOTA_FREE -lt $QUOTA ]; then
                        QUOTA=$FS_GROUP_QUOTA_FREE
                else
                        QUOTA=$QUOTA
                fi
        else
        # unlimited user and group quota
                QUOTA=$QUOTA
        fi
else
# the minimum of user and group quotas counts
        if [ $FS_USER_QUOTA_FREE -lt $FS_GROUP_QUOTA_FREE ]; then
                QUOTA=$FS_USER_QUOTA_FREE
        else
                QUOTA=$FS_GROUP_QUOTA_FREE
        fi
fi

echo $QUOTA
Have phun. Regards,
Marc
Reply With Quote
Sponsored Links
  #2  
Old 10th October 2006, 13:30
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,740 Times in 2,575 Posts
Default

Does it check if the current mailbox + the new message is greater than the quota value, or just if the new message is greater than the quota value?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 10th October 2006, 21:19
jmroth jmroth is offline
ISPConfig Developer
 
Join Date: Sep 2005
Posts: 191
Thanks: 1
Thanked 6 Times in 6 Posts
Default

Actually the shell script will output how much space is _available_ to either user or group the user is a member of, whatever is the least. (Large group quota will help nothing if the user is f.e. already over quota)
Then, the procmail script will compare the message size to that value.
The problem I saw many times in the forums was that *1024-error. Mainly that is due to the "quota" command appending an * to the value it outputs in case the user is over quota. The regexp in the script removes this superfluous *, so the math can be done correctly.
The main reason I tried to implement this is so that the senders get more verbose messages back than "can't create user output file", which to most people means nothing. Here you can define the LOG="..." string in the procmail recipe as you like. (From what I have seen this only works if logging is not enabled in the procmail file.)
Regards,
Marc
Reply With Quote
  #4  
Old 11th October 2006, 10:05
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 35,788
Thanks: 821
Thanked 5,337 Times in 4,187 Posts
Default

Looks promising. I will try to implement this in the dev tree.

Maybe we can provide the QUOTA value to the shell script as commandline parameter, so we dont have to make a bash script for every user with different quota values.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #5  
Old 11th October 2006, 16:28
jmroth jmroth is offline
ISPConfig Developer
 
Join Date: Sep 2005
Posts: 191
Thanks: 1
Thanked 6 Times in 6 Posts
 
Default

Why make a script for every user with different quota values?
The QUOTA=10GB at the beginning is only there as a fallback, so noone can ever be sent a message larger than 10 GB. I took this somewhere from the old scripts. One could just remove that altogether. The actual quota of the user/group is of course given to the script via the quota command. (FS_GROUP_QUOTA=`quota -g | sed -n 3p | awk '{print $3}'`*1024 ...)
Regards,
Marc
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with copy & paste dspuser Server Operation 3 23rd May 2006 17:21
quota WARNING during configuration badgerbox76 Installation/Configuration 2 18th March 2006 11:12
Perfect Installation Fedora Core 4 cybereatl Installation/Configuration 30 8th March 2006 04:42
Syntax error in Quota? st2xo Installation/Configuration 2 13th February 2006 11:30
another quota question... Ovidiu General 9 21st December 2005 01:08


All times are GMT +2. The time now is 16:30.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.