[imp] IMAP Quota Redhat 7.3 extra code

Arie Kraak maillists@obdnwh.nl
Sun, 2 Jun 2002 08:38:27 +0200


This is a multi-part message in MIME format.

---------------------- multipart/related attachment

------=_NextPart_001_013A_01C20A10.DE01A740
I changed the code a bit,

Here's the result.



// See the 'imp_show_quota' function below for an example.
$conf['hooks']['quota'] =3D 'imp_show_quota';

/* Gets the quota usage for a user.  */
/* This requires a modified "quota" command that allows the httpd server =
*/
/* account to get quotas for other users...  It also requires that your  =
*/
/* web server and imap server be the same server or at least have shared =
*/
/* authentication and file servers (e.g. via NIS/NFS)                    =
*/
if (!function_exists('imp_show_quota')) {
   function imp_show_quota ($imp) {
        $imap_admin =3D $imp['user'];
        $passwd_array =3D posix_getpwnam($imap_admin);
        $homedir =3D split("/", $passwd_array['dir']);
        $realname =3D split(",", $passwd_array['gecos']);

        $quota_html =3D '<table width=3D"100%" border=3D"0" =
cellpadding=3D"0" cellspacing=3D"0"><tr><td class=3D"item"><table =
border=3D"0" cellspacing=3D"0" cellpadding=3D"0" width=3D"100%"><tr>';
        $quota_html .=3D '<td align=3D"left" class=3D"header">Login: ' . =
$realname[0] . " (" . $imap_admin . ")" . '</td>';

        $junk =3D exec("sudo /usr/bin/quota -u $imap_admin | grep =
/dev/md1",
                     $quota_data,$return_code);
        if ($return_code =3D=3D 0 && count($quota_data) =3D=3D 1) {
           $splitted =3D split("[[:blank:]]+", trim($quota_data[0]));
           $taken =3D $splitted[1] / 1000 ; $total =3D $splitted[2] / =
1000 ;
           $percent =3D $taken * 100 / $total ;
           if ($percent >=3D 90) {
               $color =3D '#FF0000';
           } elseif ($percent >=3D 80) {
               $color =3D '#FCE30D';
           } else {
               $color =3D '#339933';
           }
           $quota_html .=3D '<td align=3D"center" class=3D"header">';
           $quota_html .=3D sprintf("<font size=3D-2>Quota on /%s: =
%.1fMB/%.1fMB (%.1f%%)</font>", $homedir[1], $taken, $total, $percent);
        } else {
            $quota_html .=3D '<td align=3D"center" class=3D"header">';
            $quota_html .=3D "Quota not available";
        }
        $quota_html .=3D '</td><td width=3D"30" class=3D"header" =
align=3D"right"><font size=3D"-3">0%</font></td><td width=3D"200" =
class=3D"header">';
        $quota_html .=3D '<table width=3D"100%"><tr><td =
bgcolor=3D"#ccccff"><div style=3D"height:6px; width:'. sprintf("%.1f%%", =
$percent). '; font-size:3px; background-color:'.$color.'">';
        $quota_html .=3D '</div></td></tr></table></td><td width=3D"30" =
class=3D"header" align=3D"left"><font =
size=3D"-3">100%</font></td></tr></table></td></tr></table>';
        return $quota_html;
    }
}

=20
Arie Kraak jr.

------=_NextPart_001_013A_01C20A10.DE01A740
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>I changed&nbsp;the code a =
bit,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here's the result.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><IMG align=3Dbaseline alt=3D"" border=3D0 hspace=3D0=20
src=3D"cid:013801c20a00$1a75ca00$4101a8c0@laptoparie"></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>// See the 'imp_show_quota' function =
below for an=20
example.<BR>$conf['hooks']['quota'] =3D 'imp_show_quota';</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>/* Gets the quota usage for a =
user.&nbsp; */<BR>/*=20
This requires a modified "quota" command that allows the httpd server =
*/<BR>/*=20
account to get quotas for other users...&nbsp; It also requires that =
your&nbsp;=20
*/<BR>/* web server and imap server be the same server or at least have =
shared=20
*/<BR>/* authentication and file servers (e.g. via=20
NIS/NFS)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
*/<BR>if (!function_exists('imp_show_quota')) {<BR>&nbsp;&nbsp; function =

imp_show_quota ($imp) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$imap_admin =3D =
$imp['user'];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$passwd_array =3D=20
posix_getpwnam($imap_admin);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
$homedir =3D split("/",=20
$passwd_array['dir']);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
$realname =3D=20
split(",", $passwd_array['gecos']);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$quota_html =3D '&lt;table width=3D"100%" border=3D"0" cellpadding=3D"0" =

cellspacing=3D"0"&gt;&lt;tr&gt;&lt;td class=3D"item"&gt;&lt;table =
border=3D"0"=20
cellspacing=3D"0" cellpadding=3D"0"=20
width=3D"100%"&gt;&lt;tr&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
$quota_html .=3D '&lt;td align=3D"left" class=3D"header"&gt;Login: ' . =
$realname[0] .=20
" (" . $imap_admin . ")" . '&lt;/td&gt;';</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $junk =3D=20
exec("sudo /usr/bin/quota -u $imap_admin | grep=20
/dev/md1",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$quota_data,$return_code);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
if=20
($return_code =3D=3D 0 &amp;&amp; count($quota_data) =3D=3D 1)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
$splitted =3D=20
split("[[:blank:]]+",=20
trim($quota_data[0]));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
$taken =3D $splitted[1] / 1000 ; $total =3D $splitted[2] / 1000=20
;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
$percent =3D=20
$taken * 100 / $total=20
;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if =
($percent=20
&gt;=3D 90)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
$color =3D=20
'#FF0000';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; }=20
elseif ($percent &gt;=3D 80)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
$color =3D=20
'#FCE30D';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; }=20
else=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
$color =3D=20
'#339933';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
$quota_html .=3D=20
'&lt;td align=3D"center"=20
class=3D"header"&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
$quota_html .=3D sprintf("&lt;font size=3D-2&gt;Quota on /%s: =
%.1fMB/%.1fMB=20
(%.1f%%)&lt;/font&gt;", $homedir[1], $taken, $total,=20
$percent);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$quota_html .=3D '&lt;td align=3D"center"=20
class=3D"header"&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;=20
$quota_html .=3D "Quota not=20
available";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $quota_html .=3D=20
'&lt;/td&gt;&lt;td width=3D"30" class=3D"header" =
align=3D"right"&gt;&lt;font=20
size=3D"-3"&gt;0%&lt;/font&gt;&lt;/td&gt;&lt;td width=3D"200"=20
class=3D"header"&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
$quota_html=20
.=3D '&lt;table width=3D"100%"&gt;&lt;tr&gt;&lt;td =
bgcolor=3D"#ccccff"&gt;&lt;div=20
style=3D"height:6px; width:'. sprintf("%.1f%%", $percent). '; =
font-size:3px;=20
background-color:'.$color.'"&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;=20
$quota_html .=3D=20
'&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;td =
width=3D"30"=20
class=3D"header" align=3D"left"&gt;&lt;font=20
size=3D"-3"&gt;100%&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/=
td&gt;&lt;/tr&gt;&lt;/table&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
return $quota_html;<BR>&nbsp;&nbsp;&nbsp; }<BR>}<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV></FONT>
<DIV><FONT face=3DArial size=3D2>Arie Kraak=20
jr.</DIV></FONT></FONT></DIV></BODY></HTML>

------=_NextPart_001_013A_01C20A10.DE01A740--

---------------------- multipart/related attachment
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 7664 bytes
Desc: not available
Url : http://lists.horde.org/archives/imp/attachments/59973542/attachment.gif

---------------------- multipart/related attachment--