[imp] quota

dhottinger@harrisonburg.k12.va.us dhottinger at harrisonburg.k12.va.us
Mon Jan 29 08:01:46 PST 2007


I still havent gotten user quotas to work with horde 3.1.1, imp 4.1.3.  
  I have the following in my /imp/config/servers.php:
    'quota' => array(
     'driver' => 'command',
       'params' => array(
	'new_quota' => 'true',
          'quota_path' => '/usr/bin/quota',
           'grep_path'  => '/bin/grep'
       )
   ),
This is my imp/lib/quota/command.php:

class IMP_Quota_command extends IMP_Quota {

     /**
      * Constructor
      *
      * @access public
      *
      * @param optional array $params  Hash containing connection
parameters.
      */
     function IMP_Quota_command($params = array())
     {
         $this->_params = array(
             'quota_path' => 'quota',
             'grep_path'  => 'grep'
         );

         $this->_params = array_merge($this->_params, $params);
     }

     /**
      * Get quota information (used/allocated), in bytes.
      *
      * @access public
      *
      * @return mixed  An associative array.
      *                'limit' = Maximum quota allowed
      *                'usage' = Currently used portion of quota (in
bytes)
      *                Returns PEAR_Error on failure.
      */
     function getQuota()
     {
         global $imp;

         $imap_user = strtolower($imp['user']);
         $passwd_array = posix_getpwnam($imap_user);
         $homedir = split('/', $passwd_array['dir']);
         if (isset($this->_params['new_quota'])) {
             if (!isset($this->_params['partition'])) {
                 return PEAR::raiseError(_("You must specify the
partition to retrieve quota for"), 'horde.error');
             }
             $cmd = $this->_params['quota_path'] . " $imap_user";
             exec($cmd, $cmd_output, $rc);
             // Output should be one line for header, then one line per
partition for
             // for which there is a quota
             if ($rc == 0) {
                 if ((count($cmd_output) == 1) and
                     preg_match("/Disk quotas for user .+ \(uid \d+\):
none/", $cmd_output[0])) {
                     // No quota fo this user
                     return array('usage' => 0, 'limit' => 0); // FIXME :
is this corrct ?

                 } else if (count($cmd_output > 1)) { // Parse quota
output
                     // Throw away header
                     array_shift($cmd_output);
                     $wrap = false;
                     $pattern = '/\s*' . str_replace('/', '\/',
$this->_params['partition']) . '/';
                     foreach ($cmd_output as $line) {
                         $line = preg_replace('/^\s*/', '//', $line);
                         if ($wrap === true) {
                             // Partition name wrapped, this line is the
output we are looking for
                             $fields = preg_split('/\s+/', $line);
                             if (isset($fields[0]) and isset($fields[2]))
{
                                 // FIXME this assume 1024 bytes per
blocks
                                 return array('usage' => $fields[0] *
1024, 'limit' => $fields[2] * 1024);
                             } else {
                                 return PEAR::raiseError(_("Unable to
retrieve quota"), 'horde.error');
                             }
                         }
                         if (preg_match($pattern, $line)) {
                             // When partition name is longer that 15
chars, fields goes on the next line
                             if (strlen($this->_params['partition']) >
15) {
                                 $wrap = true;
                             } else {
                                 $fields = preg_split('/\s+/', $line);
                                 if (isset($fields[1]) and
isset($fields[3])) {
                                     // FIXME this assume 1024 bytes per
blocks
                                     return array('usage' => $fields[1] *
1024, 'limit' => $fields[3] * 1024);
                                 } else {
                                     return PEAR::raiseError(_("Unable to
retrieve quota"), 'horde.error');
                                 }
                             }
                         }
                     }
                 }
             }

         } else {
             $cmdline = $this->_params['quota_path'] . " -u $imap_user |
" .
                        $this->_params['grep_path'] . " $homedir[1]";
             $junk = exec($cmdline, $quota_data, $return_code);
             if (($return_code == 0) && (count($quota_data) == 1)) {
                 $quota = split("[[:blank:]]+", trim($quota_data[0]));
                 return array('usage' => $quota[1] * 1024, 'limit' =>
$quota[2] * 1024);
             }
         }

         return PEAR::raiseError(_("Unable to retrieve quota"),
'horde.error');
     }

}
I dont get anything either in my httpd/error_logs, nor do I get any  
php warnings with error_display turned on.  I dont have anything in my  
top menu.  Nothing in my horde portal blocks.  Quotas are enabled for  
/dev/sdb.  quota command returns each users quota.  I added Cmnd_Alias  
QUOTA = /usr/bin/quota
apache  ALL= (ALL)NOPASSWD: QUOTA
to my /etc/sudoers.  Does anyone have this working?  Im running an fc  
6.  If you do can you send me a screen shot or help me get it going?   
I have 750 users and definately need quotas for the users.

thanks,

ddh


-- 
Dwayne Hottinger
Network Administrator
Harrisonburg City Public Schools



More information about the imp mailing list