[imp] Fwd: [PHP-DEV] IMAP quota functionality

tomc@teamics.com tomc@teamics.com
Tue, 23 Jul 2002 08:54:08 -0500


I took a different approach entirely.  Because we have 15000 users, the
prospect of near real time quota reporting seemed risky from a performance
standpoint.  We also have separate http and imap servers, so the latency
associated with retrieving quota information in real time could be
problematic.

What I decided to do was generate a quota report every 15 minutes to a flat
file.  Then use an awk command to retrieve the user's quota info from the
file.

It takes 3 minutes to regenerate the file, (but we're not in a hurry):

    nice -n -19 /usr/sbin/repquota /mailusers > /var/q/qinfo


Then the code in imp/conf.php has an awk statement based on $imp['user'] :

if (!function_exists('imp_show_quota')) {
    function imp_show_quota ($imp) {
         $user=$imp['user'];
         $command="/bin/awk '$1 == \"".$user."\"' /var/tmp/quota.info";
         $junk = exec($command,$quota_data, $return_code);
         if ($return_code == 0 && count($quota_data) == 1) {
             $fields = split("[[:blank:]]+", trim($quota_data[0]));
             $taken   = $fields[2] / 1000.0;
             $total   = $fields[4] / 1000.0;
             $percent = $taken * 100 / $total;
             if ($percent >= 90) {
                 $class = 'quotaalert';
                 } elseif ($percent >= 75) {
                 $class = 'quotawarn';
                 } else {
                 $class = 'control';
                 }
             $quota_html = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td class="item">'
                           . '<table border="0" cellspacing="2" cellpadding="2"
width="100%"><tr><td align="center" class="' . $class . '">'
                           . sprintf("%.2fMB / %.2fMB  (%.2f%%)", $taken, $total, $percent)
                           . '</td></tr></table></td></tr></table>';
         return $quota_html;
         }
     }
 }




tc


Zitat von Michael Cochrane <mike@graftonhall.co.nz>:

> On another quota related issue... i'm currently creating and Quota API
> for IMP
> with courier, cyrus and mdaemon implementations for retrieving the quota.
> This
> will allow the quota source to be defined in servers.php where it should
> be.
> thinking something like:

[snip]

> The current hook is only really practical if you only have one mail
> server to
> worry about. else if gets really messy when you want quotas from multiple
> mail
> servers running different software.
>
> Interest, comments, suggestions welcomed.

That makes sense and the approach looks good.

Jan.

--