Beispiel #1
0
 /**
  * send http post request
  *
  * @param string $url
  * @param array $fields data send by the request
  * @return array
  * @deprecated Use \OCP\Http\Client\IClientService
  */
 public function post($url, array $fields)
 {
     $client = $this->clientService->newClient();
     try {
         $response = $client->post($url, ['body' => $fields, 'connect_timeout' => 10]);
     } catch (\Exception $e) {
         return ['success' => false, 'result' => $e->getMessage()];
     }
     return ['success' => true, 'result' => $response->getBody()];
 }
	/**
	 * Checks if the ownCloud server can connect to the internet using HTTPS and HTTP
	 * @return bool
	 */
	private function isInternetConnectionWorking() {
		if ($this->config->getSystemValue('has_internet_connection', true) === false) {
			return false;
		}

		try {
			$client = $this->clientService->newClient();
			$client->get('https://www.owncloud.org/');
			$client->get('http://www.owncloud.org/');
			return true;
		} catch (\Exception $e) {
			return false;
		}
	}
 /**
  * Check if the used  SSL lib is outdated. Older OpenSSL and NSS versions do
  * have multiple bugs which likely lead to problems in combination with
  * functionality required by ownCloud such as SNI.
  *
  * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
  * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
  * @return string
  */
 private function isUsedTlsLibOutdated()
 {
     $versionString = $this->getCurlVersion();
     if (isset($versionString['ssl_version'])) {
         $versionString = $versionString['ssl_version'];
     } else {
         return '';
     }
     $features = (string) $this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
     if (OC_Util::getEditionString() !== '') {
         $features = (string) $this->l10n->t('Federated Cloud Sharing');
     }
     // Check if at least OpenSSL after 1.01d or 1.0.2b
     if (strpos($versionString, 'OpenSSL/') === 0) {
         $majorVersion = substr($versionString, 8, 5);
         $patchRelease = substr($versionString, 13, 6);
         if ($majorVersion === '1.0.1' && ord($patchRelease) < ord('d') || $majorVersion === '1.0.2' && ord($patchRelease) < ord('b')) {
             return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]);
         }
     }
     // Check if NSS and perform heuristic check
     if (strpos($versionString, 'NSS/') === 0) {
         try {
             $firstClient = $this->clientService->newClient();
             $firstClient->get('https://www.owncloud.org/');
             $secondClient = $this->clientService->newClient();
             $secondClient->get('https://owncloud.org/');
         } catch (ClientException $e) {
             if ($e->getResponse()->getStatusCode() === 400) {
                 return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]);
             }
         }
     }
     return '';
 }
Beispiel #4
0
 /**
  * Get the download url for an application from the OCS server
  * @param string $id
  * @param array $targetVersion The target ownCloud version
  * @return array|null an array of application data or null
  */
 public function getApplicationDownload($id, array $targetVersion)
 {
     if (!$this->isAppStoreEnabled()) {
         return null;
     }
     $url = $this->getAppStoreUrl() . '/content/download/' . urlencode($id) . '/1';
     $client = $this->httpClientService->newClient();
     try {
         $response = $client->get($url, ['timeout' => 5, 'query' => ['version' => implode('x', $targetVersion)]]);
     } catch (\Exception $e) {
         $this->logger->error(sprintf('Could not get application download URL: %s', $e->getMessage()), ['app' => 'core']);
         return null;
     }
     $data = $this->loadData($response->getBody(), 'application download URL');
     if ($data === null) {
         return null;
     }
     $tmp = $data->data->content;
     $app = [];
     if (isset($tmp->downloadlink)) {
         $app['downloadlink'] = (string) $tmp->downloadlink;
     } else {
         $app['downloadlink'] = '';
     }
     return $app;
 }
 /**
  * try http post first with https and then with http as a fallback
  *
  * @param string $remoteDomain
  * @param string $urlSuffix
  * @param array $fields post parameters
  * @return array
  * @throws \Exception
  */
 protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields)
 {
     $client = $this->httpClientService->newClient();
     $protocol = 'https://';
     $result = ['success' => false, 'result' => ''];
     $try = 0;
     while ($result['success'] === false && $try < 2) {
         $endpoint = $this->discoveryManager->getShareEndpoint($protocol . $remoteDomain);
         try {
             $response = $client->post($protocol . $remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, ['body' => $fields, 'timeout' => 10, 'connect_timeout' => 10]);
             $result['result'] = $response->getBody();
             $result['success'] = true;
             break;
         } catch (\Exception $e) {
             // if flat re-sharing is not supported by the remote server
             // we re-throw the exception and fall back to the old behaviour.
             // (flat re-shares has been introduced in ownCloud 9.1)
             if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
                 throw $e;
             }
             $try++;
             $protocol = 'http://';
         }
     }
     return $result;
 }
Beispiel #6
0
 /**
  * @param string $path
  * @param string $target
  */
 protected function uploadFile($path, $target)
 {
     $this->init();
     // invalidate
     $target = $this->cleanPath($target);
     $this->statCache->remove($target);
     $source = fopen($path, 'r');
     $this->httpClientService->newClient()->put($this->createBaseUri() . $this->encodePath($target), ['body' => $source, 'auth' => [$this->user, $this->password]]);
     $this->removeCachedFile($target);
 }
 /**
  * Test whether the specified remote is accessible
  *
  * @param string $remote
  * @return bool
  */
 protected function testUrl($remote)
 {
     try {
         $client = $this->clientService->newClient();
         $response = json_decode($client->get($remote, ['timeout' => 3, 'connect_timeout' => 3])->getBody());
         return !empty($response->version) && version_compare($response->version, '7.0.0', '>=');
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * check if URL point to a ownCloud server
  *
  * @param string $url
  * @return bool
  */
 public function isOwnCloudServer($url)
 {
     $isValidOwnCloud = false;
     $client = $this->httpClientService->newClient();
     $result = $client->get($url . '/status.php', ['timeout' => 3, 'connect_timeout' => 3]);
     if ($result->getStatusCode() === Http::STATUS_OK) {
         $isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody());
     }
     return $isValidOwnCloud;
 }
Beispiel #9
0
 /**
  * @codeCoverageIgnore
  * @param string $url
  * @return bool|resource|string
  */
 protected function getUrlContent($url)
 {
     try {
         $client = $this->clientService->newClient();
         $response = $client->get($url);
         return $response->getBody();
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * Check if the used  SSL lib is outdated. Older OpenSSL and NSS versions do
  * have multiple bugs which likely lead to problems in combination with
  * functionality required by ownCloud such as SNI.
  *
  * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546
  * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172
  * @return string
  */
 private function isUsedTlsLibOutdated()
 {
     // Appstore is disabled by default in EE
     $appStoreDefault = false;
     if (\OC_Util::getEditionString() === '') {
         $appStoreDefault = true;
     }
     // Don't run check when:
     // 1. Server has `has_internet_connection` set to false
     // 2. AppStore AND S2S is disabled
     if (!$this->config->getSystemValue('has_internet_connection', true)) {
         return '';
     }
     if (!$this->config->getSystemValue('appstoreenabled', $appStoreDefault) && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no' && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') {
         return '';
     }
     $versionString = $this->getCurlVersion();
     if (isset($versionString['ssl_version'])) {
         $versionString = $versionString['ssl_version'];
     } else {
         return '';
     }
     $features = (string) $this->l10n->t('installing and updating apps via the app store or Federated Cloud Sharing');
     if (!$this->config->getSystemValue('appstoreenabled', $appStoreDefault)) {
         $features = (string) $this->l10n->t('Federated Cloud Sharing');
     }
     // Check if at least OpenSSL after 1.01d or 1.0.2b
     if (strpos($versionString, 'OpenSSL/') === 0) {
         $majorVersion = substr($versionString, 8, 5);
         $patchRelease = substr($versionString, 13, 6);
         if ($majorVersion === '1.0.1' && ord($patchRelease) < ord('d') || $majorVersion === '1.0.2' && ord($patchRelease) < ord('b')) {
             return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['OpenSSL', $versionString, $features]);
         }
     }
     // Check if NSS and perform heuristic check
     if (strpos($versionString, 'NSS/') === 0) {
         try {
             $firstClient = $this->clientService->newClient();
             $firstClient->get('https://www.owncloud.org/');
             $secondClient = $this->clientService->newClient();
             $secondClient->get('https://owncloud.org/');
         } catch (ClientException $e) {
             if ($e->getResponse()->getStatusCode() === 400) {
                 return (string) $this->l10n->t('cURL is using an outdated %s version (%s). Please update your operating system or features such as %s will not work reliably.', ['NSS', $versionString, $features]);
             }
         }
     }
     return '';
 }
Beispiel #11
0
 /**
  * check if URL point to a ownCloud server
  *
  * @param string $url
  * @return bool
  */
 public function isOwnCloudServer($url)
 {
     $isValidOwnCloud = false;
     $client = $this->httpClientService->newClient();
     try {
         $result = $client->get($url . '/status.php', ['timeout' => 3, 'connect_timeout' => 3]);
         if ($result->getStatusCode() === Http::STATUS_OK) {
             $isValidOwnCloud = $this->checkOwnCloudVersion($result->getBody());
         }
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage(), ['app' => 'federation']);
         return false;
     }
     return $isValidOwnCloud;
 }
 /**
  * @return \OC_OCS_Result
  */
 public function sendReport()
 {
     $report = $this->getReport();
     $client = $this->clientService->newClient();
     $this->config->setAppValue('popularitycontestclient', 'last_sent', time());
     $this->config->setAppValue('popularitycontestclient', 'last_report', json_encode($report));
     try {
         $response = $client->post(self::SURVEY_SERVER_URL . 'ocs/v2.php/apps/popularitycontestserver/api/v1/survey', ['timeout' => 5, 'query' => ['data' => json_encode($report)]]);
     } catch (\Exception $e) {
         return new \OC_OCS_Result($report, Http::STATUS_INTERNAL_SERVER_ERROR);
     }
     if ($response->getStatusCode() === Http::STATUS_OK) {
         return new \OC_OCS_Result($report, 100);
     }
     return new \OC_OCS_Result($report, Http::STATUS_INTERNAL_SERVER_ERROR);
 }
Beispiel #13
0
 /**
  * @param string $url
  * @return bool
  */
 private function testRemoteUrl($url)
 {
     $cache = $this->memcacheFactory->create('files_sharing_remote_url');
     if ($cache->hasKey($url)) {
         return (bool) $cache->get($url);
     }
     $client = $this->httpClient->newClient();
     try {
         $result = $client->get($url, ['timeout' => 10, 'connect_timeout' => 10])->getBody();
         $data = json_decode($result);
         $returnValue = is_object($data) && !empty($data->version);
     } catch (ConnectException $e) {
         $returnValue = false;
     } catch (ClientException $e) {
         $returnValue = false;
     }
     $cache->set($url, $returnValue);
     return $returnValue;
 }
Beispiel #14
0
 /**
  * try http post first with https and then with http as a fallback
  *
  * @param string $url
  * @param array $fields post parameters
  * @return array
  */
 private function tryHttpPost($url, array $fields)
 {
     $client = $this->httpClientService->newClient();
     $protocol = 'https://';
     $result = ['success' => false, 'result' => ''];
     $try = 0;
     while ($result['success'] === false && $try < 2) {
         try {
             $response = $client->post($protocol . $url, ['body' => $fields]);
             $result['result'] = $response->getBody();
             $result['success'] = true;
             break;
         } catch (\Exception $e) {
             $try++;
             $protocol = 'http://';
         }
     }
     return $result;
 }
Beispiel #15
0
 /**
  * try http post first with https and then with http as a fallback
  *
  * @param string $remoteDomain
  * @param string $urlSuffix
  * @param array $fields post parameters
  * @return array
  */
 private function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields)
 {
     $client = $this->httpClientService->newClient();
     $protocol = 'https://';
     $result = ['success' => false, 'result' => ''];
     $try = 0;
     while ($result['success'] === false && $try < 2) {
         $endpoint = $this->discoveryManager->getShareEndpoint($protocol . $remoteDomain);
         try {
             $response = $client->post($protocol . $remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, ['body' => $fields]);
             $result['result'] = $response->getBody();
             $result['success'] = true;
             break;
         } catch (\Exception $e) {
             $try++;
             $protocol = 'http://';
         }
     }
     return $result;
 }
 /**
  * @param ICacheFactory $cacheFactory
  * @param IClientService $clientService
  */
 public function __construct(ICacheFactory $cacheFactory, IClientService $clientService)
 {
     $this->cache = $cacheFactory->create('ocs-discovery');
     $this->client = $clientService->newClient();
 }