Skip to content

Commit 3a6ead4

Browse files
committed
implment getUpdaterUrl to handle reverse proxy configurations via web root overwrite
1 parent 61a84cc commit 3a6ead4

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

index.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,37 @@ private function getChangelogURL($versionString) {
547547
return $changelogURL;
548548
}
549549

550+
/**
551+
* Gets the updater URL for this nextcloud instance
552+
* Supports reverse proxy configurations (overwrite*)
553+
* @return string
554+
*/
555+
public function getUpdaterUrl() {
556+
$this->silentLog('[info] getUpdaterUrl()');
557+
558+
// Start from the request URI of the server, and get our updater sub-path
559+
// from the URI, typically this is "/updater/"
560+
$updaterUrl = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
561+
$this->silentLog('[debug] getUpdaterUrl() initial from _SERVER array: ' . $updaterUrl);
562+
563+
// Ensure updater URL is suffixed with /index.php
564+
if(strpos($updaterUrl, 'index.php') === false) {
565+
$updaterUrl = rtrim($updaterUrl, '/') . '/index.php';
566+
}
567+
$this->silentLog('[debug] getUpdaterUrl() after trimming and index.php suffix: ' . $updaterUrl);
568+
569+
// Support reverse proxy configuration
570+
// https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/reverse_proxy_configuration.html#overwrite-parameters
571+
$overwriteWebRootConfig = $this -> getConfigOption('overwritewebroot');
572+
if(!empty($overwriteWebRootConfig)) {
573+
$this->silentLog('[info] getUpdaterUrl() detected overwrite web root configuration >' . $overwriteWebRootConfig . '<, updating for reverse proxy');
574+
$updaterUrl = $overwriteWebRootConfig . $updaterUrl;
575+
}
576+
$this->silentLog('[info] getUpdaterUrl() final: ' . $updaterUrl);
577+
578+
return $updaterUrl;
579+
}
580+
550581
/**
551582
* @return array
552583
* @throws \Exception
@@ -1411,10 +1442,8 @@ public function logVersion() {
14111442

14121443
$updater->log('[info] show HTML page');
14131444
$updater->logVersion();
1414-
$updaterUrl = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
1415-
if(strpos($updaterUrl, 'index.php') === false) {
1416-
$updaterUrl = rtrim($updaterUrl, '/') . '/index.php';
1417-
}
1445+
$updaterUrl = $updater->getUpdaterUrl();
1446+
14181447
?>
14191448

14201449
<html>
@@ -2199,4 +2228,3 @@ function confirmExit() {
21992228
<?php endif; ?>
22002229

22012230
</html>
2202-

0 commit comments

Comments
 (0)