From 2f76218fd0a64dc121003ca7d07edd0bd1d4e0ff Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 8 Oct 2010 15:00:58 -0600 Subject: [PATCH] SESSION->imp->user does not exist anymore --- imp/config/backends.php.dist | 4 ++-- imp/config/hooks.php.dist | 12 ++++++++---- imp/lib/Injector/Factory/Quota.php | 6 ++---- imp/lib/Quota/Base.php | 4 +++- imp/lib/Quota/Command.php | 4 ++-- imp/lib/Quota/Maildir.php | 5 +---- imp/lib/Quota/Mdaemon.php | 6 +++++- imp/lib/Quota/Mercury32.php | 2 +- imp/lib/Quota/Sql.php | 13 ++++++------- 9 files changed, 30 insertions(+), 26 deletions(-) diff --git a/imp/config/backends.php.dist b/imp/config/backends.php.dist index 2c238cf85..8cdd94f63 100644 --- a/imp/config/backends.php.dist +++ b/imp/config/backends.php.dist @@ -157,8 +157,8 @@ * DRIVER: 'hook' * Use the quota hook to handle quotas (see * imp/config/hooks.php). - * PARAMS: 'params' - [array] Parameters to pass to the quota - * hook function. + * PARAMS: Any parameters defined here will be passed to the quota + * hook function. * * DRIVER: 'imap' * Use the IMAP QUOTA extension to handle quotas. diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index dd626b25f..9cd91a037 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -612,10 +612,14 @@ class IMP_Hooks // { // // Example #1: Sample function for returning the quota. // // Uses the PECL ssh2 extension. -// $host = $_SESSION['imp']['server']; -// $user = $_SESSION['imp']['user']; -// $pass = $GLOBALS['registry']->getAuthCredential('password'); -// $command = $params[0]; +// // Requires the 'command' parameter to be defined in backends.php, +// // which defines the quota reporting function to run on the SSH +// // host. +// $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); +// $host = $imap_ob->ob->getParam('hostspec'); +// $user = $params['host']; +// $pass = $imap_ob->ob->getParam('password'); +// $command = $params['command']; // // $session = ssh2_connect($host); // if (!$session) { diff --git a/imp/lib/Injector/Factory/Quota.php b/imp/lib/Injector/Factory/Quota.php index 3128fe1ad..29d85ec67 100644 --- a/imp/lib/Injector/Factory/Quota.php +++ b/imp/lib/Injector/Factory/Quota.php @@ -54,15 +54,13 @@ class IMP_Injector_Factory_Quota : IMP::$mailbox; break; - case 'maildir': - $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username'); - break; - case 'sql': $params['db'] = $injector->getInstance('Horde_Core_Factory_Db')->create('imp', $params); break; } + $params['username'] = $injector->getInstance('IMP_Injector_Factory_Imap')->create()->getParam('username'); + return IMP_Quota::factory($driver, $params); } diff --git a/imp/lib/Quota/Base.php b/imp/lib/Quota/Base.php index 513882487..584bf6c2f 100644 --- a/imp/lib/Quota/Base.php +++ b/imp/lib/Quota/Base.php @@ -1,6 +1,7 @@ */ public function __construct(array $params = array()) diff --git a/imp/lib/Quota/Command.php b/imp/lib/Quota/Command.php index 624d1d9cb..75623e120 100644 --- a/imp/lib/Quota/Command.php +++ b/imp/lib/Quota/Command.php @@ -73,12 +73,12 @@ class IMP_Quota_Command extends IMP_Quota_Base public function getQuota() { if (empty($this->_params['partition'])) { - $passwd_array = posix_getpwnam($_SESSION['imp']['user']); + $passwd_array = posix_getpwnam($this->_params['username']); list($junk, $search_string, $junk) = explode('/', $passwd_array['dir']); } else { $search_string = $this->_params['partition']; } - $cmdline = $this->_params['quota_path'] . ' -u ' . escapeshellarg($_SESSION['imp']['user']) . ' | ' . escapeshellcmd($this->_params['grep_path']) . ' ' . escapeshellarg($search_string); + $cmdline = $this->_params['quota_path'] . ' -u ' . escapeshellarg($this->_params['username']) . ' | ' . escapeshellcmd($this->_params['grep_path']) . ' ' . escapeshellarg($search_string); exec($cmdline, $quota_data, $return_code); if (($return_code == 0) && (count($quota_data) == 1)) { $quota = split("[[:blank:]]+", trim($quota_data[0])); diff --git a/imp/lib/Quota/Maildir.php b/imp/lib/Quota/Maildir.php index ed6e2bbde..094366c7e 100644 --- a/imp/lib/Quota/Maildir.php +++ b/imp/lib/Quota/Maildir.php @@ -29,16 +29,13 @@ class IMP_Quota_Maildir extends IMP_Quota_Base * that location. * E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/' * DEFAULT: '' - * 'username' - (string) Username to substitute into the string. - * DEFAULT: none * */ public function __construct($params = array()) { parent::__construct(array_merge(array( 'msg_count' => false, - 'path' => '', - 'username' => '' + 'path' => '' ), $params)); } diff --git a/imp/lib/Quota/Mdaemon.php b/imp/lib/Quota/Mdaemon.php index 4724f49e8..643401b69 100644 --- a/imp/lib/Quota/Mdaemon.php +++ b/imp/lib/Quota/Mdaemon.php @@ -43,7 +43,11 @@ class IMP_Quota_Mdaemon extends IMP_Quota_Base */ public function getQuota() { - $userDetails = $this->_getUserDetails($_SESSION['imp']['user'], $_SESSION['imp']['maildomain']); + $imap_ob = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_Imap')->create(); + $userDetails = $this->_getUserDetails( + $this->_params['username'], + $_SESSION['imp']['maildomain'] + ); if ($userDetails !== false) { $userHome = trim(substr($userDetails, 105, 90)); diff --git a/imp/lib/Quota/Mercury32.php b/imp/lib/Quota/Mercury32.php index c0608d74b..a1bb68cb3 100644 --- a/imp/lib/Quota/Mercury32.php +++ b/imp/lib/Quota/Mercury32.php @@ -65,7 +65,7 @@ class IMP_Quota_Mercury32 extends IMP_Quota_Base $quota = 0; try { - $di = new DirectoryIterator($this->_params['mail_user_folder'] . '/' . $_SESSION['imp']['user'] . '/'); + $di = new DirectoryIterator($this->_params['mail_user_folder'] . '/' . $this->_params['username'] . '/'); } catch (UnexpectedValueException $e) { throw new IMP_Exception(_("Unable to retrieve quota")); } diff --git a/imp/lib/Quota/Sql.php b/imp/lib/Quota/Sql.php index 0ab7e1023..f8706b1bb 100644 --- a/imp/lib/Quota/Sql.php +++ b/imp/lib/Quota/Sql.php @@ -69,7 +69,6 @@ class IMP_Quota_Sql extends IMP_Quota_Base */ public function getQuota() { - $user = $_SESSION['imp']['user']; $quota = array( 'limit' => 0, 'usage' => 0 @@ -78,10 +77,10 @@ class IMP_Quota_Sql extends IMP_Quota_Base if (empty($this->_params['query_quota'])) { Horde::logMessage(__CLASS__ . ': query_quota SQL query not set.', 'ERR'); } else { - @list($bare_user, $domain) = explode('@', $user, 2); + @list($bare_user, $domain) = explode('@', $this->_params['username'], 2); $query = str_replace(array('?', '%u', '%U', '%d'), - array($this->_db->quote($user), - $this->_db->quote($user), + array($this->_db->quote($this->_params['username']), + $this->_db->quote($this->_params['username']), $this->_db->quote($bare_user), $this->_db->quote($domain)), $this->_params['query_quota']); @@ -97,10 +96,10 @@ class IMP_Quota_Sql extends IMP_Quota_Base if (empty($this->_params['query_used'])) { Horde::logMessage(__CLASS__ . ': query_used SQL query not set.', 'ERR'); } else { - @list($bare_user, $domain) = explode('@', $user, 2); + @list($bare_user, $domain) = explode('@', $this->_params['username'], 2); $query = str_replace(array('?', '%u', '%U', '%d'), - array($this->_db->quote($user), - $this->_db->quote($user), + array($this->_db->quote($this->_params['username']), + $this->_db->quote($this->_params['username']), $this->_db->quote($bare_user), $this->_db->quote($domain)), $this->_params['query_used']); -- 2.11.0