Skip to content

Commit

Permalink
Merge pull request #350 from nextcloud/backport/331/stable19
Browse files Browse the repository at this point in the history
[stable19] Disable UI when web updater is disabled in config.php
  • Loading branch information
MorrisJobke authored Mar 23, 2021
2 parents 7399854 + 64150d1 commit 068bc03
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class Updater {
private $updateAvailable = false;
/** @var string */
private $requestID = null;
/** @var bool */
private $disabled = false;

/**
* Updater constructor
Expand All @@ -175,6 +177,12 @@ public function __construct($baseDir) {
require_once $configFileName;
$this->configValues = $CONFIG;

if (php_sapi_name() !== 'cli' && ($this->configValues['upgrade.disable-web'] ?? false)) {
// updater disabled
$this->disabled = true;
return;
}

$dataDir = $this->getDataDirectoryLocation();
if(empty($dataDir) || !is_string($dataDir)) {
throw new \Exception('Could not read data directory from config.php.');
Expand Down Expand Up @@ -210,6 +218,15 @@ public function __construct($baseDir) {
$this->buildTime = $buildTime;
}

/**
* Returns whether the web updater is disabled
*
* @return bool
*/
public function isDisabled() {
return $this->disabled;
}

/**
* Returns current version or "unknown" if this could not be determined.
*
Expand Down Expand Up @@ -1279,8 +1296,13 @@ public function logVersion() {
// Check if the config.php is at the expected place
try {
$updater = new Updater(__DIR__);
if ($updater->isDisabled()) {
http_response_code(403);
die('Updater is disabled, please use the command line');
}
} catch (\Exception $e) {
// logging here is not possible because we don't know the data directory
http_response_code(500);
die($e->getMessage());
}

Expand Down
17 changes: 17 additions & 0 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Updater {
private $updateAvailable = false;
/** @var string */
private $requestID = null;
/** @var bool */
private $disabled = false;

/**
* Updater constructor
Expand All @@ -58,6 +60,12 @@ public function __construct($baseDir) {
require_once $configFileName;
$this->configValues = $CONFIG;

if (php_sapi_name() !== 'cli' && ($this->configValues['upgrade.disable-web'] ?? false)) {
// updater disabled
$this->disabled = true;
return;
}

$dataDir = $this->getDataDirectoryLocation();
if(empty($dataDir) || !is_string($dataDir)) {
throw new \Exception('Could not read data directory from config.php.');
Expand Down Expand Up @@ -93,6 +101,15 @@ public function __construct($baseDir) {
$this->buildTime = $buildTime;
}

/**
* Returns whether the web updater is disabled
*
* @return bool
*/
public function isDisabled() {
return $this->disabled;
}

/**
* Returns current version or "unknown" if this could not be determined.
*
Expand Down

0 comments on commit 068bc03

Please sign in to comment.