Merge pull request #11 from LDAPAccountManager/type_api_tmp

new type API
This commit is contained in:
gruberroland 2016-12-25 18:49:54 +01:00 committed by GitHub
commit 8e9fd5bb36
4 changed files with 81 additions and 68 deletions

View File

@ -19,6 +19,7 @@
@ -48,6 +49,7 @@ This is a list of API changes for all LAM releases.
<h2>5.5 -&gt; 5.6</h2>
Functions in lib/types.inc got namespace LAM/TYPES (e.g. getTypeAlias()).<br>
New API to access configured account types: LAM\TYPES\TypeManager.<br>
<h2>5.4 -&gt; 5.5</h2>Functions Ldap::encrypt/decrypt in ldap.inc moved to lamEncrypt/lamDecrypt in security.inc.<br>
<br>

View File

@ -197,21 +197,27 @@ jQuery(document).ready(function() {
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<?php
$typeManager = new LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
$linkList = array();
foreach ($types as $type) {
if ($type->isHidden()) {
continue;
}
$link = '<a href="' . $headerPrefix . 'lists/list.php?type=' . $type->getId() .
'" onmouseover="jQuery(this).addClass(\'tabs-hover\');" onmouseout="jQuery(this).removeClass(\'tabs-hover\');">' .
'<img height="16" width="16" alt="' . $type->getId() . '" src="' . $headerPrefix . '../graphics/' . $type->getScope() . '.png">&nbsp;' .
$type->getAlias() . '</a>';
echo '<li id="tab_' . $type->getId() . '" class="ui-state-default ui-corner-top">';
echo $link;
echo "</li>\n";
}
printTypeTabs($headerPrefix);
?>
</ul>
<?php
function printTypeTabs($headerPrefix) {
$typeManager = new LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
$linkList = array();
foreach ($types as $type) {
if ($type->isHidden()) {
continue;
}
$link = '<a href="' . $headerPrefix . 'lists/list.php?type=' . $type->getId() .
'" onmouseover="jQuery(this).addClass(\'tabs-hover\');" onmouseout="jQuery(this).removeClass(\'tabs-hover\');">' .
'<img height="16" width="16" alt="' . $type->getId() . '" src="' . $headerPrefix . '../graphics/' . $type->getScope() . '.png">&nbsp;' .
$type->getAlias() . '</a>';
echo '<li id="tab_' . $type->getId() . '" class="ui-state-default ui-corner-top">';
echo $link;
echo "</li>\n";
}
}

View File

@ -51,16 +51,17 @@ if (!empty($_POST)) {
validateSecurityToken();
}
$types = $_SESSION['config']->get_ActiveTypes();
$typeManager = new LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
$profileClasses = array();
$profileClassesTemp = array();
for ($i = 0; $i < sizeof($types); $i++) {
if (isAccountTypeHidden($types[$i]) || !checkIfWriteAccessIsAllowed($types[$i])) {
foreach ($types as $type) {
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) {
continue;
}
$profileClassesTemp[LAM\TYPES\getTypeAlias($types[$i])] = array(
'scope' => $types[$i],
'title' => LAM\TYPES\getTypeAlias($types[$i]),
$profileClassesTemp[$type->getAlias()] = array(
'typeId' => $type->getId(),
'title' => $type->getAlias(),
'profiles' => "");
}
$profileClassesKeys = array_keys($profileClassesTemp);
@ -83,9 +84,9 @@ elseif (isset($_POST['createProfileButton'])) {
}
// check if a profile should be edited
for ($i = 0; $i < sizeof($profileClasses); $i++) {
if (isset($_POST['editProfile_' . $profileClasses[$i]['scope']]) || isset($_POST['editProfile_' . $profileClasses[$i]['scope'] . '_x'])) {
metaRefresh("profilepage.php?type=" . htmlspecialchars($profileClasses[$i]['scope']) .
"&amp;edit=" . htmlspecialchars($_POST['profile_' . $profileClasses[$i]['scope']]));
if (isset($_POST['editProfile_' . $profileClasses[$i]['typeId']]) || isset($_POST['editProfile_' . $profileClasses[$i]['typeId'] . '_x'])) {
metaRefresh("profilepage.php?type=" . htmlspecialchars($profileClasses[$i]['typeId']) .
"&amp;edit=" . htmlspecialchars($_POST['profile_' . $profileClasses[$i]['typeId']]));
exit;
}
}
@ -99,18 +100,19 @@ $container = new htmlTable();
$container->addElement(new htmlTitle(_("Profile editor")), true);
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
if (isAccountTypeHidden($_POST['profileDeleteType'])) {
$type = $typeManager->getConfiguredType($_POST['profileDeleteType']);
if ($type->isHidden()) {
logNewMessage(LOG_ERR, 'User tried to delete hidden account type profile: ' . $_POST['profileDeleteType']);
die();
}
// delete profile
if (delAccountProfile($_POST['profileDeleteName'], $_POST['profileDeleteType'])) {
$message = new htmlStatusMessage('INFO', _('Deleted profile.'), LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message = new htmlStatusMessage('INFO', _('Deleted profile.'), $type->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
}
else {
$message = new htmlStatusMessage('ERROR', _('Unable to delete profile!'), LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message = new htmlStatusMessage('ERROR', _('Unable to delete profile!'), $type->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
}
@ -120,12 +122,12 @@ if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) {
$cfg = new LAMCfgMain();
$impExpMessage = null;
if (isset($_POST['importProfiles_' . $_POST['scope']])) {
if (isset($_POST['importProfiles_' . $_POST['typeId']])) {
// check master password
if (!$cfg->checkPassword($_POST['passwd_' . $_POST['scope']])) {
if (!$cfg->checkPassword($_POST['passwd_' . $_POST['typeId']])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyAccountProfiles($_POST['importProfiles_' . $_POST['scope']], $_POST['scope'])) {
elseif (copyAccountProfiles($_POST['importProfiles_' . $_POST['typeId']], $_POST['typeId'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Import successful'));
}
} else if (isset($_POST['exportProfiles'])) {
@ -133,7 +135,7 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) {
if (!$cfg->checkPassword($_POST['passwd'])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyAccountProfiles($_POST['exportProfiles'], $_POST['scope'], $_POST['destServerProfiles'])) {
elseif (copyAccountProfiles($_POST['exportProfiles'], $_POST['typeId'], $_POST['destServerProfiles'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Export successful'));
}
}
@ -145,7 +147,7 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) {
// get list of profiles for each account type
for ($i = 0; $i < sizeof($profileClasses); $i++) {
$profileList = getAccountProfiles($profileClasses[$i]['scope']);
$profileList = getAccountProfiles($profileClasses[$i]['typeId']);
natcasesort($profileList);
$profileClasses[$i]['profiles'] = $profileList;
}
@ -161,7 +163,7 @@ if (!empty($profileClasses)) {
$container->addElement(new htmlSubTitle(_('Create a new profile')), true);
$sortedTypes = array();
for ($i = 0; $i < sizeof($profileClasses); $i++) {
$sortedTypes[$profileClasses[$i]['title']] = $profileClasses[$i]['scope'];
$sortedTypes[$profileClasses[$i]['title']] = $profileClasses[$i]['typeId'];
}
natcasesort($sortedTypes);
$newContainer = new htmlTable();
@ -188,32 +190,32 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$existingContainer->addElement(new htmlSpacer(null, '10px'), true);
}
$existingContainer->addElement(new htmlImage('../../graphics/' . $profileClasses[$i]['scope'] . '.png'));
$existingContainer->addElement(new htmlImage('../../graphics/' . $profileClasses[$i]['typeId'] . '.png'));
$existingContainer->addElement(new htmlSpacer('3px', null));
$existingContainer->addElement(new htmlOutputText($profileClasses[$i]['title']));
$existingContainer->addElement(new htmlSpacer('3px', null));
$select = new htmlSelect('profile_' . $profileClasses[$i]['scope'], $profileClasses[$i]['profiles']);
$select = new htmlSelect('profile_' . $profileClasses[$i]['typeId'], $profileClasses[$i]['profiles']);
$select->setWidth('15em');
$existingContainer->addElement($select);
$existingContainer->addElement(new htmlSpacer('3px', null));
$editButton = new htmlButton('editProfile_' . $profileClasses[$i]['scope'], 'edit.png', true);
$editButton = new htmlButton('editProfile_' . $profileClasses[$i]['typeId'], 'edit.png', true);
$editButton->setTitle(_('Edit'));
$existingContainer->addElement($editButton);
$deleteLink = new htmlLink(null, '#', '../../graphics/delete.png');
$deleteLink->setTitle(_('Delete'));
$deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['scope'] . "', '" . 'profile_' . $profileClasses[$i]['scope'] . "');");
$deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', '" . 'profile_' . $profileClasses[$i]['typeId'] . "');");
$existingContainer->addElement($deleteLink);
if (count($configProfiles) > 1) {
$importLink = new htmlLink(null, '#', '../../graphics/import.png');
$importLink->setTitle(_('Import profiles'));
$importLink->setOnClick("showDistributionDialog('" . _("Import profiles") . "', '" .
_('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['scope'] . "', 'import');");
_('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', 'import');");
$existingContainer->addElement($importLink);
}
$exportLink = new htmlLink(null, '#', '../../graphics/export.png');
$exportLink->setTitle(_('Export profile'));
$exportLink->setOnClick("showDistributionDialog('" . _("Export profile") . "', '" .
_('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['scope'] . "', 'export', '" . 'profile_' . $profileClasses[$i]['scope'] . "', '" . $_SESSION['config']->getName() . "');");
_('Ok') . "', '" . _('Cancel') . "', '" . $profileClasses[$i]['typeId'] . "', 'export', '" . 'profile_' . $profileClasses[$i]['typeId'] . "', '" . $_SESSION['config']->getName() . "');");
$existingContainer->addElement($exportLink);
$existingContainer->addNewLine();
}
@ -228,11 +230,11 @@ echo "</form>\n";
echo "</div>\n";
for ($i = 0; $i < sizeof($profileClasses); $i++) {
$scope = $profileClasses[$i]['scope'];
$typeId = $profileClasses[$i]['typeId'];
$tmpArr = array();
foreach ($configProfiles as $profile) {
if ($profile != $_SESSION['config']->getName()) {
$accountProfiles = getAccountProfiles($scope, $profile);
$accountProfiles = getAccountProfiles($typeId, $profile);
if (!empty($accountProfiles)) {
for ($p = 0; $p < sizeof($accountProfiles); $p++) {
$tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p];
@ -242,13 +244,13 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
}
//import dialog
echo "<div id=\"importDialog_$scope\" class=\"hidden\">\n";
echo "<form id=\"importDialogForm_$scope\" method=\"post\" action=\"profilemain.php\">\n";
echo "<div id=\"importDialog_$typeId\" class=\"hidden\">\n";
echo "<form id=\"importDialogForm_$typeId\" method=\"post\" action=\"profilemain.php\">\n";
$container = new htmlTable();
$container->addElement(new htmlOutputText(_('Profiles')), true);
$select = new htmlSelect('importProfiles_' . $scope, $tmpArr, array(), count($tmpArr, 1) < 15 ? count($tmpArr, 1) : 15);
$select = new htmlSelect('importProfiles_' . $typeId, $tmpArr, array(), count($tmpArr, 1) < 15 ? count($tmpArr, 1) : 15);
$select->setMultiSelect(true);
$select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true);
@ -260,12 +262,12 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd_' . $scope);
$exportPasswd = new htmlInputField('passwd_' . $typeId);
$exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1'));
$container->addElement(new htmlHiddenInput('scope', $scope), true);
$container->addElement(new htmlHiddenInput('typeId', $typeId), true);
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');

View File

@ -3,7 +3,7 @@
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2015 Roland Gruber
Copyright (C) 2003 - 2016 Roland Gruber
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
@ -62,10 +62,16 @@ if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
}
// copy type and profile name from POST to GET
if (isset($_POST['profname'])) $_GET['edit'] = $_POST['profname'];
if (isset($_POST['accounttype'])) $_GET['type'] = $_POST['accounttype'];
if (isset($_POST['profname'])) {
$_GET['edit'] = $_POST['profname'];
}
if (isset($_POST['accounttype'])) {
$_GET['type'] = $_POST['accounttype'];
}
if (isAccountTypeHidden($_GET['type']) || !checkIfWriteAccessIsAllowed($_GET['type'])) {
$typeManager = new LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($_GET['type']);
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($_GET['type'])) {
logNewMessage(LOG_ERR, 'User tried to access hidden account type profile: ' . $_GET['type']);
die();
}
@ -144,11 +150,8 @@ if (sizeof($errors) > 0) {
// empty list of attribute types
$_SESSION['profile_types'] = array();
// check if account type is valid
$type = $_GET['type'];
// get module options
$options = getProfileOptions($type);
$options = getProfileOptions($type->getId());
// load old profile or POST values if needed
$old_options = array();
@ -169,11 +172,11 @@ if (isset($_POST['save'])) {
}
}
elseif (isset($_GET['edit'])) {
$old_options = loadAccountProfile($_GET['edit'], $type);
$old_options = loadAccountProfile($_GET['edit'], $type->getId());
}
// display formular
echo "<form action=\"profilepage.php?type=$type\" method=\"post\">\n";
echo "<form action=\"profilepage.php?type=" . $type->getId() . "\" method=\"post\">\n";
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">';
$profName = '';
@ -192,10 +195,10 @@ $dnContent->addElement(new htmlTableExtendedInputField(_("Profile name") . '*',
$dnContent->addElement(new htmlSpacer(null, '10px'), true);
// suffix box
// get root suffix
$rootsuffix = $_SESSION['config']->get_Suffix($type);
$rootsuffix = $type->getSuffix();
// get subsuffixes
$suffixes = array('-' => '-');
$typeObj = new $type();
$typeObj = $type->getBaseType();
$possibleSuffixes = $typeObj->getSuffixList();
foreach ($possibleSuffixes as $suffix) {
$suffixes[getAbstractDN($suffix)] = $suffix;
@ -210,7 +213,7 @@ $suffixSelect->setSortElements(false);
$suffixSelect->setRightToLeftTextDirection(true);
$dnContent->addElement($suffixSelect, true);
// RDNs
$rdns = getRDNAttributes($type);
$rdns = getRDNAttributes($type->getId());
$selectedRDN = array();
if (isset($old_options['ldap_rdn'][0])) {
$selectedRDN[] = $old_options['ldap_rdn'][0];
@ -220,22 +223,22 @@ $dnContent->addElement(new htmlTableExtendedSelect('ldap_rdn', $rdns, $selectedR
$container->addElement(new htmlFieldset($dnContent, _("General settings"), '../../graphics/logo32.png'), true);
$container->addElement(new htmlSpacer(null, '15px'), true);
$_SESSION['profile_types'] = parseHtml(null, $container, $old_options, false, $tabindex, $type);
$_SESSION['profile_types'] = parseHtml(null, $container, $old_options, false, $tabindex, $type->getScope());
// display module options
$modules = array_keys($options);
for ($m = 0; $m < sizeof($modules); $m++) {
// ignore modules without options
if (sizeof($options[$modules[$m]]) < 1) continue;
$module = new $modules[$m]($type);
$module = new $modules[$m]($type->getId());
$icon = $module->getIcon();
if (($icon != null) && !(strpos($icon, 'http') === 0) && !(strpos($icon, '/') === 0)) {
$icon = '../../graphics/' . $icon;
}
$container = new htmlTable();
$container->addElement(new htmlFieldset($options[$modules[$m]], getModuleAlias($modules[$m], $type), $icon), true);
$container->addElement(new htmlFieldset($options[$modules[$m]], getModuleAlias($modules[$m], $type->getScope()), $icon), true);
$container->addElement(new htmlSpacer(null, '15px'), true);
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml($modules[$m], $container, $old_options, false, $tabindex, $type));
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml($modules[$m], $container, $old_options, false, $tabindex, $type->getScope()));
}
// profile name and submit/abort buttons
@ -246,9 +249,9 @@ $buttonTable->addElement($saveButton);
$cancelButton = new htmlButton('abort', _('Cancel'));
$cancelButton->setIconClass('cancelButton');
$buttonTable->addElement($cancelButton);
$buttonTable->addElement(new htmlHiddenInput('accounttype', $type));
$buttonTable->addElement(new htmlHiddenInput('accounttype', $type->getId()));
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml(null, $buttonTable, $old_options, false, $tabindex, $type));
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml(null, $buttonTable, $old_options, false, $tabindex, $type->getScope()));
?>
<script type="text/javascript">