Inheritance: implements Zend_Http_Client_Adapter_Interface, implements Zend_Http_Client_Adapter_Stream
 public function validate($username, $password)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Options: ' . print_r($this->_options, true));
     }
     $url = isset($this->_options['url']) ? $this->_options['url'] : 'https://localhost/validate/check';
     $adapter = new Zend_Http_Client_Adapter_Socket();
     $adapter->setStreamContext($this->_options = array('ssl' => array('verify_peer' => isset($this->_options['ignorePeerName']) ? false : true, 'allow_self_signed' => isset($this->_options['allowSelfSigned']) ? true : false)));
     $client = new Zend_Http_Client($url, array('maxredirects' => 0, 'timeout' => 30));
     $client->setAdapter($adapter);
     $params = array('user' => $username, 'pass' => $password);
     $client->setParameterPost($params);
     try {
         $response = $client->request(Zend_Http_Client::POST);
     } catch (Zend_Http_Client_Adapter_Exception $zhcae) {
         Tinebase_Exception::log($zhcae);
         return Tinebase_Auth::FAILURE;
     }
     $body = $response->getBody();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Request: ' . $client->getLastRequest());
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Response: ' . $body);
     }
     if ($response->getStatus() !== 200) {
         return Tinebase_Auth::FAILURE;
     }
     $result = Tinebase_Helper::jsonDecode($body);
     if (isset($result['result']) && $result['result']['status'] === true && $result['result']['value'] === true) {
         return Tinebase_Auth::SUCCESS;
     } else {
         return Tinebase_Auth::FAILURE;
     }
 }
 /**
  * Constructor
  *
  * Accepts a Zend_Http_Client argument enabling the implementer to use
  * a custom client (custom stream context, etc). Unless specified, a
  * default client is used with some common stream context options
  *
  * @param Zend_Http_Client $client
  * @throws CheddarGetter_Client_Exception Throws an exception
  * if Zend_Http_Client is not available.
  */
 public function __construct(Zend_Http_Client $client = null)
 {
     if (!class_exists('Zend_Http_Client')) {
         throw new CheddarGetter_Client_Exception('Zend_Http_Client is not available.', CheddarGetter_Client_Exception::USAGE_INVALID);
     }
     // default client
     if (!$client) {
         $userAgent = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] . ' - CheddarGetter_Client PHP' : 'CheddarGetter_Client PHP';
         // socket adapter with custom stream context
         $options = array('http' => array('follow_location' => 0, 'max_redirects' => 0, 'timeout' => 100, 'user_agent' => $userAgent), 'ssl' => array('verify_peer' => true, 'allow_self_signed' => false));
         $adapter = new Zend_Http_Client_Adapter_Socket();
         $adapter->setStreamContext($options);
         $client = new Zend_Http_Client(null, array('userAgent' => $options['http']['user_agent'], 'timeout' => 120));
         $client->setAdapter($adapter);
     }
     $this->_client = $client;
 }
 /**
  * @param Enlight_Config $config
  * @see https://github.com/paypal/sdk-core-php
  * @return Zend_Http_Client_Adapter_Curl|Zend_Http_Client_Adapter_Socket
  */
 public static function createAdapterFromConfig($config)
 {
     $curl = $config->get('paypalCurl', true);
     $sslVersion = $config->get('paypalSslVersion', 0);
     $timeout = $config->get('paypalTimeout') ?: 60;
     $userAgent = 'Shopware/' . Shopware::VERSION;
     if ($curl && extension_loaded('curl')) {
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $adapter->setConfig(array('useragent' => $userAgent, 'timeout' => $timeout));
         if (!empty($config->paypalSandbox)) {
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
         }
         $adapter->setCurlOption(CURLOPT_TIMEOUT, $timeout);
         $adapter->setCurlOption(CURLOPT_SSLVERSION, $sslVersion);
         //$adapter->setCurlOption(CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
         //$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
         //$adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, 2);
     } else {
         $adapter = new Zend_Http_Client_Adapter_Socket();
         $adapter->setConfig(array('useragent' => $userAgent, 'timeout' => $timeout, 'ssltransport' => $sslVersion > 3 || $sslVersion == 1 ? 'tls' : 'ssl'));
     }
     return $adapter;
 }
Exemple #4
0
 /**
  * Close the connection to the server
  *
  */
 public function close()
 {
     parent::close();
     $this->negotiated = false;
 }
 /**
  * Close the connection to the server
  *
  */
 public function close()
 {
     $this->log("Closing socket\n\n");
     parent::close();
 }
Exemple #6
0
 /**
  * Send request to the proxy server
  *
  * @param string        $method
  * @param Zend_Uri_Http $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // If no proxy is set, fall back to default Socket adapter
     if (!$this->config['proxy_host']) {
         return parent::write($method, $uri, $http_ver, $headers, $body);
     }
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
     }
     $host = $this->config['proxy_host'];
     $port = $this->config['proxy_port'];
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
         throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong proxy server");
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n";
     // Add Proxy-Authorization header
     if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) {
         $headers['proxy-authorization'] = Zend_Http_Client::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']);
     }
     // Add all headers to the request string
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = ucfirst($k) . ": {$v}";
         }
         $request .= "{$v}\r\n";
     }
     // Add the request body
     $request .= "\r\n" . $body;
     // Send the request
     if (!fwrite($this->socket, $request)) {
         throw new Zend_Http_Client_Adapter_Exception("Error writing request to proxy server");
     }
     return $request;
 }
 /**
  * Read response from server
  *
  * @see Zend_Http_Client_Adapter_Socket::read()
  *
  * @return string
  */
 public function read()
 {
     $response = false;
     if (Mage::app()->useCache(self::CACHE_TYPE)) {
         $cache = $this->getCache();
         $cache->addData($this->_params);
         $cacheMode = $this->getConfigData('cache_mode');
         if ($cacheMode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_HTTP_PRIOR) {
             try {
                 $response = parent::read();
                 $cache->save($response);
             } catch (Zend_Http_Client_Adapter_Exception $e) {
                 $response = $cache->load();
             }
         } elseif ($cacheMode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_CACHE_PRIOR) {
             $response = $cache->loadById();
             if (!$response) {
                 try {
                     $response = parent::read();
                     $cache->save($response);
                 } catch (Zend_Http_Client_Adapter_Exception $e) {
                     $response = $cache->loadByTags();
                 }
             }
         } elseif ($cacheMode == PedroTeixeira_Correios_Model_Source_CacheMode::MODE_CACHE_ONLY) {
             $response = $cache->load();
         }
     } else {
         $response = parent::read();
     }
     return $response;
 }
 /**
  * Returns a reference to the REST client
  *
  * @return Zend_Rest_Client
  */
 public function getRestClient()
 {
     if ($this->_rest === null) {
         /**
          * @see Zend_Rest_Client
          */
         require_once 'Zend/Rest/Client.php';
         $this->_rest = new Zend_Rest_Client();
         /**
          * @see Zend_Http_Client
          */
         require_once 'Zend/Http/Client.php';
         $httpClient = new Zend_Http_Client($this->_baseUri, array('keepalive' => $this->_usePersistentConnections));
         /**
          * The Ticket Evolution Sandbox uses a self-signed certificate which,
          * by default is not allowed. If we are using https in the sandbox lets
          * tweak the options to allow this self-signed certificate.
          *
          * @link http://framework.zend.com/manual/en/zend.http.client.adapters.html Example 2
          */
         if (strpos($this->_baseUri, 'sandbox') !== false) {
             $streamOptions = array('ssl' => array('allow_self_signed' => true));
         } else {
             $streamOptions = array();
         }
         /**
          * Create an adapter object and attach it to the HTTP client
          *
          * @see Zend_Http_Client_Adapter_Socket
          */
         require_once 'Zend/Http/Client/Adapter/Socket.php';
         $adapter = new Zend_Http_Client_Adapter_Socket();
         $adapterConfig = array('persistent' => $this->_usePersistentConnections);
         $adapter->setConfig($adapterConfig);
         $httpClient->setAdapter($adapter);
         // Pass the streamOptions array to setStreamContext()
         $adapter->setStreamContext($streamOptions);
         $this->_rest->setHttpClient($httpClient);
     }
     return $this->_rest;
 }
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     $uri->setHost($this->_ip);
     return parent::write($method, $uri, $http_ver, $headers, $body);
 }
 /**
  * reads the RSS feeds and extracts the 'description' field from each one.
  * Uses caching and http conditional GET to ensure that the feed is only
  * read if it has been updated
  * 
  * @return array 
  */
 protected function _getFeedData()
 {
     //Get the  feed url from the configuration options
     $options = $this->_getConfigOptions();
     $feed_url = $options['feed']['url'];
     $cache_dir = $options['cache']['directory'];
     // set cache - this allows us to check whether the feed has been updated
     $cache = Zend_Cache::factory('Core', 'File', array('lifetime' => null), array('cache_dir' => $cache_dir));
     Zend_Feed_Reader::setCache($cache);
     // set Reader properties to allow Conditional GET Requests
     Zend_Feed_Reader::useHttpConditionalGet();
     // disable SSL peer  verification as it can cause problems from some isp's
     $options = array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true));
     $adapter = new Zend_Http_Client_Adapter_Socket();
     $adapter->setStreamContext($options);
     Zend_Feed_Reader::getHttpClient()->setAdapter($adapter);
     // interrogate the RSS feed
     try {
         $rss_data = Zend_Feed_Reader::import($feed_url);
     } catch (Zend_Feed_Exception $e) {
         // feed import failed
         Zend_Registry::get('logger')->log('Exception importing feed: ' . $e->getMessage(), Zend_Log::WARN);
         return null;
     } catch (Zend_Http_Client_Exception $e) {
         Zend_Registry::get('logger')->log('Error with URL: ' . $e->getMessage(), Zend_Log::WARN);
         return null;
     } catch (Exception $e) {
         Zend_Registry::get('logger')->log('Unknown error when reading feed: ' . $e->getMessage(), Zend_Log::WARN);
         return null;
     }
     $entries = array();
     // response status will be 200 if new data, 304 if not modified
     $last_response = Zend_Feed_Reader::getHttpClient()->getLastResponse();
     if ($last_response) {
         $response_status = $last_response->getStatus();
         // Only process if new data
         if (200 === $response_status) {
             foreach ($rss_data as $item) {
                 $entry['description'] = $item->getDescription();
                 $entries[] = $entry;
             }
             if ($this->_getVerbose()) {
                 $this->getResponse()->appendBody(new Zend_Date() . ': ' . count($entries) . ' new entries downloaded from rss feed' . PHP_EOL);
             }
         } else {
             if ($this->_getVerbose()) {
                 $this->getResponse()->appendBody(new Zend_Date() . ': ' . 'No new data found' . PHP_EOL);
             }
         }
     }
     return $entries;
 }