From 57807ab71c84b5d0d4cfe9aeac3ddb9c5c143694 Mon Sep 17 00:00:00 2001 From: katagia Date: Sat, 10 Jan 2004 11:47:48 +0000 Subject: [PATCH] *** empty log message *** --- lam/lib/account.inc | 166 ++++++++--- lam/lib/modules/account.inc | 3 +- lam/lib/modules/inetOrgPerson.inc | 3 +- lam/lib/modules/main.inc | 7 +- lam/lib/modules/posixAccount.inc | 11 +- lam/lib/modules/posixGroup.inc | 4 +- lam/lib/modules/quota.inc | 6 +- lam/lib/modules/sambaAccount.inc | 3 +- lam/lib/modules/sambaGroupMapping.inc | 3 +- lam/lib/modules/sambaSamAccount.inc | 3 +- lam/lib/modules/shadowAccount.inc | 3 +- lam/templates/delete.php | 400 +++++++++++++------------- lam/templates/masscreate.php | 38 ++- 13 files changed, 376 insertions(+), 274 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 00daf150..63aa710a 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -234,19 +234,51 @@ class cache { /* This function update the cache when changes were * 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', '*' ); 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 + // 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(); - 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]; + if (is_array($attributes)) + switch ($mode) { + case 'add': + $list = array_keys($attributes); + for ($i=0; $ildapcache[$singlescope][$dn][$list[$i]][] = $attributes[$list[$i]]; + break; + case 'remove': + $list = array_keys($attributes); + for ($i=0; $ildapcache[$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; $ildapcache[$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 * gidNumbers are taken from cache-array */ @@ -809,48 +841,104 @@ class accountContainer { unset ($attributes[$this->dn]); $this->dn = $this->dn_orig; } + // Set to true if an real error has happened + $stopprocessing = false; // Add new DN - 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) { - $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 (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) { + // 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); for ($i=0; $ildap]->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])); - } - // add attributes - if (isset($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])); - } - // removce attributes - if (isset($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 (!$stopprocessing) { + // modify attributes + if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) { + $success = @ldap_mod_replace($_SESSION[$this->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[$this->cache]->update_cache($this->$dn, 'modify', $attributes[$this->dn]['modify']); + } + // add attributes + if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) { + $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; } diff --git a/lam/lib/modules/account.inc b/lam/lib/modules/account.inc index 133e7c0d..21a3aaa9 100644 --- a/lam/lib/modules/account.inc +++ b/lam/lib/modules/account.inc @@ -141,8 +141,7 @@ class account { } function delete_attributes($post) { - $return = array(); - return $return; + return 0; } /* Write variables into object and do some regexp checks diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index 881c8014..40344633 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -149,8 +149,7 @@ class inetOrgPerson { */ function delete_attributes($post) { - $return = array(); - return $return; + return 0; } function proccess_attributes($post) { diff --git a/lam/lib/modules/main.inc b/lam/lib/modules/main.inc index 7995cc5b..079551f9 100644 --- a/lam/lib/modules/main.inc +++ b/lam/lib/modules/main.inc @@ -102,8 +102,7 @@ class main { } function delete_attributes($post) { - $return = array(); - return $return; + return 0; } /* Write variables into object and do some regexp checks @@ -123,8 +122,8 @@ class main { } // save account if ($post['create']) { - $success = $_SESSION[$this->base]->save_account(); - if (is_array($success)) return array($success); + $errors = $_SESSION[$this->base]->save_account(); + if (is_array($errors)) return array($errors); // return name of subpage return 'finish'; } diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index a1bedc7d..de26c4c1 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -159,6 +159,11 @@ class posixAccount { 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 * which are part of posixAccount and returns * also their values. @@ -322,9 +327,9 @@ class posixAccount { $groups = $_SESSION[$_SESSION[$this->base]->cache]->get_cache('memberUid', 'posixGroup', 'group'); $DNs = array_keys($groups); for ($i=0; $iattributes['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; } @@ -627,7 +632,7 @@ class posixAccount { function display_html_delete($post) { if ($_SESSION[$this->base]->type=='user' && isset($_SESSION[$_SESSION[$this->base]->config]->scriptPath)) { echo "\n"; - echo "" . _('Delete home directory') . "*\n"; + echo "" . _('Delete home directory') . "\n"; echo "\n"; echo "\n"; } diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index 49a9603a..409cc622 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -292,7 +292,8 @@ class posixGroup { } 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; } @@ -528,6 +529,7 @@ class posixGroup { } function display_html_delete($post) { + // Get list of primary groupmembers. return 0; } diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index c0a4fa41..b07d28ea 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -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=='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; } @@ -265,6 +265,10 @@ class quota { return 0; } + function display_html_delete($post) { + return 0; + } + } ?> diff --git a/lam/lib/modules/sambaAccount.inc b/lam/lib/modules/sambaAccount.inc index eaea4ee5..c3b93d8f 100644 --- a/lam/lib/modules/sambaAccount.inc +++ b/lam/lib/modules/sambaAccount.inc @@ -233,8 +233,7 @@ class sambaAccount { } function delete_attributes($post) { - $return = array(); - return $return; + return 0; } /* Write variables into object and do some regexp checks diff --git a/lam/lib/modules/sambaGroupMapping.inc b/lam/lib/modules/sambaGroupMapping.inc index 53e628d1..3f0a730c 100644 --- a/lam/lib/modules/sambaGroupMapping.inc +++ b/lam/lib/modules/sambaGroupMapping.inc @@ -182,8 +182,7 @@ class sambaGroupMapping { } function delete_attributes($post) { - $return = array(); - return $return; + return 0; } /* Write variables into object and do some regexp checks diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 7b99863f..9095408a 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -239,8 +239,7 @@ class sambaSamAccount { } function delete_attributes($post) { - $return = array(); - return $return; + return 0; } /* Write variables into object and do some regexp checks diff --git a/lam/lib/modules/shadowAccount.inc b/lam/lib/modules/shadowAccount.inc index 8a822b73..cdbc9271 100644 --- a/lam/lib/modules/shadowAccount.inc +++ b/lam/lib/modules/shadowAccount.inc @@ -163,8 +163,7 @@ class shadowAccount { } function delete_attributes($post) { - $return = array(); - return $return; + return 0; } /* Write variables into object and do some regexp checks diff --git a/lam/templates/delete.php b/lam/templates/delete.php index 4bb312af..6ecaf2f5 100644 --- a/lam/templates/delete.php +++ b/lam/templates/delete.php @@ -23,233 +23,225 @@ $Id$ LDAP Account Manager Delete user, hosts or groups */ -include_once('../lib/ldap.inc'); -include_once('../lib/account.inc'); -include_once('../lib/config.inc'); -// start session + +// include all needed files +include_once('../lib/account.inc'); // File with all account-funtions +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_start(); + // Redirect to startpage if user is not loged in if (!isset($_SESSION['loggedIn'])) { metaRefresh("login.php"); - die; + exit; } -// set language +// Set correct language, codepages, .... setlanguage(); -// use references because session-vars can change in future -$ldap_intern =& $_SESSION['ldap']; -$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; +if (!isset($_SESSION['cache'])) { + $_SESSION['cache'] = new cache(); } - -// Print header and part of body -echo $header_intern; -echo ''; -echo _('Delete Account'); -echo ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - '
'."\n"; - - if ($_GET['type']) { - // $_GET['type'] is true if delete.php was called from *list.php - // Store $_GET['type'] as $_POST['type'] - // Replace wrong chars from Session - echo ''; - switch ($_GET['type']) { - // Select which layout and text should be displayed - case 'user': - echo "
"; - echo _('Delete user(s)'); - echo "\n"; - echo ''._('Do you really want to delete user(s):').''; - break; - case 'host': - echo "
"; - echo _('Delete host(s)'); - echo "\n"; - echo ''._('Do you really want to delete host(s):').''; - break; - case 'group': - echo "
"; - echo _('Delete group(s)'); - echo "\n"; - echo ''._('Do you really want to delete group(s):').''; - break; + // Create account list + foreach ($_SESSION['delete_dn'] as $dn) { + $start = strpos ($dn, "=")+1; + $end = strpos ($dn, ","); + $users[] = substr($dn, $start, $end-$start); } + + //load account + $_SESSION['account'] = new accountContainer($_GET['type'], 'account'); + $_SESSION['account']->load_account($_SESSION['delete_dn'][0]); + // Show HTML Page + echo $_SESSION['header']; + echo ""; + echo _("Delete Account"); + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
"; + echo _('Please confirm:'); + echo "\n"; + echo "\n"; + echo sprintf(_("Do you really want to remove the following %ss?\n"), $_GET['type']); echo "
\n"; - // display all DNs in a tables - echo "\n"; - foreach ($delete_dn as $dn) echo ''; + echo "
'.$dn.'
\n\n"; + echo "\n"; + echo "\n"; + } echo "
"; + for ($i=0; $i\n"; + echo "" . sprintf(_('%sname:'), ucfirst($_GET['type'])) . " $users[$i]" . _('DN:') . " " . $_SESSION['delete_dn'][$i] . "
\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 "
\n"; - echo "\n"; - echo ''."\n".''."\n"; - echo "
'; - echo _('Delete also Homedirectories'); - echo ''. - '
\n"; + echo "
\n"; + // Print delete rows from modules + echo "\n
"; + $modules = array_keys($_SESSION['account']->module); + for ($i=0; $imodule[$modules[$i]]->display_html_delete($_POST); } - - // Print buttons - echo "
\n"; - echo ''; - echo "
'. - ''. - '
\n"; + echo "
\n"; + echo "
\n"; + echo "\n\n"; + echo "\n"; + echo "
"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; } +if ($_POST['cancel']) { + if (isset($_SESSION['delete_dn'])) unset($_SESSION['delete_dn']); + metaRefresh("lists/list" . $_POST['type'] . "s.php"); + } -if ($_POST['delete_yes']) { - // deletion has been confirmed. - switch ($_POST['type']) { - case 'user': - echo "
"; - echo _('Deleting user(s)...'); - echo "\n"; - break; - case 'host': - echo "
"; - echo _('Deleting host(s)...'); - echo "\n"; - break; - case 'group': - echo "
"; - echo _('Deleting group(s)...'); - echo "\n"; - break; - } - echo ''; - echo "
\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); +if ($_POST['delete']) { + // Show HTML Page + echo $_SESSION['header']; + echo ""; + echo _("Delete Account"); + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
"; + echo _('Deleting. Please stand by ...'); + echo "\n"; + + echo "
\n\n"; + echo "\n"; + echo "\n"; + foreach ($errors as $error) StatusMessage($error[0], $error[1], $error[2]); + } + else { + echo "\n"; + echo "\n"; + echo "\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 "\n"; - else echo "\n"; } - echo "
"; + // Delete dns + for ($m=0; $mload_account($_SESSION['delete_dn'][$m]); + // get commands and changes of each attribute + $module = array_keys ($_SESSION['account']->module); + $attributes = array(); + $errors = array(); + // load attributes + foreach ($module as $singlemodule) { + // load changes + $temp = $_SESSION['account']->module[$singlemodule]->delete_attributes($_POST); + if (is_array($temp)) { + // merge changes + $DNs = array_keys($temp); + // *** fixme don't include references + $attributes = array_merge_recursive($temp, $attributes); + for ($i=0; $iserver(), $dn); - if (!$success) $error = _('Could not delete user:').' '.$dn; - break; - case 'host': - // Delete host itself - $success = ldap_delete($ldap_intern->server(), $dn); - if (!$success) $error = _('Could not delete host:').' '.$dn; - 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; + } + } + $DNs = array_keys($attributes); + for ($i=0; $ildap]->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)) { - // Remove homedir if required - if ($_POST['f_rem_home']) remhomedir($usernames); - // Remove quotas if lamdaemon.pl is used - remquotas($usernames, 'user'); + 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 "
" . sprintf(_('Deleted DN: %s'), $_SESSION['delete_dn'][$m]) . "
" . sprintf(_('Error while deleting DN: %s'), $_SESSION['delete_dn'][$m]) . "
$dn ". _('deleted').".
$error

\n"; - switch ($_POST['type']) { - // Select which page should be displayd if back-button will be pressed - case 'user': - echo ''; - break; - case 'group': - echo ''; - break; - case 'host': - echo ''; - break; - } - echo "
\n"; + echo "\n"; + echo "
\n"; + echo "\n\n"; + echo "
"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } -if ($_POST['delete_no']) { - // Delete no accounts - echo ''; - switch ($_POST['type']) { - // Select which page should be displayd if back-button will be pressed - case 'user': - echo "
"; - echo _('Deleting user(s) canceled.'); - echo "\n"; - echo _('No user(s) were deleted'); - echo "
"; - echo ''; - break; - case 'host': - echo "
"; - echo _('Deleting host(s) canceled.'); - echo "\n"; - echo _('No host(s) were deleted'); - echo "
"; - echo ''; - break; - case 'group': - echo "
"; - echo _('Deleting group(s) canceled.'); - echo "\n"; - echo _('No group(s) were deleted'); - echo "
"; - echo ''; - break; - } - echo "
\n"; - } - -echo ''."\n"; ?> diff --git a/lam/templates/masscreate.php b/lam/templates/masscreate.php index 9b816ab2..3c2a6b2b 100644 --- a/lam/templates/masscreate.php +++ b/lam/templates/masscreate.php @@ -24,26 +24,39 @@ $Id$ */ // 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/ldap.inc'); // LDAP-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 -// 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_start(); // Redirect to startpage if user is not loged in if (!isset($_SESSION['loggedIn'])) { metaRefresh("login.php"); - die; + exit; } // Set correct language, codepages, .... setlanguage(); +if (!isset($_SESSION['cache'])) { + $_SESSION['cache'] = new cache(); + } + /* Save current time in $time. We need $time to check out how * long masscreate.php is running. To avoid max. execution time * set in php.ini masscreate.php will create a redirect to @@ -54,12 +67,17 @@ $time=time(); * from masscreate.php itself via meta refresh */ if (count($_POST)==0) { - // Go to page which shows all users - if (isset($_GET['list2'])) $select = 'list2'; - // (Continue) to create users - else if (isset($_GET['create'])) $select='create'; - // Display mainpage if nothing else should be displayed - else $select='main'; + // Register new account_container + $_SESSION['account'] = new accountContainer('user', 'account'); + // load profile + + // Find out list of attribtues which must be set put not allready covered by profile + + // Print first HTML-Page + echo $_SESSION['header']; + echo "" . _('Create new Accounts') . "\n"; + echo "\n"; + } else { /* Check loaded attributed in $_SESSION['accounts'] if file was loaded and