Merge pull request #475 from LDAPAccountManager/feature/389_config_format

#389 enforce new configuration file format
This commit is contained in:
gruberroland 2025-09-18 07:54:01 +02:00 committed by GitHub
commit 9fd2a75264
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 71 deletions

View file

@ -1,4 +1,5 @@
December 2025 9.4 December 2025 9.4
- Main configuration and server profiles require latest file format (introduced in 9.0) (389)
- LAM Pro: - LAM Pro:
-> SMS sending can be done with email2SMS providers (465) -> SMS sending can be done with email2SMS providers (465)

View file

@ -608,6 +608,18 @@
version. Unless explicitly noticed there is no need to install an version. Unless explicitly noticed there is no need to install an
intermediate release.</para> intermediate release.</para>
<section>
<title>9.3 -&gt; 9.4</title>
<para><emphasis role="bold">New configuration format for main
configuration and server profiles is enforced.</emphasis> Please save your main
configuration and all server profiles with LAM 9.0 - 9.3 before
upgrading. You can also export your configuration and import all
server profiles and main configuration. This format change does not
apply if you use MySQL for configuration
storage.</para>
</section>
<section> <section>
<title>9.2 -&gt; 9.3</title> <title>9.2 -&gt; 9.3</title>

View file

@ -570,66 +570,19 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS
$config = new LAMConfig(); $config = new LAMConfig();
$confFilePath = $this->getPath($name); $confFilePath = $this->getPath($name);
if (!is_file($confFilePath)) { if (!is_file($confFilePath)) {
logNewMessage(LOG_ERR, 'No such file ' . $confFilePath);
throw new LAMException(_('Unable to read file.')); throw new LAMException(_('Unable to read file.'));
} }
$file = @fopen($confFilePath, "r"); $file = @fopen($confFilePath, "r");
if (!$file) { if (!$file) {
logNewMessage(LOG_ERR, 'Unable to open for reading: ' . $confFilePath);
throw new LAMException(_('Unable to read file.')); throw new LAMException(_('Unable to read file.'));
} }
$json = fread($file, 1000000); $json = fread($file, 1000000);
$data = json_decode($json, true); $data = json_decode($json, true);
if ($data === null) { if ($data === null) {
fclose($file); logNewMessage(LOG_ERR, 'Unable to read JSON from ' . $confFilePath);
$file = @fopen($confFilePath, "r"); throw new LAMException(_('Unable to read file.'));
$data = [];
$moduleSettings = [];
$typeSettings = [];
$toolSettings = [];
$jobSettings = [];
while (!feof($file)) {
$line = fgets($file, 1000000);
$line = trim($line); // remove spaces at the beginning and end
if (($line === "") || ($line[0] === "#")) {
continue; // ignore comments and empty lines
}
// search keywords
$parts = explode(': ', $line);
$keyword = $parts[0];
$keyword = trim($keyword, ':');
$startIndex = strlen($keyword) + 2;
$value = (count($parts) > 1) ? substr($line, $startIndex) : '';
if (!in_array($keyword, ['modules', 'types', 'tools', 'jobs'])) {
$data[$keyword] = $value;
}
else {
$subKeyword = $parts[1];
$startIndex = $startIndex + strlen($subKeyword) + 2;
$option = substr($line, $startIndex);
if (empty($option)) {
continue;
}
// module settings
if ($keyword === 'modules') {
$moduleSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option);
}
// type settings
if ($keyword === 'types') {
$typeSettings[$subKeyword] = $option;
}
// tool settings
if ($keyword === 'tools') {
$toolSettings[$subKeyword] = $option;
}
// job settings
if ($keyword === 'jobs') {
$jobSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option);
}
}
}
$data['moduleSettings'] = $moduleSettings;
$data['typeSettings'] = $typeSettings;
$data['toolSettings'] = $toolSettings;
$data['jobSettings'] = $jobSettings;
} }
fclose($file); fclose($file);
$config->importData($data); $config->importData($data);
@ -3211,25 +3164,7 @@ class LAMCfgMain {
$this->importData($data); $this->importData($data);
} }
else { else {
// fallback to old format throw new LAMException(_('The config file is not readable.'));
fclose($file);
$file = @fopen($this->conffile, "r");
while (!feof($file)) {
$line = fgets($file, 1000000);
$line = trim($line); // remove spaces at the beginning and end
if (($line === "") || ($line[0] === "#")) {
continue; // ignore comments
}
// search keywords
for ($i = 0; $i < count($this->settings); $i++) {
$keyword = $this->settings[$i];
$keylen = strlen($keyword);
if (strtolower(substr($line, 0, $keylen + 2)) === strtolower($keyword . ": ")) {
$this->$keyword = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
break;
}
}
}
} }
fclose($file); fclose($file);
} }

View file

@ -215,7 +215,7 @@ setlanguage(); // setting correct language
* @throws LAMException error rendering login page * @throws LAMException error rendering login page
*/ */
function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $error_message, ?string $errorDetails = null, ?string $extraMessage = null): void { function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $error_message, ?string $errorDetails = null, ?string $extraMessage = null): void {
$config_object = $_SESSION['config']; $config_object = $_SESSION['config'] ?? null;
$cfgMain = $_SESSION["cfgMain"]; $cfgMain = $_SESSION["cfgMain"];
if (!($cfgMain instanceof LAMCfgMain)) { if (!($cfgMain instanceof LAMCfgMain)) {
die(); die();
@ -263,6 +263,9 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
echo "<br>"; echo "<br>";
} }
} }
elseif ($error_message !== null) {
StatusMessage("ERROR", $error_message);
}
else { else {
StatusMessage('WARN', _('Please enter the configuration and create a server profile.')); StatusMessage('WARN', _('Please enter the configuration and create a server profile.'));
} }

View file

@ -36,6 +36,9 @@ function testCreateDefaultConfig() {
unlink($cfgPath); unlink($cfgPath);
} }
touch($cfgPath); touch($cfgPath);
$fileHandle = fopen($cfgPath, 'w');
fwrite($fileHandle, '{}');
fclose($fileHandle);
$serverProfilePersistenceManager = new ServerProfilePersistenceManager(); $serverProfilePersistenceManager = new ServerProfilePersistenceManager();
$config = $serverProfilePersistenceManager->loadProfile(LAMConfigTest::FILE_NAME); $config = $serverProfilePersistenceManager->loadProfile(LAMConfigTest::FILE_NAME);
$_SESSION['config'] = $config; $_SESSION['config'] = $config;