Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php14
-rw-r--r--lib/WOPI/DiscoveryManager.php45
2 files changed, 55 insertions, 4 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 044e7ab4..7e86f801 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -188,18 +188,24 @@ class Application extends App {
if ($this->getContainer()->getServer()->getAppManager()->isEnabledForUser($CODEAppID)) {
$appConfig = $this->getContainer()->query(AppConfig::class);
$wopi_url = $appConfig->getAppValue('wopi_url');
+ $isCODEEnabled = strpos($wopi_url, 'proxy.php?req=') !== false;
- // Check if we have the wopi_url set currently
- if ($wopi_url !== null && $wopi_url !== '') {
+ // Check if we have the wopi_url set to custom currently
+ if ($wopi_url !== null && $wopi_url !== '' && $isCODEEnabled === false) {
return;
}
$urlGenerator = \OC::$server->getURLGenerator();
$relativeUrl = $urlGenerator->linkTo($CODEAppID, '') . 'proxy.php';
$absoluteUrl = $urlGenerator->getAbsoluteURL($relativeUrl);
- $wopi_url = $absoluteUrl . '?req=';
+ $new_wopi_url = $absoluteUrl . '?req=';
- $appConfig->setAppValue('wopi_url', $wopi_url);
+ // Check if the wopi url needs to be updated
+ if ($isCODEEnabled && $wopi_url === $new_wopi_url) {
+ return;
+ }
+
+ $appConfig->setAppValue('wopi_url', $new_wopi_url);
$appConfig->setAppValue('disable_certificate_verification', 'yes');
$discoveryManager = $this->getContainer()->query(DiscoveryManager::class);
diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php
index 585a0c76..d8d70b58 100644
--- a/lib/WOPI/DiscoveryManager.php
+++ b/lib/WOPI/DiscoveryManager.php
@@ -77,6 +77,9 @@ class DiscoveryManager {
$options['verify'] = false;
}
+ if ($this->isProxyStarting($wopiDiscovery))
+ $options['timeout'] = 180;
+
try {
return $client->get($wopiDiscovery, $options);
} catch (\Exception $e) {
@@ -88,4 +91,46 @@ class DiscoveryManager {
$this->cache->remove('discovery');
$this->discovery = null;
}
+
+ /**
+ * @return boolean indicating if proxy.php is in initialize or false otherwise
+ */
+ private function isProxyStarting($url) {
+ $usesProxy = false;
+ $proxyPos = strrpos($url, 'proxy.php');
+ if ($proxyPos === false)
+ $usesProxy = false;
+ else
+ $usesProxy = true;
+
+ if ($usesProxy === true) {
+ $statusUrl = substr($url, 0, $proxyPos);
+ $statusUrl = $statusUrl . 'proxy.php?status';
+
+ $client = $this->clientService->newClient();
+ $options = ['timeout' => 5, 'nextcloud' => ['allow_local_address' => true]];
+
+ if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') {
+ $options['verify'] = false;
+ }
+
+ try {
+ $response = $client->get($statusUrl, $options);
+
+ if ($response->getStatusCode() === 200) {
+ $body = json_decode($response->getBody(), true);
+
+ if ($body['status'] === 'starting'
+ || $body['status'] === 'stopped'
+ || $body['status'] === 'restarting') {
+ return true;
+ }
+ }
+ } catch (\Exception $e) {
+ // ignore
+ }
+ }
+
+ return false;
+ }
}