2004-03-09 14:29:47 +00:00
|
|
|
<?php
|
2016-12-26 09:02:08 +00:00
|
|
|
namespace LAM\TOOLS\PROFILE_EDITOR;
|
2018-05-17 17:56:58 +00:00
|
|
|
use \htmlResponsiveRow;
|
2016-12-26 09:02:08 +00:00
|
|
|
use \htmlTitle;
|
2018-05-17 17:56:58 +00:00
|
|
|
use \htmlResponsiveInputField;
|
|
|
|
use \htmlResponsiveSelect;
|
2016-12-26 09:02:08 +00:00
|
|
|
use \htmlButton;
|
|
|
|
use \htmlHiddenInput;
|
2018-05-17 17:56:58 +00:00
|
|
|
use \htmlSubTitle;
|
2004-03-09 14:29:47 +00:00
|
|
|
/*
|
|
|
|
|
2009-10-27 18:47:12 +00:00
|
|
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
2019-09-22 11:19:26 +00:00
|
|
|
Copyright (C) 2003 - 2019 Roland Gruber
|
2004-03-09 14:29:47 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2004-06-10 22:13:39 +00:00
|
|
|
*/
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2004-06-10 22:13:39 +00:00
|
|
|
/**
|
|
|
|
* Manages creating/changing of profiles.
|
|
|
|
*
|
2004-10-09 11:04:20 +00:00
|
|
|
* @package profiles
|
2004-06-10 22:13:39 +00:00
|
|
|
* @author Roland Gruber
|
2004-03-09 14:29:47 +00:00
|
|
|
*/
|
|
|
|
|
2006-03-26 17:51:25 +00:00
|
|
|
/** security functions */
|
2018-12-23 16:46:31 +00:00
|
|
|
include_once(__DIR__ . "/../../lib/security.inc");
|
2004-06-10 22:13:39 +00:00
|
|
|
/** helper functions for profiles */
|
2018-12-23 16:46:31 +00:00
|
|
|
include_once(__DIR__ . "/../../lib/profiles.inc");
|
2004-06-10 22:13:39 +00:00
|
|
|
/** access to LDAP server */
|
2018-12-23 16:46:31 +00:00
|
|
|
include_once(__DIR__ . "/../../lib/ldap.inc");
|
2004-06-10 22:13:39 +00:00
|
|
|
/** access to configuration options */
|
2018-12-23 16:46:31 +00:00
|
|
|
include_once(__DIR__ . "/../../lib/config.inc");
|
2004-06-10 22:13:39 +00:00
|
|
|
/** access to account modules */
|
2018-12-23 16:46:31 +00:00
|
|
|
include_once(__DIR__ . "/../../lib/modules.inc");
|
2005-07-12 15:52:15 +00:00
|
|
|
/** Used to display status messages */
|
2018-12-23 16:46:31 +00:00
|
|
|
include_once(__DIR__ . "/../../lib/status.inc");
|
2004-03-09 14:29:47 +00:00
|
|
|
|
|
|
|
// start session
|
2006-03-26 17:51:25 +00:00
|
|
|
startSecureSession();
|
2017-02-11 16:11:37 +00:00
|
|
|
enforceUserIsLoggedIn();
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2007-12-30 13:15:39 +00:00
|
|
|
// die if no write access
|
|
|
|
if (!checkIfWriteAccessIsAllowed()) die();
|
|
|
|
|
2012-08-13 17:43:48 +00:00
|
|
|
checkIfToolIsActive('toolProfileEditor');
|
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
setlanguage();
|
|
|
|
|
2015-05-15 19:16:46 +00:00
|
|
|
if (!empty($_POST)) {
|
|
|
|
validateSecurityToken();
|
|
|
|
}
|
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
// check if user is logged in, if not go to login
|
|
|
|
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
|
|
|
|
metaRefresh("../login.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// copy type and profile name from POST to GET
|
2016-12-25 17:46:41 +00:00
|
|
|
if (isset($_POST['profname'])) {
|
|
|
|
$_GET['edit'] = $_POST['profname'];
|
|
|
|
}
|
|
|
|
if (isset($_POST['accounttype'])) {
|
|
|
|
$_GET['type'] = $_POST['accounttype'];
|
|
|
|
}
|
2005-07-12 15:52:15 +00:00
|
|
|
|
2016-12-26 09:02:08 +00:00
|
|
|
$typeManager = new \LAM\TYPES\TypeManager();
|
2016-12-25 17:46:41 +00:00
|
|
|
$type = $typeManager->getConfiguredType($_GET['type']);
|
|
|
|
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($_GET['type'])) {
|
2013-01-01 20:46:28 +00:00
|
|
|
logNewMessage(LOG_ERR, 'User tried to access hidden account type profile: ' . $_GET['type']);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// abort button was pressed
|
|
|
|
// back to profile editor
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST['abort'])) {
|
2005-07-12 15:52:15 +00:00
|
|
|
metaRefresh("profilemain.php");
|
|
|
|
exit;
|
|
|
|
}
|
2004-03-14 15:34:53 +00:00
|
|
|
|
2010-05-26 17:30:55 +00:00
|
|
|
$errors = array();
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// save button was presed
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST['save'])) {
|
2005-07-12 15:52:15 +00:00
|
|
|
// create option array to check and save
|
|
|
|
$options = array();
|
|
|
|
$opt_keys = array_keys($_SESSION['profile_types']);
|
|
|
|
foreach ($opt_keys as $element) {
|
|
|
|
// text fields
|
|
|
|
if ($_SESSION['profile_types'][$element] == "text") {
|
|
|
|
$options[$element] = array($_POST[$element]);
|
|
|
|
}
|
|
|
|
// checkboxes
|
|
|
|
elseif ($_SESSION['profile_types'][$element] == "checkbox") {
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST[$element]) && ($_POST[$element] == "on")) $options[$element] = array('true');
|
2005-07-12 15:52:15 +00:00
|
|
|
else $options[$element] = array('false');
|
|
|
|
}
|
|
|
|
// dropdownbox
|
|
|
|
elseif ($_SESSION['profile_types'][$element] == "select") {
|
|
|
|
$options[$element] = array($_POST[$element]);
|
|
|
|
}
|
|
|
|
// multiselect
|
|
|
|
elseif ($_SESSION['profile_types'][$element] == "multiselect") {
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST[$element])) $options[$element] = $_POST[$element]; // value is already an array
|
|
|
|
else $options[$element] = array();
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
2012-08-26 14:09:22 +00:00
|
|
|
// textareas
|
|
|
|
if ($_SESSION['profile_types'][$element] == "textarea") {
|
|
|
|
$options[$element] = explode("\r\n", $_POST[$element]);
|
|
|
|
}
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
2016-12-25 17:46:41 +00:00
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// check options
|
|
|
|
$errors = checkProfileOptions($_POST['accounttype'], $options);
|
2010-05-26 17:30:55 +00:00
|
|
|
if (sizeof($errors) == 0) { // input data is valid, save profile
|
2005-07-12 15:52:15 +00:00
|
|
|
// save profile
|
2017-01-06 12:56:17 +00:00
|
|
|
if (\LAM\PROFILES\saveAccountProfile($options, $_POST['profname'], $_POST['accounttype'])) {
|
2010-05-26 17:30:55 +00:00
|
|
|
metaRefresh('profilemain.php?savedSuccessfully=' . $_POST['profname']);
|
2005-07-12 15:52:15 +00:00
|
|
|
exit();
|
|
|
|
}
|
2010-05-26 17:30:55 +00:00
|
|
|
else {
|
|
|
|
$errors[] = array("ERROR", _("Unable to save profile!"), $_POST['profname']);
|
|
|
|
}
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-26 17:30:55 +00:00
|
|
|
// print header
|
2018-12-23 16:46:31 +00:00
|
|
|
include __DIR__ . '/../../lib/adminHeader.inc';
|
2018-05-17 17:56:58 +00:00
|
|
|
echo '<div class="user-bright smallPaddingContent">';
|
2010-05-26 17:30:55 +00:00
|
|
|
|
|
|
|
// print error messages if any
|
|
|
|
if (sizeof($errors) > 0) {
|
2010-12-19 13:51:39 +00:00
|
|
|
echo "<br>\n";
|
2018-01-07 16:00:02 +00:00
|
|
|
foreach ($errors as $error) {
|
|
|
|
call_user_func_array('StatusMessage', $error);
|
2010-05-26 17:30:55 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-25 17:46:41 +00:00
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// empty list of attribute types
|
|
|
|
$_SESSION['profile_types'] = array();
|
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
// get module options
|
2016-12-25 17:46:41 +00:00
|
|
|
$options = getProfileOptions($type->getId());
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// load old profile or POST values if needed
|
2004-03-15 16:34:16 +00:00
|
|
|
$old_options = array();
|
2005-07-12 15:52:15 +00:00
|
|
|
if (isset($_POST['save'])) {
|
2018-01-07 16:00:02 +00:00
|
|
|
foreach ($_POST as $key => $value) {
|
|
|
|
if (!is_array($value)) {
|
|
|
|
$old_options[$key] = array($value);
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-01-07 16:00:02 +00:00
|
|
|
$old_options[$key] = $value;
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (isset($_GET['edit'])) {
|
2017-01-06 12:56:17 +00:00
|
|
|
$old_options = \LAM\PROFILES\loadAccountProfile($_GET['edit'], $type->getId());
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// display formular
|
2018-06-30 07:49:20 +00:00
|
|
|
echo "<form id=\"profilepage\" action=\"profilepage.php?type=" . $type->getId() . "\" method=\"post\">\n";
|
2015-05-15 19:16:46 +00:00
|
|
|
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">';
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2010-09-25 16:39:07 +00:00
|
|
|
$profName = '';
|
|
|
|
if (isset($_GET['edit'])) {
|
|
|
|
$profName = $_GET['edit'];
|
|
|
|
}
|
|
|
|
|
2010-12-19 13:51:39 +00:00
|
|
|
$tabindex = 1;
|
2010-09-25 16:39:07 +00:00
|
|
|
|
2018-05-17 17:56:58 +00:00
|
|
|
$container = new htmlResponsiveRow();
|
|
|
|
$container->add(new htmlTitle(_("Profile editor")), 12);
|
2010-09-25 16:39:07 +00:00
|
|
|
|
2010-12-19 13:51:39 +00:00
|
|
|
// general options
|
2018-05-17 17:56:58 +00:00
|
|
|
$container->add(new htmlSubTitle(_("General settings"), '../../graphics/logo32.png', null, true), 12);
|
|
|
|
$container->add(new htmlResponsiveInputField(_("Profile name") . '*', 'profname', $profName, '360'), 12);
|
|
|
|
$container->addVerticalSpacer('1rem');
|
2004-06-27 18:07:43 +00:00
|
|
|
// suffix box
|
|
|
|
// get root suffix
|
2016-12-25 17:46:41 +00:00
|
|
|
$rootsuffix = $type->getSuffix();
|
2004-06-27 18:07:43 +00:00
|
|
|
// get subsuffixes
|
2011-05-14 13:51:08 +00:00
|
|
|
$suffixes = array('-' => '-');
|
2016-12-31 13:44:46 +00:00
|
|
|
$possibleSuffixes = $type->getSuffixList();
|
2011-04-25 18:01:11 +00:00
|
|
|
foreach ($possibleSuffixes as $suffix) {
|
2010-12-19 13:51:39 +00:00
|
|
|
$suffixes[getAbstractDN($suffix)] = $suffix;
|
2004-06-27 18:07:43 +00:00
|
|
|
}
|
2010-12-19 13:51:39 +00:00
|
|
|
$selectedSuffix = array();
|
|
|
|
if (isset($old_options['ldap_suffix'][0])) {
|
|
|
|
$selectedSuffix[] = $old_options['ldap_suffix'][0];
|
|
|
|
}
|
2018-05-17 17:56:58 +00:00
|
|
|
$suffixSelect = new htmlResponsiveSelect('ldap_suffix', $suffixes, $selectedSuffix, _("LDAP suffix"), '361');
|
2010-12-19 13:51:39 +00:00
|
|
|
$suffixSelect->setHasDescriptiveElements(true);
|
|
|
|
$suffixSelect->setSortElements(false);
|
|
|
|
$suffixSelect->setRightToLeftTextDirection(true);
|
2018-05-17 17:56:58 +00:00
|
|
|
$container->add($suffixSelect, 12);
|
2010-12-19 13:51:39 +00:00
|
|
|
// RDNs
|
2016-12-25 17:46:41 +00:00
|
|
|
$rdns = getRDNAttributes($type->getId());
|
2010-12-19 13:51:39 +00:00
|
|
|
$selectedRDN = array();
|
|
|
|
if (isset($old_options['ldap_rdn'][0])) {
|
|
|
|
$selectedRDN[] = $old_options['ldap_rdn'][0];
|
|
|
|
}
|
2018-05-17 17:56:58 +00:00
|
|
|
$container->add(new htmlResponsiveSelect('ldap_rdn', $rdns, $selectedRDN, _("RDN identifier"), '301'), 12);
|
2005-05-21 14:35:14 +00:00
|
|
|
|
2018-05-17 17:56:58 +00:00
|
|
|
$container->addVerticalSpacer('2rem');
|
2010-12-19 13:51:39 +00:00
|
|
|
|
2016-12-25 17:46:41 +00:00
|
|
|
$_SESSION['profile_types'] = parseHtml(null, $container, $old_options, false, $tabindex, $type->getScope());
|
2004-06-27 18:07:43 +00:00
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
// display module options
|
2018-01-07 16:00:02 +00:00
|
|
|
foreach ($options as $moduleName => $moduleOptions) {
|
2004-03-09 14:29:47 +00:00
|
|
|
// ignore modules without options
|
2018-06-30 07:16:43 +00:00
|
|
|
if (empty($moduleOptions)) {
|
2018-01-07 16:00:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$module = new $moduleName($type->getScope());
|
2010-12-19 13:51:39 +00:00
|
|
|
$icon = $module->getIcon();
|
2017-09-18 17:39:08 +00:00
|
|
|
if (!empty($icon) && !(strpos($icon, 'http') === 0) && !(strpos($icon, '/') === 0)) {
|
2010-12-19 13:51:39 +00:00
|
|
|
$icon = '../../graphics/' . $icon;
|
2007-11-19 18:52:50 +00:00
|
|
|
}
|
2018-05-17 17:56:58 +00:00
|
|
|
$modContainer = new htmlResponsiveRow();
|
|
|
|
$modContainer->add(new htmlSubTitle(getModuleAlias($moduleName, $type->getScope()), $icon, null, true), 12);
|
|
|
|
$modContainer->add($moduleOptions, 12);
|
|
|
|
$modContainer->addVerticalSpacer('2rem');
|
|
|
|
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml($moduleName, $modContainer, $old_options, false, $tabindex, $type->getScope()));
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
2010-12-19 13:51:39 +00:00
|
|
|
// profile name and submit/abort buttons
|
2018-05-17 17:56:58 +00:00
|
|
|
$buttonTable = new htmlResponsiveRow();
|
2010-12-19 13:51:39 +00:00
|
|
|
$saveButton = new htmlButton('save', _('Save'));
|
|
|
|
$saveButton->setIconClass('saveButton');
|
2018-05-17 17:56:58 +00:00
|
|
|
$buttonTable->addLabel($saveButton);
|
2010-12-19 13:51:39 +00:00
|
|
|
$cancelButton = new htmlButton('abort', _('Cancel'));
|
|
|
|
$cancelButton->setIconClass('cancelButton');
|
2018-05-17 17:56:58 +00:00
|
|
|
$buttonTable->addField($cancelButton);
|
|
|
|
$buttonTable->add(new htmlHiddenInput('accounttype', $type->getId()), 0);
|
2010-12-19 13:51:39 +00:00
|
|
|
|
2016-12-25 17:46:41 +00:00
|
|
|
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml(null, $buttonTable, $old_options, false, $tabindex, $type->getScope()));
|
2010-12-19 13:51:39 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
2019-09-22 11:19:26 +00:00
|
|
|
jQuery("#profilepage").validationEngine({promptPosition: "topLeft", addFailureCssClassToField: "lam-input-error", autoHidePrompt: true, autoHideDelay: 5000});
|
2010-12-19 13:51:39 +00:00
|
|
|
</script>
|
2018-05-17 17:56:58 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
2010-12-19 13:51:39 +00:00
|
|
|
<?php
|
2018-12-23 16:46:31 +00:00
|
|
|
include __DIR__ . '/../../lib/adminFooter.inc';
|
2004-03-09 14:29:47 +00:00
|
|
|
|
|
|
|
?>
|