diff --git a/index.php b/index.php index 4ff85f48..09076ac2 100644 --- a/index.php +++ b/index.php @@ -547,6 +547,37 @@ private function getChangelogURL($versionString) { return $changelogURL; } + /** + * Gets the updater URL for this nextcloud instance + * Supports reverse proxy configurations (overwrite*) + * @return string + */ + public function getUpdaterUrl() { + $this->silentLog('[info] getUpdaterUrl()'); + + // Start from the request URI of the server, and get our updater sub-path + // from the URI, typically this is "/updater/" + $updaterUrl = explode('?', $_SERVER['REQUEST_URI'], 2)[0]; + $this->silentLog('[debug] getUpdaterUrl() initial from _SERVER array: ' . $updaterUrl); + + // Ensure updater URL is suffixed with /index.php + if(strpos($updaterUrl, 'index.php') === false) { + $updaterUrl = rtrim($updaterUrl, '/') . '/index.php'; + } + $this->silentLog('[debug] getUpdaterUrl() after trimming and index.php suffix: ' . $updaterUrl); + + // Support reverse proxy configuration + // https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/reverse_proxy_configuration.html#overwrite-parameters + $overwriteWebRootConfig = $this -> getConfigOption('overwritewebroot'); + if(!empty($overwriteWebRootConfig)) { + $this->silentLog('[info] getUpdaterUrl() detected overwrite web root configuration >' . $overwriteWebRootConfig . '<, updating for reverse proxy'); + $updaterUrl = $overwriteWebRootConfig . $updaterUrl; + } + $this->silentLog('[info] getUpdaterUrl() final: ' . $updaterUrl); + + return $updaterUrl; + } + /** * @return array * @throws \Exception @@ -1411,10 +1442,8 @@ public function logVersion() { $updater->log('[info] show HTML page'); $updater->logVersion(); -$updaterUrl = explode('?', $_SERVER['REQUEST_URI'], 2)[0]; -if(strpos($updaterUrl, 'index.php') === false) { - $updaterUrl = rtrim($updaterUrl, '/') . '/index.php'; -} +$updaterUrl = $updater->getUpdaterUrl(); + ?> @@ -2199,4 +2228,3 @@ function confirmExit() { - diff --git a/lib/Updater.php b/lib/Updater.php index e62b79f8..e6565abb 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -430,6 +430,37 @@ private function getChangelogURL($versionString) { return $changelogURL; } + /** + * Gets the updater URL for this nextcloud instance + * Supports reverse proxy configurations (overwrite*) + * @return string + */ + public function getUpdaterUrl() { + $this->silentLog('[info] getUpdaterUrl()'); + + // Start from the request URI of the server, and get our updater sub-path + // from the URI, typically this is "/updater/" + $updaterUrl = explode('?', $_SERVER['REQUEST_URI'], 2)[0]; + $this->silentLog('[debug] getUpdaterUrl() initial from _SERVER array: ' . $updaterUrl); + + // Ensure updater URL is suffixed with /index.php + if(strpos($updaterUrl, 'index.php') === false) { + $updaterUrl = rtrim($updaterUrl, '/') . '/index.php'; + } + $this->silentLog('[debug] getUpdaterUrl() after trimming and index.php suffix: ' . $updaterUrl); + + // Support reverse proxy configuration + // https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/reverse_proxy_configuration.html#overwrite-parameters + $overwriteWebRootConfig = $this -> getConfigOption('overwritewebroot'); + if(!empty($overwriteWebRootConfig)) { + $this->silentLog('[info] getUpdaterUrl() detected overwrite web root configuration >' . $overwriteWebRootConfig . '<, updating for reverse proxy'); + $updaterUrl = $overwriteWebRootConfig . $updaterUrl; + } + $this->silentLog('[info] getUpdaterUrl() final: ' . $updaterUrl); + + return $updaterUrl; + } + /** * @return array * @throws \Exception