Skip to content

Commit

Permalink
implment getUpdaterUrl to handle reverse proxy configurations via web…
Browse files Browse the repository at this point in the history
… root overwrite
  • Loading branch information
fermulator committed Nov 17, 2020
1 parent 61a84cc commit 3a6ead4
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

?>

<html>
Expand Down Expand Up @@ -2199,4 +2228,3 @@ function confirmExit() {
<?php endif; ?>

</html>

0 comments on commit 3a6ead4

Please sign in to comment.