Menu

Quota update and notification

2011-08-31
2013-01-23
  • Rhys McWilliams

    Rhys McWilliams - 2011-08-31

    I decided I wanted Postfix to deliver the mail to the users mailbox and not Dovecot.
    This of course prevents dovecot from updating the quota table in Postfixadmin (which I had some trouble getting Dovecot to do anyway).

    I've written a script that updates the quota table in Postfixadmin & you run from cron whenever you feel it's necessary, I only run it every hour on my server as it's only serving 6 domain & 87 accounts & I don't need up-to-the-minute updates.

    The main reason for writing this script is that I feel it's only fair to notify users when they're approaching their quota limits & I couldn't find anything mentioned that Postfixadmin already did this.

    This script can also send notices at defined levels of quota usage to the user informing them of the level used.
    Two columns are added to the quota table to keep track of notices.
    You can define the subject and body of the notice to send, see the "## EDIT these variables" section.
    The notices are sent as postmaster from the users own domain.
    Notice are not sent to user that are over their quota or that are not active in the Postfixadmin database as the notice e-mails would just bounce…

    The database details (name, user, passwd etc) are retrieved from the PostfixAdmin config files so no need to specify them in the script.

    The script also has an option to clean the quota table to remove entries of users that have been removed from the Postfixadmin database.

    You can also run the script from the command line to see quota info for a user, domain or all domains.
    Put the script into the path somewhere (e.g. /usr/bin) and run

    pfadmin-quota.pl  --help
    

    to get the perldoc help info in the script that gives the details on how to implement it etc.
    If your perl is not in /usr/bin/perl then you'll need to edit line 1 and correct the path to perl on your box.
    Edit the script in your favourite editor and look for the "## EDIT these variables" section and edit the relevant variables to suite your Postfix & Postfixadmin installation.
    You can also edit the notification message that is sent to the users, all within that "## EDIT these variables" section.

    Please not that I have only run it with the Postfixadmin database in mysql so I don't know yet if it will work with postgresql.

    This is pretty much my first perl script, I mainly used bash scripting up 'till now, so I'm sure it could be better. I wrote it for my purposes but have decided to post it here as there just may be someone else who could use it…
    I welcome any suggestions (and even criticisms) to potentially improve it…

    You can download it from here: http://www.castlehillcc.co.za/downloads/pfadmin-quota.pl.tgz
    The download file is a tar gzip so once downloaded run

    tar  -xvzf  pfadmin-quota.pl.tgz
    

    to extract the pfadmin-quota.pl script itself.

     
  • Rhys McWilliams

    Rhys McWilliams - 2011-09-01

    I've made a minor change to allow those that still want to use their own method (dovecot etc) to update the quota table to still be able to use this script to send notifications.

    My initial release directly calculated the size of the maildir folders all the relevant routines, this was mainly done to have the current size when checking whether or not to send a notification.
    I've now changed the routines (except the -update routine) to rather fetch the users quota size from the quota table so you can still use your method to update the quota table.

    If you are planning on using this script the way I do (to update the quota table) then I'd recommend running a -update in cron just before you run the -notify option to make sure your quota tables are up to date.

     

Log in to post a comment.