| 1 |
<?php |
| 2 |
namespace LAM\TOOLS\PROFILE_EDITOR; |
| 3 |
use htmlDiv; |
| 4 |
use htmlForm; |
| 5 |
use htmlResponsiveInputField; |
| 6 |
use htmlResponsiveSelect; |
| 7 |
use \htmlTitle; |
| 8 |
use \htmlStatusMessage; |
| 9 |
use LAM\PROFILES\AccountProfilePersistenceManager; |
| 10 |
use \LAMCfgMain; |
| 11 |
use \htmlSubTitle; |
| 12 |
use \htmlSpacer; |
| 13 |
use \htmlSelect; |
| 14 |
use \htmlButton; |
| 15 |
use \htmlImage; |
| 16 |
use \htmlLink; |
| 17 |
use \htmlOutputText; |
| 18 |
use \htmlHelpLink; |
| 19 |
use \htmlHiddenInput; |
| 20 |
use \htmlInputField; |
| 21 |
use \htmlResponsiveRow; |
| 22 |
use \htmlGroup; |
| 23 |
use \LAM\TYPES\TypeManager; |
| 24 |
use LAMConfig; |
| 25 |
use LAMException; |
| 26 |
use ServerProfilePersistenceManager; |
| 27 |
|
| 28 |
/* |
| 29 |
|
| 30 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 31 |
Copyright (C) 2003 - 2025 Roland Gruber |
| 32 |
|
| 33 |
This program is free software; you can redistribute it and/or modify |
| 34 |
it under the terms of the GNU General Public License as published by |
| 35 |
the Free Software Foundation; either version 2 of the License, or |
| 36 |
(at your option) any later version. |
| 37 |
|
| 38 |
This program is distributed in the hope that it will be useful, |
| 39 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 41 |
GNU General Public License for more details. |
| 42 |
|
| 43 |
You should have received a copy of the GNU General Public License |
| 44 |
along with this program; if not, write to the Free Software |
| 45 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 46 |
|
| 47 |
*/ |
| 48 |
|
| 49 |
/** |
| 50 |
* This is the main window of the profile editor. |
| 51 |
* |
| 52 |
* @package profiles |
| 53 |
* @author Roland Gruber |
| 54 |
*/ |
| 55 |
|
| 56 |
/** security functions */ |
| 57 |
include_once(__DIR__ . "/../../lib/security.inc"); |
| 58 |
/** helper functions for profiles */ |
| 59 |
include_once(__DIR__ . "/../../lib/profiles.inc"); |
| 60 |
/** access to LDAP server */ |
| 61 |
include_once(__DIR__ . "/../../lib/ldap.inc"); |
| 62 |
/** access to configuration options */ |
| 63 |
include_once(__DIR__ . "/../../lib/config.inc"); |
| 64 |
|
| 65 |
// start session |
| 66 |
startSecureSession(); |
| 67 |
enforceUserIsLoggedIn(); |
| 68 |
|
| 69 |
// die if no write access |
| 70 |
if (!checkIfWriteAccessIsAllowed()) { |
| 71 |
die(); |
| 72 |
} |
| 73 |
|
| 74 |
checkIfToolIsActive('toolProfileEditor'); |
| 75 |
|
| 76 |
setlanguage(); |
| 77 |
|
| 78 |
if (!empty($_POST)) { |
| 79 |
validateSecurityToken(); |
| 80 |
} |
| 81 |
|
| 82 |
$typeManager = new TypeManager(); |
| 83 |
$types = $typeManager->getConfiguredTypes(); |
| 84 |
|
| 85 |
$container = new htmlResponsiveRow(); |
| 86 |
$container->add(new htmlTitle(_("Profile editor")), 12); |
| 87 |
|
| 88 |
$accountProfilePersistenceManager = new AccountProfilePersistenceManager(); |
| 89 |
|
| 90 |
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { |
| 91 |
$type = $typeManager->getConfiguredType($_POST['profileDeleteType']); |
| 92 |
if (($type === null) || $type->isHidden()) { |
| 93 |
logNewMessage(LOG_ERR, 'User tried to delete hidden account type profile: ' . $_POST['profileDeleteType']); |
| 94 |
die(); |
| 95 |
} |
| 96 |
// delete profile |
| 97 |
try { |
| 98 |
$accountProfilePersistenceManager->deleteAccountProfile($_POST['profileDeleteType'], $_POST['profileDeleteName'], $_SESSION['config']->getName()); |
| 99 |
$message = new htmlStatusMessage('INFO', _('Deleted profile.'), $type->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); |
| 100 |
$container->add($message, 12); |
| 101 |
} |
| 102 |
catch (LAMException $e) { |
| 103 |
$message = new htmlStatusMessage('ERROR', $e->getTitle(), $type->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); |
| 104 |
$container->add($message, 12); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
// delete global template |
| 109 |
if (isset($_POST['deleteGlobalTemplate']) && !empty($_POST['globalTemplatesDelete'])) { |
| 110 |
$cfg = new LAMCfgMain(); |
| 111 |
if (empty($_POST['globalTemplateDeletePassword']) || !$cfg->checkPassword($_POST['globalTemplateDeletePassword'])) { |
| 112 |
$container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!')), 12); |
| 113 |
} |
| 114 |
else { |
| 115 |
$selectedOptions = explode(':', $_POST['globalTemplatesDelete']); |
| 116 |
$selectedScope = $selectedOptions[0]; |
| 117 |
$selectedName = $selectedOptions[1]; |
| 118 |
try { |
| 119 |
$accountProfilePersistenceManager->deleteAccountProfileTemplate($selectedScope, $selectedName); |
| 120 |
$container->add(new htmlStatusMessage('INFO', _('Deleted profile.'), $selectedName), 12); |
| 121 |
} catch (LAMException $e) { |
| 122 |
$container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()), 12); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
$serverProfilePersistenceManager = new ServerProfilePersistenceManager(); |
| 128 |
$serverProfiles = []; |
| 129 |
$configProfiles = []; |
| 130 |
try { |
| 131 |
$configProfiles = $serverProfilePersistenceManager->getProfiles(); |
| 132 |
foreach ($configProfiles as $profileName) { |
| 133 |
$serverProfiles[$profileName] = $serverProfilePersistenceManager->loadProfile($profileName); |
| 134 |
} |
| 135 |
} catch (LAMException $e) { |
| 136 |
logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); |
| 137 |
} |
| 138 |
|
| 139 |
// import profiles |
| 140 |
if (!empty($_POST['import'])) { |
| 141 |
$cfg = new LAMCfgMain(); |
| 142 |
// check master password |
| 143 |
$errMessage = null; |
| 144 |
if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) { |
| 145 |
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); |
| 146 |
} |
| 147 |
elseif (!empty($_POST['importProfiles'])) { |
| 148 |
$options = []; |
| 149 |
foreach ($_POST['importProfiles'] as $importProfiles) { |
| 150 |
$parts = explode('##', $importProfiles); |
| 151 |
$options[] = ['conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]]; |
| 152 |
} |
| 153 |
$errMessage = importProfiles($_POST['typeId'], $options, $serverProfiles, $typeManager); |
| 154 |
} |
| 155 |
if ($errMessage !== null) { |
| 156 |
$container->add($errMessage, 12); |
| 157 |
} |
| 158 |
} |
| 159 |
// export profiles |
| 160 |
if (!empty($_POST['export'])) { |
| 161 |
$cfg = new LAMCfgMain(); |
| 162 |
// check master password |
| 163 |
$errMessage = null; |
| 164 |
if (!$cfg->checkPassword($_POST['passwd_e_' . $_POST['typeId']])) { |
| 165 |
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); |
| 166 |
} |
| 167 |
elseif (!empty($_POST['exportProfiles'])) { |
| 168 |
$options = []; |
| 169 |
foreach ($_POST['exportProfiles'] as $importProfiles) { |
| 170 |
$parts = explode('##', $importProfiles); |
| 171 |
$options[] = ['conf' => $parts[0], 'typeId' => $parts[1]]; |
| 172 |
} |
| 173 |
$typeId = $_POST['typeId']; |
| 174 |
$name = $_POST['name_' . $typeId]; |
| 175 |
$errMessage = exportProfiles($typeId, $name, $options, $serverProfiles, $typeManager); |
| 176 |
} |
| 177 |
if ($errMessage !== null) { |
| 178 |
$container->add($errMessage, 12); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
$profileClasses = []; |
| 183 |
$profileClassesTemp = []; |
| 184 |
foreach ($types as $type) { |
| 185 |
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) { |
| 186 |
continue; |
| 187 |
} |
| 188 |
$profileList = $accountProfilePersistenceManager->getAccountProfileNames($type->getId(), $_SESSION['config']->getName()); |
| 189 |
natcasesort($profileList); |
| 190 |
$profileClassesTemp[$type->getAlias()] = [ |
| 191 |
'typeId' => $type->getId(), |
| 192 |
'scope' => $type->getScope(), |
| 193 |
'title' => $type->getAlias(), |
| 194 |
'icon' => $type->getIcon(), |
| 195 |
'profiles' => $profileList |
| 196 |
]; |
| 197 |
} |
| 198 |
$profileClassesKeys = array_keys($profileClassesTemp); |
| 199 |
natcasesort($profileClassesKeys); |
| 200 |
$profileClassesKeys = array_values($profileClassesKeys); |
| 201 |
foreach ($profileClassesKeys as $profileClassesKey) { |
| 202 |
$profileClasses[] = $profileClassesTemp[$profileClassesKey]; |
| 203 |
} |
| 204 |
|
| 205 |
// check if user is logged in, if not go to login |
| 206 |
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) { |
| 207 |
metaRefresh("../login.php"); |
| 208 |
exit; |
| 209 |
} |
| 210 |
|
| 211 |
// check if new profile should be created |
| 212 |
elseif (isset($_POST['createProfileButton'])) { |
| 213 |
metaRefresh("profilepage.php?type=" . htmlspecialchars($_POST['createProfile'])); |
| 214 |
exit; |
| 215 |
} |
| 216 |
// check if a profile should be edited |
| 217 |
foreach ($profileClasses as $profileClass) { |
| 218 |
if (isset($_POST['editProfile_' . $profileClass['typeId']]) || isset($_POST['editProfile_' . $profileClass['typeId'] . '_x'])) { |
| 219 |
metaRefresh("profilepage.php?type=" . htmlspecialchars($profileClass['typeId']) . |
| 220 |
"&edit=" . htmlspecialchars($_POST['profile_' . $profileClass['typeId']])); |
| 221 |
exit; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
include __DIR__ . '/../../lib/adminHeader.inc'; |
| 226 |
echo "<div class=\"smallPaddingContent\">\n"; |
| 227 |
echo "<form name=\"profilemainForm\" action=\"profilemain.php\" method=\"post\">\n"; |
| 228 |
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">'; |
| 229 |
|
| 230 |
if (isset($_GET['savedSuccessfully'])) { |
| 231 |
$message = new htmlStatusMessage("INFO", _("Profile was saved."), htmlspecialchars($_GET['savedSuccessfully'])); |
| 232 |
$container->add($message, 12); |
| 233 |
} |
| 234 |
|
| 235 |
// new profile |
| 236 |
if (!empty($profileClasses)) { |
| 237 |
$container->add(new htmlSubTitle(_('Create a new profile')), 12); |
| 238 |
$sortedTypes = []; |
| 239 |
foreach ($profileClasses as $profileClass) { |
| 240 |
$sortedTypes[$profileClass['title']] = $profileClass['typeId']; |
| 241 |
} |
| 242 |
natcasesort($sortedTypes); |
| 243 |
$newProfileSelect = new htmlSelect('createProfile', $sortedTypes); |
| 244 |
$newProfileSelect->setHasDescriptiveElements(true); |
| 245 |
$container->addLabel($newProfileSelect); |
| 246 |
$createButton = new htmlButton('createProfileButton', _('Create')); |
| 247 |
$createButton->setCSSClasses(['lam-primary']); |
| 248 |
$container->addField($createButton); |
| 249 |
} |
| 250 |
|
| 251 |
$container->addVerticalSpacer('1rem'); |
| 252 |
|
| 253 |
// existing profiles |
| 254 |
$container->add(new htmlSubTitle(_('Manage existing profiles')), 12); |
| 255 |
|
| 256 |
foreach ($profileClasses as $profileClass) { |
| 257 |
$labelGroup = new htmlGroup(); |
| 258 |
$labelGroup->addElement(new htmlImage('../../graphics/' . $profileClass['icon'], '16px', '16px')); |
| 259 |
$labelGroup->addElement(new htmlSpacer('3px', null)); |
| 260 |
$labelGroup->addElement(new htmlOutputText($profileClass['title'])); |
| 261 |
$container->add($labelGroup, 12, 4); |
| 262 |
$select = new htmlSelect('profile_' . $profileClass['typeId'], $profileClass['profiles']); |
| 263 |
$container->add($select, 12, 4); |
| 264 |
$buttonGroup = new htmlGroup(); |
| 265 |
$editButton = new htmlButton('editProfile_' . $profileClass['typeId'], 'edit.svg', true); |
| 266 |
$editButton->setTitle(_('Edit')); |
| 267 |
$buttonGroup->addElement($editButton); |
| 268 |
$deleteLink = new htmlLink('', '#', '../../graphics/del.svg'); |
| 269 |
$deleteLink->setTitle(_('Delete')); |
| 270 |
$deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $profileClass['typeId'] . "', '" . 'profile_' . $profileClass['typeId'] . "'); return false;"); |
| 271 |
$deleteLink->setCSSClasses(['margin3']); |
| 272 |
$buttonGroup->addElement($deleteLink); |
| 273 |
if (count($configProfiles) > 1) { |
| 274 |
$importLink = new htmlLink('', '#', '../../graphics/import.svg'); |
| 275 |
$importLink->setTitle(_('Import profiles')); |
| 276 |
$importLink->setOnClick("window.lam.profilePdfEditor.showDistributionDialog('" . _("Import profiles") . "', '" . |
| 277 |
_('Ok') . "', '" . _('Cancel') . "', '" . $profileClass['typeId'] . "', 'import'); return false;"); |
| 278 |
$importLink->setCSSClasses(['margin3']); |
| 279 |
$buttonGroup->addElement($importLink); |
| 280 |
} |
| 281 |
$exportLink = new htmlLink('', '#', '../../graphics/export.svg'); |
| 282 |
$exportLink->setTitle(_('Export profile')); |
| 283 |
$exportLink->setOnClick("window.lam.profilePdfEditor.showDistributionDialog('" . _("Export profile") . "', '" . |
| 284 |
_('Ok') . "', '" . _('Cancel') . "', '" . $profileClass['typeId'] . "', 'export', '" . 'profile_' . $profileClass['typeId'] . "'); return false;"); |
| 285 |
$exportLink->setCSSClasses(['margin3']); |
| 286 |
$buttonGroup->addElement($exportLink); |
| 287 |
$container->add($buttonGroup, 12, 4); |
| 288 |
$container->addVerticalSpacer('1rem'); |
| 289 |
} |
| 290 |
$container->addVerticalSpacer('1rem'); |
| 291 |
|
| 292 |
// generate content |
| 293 |
parseHtml(null, $container, [], false, 'user'); |
| 294 |
|
| 295 |
echo "</form>\n"; |
| 296 |
|
| 297 |
// delete global templates |
| 298 |
$globalDeletableTemplates = []; |
| 299 |
try { |
| 300 |
$globalTemplates = $accountProfilePersistenceManager->getAccountProfileTemplateNames(); |
| 301 |
foreach ($globalTemplates as $typeId => $availableTemplates) { |
| 302 |
if (empty($availableTemplates)) { |
| 303 |
continue; |
| 304 |
} |
| 305 |
foreach ($availableTemplates as $availableTemplate) { |
| 306 |
if ($availableTemplate !== 'default') { |
| 307 |
$globalDeletableTemplates[$typeId][$availableTemplate] = $typeId . ':' . $availableTemplate; |
| 308 |
} |
| 309 |
} |
| 310 |
} |
| 311 |
} |
| 312 |
catch (LAMException $e) { |
| 313 |
logNewMessage(LOG_ERR, $e->getTitle()); |
| 314 |
} |
| 315 |
|
| 316 |
if (!empty($globalDeletableTemplates)) { |
| 317 |
$container = new htmlResponsiveRow(); |
| 318 |
$globalTemplatesSubtitle = new htmlSubTitle(_('Global templates')); |
| 319 |
$globalTemplatesSubtitle->setHelpId('364'); |
| 320 |
$container->add($globalTemplatesSubtitle); |
| 321 |
$globalTemplatesSelect = new htmlResponsiveSelect('globalTemplatesDelete', $globalDeletableTemplates, [], _('Delete')); |
| 322 |
$globalTemplatesSelect->setContainsOptgroups(true); |
| 323 |
$globalTemplatesSelect->setHasDescriptiveElements(true); |
| 324 |
$container->add($globalTemplatesSelect); |
| 325 |
$container->addVerticalSpacer('1rem'); |
| 326 |
$globalTemplateDeleteButton = new htmlButton('deleteGlobalProfileButton', _('Delete')); |
| 327 |
$globalTemplateDeleteButton->setCSSClasses(['lam-danger']); |
| 328 |
$globalTemplateDeleteButton->setOnClick("window.lam.dialog.requestPasswordAndSendForm('" . _('Do you really want to delete this profile?') . "', '" . |
| 329 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'globalTemplateDeletePassword', 'deleteGlobalTemplatesForm'); return false;"); |
| 330 |
$container->addLabel(new htmlOutputText(' ', false)); |
| 331 |
$container->addField($globalTemplateDeleteButton); |
| 332 |
addSecurityTokenToMetaHTML($container); |
| 333 |
$container->add(new htmlHiddenInput('deleteGlobalTemplate', 'true')); |
| 334 |
$container->addVerticalSpacer('1rem'); |
| 335 |
$globalTemplateDeleteForm = new htmlForm('deleteGlobalTemplatesForm', 'profilemain.php', $container); |
| 336 |
parseHtml(null, $globalTemplateDeleteForm, [], false, 'user'); |
| 337 |
} |
| 338 |
|
| 339 |
echo "</div>\n"; |
| 340 |
|
| 341 |
foreach ($profileClasses as $profileClass) { |
| 342 |
$typeId = $profileClass['typeId']; |
| 343 |
$scope = $profileClass['scope']; |
| 344 |
$importOptions = []; |
| 345 |
foreach ($configProfiles as $profile) { |
| 346 |
$typeManagerImport = new TypeManager($serverProfiles[$profile]); |
| 347 |
$typesImport = $typeManagerImport->getConfiguredTypesForScope($scope); |
| 348 |
foreach ($typesImport as $typeImport) { |
| 349 |
if (($profile != $_SESSION['config']->getName()) || ($typeImport->getId() != $typeId)) { |
| 350 |
$accountProfiles = $accountProfilePersistenceManager->getAccountProfileNames($typeImport->getId(), $profile); |
| 351 |
foreach ($accountProfiles as $accountProfile) { |
| 352 |
$importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfile] = $profile . '##' . $typeImport->getId() . '##' . $accountProfile; |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
//import dialog |
| 359 |
echo "<div id=\"importDialog_$typeId\" class=\"hidden\">\n"; |
| 360 |
echo "<form id=\"importDialogForm_$typeId\" method=\"post\" action=\"profilemain.php\">\n"; |
| 361 |
|
| 362 |
$containerProfiles = new htmlResponsiveRow(); |
| 363 |
$containerProfiles->add(new htmlOutputText(_('Profiles')), 12); |
| 364 |
|
| 365 |
$select = new htmlSelect('importProfiles', $importOptions, [], count($importOptions, 1) < 15 ? count($importOptions, 1) : 15); |
| 366 |
$select->setMultiSelect(true); |
| 367 |
$select->setHasDescriptiveElements(true); |
| 368 |
$select->setContainsOptgroups(true); |
| 369 |
|
| 370 |
$containerProfiles->add($select, 11); |
| 371 |
$containerProfiles->add(new htmlHelpLink('362'), 1); |
| 372 |
|
| 373 |
$containerProfiles->addVerticalSpacer('2rem'); |
| 374 |
|
| 375 |
$containerProfiles->add(new htmlOutputText(_("Master password")), 12); |
| 376 |
$exportPasswd = new htmlInputField('passwd_i_' . $typeId); |
| 377 |
$exportPasswd->setIsPassword(true); |
| 378 |
$containerProfiles->add($exportPasswd, 11); |
| 379 |
$containerProfiles->add(new htmlHelpLink('236'), 1); |
| 380 |
$containerProfiles->add(new htmlHiddenInput('import', '1'), 0); |
| 381 |
$containerProfiles->add(new htmlHiddenInput('typeId', $typeId), 0); |
| 382 |
addSecurityTokenToMetaHTML($containerProfiles); |
| 383 |
|
| 384 |
parseHtml(null, $containerProfiles, [], false, 'user'); |
| 385 |
|
| 386 |
echo '</form>'; |
| 387 |
echo "</div>\n"; |
| 388 |
|
| 389 |
//export dialog |
| 390 |
echo "<div id=\"exportDialog_$typeId\" class=\"hidden\">\n"; |
| 391 |
echo "<form id=\"exportDialogForm_$typeId\" method=\"post\" action=\"profilemain.php\">\n"; |
| 392 |
|
| 393 |
$containerTarget = new htmlResponsiveRow(); |
| 394 |
|
| 395 |
$containerTarget->add(new htmlOutputText(_("Target server profile")), 12); |
| 396 |
$exportOptions = []; |
| 397 |
foreach ($configProfiles as $profile) { |
| 398 |
$typeManagerExport = new TypeManager($serverProfiles[$profile]); |
| 399 |
if ($typeManagerExport->getConfig() === null) { |
| 400 |
continue; |
| 401 |
} |
| 402 |
$typesExport = $typeManagerExport->getConfiguredTypesForScope($scope); |
| 403 |
foreach ($typesExport as $typeExport) { |
| 404 |
if (($profile != $_SESSION['config']->getName()) || ($typeExport->getId() != $typeId)) { |
| 405 |
$exportOptions[$typeManagerExport->getConfig()->getName()][$typeExport->getAlias()] = $profile . '##' . $typeExport->getId(); |
| 406 |
} |
| 407 |
} |
| 408 |
} |
| 409 |
$exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##'; |
| 410 |
|
| 411 |
$select = new htmlSelect('exportProfiles', $exportOptions, [], count($exportOptions) < 10 ? count($exportOptions, 1) : 10); |
| 412 |
$select->setHasDescriptiveElements(true); |
| 413 |
$select->setContainsOptgroups(true); |
| 414 |
$select->setMultiSelect(true); |
| 415 |
|
| 416 |
$containerTarget->add($select, 11); |
| 417 |
$containerTarget->add(new htmlHelpLink('363'), 1); |
| 418 |
|
| 419 |
$containerTarget->addVerticalSpacer('2rem'); |
| 420 |
|
| 421 |
$containerTarget->add(new htmlOutputText(_("Master password")), 12); |
| 422 |
$exportPasswd = new htmlInputField('passwd_e_' . $typeId); |
| 423 |
$exportPasswd->setIsPassword(true); |
| 424 |
$containerTarget->add($exportPasswd, 11); |
| 425 |
$containerTarget->add(new htmlHelpLink('236'), 1); |
| 426 |
$containerTarget->add(new htmlHiddenInput('export', '1'), 0); |
| 427 |
$containerTarget->add(new htmlHiddenInput('typeId', $typeId), 0); |
| 428 |
$containerTarget->add(new htmlHiddenInput('name_' . $typeId, '_'), 0); |
| 429 |
addSecurityTokenToMetaHTML($containerTarget); |
| 430 |
|
| 431 |
parseHtml(null, $containerTarget, [], false, 'user'); |
| 432 |
|
| 433 |
echo '</form>'; |
| 434 |
echo "</div>\n"; |
| 435 |
|
| 436 |
} |
| 437 |
|
| 438 |
// form for delete action |
| 439 |
echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="profilemain.php" method="post">'; |
| 440 |
echo _("Do you really want to delete this profile?"); |
| 441 |
echo '<br><br><div class="nowrap">'; |
| 442 |
echo _("Profile name") . ': <div id="deleteText" style="display: inline;"></div></div>'; |
| 443 |
echo '<input id="profileDeleteType" type="hidden" name="profileDeleteType" value="">'; |
| 444 |
echo '<input id="profileDeleteName" type="hidden" name="profileDeleteName" value="">'; |
| 445 |
echo '<input type="hidden" name="deleteProfile" value="true">'; |
| 446 |
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">'; |
| 447 |
echo '</form></div>'; |
| 448 |
|
| 449 |
include __DIR__ . '/../../lib/adminFooter.inc'; |
| 450 |
|
| 451 |
/** |
| 452 |
* Imports the selected account profiles. |
| 453 |
* |
| 454 |
* @param string $typeId type id |
| 455 |
* @param array<mixed> $options options |
| 456 |
* @param LAMConfig[] $serverProfiles server profiles (name => profile object) |
| 457 |
* @param TypeManager $typeManager type manager |
| 458 |
* @return htmlStatusMessage message or null |
| 459 |
*/ |
| 460 |
function importProfiles($typeId, array $options, &$serverProfiles, TypeManager &$typeManager) { |
| 461 |
$accountProfilesPersistenceManager = new AccountProfilePersistenceManager(); |
| 462 |
foreach ($options as $option) { |
| 463 |
$sourceConfName = $option['conf']; |
| 464 |
$sourceTypeId = $option['typeId']; |
| 465 |
$sourceName = $option['name']; |
| 466 |
if (empty($serverProfiles[$sourceConfName])) { |
| 467 |
continue; |
| 468 |
} |
| 469 |
$sourceTypeManager = new TypeManager($serverProfiles[$sourceConfName]); |
| 470 |
$sourceType = $sourceTypeManager->getConfiguredType($sourceTypeId); |
| 471 |
$targetType = $typeManager->getConfiguredType($typeId); |
| 472 |
if (($sourceType !== null) && ($targetType !== null)) { |
| 473 |
try { |
| 474 |
if ($targetType->getTypeManager()->getConfig() === null) { |
| 475 |
continue; |
| 476 |
} |
| 477 |
$data = $accountProfilesPersistenceManager->loadAccountProfile($sourceType->getId(), $sourceName, $sourceConfName); |
| 478 |
$accountProfilesPersistenceManager->writeAccountProfile($typeId, $sourceName, |
| 479 |
$targetType->getTypeManager()->getConfig()->getName(), $data); |
| 480 |
} |
| 481 |
catch (LAMException $e) { |
| 482 |
return new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); |
| 483 |
} |
| 484 |
} |
| 485 |
} |
| 486 |
return new htmlStatusMessage('INFO', _('Import successful')); |
| 487 |
} |
| 488 |
|
| 489 |
/** |
| 490 |
* Exports the selected account profile. |
| 491 |
* |
| 492 |
* @param string $typeId source type id |
| 493 |
* @param string $name profile name |
| 494 |
* @param array<mixed> $options options |
| 495 |
* @param LAMConfig[] $serverProfiles server profiles (name => profile object) |
| 496 |
* @param TypeManager $typeManager type manager |
| 497 |
* @return htmlStatusMessage|null message or null |
| 498 |
*/ |
| 499 |
function exportProfiles($typeId, $name, array $options, &$serverProfiles, TypeManager &$typeManager): ?htmlStatusMessage { |
| 500 |
$sourceType = $typeManager->getConfiguredType($typeId); |
| 501 |
if ($sourceType === null) { |
| 502 |
return null; |
| 503 |
} |
| 504 |
$accountProfilePersistenceManager = new AccountProfilePersistenceManager(); |
| 505 |
foreach ($options as $option) { |
| 506 |
$targetConfName = $option['conf']; |
| 507 |
if ($targetConfName == 'templates*') { |
| 508 |
try { |
| 509 |
$data = $accountProfilePersistenceManager->loadAccountProfile($sourceType->getId(), $name, $_SESSION['config']->getName()); |
| 510 |
$accountProfilePersistenceManager->writeAccountProfileTemplate($sourceType->getScope(), $name, $data); |
| 511 |
} |
| 512 |
catch (LAMException $e) { |
| 513 |
return new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); |
| 514 |
} |
| 515 |
} |
| 516 |
else { |
| 517 |
$targetTypeId = $option['typeId']; |
| 518 |
if (empty($serverProfiles[$targetConfName])) { |
| 519 |
continue; |
| 520 |
} |
| 521 |
$targetTypeManager = new TypeManager($serverProfiles[$targetConfName]); |
| 522 |
$targetType = $targetTypeManager->getConfiguredType($targetTypeId); |
| 523 |
if ($targetType !== null) { |
| 524 |
try { |
| 525 |
$data = $accountProfilePersistenceManager->loadAccountProfile($sourceType->getId(), $name, $_SESSION['config']->getName()); |
| 526 |
$accountProfilePersistenceManager->writeAccountProfile($targetType->getId(), $name, $targetConfName, $data); |
| 527 |
} |
| 528 |
catch (LAMException $e) { |
| 529 |
return new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); |
| 530 |
} |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
return new htmlStatusMessage('INFO', _('Export successful')); |
| 535 |
} |