checkPassword($_SESSION["mainconf_password"]))) {
require(__DIR__ . '/mainlogin.php');
exit();
}
if (isset($_POST['cancel'])) {
// back to login
metaRefresh('../login.php');
exit();
}
if (isset($_SESSION['header'])) {
echo $_SESSION['header'];
}
printHeaderContents(_("Edit general settings"), '../..');
?>
configDatabaseType = $_POST['configDatabaseType'];
$cfg->configDatabaseServer = $_POST['configDatabaseServer'];
$cfg->configDatabaseSSLCA = $_POST['configDatabaseSSLCA'];
$cfg->configDatabasePort = $_POST['configDatabasePort'];
$cfg->configDatabaseName = $_POST['configDatabaseName'];
$cfg->configDatabaseUser = $_POST['configDatabaseUser'];
$cfg->configDatabasePassword = $_POST['configDatabasePassword'];
if ($cfg->configDatabaseType === LAMCfgMain::DATABASE_MYSQL) {
$mySqlConfigOk = true;
if (empty($cfg->configDatabaseServer) || !get_preg($cfg->configDatabaseServer, 'hostname')) {
$errors[] = _('Please enter a valid database host name.');
$mySqlConfigOk = false;
}
if (empty($cfg->configDatabaseName)) {
$errors[] = _('Please enter a valid database name.');
$mySqlConfigOk = false;
}
if (empty($cfg->configDatabaseUser)) {
$errors[] = _('Please enter a valid database user.');
$mySqlConfigOk = false;
}
if (empty($cfg->configDatabasePassword)) {
$errors[] = _('Please enter a valid database password.');
$mySqlConfigOk = false;
}
if ($mySqlConfigOk) {
try {
$configurationDatabase = new ConfigurationDatabase($cfg);
$configurationDatabase->checkConnection();
}
catch (Exception $e) {
logNewMessage(LOG_ERR, 'Unable to connect to configuration database: ' . $e->getMessage());
$errors[] = _('Unable to connect to configuration database.');
}
}
}
}
// set master password
if (!empty($_POST['masterpassword'])) {
if (($_POST['masterpassword'] !== $_POST['masterpassword2'])) {
$errors[] = _("Master passwords are different.");
}
elseif (!isValidConfigurationPassword($_POST['masterpassword'])) {
$errors[] = _('Please enter at least 8 characters including letters, a number and a symbol.');
}
else {
$cfg->setPassword($_POST['masterpassword']);
$msg = _("New master password set successfully.");
unset($_SESSION["mainconf_password"]);
}
}
// set license
if (isLAMProVersion()) {
$licenseLines = explode("\n", $_POST['license']);
$licenseLines = array_map(trim(...), $licenseLines);
$cfg->setLicenseLines($licenseLines);
$cfg->licenseWarningType = $_POST['licenseWarningType'];
$cfg->licenseEmailFrom = $_POST['licenseEmailFrom'];
$cfg->licenseEmailTo = $_POST['licenseEmailTo'];
if ((($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_EMAIL) || ($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_ALL))
&& !get_preg($cfg->licenseEmailFrom, 'email')) {
$errors[] = _('Licence') . ': ' . _('From address') . ' - ' . _('Please enter a valid email address!');
}
if (($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_EMAIL) || ($cfg->licenseWarningType === LAMCfgMain::LICENSE_WARNING_ALL)) {
$toEmails = preg_split('/;[ ]*/', $cfg->licenseEmailTo);
if ($toEmails !== false) {
foreach ($toEmails as $toEmail) {
if (!get_preg($toEmail, 'email')) {
$errors[] = _('Licence') . ': ' . _('To address') . ' - ' . _('Please enter a valid email address!');
break;
}
}
}
}
}
// set session timeout
$cfg->sessionTimeout = intval($_POST['sessionTimeout']);
// set hide login error details
$cfg->hideLoginErrorDetails = (isset($_POST['hideLoginErrorDetails']) && ($_POST['hideLoginErrorDetails'] === 'on')) ? 'true' : 'false';
// set allowed hosts
if (isset($_POST['allowedHosts'])) {
$allowedHosts = $_POST['allowedHosts'];
$allowedHostsList = explode("\n", $allowedHosts);
$allowedHostsListNew = [];
foreach ($allowedHostsList as $allowedHostEntry) {
$allowedHostEntry = trim($allowedHostEntry);
// ignore empty lines
if ($allowedHostEntry === '') {
continue;
}
// check each line
$ipRegex = '/^[0-9a-f\\.:\\*]+$/i';
if (!preg_match($ipRegex, $allowedHostEntry) || (strlen($allowedHostEntry) > 45)) {
$errors[] = sprintf(_("The IP address %s is invalid!"), htmlspecialchars(str_replace('%', '%%', $allowedHostEntry)));
}
$allowedHostsListNew[] = $allowedHostEntry;
}
$allowedHostsList = array_unique($allowedHostsListNew);
$allowedHosts = implode(",", $allowedHostsList);
}
else {
$allowedHosts = "";
}
$cfg->allowedHosts = $allowedHosts;
// set allowed hosts for self-service
if (isLAMProVersion()) {
if (isset($_POST['allowedHostsSelfService'])) {
$allowedHostsSelfService = $_POST['allowedHostsSelfService'];
$allowedHostsSelfServiceList = explode("\r\n", $allowedHostsSelfService);
$allowedHostsSelfServiceListNew = [];
foreach ($allowedHostsSelfServiceList as $allowedHostsSelfServiceEntry) {
$allowedHostsSelfServiceEntry = trim($allowedHostsSelfServiceEntry);
// ignore empty lines
if ($allowedHostsSelfServiceEntry === '') {
continue;
}
// check each line
$ipRegex = '/^[0-9a-f\\.:\\*]+$/i';
if (!preg_match($ipRegex, $allowedHostsSelfServiceEntry) || (strlen($allowedHostsSelfServiceEntry) > 45)) {
$errors[] = sprintf(_("The IP address %s is invalid!"), htmlspecialchars(str_replace('%', '%%', $allowedHostsSelfServiceEntry)));
}
$allowedHostsSelfServiceListNew[] = $allowedHostsSelfServiceEntry;
}
$allowedHostsSelfServiceList = array_unique($allowedHostsSelfServiceListNew);
$allowedHostsSelfService = implode(",", $allowedHostsSelfServiceList);
}
else {
$allowedHostsSelfService = "";
}
$cfg->allowedHostsSelfService = $allowedHostsSelfService;
}
// set log level
$cfg->logLevel = intval($_POST['logLevel']);
// set log destination
if ($_POST['logDestination'] == "none") {
$cfg->logDestination = "NONE";
}
elseif ($_POST['logDestination'] == "syslog") {
$cfg->logDestination = "SYSLOG";
}
elseif ($_POST['logDestination'] == "remote") {
$cfg->logDestination = "REMOTE:" . $_POST['logRemote'];
$remoteParts = explode(':', $_POST['logRemote']);
if ((count($remoteParts) !== 2) || !get_preg($remoteParts[0], 'DNSname') || !get_preg($remoteParts[1], 'digit')) {
$errors[] = _("Please enter a valid remote server in format \"server:port\".");
}
}
else {
$isValidLogFile = isset($_POST['logFile']) && LAMCfgMain::isValidLogFilename($_POST['logFile']);
$blockedPrefixes = ['/usr', '/etc', '/dev', '/boot', '/lib', '/proc', '/root', '/run', '/sys', '/snap'];
if (!empty($_SERVER['DOCUMENT_ROOT'])) {
$blockedPrefixes[] = $_SERVER['DOCUMENT_ROOT'];
}
foreach ($blockedPrefixes as $blockedPrefix) {
if (!$isValidLogFile) {
break;
}
if (str_starts_with($_POST['logFile'], $blockedPrefix)) {
$isValidLogFile = false;
}
}
if ($isValidLogFile) {
$cfg->logDestination = $_POST['logFile'];
}
else {
$errors[] = _("The log file is empty or contains invalid characters! Valid characters are: a-z, A-Z, 0-9, /, ., _ and -. The file must end with '.log' or '.txt'.");
}
}
// password policies
$cfg->passwordMinLength = intval($_POST['passwordMinLength']);
$cfg->passwordMinLower = intval($_POST['passwordMinLower']);
$cfg->passwordMinUpper = intval($_POST['passwordMinUpper']);
$cfg->passwordMinNumeric = intval($_POST['passwordMinNumeric']);
$cfg->passwordMinSymbol = intval($_POST['passwordMinSymbol']);
$cfg->passwordMinClasses = intval($_POST['passwordMinClasses']);
$cfg->checkedRulesCount = intval($_POST['passwordRulesCount']);
$cfg->passwordMustNotContain3Chars = isset($_POST['passwordMustNotContain3Chars']) && ($_POST['passwordMustNotContain3Chars'] == 'on') ? 'true' : 'false';
$cfg->passwordMustNotContainUser = isset($_POST['passwordMustNotContainUser']) && ($_POST['passwordMustNotContainUser'] == 'on') ? 'true' : 'false';
if (function_exists('curl_init')) {
$cfg->externalPwdCheckUrl = $_POST['externalPwdCheckUrl'];
if (!empty($cfg->externalPwdCheckUrl) && (!str_contains($cfg->externalPwdCheckUrl, '{SHA1PREFIX}'))) {
$errors[] = _('The URL for the external password check is invalid.');
}
}
if (isset($_POST['sslCaCertUpload'])) {
if (!isset($_FILES['sslCaCert']) || ($_FILES['sslCaCert']['size'] == 0)) {
$errors[] = _('No file selected.');
}
else {
$handle = fopen($_FILES['sslCaCert']['tmp_name'], "r");
if ($handle === false) {
$errors[] = _('Unable to create temporary file.');
}
else {
$data = fread($handle, 10_000_000);
if ($data === false) {
$errors[] = _('Unable to create temporary file.');
}
else {
fclose($handle);
$sslReturn = $cfg->uploadSSLCaCert($data);
if ($sslReturn !== true) {
$errors[] = $sslReturn;
}
else {
$messages[] = _('You might need to restart your webserver for changes to take effect.');
}
}
}
}
}
if (isset($_POST['sslCaCertDelete'])) {
$cfg->deleteSSLCaCert();
$messages[] = _('You might need to restart your webserver for changes to take effect.');
}
if (isset($_POST['sslCaCertImport'])) {
$matches = [];
if (preg_match('/^ldaps:\/\/([a-zA-Z0-9_.-]+)(:(\d+))?$/', $_POST['serverurl'], $matches)) {
$port = '636';
if (!empty($matches[3])) {
$port = $matches[3];
}
$pemResult = getLDAPSSLCertificate($matches[1], $port);
if ($pemResult !== false) {
$messages[] = _('Imported certificate from server.');
$messages[] = _('You might need to restart your webserver for changes to take effect.');
$cfg->uploadSSLCaCert($pemResult);
}
else {
$errors[] = _('Unable to import server certificate. Please use the upload function.');
}
}
else {
$errors[] = _('Invalid server name. Please enter "server" or "server:port".');
}
}
foreach (array_keys($_POST) as $key) {
if (str_starts_with($key, 'deleteCert_')) {
$index = (int) substr($key, strlen('deleteCert_'));
$cfg->deleteSSLCaCert($index);
}
}
// mail settings
if (isLAMProVersion()) {
$cfg->mailUser = $_POST['mailUser'];
$cfg->mailPassword = $_POST['mailPassword'];
$cfg->mailEncryption = $_POST['mailEncryption'];
$cfg->mailServer = $_POST['mailServer'];
if (!empty($cfg->mailServer) && !get_preg($cfg->mailServer, 'hostAndPort')) {
$errors[] = _('Please enter the mail server with host name and port.');
}
$mailAttribute = strtolower($_POST['mailAttribute']);
$mailBackupAttribute = strtolower($_POST['mailBackupAttribute']);
if (empty($mailAttribute)) {
$cfg->mailAttribute = LAMCfgMain::MAIL_ATTRIBUTE_DEFAULT;
}
elseif (preg_match('/^[a-z0-9_-]+$/', $mailAttribute)) {
$cfg->mailAttribute = $mailAttribute;
}
else {
$errors[] = _('The mail attributes are invalid.');
}
if (empty($mailBackupAttribute)) {
$cfg->mailBackupAttribute = LAMCfgMain::MAIL_BACKUP_ATTRIBUTE_DEFAULT;
}
elseif (preg_match('/^[a-z0-9_-]+$/', $mailBackupAttribute)) {
$cfg->mailBackupAttribute = $mailBackupAttribute;
}
else {
$errors[] = _('The mail attributes are invalid.');
}
}
// SMS settings
if (isLAMProVersion()) {
$cfg->smsProvider = $_POST['smsProvider'];
$cfg->smsAttributes = $_POST['smsAttributes'];
$cfg->smsApiKey = $_POST['smsApiKey'];
$cfg->smsToken = $_POST['smsApiToken'];
$cfg->smsAccountId = $_POST['smsAccountId'];
$cfg->smsRegion = $_POST['smsRegion'];
$cfg->smsFrom = $_POST['smsFrom'];
$cfg->smsSubject = $_POST['smsSubject'];
$cfg->smsDefaultCountryPrefix = $_POST['smsDefaultCountryPrefix'];
}
$cfg->errorReporting = $_POST['errorReporting'];
// module settings
$allModules = getAllModules();
$moduleSettings = $cfg->getModuleSettings();
foreach ($allModules as $module) {
$module->checkGlobalConfigOptions($moduleSettings, $messages, $errors);
}
$cfg->setModuleSettings($moduleSettings);
// save settings
if (isset($_POST['submit']) && empty($errors)) {
try {
$cfg->save();
$scriptTag = new htmlJavaScript('window.lam.dialog.showSuccessMessageAndRedirect("' . _("Your settings were successfully saved.") . '", "", "' . _('Ok') . '", "../login.php")');
parseHtml(null, $scriptTag, [], false, null);
echo '