[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 the code a =
bit,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Here's the result.</FONT></DIV>
<DIV> </DIV>
<DIV><IMG align=3Dbaseline alt=3D"" border=3D0 hspace=3D0=20
src=3D"cid:013801c20a00$1a75ca00$4101a8c0@laptoparie"></DIV>
<DIV> </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> </DIV>
<DIV><FONT face=3DArial size=3D2>/* Gets the quota usage for a =
user. */<BR>/*=20
This requires a modified "quota" command that allows the httpd server =
*/<BR>/*=20
account to get quotas for other users... It also requires that =
your =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)  =
; =20
*/<BR>if (!function_exists('imp_show_quota')) {<BR> function =
imp_show_quota ($imp) {<BR> =20
$imap_admin =3D =
$imp['user'];<BR> =20
$passwd_array =3D=20
posix_getpwnam($imap_admin);<BR>  =
;=20
$homedir =3D split("/",=20
$passwd_array['dir']);<BR> =
$realname =3D=20
split(",", $passwd_array['gecos']);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2> =20
$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"=20
cellspacing=3D"0" cellpadding=3D"0"=20
width=3D"100%"><tr>';<BR> &nb=
sp;=20
$quota_html .=3D '<td align=3D"left" class=3D"header">Login: ' . =
$realname[0] .=20
" (" . $imap_admin . ")" . '</td>';</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial =
size=3D2> $junk =3D=20
exec("sudo /usr/bin/quota -u $imap_admin | grep=20
/dev/md1",<BR>  =
; =20
$quota_data,$return_code);<BR> =
if=20
($return_code =3D=3D 0 && count($quota_data) =3D=3D 1)=20
{<BR> =
$splitted =3D=20
split("[[:blank:]]+",=20
trim($quota_data[0]));<BR>  =
; =20
$taken =3D $splitted[1] / 1000 ; $total =3D $splitted[2] / 1000=20
;<BR> =
$percent =3D=20
$taken * 100 / $total=20
;<BR> if =
($percent=20
>=3D 90)=20
{<BR> &n=
bsp; =20
$color =3D=20
'#FF0000';<BR>  =
; }=20
elseif ($percent >=3D 80)=20
{<BR> &n=
bsp; =20
$color =3D=20
'#FCE30D';<BR>  =
; }=20
else=20
{<BR> &n=
bsp; =20
$color =3D=20
'#339933';<BR>  =
;=20
}<BR> =
$quota_html .=3D=20
'<td align=3D"center"=20
class=3D"header">';<BR>  =
; =20
$quota_html .=3D sprintf("<font size=3D-2>Quota on /%s: =
%.1fMB/%.1fMB=20
(%.1f%%)</font>", $homedir[1], $taken, $total,=20
$percent);<BR> } else=20
{<BR> =20
$quota_html .=3D '<td align=3D"center"=20
class=3D"header">';<BR>  =
; =20
$quota_html .=3D "Quota not=20
available";<BR> =20
}<BR> $quota_html .=3D=20
'</td><td width=3D"30" class=3D"header" =
align=3D"right"><font=20
size=3D"-3">0%</font></td><td width=3D"200"=20
class=3D"header">';<BR> =
$quota_html=20
.=3D '<table width=3D"100%"><tr><td =
bgcolor=3D"#ccccff"><div=20
style=3D"height:6px; width:'. sprintf("%.1f%%", $percent). '; =
font-size:3px;=20
background-color:'.$color.'">';<BR>  =
; =20
$quota_html .=3D=20
'</div></td></tr></table></td><td =
width=3D"30"=20
class=3D"header" align=3D"left"><font=20
size=3D"-3">100%</font></td></tr></table></=
td></tr></table>';<BR> =
=20
return $quota_html;<BR> }<BR>}<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> </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--