*** 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 (is_array($attributes))
switch ($mode) {
case 'add':
$list = array_keys($attributes);
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]); if (isset($this->ldapcache[$singlescope][$dn])) unset($this->ldapcache[$singlescope][$dn]);
$attrnames = array_keys ($this->attributes[$singlescope]);
foreach ($attrnames as $name) {
if (is_string($attributes[$name])) $this->ldapcache[$singlescope][$dn][$name][] = $attributes[$name];
if (is_array($attributes[$name])) $this->ldapcache[$singlescope][$dn][$name] = $attributes[$name];
} }
} }
/* 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,7 +841,18 @@ 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 (isset($attributes[$DNs[$i]]['errors'])) {
foreach ($attributes[$DNs[$i]]['errors'] as $singleerror) {
$errors[] = $singleerror;
if ($singleerror[0] = 'ERROR') $stopprocessing = true;
}
}
// fixme *** ad update_cache after every ldap-change
if (!$stopprocessing) {
if ($this->dn != $this->dn_orig) { if ($this->dn != $this->dn_orig) {
// move existing DN // move existing DN
if ($this->dn_orig!='') { if ($this->dn_orig!='') {
@ -817,40 +860,85 @@ class accountContainer {
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); $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); $success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attr);
if ($success) { if ($success) {
$_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attr);
$success = @ldap_delete($_SESSION[$this->ldap]->server(), $this->dn_orig); $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 (!$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 // create complete new dn
else { else {
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); $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']); $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)); 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]); 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++) {
if (!$stopprocessing) {
// modify attributes // modify attributes
if (isset($attributes[$DNs[$i]]['modify'])) { if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
$success = @ldap_mod_replace($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']); $success = @ldap_mod_replace($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
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])); 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[$this->cache]->update_cache($this->$dn, 'modify', $attributes[$this->dn]['modify']);
} }
// add attributes // add attributes
if (isset($attributes[$DNs[$i]]['add'])) { if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
$success = @ldap_mod_add($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['add']); $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])); 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 // removce attributes
if (isset($attributes[$DNs[$i]]['remove'])) { if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']); $success = @ldap_mod_del($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
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])); 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";
// Ask if lam should delete homedirs if users are deleted and lamdaemon.pl is in use
if (($_GET['type']== user) && $config_intern->scriptServer) {
echo "<br>\n"; echo "<br>\n";
echo "<table border=0>\n"; // Print delete rows from modules
echo '<tr><td>'; echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
echo _('Delete also Homedirectories'); $modules = array_keys($_SESSION['account']->module);
echo '</td>'."\n".'<td><input name="f_rem_home" type="checkbox">'. for ($i=0; $i<count($modules); $i++) {
'</td></tr>'."\n"; $_SESSION['account']->module[$modules[$i]]->display_html_delete($_POST);
}
echo "</table>\n"; echo "</table>\n";
echo "<br>\n";
echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
echo "<td><input name=\"delete\" type=\"submit\" value=\"" . _('Delete') . "\"></td>\n";
echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Cancel') . "\"></td>\n";
echo "</table>\n";
echo "</fieldset>\n";
echo "</form>\n";
echo "</body>\n";
echo "</html>\n";
} }
// Print buttons if ($_POST['cancel']) {
echo "<br><table border=0>\n"; if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']);
echo '<tr><td>'. metaRefresh("lists/list" . $_POST['type'] . "s.php");
'<input name="delete_no" type="submit" value="';
echo _('Cancel'); echo '"></td><td></td><td>'.
'<input name="delete_yes" type="submit" value="';
echo _('Commit'); echo '"></td></tr>';
echo "</table></fieldset>\n";
} }
if ($_POST['delete']) {
// 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 "<input name=\"type\" type=\"hidden\" value=\"" . $_POST['type'] . "\">\n";
echo "<fieldset class=\"".$_POST['type']."edit-dark\"><legend class=\"".$_POST['type']."edit-bright\"><b>";
echo _('Deleting. Please stand by ...');
echo "</b></legend>\n";
if ($_POST['delete_yes']) { echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
// deletion has been confirmed. // Delete dns
switch ($_POST['type']) { for ($m=0; $m<count($_SESSION['delete_dn']); $m++) {
case 'user': // Set to true if an real error has happened
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>"; $stopprocessing = false;
echo _('Deleting user(s)...'); // First load DN.
echo "</b></legend>\n"; $_SESSION['account']->load_account($_SESSION['delete_dn'][$m]);
break; // get commands and changes of each attribute
case 'host': $module = array_keys ($_SESSION['account']->module);
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>"; $attributes = array();
echo _('Deleting host(s)...'); $errors = array();
echo "</b></legend>\n"; // load attributes
break; foreach ($module as $singlemodule) {
case 'group': // load changes
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>"; $temp = $_SESSION['account']->module[$singlemodule]->delete_attributes($_POST);
echo _('Deleting group(s)...'); if (is_array($temp)) {
echo "</b></legend>\n"; // merge changes
break; $DNs = array_keys($temp);
// *** fixme don't include references
$attributes = array_merge_recursive($temp, $attributes);
for ($i=0; $i<count($DNs); $i++) {
$ops = array_keys($temp[$DNs[$i]]);
for ($j=0; $j<count($ops); $j++) {
$attrs = array_keys($temp[$DNs[$i]][$ops[$j]]);
for ($k=0; $k<count($attrs); $k++)
$attributes[$DNs[$i]][$ops[$j]][$attrs[$k]] = array_unique($attributes[$DNs[$i]][$ops[$j]][$attrs[$k]]);
} }
echo '<input name="type" type="hidden" value="'.$_POST['type'].'">';
echo "<br><table border=0 >\n";
// Store kind of DNs
foreach ($delete_dn as $dn) {
// Loop for every DN which should be deleted
switch ($_POST['type']) {
case 'user':
// Get username from DN
$temp=explode(',', $dn);
$username = str_replace('uid=', '', $temp[0]);
// Fill array with groupnames
$usernames[] = $username;
// 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);
// loop for every found group and remove membership
while ($entry) {
$success = ldap_mod_del($ldap_intern->server(), ldap_get_dn($ldap_intern->server(), $entry) , array('memberUid' => $username));
// *** fixme add error-message if memberUid couldn't be deleted
$entry = ldap_next_entry($ldap_intern->server(), $entry);
} }
// 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 if (!$stopprocessing) {
* as primary group. It's not allowed to delete a // modify attributes
* group if it still contains primaty members if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
*/ $success = @ldap_mod_replace($_SESSION[$_SESSION['account']->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
$temp=explode(',', $dn); if (!$success) {
$groupname = str_replace('cn=', '', $temp[0]); $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]));
// Fill array with groupnames $stopprocessing = true;
$usernames[] = $groupname; }
// Get group GIDNumber else
$groupgid = getgid($groupname); $_SESSION['cache']->update_cache($DNs[$i], 'modify', $attributes[$DNs[$i]]['modify']);
// Search for users which have gid set to current gid }
$result = ldap_search($ldap_intern->server(), $config_intern->get_UserSuffix(), "gidNumber=$groupgid", array('')); // add attributes
// Print error if still users in group if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
if (!$result) $error = _('Could not delete group. Still users in group:').' '.$dn; $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 (!$stopprocessing) {
foreach ($attributes as $DN) {
if (is_array($DN['lamdaemon']['command'])) $result = $_SESSION['account']->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 (!$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 { else {
// Delete group itself echo "<tr>\n";
$success = ldap_delete($ldap_intern->server(), $dn); echo "<td>" . sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "</td>\n";
if (!$success) $error = _('Could not delete group:').' '.$dn; echo "</tr>\n";
foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]);
} }
break;
} }
if ($config_intern->scriptServer && isset($usernames)) { echo "</table>\n";
// Remove homedir if required echo "<br>\n";
if ($_POST['f_rem_home']) remhomedir($usernames); echo "<table border=0 width=\"100%\">\n<tr><td valign=\"top\" width=\"15%\" >";
// Remove quotas if lamdaemon.pl is used echo "<td><input name=\"cancel\" type=\"submit\" value=\"" . _('Back to list') . "\"></td>\n";
remquotas($usernames, 'user'); echo "</table>\n";
} echo "</fieldset>\n";
// Remove DNs from cache-array echo "</form>\n";
if ($success && isset($_SESSION[$_POST['type'].'DN'][$dn])) unset($_SESSION[$_POST['type'].'DN'][$dn]); echo "</body>\n";
// Display success or error-message echo "</html>\n";
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";
switch ($_POST['type']) {
// Select which page should be displayd if back-button will be pressed
case 'user':
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
break;
case 'group':
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">';
break;
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