2003-07-28 18:36:38 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
|
|
|
Copyright (C) 2003 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
|
|
|
|
|
2004-07-10 09:25:15 +00:00
|
|
|
*/
|
2003-07-28 18:36:38 +00:00
|
|
|
|
2004-07-10 09:25:15 +00:00
|
|
|
/**
|
|
|
|
* Creates main suffixes if they are missing.
|
|
|
|
*
|
|
|
|
* @author Roland Gruber
|
|
|
|
* @package main
|
2003-07-28 18:36:38 +00:00
|
|
|
*/
|
|
|
|
|
2004-07-10 09:25:15 +00:00
|
|
|
/** access to configuration settings */
|
2003-07-28 18:36:38 +00:00
|
|
|
include_once ("../lib/config.inc");
|
2004-07-10 09:25:15 +00:00
|
|
|
/** LDAP access */
|
2003-07-28 18:36:38 +00:00
|
|
|
include_once ("../lib/ldap.inc");
|
2004-07-10 09:25:15 +00:00
|
|
|
/** status messages */
|
2003-07-28 18:36:38 +00:00
|
|
|
include_once ("../lib/status.inc");
|
|
|
|
|
|
|
|
// start session
|
|
|
|
session_save_path("../sess");
|
|
|
|
@session_start();
|
|
|
|
|
|
|
|
setlanguage();
|
|
|
|
|
|
|
|
// check if user already pressed button
|
2003-07-29 11:33:12 +00:00
|
|
|
if ($_POST['add_suff'] || $_POST['cancel']) {
|
|
|
|
if ($_POST['add_suff']) {
|
2003-11-03 17:48:15 +00:00
|
|
|
$fail = array();
|
|
|
|
$errors = array();
|
|
|
|
$new_suff = $_POST['new_suff'];
|
2004-02-16 19:50:22 +00:00
|
|
|
$new_suff = str_replace("\\", "", $new_suff);
|
|
|
|
$new_suff = str_replace("'", "", $new_suff);
|
2003-11-03 17:48:15 +00:00
|
|
|
$new_suff = explode(";", $new_suff);
|
|
|
|
// add entries
|
2003-07-28 18:36:38 +00:00
|
|
|
for ($i = 0; $i < sizeof($new_suff); $i++) {
|
2003-11-03 17:48:15 +00:00
|
|
|
// check if entry is already present
|
|
|
|
$info = @ldap_search($_SESSION['ldap']->server, $new_suff[$i], "", array());
|
|
|
|
$res = @ldap_get_entries($_SESSION['ldap']->server, $info);
|
|
|
|
if ($res) continue;
|
2003-07-28 18:36:38 +00:00
|
|
|
$suff = $new_suff[$i];
|
|
|
|
// generate DN and attributes
|
|
|
|
$tmp = explode(",", $suff);
|
|
|
|
$name = explode("=", $tmp[0]);
|
|
|
|
array_shift($tmp);
|
|
|
|
$end = implode(",", $tmp);
|
2003-11-03 17:48:15 +00:00
|
|
|
if ($name[0] != "ou") { // add root entry
|
|
|
|
$attr = array();
|
|
|
|
$attr[$name[0]] = $name[1];
|
|
|
|
$attr['objectClass'] = 'organization';
|
|
|
|
$dn = $suff;
|
|
|
|
if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) {
|
|
|
|
$fail[] = $suff;
|
|
|
|
continue;
|
|
|
|
}
|
2003-07-28 18:36:38 +00:00
|
|
|
}
|
2003-11-03 17:48:15 +00:00
|
|
|
else { // add organizational unit
|
2003-07-28 18:36:38 +00:00
|
|
|
$name = $name[1];
|
|
|
|
$attr = array();
|
|
|
|
$attr['objectClass'] = "organizationalunit";
|
|
|
|
$attr['ou'] = $name;
|
2003-11-03 17:48:15 +00:00
|
|
|
$dn = $suff;
|
2003-10-11 15:23:08 +00:00
|
|
|
if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) {
|
2003-11-03 17:48:15 +00:00
|
|
|
// check if we have to add parent entries
|
|
|
|
if (ldap_errno($_SESSION['ldap']->server()) == 32) {
|
|
|
|
$temp = explode(",", $suff);
|
|
|
|
$subsuffs = array();
|
|
|
|
// make list of subsuffixes
|
|
|
|
for ($k = 0; $k < sizeof($temp); $k++) {
|
|
|
|
$part = explode("=", $temp[$k]);
|
|
|
|
if ($part[0] == "ou") $subsuffs[] = implode(",", array_slice($temp, $k));
|
|
|
|
else {
|
|
|
|
$subsuffs[] = implode(",", array_slice($temp, $k));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// create missing entries
|
|
|
|
for ($k = sizeof($subsuffs) - 1; $k >= 0; $k--) {
|
|
|
|
// check if subsuffix is present
|
|
|
|
$info = @ldap_search($_SESSION['ldap']->server, $subsuffs[$k], "", array());
|
|
|
|
$res = @ldap_get_entries($_SESSION['ldap']->server, $info);
|
|
|
|
if (!$res) {
|
|
|
|
$suffarray = explode(",", $subsuffs[$k]);
|
|
|
|
$headarray = explode("=", $suffarray[0]);
|
|
|
|
if ($headarray[0] == "ou") { // add ou entry
|
|
|
|
$attr = array();
|
|
|
|
$attr['objectClass'] = 'organizationalunit';
|
|
|
|
$attr['ou'] = $headarray[1];
|
|
|
|
$dn = $subsuffs[$k];
|
|
|
|
if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) {
|
|
|
|
$fail[] = $suff;
|
|
|
|
$error[] = ldap_error($_SESSION['ldap']->server());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // add root entry
|
|
|
|
$attr = array();
|
2004-01-07 17:45:28 +00:00
|
|
|
$attr['objectClass'][] = 'organization';
|
2003-11-03 17:48:15 +00:00
|
|
|
$attr[$headarray[0]] = $headarray[1];
|
2004-01-07 17:45:28 +00:00
|
|
|
if ($headarray[0] == "dc") {
|
|
|
|
$attr['o'] = $headarray[1];
|
|
|
|
$attr['objectClass'][] = 'dcObject';
|
|
|
|
}
|
2003-11-03 17:48:15 +00:00
|
|
|
$dn = $subsuffs[$k];
|
|
|
|
if (!@ldap_add($_SESSION['ldap']->server(), $dn, $attr)) {
|
|
|
|
$fail[] = $suff;
|
|
|
|
$error[] = ldap_error($_SESSION['ldap']->server());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$fail[] = $suff;
|
|
|
|
$error[] = ldap_error($_SESSION['ldap']->server());
|
|
|
|
}
|
2003-10-11 15:23:08 +00:00
|
|
|
}
|
2003-07-28 18:36:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-29 11:33:12 +00:00
|
|
|
echo $_SESSION['header'];
|
2003-11-29 12:54:00 +00:00
|
|
|
echo "<title>initsuff</title>\n";
|
2003-07-29 11:33:12 +00:00
|
|
|
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n";
|
2003-11-03 20:41:59 +00:00
|
|
|
echo "</head>\n<body>\n";
|
2003-07-29 11:33:12 +00:00
|
|
|
// print error/success messages
|
|
|
|
if ($_POST['add_suff']) {
|
|
|
|
if (sizeof($fail) > 0) {
|
2003-11-03 20:41:59 +00:00
|
|
|
// print error messages
|
2003-07-29 11:33:12 +00:00
|
|
|
for ($i = 0; $i < sizeof($fail); $i++) {
|
2003-10-11 15:23:08 +00:00
|
|
|
StatusMessage("ERROR", _("Failed to create entry!") . "<br>" . $error[$i], $fail[$i]);
|
2003-07-29 11:33:12 +00:00
|
|
|
}
|
2003-11-03 20:41:59 +00:00
|
|
|
echo "</body></html>\n";
|
2003-07-29 11:33:12 +00:00
|
|
|
}
|
2003-11-03 20:41:59 +00:00
|
|
|
else {
|
|
|
|
// print success message
|
|
|
|
StatusMessage("INFO", "", _("All changes were successful."));
|
2004-05-30 12:14:31 +00:00
|
|
|
echo "</body></html>\n";
|
2003-11-03 20:41:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// no suffixes were created
|
|
|
|
StatusMessage("INFO", "", _("No changes were made."));
|
|
|
|
echo "</body></html>\n";
|
2003-07-29 11:33:12 +00:00
|
|
|
}
|
2003-07-28 18:36:38 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// first show of page
|
|
|
|
$new_suff = $_GET['suffs'];
|
2004-02-16 19:50:22 +00:00
|
|
|
$new_suff = str_replace("\\", "", $new_suff);
|
|
|
|
$new_suff = str_replace("'", "", $new_suff);
|
2003-07-28 18:36:38 +00:00
|
|
|
$new_suff = explode(";", $new_suff);
|
|
|
|
|
2003-07-29 11:52:26 +00:00
|
|
|
echo $_SESSION['header'];
|
2003-11-29 12:54:00 +00:00
|
|
|
echo "<title>initsuff</title>\n";
|
2003-07-28 18:36:38 +00:00
|
|
|
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n";
|
|
|
|
echo "</head><body>\n";
|
|
|
|
echo "<p> </p>\n";
|
|
|
|
echo "<p><font color=\"red\"><b>" . _("The following suffix(es) are missing in LDAP. LAM can create them for you.") . "</b></font></p>\n";
|
|
|
|
echo "<p> </p>\n";
|
|
|
|
// print missing suffixes
|
|
|
|
for ($i = 0; $i < sizeof($new_suff); $i++) {
|
|
|
|
echo "<p><b>" . $new_suff[$i] . "</b></p>\n";
|
|
|
|
}
|
|
|
|
echo "<p> </p>\n";
|
|
|
|
echo "<form action=\"initsuff.php\" method=\"post\">\n";
|
|
|
|
echo "<input type=\"hidden\" name=\"new_suff\" value=\"" . implode(";", $new_suff) . "\">\n";
|
|
|
|
echo "<input type=\"submit\" name=\"add_suff\" value=\"" . _("Create") . "\">";
|
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"" . _("Cancel") . "\">";
|
|
|
|
echo "</form>\n";
|
|
|
|
echo "</body></html>\n";
|
|
|
|
?>
|