Add warning message in case node.config.php isn't writable

This commit is contained in:
Philipp Holzer 2023-01-07 15:16:55 +01:00
parent 308618b559
commit 6e0d16f22b
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432
3 changed files with 35 additions and 2 deletions

View file

@ -218,6 +218,22 @@ class ConfigFileManager
}
}
/**
* Checks, if the node.config.php is writable
*
* @return bool
*/
public function dataIsWritable(): bool
{
$filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
if (file_exists($filename)) {
return is_writable($filename);
} else {
return is_writable($this->configDir);
}
}
/**
* Saves overridden config entries back into the data.config.php
*
@ -229,6 +245,11 @@ class ConfigFileManager
{
$filename = $this->configDir . '/' . self::CONFIG_DATA_FILE;
// fail at a early stage, if we already know that we cannot save the data
if (!$this->dataIsWritable()) {
throw new ConfigFileException(sprintf('Cannot open file "%s" in mode c+', $filename));
}
if (file_exists($filename)) {
$fileExists = true;
} else {
@ -238,13 +259,15 @@ class ConfigFileManager
/**
* Creates a read-write stream
*
* @see https://www.php.net/manual/en/function.fopen.php
* @see https://www.php.net/manual/en/function.fopen.php
* @note Open the file for reading and writing. If the file does not exist, it is created.
* If it exists, it is neither truncated (as opposed to 'w'), nor the call to this function fails
* (as is the case with 'x'). The file pointer is positioned on the beginning of the file.
*
*/
$configStream = fopen($filename, 'c+');
if (($configStream = @fopen($filename, 'c+')) !== false) {
throw new ConfigFileException(sprintf('Cannot open file "%s" in mode c+', $filename));
}
try {
// We do want an exclusive lock, so we wait until every LOCK_SH (config reading) is unlocked

View file

@ -181,6 +181,11 @@ abstract class DI
return self::$dice->create(Core\Config\Capability\IManageConfigValues::class);
}
public static function configFileManager(): Core\Config\Util\ConfigFileManager
{
return self::$dice->create(Core\Config\Util\ConfigFileManager::class);
}
public static function keyValue(): Core\KeyValueStorage\Capabilities\IManageKeyValuePairs
{
return self::$dice->create(Core\KeyValueStorage\Capabilities\IManageKeyValuePairs::class);

View file

@ -23,6 +23,7 @@ namespace Friendica\Module\Admin;
use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
@ -114,6 +115,10 @@ class Summary extends BaseAdmin
$warningtext[] = DI::l10n()->t('Friendica\'s configuration now is stored in config/local.config.php, please copy config/local-sample.config.php and move your config from <code>config/local.ini.php</code>. See <a href="%s">the Config help page</a> for help with the transition.', DI::baseUrl()->get() . '/help/Config');
}
if (!DI::configFileManager()->dataIsWritable()) {
$warningtext[] = DI::l10n()->t('Friendica\'s configuration store "%s" isn\'t writable. Beware that updates, gui changes and console changes aren\'t working reliable.', ConfigFileManager::CONFIG_DATA_FILE);
}
// Check server vitality
if (!self::checkSelfHostMeta()) {
$well_known = DI::baseUrl()->get() . Probe::HOST_META;