implemented editor for organizational units
This commit is contained in:
parent
2be6020068
commit
6f65c533e6
|
@ -38,26 +38,27 @@ echo ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http:/
|
|||
<body>
|
||||
<table border=0 width="100%">
|
||||
<tr>
|
||||
<td width="100" rowspan=3> </td>
|
||||
<td rowspan=3 align="center">
|
||||
<td width="100" align="left"><a href="./profedit/profilemain.php" target="mainpart"><? echo _("Profile Editor") ?></a></td>
|
||||
<td rowspan=3 colspan=3 align="center">
|
||||
<a href="http://lam.sf.net" target="new_window"><img src="../graphics/banner.jpg" border=1 alt="LDAP Account Manager"></a>
|
||||
</td>
|
||||
<td width="100" align="right" height=20><a href="./logout.php" target="_top"><b><? echo _("Logout") ?></b></a></td>
|
||||
<td width="100" align="right" height=20><a href="./logout.php" target="_top"><big><b><? echo _("Logout") ?></b></big></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><a href="./profedit/profilemain.php" target="mainpart"><? echo _("Profile Editor") ?></a></td>
|
||||
<td align="left"><a href="ou_edit.php" target="mainpart"><? echo _("OU Editor") ?></a></td>
|
||||
<td rowspan=2></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right"><a href="masscreate.php" target="mainpart"><? echo _("File Upload") ?></a></td>
|
||||
<td align="left"><a href="masscreate.php" target="mainpart"><? echo _("File Upload") ?></a></td>
|
||||
</tr>
|
||||
<tr><td colspan=5> </td></tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td width="200" align="center"><a href="./lists/listusers.php" target="mainpart"> <? echo _("Users");?> </a></td>
|
||||
<td width="200" align="center"><a href="./lists/listgroups.php" target="mainpart"> <? echo _("Groups");?> </a></td>
|
||||
<td width="200" align="center"><a href="./lists/listhosts.php" target="mainpart"> <? echo _("Hosts");?> </a></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<table border=0 align="center" width="600">
|
||||
<tr>
|
||||
<td width="200" align="center"><a href="./lists/listusers.php" target="mainpart"> <? echo _("Users");?> </a></td>
|
||||
<td width="200" align="center"><a href="./lists/listgroups.php" target="mainpart"> <? echo _("Groups");?> </a></td>
|
||||
<td width="200" align="center"><a href="./lists/listhosts.php" target="mainpart"> <? echo _("Hosts");?> </a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,403 @@
|
|||
<?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
|
||||
|
||||
This is an editor for orgnizational units.
|
||||
|
||||
*/
|
||||
|
||||
include_once ("../lib/config.inc");
|
||||
include_once ("../lib/ldap.inc");
|
||||
include_once ("../lib/status.inc");
|
||||
|
||||
// start session
|
||||
session_save_path("../sess");
|
||||
@session_start();
|
||||
|
||||
setlanguage();
|
||||
|
||||
// check if submit button was pressed
|
||||
if ($_POST['submit']) {
|
||||
// user operations
|
||||
// new user ou
|
||||
if ($_POST['type'] == "new_usr") {
|
||||
// create ou if valid
|
||||
if (eregi("^[a-z0-9_\\-]+$", $_POST['newsuff_u'])) {
|
||||
// check if ou already exists
|
||||
$new_dn = "ou=" . $_POST['newsuff_u'] . "," . $_POST['usersuff_n'];
|
||||
if (!in_array(strtolower($new_dn), $_SESSION['ldap']->search_units($_POST['usersuff_n']))) {
|
||||
// add new ou
|
||||
$ou = array();
|
||||
$ou['objectClass'] = "organizationalunit";
|
||||
$ou['ou'] = $_POST['newsuff_u'];
|
||||
$ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou);
|
||||
if ($ret) {
|
||||
$message = _("New OU created successfully.");
|
||||
}
|
||||
else {
|
||||
$error = _("Unable to create new OU!");
|
||||
}
|
||||
}
|
||||
else $error = _("OU already exists!");
|
||||
}
|
||||
// show errormessage if ou is invalid
|
||||
else {
|
||||
$error = _("OU is invalid!") . " " . $_POST['newsuff_u'];
|
||||
}
|
||||
}
|
||||
// delete ou, user was sure
|
||||
elseif (($_POST['type'] == "del_usr") && ($_POST['sure'])) {
|
||||
// check for sub entries
|
||||
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['usersuff_d'], "ObjectClass=*", array(""));
|
||||
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($info['count'] == 0) {
|
||||
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['usersuff_d']);
|
||||
if ($ret) {
|
||||
$message = _("OU deleted successfully.");
|
||||
}
|
||||
else {
|
||||
$error = _("Unable to delete OU!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error = _("OU is not empty!");
|
||||
}
|
||||
}
|
||||
// do not delete ou
|
||||
elseif (($_POST['type'] == "del_usr") && ($_POST['abort'])) {
|
||||
display_main();
|
||||
exit;
|
||||
}
|
||||
// ask if user is sure to delete
|
||||
elseif ($_POST['type'] == "del_usr") {
|
||||
// check for sub entries
|
||||
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['usersuff_d'], "ObjectClass=*", array(""));
|
||||
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($info['count'] == 0) {
|
||||
$text = "<br>\n" .
|
||||
"<p><big><b>" . _("Do you really want to delete this OU?") . " </b></big>" . "\n" .
|
||||
"<br>\n<p>" . $_POST['usersuff_d'] . "</p>\n" .
|
||||
"<br>\n" .
|
||||
"<form action=\"ou_edit.php?type=user\" method=\"post\">\n" .
|
||||
"<input type=\"hidden\" name=\"type\" value=\"del_usr\">\n" .
|
||||
"<input type=\"hidden\" name=\"submit\" value=\"submit\">\n" .
|
||||
"<input type=\"hidden\" name=\"usersuff_d\" value=\"" . $_POST['usersuff_d'] . "\">\n" .
|
||||
"<input type=\"submit\" name=\"sure\" value=\"" . _("Submit") . "\">\n" .
|
||||
"<input type=\"submit\" name=\"abort\" value=\"" . _("Abort") . "\">\n" .
|
||||
"</form>";
|
||||
}
|
||||
else {
|
||||
$error = _("OU is not empty!");
|
||||
}
|
||||
}
|
||||
|
||||
// group operations
|
||||
// new group ou
|
||||
if ($_POST['type'] == "new_grp") {
|
||||
// create ou if valid
|
||||
if (eregi("^[a-z0-9_\\-]+$", $_POST['newsuff_g'])) {
|
||||
// check if ou already exists
|
||||
$new_dn = "ou=" . $_POST['newsuff_g'] . "," . $_POST['groupsuff_n'];
|
||||
if (!in_array(strtolower($new_dn), $_SESSION['ldap']->search_units($_POST['groupsuff_n']))) {
|
||||
// add new ou
|
||||
$ou = array();
|
||||
$ou['objectClass'] = "organizationalunit";
|
||||
$ou['ou'] = $_POST['newsuff_g'];
|
||||
$ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou);
|
||||
if ($ret) {
|
||||
$message = _("New OU created successfully.");
|
||||
}
|
||||
else {
|
||||
$error = _("Unable to create new OU!");
|
||||
}
|
||||
}
|
||||
else $error = _("OU already exists!");
|
||||
}
|
||||
// show errormessage if ou is invalid
|
||||
else {
|
||||
$error = _("OU is invalid!") . " " . $_POST['newsuff_g'];
|
||||
}
|
||||
}
|
||||
// delete ou, user was sure
|
||||
elseif (($_POST['type'] == "del_grp") && ($_POST['sure'])) {
|
||||
// check for sub entries
|
||||
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['groupsuff_d'], "ObjectClass=*", array(""));
|
||||
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($info['count'] == 0) {
|
||||
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['groupsuff_d']);
|
||||
if ($ret) {
|
||||
$message = _("OU deleted successfully.");
|
||||
}
|
||||
else {
|
||||
$error = _("Unable to delete OU!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error = _("OU is not empty!");
|
||||
}
|
||||
}
|
||||
// do not delete ou
|
||||
elseif (($_POST['type'] == "del_grp") && ($_POST['abort'])) {
|
||||
display_main();
|
||||
exit;
|
||||
}
|
||||
// ask if user is sure to delete
|
||||
elseif ($_POST['type'] == "del_grp") {
|
||||
// check for sub entries
|
||||
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['groupsuff_d'], "ObjectClass=*", array(""));
|
||||
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($info['count'] == 0) {
|
||||
$text = "<br>\n" .
|
||||
"<p><big><b>" . _("Do you really want to delete this OU?") . " </b></big>" . "\n" .
|
||||
"<br>\n<p>" . $_POST['groupsuff_d'] . "</p>\n" .
|
||||
"<br>\n" .
|
||||
"<form action=\"ou_edit.php?type=group\" method=\"post\">\n" .
|
||||
"<input type=\"hidden\" name=\"type\" value=\"del_grp\">\n" .
|
||||
"<input type=\"hidden\" name=\"submit\" value=\"submit\">\n" .
|
||||
"<input type=\"hidden\" name=\"groupsuff_d\" value=\"" . $_POST['groupsuff_d'] . "\">\n" .
|
||||
"<input type=\"submit\" name=\"sure\" value=\"" . _("Submit") . "\">\n" .
|
||||
"<input type=\"submit\" name=\"abort\" value=\"" . _("Abort") . "\">\n" .
|
||||
"</form>";
|
||||
}
|
||||
else {
|
||||
$error = _("OU is not empty!");
|
||||
}
|
||||
}
|
||||
|
||||
// host operations
|
||||
// new host ou
|
||||
if ($_POST['type'] == "new_hst") {
|
||||
// create ou if valid
|
||||
if (eregi("^[a-z0-9_\\-]+$", $_POST['newsuff_h'])) {
|
||||
// check if ou already exists
|
||||
$new_dn = "ou=" . $_POST['newsuff_h'] . "," . $_POST['hostsuff_n'];
|
||||
if (!in_array(strtolower($new_dn), $_SESSION['ldap']->search_units($_POST['hostsuff_n']))) {
|
||||
// add new ou
|
||||
$ou = array();
|
||||
$ou['objectClass'] = "organizationalunit";
|
||||
$ou['ou'] = $_POST['newsuff_h'];
|
||||
$ret = @ldap_add($_SESSION['ldap']->server(), $new_dn, $ou);
|
||||
if ($ret) {
|
||||
$message = _("New OU created successfully.");
|
||||
}
|
||||
else {
|
||||
$error = _("Unable to create new OU!");
|
||||
}
|
||||
}
|
||||
else $error = _("OU already exists!");
|
||||
}
|
||||
// show errormessage if ou is invalid
|
||||
else {
|
||||
$error = _("OU is invalid!") . " " . $_POST['newsuff_h'];
|
||||
}
|
||||
}
|
||||
// delete ou, user was sure
|
||||
elseif (($_POST['type'] == "del_hst") && ($_POST['sure'])) {
|
||||
// check for sub entries
|
||||
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['hostsuff_d'], "ObjectClass=*", array(""));
|
||||
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($info['count'] == 0) {
|
||||
$ret = @ldap_delete($_SESSION['ldap']->server(), $_POST['hostsuff_d']);
|
||||
if ($ret) {
|
||||
$message = _("OU deleted successfully.");
|
||||
}
|
||||
else {
|
||||
$error = _("Unable to delete OU!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error = _("OU is not empty!");
|
||||
}
|
||||
}
|
||||
// do not delete ou
|
||||
elseif (($_POST['type'] == "del_hst") && ($_POST['abort'])) {
|
||||
display_main();
|
||||
exit;
|
||||
}
|
||||
// ask if user is sure to delete
|
||||
elseif ($_POST['type'] == "del_hst") {
|
||||
// check for sub entries
|
||||
$sr = ldap_list($_SESSION['ldap']->server(), $_POST['hostsuff_d'], "ObjectClass=*", array(""));
|
||||
$info = ldap_get_entries($_SESSION['ldap']->server(), $sr);
|
||||
if ($info['count'] == 0) {
|
||||
$text = "<br>\n" .
|
||||
"<p><big><b>" . _("Do you really want to delete this OU?") . " </b></big>" . "\n" .
|
||||
"<br>\n<p>" . $_POST['hostsuff_d'] . "</p>\n" .
|
||||
"<br>\n" .
|
||||
"<form action=\"ou_edit.php?type=host\" method=\"post\">\n" .
|
||||
"<input type=\"hidden\" name=\"type\" value=\"del_hst\">\n" .
|
||||
"<input type=\"hidden\" name=\"submit\" value=\"submit\">\n" .
|
||||
"<input type=\"hidden\" name=\"hostsuff_d\" value=\"" . $_POST['hostsuff_d'] . "\">\n" .
|
||||
"<input type=\"submit\" name=\"sure\" value=\"" . _("Submit") . "\">\n" .
|
||||
"<input type=\"submit\" name=\"abort\" value=\"" . _("Abort") . "\">\n" .
|
||||
"</form>";
|
||||
}
|
||||
else {
|
||||
$error = _("OU is not empty!");
|
||||
}
|
||||
}
|
||||
|
||||
// print header
|
||||
echo ("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n");
|
||||
echo ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
|
||||
echo ("<html>\n");
|
||||
echo ("<head>\n");
|
||||
echo ("<title>OU-Editor</title>\n");
|
||||
echo ("<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n");
|
||||
echo ("</head>\n");
|
||||
echo ("<body>\n");
|
||||
// display messages
|
||||
if ($error || $message || $text) {
|
||||
if ($text) echo $text;
|
||||
elseif ($error) {
|
||||
StatusMessage("ERROR", "", $error);
|
||||
echo ("<br><a href=\"ou_edit.php\">" . _("Back to OU-Editor") . "</a>\n");
|
||||
}
|
||||
else {
|
||||
StatusMessage("INFO", "", $message);
|
||||
echo ("<br><a href=\"ou_edit.php\">" . _("Back to OU-Editor") . "</a>\n");
|
||||
}
|
||||
}
|
||||
|
||||
echo ("</body></html>\n");
|
||||
exit;
|
||||
}
|
||||
else display_main();
|
||||
|
||||
function display_main() {
|
||||
// generate lists of possible suffixes
|
||||
$usr_units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_UserSuffix());
|
||||
$grp_units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_GroupSuffix());
|
||||
$hst_units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_HostSuffix());
|
||||
|
||||
// display main page
|
||||
echo ("<?xml version=\"1.0\" encoding=\"ISO-8859-15\"?>\n");
|
||||
echo ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n");
|
||||
echo ("<html>\n");
|
||||
echo ("<head>\n");
|
||||
echo ("<title>OU-Editor</title>\n");
|
||||
echo ("<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n");
|
||||
echo ("</head>\n");
|
||||
echo ("<body>\n");
|
||||
echo ("<form action=\"ou_edit.php?type=user\" method=\"post\">\n");
|
||||
|
||||
// user OUs
|
||||
echo ("<fieldset><legend><b>" . _("Users") . "</b></legend>\n");
|
||||
echo ("<table border=0>\n");
|
||||
// new OU
|
||||
echo ("<tr>\n");
|
||||
echo ("<td><input type=radio name=\"type\" value=\"new_usr\" checked></td>\n");
|
||||
echo ("<td><select size=1 name=usersuff_n>");
|
||||
for ($i = 0; $i < sizeof($usr_units); $i++) {
|
||||
echo ("<option>" . $usr_units[$i] . "</option>\n");
|
||||
}
|
||||
echo ("</select><td>\n");
|
||||
echo ("<td><input type=text name=newsuff_u></td>\n");
|
||||
echo ("<td><b>" . _("New organizational unit") . "</b></td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><a href=\"help.php?HelpNumber=501\">". _("Help") ."</a></td>\n");
|
||||
echo ("</tr>\n");
|
||||
// delete OU
|
||||
echo ("<tr>\n");
|
||||
echo ("<td><input type=radio name=\"type\" value=\"del_usr\"></td>\n");
|
||||
echo ("<td><select size=1 name=usersuff_d>");
|
||||
for ($i = 0; $i < sizeof($usr_units); $i++) {
|
||||
echo ("<option>" . $usr_units[$i] . "</option>\n");
|
||||
}
|
||||
echo ("</select><td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><b>" . _("Delete organizational unit") . "</b></td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><a href=\"help.php?HelpNumber=502\">". _("Help") ."</a></td>\n");
|
||||
echo ("</tr>\n");
|
||||
echo ("</table>\n");
|
||||
echo ("</fieldset>\n");
|
||||
echo ("<br>\n");
|
||||
|
||||
// group OUs
|
||||
echo ("<fieldset><legend><b>" . _("Groups") . "</b></legend>\n");
|
||||
echo ("<table border=0>\n");
|
||||
// new OU
|
||||
echo ("<tr>\n");
|
||||
echo ("<td><input type=radio name=\"type\" value=\"new_grp\"></td>\n");
|
||||
echo ("<td><select size=1 name=groupsuff_n>");
|
||||
for ($i = 0; $i < sizeof($grp_units); $i++) {
|
||||
echo ("<option>" . $grp_units[$i] . "</option>\n");
|
||||
}
|
||||
echo ("</select><td>\n");
|
||||
echo ("<td><input type=text name=newsuff_g></td>\n");
|
||||
echo ("<td><b>" . _("New organizational unit") . "</b></td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><a href=\"help.php?HelpNumber=511\">". _("Help") ."</a></td>\n");
|
||||
echo ("</tr>\n");
|
||||
// delete OU
|
||||
echo ("<tr>\n");
|
||||
echo ("<td><input type=radio name=\"type\" value=\"del_grp\"></td>\n");
|
||||
echo ("<td><select size=1 name=groupsuff_d>");
|
||||
for ($i = 0; $i < sizeof($grp_units); $i++) {
|
||||
echo ("<option>" . $grp_units[$i] . "</option>\n");
|
||||
}
|
||||
echo ("</select><td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><b>" . _("Delete organizational unit") . "</b></td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><a href=\"help.php?HelpNumber=512\">". _("Help") ."</a></td>\n");
|
||||
echo ("</tr>\n");
|
||||
echo ("</table>\n");
|
||||
echo ("</fieldset>\n");
|
||||
echo ("<br>\n");
|
||||
|
||||
// host OUs
|
||||
echo ("<fieldset><legend><b>" . _("Samba Hosts") . "</b></legend>\n");
|
||||
echo ("<table border=0>\n");
|
||||
// new OU
|
||||
echo ("<tr>\n");
|
||||
echo ("<td><input type=radio name=\"type\" value=\"new_hst\"></td>\n");
|
||||
echo ("<td><select size=1 name=hostsuff_n>");
|
||||
for ($i = 0; $i < sizeof($hst_units); $i++) {
|
||||
echo ("<option>" . $hst_units[$i] . "</option>\n");
|
||||
}
|
||||
echo ("</select><td>\n");
|
||||
echo ("<td><input type=text name=newsuff_h></td>\n");
|
||||
echo ("<td><b>" . _("New organizational unit") . "</b></td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><a href=\"help.php?HelpNumber=521\">". _("Help") ."</a></td>\n");
|
||||
echo ("</tr>\n");
|
||||
// delete OU
|
||||
echo ("<tr>\n");
|
||||
echo ("<td><input type=radio name=\"type\" value=\"del_hst\"></td>\n");
|
||||
echo ("<td><select size=1 name=hostsuff_d>");
|
||||
for ($i = 0; $i < sizeof($hst_units); $i++) {
|
||||
echo ("<option>" . $hst_units[$i] . "</option>\n");
|
||||
}
|
||||
echo ("</select><td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><b>" . _("Delete organizational unit") . "</b></td>\n");
|
||||
echo ("<td> </td>\n");
|
||||
echo ("<td><a href=\"help.php?HelpNumber=522\">". _("Help") ."</a></td>\n");
|
||||
echo ("</tr>\n");
|
||||
echo ("</table>\n");
|
||||
echo ("</fieldset>\n");
|
||||
echo ("<br>\n");
|
||||
|
||||
echo ("<input type=\"submit\" name=\"submit\" value=\"" . _("Submit") . "\">");
|
||||
echo ("</form>\n");
|
||||
echo ("</body></html>\n");
|
||||
}
|
Loading…
Reference in New Issue