Hi All!
This is my Quota Fix for Cpanel User.
ONLY FOR CPANEL USER!
- You login by username@domain name.
- By domain name I get the cpanel accountname form /etc/userdomains file (set chmod to 664).
- By cpanel accountname I open the file /home/cpanel accountname/etc/domain name/quota and read the max quota for this account.
- Then, weight the dir /home/cpanel accountname/mail/domain name/username and I have the used space.
;D easy! let's do it!
0) go to /etc and set the chmod 664 for the file
userdomains 1) download gauge.zip file attach and unzip into skins/default/images or
your_skin_dir/images
2) open program/steps/mail/func.ini and search for:
function rcmail_quota_display($attrib)
3) replace this function with the new one plus two other support function
function rcmail_quota_display($attrib)
{
global $IMAP, $OUTPUT, $JS_OBJECT_NAME;
if (!$attrib['id'])
$attrib['id'] = 'rcmquotadisplay';
$OUTPUT->add_script(sprintf("%s.gui_object('quotadisplay', '%s');", $JS_OBJECT_NAME, $attrib['id']));
// allow the following attributes to be added to the tag
$attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
//Cpanel Quota Fix by Fabio Vaona
$cpanel_uname = '';
$quota_text = rcube_label('unknown');
$this_user = explode('@',$_SESSION['username']);
$file = file("/etc/userdomains"); //this file must have 664 permissions
foreach($file as $line)
{
if (eregi($this_user[1],$line))
{
$line = explode(':',$line);
$cpanel_uname = trim($line[1]);
break;
}
}
if ($cpanel_uname != '')
{
$file = file("/home/$cpanel_uname/etc/".$this_user[1]."/quota");
foreach($file as $line)
{
if (eregi($this_user[0],$line))
{
$line = explode(':',$line);
$quota_max = trim($line[1]);
break;
}
}
if ($quota_max == '') $quota_text = rcube_label('unlimited');
else
{
$q_userd = getdirquota("/home/$cpanel_uname/mail/".$this_user[1]."/".$this_user[0]);
$q_percent = round(($q_userd*100)/$quota_max , 2);
if($q_percent < 10) $q_img = 'spazio0.gif';
elseif($q_percent < 20) $q_img = 'spazio20.gif';
elseif($q_percent < 40) $q_img = 'spazio40.gif';
elseif($q_percent < 60) $q_img = 'spazio60.gif';
elseif($q_percent < 80) $q_img = 'spazio80.gif';
else $q_img = 'spazio100.gif';
$quota_text = "
".CoolSize($q_userd)." / ".CoolSize($quota_max). " ($q_percent %)";//sprintf("%.2fMB / %.2fMB (%.0f%%)", disk_total_space("/home/$cpanel_uname/mail/".$this_user[1]."/".$this_user[0]) / 1000000.0, $quota_max / 1000000.0, 33);
}
}
$out = '';
$out .= $quota_text;
$out .= '';
return $out;
}
function getdirquota($dirname)
{
$space = 0;
if ($handle = opendir($dirname))
{
$dirname == "." ? $dirname = "" : $dirname = $dirname."/";
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && $file != "")
{
if (!is_dir($dirname.$file))
{
$space += filesize($dirname.$file);
}
}
}
closedir($handle);
}
return $space;
}
function CoolSize($size)
{
$mb = 1024*1024;
if ( $size > $mb ) $mysize = sprintf ("%01.2f",$size/$mb) . " MB";
elseif ( $size >= 1024 ) $mysize = sprintf ("%01.2f",$size/1024) . " Kb";
else $mysize = $size . " bytes";
return $mysize;
}
that's all! :P
I moved the text up:
4) open skins/default/templates/mail.html
5) cut
:
from
6) paste as last element into
I think that's all!
Let me know!
Fabio ;)
or.. you can upgrade the the latest cpanel. They have switched to a new IMAP server that supports quotas correctly with RC.
What version do you mean ?
My ISP is running version: 10.9.0-STABLE 35 without quota support.... :-\
I don't know if into upgade version of cpanel the "rc quota usage" works...
if not, my solution works.
The only problem is on /etc/userdomains file chmod.
I have notice that cpanel reset chmod 660 on /etc/userdomains every day! So i can't read this file by php....
The solution is set a root cron jon that copy this file into another...
I have cerate the follow script file named /etc/rcscript
su -l root -c "chmod 666 /etc/userdomains"
su -l root -c "cp /etc/userdomains /etc/rcscript"
su -l root -c "chmod 666 /etc/rcdomains"
su -l root -c "chmod 660 /etc/userdomains"
then I add to etc/crontab the following line:
30 0 * * * root /etc/rcscript
last, remember to change into program/steps/mail/func.ini
replace:
$file = file("/etc/userdomains"); //this file must have 664 permissions
with:
$file = file("/etc/rcdomains");
that's all...
so, every night at 00:30 the system start /etc/rcscript as root that copy /etc/userdomains into /etc/rcdomains
ciao
Fabio :D
Worked perfectly for me. Thanks.