From 6e0d16f22b94bb528185d16d61c2ed93de38fcbd Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 15:16:55 +0100 Subject: [PATCH 1/6] Add warning message in case node.config.php isn't writable --- src/Core/Config/Util/ConfigFileManager.php | 27 ++++++++++++++++++++-- src/DI.php | 5 ++++ src/Module/Admin/Summary.php | 5 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Core/Config/Util/ConfigFileManager.php b/src/Core/Config/Util/ConfigFileManager.php index f9d3b32b6..8705bf76e 100644 --- a/src/Core/Config/Util/ConfigFileManager.php +++ b/src/Core/Config/Util/ConfigFileManager.php @@ -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 diff --git a/src/DI.php b/src/DI.php index 0ef18a1aa..6fd0e3a7a 100644 --- a/src/DI.php +++ b/src/DI.php @@ -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); diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 038628ee1..325e392a1 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -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 config/local.ini.php. See the Config help page 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; From f2253991e728a0afa1bcbc795f95492fc9f581d6 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 15:18:23 +0100 Subject: [PATCH 2/6] Update messages.po --- view/lang/C/messages.po | 73 ++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index d10d339fc..076587da7 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2023.03-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-01-05 10:33-0500\n" +"POT-Creation-Date: 2023-01-07 14:18+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2731,36 +2731,36 @@ msgstr "" msgid "Enter a valid existing folder" msgstr "" -#: src/Core/Update.php:70 +#: src/Core/Update.php:80 #, php-format msgid "" "Updates from version %s are not supported. Please update at least to version " "2021.01 and wait until the postupdate finished version 1383." msgstr "" -#: src/Core/Update.php:81 +#: src/Core/Update.php:91 #, php-format msgid "" "Updates from postupdate version %s are not supported. Please update at least " "to version 2021.01 and wait until the postupdate finished version 1383." msgstr "" -#: src/Core/Update.php:156 +#: src/Core/Update.php:186 #, php-format msgid "%s: executing pre update %d" msgstr "" -#: src/Core/Update.php:198 +#: src/Core/Update.php:228 #, php-format msgid "%s: executing post update %d" msgstr "" -#: src/Core/Update.php:272 +#: src/Core/Update.php:302 #, php-format msgid "Update %s failed. See error logs." msgstr "" -#: src/Core/Update.php:312 +#: src/Core/Update.php:342 #, php-format msgid "" "\n" @@ -2772,16 +2772,16 @@ msgid "" "might be invalid." msgstr "" -#: src/Core/Update.php:318 +#: src/Core/Update.php:348 #, php-format msgid "The error message is\\n[pre]%s[/pre]" msgstr "" -#: src/Core/Update.php:322 src/Core/Update.php:350 +#: src/Core/Update.php:352 src/Core/Update.php:380 msgid "[Friendica Notify] Database update" msgstr "" -#: src/Core/Update.php:344 +#: src/Core/Update.php:374 #, php-format msgid "" "\n" @@ -3265,7 +3265,7 @@ msgstr "" msgid "Title/Description:" msgstr "" -#: src/Model/Profile.php:1023 src/Module/Admin/Summary.php:217 +#: src/Model/Profile.php:1023 src/Module/Admin/Summary.php:222 #: src/Module/Moderation/Summary.php:77 msgid "Summary" msgstr "" @@ -3593,7 +3593,7 @@ msgstr "" #: src/Module/Admin/Federation.php:207 src/Module/Admin/Logs/Settings.php:79 #: src/Module/Admin/Logs/View.php:84 src/Module/Admin/Queue.php:72 #: src/Module/Admin/Site.php:435 src/Module/Admin/Storage.php:138 -#: src/Module/Admin/Summary.php:216 src/Module/Admin/Themes/Details.php:90 +#: src/Module/Admin/Summary.php:221 src/Module/Admin/Themes/Details.php:90 #: src/Module/Admin/Themes/Index.php:111 src/Module/Admin/Tos.php:77 #: src/Module/Moderation/Users/Create.php:61 #: src/Module/Moderation/Users/Pending.php:96 @@ -4976,12 +4976,12 @@ msgstr "" msgid "Database (legacy)" msgstr "" -#: src/Module/Admin/Summary.php:56 +#: src/Module/Admin/Summary.php:57 #, php-format msgid "Template engine (%s) error: %s" msgstr "" -#: src/Module/Admin/Summary.php:60 +#: src/Module/Admin/Summary.php:61 #, php-format msgid "" "Your DB still runs with MyISAM tables. You should change the engine type to " @@ -4992,7 +4992,7 @@ msgid "" "automatic conversion.
" msgstr "" -#: src/Module/Admin/Summary.php:65 +#: src/Module/Admin/Summary.php:66 #, php-format msgid "" "Your DB still runs with InnoDB tables in the Antelope file format. You " @@ -5003,7 +5003,7 @@ msgid "" "installation for an automatic conversion.
" msgstr "" -#: src/Module/Admin/Summary.php:75 +#: src/Module/Admin/Summary.php:76 #, php-format msgid "" "Your table_definition_cache is too low (%d). This can lead to the database " @@ -5011,39 +5011,39 @@ msgid "" "to %d. See here for more information.
" msgstr "" -#: src/Module/Admin/Summary.php:85 +#: src/Module/Admin/Summary.php:86 #, php-format msgid "" "There is a new version of Friendica available for download. Your current " "version is %1$s, upstream version is %2$s" msgstr "" -#: src/Module/Admin/Summary.php:94 +#: src/Module/Admin/Summary.php:95 msgid "" "The database update failed. Please run \"php bin/console.php dbstructure " "update\" from the command line and have a look at the errors that might " "appear." msgstr "" -#: src/Module/Admin/Summary.php:98 +#: src/Module/Admin/Summary.php:99 msgid "" "The last update failed. Please run \"php bin/console.php dbstructure update" "\" from the command line and have a look at the errors that might appear. " "(Some of the errors are possibly inside the logfile.)" msgstr "" -#: src/Module/Admin/Summary.php:103 +#: src/Module/Admin/Summary.php:104 msgid "The worker was never executed. Please check your database structure!" msgstr "" -#: src/Module/Admin/Summary.php:105 +#: src/Module/Admin/Summary.php:106 #, php-format msgid "" "The last worker execution was on %s UTC. This is older than one hour. Please " "check your crontab settings." msgstr "" -#: src/Module/Admin/Summary.php:110 +#: src/Module/Admin/Summary.php:111 #, php-format msgid "" "Friendica's configuration now is stored in config/local.config.php, please " @@ -5052,7 +5052,7 @@ msgid "" "with the transition." msgstr "" -#: src/Module/Admin/Summary.php:114 +#: src/Module/Admin/Summary.php:115 #, php-format msgid "" "Friendica's configuration now is stored in config/local.config.php, please " @@ -5061,7 +5061,14 @@ msgid "" "with the transition." msgstr "" -#: src/Module/Admin/Summary.php:120 +#: src/Module/Admin/Summary.php:119 +#, php-format +msgid "" +"Friendica's configuration store \"%s\" isn't writable. Beware that updates, " +"gui changes and console changes aren't working reliable." +msgstr "" + +#: src/Module/Admin/Summary.php:125 #, php-format msgid "" "%s is not reachable on your system. This is a severe " @@ -5069,50 +5076,50 @@ msgid "" "href=\"%s\">the installation page for help." msgstr "" -#: src/Module/Admin/Summary.php:138 +#: src/Module/Admin/Summary.php:143 #, php-format msgid "The logfile '%s' is not usable. No logging possible (error: '%s')" msgstr "" -#: src/Module/Admin/Summary.php:152 +#: src/Module/Admin/Summary.php:157 #, php-format msgid "The debug logfile '%s' is not usable. No logging possible (error: '%s')" msgstr "" -#: src/Module/Admin/Summary.php:168 +#: src/Module/Admin/Summary.php:173 #, php-format msgid "" "Friendica's system.basepath was updated from '%s' to '%s'. Please remove the " "system.basepath from your db to avoid differences." msgstr "" -#: src/Module/Admin/Summary.php:176 +#: src/Module/Admin/Summary.php:181 #, php-format msgid "" "Friendica's current system.basepath '%s' is wrong and the config file '%s' " "isn't used." msgstr "" -#: src/Module/Admin/Summary.php:184 +#: src/Module/Admin/Summary.php:189 #, php-format msgid "" "Friendica's current system.basepath '%s' is not equal to the config file " "'%s'. Please fix your configuration." msgstr "" -#: src/Module/Admin/Summary.php:195 +#: src/Module/Admin/Summary.php:200 msgid "Message queues" msgstr "" -#: src/Module/Admin/Summary.php:201 +#: src/Module/Admin/Summary.php:206 msgid "Server Settings" msgstr "" -#: src/Module/Admin/Summary.php:219 +#: src/Module/Admin/Summary.php:224 msgid "Version" msgstr "" -#: src/Module/Admin/Summary.php:223 +#: src/Module/Admin/Summary.php:228 msgid "Active addons" msgstr "" From b7a2b6b3527faa309a3498c887ee5c31cbdb7ce7 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 15:28:49 +0100 Subject: [PATCH 3/6] Update src/Module/Admin/Summary.php Co-authored-by: Hypolite Petovan --- src/Module/Admin/Summary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 325e392a1..e7c0dea51 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -116,7 +116,7 @@ class Summary extends BaseAdmin } 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); + $warningtext[] = DI::l10n()->t('Friendica\'s configuration store "%s" isn\'t writable. Until then database updates won't be applied automatically, admin settings and console configuration changes won't be saved.', ConfigFileManager::CONFIG_DATA_FILE); } // Check server vitality From 6e4e2c4a82384b614cda8b1fabe7288f117113c1 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 15:30:45 +0100 Subject: [PATCH 4/6] Fix warning text --- src/Core/Config/Util/ConfigFileManager.php | 5 ----- src/Module/Admin/Summary.php | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Core/Config/Util/ConfigFileManager.php b/src/Core/Config/Util/ConfigFileManager.php index 8705bf76e..9e07d27ae 100644 --- a/src/Core/Config/Util/ConfigFileManager.php +++ b/src/Core/Config/Util/ConfigFileManager.php @@ -245,11 +245,6 @@ 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 { diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index e7c0dea51..13ef0fd71 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -116,7 +116,7 @@ class Summary extends BaseAdmin } if (!DI::configFileManager()->dataIsWritable()) { - $warningtext[] = DI::l10n()->t('Friendica\'s configuration store "%s" isn\'t writable. Until then database updates won't be applied automatically, admin settings and console configuration changes won't be saved.', ConfigFileManager::CONFIG_DATA_FILE); + $warningtext[] = DI::l10n()->t('Friendica\'s configuration store "%s" isn\'t writable. Until then database updates won\'t be applied automatically, admin settings and console configuration changes won\'t be saved.', ConfigFileManager::CONFIG_DATA_FILE); } // Check server vitality From 6bd1740a94a694ca4fcb8ef21ee9536a80925f8f Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 15:49:55 +0100 Subject: [PATCH 5/6] omg .. wrong assertion .. --- src/Core/Config/Util/ConfigFileManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Config/Util/ConfigFileManager.php b/src/Core/Config/Util/ConfigFileManager.php index 9e07d27ae..f3627cf47 100644 --- a/src/Core/Config/Util/ConfigFileManager.php +++ b/src/Core/Config/Util/ConfigFileManager.php @@ -260,7 +260,7 @@ class ConfigFileManager * (as is the case with 'x'). The file pointer is positioned on the beginning of the file. * */ - if (($configStream = @fopen($filename, 'c+')) !== false) { + if (($configStream = @fopen($filename, 'c+')) === false) { throw new ConfigFileException(sprintf('Cannot open file "%s" in mode c+', $filename)); } From 7b30c44b60e943de7e8b2bb473247d4eaf2f8a7f Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 15:50:03 +0100 Subject: [PATCH 6/6] Update messages.po --- view/lang/C/messages.po | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 076587da7..091e61a7f 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2023.03-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-01-07 14:18+0000\n" +"POT-Creation-Date: 2023-01-07 14:32+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -5064,8 +5064,9 @@ msgstr "" #: src/Module/Admin/Summary.php:119 #, php-format msgid "" -"Friendica's configuration store \"%s\" isn't writable. Beware that updates, " -"gui changes and console changes aren't working reliable." +"Friendica's configuration store \"%s\" isn't writable. Until then database " +"updates won't be applied automatically, admin settings and console " +"configuration changes won't be saved." msgstr "" #: src/Module/Admin/Summary.php:125