Copyright 2002-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Chris Bowlby (cbowlby@tenthpowertech.com)
Author: Max Kalika (max@horde.org)
Author: Jan Schneider (jan@horde.org)
コード例 #1
0
ファイル: Driver.php プロジェクト: horde/horde
 /**
  * Return an Sam_Driver_Base instance.
  *
  * @return Sam_Driver_Base
  * @throws Sam_Exception
  */
 public function create(Horde_Injector $injector)
 {
     $backend = Sam::getPreferredBackend();
     $signature = hash('md5', serialize($backend));
     if (empty($this->_instances[$signature])) {
         $user = Sam::mapUser($backend['hordeauth']);
         switch ($backend['driver']) {
             case 'Amavisd_Sql':
             case 'Spamd_Sql':
                 $db_params = array_merge(Horde::getDriverConfig(null, 'sql'), $backend['params']);
                 unset($db_params['table_map']);
                 try {
                     $db = $injector->getInstance('Horde_Core_Factory_Db')->create('sam', $db_params);
                 } catch (Horde_Exception $e) {
                     throw new Sam_Exception($e);
                 }
                 $params = array_merge($backend['params'], array('db' => $db));
                 break;
             case 'Spamd_Ldap':
                 $params = array_merge(array('binddn' => sprintf('%s=%s,%s', $backend['params']['uid'], $user, $backend['params']['basedn']), 'bindpw' => $GLOBALS['registry']->getAuthCredential('password')), $backend['params']);
                 try {
                     $ldap = $injector->getInstance('Horde_Core_Factory_Ldap')->create('sam', $params);
                 } catch (Horde_Exception $e) {
                     throw new Sam_Exception($e);
                 }
                 $params = array_merge($backend['params'], array('ldap' => $ldap));
                 break;
             case 'Spamd_Ftp':
                 $params = array_merge(array('username' => $user, 'password' => $GLOBALS['registry']->getAuthCredential('password')), $backend['params']);
                 try {
                     $vfs = $injector->getInstance('Horde_Core_Factory_Vfs')->create('sam', array('type' => 'ftp', 'params' => $params));
                 } catch (Horde_Exception $e) {
                     throw new Sam_Exception($e);
                 }
                 $params = array_merge($backend['params'], array('vfs' => $vfs));
                 break;
             default:
                 $params = $backend['params'];
                 break;
         }
         $class = 'Sam_Driver_' . $backend['driver'];
         $this->_instances[$signature] = new $class($user, $params);
     }
     return $this->_instances[$signature];
 }
コード例 #2
0
ファイル: Options.php プロジェクト: horde/horde
 public function __construct($vars)
 {
     parent::__construct($vars, _("Spam Options"));
     $this->setButtons(_("Save"), true);
     try {
         $sam_driver = $GLOBALS['injector']->getInstance('Sam_Driver');
     } catch (Sam_Exception $e) {
         return;
     }
     foreach (Sam::getAttributes() as $key => $attribute) {
         if (!Sam::infoAttribute($attribute['type']) && !$sam_driver->hasCapability($key)) {
             continue;
         }
         $var = $this->addVariable($attribute['label'], $key, $attribute['type'], !empty($attribute['required']), !empty($attribute['readonly']), isset($attribute['description']) ? $attribute['description'] : null, isset($attribute['params']) ? $attribute['params'] : array());
         $var->setHelp($key);
         if (isset($attribute['default'])) {
             $var->setDefault($attribute['default']);
         }
         if ($vars->exists($key)) {
             continue;
         }
         if (isset($attribute['basepref'])) {
             /* If basepref is set, key is one of multiple multiple possible
              * entries for basepref.  Get all basepref entries from
              * backend. */
             $value = $sam_driver->getListOption($attribute['basepref']);
             /* Split entries into individual elements */
             $elements = preg_split('/\\n/', $value, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($elements as $element) {
                 /* Split element into subtype and data e.g. 'Subject' and
                  * '***SPAM***' */
                 $pref = explode(' ', $element);
                 /* Find right subtype entry for this key */
                 if (isset($pref[0]) && $pref[0] == $attribute['subtype']) {
                     if (isset($pref[1])) {
                         /* Set value for key to just the data */
                         $vars->set($key, $pref[1]);
                     } else {
                         $vars->set($key, '');
                     }
                     break;
                 }
             }
         } else {
             $value = $sam_driver->getOption($key);
             if (!is_null($value)) {
                 if ($attribute['type'] == 'boolean') {
                     $boolean = $sam_driver->optionToBoolean($value);
                     $vars->set($key, $boolean);
                 } else {
                     $vars->set($key, $value);
                 }
             }
         }
     }
     if ($sam_driver->hasCapability('global_defaults') && $GLOBALS['registry']->isAdmin()) {
         $this->addVariable('', '', 'spacer', false);
         $var = $this->addVariable(_("Make Settings Global"), 'global_defaults', 'boolean', false);
         $var->setHelp('global_defaults');
     }
 }
コード例 #3
0
ファイル: spam.php プロジェクト: raz0rsdge/horde
if ($form->isSubmitted() && $vars->exists('global_defaults') && $vars->get('global_defaults')) {
    if (!$registry->isAdmin()) {
        $notification->push(_("Only an administrator may change the global defaults."), 'horde.error');
        $vars->remove('global_defaults');
        $form->setSubmitted(false);
    } elseif (!$sam_driver->hasCapability('global_defaults')) {
        $notification->push(_("The configured backend does not support global defaults."), 'horde.error');
        $vars->remove('global_defaults');
        $form->setSubmitted(false);
    } else {
        $defaults = true;
    }
}
if ($form->validate($vars)) {
    $stackedOptions = array();
    foreach (Sam::getAttributes() as $key => $attribute) {
        if ($sam_driver->hasCapability($key) && $vars->exists($key)) {
            $data = $vars->get($key);
            if (isset($attribute['basepref'])) {
                /* SA docs claim that a null value for a rewrite string merely
                 * removes any previous changes to the specified header.  This
                 * should be harmless, and saves needing to add a DELETE
                 * preference call in the backend when the user doesn't use
                 * header rewrites. */
                /* Build string with all basepref entries, separated by
                 * newlines */
                if (!isset($stackedOptions[$attribute['basepref']])) {
                    $stackedOptions[$attribute['basepref']] = '';
                } else {
                    $stackedOptions[$attribute['basepref']] .= "\n";
                }