Merge pull request #10 from LDAPAccountManager/type_api_tmp

new type API
This commit is contained in:
gruberroland 2016-12-24 15:46:35 +01:00 committed by GitHub
commit ad77a4054f
6 changed files with 69 additions and 66 deletions

View File

@ -1,4 +1,6 @@
<?php
use LAM\TYPES\ConfiguredType;
/*
$Id$
@ -688,17 +690,12 @@ class accountContainer {
/**
* Constructor
*
* @param string $type account type
* @param ConfiguredType $type account type
* @param string $base key in $_SESSION where this object is saved
* @param integer $randomID random ID to avoid parallel editing (default: null)
*/
function __construct($type, $base, $randomID = null) {
/* Set the type of account. Valid
* types are: user, group, host
*/
// Check input variable
if (!is_string($type)) trigger_error('Argument of accountContainer must be string.', E_USER_ERROR);
if (!($type instanceof ConfiguredType)) trigger_error('Argument of accountContainer must be ConfiguredType.', E_USER_ERROR);
if (!is_string($base)) trigger_error('Argument of accountContainer must be string.', E_USER_ERROR);
$this->type = $type;
$this->base = $base;
@ -800,7 +797,7 @@ class accountContainer {
/**
* Returns the accout type of this object (e.g. user, group, host).
*
* @return string account type
* @return ConfiguredType account type
*/
function get_type() {
return $this->type;
@ -812,7 +809,7 @@ class accountContainer {
*/
function continue_main() {
if (!empty($_POST['account_randomID']) && ($this->randomID != $_POST['account_randomID'])) {
metaRefresh("../lists/list.php?type=" . $this->type . '&amp;accountEditInvalidID=true');
metaRefresh("../lists/list.php?type=" . $this->type->getId() . '&amp;accountEditInvalidID=true');
exit();
}
$oldPage = $this->current_page;
@ -821,7 +818,7 @@ class accountContainer {
$result = array();
$stopProcessing = false; // when set to true, no module options are displayed
$errorsOccured = false;
$typeObject = new $this->type();
$typeObject = $this->type->getBaseType();
$profileLoaded = $this->loadProfileIfRequested();
if ($this->subpage=='') $this->subpage='attributes';
if (isset($_POST['accountContainerReset'])) {
@ -843,30 +840,30 @@ class accountContainer {
if (isset($_POST['accountContainerCreateAgain'])) {
// open fresh account page
unset($_SESSION[$this->base]);
metaRefresh("edit.php?type=" . $this->type . "&amp;suffix=" . $this->dnSuffix);
metaRefresh("edit.php?type=" . $this->type->getId() . "&amp;suffix=" . $this->dnSuffix);
exit();
}
// reedit account
if (isset($_POST['accountContainerBackToEdit'])) {
// open fresh account page
unset($_SESSION[$this->base]);
metaRefresh("edit.php?type=" . $this->type . "&amp;DN=" . urlencode($this->finalDN));
metaRefresh("edit.php?type=" . $this->type->getId() . "&amp;DN=" . urlencode($this->finalDN));
exit();
}
// back to account list
if (isset($_POST['accountContainerBackToList'])) {
// Return to account list
unset($_SESSION[$this->base]);
metaRefresh("../lists/list.php?type=" . $this->type . '&amp;accountEditBack=true');
metaRefresh("../lists/list.php?type=" . $this->type->getId() . '&amp;accountEditBack=true');
exit;
}
// create PDF file
if (isset($_POST['accountContainerCreatePDF'])) {
metaRefresh('../lists/list.php?printPDF=1&amp;type=' . $this->type . "&amp;refresh=true&amp;PDFSessionID=" . $this->base);
metaRefresh('../lists/list.php?printPDF=1&amp;type=' . $this->type->getId() . "&amp;refresh=true&amp;PDFSessionID=" . $this->base);
exit;
}
// module actions
if ((sizeof($_POST) > 0) && checkIfWriteAccessIsAllowed($this->type)) {
if ((sizeof($_POST) > 0) && checkIfWriteAccessIsAllowed($this->type->getId())) {
$result = call_user_func(array(&$this->module[$this->order[$this->current_page]], 'process_'.$this->subpage));
if (is_array($result)) { // messages were returned, check for errors
for ($i = 0; $i < sizeof($result); $i++) {
@ -987,13 +984,13 @@ class accountContainer {
}
}
echo '<div id="passwordMessageArea"></div>';
echo "<table class=\"".$this->type."-bright\" border=0 width=\"100%\" style=\"border-collapse: collapse;\">\n";
if (checkIfWriteAccessIsAllowed($this->type)) {
echo "<tr class=\"".$this->type."-bright\"><td style=\"padding: 15px 15px 0px 15px;\">\n";
echo "<table class=\"".$this->type->getScope()."-bright\" border=0 width=\"100%\" style=\"border-collapse: collapse;\">\n";
if (checkIfWriteAccessIsAllowed($this->type->getId())) {
echo "<tr class=\"" . $this->type->getScope() . "-bright\"><td style=\"padding: 15px 15px 0px 15px;\">\n";
$this->printCommonControls($tabindex);
echo "</td></tr>\n";
}
echo "<tr class=\"".$this->type."-bright\" valign=\"top\"><td style=\"padding: 15px;\">";
echo "<tr class=\"" . $this->type->getScope() . "-bright\" valign=\"top\"><td style=\"padding: 15px;\">";
// print title bar
echo '<div class="titleBar ui-corner-top">';
echo '<table width="100%"><tr>';
@ -1021,10 +1018,10 @@ class accountContainer {
// RDN selection
$group->addElement(new htmlOutputText(_('RDN identifier')));
$group->addElement(new htmlSpacer('2px', null));
$rdnlist = getRDNAttributes($this->type);
$rdnlist = getRDNAttributes($this->type->getId());
$group->addElement(new htmlSelect('accountContainerRDN', $rdnlist, array($this->rdn)));
$group->addElement(new htmlHelpLink('301'));
parseHtml(null, $group, array(), true, $tabindex, $this->type);
parseHtml(null, $group, array(), true, $tabindex, $this->type->getScope());
echo '</td>';
echo '</tr></table>';
if ($this->titleBarSubtitle != null) {
@ -1044,7 +1041,7 @@ class accountContainer {
// display html-code from modules
$return = call_user_func(array($this->module[$this->order[$this->current_page]], 'display_html_'.$this->subpage));
$y = 5000;
parseHtml($this->order[$this->current_page], $return, array(), false, $y, $this->type);
parseHtml($this->order[$this->current_page], $return, array(), false, $y, $this->type->getScope());
echo "</div>\n";
echo '</td>';
echo '</tr>';
@ -1114,9 +1111,9 @@ class accountContainer {
if (!(strpos($buttonImage, 'http') === 0) && !(strpos($buttonImage, '/') === 0)) {
$buttonImage = '../../graphics/' . $buttonImage;
}
$moduleContainer->addElement(new htmlImage($buttonImage, null, null, getModuleAlias($name, $this->type)));
$moduleContainer->addElement(new htmlImage($buttonImage, null, null, getModuleAlias($name, $this->type->getScope())));
}
$moduleContainer->addElement(new htmlTableExtendedInputCheckbox('password_cb_' . $name, true, getModuleAlias($name, $this->type), null, false));
$moduleContainer->addElement(new htmlTableExtendedInputCheckbox('password_cb_' . $name, true, getModuleAlias($name, $this->type->getScope()), null, false));
$moduleContainer->addElement(new htmlSpacer('10px', null));
}
}
@ -1125,7 +1122,7 @@ class accountContainer {
// generate HTML
$tabindex = 2000;
if ($printContainer) {
parseHtml(null, $container, array(), false, $tabindex, $this->type);
parseHtml(null, $container, array(), false, $tabindex, $this->type->getScope());
}
echo "</div>\n";
}
@ -1260,7 +1257,7 @@ class accountContainer {
$rightGroup = new htmlGroup();
$rightGroup->alignment = htmlElement::ALIGN_RIGHT;
// profile selection
$profilelist = getAccountProfiles($this->type);
$profilelist = getAccountProfiles($this->type->getId());
if (sizeof($profilelist) > 0) {
$rightGroup->addElement(new htmlSelect('accountContainerSelectLoadProfile', $profilelist, array($this->lastLoadedProfile)));
$profileButton = new htmlButton('accountContainerLoadProfile', _('Load profile'));
@ -1275,7 +1272,7 @@ class accountContainer {
}
$table->addElement($rightGroup);
parseHtml(null, $table, array(), false, $tabindex, $this->type);
parseHtml(null, $table, array(), false, $tabindex, $this->type->getScope());
?>
<script type="text/javascript">
jQuery(document).ready(function() {
@ -1347,7 +1344,7 @@ class accountContainer {
else {
$text = _("Account was modified successfully.");
}
echo "<div class=\"".$this->type."-bright smallPaddingContent\">";
echo "<div class=\"" . $this->type->getScope() . "-bright smallPaddingContent\">";
$container = new htmlTable();
// show messages
@ -1368,9 +1365,9 @@ class accountContainer {
$container->addElement($message, true);
$container->addElement(new htmlSpacer(null, '20px'), true);
$type = new $this->type();
$type = $this->type->getBaseType();
$buttonGroup = new htmlGroup();
if (checkIfNewEntriesAreAllowed($this->type)) {
if (checkIfNewEntriesAreAllowed($this->type->getId())) {
$createButton = new htmlButton('accountContainerCreateAgain', $type->LABEL_CREATE_ANOTHER_ACCOUNT);
$createButton->setIconClass('createButton');
$buttonGroup->addElement($createButton);
@ -1390,7 +1387,7 @@ class accountContainer {
$container->addElement($buttonGroup, true);
$tabindex = 1;
parseHtml(null, $container, array(), false, $tabindex, $this->type);
parseHtml(null, $container, array(), false, $tabindex, $this->type->getScope());
echo "</div>\n";
$this->printPageFooter();
@ -1403,13 +1400,13 @@ class accountContainer {
*/
private function loadProfileIfRequested() {
if (isset($_POST['accountContainerLoadProfile']) && isset($_POST['accountContainerSelectLoadProfile'])) {
$profile = loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type);
$profile = loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type->getId());
$this->lastLoadedProfile = $_POST['accountContainerSelectLoadProfile'];
// pass profile to each module
$modules = array_keys($this->module);
foreach ($modules as $module) $this->module[$module]->load_profile($profile);
if (isset($profile['ldap_rdn'][0])) {
if (in_array($profile['ldap_rdn'][0], getRDNAttributes($this->type))) {
if (in_array($profile['ldap_rdn'][0], getRDNAttributes($this->type->getId()))) {
$this->rdn = $profile['ldap_rdn'][0];
}
}
@ -1437,7 +1434,7 @@ class accountContainer {
$buttonImage = $this->module[$this->order[$i]]->getIcon();
$activatedClass = '';
if ($this->order[$this->current_page] == $this->order[$i]) {
$activatedClass = ' ui-tabs-selected ui-state-active ' . $this->type . '-bright';
$activatedClass = ' ui-tabs-selected ui-state-active ' . $this->type->getScope() . '-bright';
}
// print button
echo '<li class="ui-state-default ui-corner-left' . $activatedClass . '">';
@ -1551,11 +1548,11 @@ class accountContainer {
function load_account($dn, $infoAttributes = array()) {
logNewMessage(LOG_DEBUG, "Edit account " . $dn);
$this->module = array();
$modules = $_SESSION['config']->get_AccountModules($this->type);
$modules = $_SESSION['config']->get_AccountModules($this->type->getId());
$search = substr($dn, 0, strpos($dn, ','));
$searchAttrs = array('*', '+');
foreach ($modules as $module) {
$modTmp = new $module($this->type);
$modTmp = new $module($this->type->getScope());
$searchAttrs = array_merge($searchAttrs, $modTmp->getManagedHiddenAttributes());
}
$result = @ldap_read($_SESSION['ldap']->server(), escapeDN($dn), escapeDN($search), $searchAttrs, 0, 0, 0, LDAP_DEREF_NEVER);
@ -1592,7 +1589,7 @@ class accountContainer {
foreach ($modules as $module) {
if (!isset($this->module[$module])) {
$this->module[$module] = new $module($this->type);
$this->module[$module] = new $module($this->type->getScope());
$this->module[$module]->init($this->base);
}
$this->module[$module]->load_attributes($attr);
@ -1601,7 +1598,7 @@ class accountContainer {
// sort module buttons
$this->sortModules();
// get titles
$typeObject = new $this->type();
$typeObject = $this->type->getBaseType();
$this->titleBarTitle = $typeObject->getTitleBarTitle($this);
$this->titleBarSubtitle = $typeObject->getTitleBarSubtitle($this);
return array();
@ -1622,7 +1619,7 @@ class accountContainer {
$aliases = array();
$ldapAttributesTemp = array();
foreach ($modules as $module) {
$moduleObj = moduleCache::getModule($module, $this->type);
$moduleObj = moduleCache::getModule($module, $this->type->getScope());
$objectClasses = array_merge($objectClasses, $moduleObj->getManagedObjectClasses());
$aliases = array_merge($aliases, $moduleObj->getLDAPAliases());
$ldapAttributesTemp = array_merge($ldapAttributesTemp, $moduleObj->getManagedAttributes());
@ -1688,22 +1685,22 @@ class accountContainer {
* This function will prepare the object for a new account.
*/
function new_account() {
logNewMessage(LOG_DEBUG, "New account with type " . $this->type);
logNewMessage(LOG_DEBUG, "New account with type " . $this->type->getId());
$this->isNewAccount = true;
$this->lastLoadedProfile = 'default';
$modules = $_SESSION['config']->get_AccountModules($this->type);
$modules = $_SESSION['config']->get_AccountModules($this->type->getId());
foreach ($modules as $module) {
$this->module[$module] = new $module($this->type);
$this->module[$module] = new $module($this->type->getScope());
$this->module[$module]->init($this->base);
}
// sort module buttons
$this->sortModules();
$profile = loadAccountProfile('default', $this->type);
$profile = loadAccountProfile('default', $this->type->getId());
// pass profile to each module
$modules = array_keys($this->module);
foreach ($modules as $module) $this->module[$module]->load_profile($profile);
if (isset($profile['ldap_rdn'][0])) {
if (in_array($profile['ldap_rdn'][0], getRDNAttributes($this->type))) {
if (in_array($profile['ldap_rdn'][0], getRDNAttributes($this->type->getId()))) {
$this->rdn = $profile['ldap_rdn'][0];
}
}
@ -1711,7 +1708,7 @@ class accountContainer {
$this->dnSuffix = $profile['ldap_suffix'][0];
}
// get titles
$typeObject = new $this->type();
$typeObject = $this->type->getBaseType();
$this->titleBarTitle = $typeObject->getTitleBarTitle($this);
$this->titleBarSubtitle = $typeObject->getTitleBarSubtitle($this);
return 0;
@ -1723,7 +1720,7 @@ class accountContainer {
* @return array list of status messages
*/
function save_account() {
if (!checkIfWriteAccessIsAllowed($this->type)) {
if (!checkIfWriteAccessIsAllowed($this->type->getId())) {
die();
}
$this->finalDN = $this->dn_orig;
@ -2027,7 +2024,7 @@ class accountContainer {
for ($i = 0; $i < sizeof($modules); $i++) {
// insert waiting modules
for ($w = 0; $w < sizeof($depModules); $w++) {
$dependencies = $this->module[$depModules[$w]]->get_dependencies($this->type);
$dependencies = $this->module[$depModules[$w]]->get_dependencies($this->type->getScope());
$dependencies = $dependencies['depends'];
$everything_found = true;
for ($d = 0; $d < sizeof($dependencies); $d++) {
@ -2045,7 +2042,7 @@ class accountContainer {
}
}
// check next module
$dependencies = $this->module[$modules[$i]]->get_dependencies($this->type);
$dependencies = $this->module[$modules[$i]]->get_dependencies($this->type->getScope());
if (is_array($dependencies['depends'])) {
$everything_found = true;
$dependencies = $dependencies['depends'];
@ -2138,7 +2135,7 @@ class accountContainer {
if ($this->cachedOUs != null) {
return $this->cachedOUs;
}
$typeObj = new $this->type();
$typeObj = $this->type->getBaseType();
$this->cachedOUs = $typeObj->getSuffixList();
return $this->cachedOUs;
}

View File

@ -67,7 +67,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
$account_type = $accounts[0]->get_type();
// Get PDF structure from xml file
$load = loadPDFStructureDefinitions($account_type,$pdf_structure);
$load = loadPDFStructureDefinitions($account_type->getId(), $pdf_structure);
$structure = $load['structure'];
// get list of PDF keys
$pdfKeys = array();

View File

@ -330,6 +330,12 @@ class ListAttribute {
*/
class TypeManager {
/**
* Returns the configured type with the given id or null.
*
* @param string $typeId type id
* @return \LAM\TYPES\ConfiguredType|NULL type
*/
public function getConfiguredType($typeId) {
$configuredTypes = array();
$activeTypes = $_SESSION['config']->get_ActiveTypes();

View File

@ -283,7 +283,8 @@ class Uploader {
}
}
// load account
$_SESSION['mass_pdfAccount'] = new accountContainer($this->scope, 'mass_pdfAccount');
$typeManager = new \LAM\TYPES\TypeManager();
$_SESSION['mass_pdfAccount'] = new accountContainer($typeManager->getConfiguredType($this->scope), 'mass_pdfAccount');
$pdfErrors = $_SESSION['mass_pdfAccount']->load_account($dn, $infoAttributes);
if (sizeof($pdfErrors) > 0) {
$_SESSION['mass_errors'] = array_merge($_SESSION['mass_errors'], $pdfErrors);

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2005 - 2015 Roland Gruber
2005 - 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
@ -57,14 +57,13 @@ if (!isLoggedIn()) {
// Set correct language, codepages, ....
setlanguage();
$typeManager = new LAM\TYPES\TypeManager();
//load account
if (isset($_GET['DN'])) {
$type = $typeManager->getConfiguredType($_GET['type']);
$DN = str_replace("\\'", '', $_GET['DN']);
$type = str_replace("\\'", '', $_GET['type']);
if ($_GET['type'] == $type) $type = str_replace("'", '',$_GET['type']);
if (isAccountTypeHidden($type)) {
logNewMessage(LOG_ERR, 'User tried to access hidden account type: ' . $type);
if ($type->isHidden()) {
logNewMessage(LOG_ERR, 'User tried to access hidden account type: ' . $type->getId());
die();
}
if ($_GET['DN'] == $DN) {
@ -75,10 +74,10 @@ if (isset($_GET['DN'])) {
$DN = substr($DN, 0, -1);
}
}
$suffix = strtolower($_SESSION['config']->get_Suffix($type));
$suffix = strtolower($type->getSuffix());
$DNlower = strtolower($DN);
if (strpos($DNlower, $suffix) !== (strlen($DNlower) - strlen($suffix))) {
logNewMessage(LOG_ERR, 'User tried to access entry of type ' . $type . ' outside suffix ' . $suffix);
logNewMessage(LOG_ERR, 'User tried to access entry of type ' . $type->getId() . ' outside suffix ' . $suffix);
die();
}
$_SESSION['account'] = new accountContainer($type, 'account', getRandomNumber());
@ -94,14 +93,13 @@ if (isset($_GET['DN'])) {
}
// new account
else if (count($_POST)==0) {
$type = str_replace("\\'", '', $_GET['type']);
if ($_GET['type'] == $type) $type = str_replace("'", '',$_GET['type']);
if (isAccountTypeHidden($type)) {
logNewMessage(LOG_ERR, 'User tried to access hidden account type: ' . $type);
$type = $typeManager->getConfiguredType($_GET['type']);
if ($type->isHidden()) {
logNewMessage(LOG_ERR, 'User tried to access hidden account type: ' . $type->getId());
die();
}
elseif (!checkIfNewEntriesAreAllowed($type)) {
logNewMessage(LOG_ERR, 'User tried to create entry of forbidden account type: ' . $type);
elseif (!checkIfNewEntriesAreAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to create entry of forbidden account type: ' . $type->getId());
die();
}
$_SESSION['account'] = new accountContainer($type, 'account', getRandomNumber());

View File

@ -88,7 +88,8 @@ if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
}
//load account
$_SESSION['account'] = new accountContainer($_GET['type'], 'account');
$typeManager = new LAM\TYPES\TypeManager();
$_SESSION['account'] = new accountContainer($typeManager->getConfiguredType($_GET['type']), 'account');
// Show HTML Page
include 'main_header.php';
echo "<div class=\"".$_GET['type']."-bright smallPaddingContent\">";