array( * 'driver' => 'command', * 'params' => array( * 'quota_path' => '/usr/bin/quota', * 'grep_path' => '/bin/grep' * ) * ) * * If your quota is relatively recent, its output may look like this : * * Disk quotas for user egoyer (uid 500): * Filesystem blocks quota limit grace files quota limit grace * /dev/sda2 17 0 10240 8 0 0 * * If this is the case, you need to use new style of quota parsing. Your * configuration should look like this : * * 'quota' => array( * 'driver' => 'command', * 'params' => array( * 'new_quota' => true, * 'quota_path' => 'sudo /usr/sbin/quota', * 'partition' => '/dev/sda2' * ), * ) * * The partition argument must be the partition name of the filesystem you want * to get quota for. * * $Horde: imp/lib/Quota/command.php,v 1.9 2003/09/30 18:33:34 slusarz Exp $ * * Copyright 2002-2003 Eric Jon Rostetter * * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. * * @author Eric Rostetter * @version $Revision: 1.9 $ * @since IMP 4.0 * @package imp.quota */ 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'); } }