*** empty log message ***

This commit is contained in:
katagia 2004-01-10 11:47:48 +00:00
parent 9fd6df2f03
commit 57807ab71c
13 changed files with 376 additions and 274 deletions

View File

@ -234,19 +234,51 @@ class cache {
/* This function update the cache when changes were /* This function update the cache when changes were
* made without refrehing the complete cache * made without refrehing the complete cache
*/ */
function update_cache($dn, $attributes, $singlescope) { function update_cache($dn, $mode, $attributes=false) {
$allowed_modes = array ( 'add', 'remove', 'modify', 'delete_dn' );
$allowed_types = array ( 'user', 'group', 'host', 'domain', '*' ); $allowed_types = array ( 'user', 'group', 'host', 'domain', '*' );
if (!in_array($singlescope, $allowed_types)) trigger_error(sprintf(_('Invalid scope. Valid scopes are %s.'), implode(" ", $allowed_types)), E_USER_ERROR); if (!in_array($singlescope, $allowed_types)) trigger_error(sprintf(_('Invalid scope. Valid scopes are %s.'), implode(" ", $allowed_types)), E_USER_ERROR);
if (!in_array($mode, $allowed_modes)) trigger_error(sprintf(_('Invalid mode. Valid modes are %s.'), implode(" ", $allowed_modes)), E_USER_ERROR);
// Everything seems to be OK, start processing data // Everything seems to be OK, start processing data
// Get Scope
foreach ($allowed_types as $scope) {
$function = '$suffix = $this->config->get_'.ucfirst($scope).'Suffix();';
eval($function);
if (strpos($dn, $suffix)) $singlescope = $scope;
}
if (!isset($singlescope)) trigger_error(sprintf(_('Invalid dn: %s. DN not covered by any suffix.'), $dn), E_USER_WARN);
// Refresh Cache
$this->refresh_cache(); $this->refresh_cache();
if (isset($this->ldapcache[$singlescope][$dn])) unset($this->ldapcache[$singlescope][$dn]); if (is_array($attributes))
$attrnames = array_keys ($this->attributes[$singlescope]); switch ($mode) {
foreach ($attrnames as $name) { case 'add':
if (is_string($attributes[$name])) $this->ldapcache[$singlescope][$dn][$name][] = $attributes[$name]; $list = array_keys($attributes);
if (is_array($attributes[$name])) $this->ldapcache[$singlescope][$dn][$name] = $attributes[$name]; for ($i=0; $i<count($list); $i++)
foreach ($attributes[$list[$i]] as $attribute)
$this->ldapcache[$singlescope][$dn][$list[$i]][] = $attributes[$list[$i]];
break;
case 'remove':
$list = array_keys($attributes);
for ($i=0; $i<count($list); $i++)
foreach ($attributes[$list[$i]] as $attribute)
if (isset($this->ldapcache[$singlescope][$dn][$list[$i]][$attributes[$list[$i]]]))
unset($this->ldapcache[$singlescope][$dn][$list[$i]][$attributes[$list[$i]]]);
break;
case 'modify':
$list = array_keys($attributes);
for ($i=0; $i<count($list); $i++) {
if (isset($this->ldapcache[$singlescope][$dn][$list[$i]])) unset($this->ldapcache[$singlescope][$dn][$list[$i]]);
foreach ($attributes[$list[$i]] as $attribute)
$this->ldapcache[$singlescope][$dn][$list[$i]][] = $attributes[$list[$i]];
}
}
else {
if ($mode=='delete_dn')
if (isset($this->ldapcache[$singlescope][$dn])) unset($this->ldapcache[$singlescope][$dn]);
} }
} }
/* This function will return the gidNumber to an existing groupname /* This function will return the gidNumber to an existing groupname
* gidNumbers are taken from cache-array * gidNumbers are taken from cache-array
*/ */
@ -809,48 +841,104 @@ class accountContainer {
unset ($attributes[$this->dn]); unset ($attributes[$this->dn]);
$this->dn = $this->dn_orig; $this->dn = $this->dn_orig;
} }
// Set to true if an real error has happened
$stopprocessing = false;
// Add new DN // Add new DN
if ($this->dn != $this->dn_orig) { if (isset($attributes[$DNs[$i]]['errors'])) {
// move existing DN foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
if ($this->dn_orig!='') { $errors[] = $singleerror;
// merge attributes together if ($singleerror[0] = 'ERROR') $stopprocessing = true;
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); }
$success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attr); }
if ($success) { // fixme *** ad update_cache after every ldap-change
$success = @ldap_delete($_SESSION[$this->ldap]->server(), $this->dn_orig);
if (!$success) return array('ERROR', 'LDAP', sprintf(_('Was unable to delete dn: %s.'), $this->dn_orig)); if (!$stopprocessing) {
if ($this->dn != $this->dn_orig) {
// move existing DN
if ($this->dn_orig!='') {
// merge attributes together
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']);
$success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attr);
if ($success) {
$_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attr);
$success = @ldap_delete($_SESSION[$this->ldap]->server(), $this->dn_orig);
if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to delete dn: %s.'), $this->dn_orig));
$stopprocessing = true;
}
if ($success)
$_SESSION[$this->cache]->update_cache($this->$dn, 'delete_dn');
}
if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to create dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $this->dn));
$stopprocessing = true;
}
} }
if (!$success) return array('ERROR', 'LDAP', sprintf(_('Was unable to create dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $this->dn)); // create complete new dn
else {
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']);
$success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attributes[$this->dn]['add']);
if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to create dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $this->dn));
$stopprocessing = true;
}
else
$_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attributes[$this->dn]['add']);
}
unset($attributes[$this->dn]);
} }
// create complete new dn
else {
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']);
$success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attributes[$this->dn]['add']);
if (!$success) return array('ERROR', 'LDAP', sprintf(_('Was unable to create dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $this->dn));
}
unset($attributes[$this->dn]);
} }
$DNs = array_keys($attributes); $DNs = array_keys($attributes);
for ($i=0; $i<count($DNs); $i++) { for ($i=0; $i<count($DNs); $i++) {
// modify attributes if (!$stopprocessing) {
if (isset($attributes[$DNs[$i]]['modify'])) { // modify attributes
$success = @ldap_mod_replace($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']); if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
if (!$success) return array('ERROR', 'LDAP', sprintf(_('Was unable to modify attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i])); $success = @ldap_mod_replace($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
} if (!$success) {
// add attributes $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to modify attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
if (isset($attributes[$DNs[$i]]['add'])) { $stopprocessing = true;
$success = @ldap_mod_add($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['add']); }
if (!$success) return array('ERROR', 'LDAP', sprintf(_('Was unable to add attribtues to dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i])); else
} $_SESSION[$this->cache]->update_cache($this->$dn, 'modify', $attributes[$this->dn]['modify']);
// removce attributes }
if (isset($attributes[$DNs[$i]]['remove'])) { // add attributes
$success = @ldap_mod_del($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']); if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
if (!$success) return array('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i])); $success = @ldap_mod_add($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['add']);
if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to add attribtues to dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true;
}
else
$_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attributes[$this->dn]['add']);
}
// removce attributes
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true;
}
else
$_SESSION[$this->cache]->update_cache($this->$dn, 'remove', $attributes[$this->dn]['remove']);
}
} }
} }
foreach ($attributes as $DN)
if (is_array($DN['lamdaemon']['command'])) $this->lamdaemon($DN['lamdaemon']['command']);
if (!$stopprocessing) {
foreach ($attributes as $DN) {
if (is_array($DN['lamdaemon']['command'])) $result = $this->lamdaemon($DN['lamdaemon']['command']);
// Error somewhere in lamdaemon
foreach ($result as $singleresult) {
if (is_array($singleresult)) {
if ($singleresult[0] = 'ERROR') $stopprocessing = true;
$temparray[0] = $singleresult[0];
$temparray[1] = _($singleresult[1]);
$temparray[2] = _($singleresult[2]);
}
}
}
}
if (count($errors)!=0) return $errors;
return 0; return 0;
} }

View File

@ -141,8 +141,7 @@ class account {
} }
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); return 0;
return $return;
} }
/* Write variables into object and do some regexp checks /* Write variables into object and do some regexp checks

View File

@ -149,8 +149,7 @@ class inetOrgPerson {
*/ */
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); return 0;
return $return;
} }
function proccess_attributes($post) { function proccess_attributes($post) {

View File

@ -102,8 +102,7 @@ class main {
} }
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); return 0;
return $return;
} }
/* Write variables into object and do some regexp checks /* Write variables into object and do some regexp checks
@ -123,8 +122,8 @@ class main {
} }
// save account // save account
if ($post['create']) { if ($post['create']) {
$success = $_SESSION[$this->base]->save_account(); $errors = $_SESSION[$this->base]->save_account();
if (is_array($success)) return array($success); if (is_array($errors)) return array($errors);
// return name of subpage // return name of subpage
return 'finish'; return 'finish';
} }

View File

@ -159,6 +159,11 @@ class posixAccount {
return array('attributes', 'groups'); return array('attributes', 'groups');
} }
function profile_attributes() {
// array of attribtues wich are unique and not allowed to store in profile
array unique_attributes ( 'user' => array ('cn', 'rid', 'uid', 'uidNumber', 'userPassword') );
}
/* This function returns all ldap attributes /* This function returns all ldap attributes
* which are part of posixAccount and returns * which are part of posixAccount and returns
* also their values. * also their values.
@ -322,9 +327,9 @@ class posixAccount {
$groups = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('memberUid', 'posixGroup', 'group'); $groups = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('memberUid', 'posixGroup', 'group');
$DNs = array_keys($groups); $DNs = array_keys($groups);
for ($i=0; $i<count($DNs); $i++) { for ($i=0; $i<count($DNs); $i++) {
if (in_array($this->attributes['uid'][0], $groups[$DNs[$i]])) $return[$DNs[$i]]['remove']['memberUid'] = $this->attributes['uid'][0]; if (in_array($this->attributes['uid'][0], $groups[$DNs[$i]])) $return[$DNs[$i]]['remove']['memberUid'][] = $this->attributes['uid'][0];
} }
if ($post['deletehomedir']) $return[$_SESSION[$this->base]->dn]['lamdaemon']['command'][] = $this->attributes['uid'][0] . " home rem"; if ($post['deletehomedir']) $return[$_SESSION[$this->base]->dn_orig]['lamdaemon']['command'][] = $this->attributes['uid'][0] . " home rem";
return $return; return $return;
} }
@ -627,7 +632,7 @@ class posixAccount {
function display_html_delete($post) { function display_html_delete($post) {
if ($_SESSION[$this->base]->type=='user' && isset($_SESSION[$_SESSION[$this->base]->config]->scriptPath)) { if ($_SESSION[$this->base]->type=='user' && isset($_SESSION[$_SESSION[$this->base]->config]->scriptPath)) {
echo "<tr>\n"; echo "<tr>\n";
echo "<td>" . _('Delete home directory') . "*</td>\n"; echo "<td>" . _('Delete home directory') . "</td>\n";
echo "<td><input name=\"deletehomedir\" type=\"checkbox\"></td>\n"; echo "<td><input name=\"deletehomedir\" type=\"checkbox\"></td>\n";
echo "<tr>\n"; echo "<tr>\n";
} }

View File

@ -292,7 +292,8 @@ class posixGroup {
} }
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); if ($_SESSION[$_SESSION[$this->base]->cache]->in_cache($this->attributes['gidNumber'][0], 'gidNumber', 'user'))
$return[$_SESSION[$this->base]->dn]['errors'][] = array ('ERROR', _('Primary groupmembers'), _('There are still primary members in group.'));
return $return; return $return;
} }
@ -528,6 +529,7 @@ class posixGroup {
} }
function display_html_delete($post) { function display_html_delete($post) {
// Get list of primary groupmembers.
return 0; return 0;
} }

View File

@ -179,7 +179,7 @@ class quota {
} }
if ($_SESSION[$this->base]->type=='user') $id = $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0]; if ($_SESSION[$this->base]->type=='user') $id = $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0];
if ($_SESSION[$this->base]->type=='group') $id = $_SESSION[$this->base]->module['posixGroup']->attributes['cn'][0]; if ($_SESSION[$this->base]->type=='group') $id = $_SESSION[$this->base]->module['posixGroup']->attributes['cn'][0];
$return[$_SESSION[$this->base]->dn]['lamdaemon']['command'][] = $id . " quota set " . $_SESSION[$this->base]->type . " $quotastring\n"; $return[$_SESSION[$this->base]->dn_orig]['lamdaemon']['command'][] = $id . " quota set " . $_SESSION[$this->base]->type . " $quotastring\n";
return $return; return $return;
} }
@ -265,6 +265,10 @@ class quota {
return 0; return 0;
} }
function display_html_delete($post) {
return 0;
}
} }
?> ?>

View File

@ -233,8 +233,7 @@ class sambaAccount {
} }
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); return 0;
return $return;
} }
/* Write variables into object and do some regexp checks /* Write variables into object and do some regexp checks

View File

@ -182,8 +182,7 @@ class sambaGroupMapping {
} }
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); return 0;
return $return;
} }
/* Write variables into object and do some regexp checks /* Write variables into object and do some regexp checks

View File

@ -239,8 +239,7 @@ class sambaSamAccount {
} }
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); return 0;
return $return;
} }
/* Write variables into object and do some regexp checks /* Write variables into object and do some regexp checks

View File

@ -163,8 +163,7 @@ class shadowAccount {
} }
function delete_attributes($post) { function delete_attributes($post) {
$return = array(); return 0;
return $return;
} }
/* Write variables into object and do some regexp checks /* Write variables into object and do some regexp checks

View File

@ -23,233 +23,225 @@ $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/account.inc'); // include all needed files
include_once('../lib/config.inc'); include_once('../lib/account.inc'); // File with all account-funtions
// start session include_once('../lib/config.inc'); // File with configure-functions
include_once('../lib/profiles.inc'); // functions to load and save profiles
include_once('../lib/status.inc'); // Return error-message
include_once('../lib/pdf.inc'); // Return a pdf-file
include_once('../lib/ldap.inc'); // LDAP-functions
/* We have to include all modules
* before start session
* *** fixme I would prefer loading them dynamic but
* i don't know how to to this
*/
$dir = opendir('../lib/modules');
while ($entry = readdir($dir))
if (is_file('../lib/modules/'.$entry)) include_once ('../lib/modules/'.$entry);
// Start session
session_save_path('../sess'); session_save_path('../sess');
@session_start(); @session_start();
// Redirect to startpage if user is not loged in // Redirect to startpage if user is not loged in
if (!isset($_SESSION['loggedIn'])) { if (!isset($_SESSION['loggedIn'])) {
metaRefresh("login.php"); metaRefresh("login.php");
die; exit;
} }
// set language // Set correct language, codepages, ....
setlanguage(); setlanguage();
// use references because session-vars can change in future if (!isset($_SESSION['cache'])) {
$ldap_intern =& $_SESSION['ldap']; $_SESSION['cache'] = new cache();
$header_intern =& $_SESSION['header'];
$config_intern =& $_SESSION['config'];
$delete_dn =& $_SESSION['delete_dn'];
if ($_POST['backmain']) {
// back to list page
if (isset($_SESSION['delete_dn'])) unset ($_SESSION['delete_dn']);
metaRefresh("lists/list".$_POST['type']."s.php");
// stop script because we don't want to reate invalid html-code
die;
} }
// Print header and part of body
echo $header_intern;
echo '<title>';
echo _('Delete Account');
echo '</title>'."\n".
'<link rel="stylesheet" type="text/css" href="../style/layout.css">'."\n".
'<meta http-equiv="pragma" content="no-cache">'."\n".
'<meta http-equiv="cache-control" content="no-cache">'."\n".
'</head>'."\n".
'<body>'."\n".
'<form action="delete.php" method="post">'."\n";
if ($_GET['type']) { if ($_GET['type']) {
// $_GET['type'] is true if delete.php was called from *list.php // Create account list
// Store $_GET['type'] as $_POST['type'] foreach ($_SESSION['delete_dn'] as $dn) {
// Replace wrong chars from Session $start = strpos ($dn, "=")+1;
echo '<input name="type" type="hidden" value="'.$_GET['type'].'">'; $end = strpos ($dn, ",");
switch ($_GET['type']) { $users[] = substr($dn, $start, $end-$start);
// Select which layout and text should be displayed
case 'user':
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Delete user(s)');
echo "</b></legend>\n";
echo '<b>'._('Do you really want to delete user(s):').'</b>';
break;
case 'host':
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
echo _('Delete host(s)');
echo "</b></legend>\n";
echo '<b>'._('Do you really want to delete host(s):').'</b>';
break;
case 'group':
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
echo _('Delete group(s)');
echo "</b></legend>\n";
echo '<b>'._('Do you really want to delete group(s):').'</b>';
break;
} }
//load account
$_SESSION['account'] = new accountContainer($_GET['type'], 'account');
$_SESSION['account']->load_account($_SESSION['delete_dn'][0]);
// Show HTML Page
echo $_SESSION['header'];
echo "<title>";
echo _("Delete Account");
echo "</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n";
echo "</head><body>\n";
echo "<form action=\"delete.php\" method=\"post\">\n";
echo "<fieldset class=\"".$_GET['type']."edit-dark\"><legend class=\"".$_GET['type']."edit-bright\"><b>";
echo _('Please confirm:');
echo "</b></legend>\n";
echo "<input name=\"type\" type=\"hidden\" value=\"" . $_GET['type'] . "\">\n";
echo sprintf(_("Do you really want to remove the following %ss?\n"), $_GET['type']);
echo "<br>\n"; echo "<br>\n";
// display all DNs in a tables echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
echo "<table border=0 width=\"100%\">\n"; for ($i=0; $i<count($users); $i++) {
foreach ($delete_dn as $dn) echo '<tr><td>'.$dn.'</td></tr>'; echo "<tr>\n";
echo "<td>" . sprintf(_('%sname:'), ucfirst($_GET['type'])) . " $users[$i]</td>\n";
echo "<td>" . _('DN:') . " " . $_SESSION['delete_dn'][$i] . "</td>\n";
echo "</tr>\n";
}
echo "</table>\n"; echo "</table>\n";
echo "<br>\n";
// Ask if lam should delete homedirs if users are deleted and lamdaemon.pl is in use // Print delete rows from modules
if (($_GET['type']== user) && $config_intern->scriptServer) { echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
echo "<br>\n"; $modules = array_keys($_SESSION['account']->module);
echo "<table border=0>\n"; for ($i=0; $i<count($modules); $i++) {
echo '<tr><td>'; $_SESSION['account']->module[$modules[$i]]->display_html_delete($_POST);
echo _('Delete also Homedirectories');
echo '</td>'."\n".'<td><input name="f_rem_home" type="checkbox">'.
'</td></tr>'."\n";
echo "</table>\n";
} }
echo "</table>\n";
// Print buttons echo "<br>\n";
echo "<br><table border=0>\n"; echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
echo '<tr><td>'. echo "<td><input name=\"delete\" type=\"submit\" value=\"" . _('Delete') . "\"></td>\n";
'<input name="delete_no" type="submit" value="'; echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Cancel') . "\"></td>\n";
echo _('Cancel'); echo '"></td><td></td><td>'. echo "</table>\n";
'<input name="delete_yes" type="submit" value="'; echo "</fieldset>\n";
echo _('Commit'); echo '"></td></tr>'; echo "</form>\n";
echo "</table></fieldset>\n"; echo "</body>\n";
echo "</html>\n";
} }
if ($_POST['cancel']) {
if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
metaRefresh("lists/list" . $_POST['type'] . "s.php");
}
if ($_POST['delete_yes']) { if ($_POST['delete']) {
// deletion has been confirmed. // Show HTML Page
switch ($_POST['type']) { echo $_SESSION['header'];
case 'user': echo "<title>";
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>"; echo _("Delete Account");
echo _('Deleting user(s)...'); echo "</title>\n";
echo "</b></legend>\n"; echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n";
break; echo "</head><body>\n";
case 'host': echo "<form action=\"delete.php\" method=\"post\">\n";
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>"; echo "<input name=\"type\" type=\"hidden\" value=\"" . $_POST['type'] . "\">\n";
echo _('Deleting host(s)...'); echo "<fieldset class=\"".$_POST['type']."edit-dark\"><legend class=\"".$_POST['type']."edit-bright\"><b>";
echo "</b></legend>\n"; echo _('Deleting. Please stand by ...');
break; echo "</b></legend>\n";
case 'group':
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>"; echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
echo _('Deleting group(s)...'); // Delete dns
echo "</b></legend>\n"; for ($m=0; $m<count($_SESSION['delete_dn']); $m++) {
break; // Set to true if an real error has happened
} $stopprocessing = false;
echo '<input name="type" type="hidden" value="'.$_POST['type'].'">'; // First load DN.
echo "<br><table border=0 >\n"; $_SESSION['account']->load_account($_SESSION['delete_dn'][$m]);
// Store kind of DNs // get commands and changes of each attribute
foreach ($delete_dn as $dn) { $module = array_keys ($_SESSION['account']->module);
// Loop for every DN which should be deleted $attributes = array();
switch ($_POST['type']) { $errors = array();
case 'user': // load attributes
// Get username from DN foreach ($module as $singlemodule) {
$temp=explode(',', $dn); // load changes
$username = str_replace('uid=', '', $temp[0]); $temp = $_SESSION['account']->module[$singlemodule]->delete_attributes($_POST);
// Fill array with groupnames if (is_array($temp)) {
$usernames[] = $username; // merge changes
// Search for groups which have memberUid set to username $DNs = array_keys($temp);
$result = ldap_search($ldap_intern->server(), $config_intern->get_GroupSuffix(), "(&(objectClass=PosixGroup)(memberUid=$username))", array('')); // *** fixme don't include references
$entry = ldap_first_entry($ldap_intern->server(), $result); $attributes = array_merge_recursive($temp, $attributes);
// loop for every found group and remove membership for ($i=0; $i<count($DNs); $i++) {
while ($entry) { $ops = array_keys($temp[$DNs[$i]]);
$success = ldap_mod_del($ldap_intern->server(), ldap_get_dn($ldap_intern->server(), $entry) , array('memberUid' => $username)); for ($j=0; $j<count($ops); $j++) {
// *** fixme add error-message if memberUid couldn't be deleted $attrs = array_keys($temp[$DNs[$i]][$ops[$j]]);
$entry = ldap_next_entry($ldap_intern->server(), $entry); for ($k=0; $k<count($attrs); $k++)
$attributes[$DNs[$i]][$ops[$j]][$attrs[$k]] = array_unique($attributes[$DNs[$i]][$ops[$j]][$attrs[$k]]);
}
} }
// Delete user itself }
$success = ldap_delete($ldap_intern->server(), $dn); }
if (!$success) $error = _('Could not delete user:').' '.$dn; $DNs = array_keys($attributes);
break; for ($i=0; $i<count($DNs); $i++) {
case 'host': if (isset($attributes[$DNs[$i]]['errors'])) {
// Delete host itself foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
$success = ldap_delete($ldap_intern->server(), $dn); $errors[] = $singleerror;
if (!$success) $error = _('Could not delete host:').' '.$dn; if ($singleerror[0] = 'ERROR') $stopprocessing = true;
break;
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);
$groupname = str_replace('cn=', '', $temp[0]);
// Fill array with groupnames
$usernames[] = $groupname;
// Get group GIDNumber
$groupgid = getgid($groupname);
// Search for users which have gid set to current gid
$result = ldap_search($ldap_intern->server(), $config_intern->get_UserSuffix(), "gidNumber=$groupgid", array(''));
// Print error if still users in group
if (!$result) $error = _('Could not delete group. Still users in group:').' '.$dn;
else {
// Delete group itself
$success = ldap_delete($ldap_intern->server(), $dn);
if (!$success) $error = _('Could not delete group:').' '.$dn;
} }
break; }
if (!$stopprocessing) {
// modify attributes
if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
$success = @ldap_mod_replace($_SESSION[$_SESSION['account']->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
if (!$success) {
$errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to modify attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true;
}
else
$_SESSION['cache']->update_cache($DNs[$i], 'modify', $attributes[$DNs[$i]]['modify']);
}
// add attributes
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
$success = @ldap_mod_add($_SESSION[$_SESSION['account']->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['add']);
if (!$success) {
$errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to add attribtues to dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true;
}
else
$_SESSION['cache']->update_cache($DNs[$i], 'add', $attributes[$DNs[$i]]['add']);
}
// removce attributes
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION[$_SESSION['account']->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
if (!$success) {
$errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true;
}
else
$_SESSION['cache']->update_cache($DNs[$i], 'remove', $attributes[$DNs[$i]]['remove']);
}
}
} }
if ($config_intern->scriptServer && isset($usernames)) { if (!$stopprocessing) {
// Remove homedir if required foreach ($attributes as $DN) {
if ($_POST['f_rem_home']) remhomedir($usernames); if (is_array($DN['lamdaemon']['command'])) $result = $_SESSION['account']->lamdaemon($DN['lamdaemon']['command']);
// Remove quotas if lamdaemon.pl is used // Error somewhere in lamdaemon
remquotas($usernames, 'user'); foreach ($result as $singleresult) {
if (is_array($singleresult)) {
if ($singleresult[0] = 'ERROR') $stopprocessing = true;
$temparray[0] = $singleresult[0];
$temparray[1] = _($singleresult[1]);
$temparray[2] = _($singleresult[2]);
}
}
}
}
if (!$stopprocessing) {
$success = @ldap_delete($_SESSION[$_SESSION['account']->ldap]->server(), $_SESSION['delete_dn'][$m]);
if (!$success) $errors[] = array ('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
else
$_SESSION['cache']->update_cache($_SESSION['delete_dn'][$m], 'delete_dn');
}
if (!$stopprocessing) {
echo "<tr>\n";
echo "<td>" . sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "</td>\n";
echo "</tr>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
}
else {
echo "<tr>\n";
echo "<td>" . sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "</td>\n";
echo "</tr>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
} }
// 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";
else echo "<tr><td><b>$error</b></td></tr>\n";
} }
echo "</table><br>\n"; echo "</table>\n";
switch ($_POST['type']) { echo "<br>\n";
// Select which page should be displayd if back-button will be pressed echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
case 'user': echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\"></td>\n";
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">'; echo "</table>\n";
break; echo "</fieldset>\n";
case 'group': echo "</form>\n";
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">'; echo "</body>\n";
break; echo "</html>\n";
case 'host':
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
break;
}
echo "<br></fieldset>\n";
} }
if ($_POST['delete_no']) {
// Delete no accounts
echo '<input name="type" type="hidden" value="'.$_POST['type'].'">';
switch ($_POST['type']) {
// Select which page should be displayd if back-button will be pressed
case 'user':
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Deleting user(s) canceled.');
echo "</b></legend>\n";
echo _('No user(s) were deleted');
echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
break;
case 'host':
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
echo _('Deleting host(s) canceled.');
echo "</b></legend>\n";
echo _('No host(s) were deleted');
echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
break;
case 'group':
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
echo _('Deleting group(s) canceled.');
echo "</b></legend>\n";
echo _('No group(s) were deleted');
echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">';
break;
}
echo "<br></fieldset>\n";
}
echo '</form></body></html>'."\n";
?> ?>

View File

@ -24,26 +24,39 @@ $Id$
*/ */
// include all needed files // include all needed files
include_once('../lib/account.inc'); // File with custom functions include_once('../lib/account.inc'); // File with all account-funtions
include_once('../lib/config.inc'); // File with configure-functions include_once('../lib/config.inc'); // File with configure-functions
include_once('../lib/ldap.inc'); // LDAP-functions
include_once('../lib/profiles.inc'); // functions to load and save profiles include_once('../lib/profiles.inc'); // functions to load and save profiles
include_once('../lib/status.inc'); // Return error-message 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
// Start Session /* We have to include all modules
* before start session
* *** fixme I would prefer loading them dynamic but
* i don't know how to to this
*/
$dir = opendir('../lib/modules');
while ($entry = readdir($dir))
if (is_file('../lib/modules/'.$entry)) include_once ('../lib/modules/'.$entry);
// Start session
session_save_path('../sess'); session_save_path('../sess');
@session_start(); @session_start();
// Redirect to startpage if user is not loged in // Redirect to startpage if user is not loged in
if (!isset($_SESSION['loggedIn'])) { if (!isset($_SESSION['loggedIn'])) {
metaRefresh("login.php"); metaRefresh("login.php");
die; exit;
} }
// Set correct language, codepages, .... // Set correct language, codepages, ....
setlanguage(); setlanguage();
if (!isset($_SESSION['cache'])) {
$_SESSION['cache'] = new cache();
}
/* Save current time in $time. We need $time to check out how /* Save current time in $time. We need $time to check out how
* long masscreate.php is running. To avoid max. execution time * long masscreate.php is running. To avoid max. execution time
* set in php.ini masscreate.php will create a redirect to * set in php.ini masscreate.php will create a redirect to
@ -54,12 +67,17 @@ $time=time();
* from masscreate.php itself via meta refresh * from masscreate.php itself via meta refresh
*/ */
if (count($_POST)==0) { if (count($_POST)==0) {
// Go to page which shows all users // Register new account_container
if (isset($_GET['list2'])) $select = 'list2'; $_SESSION['account'] = new accountContainer('user', 'account');
// (Continue) to create users // load profile
else if (isset($_GET['create'])) $select='create';
// Display mainpage if nothing else should be displayed // Find out list of attribtues which must be set put not allready covered by profile
else $select='main';
// Print first HTML-Page
echo $_SESSION['header'];
echo "<title>" . _('Create new Accounts') . "</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/layout.css\">\n";
} }
else { else {
/* Check loaded attributed in $_SESSION['accounts'] if file was loaded and /* Check loaded attributed in $_SESSION['accounts'] if file was loaded and