Exemple #1
0
 function restoreEncrypted()
 {
     $encoded = basename($_SERVER['PATH_INFO']);
     $rc4 =& new Crypt_RC4(SECRET_KEY);
     $encoded = base64_decode(str_replace('^', '/', $encoded));
     $rc4->decrypt($encoded);
     $params = unserialize($encoded);
     if (is_array($params)) {
         foreach ($params as $name => $value) {
             $_REQUEST[$name] = $_GET[$name] = $value;
         }
         unset($params['crc32_chk']);
         if (CHECK_URLS_CRC32) {
             if (!isset($_GET['crc32_chk']) || crc32(serialize($params)) != $_GET['crc32_chk']) {
                 return PEAR::throwError('URL Error: URL Manipulation', URL_MANIPULATION, array('class' => 'SAUrl', 'file' => __FILE__, 'line' => __LINE__));
             }
         }
     }
     return URL_OK;
 }
 /**
  * Authenticate
  * 
  * Auth process (not yet standarized but used any way)
  * http://www.mibsoftware.com/userkt/nntpext/index.html
  *
  * @param string $user The username
  * @param optional string $pass The password
  * @param optional string $mode The authentication mode (original, simple, generic).
  *
  * @return mixed (bool) true on success or (object) pear_error on failure
  * @access public
  * @see Net_NNTP_Client::connect()
  * @see Net_NNTP_Client::connectAuthenticated()
  */
 function authenticate($user, $pass, $mode = NET_NNTP_CLIENT_AUTH_ORIGINAL)
 {
     // Username is a must...
     if ($user == null) {
         return PEAR::throwError('No username supplied', null);
     }
     // Use selected authentication method
     switch ($mode) {
         case NET_NNTP_CLIENT_AUTH_ORIGINAL:
             return $this->cmdAuthinfo($user, $pass);
             break;
         case NET_NNTP_CLIENT_AUTH_SIMPLE:
             return $this->cmdAuthinfoSimple($user, $pass);
             break;
         case NET_NNTP_CLIENT_AUTH_GENERIC:
             return $this->cmdAuthinfoGeneric($user, $pass);
             break;
         default:
             return PEAR::throwError("The auth mode: '{$mode}' is unknown", null);
     }
 }
Exemple #3
0
 /**
  * Issue a command to the NNTP server
  *
  * @param string $cmd The command to launch, ie: "ARTICLE 1004853"
  *
  * @return mixed (int) response code on success or (object) pear_error on failure
  * @access public
  */
 function command($cmd)
 {
     $code = $this->_sendCommand($cmd);
     if (PEAR::isError($code)) {
         return PEAR::throwError($code);
     }
     return $code . ' ' . $this->currentStatusResponse() . "\r\n";
 }
 /**
  * Send a command to the server. A carriage return / linefeed (CRLF) sequence
  * will be appended to each command string before it is sent to the IMAP server.
  *
  * @param string $cmd The command to launch, ie: "ARTICLE 1004853"
  *
  * @return mixed (int) response code on success or (object) pear_error on failure
  * @access private
  */
 function _sendCommand($cmd)
 {
     // NNTP/RFC977 only allows command up to 512 (-2) chars.
     if (!strlen($cmd) > 510) {
         return PEAR::throwError('Failed to write to socket! (Command to long - max 510 chars)');
     }
     // Check if connected
     if (!$this->isConnected()) {
         return PEAR::throwError('Failed to write to socket! (connection lost!)');
     }
     // Send the command
     $R = $this->_socket->writeLine($cmd);
     if (PEAR::isError($R)) {
         return PEAR::throwError('Failed to write to socket!', null, $R->getMessage());
     }
     if ($this->_debug) {
         echo "C: {$cmd}\r\n";
     }
     return $this->_getStatusResponse();
 }
 /**
  * 
  * Extended behavior for PEAR_Error.
  *
  * @access public
  *
  * @return void
  *
  */
 function error()
 {
     // throw a PEAR_Error
     PEAR::throwError($this->text, $this->code, $this->info);
 }
 /**
  * Sets which items should be persistant
  *
  * Sets which items should have the disabled attribute
  * to keep it persistant
  *
  * @param mixed $optionValues Options (key-values) that should be persistant
  * @param bool  $persistant   (optional) TRUE if persistant, FALSE otherwise
  *
  * @since      version 1.5.0 (2009-02-15)
  * @access     public
  * @return     PEAR_Error on error and TRUE on success
  * @throws     PEAR_Error
  */
 function setPersistantOptions($optionValues, $persistant = true)
 {
     if (!is_bool($persistant)) {
         return PEAR::throwError('Argument 2 of HTML_QuickForm_advmultiselect::' . 'setPersistantOptions is not a boolean', HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT, array('level' => 'exception'));
     }
     if (is_string($optionValues)) {
         $optionValues = array($optionValues);
     }
     if (!is_array($optionValues)) {
         return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . 'setPersistantOptions is not a valid array', HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT, array('level' => 'exception'));
     }
     foreach ($this->_options as $k => $v) {
         if (in_array($v['attr']['value'], $optionValues)) {
             if ($persistant) {
                 $this->_options[$k]['attr']['disabled'] = 'disabled';
             } else {
                 unset($this->_options[$k]['attr']['disabled']);
             }
         }
     }
     return true;
 }
Exemple #7
0
 /**
  * Factory for Net_Ping_Result
  *
  * @access public
  * @param array $result Net_Ping result
  * @param string $sysname OS_Guess::sysname
  */
 function factory($result, $sysname)
 {
     if (!Net_Ping_Result::_prepareParseResult($sysname)) {
         return PEAR::throwError(NET_PING_RESULT_UNSUPPORTED_BACKEND_MSG, NET_PING_RESULT_UNSUPPORTED_BACKEND);
     } else {
         return new Net_Ping_Result($result, $sysname);
     }
 }
Exemple #8
0
 /**
  * Login function
  *
  * @access private
  * @return void
  */
 function login()
 {
     $login_ok = false;
     if (method_exists($this, '_loadStorage')) {
         $this->_loadStorage();
     }
     $this->storage->_auth_obj->_sessionName =& $this->_sessionName;
     /**
      * When the user has already entered a username,
      * we have to validate it.
      */
     if (!empty($this->username) && !empty($this->password)) {
         if ($this->authType == 'basic' && !$this->options['forceDigestOnly']) {
             if (true === $this->storage->fetchData($this->username, $this->password)) {
                 $login_ok = true;
             }
         } else {
             /* digest authentication */
             if (!$this->getAuth() || $this->getAuthData('a1') == null) {
                 /* 
                  * note:
                  *  - only PEAR::DB is supported as container.
                  *  - password should be stored in container as plain-text 
                  *    (if $options['cryptType'] == 'none') or 
                  *     A1 hashed form (md5('username:realm:password')) 
                  *    (if $options['cryptType'] == 'md5')
                  */
                 $dbs = $this->storage;
                 if (!DB::isConnection($dbs->db)) {
                     $dbs->_connect($dbs->options['dsn']);
                 }
                 $query = 'SELECT ' . $dbs->options['passwordcol'] . " FROM " . $dbs->options['table'] . ' WHERE ' . $dbs->options['usernamecol'] . " = '" . $dbs->db->quoteString($this->username) . "' ";
                 $pwd = $dbs->db->getOne($query);
                 // password stored in container.
                 if (DB::isError($pwd)) {
                     include_once 'PEAR.php';
                     return PEAR::throwError($pwd->getMessage(), $pwd->getCode());
                 }
                 if ($this->options['cryptType'] == 'none') {
                     $a1 = md5($this->username . ':' . $this->options['digestRealm'] . ':' . $pwd);
                 } else {
                     $a1 = $pwd;
                 }
                 $this->setAuthData('a1', $a1, true);
             } else {
                 $a1 = $this->getAuthData('a1');
             }
             $login_ok = $this->validateDigest($this->password, $a1);
             if ($this->nextNonce == false) {
                 $login_ok = false;
             }
         }
         if (!$login_ok && is_callable($this->loginFailedCallback)) {
             call_user_func($this->loginFailedCallback, $this->username, $this);
         }
     }
     if (!empty($this->username) && $login_ok) {
         $this->setAuth($this->username);
         if (is_callable($this->loginCallback)) {
             call_user_func($this->loginCallback, $this->username, $this);
         }
     }
     /**
      * If the login failed or the user entered no username,
      * output the login screen again.
      */
     if (!empty($this->username) && !$login_ok) {
         $this->status = AUTH_WRONG_LOGIN;
     }
     if ((empty($this->username) || !$login_ok) && $this->showLogin) {
         $this->drawLogin($this->storage->activeUser);
         return;
     }
     if (!empty($this->username) && $login_ok && $this->authType == 'digest' && $this->auth['qop'] == 'auth') {
         $this->authenticationInfo();
     }
 }
Exemple #9
0
 /**
  * Constructor
  *
  * If an error is encountered during instantiation, the error
  * message is stored in the $this->error property of the resulting
  * object. See $error property docblock for a discussion of error
  * handling. 
  * 
  * @param  object &$db   DB/MDB2 database connection object
  * @param  string $name the database name
  * @return object DB_Table_Database
  * @access public
  */
 function DB_Table_Database(&$db, $name)
 {
     // Is $db an DB/MDB2 object or null?
     if (is_a($db, 'db_common')) {
         $this->backend = 'db';
         $this->fetchmode = DB_FETCHMODE_ORDERED;
     } elseif (is_a($db, 'mdb2_driver_common')) {
         $this->backend = 'mdb2';
         $this->fetchmode = MDB2_FETCHMODE_ORDERED;
     } else {
         $code = DB_TABLE_DATABASE_ERR_DB_OBJECT;
         $text = $GLOBALS['_DB_TABLE_DATABASE']['error'][$code] . ' DB_Table_Database';
         $this->error = PEAR::throwError($text, $code);
         return;
     }
     $this->db =& $db;
     $this->name = $name;
     $this->_primary_subclass = 'DB_TABLE_DATABASE';
     $this->setFixCase(false);
 }
Exemple #10
0
 /**
  * 
  * Specialized version of throwError() modeled on PEAR_Error.
  * 
  * Throws a PEAR_Error with a DB_Table error message based on a
  * DB_Table constant error code.
  * 
  * @static
  * 
  * @access public
  * 
  * @param string $code A DB_Table error code constant.
  * 
  * @param string $extra Extra text for the error (in addition to the 
  * regular error message).
  * 
  * @return object PEAR_Error
  * 
  */
 function &throwError($code, $extra = null)
 {
     // get the error message text based on the error code
     $text = $GLOBALS['_DB_TABLE']['error'][$code];
     // add any additional error text
     if ($extra) {
         $text .= ' ' . $extra;
     }
     // done!
     $error = PEAR::throwError($text, $code);
     return $error;
 }
Exemple #11
0
 /**
  * Constructor
  *
  * Set up the storage driver.
  *
  * @param string    Type of the storage driver
  * @param mixed     Additional options for the storage driver
  *                  (example: if you are using DB as the storage
  *                   driver, you have to pass the dsn string here)
  *
  * @param string    Name of the function that creates the login form
  * @param boolean   Should the login form be displayed if neccessary?
  * @return void
  */
 function Auth($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
 {
     $this->applyAuthOptions($options);
     // Start the session suppress error if already started
     if (!session_id()) {
         @session_start();
         if (!session_id()) {
             // Throw error
             include_once 'lib/pear/PEAR.php';
             PEAR::throwError('Session could not be started by Auth, ' . 'possibly headers are already sent, try putting ' . 'ob_start in the beginning of your script');
         }
     }
     // Make Sure Auth session variable is there
     if (!isset($_SESSION[$this->_sessionName])) {
         $_SESSION[$this->_sessionName] = array();
     }
     // Assign Some globals to internal references, this will replace _importGlobalVariable
     $this->session =& $_SESSION[$this->_sessionName];
     $this->server =& $_SERVER;
     $this->post =& $_POST;
     $this->cookie =& $_COOKIE;
     if ($loginFunction != '' && is_callable($loginFunction)) {
         $this->loginFunction = $loginFunction;
     }
     if (is_bool($showLogin)) {
         $this->showLogin = $showLogin;
     }
     if (is_object($storageDriver)) {
         $this->storage =& $storageDriver;
         // Pass a reference to auth to the container, ugly but works
         // this is used by the DB container to use method setAuthData not staticaly.
         $this->storage->_auth_obj =& $this;
     } else {
         // $this->storage = $this->_factory($storageDriver, $options);
         //
         $this->storage_driver = $storageDriver;
         $this->storage_options =& $options;
     }
 }
Exemple #12
0
 /**
  * Factory for Net_Traceroute_Result
  *
  * @param  array  $result      Net_Traceroute result
  * @param  string $sysname     OS_Guess::sysname
  * @access public
  */
 function factory($result, $sysname)
 {
     if (!Net_Traceroute_Result::_prepareParseResult($sysname)) {
         return PEAR::throwError(NET_TRACEROUTE_RESULT_UNSUPPORTED_BACKEND_MSG, NET_TRACEROUTE_RESULT_UNSUPPORTED_BACKEND);
     } else {
         return new Net_Traceroute_Result($result, $sysname);
     }
 }
Exemple #13
0
 /**
  *
  * Simple error-object generator.
  *
  * @access public
  *
  * @param string $message The error message.
  *
  * @return object PEAR_Error
  *
  */
 function &error($message)
 {
     throw new ProcessException($message);
     // FIX?
     if (!class_exists('PEAR_Error')) {
         include_once 'PEAR.php';
     }
     return PEAR::throwError($message);
 }
 /**
  *
  * Simple error-object generator.
  *
  * @access public
  *
  * @param string $message The error message.
  *
  * @return object PEAR_Error
  *
  */
 function &error($message)
 {
     if (!class_exists('PEAR_Error')) {
         include_once 'PEAR.php';
     }
     return PEAR::throwError($message);
 }
Exemple #15
0
 /**
  * Checks if all necessary parameters for a driver's configuration are set
  * and returns a PEAR_Error if something is missing.
  *
  * @param array $params   The configuration array with all parameters.
  * @param array $fields   An array with mandatory parameter names for this
  *                        driver.
  * @param string $name    The clear text name of the driver. If not
  *                        specified, the application name will be used.
  * @param array $info     A hash containing detailed information about the
  *                        driver. Will be passed as the userInfo to the
  *                        PEAR_Error.
  */
 function assertDriverConfig($params, $fields, $name, $info = array())
 {
     $info = array_merge($info, array('params' => $params, 'fields' => $fields, 'name' => $name));
     if (!is_array($params) || !count($params)) {
         require_once 'PEAR.php';
         return PEAR::throwError(sprintf(_("No configuration information specified for %s."), $name), HORDE_ERROR_DRIVER_CONFIG_MISSING, $info);
     }
     foreach ($fields as $field) {
         if (!isset($params[$field])) {
             require_once 'PEAR.php';
             return PEAR::throwError(sprintf(_("Required \"%s\" not specified in configuration."), $field, $name), HORDE_ERROR_DRIVER_CONFIG, $info);
         }
     }
 }
Exemple #16
0
 /**
  * Specialized version of throwError() modeled on PEAR_Error.
  * 
  * Throws a PEAR_Error with an error message based on an error code 
  * and corresponding error message defined in $this->_primary_subclass
  * 
  * @param string $code  An error code constant 
  * @param string $extra Extra text for the error (in addition to the 
  *                      regular error message).
  * @return object PEAR_Error
  * @access public
  * @static
  */
 function &throwError($code, $extra = null)
 {
     // get the error message text based on the error code
     $index = '_' . $this->_primary_subclass;
     $text = $this->_primary_subclass . " Error - \n" . $GLOBALS[$index]['error'][$code];
     // add any additional error text
     if ($extra) {
         $text .= ' ' . $extra;
     }
     // done!
     $error = PEAR::throwError($text, $code);
     return $error;
 }
Exemple #17
0
 /**
  * Simpler form of raiseError with fewer options.  In most cases
  * message, code and userinfo are enough.
  *
  * @param mixed $message a text error message or a PEAR error object
  *
  * @param int $code      a numeric error code (it is up to your class
  *                  to define these if you want to use codes)
  *
  * @param string $userinfo If you need to pass along for example debug
  *                  information, this parameter is meant for that.
  *
  * @return object   a PEAR error object
  * @see PEAR::raiseError
  * @uses PEAR::&throwError()
  */
 public function throwError($message = null, $code = null, $userinfo = null)
 {
     $tmp = $this->pear->throwError($message, $code, $userinfo);
     return $tmp;
 }