Added a lot of comments in account.inc

and fixed little bugs.
This commit is contained in:
katagia 2003-10-20 17:56:52 +00:00
parent 21d6b5c5c6
commit 6cdcde26c0
6 changed files with 853 additions and 689 deletions

File diff suppressed because it is too large Load Diff

View File

@ -403,11 +403,8 @@ echo "</title>\n".
"<form action=\"groupedit.php\" method=\"post\">\n". "<form action=\"groupedit.php\" method=\"post\">\n".
"<input name=\"varkey\" type=\"hidden\" value=\"".$varkey."\">\n"; "<input name=\"varkey\" type=\"hidden\" value=\"".$varkey."\">\n";
if (is_array($errors)) { if (is_array($errors))
echo "<table class=\"groupedit\" width=\"100%\">\n";
for ($i=0; $i<sizeof($errors); $i++) StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]); for ($i=0; $i<sizeof($errors); $i++) StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]);
echo "</table>";
}
// print_r($account_old); // print_r($account_old);
switch ($select_local) { // Select which part of page will be loaded switch ($select_local) { // Select which part of page will be loaded
@ -426,6 +423,19 @@ switch ($select_local) { // Select which part of page will be loaded
foreach ($temp2 as $temp) $users[] = $temp['cn']; foreach ($temp2 as $temp) $users[] = $temp['cn'];
if (is_array($users)) sort($users, SORT_STRING); if (is_array($users)) sort($users, SORT_STRING);
$users = array_delete($account_new->unix_memberUid, $users); $users = array_delete($account_new->unix_memberUid, $users);
if (isset($account_old->general_uidNumber))
$result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_UserSuffix(), "(&(objectClass=PosixAccount)(gidNumber=$account_old->general_uidNumber))", array('cn'));
else $result = ldap_search($_SESSION['ldap']->server(), $_SESSION['config']->get_UserSuffix(), "(&(objectClass=PosixAccount)(gidNumber=$account_new->general_uidNumber))", array('cn'));
$entry = ldap_first_entry($_SESSION['ldap']->server(), $result);
while ($entry) {
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
if (isset($attr['cn'][0])) {
$users = @array_flip($users);
unset ($users[$attr['cn'][0]]);
$users = @array_flip($users);
}
$entry = ldap_next_entry($_SESSION['ldap']->server(), $entry);
}
echo "<input name=\"select\" type=\"hidden\" value=\"groupmembers\">\n"; echo "<input name=\"select\" type=\"hidden\" value=\"groupmembers\">\n";
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >"; echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
echo "<table border=0><tr><td><fieldset class=\"groupedit-middle\"><legend class=\"groupedit-bright\"><b>"; echo "<table border=0><tr><td><fieldset class=\"groupedit-middle\"><legend class=\"groupedit-bright\"><b>";

View File

@ -285,11 +285,8 @@ echo "</title>\n".
"<form action=\"hostedit.php\" method=\"post\">\n". "<form action=\"hostedit.php\" method=\"post\">\n".
"<input name=\"varkey\" type=\"hidden\" value=\"".$varkey."\">\n"; "<input name=\"varkey\" type=\"hidden\" value=\"".$varkey."\">\n";
if (is_array($errors)) { if (is_array($errors))
echo "<table class=\"account\" width=\"100%\">\n";
for ($i=0; $i<sizeof($errors); $i++) StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]); for ($i=0; $i<sizeof($errors); $i++) StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]);
echo "</table>";
}
// print_r($account_new); // print_r($account_new);
@ -419,13 +416,6 @@ switch ($select_local) { // Select which part of page will be loaded
echo _('Reset password'); echo '">'; echo _('Reset password'); echo '">';
} }
echo '</td></tr>'."\n".'<tr><td>'; echo '</td></tr>'."\n".'<tr><td>';
echo _('Account is deactivated');
echo '</td>'."\n".'<td><input name="f_smb_flagsD" type="checkbox"';
if ($account_new->smb_flagsD) echo ' checked ';
echo '></td><td>'.
'<a href="../help.php?HelpNumber=432" target="lamhelp">'._('Help').'</a>'.
'</td></tr>'."\n".'<tr><td>';
echo '</td></tr>'."\n".'<tr><td>';
echo _('Domain'); echo _('Domain');
if ($config_intern->is_samba3()) { if ($config_intern->is_samba3()) {
echo '</td><td><select name="f_smb_domain">'; echo '</td><td><select name="f_smb_domain">';

View File

@ -653,11 +653,8 @@ echo "</title>\n".
"<form action=\"useredit.php\" method=\"post\">\n". "<form action=\"useredit.php\" method=\"post\">\n".
"<input name=\"varkey\" type=\"hidden\" value=\"".$varkey."\">\n"; "<input name=\"varkey\" type=\"hidden\" value=\"".$varkey."\">\n";
if (is_array($errors)) { if (is_array($errors))
echo "<table class=\"account\" width=\"100%\">\n";
for ($i=0; $i<sizeof($errors); $i++) StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]); for ($i=0; $i<sizeof($errors); $i++) StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]);
echo "</table>";
}
// print_r($account_new); // print_r($account_new);
// print_r($_POST); // print_r($_POST);

View File

@ -22,41 +22,50 @@ $Id$
LDAP Account Manager Delete user, hosts or groups LDAP Account Manager Delete user, hosts or groups
*/ */
include_once('../lib/ldap.inc'); include_once('../lib/ldap.inc');
include_once('../lib/account.inc'); include_once('../lib/account.inc');
include_once('../lib/config.inc'); include_once('../lib/config.inc');
// start session
session_save_path('../sess'); session_save_path('../sess');
@session_start(); @session_start();
// set language
setlanguage(); setlanguage();
// use references because session-vars can change in future
$ldap_intern =& $_SESSION['ldap']; $ldap_intern =& $_SESSION['ldap'];
$header_intern =& $_SESSION['header']; $header_intern =& $_SESSION['header'];
$lamurl_intern =& $_SESSION['lamurl'];
$config_intern =& $_SESSION['config']; $config_intern =& $_SESSION['config'];
$delete_dn =& $_SESSION['delete_dn']; $delete_dn =& $_SESSION['delete_dn'];
if ($_POST['backmain']) { // back to list page if ($_POST['backmain']) {
// back to list page
if (isset($_SESSION['delete_dn'])) unset ($_SESSION['delete_dn']); if (isset($_SESSION['delete_dn'])) unset ($_SESSION['delete_dn']);
metaRefresh($lamurl_intern."templates/lists/list".$_POST['type5']."s.php"); metaRefresh("lists/list".$_POST['type']."s.php");
// stop script because we don't want to reate invalid html-code
die; die;
} }
// Print header and part of body
echo $header_intern; echo $header_intern;
echo '<html><head><title>'; echo '<html><head><title>';
echo _('Delete Account'); echo _('Delete Account');
echo '</title>'."\n". echo '</title>'."\n".
'<link rel="stylesheet" type="text/css" href="'.$lamurl_intern.'style/layout.css">'."\n". '<link rel="stylesheet" type="text/css" href="../style/layout.css">'."\n".
'<meta http-equiv="pragma" content="no-cache">'."\n". '<meta http-equiv="pragma" content="no-cache">'."\n".
'<meta http-equiv="cache-control" content="no-cache">'."\n". '<meta http-equiv="cache-control" content="no-cache">'."\n".
'</head>'."\n". '</head>'."\n".
'<body>'."\n". '<body>'."\n".
'<form action="delete.php" method="post">'."\n"; '<form action="delete.php" method="post">'."\n";
if ($_GET['type']) { if ($_GET['type']) {
//$DN2 = explode(";", str_replace("\'", '',$_GET['DN'])); // $_GET['type'] is true if delete.php was called from *list.php
echo '<input name="type5" type="hidden" value="'.$_GET['type'].'">'; // Store $_GET['type'] as $_POST['type']
echo '<input name="type" type="hidden" value="'.$_GET['type'].'">';
switch ($_GET['type']) { switch ($_GET['type']) {
// Select which layout and text should be displayed
case 'user': case 'user':
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>"; echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Delete user(s)'); echo _('Delete user(s)');
@ -77,9 +86,12 @@ if ($_GET['type']) {
break; break;
} }
echo "<br>\n"; echo "<br>\n";
// display all DNs in a tables
echo "<table border=0 width=\"100%\">\n"; echo "<table border=0 width=\"100%\">\n";
foreach ($delete_dn as $dn) echo '<tr><td>'.$dn.'</td></tr>'; foreach ($delete_dn as $dn) echo '<tr><td>'.$dn.'</td></tr>';
echo "</table>\n"; echo "</table>\n";
// Ask if lam should delete homedirs if users are deleted and lamdaemon.pl is in use
if (($_GET['type']== user) && $config_intern->scriptServer) { if (($_GET['type']== user) && $config_intern->scriptServer) {
echo "<br>\n"; echo "<br>\n";
echo "<table border=0>\n"; echo "<table border=0>\n";
@ -90,6 +102,7 @@ if ($_GET['type']) {
echo "</table>\n"; echo "</table>\n";
} }
// Print buttons
echo "<br><table border=0>\n"; echo "<br><table border=0>\n";
echo '<tr><td>'. echo '<tr><td>'.
'<input name="delete_no" type="submit" value="'; '<input name="delete_no" type="submit" value="';
@ -100,9 +113,9 @@ if ($_GET['type']) {
} }
if ($_POST['delete_yes'] && !$_POST['backmain']) { if ($_POST['delete_yes']) {
// deletion has been confirmed.
switch ($_POST['type5']) { switch ($_POST['type']) {
case 'user': case 'user':
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>"; echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Deleting user(s)...'); echo _('Deleting user(s)...');
@ -119,62 +132,74 @@ if ($_POST['delete_yes'] && !$_POST['backmain']) {
echo "</b></legend>\n"; echo "</b></legend>\n";
break; break;
} }
echo '<input name="type" type="hidden" value="'.$_POST['type'].'">';
echo "<br><table border=0 >\n"; echo "<br><table border=0 >\n";
echo '<input name="type5" type="hidden" value="'.$_POST['type5'].'">'; // Store kind of DNs
foreach ($delete_dn as $dn) { foreach ($delete_dn as $dn) {
switch ($_POST['type5']) { // Loop for every DN which should be deleted
switch ($_POST['type']) {
case 'user': case 'user':
// Get username from DN
$temp=explode(',', $dn); $temp=explode(',', $dn);
$username = str_replace('uid=', '', $temp[0]); $username = str_replace('uid=', '', $temp[0]);
if ($config_intern->scriptServer) { if ($config_intern->scriptServer) {
// Remove homedir if required
if ($_POST['f_rem_home']) remhomedir($username); if ($_POST['f_rem_home']) remhomedir($username);
remquotas($username, $_POST['type5']); // Remove quotas if lamdaemon.pl is used
if ($config_intern->scriptServer) remquotas($username, 'user');
} }
$result = ldap_search($ldap_intern->server(), $config_intern->get_GroupSuffix(), 'objectClass=PosixGroup', array('memberUid')); // Search for groups which have memberUid set to username
$result = ldap_search($ldap_intern->server(), $config_intern->get_GroupSuffix(), "(&(objectClass=PosixGroup)(memberUid=$username))", array(''));
$entry = ldap_first_entry($ldap_intern->server(), $result); $entry = ldap_first_entry($ldap_intern->server(), $result);
// loop for every found group and remove membership
while ($entry) { while ($entry) {
$attr2 = ldap_get_attributes($ldap_intern->server(), $entry); $success = ldap_mod_del($ldap_intern->server(), ldap_get_dn($ldap_intern->server(), $entry) , array('memberUid' => $username));
if ($attr2['memberUid']) { // *** fixme add error-message if memberUid couldn't be deleted
array_shift($attr2['memberUid']);
foreach ($attr2['memberUid'] as $nam) {
if ($nam==$username) {
$todelete['memberUid'] = $nam;
$success = ldap_mod_del($ldap_intern->server(), ldap_get_dn($ldap_intern->server(), $entry) ,$todelete);
}
}
}
$entry = ldap_next_entry($ldap_intern->server(), $entry); $entry = ldap_next_entry($ldap_intern->server(), $entry);
} }
// Delete user itself
$success = ldap_delete($ldap_intern->server(), $dn); $success = ldap_delete($ldap_intern->server(), $dn);
if (!$success) $error = _('Could not delete user:').' '.$dn; if (!$success) $error = _('Could not delete user:').' '.$dn;
break; break;
case 'host': case 'host':
// Delete host itself
$success = ldap_delete($ldap_intern->server(), $dn); $success = ldap_delete($ldap_intern->server(), $dn);
if (!$success) $error = _('Could not delete host:').' '.$dn; if (!$success) $error = _('Could not delete host:').' '.$dn;
break; break;
case 'group': case 'group':
/* First we have to check if any user uses $group
* as primary group. It's not allowed to delete a
* group if it still contains primaty members
*/
$temp=explode(',', $dn); $temp=explode(',', $dn);
$groupname = str_replace('cn=', '', $temp[0]); $groupname = str_replace('cn=', '', $temp[0]);
$result = ldap_search($ldap_intern->server(), $dn, 'objectClass=*', array('gidNumber')); // Get group GIDNumber
$groupgid = getgid($groupname);
// Search for users which have gid set to current gid
$result = ldap_search($ldap_intern->server(), $dn, "gidNumber=$groupgid", array(''));
$entry = ldap_first_entry($ldap_intern->server(), $result); $entry = ldap_first_entry($ldap_intern->server(), $result);
while ($entry) { // Print error if still users in group
$attr2 = ldap_get_attributes($ldap_intern->server(), $entry); if ($entry) $error = _('Could not delete group. Still users in group:').' '.$dn;
if ($attr2['gidNumber']==getgid($groupname)) $error = _('Could not delete group. Still users in group:').' '.$dn; else {
$entry = ldap_next_entry($ldap_intern->server(), $entry); // continue if no primary users are in group
} // Remove quotas if lamdaemon.pl is used
if (!$error) { if ($config_intern->scriptServer) remquotas($groupname, 'group');
if ($config_intern->scriptServer) remquotas($groupname, $_POST['type5']); // Delete group itself
$success = ldap_delete($ldap_intern->server(), $dn); $success = ldap_delete($ldap_intern->server(), $dn);
if (!$success) $error = _('Could not delete group:').' '.$dn; if (!$success) $error = _('Could not delete group:').' '.$dn;
} }
break; break;
} }
if ($success && isset($_SESSION[$_POST['type5'].'DN'][$dn])) unset($_SESSION[$_POST['type5'].'DN'][$dn]); // Remove DNs from cache-array
if ($success && isset($_SESSION[$_POST['type'].'DN'][$dn])) unset($_SESSION[$_POST['type'].'DN'][$dn]);
// Display success or error-message
if (!$error) echo "<tr><td><b>$dn ". _('deleted').".</b></td></tr>\n"; if (!$error) echo "<tr><td><b>$dn ". _('deleted').".</b></td></tr>\n";
else echo "<tr><td><b>$error</b></td></tr>\n"; else echo "<tr><td><b>$error</b></td></tr>\n";
} }
echo "</table><br>\n"; echo "</table><br>\n";
switch ($_POST['type5']) { switch ($_POST['type']) {
// Select which page should be displayd if back-button will be pressed
case 'user': case 'user':
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">'; echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
break; break;
@ -185,11 +210,13 @@ if ($_POST['delete_yes'] && !$_POST['backmain']) {
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">'; echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
break; break;
} }
echo "</fieldset>\n"; echo "<br></fieldset>\n";
} }
if ($_POST['delete_no']) { if ($_POST['delete_no']) {
switch ($_POST['type5']) { // Delete no accounts
switch ($_POST['type']) {
// Select which page should be displayd if back-button will be pressed
case 'user': case 'user':
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>"; echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Deleting user(s) canceled.'); echo _('Deleting user(s) canceled.');
@ -197,7 +224,6 @@ if ($_POST['delete_no']) {
echo _('No user(s) were deleted'); echo _('No user(s) were deleted');
echo "<br>"; echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">'; echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
echo "</fieldset>\n";
break; break;
case 'host': case 'host':
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>"; echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
@ -206,7 +232,6 @@ if ($_POST['delete_no']) {
echo _('No host(s) were deleted'); echo _('No host(s) were deleted');
echo "<br>"; echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">'; echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
echo "</fieldset>\n";
break; break;
case 'group': case 'group':
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>"; echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
@ -215,10 +240,9 @@ if ($_POST['delete_no']) {
echo _('No group(s) were deleted'); echo _('No group(s) were deleted');
echo "<br>"; echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">'; echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">';
echo "</fieldset>\n";
break; break;
} }
echo "<br></fieldset>\n";
} }
echo '</form></body></html>'."\n"; echo '</form></body></html>'."\n";

View File

@ -30,20 +30,22 @@ include_once('../lib/status.inc'); // Return error-message
include_once('../lib/pdf.inc'); // Return a pdf-file include_once('../lib/pdf.inc'); // Return a pdf-file
include_once('../lib/ldap.inc'); // LDAP-functions include_once('../lib/ldap.inc'); // LDAP-functions
// Start Session
session_save_path('../sess'); session_save_path('../sess');
@session_start(); @session_start();
// Print header and part of body
echo '<html><head><title>'; echo '<html><head><title>';
echo _('Create new accounts'); echo _('Create new accounts');
echo '</title>'. echo '</title>'.
'<link rel="stylesheet" type="text/css" href="'.$_SESSION['lamurl'].'style/layout.css">'. '<link rel="stylesheet" type="text/css" href="../style/layout.css">'.
'<meta http-equiv="pragma" content="no-cache">'. '<meta http-equiv="pragma" content="no-cache">'.
'<meta http-equiv="cache-control" content="no-cache">'. '<meta http-equiv="cache-control" content="no-cache">'.
'</head><body>'. '</head><body>'.
'<form enctype="multipart/form-data" action="massdetail.php" method="post">'. '<form enctype="multipart/form-data" action="massdetail.php" method="post">'.
'<table class="massdetail" width="100%">'; '<table class="massdetail" width="100%">';
if ($_GET) { if (isset($_GET)) {
$row = $_GET['row']; $row = $_GET['row'];
$select = $_GET['type']; $select = $_GET['type'];
} }