getProfiles(); } catch (LAMException $e) { logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); } // check if submit button was pressed if (isset($_POST['action'])) { // check master password if (!$cfg->checkPassword($_POST['passwd'])) { $error = _("Master password is wrong!"); } // add new profile elseif ($_POST['action'] == "add") { // check profile password if (empty($_POST['addpassword']) || ($_POST['addpassword'] !== $_POST['addpassword2'])) { $error = _("Profile passwords are different or empty!"); } elseif (!isValidConfigurationPassword($_POST['addpassword'])) { $error = _('Please enter at least 8 characters including letters, a number and a symbol.'); } else { try { $serverProfilePersistenceManager->createProfileFromTemplate($_POST['addprofile'], $_POST['addTemplate'], $_POST['addpassword']); $_SESSION['conf_isAuthenticated'] = $_POST['addprofile']; $_SESSION['conf_config'] = $serverProfilePersistenceManager->loadProfile($_POST['addprofile']); $_SESSION['conf_messages'][] = ['INFO', _("Created new profile."), $_POST['addprofile']]; metaRefresh('confmain.php'); exit; } catch (LAMException $e) { $error = $e->getTitle(); } } } // rename profile elseif ($_POST['action'] == "rename") { try { $serverProfilePersistenceManager->renameProfile($_POST['oldfilename'], $_POST['renfilename']); // reread profile list $files = $serverProfilePersistenceManager->getProfiles(); $msg = _("Renamed profile."); } catch (LAMException $e) { logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); $error = $e->getTitle(); } } // delete profile elseif ($_POST['action'] == "delete") { try { $serverProfilePersistenceManager->deleteProfile($_POST['delfilename']); // update default profile setting if needed if ($cfg->default == $_POST['delfilename']) { $filesNew = array_delete([$_POST['delfilename']], $files); if (count($filesNew) > 0) { sort($filesNew); $cfg->default = $filesNew[0]; $cfg->save(); } } // reread profile list $files = $serverProfilePersistenceManager->getProfiles(); $msg = _("Profile deleted."); } catch (LAMException $e) { $error = _("Unable to delete profile!"); logNewMessage(LOG_ERR, 'Unable to delete server profile: ' . $e->getTitle()); } } // set new profile password elseif ($_POST['action'] == "setpass") { if (preg_match("/^[a-z0-9_-]+$/i", (string) $_POST['setprofile'])) { if (empty($_POST['setpassword']) || ($_POST['setpassword'] !== $_POST['setpassword2'])) { $error = _("Profile passwords are different or empty!"); } elseif (!isValidConfigurationPassword($_POST['setpassword'])) { $error = _('Please enter at least 8 characters including letters, a number and a symbol.'); } else { try { $config = $serverProfilePersistenceManager->loadProfile($_POST['setprofile']); $config->set_Passwd($_POST['setpassword']); $serverProfilePersistenceManager->saveProfile($config, $_POST['setprofile']); $msg = _("New password set successfully."); } catch (LAMException $e) { $error = $e->getTitle(); } $config = null; } } else { $error = _("Profile name is invalid!"); } } // set default profile elseif ($_POST['action'] == "setdefault") { if (preg_match("/^[a-z0-9_-]+$/i", (string) $_POST['defaultfilename'])) { $configMain = new LAMCfgMain(); $configMain->default = $_POST['defaultfilename']; try { $configMain->save(); $configMain = null; $msg = _("New default profile set successfully."); } catch (LAMException $e) { $error = $e->getTitle(); } } else { $error = _("Profile name is invalid!"); } } } echo $_SESSION['header']; printHeaderContents(_("Profile management"), '../..'); ?>
help
menu  

add(new htmlStatusMessage('ERROR', $error)); $row->addVerticalSpacer('1rem'); } if (isset($msg)) { $row->add(new htmlStatusMessage('INFO', $msg)); $row->addVerticalSpacer('1rem'); } $box = new htmlResponsiveRow(); $box->add(new htmlTitle(_("Profile management"))); // new profile $box->add(new htmlSubTitle(_("Add profile"))); $newProfileInput = new htmlResponsiveInputField(_("Profile name"), 'addprofile', null, '230'); $box->add($newProfileInput); $profileNewPwd1 = new htmlResponsiveInputField(_("Profile password"), 'addpassword'); $profileNewPwd1->setIsPassword(true); $box->add($profileNewPwd1); $profileNewPwd2 = new htmlResponsiveInputField(_("Reenter password"), 'addpassword2'); $profileNewPwd2->setIsPassword(true); $profileNewPwd2->setSameValueFieldID('addpassword'); $box->add($profileNewPwd2); $existing = []; foreach ($files as $file) { $existing[$file] = $file; } $builtIn = []; foreach ($serverProfilePersistenceManager->getConfigTemplates() as $file) { $builtIn[$file] = $file . '.sample'; } $templates = [ _('Built-in templates') => $builtIn, _('Existing server profiles') => $existing ]; $addTemplateSelect = new htmlResponsiveSelect('addTemplate', $templates, ['unix.sample'], _('Template'), '267'); $addTemplateSelect->setContainsOptgroups(true); $addTemplateSelect->setHasDescriptiveElements(true); $box->add($addTemplateSelect); $box->addVerticalSpacer('0.5rem'); $newProfileButton = new htmlButton('btnAddProfile', _('Add')); $newProfileButton->setCSSClasses(['lam-primary']); $newProfileButton->setOnClick("document.getElementById('action').value = 'add';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Add profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); $box->addLabel($newProfileButton); $box->add(new htmlOutputText(''), 0, 6); // rename profile $box->add(new htmlSubTitle(_("Rename profile"))); $box->add(new htmlResponsiveSelect('oldfilename', $files, [], _('Profile name'), '231')); $oldProfileInput = new htmlResponsiveInputField(_('New profile name'), 'renfilename'); $box->add($oldProfileInput); $box->addVerticalSpacer('0.5rem'); $renameProfileButton = new htmlButton('btnRenameProfile', _('Rename')); $renameProfileButton->setCSSClasses(['lam-secondary']); $renameProfileButton->setOnClick("document.getElementById('action').value = 'rename';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Rename profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); $box->addLabel($renameProfileButton); $box->add(new htmlOutputText(''), 0, 6); // delete profile $box->add(new htmlSubTitle(_("Delete profile"))); $box->add(new htmlResponsiveSelect('delfilename', $files, [], _('Profile name'), '232')); $box->addVerticalSpacer('0.5rem'); $deleteProfileButton = new htmlButton('btnDeleteProfile', _('Delete')); $deleteProfileButton->setCSSClasses(['lam-danger']); $deleteProfileButton->setOnClick("document.getElementById('action').value = 'delete';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Delete profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); $box->addLabel($deleteProfileButton); $box->add(new htmlOutputText(''), 0, 6); // set password $box->add(new htmlSubTitle(_("Set profile password"))); $box->add(new htmlResponsiveSelect('setprofile', $files, [], _('Profile name'), '233')); $profileSetPwd1 = new htmlResponsiveInputField(_("Profile password"), 'setpassword'); $profileSetPwd1->setIsPassword(true); $box->add($profileSetPwd1); $profileSetPwd2 = new htmlResponsiveInputField(_("Reenter password"), 'setpassword2'); $profileSetPwd2->setIsPassword(true); $profileSetPwd2->setSameValueFieldID('setpassword'); $box->add($profileSetPwd2); $box->addVerticalSpacer('0.5rem'); $setPasswordProfileButton = new htmlButton('btnSetPasswordProfile', _('Set profile password')); $setPasswordProfileButton->setCSSClasses(['lam-secondary']); $setPasswordProfileButton->setOnClick("document.getElementById('action').value = 'setpass';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Set profile password") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); $box->addLabel($setPasswordProfileButton); $box->add(new htmlOutputText(''), 0, 6); // set default profile $conf = new LAMCfgMain(); $defaultProfile = $conf->default; $box->add(new htmlSubTitle(_("Change default profile"))); $box->add(new htmlResponsiveSelect('defaultfilename', $files, [$defaultProfile], _('Profile name'), '234')); $box->addVerticalSpacer('0.5rem'); $defaultProfileButton = new htmlButton('btnDefaultProfile', _('Ok')); $defaultProfileButton->setCSSClasses(['lam-secondary']); $defaultProfileButton->setOnClick("document.getElementById('action').value = 'setdefault';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Change default profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); $box->addLabel($defaultProfileButton); $box->add(new htmlOutputText(''), 0, 6); $boxDiv = new htmlDiv(null, $box); $boxDiv->setCSSClasses(['roundedShadowBox', 'limitWidth']); $row->add($boxDiv); $row->add(new htmlHiddenInput('action', 'none')); $row->addVerticalSpacer('2rem'); $backLink = new htmlLink(_("Back to profile login"), 'conflogin.php'); $row->add($backLink, 12, 12, 12, 'text-left'); parseHtml('', new htmlDiv(null, $row, ['centeredTable']), [], false, 'user'); ?>