示例#1
0
 public function execute()
 {
     try {
         $socket = rex_socket::factoryUrl($this->getParam('url'));
         if ($this->getParam('http-auth') == '|1|') {
             $socket->addBasicAuthorization($this->getParam('user'), $this->getParam('password'));
         }
         if (($post = $this->getParam('post')) != '') {
             $response = $socket->doPost($post);
         } else {
             $response = $socket->doGet();
         }
         $statusCode = $response->getStatusCode();
         $success = $response->isSuccessful();
         $message = $statusCode . ' ' . $response->getStatusMessage();
         if (in_array($statusCode, [301, 302, 303, 307]) && $this->getParam('redirect', true) && ($location = $response->getHeader('Location'))) {
             // maximal eine Umleitung zulassen
             $this->setParam('redirect', false);
             $this->setParam('url', $location);
             // rekursiv erneut ausfuehren
             $success = $this->execute();
             if ($this->hasMessage()) {
                 $message .= ' -> ' . $this->getMessage();
             } else {
                 $message .= ' -> Unknown error';
             }
         }
         $this->setMessage($message);
         return $success;
     } catch (rex_exception $e) {
         $this->setMessage($e->getMessage());
         return false;
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 protected function openConnection()
 {
     parent::openConnection();
     if ($this->destinationSsl) {
         $headers = ['Host' => $this->destinationHost . ':' . $this->destinationPort, 'Proxy-Connection' => 'Keep-Alive'];
         $response = $this->writeRequest('CONNECT', $this->destinationHost . ':' . $this->destinationPort, $headers);
         if (!$response->isOk()) {
             throw new rex_socket_exception(sprintf('Couldn\'t connect to proxy server, server responds with "%s %s"'), $response->getStatusCode(), $response->getStatusMessage());
         }
         stream_socket_enable_crypto($this->stream, true, STREAM_CRYPTO_METHOD_SSLv3_CLIENT);
     } else {
         unset($this->headers['Connection']);
         $this->addHeader('Proxy-Connection', 'Close');
         $this->path = 'http://' . $this->destinationHost . ':' . $this->destinationPort . $this->path;
     }
 }
示例#3
0
 public function testFactoryUrlProxy()
 {
     rex::setProperty('socket_proxy', 'proxy.example.com:8888');
     $socket = rex_socket::factoryUrl('www.example.com');
     $this->assertEquals('rex_socket_proxy', get_class($socket));
 }
示例#4
0
 public static function delete($path)
 {
     global $I18N;
     $fullpath = self::PATH . self::getPath($path);
     $error = null;
     try {
         $socket = rex_socket::factory(self::HOST, self::PORT, self::SSL);
         $socket->setPath($fullpath);
         $response = $socket->doDelete();
         if ($response->isOk()) {
             $data = json_decode($response->getBody(), true);
             if (!isset($data['error']) || !is_string($data['error'])) {
                 return;
             }
             $error = $I18N->msg('install_webservice_error') . '<br />' . $data['error'];
         }
     } catch (rex_socket_exception $e) {
     }
     if (!$error) {
         $error = $I18N->msg('install_webservice_unreachable');
     }
     throw new rex_install_functional_exception($error);
 }