Author Topic: Fix Qouta Usage for Cpanel  (Read 8244 times)

Offline paonza

  • Newbie
  • *
  • Posts: 5
Fix Qouta Usage for Cpanel
« on: November 02, 2006, 08:21:44 PM »
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:
Code: [Select]
function rcmail_quota_display($attrib)3) replace this function with the new one plus two other support function
Code: [Select]
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
Code: [Select]
: from
Code: [Select]
6) paste as last element into
Code: [Select]

I think that's all!
Let me know!

Fabio ;)



Offline socksbb

  • Newbie
  • *
  • Posts: 8
Re: Fix Qouta Usage for Cpanel
« Reply #1 on: November 13, 2006, 01:12:13 PM »
or.. you can upgrade the the latest cpanel. They have switched to a new IMAP server that supports quotas correctly with RC.

Reload

  • Guest
Re: Fix Qouta Usage for Cpanel
« Reply #2 on: November 14, 2006, 03:51:23 AM »
What version do you mean ?
My ISP is running version: 10.9.0-STABLE 35 without quota support.... :-\

Offline paonza

  • Newbie
  • *
  • Posts: 5
Re: Fix Qouta Usage for Cpanel
« Reply #3 on: November 19, 2006, 06:50:20 PM »
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
Code: [Select]
su -l root -c &quot;chmod 666 /etc/userdomains&quot;
su -l root -c &quot;cp /etc/userdomains /etc/rcscript&quot;
su -l root -c &quot;chmod 666 /etc/rcdomains&quot;
su -l root -c &quot;chmod 660 /etc/userdomains&quot;

then I add to etc/crontab the following line:
Code: [Select]
30 0 * * * root /etc/rcscript
last, remember to change into program/steps/mail/func.ini
replace:
Code: [Select]
$file = file("/etc/userdomains"); //this file must have 664 permissionswith:
Code: [Select]
$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

Offline brockster

  • Newbie
  • *
  • Posts: 1
Re: Fix Qouta Usage for Cpanel
« Reply #4 on: November 28, 2006, 08:30:55 PM »
Worked perfectly for me. Thanks.