diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 6b8d24ea..5c26bc2e 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -2701,6 +2701,9 @@ class LAMCfgMain { */ public function importData($data) { foreach ($data as $dataKey => $dataValue) { + if (!(is_array($dataValue) || is_string($dataValue) || is_int($dataValue) || is_bool($dataValue))) { + throw new LAMException('Invalid import data type for ' . htmlspecialchars($dataKey) . ': ' . gettype($dataValue)); + } $this->$dataKey = $dataValue; } } diff --git a/lam/templates/config/confImportExport.php b/lam/templates/config/confImportExport.php new file mode 100644 index 00000000..d51b8cda --- /dev/null +++ b/lam/templates/config/confImportExport.php @@ -0,0 +1,168 @@ +checkPassword($_SESSION["mainconf_password"])) { + $exporter = new ConfigDataExporter(); + if (!headers_sent()) { + header('Content-Type: application/json; charset=utf-8'); + header('Content-disposition: attachment; filename=lam-config.json'); + } + echo $exporter->exportAsJson(); + exit; +} + +echo $_SESSION['header']; +printHeaderContents(_("Import and export configuration"), '../..'); + +?> + + + + + + + +
+ +
+
+

+ setCSSClasses(array('maxrow fullwidth roundedShadowBox spacing5')); + if ($message !== null) { + $loginContent->add($message, 12); + } + $pwdInput = new htmlResponsiveInputField(_("Master password"), 'password', '', '236'); + $pwdInput->setIsPassword(true); + $loginContent->add($pwdInput, 12); + $loginContent->addLabel(new htmlOutputText(' ', false)); + $loginContent->addField(new htmlButton('submitLogin', _("Ok"))); + + $content->add($loginContent, 12); + + parseHtml(null, $content, array(), false, $tabindex, null); + } + + /** + * Checks the login password. + * + * @param LAMCfgMain $cfg main config + * @return bool login ok + */ + function checkLogin($cfg) { + $password = $_POST['password']; + if ($cfg->checkPassword($password)) { + $_SESSION["mainconf_password"] = $password; + return true; + } + showLoginDialog(new htmlStatusMessage('ERROR', _('The password is invalid! Please try again.'))); + return false; + } + + /** + * Displays the import/export functions. + * + * @param LAMCfgMain $cfg main config + */ + function displayImportExport($cfg) { + $tabindex = 0; + $content = new htmlResponsiveRow(); + + $content->add(new htmlSubTitle(_('Export')), 12); + $content->add(new htmlButton('exportConfig', _('Export')), 12); + + $content->add(new htmlSubTitle(_('Import')), 12); + + parseHtml(null, $content, array(), false, $tabindex, null); + } + + ?> +
+ + diff --git a/lam/templates/config/index.php b/lam/templates/config/index.php index 939a72e2..d6c2360c 100644 --- a/lam/templates/config/index.php +++ b/lam/templates/config/index.php @@ -1,4 +1,7 @@ setCSSClasses(array('img-padding1 display-as-block')); $topContent->add($selfServiceLink, 12); } + if (isDeveloperVersion(LAMVersion())) { + $topContent->addVerticalSpacer('1rem'); + $importExportLink = new htmlLink(_("Import and export configuration"), 'confImportExport.php', '../../graphics/confImportExport.png'); + $importExportLink->setCSSClasses(array('img-padding1 display-as-block')); + $topContent->add($importExportLink, 12); + } $content->add($topContent, 12); $content->addVerticalSpacer('4rem'); ?> diff --git a/lam/tests/lib/LAMCfgMainTest.php b/lam/tests/lib/LAMCfgMainTest.php index 1b5bad13..1368311f 100644 --- a/lam/tests/lib/LAMCfgMainTest.php +++ b/lam/tests/lib/LAMCfgMainTest.php @@ -155,4 +155,18 @@ class LAMCfgMainTest extends TestCase { $this->assertEquals('mailserver', $this->conf->mailServer); } + /** + * Tests the import with invalid data. + */ + public function testImportData_invalid() { + $importData = array(); + $importData['passwordMinLower'] = 3; + $importData['sessionTimeout'] = 240; + $importData['logLevel'] = LOG_ERR; + $importData['mailServer'] = new LAMLanguage('de_de', 'UTF-8', 'DE'); + + $this->expectException(LAMException::class); + $this->conf->importData($importData); + } + } \ No newline at end of file diff --git a/lam/tests/lib/modules/persistenceTest.php b/lam/tests/lib/persistenceTest.php similarity index 96% rename from lam/tests/lib/modules/persistenceTest.php rename to lam/tests/lib/persistenceTest.php index 09eb98b0..1e511569 100644 --- a/lam/tests/lib/modules/persistenceTest.php +++ b/lam/tests/lib/persistenceTest.php @@ -22,7 +22,7 @@ use PHPUnit\Framework\TestCase; */ -include_once __DIR__ . '/../../../lib/persistence.inc'; +include_once __DIR__ . '/../../lib/persistence.inc'; /** * ConfigDataExporter test case.