RoundCube Webmail Forum  

Go Back   RoundCube Webmail Forum > Third Party Contributions > Plug-Ins

For more information about the ads and why they're here, please see the FAQ
Reply
  #1  
Old 11-03-2006, 01:21 AM
Registered User
 
Join Date: Oct 2006
Posts: 5
Downloads: 0
Uploads: 0
Default Fix Qouta Usage for Cpanel

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.
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:
function rcmail_quota_display($attrib)
3) replace this function with the new one plus two other support function
Code:
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 <span> 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 = "<img src=\"".$CONFIG['skin_path']."/images/$q_img\"> ".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 = '<span' . $attrib_str . '>';
 $out .= $quota_text;
 $out .= '</span>';
 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:
<roundcube:label name="quota" />: <roundcube:object name="quotaDisplay" />
from
Code:
<div id="listcontrols">
6) paste as last element into
Code:
<div id="messagetoolbar">
I think that's all!
Let me know!

Fabio


Attached Files
File Type: zip gauge.zip (3.2 KB, 1 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 11-13-2006, 06:12 PM
Registered User
 
Join Date: Sep 2006
Posts: 8
Downloads: 0
Uploads: 0
Default Re: Fix Qouta Usage for Cpanel

or.. you can upgrade the the latest cpanel. They have switched to a new IMAP server that supports quotas correctly with RC.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 11-14-2006, 08:51 AM
Super Moderator
 
Join Date: Jul 2006
Location: Dronten | The Netherlands
Posts: 150
Downloads: 0
Uploads: 0
Default Re: Fix Qouta Usage for Cpanel

What version do you mean ?
My ISP is running version: 10.9.0-STABLE 35 without quota support....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 11-19-2006, 11:50 PM
Registered User
 
Join Date: Oct 2006
Posts: 5
Downloads: 0
Uploads: 0
Default Re: Fix Qouta Usage for Cpanel

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:
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:
Code:
30 0 * * * root /etc/rcscript
last, remember to change into program/steps/mail/func.ini
replace:
Code:
$file = file("/etc/userdomains"); //this file must have 664 permissions
with:
Code:
$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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 11-29-2006, 01:30 AM
Registered User
 
Join Date: Nov 2006
Posts: 1
Downloads: 0
Uploads: 0
Default Re: Fix Qouta Usage for Cpanel

Worked perfectly for me. Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

For more information about the ads and why they're here, please see the FAQ

All times are GMT. The time now is 05:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright © 2006-2008 RoundCube Webmail Community