[imp] IMAP Quota Redhat 7.3 extra code
Hanser, Kevin
kevin@merchantinternetgroup.com
Mon, 3 Jun 2002 20:17:23 -0400
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
---------------------- multipart/mixed attachment
------_=_NextPart_001_01C20B5D.3300F500
I just tried this code on my IMP installation, and I'm getting a weird
error..
The bar shows, but it's all light blue (none filled), and I get a message of
"Quota not available" instead of "quota on ..."
Also, I'm receiving these errors @ the top (above the quota bar):
Warning: Undefined variable: percent in
/var/www/vhosts/webmail/horde/imp/config/conf.php on line 412
Warning: Undefined variable: color in
/var/www/vhosts/webmail/horde/imp/config/conf.php on line 412
Here's the code I put in imp/config/conf.php:
if (!function_exists('imp_show_quota')) {
function imp_show_quota ($imp) {
$imap_admin = $imp['user'];
$passwd_array = posix_getpwnam($imap_admin);
$homedir = split("/", $passwd_array['dir']);
$realname = split(",", $passwd_array['gecos']);
$quota_html = '<table width="100%" border="0" cellpadding="0"
cellspacing="0"><tr><td class="item"><table border="0" cellspacing="0"
cellpadding="0" width="100%"><tr>';
$quota_html .= '<td align="left" class="header">Login: ' .
$realname[0] . " (" . $imap_admin . ")" . '</td>';
$junk = exec("sudo /usr/bin/quota -u $imap_admin | grep /dev/hda2",
$quota_data,$return_code);
if ($return_code == 0 && count($quota_data) == 1) {
$splitted = split("[[:blank:]]+", trim($quota_data[0]));
$taken = $splitted[1] / 1000 ; $total = $splitted[2] / 1000 ;
$percent = $taken * 100 / $total ;
if ($percent >= 90) {
$color = '#FF0000';
} elseif ($percent >= 80) {
$color = '#FCE30D';
} else {
$color = '#339933';
}
$quota_html .= '<td align="center" class="header">';
$quota_html .= sprintf("<font size=-2>Quota on /%s: %.1fMB/%.1fMB
(%.1f%%)</font>", $homedir[1], $taken, $total, $percent);
} else {
$quota_html .= '<td align="center" class="header">';
$quota_html .= "Quota not available";
}
$quota_html .= '</td><td width="30" class="header"
align="right"><font size="-3">0%</font></td><td width="200"
class="header">';
$quota_html .= '<table width="100%"><tr><td bgcolor="#ccccff"><div
style="height:6px; width:'. sprintf("%.1f%%", $percent). '; font-size:3px;
background-color:'.$color.'">';
$quota_html .= '</div></td></tr></table></td><td width="30"
class="header" align="left"><font
size="-3">100%</font></td></tr></table></td></tr></table>';
return $quota_html;
}
}
Any help would be appreciated. The screenshots of this look great, I can't
wait to get it working on my system :)
k
-----Original Message-----
From: Arie Kraak [mailto:maillists@obdnwh.nl]
Sent: Sunday, June 02, 2002 02:38
To: imp@lists.horde.org
Subject: [imp] IMAP Quota Redhat 7.3 extra code
I changed the code a bit,
Here's the result.
// See the 'imp_show_quota' function below for an example.
$conf['hooks']['quota'] = '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 = $imp['user'];
$passwd_array = posix_getpwnam($imap_admin);
$homedir = split("/", $passwd_array['dir']);
$realname = split(",", $passwd_array['gecos']);
$quota_html = '<table width="100%" border="0" cellpadding="0"
cellspacing="0"><tr><td class="item"><table border="0" cellspacing="0"
cellpadding="0" width="100%"><tr>';
$quota_html .= '<td align="left" class="header">Login: ' .
$realname[0] . " (" . $imap_admin . ")" . '</td>';
$junk = exec("sudo /usr/bin/quota -u $imap_admin | grep /dev/md1",
$quota_data,$return_code);
if ($return_code == 0 && count($quota_data) == 1) {
$splitted = split("[[:blank:]]+", trim($quota_data[0]));
$taken = $splitted[1] / 1000 ; $total = $splitted[2] / 1000 ;
$percent = $taken * 100 / $total ;
if ($percent >= 90) {
$color = '#FF0000';
} elseif ($percent >= 80) {
$color = '#FCE30D';
} else {
$color = '#339933';
}
$quota_html .= '<td align="center" class="header">';
$quota_html .= sprintf("<font size=-2>Quota on /%s: %.1fMB/%.1fMB
(%.1f%%)</font>", $homedir[1], $taken, $total, $percent);
} else {
$quota_html .= '<td align="center" class="header">';
$quota_html .= "Quota not available";
}
$quota_html .= '</td><td width="30" class="header"
align="right"><font size="-3">0%</font></td><td width="200"
class="header">';
$quota_html .= '<table width="100%"><tr><td bgcolor="#ccccff"><div
style="height:6px; width:'. sprintf("%.1f%%", $percent). '; font-size:3px;
background-color:'.$color.'">';
$quota_html .= '</div></td></tr></table></td><td width="30"
class="header" align="left"><font
size="-3">100%</font></td></tr></table></td></tr></table>';
return $quota_html;
}
}
Arie Kraak jr.
------_=_NextPart_001_01C20B5D.3300F500
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2716.2200" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2>I just tried this code on my IMP installation, and I'm getting a weird
error..</FONT></SPAN></DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2>The bar shows, but it's all light blue (none filled), and I get a message
of "Quota not available" instead of "quota on ..."</FONT></SPAN></DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2>Also, I'm receiving these errors @ the top (above the quota
bar):</FONT></SPAN></DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=225121500-04062002><STRONG>Warning</STRONG>: Undefined
variable: percent in <B>/var/www/vhosts/webmail/horde/imp/config/conf.php</B> on
line <B>412</B><BR><BR><B>Warning</B>: Undefined variable: color in
<B>/var/www/vhosts/webmail/horde/imp/config/conf.php</B> on line
<B>412</B></SPAN></DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2>Here's the code I put in imp/config/conf.php:</FONT></SPAN></DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2>if (!function_exists('imp_show_quota')) {<BR> function
imp_show_quota ($imp) {<BR>
$imap_admin = $imp['user'];<BR>
$passwd_array =
posix_getpwnam($imap_admin);<BR>
$homedir = split("/",
$passwd_array['dir']);<BR> $realname =
split(",", $passwd_array['gecos']);</FONT></SPAN></DIV>
<DIV><FONT face="Century Gothic" color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2> $quota_html = '<table
width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td
class="item"><table border="0" cellspacing="0" cellpadding="0"
width="100%"><tr>';<BR>
$quota_html .= '<td align="left" class="header">Login: ' . $realname[0] .
" (" . $imap_admin . ")" . '</td>';</FONT></SPAN></DIV>
<DIV><FONT face="Century Gothic" color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2> $junk = exec("sudo
/usr/bin/quota -u $imap_admin | grep
/dev/hda2",<BR>
$quota_data,$return_code);<BR> if
($return_code == 0 && count($quota_data) == 1)
{<BR> $splitted =
split("[[:blank:]]+",
trim($quota_data[0]));<BR>
$taken = $splitted[1] / 1000 ; $total = $splitted[2] / 1000
;<BR> $percent =
$taken * 100 / $total
;<BR> if ($percent
>= 90)
{<BR>
$color =
'#FF0000';<BR> }
elseif ($percent >= 80)
{<BR>
$color =
'#FCE30D';<BR> }
else
{<BR>
$color =
'#339933';<BR>
}<BR> $quota_html .=
'<td align="center"
class="header">';<BR>
$quota_html .= sprintf("<font size=-2>Quota on /%s: %.1fMB/%.1fMB
(%.1f%%)</font>", $homedir[1], $taken, $total,
$percent);<BR> } else
{<BR>
$quota_html .= '<td align="center"
class="header">';<BR>
$quota_html .= "Quota not
available";<BR>
}<BR> $quota_html .=
'</td><td width="30" class="header" align="right"><font
size="-3">0%</font></td><td width="200"
class="header">';<BR> $quota_html
.= '<table width="100%"><tr><td bgcolor="#ccccff"><div
style="height:6px; width:'. sprintf("%.1f%%", $percent). '; font-size:3px;
background-color:'.$color.'">';<BR>
$quota_html .=
'</div></td></tr></table></td><td width="30"
class="header" align="left"><font
size="-3">100%</font></td></tr></table></td></tr></table>';<BR>
return $quota_html;<BR> }<BR>}</FONT></SPAN></DIV>
<DIV><FONT face="Century Gothic" color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face="Century Gothic" color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2>Any help would be appreciated. The screenshots of this look great,
I can't wait to get it working on my system :)</FONT></SPAN></DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2>k</FONT></SPAN></DIV>
<DIV><SPAN class=225121500-04062002><FONT face="Century Gothic" color=#0000ff
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Arie Kraak
[mailto:maillists@obdnwh.nl]<BR><B>Sent:</B> Sunday, June 02, 2002
02:38<BR><B>To:</B> imp@lists.horde.org<BR><B>Subject:</B> [imp] IMAP Quota
Redhat 7.3 extra code<BR><BR></FONT></DIV>
<DIV><FONT face=Arial size=2>
<DIV><FONT face=Arial size=2>I changed the code a bit,</FONT></DIV>
<DIV><FONT face="Century Gothic" color=#0000ff></FONT> </DIV>
<DIV><FONT face=Arial size=2>Here's the result.</FONT></DIV>
<DIV> </DIV>
<DIV><IMG alt="" hspace=0 src="cid:225121500@04062002-074e" align=baseline
border=0></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// See the 'imp_show_quota' function below for an
example.<BR>$conf['hooks']['quota'] = 'imp_show_quota';</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>/* Gets the quota usage for a user.
*/<BR>/* This requires a modified "quota" command that allows the httpd server
*/<BR>/* account to get quotas for other users... It also requires that
your */<BR>/* web server and imap server be the same server or at least
have shared */<BR>/* authentication and file servers (e.g. via
NIS/NFS)
*/<BR>if (!function_exists('imp_show_quota')) {<BR> function
imp_show_quota ($imp) {<BR>
$imap_admin = $imp['user'];<BR>
$passwd_array =
posix_getpwnam($imap_admin);<BR>
$homedir = split("/",
$passwd_array['dir']);<BR> $realname
= split(",", $passwd_array['gecos']);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>
$quota_html = '<table width="100%" border="0" cellpadding="0"
cellspacing="0"><tr><td class="item"><table border="0"
cellspacing="0" cellpadding="0"
width="100%"><tr>';<BR>
$quota_html .= '<td align="left" class="header">Login: ' . $realname[0]
. " (" . $imap_admin . ")" . '</td>';</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> $junk
= exec("sudo /usr/bin/quota -u $imap_admin | grep
/dev/md1",<BR>
$quota_data,$return_code);<BR> if
($return_code == 0 && count($quota_data) == 1)
{<BR> $splitted =
split("[[:blank:]]+",
trim($quota_data[0]));<BR>
$taken = $splitted[1] / 1000 ; $total = $splitted[2] / 1000
;<BR> $percent =
$taken * 100 / $total
;<BR> if ($percent
>= 90)
{<BR>
$color =
'#FF0000';<BR> }
elseif ($percent >= 80)
{<BR>
$color =
'#FCE30D';<BR> }
else
{<BR>
$color =
'#339933';<BR>
}<BR> $quota_html
.= '<td align="center"
class="header">';<BR>
$quota_html .= sprintf("<font size=-2>Quota on /%s: %.1fMB/%.1fMB
(%.1f%%)</font>", $homedir[1], $taken, $total,
$percent);<BR> } else
{<BR>
$quota_html .= '<td align="center"
class="header">';<BR>
$quota_html .= "Quota not
available";<BR>
}<BR> $quota_html .=
'</td><td width="30" class="header" align="right"><font
size="-3">0%</font></td><td width="200"
class="header">';<BR> $quota_html
.= '<table width="100%"><tr><td bgcolor="#ccccff"><div
style="height:6px; width:'. sprintf("%.1f%%", $percent). '; font-size:3px;
background-color:'.$color.'">';<BR>
$quota_html .=
'</div></td></tr></table></td><td width="30"
class="header" align="left"><font
size="-3">100%</font></td></tr></table></td></tr></table>';<BR>
return $quota_html;<BR> }<BR>}<BR></FONT></DIV>
<DIV><FONT face=Arial size=2> </DIV></FONT>
<DIV><FONT face=Arial size=2>Arie Kraak
jr.</DIV></FONT></FONT></DIV></BLOCKQUOTE></BODY></HTML>
------_=_NextPart_001_01C20B5D.3300F500--
---------------------- multipart/mixed attachment
A non-text attachment was scrubbed...
Name: imp_quota_screenshot.gif
Type: image/gif
Size: 7664 bytes
Desc: not available
Url : http://lists.horde.org/archives/imp/attachments/4bb660a1/imp_quota_screenshot.gif
---------------------- multipart/mixed attachment--