Skip to content

Commit

Permalink
build: index.php
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Aug 28, 2024
1 parent 0815975 commit 42e81d8
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,23 @@ public function __construct(string $baseDir) {
if (!file_exists($configFileName)) {
throw new \Exception('Could not find config.php. Is this file in the "updater" subfolder of Nextcloud?');
}
$filePointer = @fopen($configFileName, 'r');
if ($filePointer === false) {
throw new \Exception('Could not open config.php.');
}
if (!flock($filePointer, LOCK_SH)) {
throw new \Exception(sprintf('Could not acquire a shared lock on the config file'));
}

try {
/** @var array $CONFIG */
require_once $configFileName;
} finally {
// Close the file pointer and release the lock
flock($filePointer, LOCK_UN);
fclose($filePointer);
}

/** @var array $CONFIG */
require_once $configFileName;
$this->configValues = $CONFIG;

if (php_sapi_name() !== 'cli' && ($this->configValues['upgrade.disable-web'] ?? false)) {
Expand Down Expand Up @@ -403,15 +417,31 @@ public function setMaintenanceMode(bool $state): void {
if (!file_exists($configFileName)) {
throw new \Exception('Could not find config.php.');
}
/** @var array $CONFIG */
require $configFileName;

$filePointer = @fopen($configFileName, 'r');
if ($filePointer === false) {
throw new \Exception('Could not open config.php.');
}
if (!flock($filePointer, LOCK_SH)) {
throw new \Exception(sprintf('Could not acquire a shared lock on the config file'));
}

try {
/** @var array $CONFIG */
require $configFileName;
} finally {
// Close the file pointer and release the lock
flock($filePointer, LOCK_UN);
fclose($filePointer);
}

$CONFIG['maintenance'] = $state;
$content = "<?php\n";
$content .= '$CONFIG = ';
$content .= var_export($CONFIG, true);
$content .= ";\n";
$state = file_put_contents($configFileName, $content);
if ($state === false) {
$writeSuccess = file_put_contents($configFileName, $content, LOCK_EX);
if ($writeSuccess === false) {
throw new \Exception('Could not write to config.php');
}
$this->silentLog('[info] end of setMaintenanceMode()');
Expand Down

0 comments on commit 42e81d8

Please sign in to comment.