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

[stable21] Disable UI when web updater is disabled in config.php #351

Merged
merged 3 commits into from
Mar 23, 2021
Merged
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
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