Horde_Registry::appInit('ingo');
/* Redirect if blacklist is not available. */
-if (!in_array(Ingo_Storage::ACTION_BLACKLIST, $_SESSION['ingo']['script_categories'])) {
+if (!in_array(Ingo_Storage::ACTION_BLACKLIST, $session->get('ingo', 'script_categories'))) {
$notification->push(_("Blacklist is not supported in the current filtering driver."), 'horde.error');
Horde::url('filters.php', true)->redirect();
}
}
/* Update the timestamp for the rules. */
- $_SESSION['ingo']['change'] = time();
+ $session->set('ingo', 'change', time());
}
break;
require INGO_TEMPLATES . '/filters/filter-none.inc';
} else {
$display = array();
- $i = 0;
- $rule_count = array_sum(array_map(create_function('$a', "return (in_array(\$a['action'], \$_SESSION['ingo']['script_categories'])) ? 1 : 0;"), $filter_list));
+ $i = $rule_count = 0;
+ $s_categories = $session->get('ingo', 'script_categories');
+
+ foreach ($filter_list as $val) {
+ if (in_array($val['action'], $s_categories)) {
+ ++$rule_count;
+ }
+ }
/* Common graphics. */
$down_img = Horde::img('nav/down.png', _("Move Rule Down"));
foreach ($filter_list as $rule_number => $filter) {
/* Skip non-display categories. */
- if (!in_array($filter['action'], $_SESSION['ingo']['script_categories'])) {
+ if (!in_array($filter['action'], $s_categories)) {
continue;
}
Horde_Registry::appInit('ingo');
/* Redirect if forward is not available. */
-if (!in_array(Ingo_Storage::ACTION_FORWARD, $_SESSION['ingo']['script_categories'])) {
+if (!in_array(Ingo_Storage::ACTION_FORWARD, $session->get('ingo', 'script_categories'))) {
$notification->push(_("Forward is not supported in the current filtering driver."), 'horde.error');
Horde::url('filters.php', true)->redirect();
}
}
/* Update the timestamp for the rules. */
- $_SESSION['ingo']['change'] = time();
+ $GLOBALS['session']->set('ingo', 'change', time());
return true;
} catch (Ingo_Exception $e) {}
}
/* Update the timestamp for the rules. */
- $_SESSION['ingo']['change'] = time();
+ $GLOBALS['session']->set('ingo', 'change', time());
return true;
} catch (Ingo_Exception $e) {}
$GLOBALS['all_rulesets'] = Ingo::listRulesets();
/* If personal share doesn't exist then create it. */
- $signature = $_SESSION['ingo']['backend']['id'] . ':' . $GLOBALS['registry']->getAuth();
+ $signature = $GLOBALS['session']->get('ingo', 'backend/id') . ':' . $GLOBALS['registry']->getAuth();
if (!$GLOBALS['ingo_shares']->exists($signature)) {
$identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create();
$name = $identity->getValue('fullname');
}
/* Select current share. */
- $_SESSION['ingo']['current_share'] = Horde_Util::getFormData('ruleset', @$_SESSION['ingo']['current_share']);
- if (empty($_SESSION['ingo']['current_share']) ||
- empty($GLOBALS['all_rulesets'][$_SESSION['ingo']['current_share']]) ||
- !$GLOBALS['all_rulesets'][$_SESSION['ingo']['current_share']]->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
- $_SESSION['ingo']['current_share'] = $signature;
+ $GLOBALS['session']->set('ingo', 'current_share', Horde_Util::getFormData('ruleset', $GLOBALS['session']->get('ingo', 'current_share')));
+ if (!$GLOBALS['session']->get('ingo', 'current_share') ||
+ empty($GLOBALS['all_rulesets'][$GLOBALS['session']->get('ingo', 'current_share')]) ||
+ !$GLOBALS['all_rulesets'][$GLOBALS['session']->get('ingo', 'current_share')]->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
+ $GLOBALS['session']->set('ingo', 'current_share', $signature);
}
} else {
$GLOBALS['ingo_shares'] = null;
Horde::logMessage($e->getMessage(), 'ERR');
}
- if (in_array(Ingo_Storage::ACTION_VACATION, $_SESSION['ingo']['script_categories'])) {
+ $s_categories = $GLOBALS['session']->get('ingo', 'script_categories');
+
+ if (in_array(Ingo_Storage::ACTION_VACATION, $s_categories)) {
$menu->add(Horde::url('vacation.php'), _("_Vacation"), 'vacation.png');
}
- if (in_array(Ingo_Storage::ACTION_FORWARD, $_SESSION['ingo']['script_categories'])) {
+ if (in_array(Ingo_Storage::ACTION_FORWARD, $s_categories)) {
$menu->add(Horde::url('forward.php'), _("_Forward"), 'forward.png');
}
- if (in_array(Ingo_Storage::ACTION_SPAM, $_SESSION['ingo']['script_categories'])) {
+ if (in_array(Ingo_Storage::ACTION_SPAM, $s_categories)) {
$menu->add(Horde::url('spam.php'), _("S_pam"), 'spam.png');
}
- if ($_SESSION['ingo']['script_generate'] &&
+ if ($GLOBALS['session']->get('ingo', 'script_generate') &&
(!$GLOBALS['prefs']->isLocked('auto_update') ||
!$GLOBALS['prefs']->getValue('auto_update'))) {
$menu->add(Horde::url('script.php'), _("_Script"), 'script.png');
}
if (!empty($GLOBALS['ingo_shares']) && empty($GLOBALS['conf']['share']['no_sharing'])) {
- $menu->add('#', _("_Permissions"), 'perms.png', Horde_Themes::img(null, 'horde'), '', Horde::popupJs(Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/shares/edit.php', true), array('params' => array('app' => 'ingo', 'share' => $_SESSION['ingo']['backend']['id'] . ':' . $GLOBALS['registry']->getAuth()), 'urlencode' => true)) . 'return false;');
+ $menu->add('#', _("_Permissions"), 'perms.png', Horde_Themes::img(null, 'horde'), '', Horde::popupJs(Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/services/shares/edit.php', true), array('params' => array('app' => 'ingo', 'share' => $GLOBALS['session']->get('ingo', 'backend/id') . ':' . $GLOBALS['registry']->getAuth()), 'urlencode' => true)) . 'return false;');
}
}
*/
public function prefsInit($ui)
{
- if (!isset($_SESSION['ingo']['script_generate']) ||
- $_SESSION['ingo']['script_generate']) {
+ if (!$GLOBALS['session']->exists('ingo', 'script_generate') ||
+ $GLOBALS['session']->get('ingo', 'script_generate')) {
$ui->suppressGroups[] = 'script';
}
}
$active = _("active");
}
- switch($filter['name']) {
+ $s_categories = $GLOBALS['session']->get('ingo', 'script_categories');
+
+ switch ($filter['name']) {
case 'Vacation':
- if (in_array(Ingo_Storage::ACTION_VACATION, $_SESSION['ingo']['script_categories'])) {
+ if (in_array(Ingo_Storage::ACTION_VACATION, $s_categories)) {
$html .= $html_pre .
Horde::img('vacation.png', _("Vacation")) .
'</td><td>' .
break;
case 'Forward':
- if (in_array(Ingo_Storage::ACTION_FORWARD, $_SESSION['ingo']['script_categories'])) {
+ if (in_array(Ingo_Storage::ACTION_FORWARD, $s_categories)) {
$html .= $html_pre .
Horde::img('forward.png', _("Forward")) . '</td><td>' .
Horde::url('forward.php')->link(array('title' => _("Edit"))) .
break;
case 'Whitelist':
- if (in_array(Ingo_Storage::ACTION_WHITELIST, $_SESSION['ingo']['script_categories'])) {
+ if (in_array(Ingo_Storage::ACTION_WHITELIST, $s_categories)) {
$html .= $html_pre .
Horde::img('whitelist.png', _("Whitelist")) .
'</td><td>' .
break;
case 'Blacklist':
- if (in_array(Ingo_Storage::ACTION_BLACKLIST, $_SESSION['ingo']['script_categories'])) {
+ if (in_array(Ingo_Storage::ACTION_BLACKLIST, $s_categories)) {
$html .= $html_pre .
Horde::img('blacklist.png', _("Blacklist")) .
'</td><td>' .
break;
case 'Spam Filter':
- if (in_array(Ingo_Storage::ACTION_SPAM, $_SESSION['ingo']['script_categories'])) {
+ if (in_array(Ingo_Storage::ACTION_SPAM, $s_categories)) {
$html .= $html_pre .
Horde::img('spam.png', _("Spam Filter")) .
'</td><td>' .
*/
static public function createSession()
{
- if (isset($_SESSION['ingo'])) {
+ global $prefs, $session;
+
+ $session->remove('ingo');
+ if ($session->exists('ingo', 'change')) {
return;
}
- global $prefs;
+ /* getBackend() and loadIngoScript() will both throw Exceptions, so
+ * do these first as errors are fatal. */
+ foreach (self::getBackend() as $key => $val) {
+ $session->set('ingo', 'backend/' . $key, $val);
+ }
- $_SESSION['ingo'] = array(
- 'backend' => Ingo::getBackend(),
- 'change' => 0,
- 'storage' => array()
- );
+ $ingo_script = self::loadIngoScript();
+ $session->set('ingo', 'script_generate', $ingo_script->generateAvailable());
- $ingo_script = Ingo::loadIngoScript();
- $_SESSION['ingo']['script_generate'] = $ingo_script->generateAvailable();
+ $session->set('ingo', 'change', 0);
/* Disable categories as specified in preferences */
$categories = array_merge($ingo_script->availableActions(), $ingo_script->availableCategories());
}
/* Set the list of categories this driver supports. */
- $_SESSION['ingo']['script_categories'] = $categories;
+ $session->set('ingo', 'script_categories', $categories);
}
/**
{
if (empty($GLOBALS['ingo_shares'])) {
$baseuser = ($full ||
- (isset($_SESSION['ingo']['backend']['hordeauth']) &&
- $_SESSION['ingo']['backend']['hordeauth'] === 'full'));
+ ($GLOBALS['session']->get('ingo', 'backend/hordeauth') === 'full'));
$user = $GLOBALS['registry']->getAuth($baseuser ? null : 'bare');
} else {
- list(, $user) = explode(':', $_SESSION['ingo']['current_share'], 2);
+ list(, $user) = explode(':', $GLOBALS['session']->get('ingo', 'current_share'), 2);
}
return $user;
*/
static public function updateScript()
{
- if ($_SESSION['ingo']['script_generate']) {
+ if ($GLOBALS['session']->get('ingo', 'script_generate')) {
try {
$ingo_script = self::loadIngoScript();
{
include INGO_BASE . '/config/backends.php';
if (!isset($backends) || !is_array($backends)) {
- throw new Horde_Exception(_("No backends configured in backends.php"));
+ throw new Ingo_Exception(_("No backends configured in backends.php"));
}
$backend = null;
$backends[$backend]['id'] = $name;
$backend = $backends[$backend];
- if (empty($backend['script'])) {
- throw new Ingo_Exception(sprintf(_("No \"%s\" element found in backend configuration."), 'script'));
- } elseif (empty($backend['transport'])) {
- throw new Ingo_Exception(sprintf(_("No \"%s\" element found in backend configuration."), 'transport'));
+ foreach (array('script', 'transport') as $val) {
+ if (empty($backend[$val])) {
+ throw new Ingo_Exception(sprintf(_("No \"%s\" element found in backend configuration."), $val));
+ }
}
/* Make sure the 'params' entry exists. */
*/
static public function loadIngoScript()
{
- return Ingo_Script::factory($_SESSION['ingo']['backend']['script'],
- isset($_SESSION['ingo']['backend']['scriptparams']) ? $_SESSION['ingo']['backend']['scriptparams'] : array());
+ return Ingo_Script::factory(
+ $GLOBALS['session']->get('ingo', 'backend/script'),
+ $GLOBALS['session']->get('ingo', 'backend/scriptparams', Horde_Session::TYPE_ARRAY)
+ );
}
/**
*/
static public function getTransport()
{
- $params = $_SESSION['ingo']['backend']['params'];
+ global $registry, $session;
+
+ $params = $session->get('ingo', 'backend/params');
// Set authentication parameters.
- if (!empty($_SESSION['ingo']['backend']['hordeauth'])) {
- $params['username'] = $GLOBALS['registry']->getAuth(($_SESSION['ingo']['backend']['hordeauth'] === 'full') ? null : 'bare');
- $params['password'] = $GLOBALS['registry']->getAuthCredential('password');
- } elseif (isset($_SESSION['ingo']['backend']['params']['username']) &&
- isset($_SESSION['ingo']['backend']['params']['password'])) {
- $params['username'] = $_SESSION['ingo']['backend']['params']['username'];
- $params['password'] = $_SESSION['ingo']['backend']['params']['password'];
- } else {
- $params['username'] = $GLOBALS['registry']->getAuth('bare');
- $params['password'] = $GLOBALS['registry']->getAuthCredential('password');
+ if (($hordeauth = $session->get('ingo', 'backend/hordeauth')) ||
+ !isset($params['username']) ||
+ !isset($params['password'])) {
+ $params['username'] = $registry->getAuth(($hordeauth === 'full') ? null : 'bare');
+ $params['password'] = $registry->getAuthCredential('password');
}
- return Ingo_Transport::factory($_SESSION['ingo']['backend']['transport'], $params);
+ return Ingo_Transport::factory($GLOBALS['session']->get('ingo', 'backend/transport'), $params);
}
/**
}
if (is_null(self::$_shareCache)) {
- self::$_shareCache = $GLOBALS['ingo_shares']->getPermissions($_SESSION['ingo']['current_share'], $GLOBALS['registry']->getAuth());
+ self::$_shareCache = $GLOBALS['ingo_shares']->getPermissions($GLOBALS['session']->get('ingo', 'current_share'), $GLOBALS['registry']->getAuth());
}
return self::$_shareCache & $mask;
foreach (array_keys($GLOBALS['all_rulesets']) as $id) {
$options[] = array(
'name' => htmlspecialchars($GLOBALS['all_rulesets'][$id]->get('name')),
- 'selected' => ($_SESSION['ingo']['current_share'] == $id),
+ 'selected' => ($GLOBALS['session']->get('ingo', 'current_share') == $id),
'val' => htmlspecialchars($id)
);
}
2. The mailbox has changed -or-
3. The rules have changed. */
$cache = $this->_api->getCache();
- if (($cache !== false) && ($cache == $_SESSION['ingo']['change'])) {
+ if (($cache !== false) && ($cache == $GLOBALS['session']->get('ingo', 'change'))) {
return true;
}
}
/* Set cache flag. */
- $this->_api->storeCache($_SESSION['ingo']['change']);
+ $this->_api->storeCache($GLOBALS['session']->get('ingo', 'change'));
return true;
}
*/
public function getCache()
{
- if (empty($_SESSION['ingo']['imapcache'][$this->_params['mailbox']])) {
+ if ($cache = $GLOBALS['session']->get('ingo', 'imapcache/' . $this->_params['mailbox'])) {
return false;
}
- $ptr = &$_SESSION['ingo']['imapcache'][$this->_params['mailbox']];
- if ($this->_cacheId() != $ptr['id']) {
- $ptr = array();
- return false;
- }
-
- return $ptr['ts'];
+ return ($this->_cacheId() != $cache['id'])
+ ? false
+ : $cache['ts'];
}
/**
*/
public function storeCache($timestamp)
{
- if (!isset($_SESSION['ingo']['imapcache'])) {
- $_SESSION['ingo']['imapcache'] = array();
- }
-
- $_SESSION['ingo']['imapcache'][$this->_params['mailbox']] = array(
+ $GLOBALS['session']->set('ingo', 'imapcache/' . $this->_params['mailbox'], array(
'id' => $this->_cacheId(),
'ts' => $timestamp
- );
+ ));
}
/**
{
/* Store the current objects. */
foreach ($this->_cache as $key => $val) {
- if ($val['mod'] || !isset($_SESSION['ingo']['storage'][$key])) {
- $_SESSION['ingo']['storage'][$key] = $GLOBALS['session']->store($val['ob'], false);
+ if ($val['mod'] || !$GLOBALS['session']->exists('ingo', 'storage/' . $key)) {
+ $GLOBALS['session']->set('ingo', 'storage/' . $key, $GLOBALS['session']->store($val['ob'], false));
}
}
}
/* Don't cache if using shares. */
if ($cache && empty($GLOBALS['ingo_shares'])) {
if (!isset($this->_cache[$field])) {
- $cached = $GLOBALS['session']->retrieve($_SESSION['ingo']['storage'][$field]);
+ $cached = $GLOBALS['session']->retrieve($GLOBALS['session']->get('ingo', 'storage/' . $field));
$this->_cache[$field] = array(
'mod' => false,
'ob' => $cached ? $cached : $this->_retrieve($field, $readonly)
$this->_filters[$id - 1] = $this->_filters[$id];
$this->_filters[$id] = $temp;
/* Continue to move up until we swap with a viewable category. */
- if (in_array($temp['action'], $_SESSION['ingo']['script_categories'])) {
+ if (in_array($temp['action'], $GLOBALS['session']->get('ingo', 'script_categories'))) {
$i++;
}
$id--;
$this->_filters[$id] = $temp;
/* Continue to move down until we swap with a viewable
category. */
- if (in_array($temp['action'], $_SESSION['ingo']['script_categories'])) {
+ if (in_array($temp['action'], $GLOBALS['session']->get('ingo', 'script_categories'))) {
$i++;
}
$id++;
public function supportShares()
{
return ($this->_support_shares &&
- !empty($_SESSION['ingo']['backend']['shares']));
+ $GLOBALS['session']->get('ingo', 'backend/shares'));
}
}
if (!empty($this->_params['vfs_path'])) {
$user = Ingo::getUser();
$domain = Ingo::getDomain();
- if ($_SESSION['ingo']['backend']['hordeauth'] !== 'full') {
+ if ($GLOBALS['session']->get('ingo', 'backend/hordeauth') !== 'full') {
$pos = strpos($user, '@');
if ($pos !== false) {
$domain = substr($user, $pos + 1);
function _setupStorage()
{
- $_SESSION['ingo']['change'] = 0;
+ $GLOBALS['session']->set('ingo', 'change', 0);
$GLOBALS['ingo_storage'] = Ingo_Storage::factory('mock', array());
foreach ($this->rules as $ob) {
$GLOBALS['ingo_storage']->store($ob);
}
/* Update the timestamp for the rules. */
- $_SESSION['ingo']['change'] = time();
+ $session->set('ingo', 'change', time());
/* Save the rule. */
if ($vars->actionID == 'rule_save' && $valid) {
Horde_Registry::appInit('ingo');
/* Redirect if script updating is not available. */
-if (!$_SESSION['ingo']['script_generate']) {
+if (!$session->get('ingo', 'script_generate')) {
Horde::url('filters.php', true)->redirect();
}
require_once dirname(__FILE__) . '/../../lib/Application.php';
Horde_Registry::appInit('ingo', array('authentication' => 'none', 'cli' => true));
+exit('Not updated');
+
// Initialize authentication manager.
$auth = $injector->getInstance('Horde_Auth')->getAuth();
// Retrieve the data.
$GLOBALS['auth']->setAuth($user, array());
- $_SESSION['ingo']['current_share'] = ':' . $user;
+ $GLOBALS['session']->set('ingo', 'current_share', ':' . $user);
try {
$whitelists[$user] = $GLOBALS['rules_storage']->retrieve(Ingo_Storage::ACTION_WHITELIST, false)->getWhitelist();
echo 'Converting filters for user: ' . $user;
Horde_Auth::setAuth($user, array());
- $_SESSION['ingo']['current_share'] = ':' . $user;
+ $session->set('ingo', 'current_share', ':' . $user);
foreach ($rules as $rule) {
$filter = $prefs_storage->retrieve($rule, false);
}
-if (!in_array(Ingo_Storage::ACTION_SPAM, $_SESSION['ingo']['script_categories'])) {
+if (!in_array(Ingo_Storage::ACTION_SPAM, $session->get('ingo', 'script_categories'))) {
$notification->push(_("Simple spam filtering is not supported in the current filtering driver."), 'horde.error');
Horde::url('filters.php', true)->redirect();
}
}
/* Update the timestamp for the rules. */
- $_SESSION['ingo']['change'] = time();
+ $session->set('ingo', 'change', time());
}
/* Add buttons depending on the above actions. */
Horde_Registry::appInit('ingo');
/* Redirect if vacation is not available. */
-if (!in_array(Ingo_Storage::ACTION_VACATION, $_SESSION['ingo']['script_categories'])) {
+if (!in_array(Ingo_Storage::ACTION_VACATION, $session->get('ingo', 'script_categories'))) {
$notification->push(_("Vacation is not supported in the current filtering driver."), 'horde.error');
Horde::url('filters.php', true)->redirect();
}
}
/* Update the timestamp for the rules. */
- $_SESSION['ingo']['change'] = time();
+ $session->set('ingo', 'change', time());
}
/* Add buttons depending on the above actions. */
Horde_Registry::appInit('ingo');
/* Redirect if whitelist not available. */
-if (!in_array(Ingo_Storage::ACTION_WHITELIST, $_SESSION['ingo']['script_categories'])) {
+if (!in_array(Ingo_Storage::ACTION_WHITELIST, $session->get('ingo', 'script_categories'))) {
$notification->push(_("Whitelist is not supported in the current filtering driver."), 'horde.error');
Horde::url('filters.php', true)->redirect();
}
}
/* Update the timestamp for the rules. */
- $_SESSION['ingo']['change'] = time();
+ $session->set('ingo', 'change', time());
} catch (Ingo_Exception $e) {
$notification->push($e);
}