[imp] IMAP Quota Redhat 7.3 extra code UPDATED

Arie Kraak maillists@obdnwh.nl
Tue, 4 Jun 2002 20:08:29 +0200


This is a multi-part message in MIME format.

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

------=_NextPart_001_0038_01C20C03.9854E190
Hi there,

Here's the updated code. I didn't tested the first time. But this code =
wil work.
It wil return;


and if quota's dont work it wil return.
Quota not available

Arie Kraak jr.


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);
           $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>';
        } else {
            $quota_html .=3D '<td align=3D"center" class=3D"header">';
            $quota_html .=3D "Quota not available";
        }
        $quota_html .=3D '</td></tr></table></td></tr></table>';
        return $quota_html;
    }
}


------=_NextPart_001_0038_01C20C03.9854E190
<!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>
<DIV><FONT face=3DArial size=3D2>Hi there,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here's the updated code. I didn't =
tested the first=20
time. But this code wil work.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>It wil return;</FONT></DIV>
<DIV><IMG align=3Dbaseline alt=3D"" border=3D0 hspace=3D0=20
src=3D"cid:003601c20bf2$d4b9c210$4101a8c0@laptoparie"></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>and if quota's dont work it wil=20
return.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>Quota not =
available</STRONG></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Arie Kraak jr.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>if (!function_exists('imp_show_quota')) =

{<BR>&nbsp;&nbsp; function imp_show_quota ($imp)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $imap_admin =3D=20
$imp['user'];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
$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(",",=20
$passwd_array['gecos']);<BR>&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 . ")" .=20
'&lt;/td&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $junk =3D =
exec("sudo=20
/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;&nbsp;&nbsp;&nbsp=
;=20
$quota_html .=3D '&lt;/td&gt;&lt;td width=3D"30" class=3D"header"=20
align=3D"right"&gt;&lt;font =
size=3D"-3"&gt;0%&lt;/font&gt;&lt;/td&gt;&lt;td=20
width=3D"200"=20
class=3D"header"&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;=20
$quota_html .=3D '&lt;table width=3D"100%"&gt;&lt;tr&gt;&lt;td=20
bgcolor=3D"#ccccff"&gt;&lt;div style=3D"height:6px; width:'. =
sprintf("%.1f%%",=20
$percent). '; font-size:3px;=20
background-color:'.$color.'"&gt;';<BR>&nbsp;&nbsp;&nbsp;&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;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; }=20
else =
{<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;/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></BODY></HTML>

------=_NextPart_001_0038_01C20C03.9854E190--

---------------------- 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/7e39ba6f/attachment.gif

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