Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement getUpdaterUrl to handle reverse proxy configurations #312

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>

31 changes: 31 additions & 0 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down