LDAPAccountManager/lam/templates/tools/ou_edit.php

235 lines
7.3 KiB
PHP
Raw Normal View History

<?php
2016-12-26 17:41:22 +00:00
namespace LAM\TOOLS\OU_EDIT;
use \htmlSpacer;
use \htmlOutputText;
use \htmlButton;
use \htmlHiddenInput;
2018-01-13 18:58:55 +00:00
use \htmlTitle;
2016-12-26 17:41:22 +00:00
use \htmlSubTitle;
use \htmlStatusMessage;
2018-01-13 18:58:55 +00:00
use \htmlResponsiveRow;
use \htmlResponsiveSelect;
use \htmlResponsiveInputField;
use \htmlGroup;
/*
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
2018-01-13 18:58:55 +00:00
Copyright (C) 2003 - 2018 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
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
2005-07-20 18:07:10 +00:00
*/
2005-07-20 18:07:10 +00:00
/**
* This is an editor for organizational units.
*
* @author Roland Gruber
* @package tools
*/
2006-03-26 17:51:25 +00:00
/** security functions */
2018-12-23 16:32:17 +00:00
include_once(__DIR__ . "/../../lib/security.inc");
2005-07-20 18:07:10 +00:00
/** access to configuration data */
2018-12-23 16:32:17 +00:00
include_once(__DIR__ . "/../../lib/config.inc");
2005-07-20 18:07:10 +00:00
/** access LDAP server */
2018-12-23 16:32:17 +00:00
include_once(__DIR__ . "/../../lib/ldap.inc");
2005-07-20 18:07:10 +00:00
/** used to print status messages */
2018-12-23 16:32:17 +00:00
include_once(__DIR__ . "/../../lib/status.inc");
// start session
2006-03-26 17:51:25 +00:00
startSecureSession();
2017-02-11 16:11:37 +00:00
enforceUserIsLoggedIn();
2007-12-30 13:15:39 +00:00
// die if no write access
if (!checkIfWriteAccessIsAllowed()) die();
2012-07-22 10:37:01 +00:00
checkIfToolIsActive('toolOUEditor');
setlanguage();
2015-05-15 19:16:46 +00:00
if (!empty($_POST)) {
validateSecurityToken();
}
2008-12-28 13:43:44 +00:00
// check if deletion was canceled
if (isset($_POST['abort'])) {
display_main(null, null);
2008-12-28 13:43:44 +00:00
exit;
}
2010-05-26 19:47:02 +00:00
$error = null;
$message = null;
// check if submit button was pressed
2008-12-28 13:43:44 +00:00
if (isset($_POST['createOU']) || isset($_POST['deleteOU'])) {
// new ou
if (isset($_POST['createOU'])) {
// create ou if valid
2009-08-14 18:06:15 +00:00
if (preg_match("/^[a-z0-9 _\\-]+$/i", $_POST['newOU'])) {
2008-12-28 13:43:44 +00:00
// check if ou already exists
$new_dn = "ou=" . $_POST['newOU'] . "," . $_POST['parentOU'];
2011-04-25 18:01:11 +00:00
$found = ldapGetDN($new_dn);
2017-09-18 17:39:08 +00:00
if ($found === null) {
2008-12-28 13:43:44 +00:00
// add new ou
$ou = array();
$ou['objectClass'] = "organizationalunit";
$ou['ou'] = $_POST['newOU'];
$ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou);
if ($ret) {
$message = _("New OU created successfully.");
}
else {
$error = _("Unable to create new OU!");
}
}
2008-12-28 13:43:44 +00:00
else $error = _("OU already exists!");
}
2008-12-28 13:43:44 +00:00
// show errormessage if ou is invalid
else {
2012-03-13 21:34:13 +00:00
$error = _("OU is invalid!") . "<br>" . htmlspecialchars($_POST['newOU']);
2003-08-05 18:30:31 +00:00
}
2008-12-28 13:43:44 +00:00
}
// delete ou, user was sure
elseif (isset($_POST['deleteOU']) && isset($_POST['sure'])) {
2017-10-24 18:48:34 +00:00
$ret = ldap_delete($_SESSION['ldap']->server(), $_POST['deletename']);
2008-12-28 13:43:44 +00:00
if ($ret) {
$message = _("OU deleted successfully.");
2006-01-01 16:30:05 +00:00
}
2008-12-28 13:43:44 +00:00
else {
$error = _("Unable to delete OU!");
2003-08-05 18:30:31 +00:00
}
}
2008-12-28 13:43:44 +00:00
// ask if user is sure to delete
elseif (isset($_POST['deleteOU'])) {
// check for sub entries
2017-10-24 18:48:34 +00:00
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['deleteableOU'], "ObjectClass=*", array(""));
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
2008-12-28 13:43:44 +00:00
if ($sr && $info['count'] == 0) {
2010-05-26 19:47:02 +00:00
// print header
2018-11-18 08:19:12 +00:00
include '../../lib/adminHeader.inc';
2013-01-19 13:18:52 +00:00
echo '<div class="user-bright smallPaddingContent">';
echo "<form action=\"ou_edit.php\" method=\"post\">\n";
$tabindex = 1;
2018-01-13 18:58:55 +00:00
$container = new htmlResponsiveRow();
$label = new htmlOutputText(_("Do you really want to delete this OU?"));
$label->colspan = 5;
2018-01-13 18:58:55 +00:00
$container->add($label, 12);
$container->addVerticalSpacer('1rem');
$dnLabel = new htmlOutputText(getAbstractDN($_POST['deleteableOU']));
$dnLabel->colspan = 5;
2018-01-13 18:58:55 +00:00
$container->add($dnLabel, 12);
$container->addVerticalSpacer('1rem');
$buttonGroup = new htmlGroup();
$buttonGroup->addElement(new htmlButton('sure', _("Delete")));
$buttonGroup->addElement(new htmlSpacer('0.5rem', null));
$buttonGroup->addElement(new htmlButton('abort', _("Cancel")));
$container->add($buttonGroup, 12);
$container->add(new htmlHiddenInput('deleteOU', 'submit'), 12);
$container->add(new htmlHiddenInput('deletename', $_POST['deleteableOU']), 12);
2016-12-19 20:32:08 +00:00
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');
echo "</form>";
echo '</div>';
2018-11-18 08:19:12 +00:00
include '../../lib/adminFooter.inc';
2010-05-26 19:47:02 +00:00
exit();
2008-12-28 13:43:44 +00:00
}
else {
$error = _("OU is not empty or invalid!");
}
}
}
2010-05-26 19:47:02 +00:00
display_main($message, $error);
2008-12-28 13:43:44 +00:00
/**
* Displays the main page of the OU editor
2016-12-19 20:32:08 +00:00
*
2010-05-26 19:47:02 +00:00
* @param String $message info message
* @param String $error error message
2008-12-28 13:43:44 +00:00
*/
2010-05-26 19:47:02 +00:00
function display_main($message, $error) {
// display main page
2018-12-23 16:32:17 +00:00
include __DIR__ . '/../../lib/adminHeader.inc';
2013-01-19 13:18:52 +00:00
echo '<div class="user-bright smallPaddingContent">';
2015-05-15 19:16:46 +00:00
echo "<form action=\"ou_edit.php\" method=\"post\">\n";
$tabindex = 1;
2018-01-13 18:58:55 +00:00
$container = new htmlResponsiveRow();
$container->add(new htmlTitle(_("OU editor")), 12);
2010-05-26 19:47:02 +00:00
if (isset($error)) {
$msg = new htmlStatusMessage("ERROR", "", $error);
$msg->colspan = 5;
2018-01-13 18:58:55 +00:00
$container->add($msg, 12);
2010-05-26 19:47:02 +00:00
}
elseif (isset($message)) {
$msg = new htmlStatusMessage("INFO", "", $message);
$msg->colspan = 5;
2018-01-13 18:58:55 +00:00
$container->add($msg, 12);
2010-05-26 19:47:02 +00:00
}
2016-12-19 20:32:08 +00:00
2016-12-26 17:41:22 +00:00
$typeManager = new \LAM\TYPES\TypeManager();
$typeList = $typeManager->getConfiguredTypes();
2010-05-19 19:22:29 +00:00
$types = array();
2016-12-26 17:41:22 +00:00
foreach ($typeList as $type) {
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) {
continue;
}
2016-12-26 17:41:22 +00:00
$types[$type->getId()] = $type->getAlias();
2010-05-19 19:22:29 +00:00
}
natcasesort($types);
$options = array();
2017-01-08 19:59:09 +00:00
foreach ($types as $typeId => $title) {
$type = $typeManager->getConfiguredType($typeId);
$elements = array();
2017-01-08 19:59:09 +00:00
$units = searchLDAP($type->getSuffix(), '(objectclass=organizationalunit)', array('dn'));
2017-11-04 18:27:02 +00:00
foreach ($units as $unit) {
$elements[getAbstractDN($unit['dn'])] = $unit['dn'];
2005-02-07 19:59:42 +00:00
}
$options[$title] = $elements;
2003-08-05 18:30:31 +00:00
}
2016-12-19 20:32:08 +00:00
if (!empty($options)) {
// new OU
2018-01-13 18:58:55 +00:00
$container->add(new htmlSubTitle(_("New organisational unit")), 12);
$parentOUSelect = new htmlResponsiveSelect('parentOU', $options, array(), _('Parent DN'), '601');
$parentOUSelect->setContainsOptgroups(true);
$parentOUSelect->setHasDescriptiveElements(true);
$parentOUSelect->setRightToLeftTextDirection(true);
$parentOUSelect->setSortElements(false);
2018-01-13 18:58:55 +00:00
$container->add($parentOUSelect, 12);
$container->add(new htmlResponsiveInputField(_('Name'), 'newOU'), 12);
$container->addLabel(new htmlOutputText('&nbsp;', false));
$container->addField(new htmlButton('createOU', _("Ok")));
$container->addVerticalSpacer('2rem');
2016-12-19 20:32:08 +00:00
// delete OU
2018-01-13 18:58:55 +00:00
$container->add(new htmlSubTitle(_("Delete organisational unit")), 12);
$deleteableOUSelect = new htmlResponsiveSelect('deleteableOU', $options, array(), _('Organisational unit'), '602');
$deleteableOUSelect->setContainsOptgroups(true);
$deleteableOUSelect->setHasDescriptiveElements(true);
$deleteableOUSelect->setRightToLeftTextDirection(true);
$deleteableOUSelect->setSortElements(false);
2018-01-13 18:58:55 +00:00
$container->add($deleteableOUSelect, 12);
$container->addLabel(new htmlOutputText('&nbsp;', false));
$container->addField(new htmlButton('deleteOU', _("Ok")));
}
2016-12-19 20:32:08 +00:00
2015-05-15 19:16:46 +00:00
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');
2018-12-23 10:01:29 +00:00
echo "</form>\n";
echo '</div>';
2018-12-23 16:32:17 +00:00
include __DIR__ . '/../../lib/adminFooter.inc';
2003-07-04 14:35:56 +00:00
}