| 1 |
<?php |
| 2 |
namespace LAM\CONFIG; |
| 3 |
use LAMCfgMain; |
| 4 |
use htmlStatusMessage; |
| 5 |
use htmlResponsiveRow; |
| 6 |
use htmlTitle; |
| 7 |
use htmlSubTitle; |
| 8 |
use htmlResponsiveInputField; |
| 9 |
use htmlResponsiveSelect; |
| 10 |
use htmlButton; |
| 11 |
use htmlOutputText; |
| 12 |
use htmlHiddenInput; |
| 13 |
use htmlDiv; |
| 14 |
use htmlLink; |
| 15 |
use LAMException; |
| 16 |
use ServerProfilePersistenceManager; |
| 17 |
|
| 18 |
/* |
| 19 |
|
| 20 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 21 |
Copyright (C) 2003 - 2026 Roland Gruber |
| 22 |
|
| 23 |
This program is free software; you can redistribute it and/or modify |
| 24 |
it under the terms of the GNU General Public License as published by |
| 25 |
the Free Software Foundation; either version 2 of the License, or |
| 26 |
(at your option) any later version. |
| 27 |
|
| 28 |
This program is distributed in the hope that it will be useful, |
| 29 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 30 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 31 |
GNU General Public License for more details. |
| 32 |
|
| 33 |
You should have received a copy of the GNU General Public License |
| 34 |
along with this program; if not, write to the Free Software |
| 35 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 36 |
|
| 37 |
*/ |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Configuration profile management. |
| 42 |
* |
| 43 |
* @package configuration |
| 44 |
* @author Roland Gruber |
| 45 |
*/ |
| 46 |
|
| 47 |
|
| 48 |
/** Access to config functions */ |
| 49 |
include_once(__DIR__ . '/../../lib/config.inc'); |
| 50 |
/** Used to print status messages */ |
| 51 |
include_once(__DIR__ . '/../../lib/status.inc'); |
| 52 |
|
| 53 |
// start session |
| 54 |
if (isFileBasedSession()) { |
| 55 |
session_save_path("../../sess"); |
| 56 |
} |
| 57 |
lam_start_session(); |
| 58 |
|
| 59 |
setlanguage(); |
| 60 |
|
| 61 |
|
| 62 |
$cfg = new LAMCfgMain(); |
| 63 |
$serverProfilePersistenceManager = new ServerProfilePersistenceManager(); |
| 64 |
$files = []; |
| 65 |
try { |
| 66 |
$files = $serverProfilePersistenceManager->getProfiles(); |
| 67 |
} |
| 68 |
catch (LAMException $e) { |
| 69 |
logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); |
| 70 |
} |
| 71 |
|
| 72 |
// check if submit button was pressed |
| 73 |
if (isset($_POST['action'])) { |
| 74 |
// check master password |
| 75 |
if (!$cfg->checkPassword($_POST['passwd'])) { |
| 76 |
$error = _("Master password is wrong!"); |
| 77 |
} |
| 78 |
// add new profile |
| 79 |
elseif ($_POST['action'] == "add") { |
| 80 |
// check profile password |
| 81 |
if (empty($_POST['addpassword']) || ($_POST['addpassword'] !== $_POST['addpassword2'])) { |
| 82 |
$error = _("Profile passwords are different or empty!"); |
| 83 |
} |
| 84 |
elseif (!isValidConfigurationPassword($_POST['addpassword'])) { |
| 85 |
$error = _('Please enter at least 8 characters including letters, a number and a symbol.'); |
| 86 |
} |
| 87 |
else { |
| 88 |
try { |
| 89 |
$serverProfilePersistenceManager->createProfileFromTemplate($_POST['addprofile'], $_POST['addTemplate'], $_POST['addpassword']); |
| 90 |
$_SESSION['conf_isAuthenticated'] = $_POST['addprofile']; |
| 91 |
$_SESSION['conf_config'] = $serverProfilePersistenceManager->loadProfile($_POST['addprofile']); |
| 92 |
$_SESSION['conf_messages'][] = ['INFO', _("Created new profile."), $_POST['addprofile']]; |
| 93 |
metaRefresh('confmain.php'); |
| 94 |
exit; |
| 95 |
} catch (LAMException $e) { |
| 96 |
$error = $e->getTitle(); |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
// rename profile |
| 101 |
elseif ($_POST['action'] == "rename") { |
| 102 |
try { |
| 103 |
$serverProfilePersistenceManager->renameProfile($_POST['oldfilename'], $_POST['renfilename']); |
| 104 |
// reread profile list |
| 105 |
$files = $serverProfilePersistenceManager->getProfiles(); |
| 106 |
$msg = _("Renamed profile."); |
| 107 |
} catch (LAMException $e) { |
| 108 |
logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); |
| 109 |
$error = $e->getTitle(); |
| 110 |
} |
| 111 |
} |
| 112 |
// delete profile |
| 113 |
elseif ($_POST['action'] == "delete") { |
| 114 |
try { |
| 115 |
$serverProfilePersistenceManager->deleteProfile($_POST['delfilename']); |
| 116 |
// update default profile setting if needed |
| 117 |
if ($cfg->default == $_POST['delfilename']) { |
| 118 |
$filesNew = array_delete([$_POST['delfilename']], $files); |
| 119 |
if (count($filesNew) > 0) { |
| 120 |
sort($filesNew); |
| 121 |
$cfg->default = $filesNew[0]; |
| 122 |
$cfg->save(); |
| 123 |
} |
| 124 |
} |
| 125 |
// reread profile list |
| 126 |
$files = $serverProfilePersistenceManager->getProfiles(); |
| 127 |
$msg = _("Profile deleted."); |
| 128 |
} catch (LAMException $e) { |
| 129 |
$error = _("Unable to delete profile!"); |
| 130 |
logNewMessage(LOG_ERR, 'Unable to delete server profile: ' . $e->getTitle()); |
| 131 |
} |
| 132 |
} |
| 133 |
// set new profile password |
| 134 |
elseif ($_POST['action'] == "setpass") { |
| 135 |
if (preg_match("/^[a-z0-9_-]+$/i", (string) $_POST['setprofile'])) { |
| 136 |
if (empty($_POST['setpassword']) || ($_POST['setpassword'] !== $_POST['setpassword2'])) { |
| 137 |
$error = _("Profile passwords are different or empty!"); |
| 138 |
} |
| 139 |
elseif (!isValidConfigurationPassword($_POST['setpassword'])) { |
| 140 |
$error = _('Please enter at least 8 characters including letters, a number and a symbol.'); |
| 141 |
} |
| 142 |
else { |
| 143 |
try { |
| 144 |
$config = $serverProfilePersistenceManager->loadProfile($_POST['setprofile']); |
| 145 |
$config->set_Passwd($_POST['setpassword']); |
| 146 |
$serverProfilePersistenceManager->saveProfile($config, $_POST['setprofile']); |
| 147 |
$msg = _("New password set successfully."); |
| 148 |
} catch (LAMException $e) { |
| 149 |
$error = $e->getTitle(); |
| 150 |
} |
| 151 |
$config = null; |
| 152 |
} |
| 153 |
} |
| 154 |
else { |
| 155 |
$error = _("Profile name is invalid!"); |
| 156 |
} |
| 157 |
} |
| 158 |
// set default profile |
| 159 |
elseif ($_POST['action'] == "setdefault") { |
| 160 |
if (preg_match("/^[a-z0-9_-]+$/i", (string) $_POST['defaultfilename'])) { |
| 161 |
$configMain = new LAMCfgMain(); |
| 162 |
$configMain->default = $_POST['defaultfilename']; |
| 163 |
try { |
| 164 |
$configMain->save(); |
| 165 |
$configMain = null; |
| 166 |
$msg = _("New default profile set successfully."); |
| 167 |
} |
| 168 |
catch (LAMException $e) { |
| 169 |
$error = $e->getTitle(); |
| 170 |
} |
| 171 |
} |
| 172 |
else { |
| 173 |
$error = _("Profile name is invalid!"); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
echo $_SESSION['header']; |
| 180 |
printHeaderContents(_("Profile management"), '../..'); |
| 181 |
?> |
| 182 |
</head> |
| 183 |
<body> |
| 184 |
<div id="lam-topnav" class="lam-header"> |
| 185 |
<div class="lam-header-left lam-menu-stay"> |
| 186 |
<a href="https://www.ldap-account-manager.org/" target="new_window"> |
| 187 |
<img class="align-middle" width="24" height="24" alt="help" src="../../graphics/logo.svg"> |
| 188 |
<span class="hide-on-mobile"> |
| 189 |
<?php |
| 190 |
echo getLAMVersionText(); |
| 191 |
?> |
| 192 |
</span> |
| 193 |
</a> |
| 194 |
</div> |
| 195 |
<?php |
| 196 |
if (is_dir(__DIR__ . '/../../docs/manual')) { |
| 197 |
?> |
| 198 |
<a class="lam-header-right lam-menu-icon hide-on-tablet" href="javascript:void(0);" class="icon" onclick="window.lam.topmenu.toggle();"> |
| 199 |
<img class="align-middle" width="16" height="16" alt="menu" src="../../graphics/menu.svg"> |
| 200 |
<span class="padding0"> </span> |
| 201 |
</a> |
| 202 |
<a class="lam-header-right lam-menu-entry" target="_blank" href="../../docs/manual/index.html"> |
| 203 |
<span class="padding0"><?php echo _("Help") ?></span> |
| 204 |
</a> |
| 205 |
<?php |
| 206 |
} |
| 207 |
?> |
| 208 |
</div> |
| 209 |
|
| 210 |
<?php |
| 211 |
// include all JavaScript files |
| 212 |
printJsIncludes('../..'); |
| 213 |
|
| 214 |
?> |
| 215 |
<br> |
| 216 |
<!-- form for adding/renaming/deleting profiles --> |
| 217 |
<form id="profileForm" name="profileForm" action="profmanage.php" method="post"> |
| 218 |
<?php |
| 219 |
|
| 220 |
$row = new htmlResponsiveRow(); |
| 221 |
|
| 222 |
// print messages |
| 223 |
if (isset($error)) { |
| 224 |
$row->add(new htmlStatusMessage('ERROR', $error)); |
| 225 |
$row->addVerticalSpacer('1rem'); |
| 226 |
} |
| 227 |
if (isset($msg)) { |
| 228 |
$row->add(new htmlStatusMessage('INFO', $msg)); |
| 229 |
$row->addVerticalSpacer('1rem'); |
| 230 |
} |
| 231 |
|
| 232 |
$box = new htmlResponsiveRow(); |
| 233 |
$box->add(new htmlTitle(_("Profile management"))); |
| 234 |
|
| 235 |
// new profile |
| 236 |
$box->add(new htmlSubTitle(_("Add profile"))); |
| 237 |
$newProfileInput = new htmlResponsiveInputField(_("Profile name"), 'addprofile', null, '230'); |
| 238 |
$box->add($newProfileInput); |
| 239 |
$profileNewPwd1 = new htmlResponsiveInputField(_("Profile password"), 'addpassword'); |
| 240 |
$profileNewPwd1->setIsPassword(true); |
| 241 |
$box->add($profileNewPwd1); |
| 242 |
$profileNewPwd2 = new htmlResponsiveInputField(_("Reenter password"), 'addpassword2'); |
| 243 |
$profileNewPwd2->setIsPassword(true); |
| 244 |
$profileNewPwd2->setSameValueFieldID('addpassword'); |
| 245 |
$box->add($profileNewPwd2); |
| 246 |
$existing = []; |
| 247 |
foreach ($files as $file) { |
| 248 |
$existing[$file] = $file; |
| 249 |
} |
| 250 |
$builtIn = []; |
| 251 |
foreach ($serverProfilePersistenceManager->getConfigTemplates() as $file) { |
| 252 |
$builtIn[$file] = $file . '.sample'; |
| 253 |
} |
| 254 |
$templates = [ |
| 255 |
_('Built-in templates') => $builtIn, |
| 256 |
_('Existing server profiles') => $existing |
| 257 |
]; |
| 258 |
$addTemplateSelect = new htmlResponsiveSelect('addTemplate', $templates, ['unix.sample'], _('Template'), '267'); |
| 259 |
$addTemplateSelect->setContainsOptgroups(true); |
| 260 |
$addTemplateSelect->setHasDescriptiveElements(true); |
| 261 |
$box->add($addTemplateSelect); |
| 262 |
$box->addVerticalSpacer('0.5rem'); |
| 263 |
$newProfileButton = new htmlButton('btnAddProfile', _('Add')); |
| 264 |
$newProfileButton->setCSSClasses(['lam-primary']); |
| 265 |
$newProfileButton->setOnClick("document.getElementById('action').value = 'add';" |
| 266 |
. "window.lam.dialog.requestPasswordAndSendForm('" . _("Add profile") . "', '" . |
| 267 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); |
| 268 |
$box->addLabel($newProfileButton); |
| 269 |
$box->add(new htmlOutputText(''), 0, 6); |
| 270 |
|
| 271 |
// rename profile |
| 272 |
$box->add(new htmlSubTitle(_("Rename profile"))); |
| 273 |
$box->add(new htmlResponsiveSelect('oldfilename', $files, [], _('Profile name'), '231')); |
| 274 |
$oldProfileInput = new htmlResponsiveInputField(_('New profile name'), 'renfilename'); |
| 275 |
$box->add($oldProfileInput); |
| 276 |
$box->addVerticalSpacer('0.5rem'); |
| 277 |
$renameProfileButton = new htmlButton('btnRenameProfile', _('Rename')); |
| 278 |
$renameProfileButton->setCSSClasses(['lam-secondary']); |
| 279 |
$renameProfileButton->setOnClick("document.getElementById('action').value = 'rename';" . |
| 280 |
"window.lam.dialog.requestPasswordAndSendForm('" . _("Rename profile") . "', '" . |
| 281 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); |
| 282 |
$box->addLabel($renameProfileButton); |
| 283 |
$box->add(new htmlOutputText(''), 0, 6); |
| 284 |
|
| 285 |
// delete profile |
| 286 |
$box->add(new htmlSubTitle(_("Delete profile"))); |
| 287 |
$box->add(new htmlResponsiveSelect('delfilename', $files, [], _('Profile name'), '232')); |
| 288 |
$box->addVerticalSpacer('0.5rem'); |
| 289 |
$deleteProfileButton = new htmlButton('btnDeleteProfile', _('Delete')); |
| 290 |
$deleteProfileButton->setCSSClasses(['lam-danger']); |
| 291 |
$deleteProfileButton->setOnClick("document.getElementById('action').value = 'delete';" . |
| 292 |
"window.lam.dialog.requestPasswordAndSendForm('" . _("Delete profile") . "', '" . |
| 293 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); |
| 294 |
$box->addLabel($deleteProfileButton); |
| 295 |
$box->add(new htmlOutputText(''), 0, 6); |
| 296 |
|
| 297 |
// set password |
| 298 |
$box->add(new htmlSubTitle(_("Set profile password"))); |
| 299 |
$box->add(new htmlResponsiveSelect('setprofile', $files, [], _('Profile name'), '233')); |
| 300 |
$profileSetPwd1 = new htmlResponsiveInputField(_("Profile password"), 'setpassword'); |
| 301 |
$profileSetPwd1->setIsPassword(true); |
| 302 |
$box->add($profileSetPwd1); |
| 303 |
$profileSetPwd2 = new htmlResponsiveInputField(_("Reenter password"), 'setpassword2'); |
| 304 |
$profileSetPwd2->setIsPassword(true); |
| 305 |
$profileSetPwd2->setSameValueFieldID('setpassword'); |
| 306 |
$box->add($profileSetPwd2); |
| 307 |
$box->addVerticalSpacer('0.5rem'); |
| 308 |
$setPasswordProfileButton = new htmlButton('btnSetPasswordProfile', _('Set profile password')); |
| 309 |
$setPasswordProfileButton->setCSSClasses(['lam-secondary']); |
| 310 |
$setPasswordProfileButton->setOnClick("document.getElementById('action').value = 'setpass';" . |
| 311 |
"window.lam.dialog.requestPasswordAndSendForm('" . _("Set profile password") . "', '" . |
| 312 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); |
| 313 |
$box->addLabel($setPasswordProfileButton); |
| 314 |
$box->add(new htmlOutputText(''), 0, 6); |
| 315 |
|
| 316 |
|
| 317 |
// set default profile |
| 318 |
$conf = new LAMCfgMain(); |
| 319 |
$defaultProfile = $conf->default; |
| 320 |
$box->add(new htmlSubTitle(_("Change default profile"))); |
| 321 |
$box->add(new htmlResponsiveSelect('defaultfilename', $files, [$defaultProfile], _('Profile name'), '234')); |
| 322 |
$box->addVerticalSpacer('0.5rem'); |
| 323 |
$defaultProfileButton = new htmlButton('btnDefaultProfile', _('Ok')); |
| 324 |
$defaultProfileButton->setCSSClasses(['lam-secondary']); |
| 325 |
$defaultProfileButton->setOnClick("document.getElementById('action').value = 'setdefault';" . |
| 326 |
"window.lam.dialog.requestPasswordAndSendForm('" . _("Change default profile") . "', '" . |
| 327 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); |
| 328 |
$box->addLabel($defaultProfileButton); |
| 329 |
$box->add(new htmlOutputText(''), 0, 6); |
| 330 |
|
| 331 |
$boxDiv = new htmlDiv(null, $box); |
| 332 |
$boxDiv->setCSSClasses(['roundedShadowBox', 'limitWidth']); |
| 333 |
$row->add($boxDiv); |
| 334 |
|
| 335 |
$row->add(new htmlHiddenInput('action', 'none')); |
| 336 |
|
| 337 |
$row->addVerticalSpacer('2rem'); |
| 338 |
$backLink = new htmlLink(_("Back to profile login"), 'conflogin.php'); |
| 339 |
$row->add($backLink, 12, 12, 12, 'text-left'); |
| 340 |
|
| 341 |
parseHtml('', new htmlDiv(null, $row, ['centeredTable']), [], false, 'user'); |
| 342 |
|
| 343 |
?> |
| 344 |
</form> |
| 345 |
<p><br></p> |
| 346 |
|
| 347 |
</body> |
| 348 |
</html> |
| 349 |
|