X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fadmin%2Fusers%2Fclass_userManagement.inc;h=a031e89d9f783a2cbb19272ea867938b1bde2c65;hb=47d9abbc98056723fcde3131a70713d6fd075d8d;hp=362245e0540052215c3597ab519e4cf16029eade;hpb=6a1f9891c4d90dcd283c4bfd3e75069103c736eb;p=gosa.git
diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc
index 362245e05..a031e89d9 100644
--- a/plugins/admin/users/class_userManagement.inc
+++ b/plugins/admin/users/class_userManagement.inc
@@ -18,10 +18,6 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* Include user tab class */
-require "tabs_user.inc";
-
-
class userManagement extends plugin
{
/* Plugin definitions */
@@ -31,18 +27,23 @@ class userManagement extends plugin
/* Dialog attributes */
var $usertab = NULL;
var $ui = NULL;
- var $acl = "";
var $templates = array();
var $got_uid = false;
var $CopyPasteHandler = NULL;
var $CPPasswordChange = ""; // Contains the entry id which should get a new password
var $DivListUsers;
- function userManagement($config, $ui)
+ var $pwd_change_queue = array();
+
+ var $start_pasting_copied_objects = FALSE;
+ var $current_action ="";
+ var $msg_dialog= NULL;
+
+ function userManagement(&$config, $ui)
{
/* Save configuration for internal use */
- $this->config= $config;
- $this->ui= $ui;
+ $this->config= &$config;
+ $this->ui= &$ui;
/* Copy & Paste handler */
if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
@@ -52,8 +53,6 @@ class userManagement extends plugin
/* Creat dialog object */
$this->DivListUsers = new divListUsers($this->config,$this);
- /* LOCK MESSAGE Vars */
- $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
}
@@ -62,6 +61,9 @@ class userManagement extends plugin
/* Call parent execute */
plugin::execute();
+ /* LOCK MESSAGE Vars */
+ $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/","/^multiple_edit/","/menu_action/");
+
$smarty = get_smarty(); // Smarty instance
$s_action = ""; // Contains the action to be taken
$s_entry = ""; // The value for s_action
@@ -76,12 +78,21 @@ class userManagement extends plugin
foreach($_POST as $key => $val){
/* Get every possible POST combination and set s_action/s_entry accordingly */
- foreach(array("del" => "user_del", "edit" => "user_edit",
+ foreach(array("del" => "user_del",
+ "edit" => "user_edit",
"new" => "user_new",
"new_tpl" => "user_tplnew",
+ "del_multiple" => "^remove_multiple_users",
+ "create_user_from_tpl" => "userfrom_tpl",
"change_pw" => "user_chgpw",
- "editPaste" => "editPaste", "copy" => "copy",
- "cut" => "cut") as $act => $name){
+ "editPaste" => "editPaste",
+ "copy_multiple" => "multiple_copy_users",
+ "multiple_edit" => "multiple_edit",
+ "cut_multiple" => "multiple_cut_users",
+ "multiple_password_change" => "multiple_password_change",
+ "copy" => "^copy",
+ "toggle_lock_status" => "toggle_lock_status",
+ "cut" => "^cut") as $act => $name){
if (preg_match("/".$name.".*/", $key)){
$s_action= $act;
@@ -103,98 +114,53 @@ class userManagement extends plugin
$s_tab= "user";
}
- /* Display the copy & paste dialog, if it is currently open */
- $ret = $this->copyPasteHandling($s_action,$s_entry);
- if($ret){
- return($ret);
+ if(!$this->config->search($s_tab, 'class',array('tabs'))){
+ $s_tab = "user";
}
- /********************
- Edit existing entry
- ********************/
-
- /* User wants to edit data? */
- if (($s_action=="edit") && (!isset($this->usertab->config))){
-
- /* Get 'dn' from posted 'uid', must be unique */
- $this->dn= $this->list[trim($s_entry)]['dn'];
-
- /* Check locking, save current plugin in 'back_plugin', so
- the dialog knows where to return. */
- if (($user= get_lock($this->dn)) != ""){
- return(gen_locked_message ($user, $this->dn));
- }
-
- /* Lock the current entry, so everyone will get the
- above dialog */
- add_lock ($this->dn, $this->ui->dn);
-
- /* Set up the users ACL's for this 'dn' */
- $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
-
- /* Register usertab to trigger edit dialog */
- $this->usertab= new usertabs($this->config,
- $this->config->data['TABS']['USERTABS'], $this->dn);
-
- /* Switch tab, if it was requested by the user */
- $this->usertab->current = $s_tab;
-
- /* Set ACL and move DN to the headline */
- $this->usertab->set_acl($acl);
- $_SESSION['objectinfo']= $this->dn;
+ /* handle C&P from layers menu */
+ if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
+ $s_action = "copy_multiple";
+ }
+ if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
+ $s_action = "cut_multiple";
+ }
+ if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
+ $s_action = "editPaste";
}
+ /* Create options */
+ if(isset($_POST['menu_action']) && $_POST['menu_action'] == "user_new"){
+ $s_action = "new";
+ }
+ if(isset($_POST['menu_action']) && $_POST['menu_action'] == "user_tplnew"){
+ $s_action = "new_tpl";
+ }
+ if(isset($_POST['menu_action']) && $_POST['menu_action'] == "multiple_edit"){
+ $s_action = "multiple_edit";
+ }
- /********************
- Edit canceled
- ********************/
+ /* handle remove from layers menu */
+ if(isset($_POST['menu_action']) && preg_match("/^multiple_password_change/",$_POST['menu_action'])){
+ $s_action = "multiple_password_change";
+ }
- /* Reset all relevant data, if we get a _cancel request */
- if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
- if (isset($this->usertab)){
- del_lock ($this->usertab->dn);
- unset ($this->usertab);
- }
- $this->usertab= NULL;
- $this->lognames= array();;
- $this->sn= "";
- $this->givenName= "";
- $this->uid= "";
- unset ($_SESSION['objectinfo']);
+ /* handle remove from layers menu */
+ if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
+ $s_action = "del_multiple";
}
/********************
- Change password requested
+ Copy & Paste
********************/
- /* Password change requested */
- if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
-
- if(!empty($this->CPPasswordChange)){
- $s_entry = $this->CPPasswordChange;
- $this->CPPasswordChange = "";
- }
-
- /* Get 'dn' from posted 'uid' */
- $this->dn= $this->list[trim($s_entry)]['dn'];
-
- /* Load permissions for selected 'dn' and check if
- we're allowed to remove this 'dn' */
- $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
- $acl= get_module_permission($acl, "user", $this->dn);
- if (chkacl($acl, "password") == ""){
-
- /* User is allowed to change passwords, save 'dn' and 'acl' for next
- dialog. */
- $this->acl= $acl;
- $_SESSION['objectinfo']= $this->dn;
- return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
-
- } else {
- /* User is not allowed. Show message and cancel. */
- print_red (_("You are not allowed to set this users password!"));
+ /* Display the copy & paste dialog, if it is currently open */
+ if($this->CPPasswordChange == ""){
+ $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
+ if($ret){
+ return($ret);
}
}
@@ -207,7 +173,11 @@ class userManagement extends plugin
if (isset($_POST['password_finish'])){
/* For security reasons, check if user is allowed to set password again */
- if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
+ $dn = $this->dn;
+ $acl = $this->ui->get_permissions($dn, "users/password");
+ $cacl= $this->ui->get_permissions($dn, "users/user");
+
+ if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
/* Check input and feed errors into 'message' */
$message= array();
@@ -254,8 +224,7 @@ class userManagement extends plugin
if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
}
-
- gosa_log ("Password for '".$this->usertab->dn."' has been changed");
+ new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
unset($this->usertab);
$this->usertab= NULL;
}
@@ -264,15 +233,13 @@ class userManagement extends plugin
if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
}
-
- gosa_log ("Password for '".$this->dn."' has been changed");
+ new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
}
} else {
/* Missing permissions, show message */
- print_red (_("You are not allowed to set this users password!"));
+ msg_dialog::display(_("Password change failed."),_("You are not allowed to set this users password!"),WARNING_DIALOG);
}
-
/* Clean session, delete lock */
del_lock ($this->dn);
unset ($this->usertab);
@@ -286,37 +253,278 @@ class userManagement extends plugin
/********************
- Delete entry requested, display confirm dialog
+ Change multiple passwords requested
********************/
+
+ if($s_action == "multiple_password_change"){
+ $this->pwd_change_queue = $this->list_get_selected_items();
+ }
- /* Remove user was requested */
- if ($s_action=="del"){
+
+ /********************
+ Change password requested
+ ********************/
+
+ /* Password change requested */
+ if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
+
+ /* Get users whose passwords should be changed. */
+ if(count($this->pwd_change_queue)){
+ $s_entry= array_pop($this->pwd_change_queue);
+ }
+
+ if(!empty($this->CPPasswordChange)){
+ $s_entry = $this->CPPasswordChange;
+ $this->CPPasswordChange = "";
+ }
/* Get 'dn' from posted 'uid' */
$this->dn= $this->list[trim($s_entry)]['dn'];
/* Load permissions for selected 'dn' and check if
we're allowed to remove this 'dn' */
- $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
- $this->acl= get_module_permission($acl, "user", $this->dn);
- if (chkacl($this->acl, "delete") == ""){
-
- /* Check locking, save current plugin in 'back_plugin', so
- the dialog knows where to return. */
- if (($user= get_lock($this->dn)) != ""){
- return(gen_locked_message ($user, $this->dn));
+ if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
+
+ /* User is allowed to change passwords, save 'dn' and 'acl' for next
+ dialog. */
+ $_SESSION['objectinfo']= $this->dn;
+ return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
+
+
+ } else {
+ /* User is not allowed. Show message and cancel. */
+ msg_dialog::display(_("Password change"),_("You are not allowed to set this users password!"),WARNING_DIALOG);
+ }
+ }
+
+
+
+ /********************
+ Edit existing entry
+ ********************/
+
+ /* User wants to edit data? */
+ if (($s_action=="edit") && (!isset($this->usertab->config))){
+
+ /* Get 'dn' from posted 'uid', must be unique */
+ $this->dn= $this->list[trim($s_entry)]['dn'];
+
+ /* Check locking, save current plugin in 'back_plugin', so
+ the dialog knows where to return. */
+ if (($user= get_lock($this->dn)) != ""){
+ return(gen_locked_message ($user, $this->dn));
+ }
+
+ /* Lock the current entry, so everyone will get the
+ above dialog */
+ add_lock ($this->dn, $this->ui->dn);
+
+ /* Register usertab to trigger edit dialog */
+ $this->usertab= new usertabs($this->config,
+ $this->config->data['TABS']['USERTABS'], $this->dn);
+
+ /* Switch tab, if it was requested by the user */
+ $this->usertab->current = $s_tab;
+
+ /* Set ACL and move DN to the headline */
+ $this->usertab->set_acl_base($this->dn);
+ $_SESSION['objectinfo']= $this->dn;
+ }
+
+
+ /********************
+ Edit multiple entries
+ ********************/
+
+ /* User wants to edit data? */
+ if ($s_action == "multiple_edit" && !isset($this->usertab->config)){
+
+ $this->dn = array();
+ foreach($this->list_get_selected_items() as $id){
+ $this->dn[] = $this->list[$id]['dn'];;
+ }
+ $tmp = new multi_plug($this->config,"usertabs",$this->config->data['TABS']['USERTABS'],
+ $this->dn,$this->DivListUsers->selectedBase,"user");
+ if ($tmp->entries_locked()){
+ return($tmp->display_lock_message());
+ }
+ $tmp->lock_entries($this->ui->dn);
+ if($tmp->multiple_available()){
+ $this->usertab = $tmp;
+ $this->usertab->set_active_tab($s_tab);
+ $_SESSION['objectinfo']= $this->usertab->get_object_info();
+ }
+ }
+
+
+ /********************
+ Edit canceled
+ ********************/
+
+ /* Reset all relevant data, if we get a _cancel request */
+ if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
+ if (isset($this->usertab)){
+ del_lock ($this->usertab->dn);
+ unset ($this->usertab);
+ }
+ $this->usertab= NULL;
+ $this->lognames= array();;
+ $this->sn= "";
+ $this->givenName= "";
+ $this->uid= "";
+ unset ($_SESSION['objectinfo']);
+ }
+
+
+ /********************
+ Delete MULTIPLE entries requested, display confirm dialog
+ ********************/
+
+ if ($s_action=="del_multiple"){
+ $ids = $this->list_get_selected_items();
+ $this->dns = array();
+ if(count($ids)){
+
+ foreach($ids as $id){
+ $dn = $this->list[$id]['dn'];
+ if (($user= get_lock($dn)) != ""){
+ return(gen_locked_message ($user, $dn));
+ }
+ $this->dns[$id] = $dn;
+ }
+
+ $dns_names = "
"; + foreach($this->dns as $dn){ + $dns_names .= $dn."\n"; } + $dns_names .=""; /* Lock the current entry, so nobody will edit it during deletion */ - add_lock ($this->dn, $this->ui->dn); - $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn))); - return($smarty->fetch(get_template_path('remove.tpl', TRUE))); - } else { + if (count($this->dns) == 1){ + $info = sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)); + } else { + $info = sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)); + } + $this->msg_dialog = new msg_dialog(_("Delete users"),$info,CONFIRM_DIALOG); + $this->current_action = $s_action; + } + } + + + /******************** + Delete MULTIPLE entries confirmed + ********************/ + + /* Confirmation for deletion has been passed. Users should be deleted. */ + if ($this->current_action == "del_multiple" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){ + + $this->current_action = ""; + + /* Remove user by user and check acls before removeing them */ + foreach($this->dns as $key => $dn){ + + $acl = $this->ui->get_permissions($dn, "users/user"); + if (preg_match('/d/', $acl)){ + + /* Delete request is permitted, perform LDAP action */ + $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn); + $this->usertab->set_acl_base(); + $this->usertab->delete (); + unset ($this->usertab); + $this->usertab= NULL; + } else { + msg_dialog::display(_("User delete"),sprintf(_("You are not allowed to delete the user '%s'!"),$dn),WARNING_DIALOG); + if(isset($this->ui->uid)){ + new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion."); + } + } + /* Remove lock file after successfull deletion */ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /******************** + Delete MULTIPLE entries Canceled + ********************/ + + /* Remove lock */ + if(isset($_POST['delete_multiple_user_cancel'])){ + foreach($this->dns as $key => $dn){ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /******************** + Toggle lock status for user + ********************/ + + if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){ + + /* Get entry check current status */ + $val = $this->list[$s_entry]; + $pwd = $val['userPassword'][0]; + + if(!preg_match("/^\{[^\}]/",$pwd)){ + trigger_error("Can not deactivate user which is using clear password encryption."); + }else{ + + $locked = false; + if(preg_match("/^[^\}]*+\}!/",$pwd)){ + $locked = true; + } + + /* Create ldap array to update status */ + $attrs = array("userPassword" => $pwd); + if($locked){ + $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']); + }else{ + $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']); + } + + /* Write new status back to ldap */ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($val['dn']); + $ldap->modify($attrs); + if($locked){ + show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked.")); + }else{ + show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked.")); + } + } + } + + + /******************** + Delete entry requested, display confirm dialog + ********************/ + + /* Remove user was requested */ + if ($s_action=="del"){ + + /* Get 'dn' from posted 'uid' */ + $this->dn= $this->list[trim($s_entry)]['dn']; + + /* Load permissions for selected 'dn' and check if + we're allowed to remove this 'dn' */ - /* Obviously the user isn't allowed to delete. Show message and - clean session. */ - print_red (_("You are not allowed to delete this user!")); + /* Check locking, save current plugin in 'back_plugin', so + the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return(gen_locked_message ($user, $this->dn)); } + + + /* Lock the current entry, so nobody will edit it during deletion */ +# add_lock ($this->dn, $this->ui->dn); +# $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn))); +# $smarty->assign("multiple", false); +# return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + $this->msg_dialog = new msg_dialog( _("Delete user"),sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)),CONFIRM_DIALOG); + $this->current_action = $s_action; } @@ -325,27 +533,32 @@ class userManagement extends plugin ********************/ /* Confirmation for deletion has been passed. User should be deleted. */ - if (isset($_POST['delete_user_confirm'])){ + if ($this->current_action == "del" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){ + $this->current_action = ""; + /* Some nice guy may send this as POST, so we've to check for the permissions again. */ - if (chkacl($this->acl, "delete") == ""){ + + $acl = $this->ui->get_permissions($this->dn, "users/user"); + + if (preg_match('/d/', $acl)){ /* Delete request is permitted, perform LDAP action */ $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn); - $this->usertab->set_acl(array($this->acl)); + $this->usertab->set_acl_base(); $this->usertab->delete (); - gosa_log ("User object '".$this->dn."' has been removed"); unset ($this->usertab); $this->usertab= NULL; + msg_dialog::display(_("User delted"),_("User successfully removed."),INFO_DIALOG); } else { /* Normally this shouldn't be reached, send some extra logs to notify the administrator */ - print_red (_("You are not allowed to delete this user!")); + msg_dialog::display(_("User delete"),_("You are not allowed to delete this user!"),WARNING_DIALOG); if(isset($this->ui->uid)){ - gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion."); + new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion."); } } @@ -392,10 +605,8 @@ class userManagement extends plugin /* Save user data to ldap */ if($this->usertab->save() == 1){ - gosa_log ("User object '".$this->dn."' saving failed."); return; } - gosa_log ("User object '".$this->dn."' has been saved"); if (!isset($_POST['edit_apply'])){ /* User has been saved successfully, remove lock from LDAP. */ @@ -405,6 +616,7 @@ class userManagement extends plugin /* In case of new users, ask for a password, skip this for templates */ if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){ + $this->dn = $this->usertab->dn; return($smarty->fetch(get_template_path('password.tpl', TRUE))); } @@ -434,11 +646,10 @@ class userManagement extends plugin foreach ($this->config->departments as $key => $value){ /* Get acls from different ou's */ - $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL); - $acl= get_module_permission($acl, "user", get_people_ou().$value); - + $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ; + /* If creation of a new user is allowed, append this template */ - if (chkacl($acl, "create") == ""){ + if (preg_match("/c/",$acl)){ /* Search all templates from the current dn */ $ldap->cd (get_people_ou().$value); @@ -465,11 +676,44 @@ class userManagement extends plugin Create a new user,template, user from template ********************/ + /* Check selected options for template */ + if (isset($_POST['template_continue'])){ + $message = array(); + if(!isset($_POST['template']) || (empty($_POST['template']))){ + $message[] = _("Please select a valid template."); + } + if(!isset($_POST['sn']) || (empty($_POST['sn']))){ + $message[]= _("The required field 'Name' is not set."); + } + if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){ + $message[]= _("The required field 'Given name' is not set."); + } + + /* Show error message / continue editing */ + if (count($message) > 0){ + show_errors ($message); + + foreach(array("sn", "givenName", "uid", "template") as $attr){ + if(isset($_POST[$attr])){ + $smarty->assign("$attr", $_POST[$attr]); + }else{ + $smarty->assign("$attr", ""); + } + } + $smarty->assign("templates",$this->templates); + $smarty->assign("got_uid",$this->got_uid); + $smarty->assign("edit_uid",false); + return($smarty->fetch(get_template_path('template.tpl', TRUE))); + + } + } + /* New user/template request */ if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){ /* By default we set 'dn' to 'new', all relevant plugins will react on this. */ $this->dn= "new"; + if (isset($this->config->current['IDGEN'])){ $this->got_uid= false; } else { @@ -478,8 +722,8 @@ class userManagement extends plugin /* Create new usertab object */ $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn); - $this->usertab->set_acl(array(':all')); $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase; + $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase); /* Take care about templates */ if ($s_action=="new_tpl"){ @@ -509,7 +753,8 @@ class userManagement extends plugin ********************/ /* Continue template editing */ - if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){ + if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){ + $this->sn = $_POST['sn']; $this->givenName = $_POST['givenName']; @@ -560,7 +805,6 @@ class userManagement extends plugin return($smarty->fetch(get_template_path('template.tpl', TRUE))); } - /******************** No template selected continue edit ********************/ @@ -595,10 +839,6 @@ class userManagement extends plugin $this->usertab->adapt_from_template($template_dn); $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn); $this->usertab->by_object['user']->base= $template_base; - - /* Set up the users ACL's for this 'dn' */ - $acl= get_permissions ($template_base, $this->ui->subtreeACL); - $this->usertab->set_acl($acl); } @@ -620,20 +860,32 @@ class userManagement extends plugin $display= $this->usertab->execute(); /* Don't show buttons if tab dialog requests this */ - if (!$this->usertab->by_object[$this->usertab->current]->dialog){ - $display.= "
\n"; - $display.= "\n"; - $display.= " \n"; - if ($this->dn != "new"){ - $display.= "\n"; + + $dia = FALSE; + if(isset($this->usertab->by_object[$this->usertab->current]->dialog)){ + $dia = $this->usertab->by_object[$this->usertab->current]->dialog; + } + + if(!is_object($dia) && $dia != TRUE){ + $display.= "
\n"; + $display.= "\n"; $display.= " \n"; + if ($this->dn != "new"){ + $display.= "\n"; + $display.= " \n"; + } + $display.= "\n"; + $display.= "
"; } - $display.= "\n"; - $display.= ""; - } return ($display); } - + + /* Check if there is a snapshot dialog open */ + $base = $this->DivListUsers->selectedBase; + if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){ + return($str); + } + /* Return rendered main page */ /* Display dialog with system list */ $this->DivListUsers->parent = $this; @@ -641,7 +893,7 @@ class userManagement extends plugin /* Add departments if subsearch is disabled */ if(!$this->DivListUsers->SubSearch){ - $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4); + $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1); } $this->reload(); $this->DivListUsers->setEntries($this->list); @@ -649,6 +901,13 @@ class userManagement extends plugin } + /* Return departments, that will be included within snapshot detection */ + function get_used_snapshot_bases() + { + return(array(get_people_ou().$this->DivListUsers->selectedBase)); + } + + function reload() { /* Set base for all searches */ @@ -701,26 +960,35 @@ class userManagement extends plugin $ldap= $this->config->get_ldap_link(TRUE); if ($SubSearch){ - $ListTemp = get_list($filter, $this->ui->subtreeACL, $base, - array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT); + $ListTemp = get_list($filter, "users", $base, + array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT); } else { $base= get_people_ou().$base; - $ListTemp = get_list($filter, $this->ui->subtreeACL, $base, - array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT); + $ListTemp = get_list($filter, "users", $base, + array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT); } $SortTemp = array(); $List = array(); foreach($ListTemp as $Key => $Entry){ - // Generate caption for rows - if (isset($Entry["sn"]) && isset($Entry["givenName"])){ - $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]"; - } else { - $display= "[".$Entry["uid"][0]."]"; - } - $display = strtolower($display); - $List[$display] = $Entry; - $SortTemp[$display] = $display; + /* Skip entries that are not located under the people ou (normaly 'ou=people,') + * Else winstations will be listed too, if you use the subtree flag. + */ + if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){ + continue; + }else{ + + // Generate caption for rows + if (isset($Entry["sn"]) && isset($Entry["givenName"])){ + $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]"; + } else { + $display= "[".$Entry["uid"][0]."]"; + } + + $display = strtolower($display); + $List[$display] = $Entry; + $SortTemp[$display] = $display; + } } sort($SortTemp); reset($SortTemp); @@ -739,76 +1007,103 @@ class userManagement extends plugin } } - - /* Perform copy & paste requests - If copy&paste is in progress this returns a dialog to fix required attributes - */ - function copyPasteHandling($s_action,$s_entry) + + function copyPasteHandling_from_queue($s_action,$s_entry) { - /* Only perform copy/paste if it is enabled */ - if($this->CopyPasteHandler){ + /* Check if Copy & Paste is disabled */ + if(!is_object($this->CopyPasteHandler)){ + return(""); + } - /* Prepare current object to be pasted */ - if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){ + /* Add a single entry to queue */ + if($s_action == "cut" || $s_action == "copy"){ + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); + $dn = $this->list[$s_entry]['dn']; + $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users"); + } - $this->CopyPasteHandler->save_object(); - $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase); + /* Add entries to queue */ + if($s_action == "copy_multiple" || $s_action == "cut_multiple"){ - /* Execute copy & paste dialog and display returned data, normaly a dialog which allows - us to solve all attribute mismatches for this object. - If nothing is returned, copy & paste was succesfully or aborted */ - if(($ret= $this->CopyPasteHandler->execute())){ - return ($ret); - } + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); - /* Use the last dn to search for it's ID in the newly generated list. */ - $dn= $this->CopyPasteHandler->lastdn; - foreach($this->list as $id => $entry){ - if($entry['dn'] == $dn){ - $s_entry= $id; - break; - } + /* Add new entries to CP queue */ + foreach($this->list_get_selected_items() as $id){ + $dn = $this->list[$id]['dn']; + + if($s_action == "copy_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users"); } - - /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */ - if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){ - $this->CPPasswordChange = $s_entry; + if($s_action == "cut_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users"); } } + } + + /* Start pasting entries */ + if($s_action == "editPaste"){ + $this->start_pasting_copied_objects = TRUE; + } - /* Copy selected object - Create a new empty object and the current selected object. - Send both to copy&paste class*/ - if($s_action == "copy"){ - $this->CopyPasteHandler->Clear(); - $dn= $this->list[trim($s_entry)]['dn']; - $acl= get_permissions ($dn, $this->ui->subtreeACL); - $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn); - $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new"); - $obj-> set_acl($acl); - $objNew-> set_acl($acl); - $this->CopyPasteHandler->Copy($obj,$objNew); + /* Return C&P dialog */ + if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){ + + /* Load entry from queue and set base */ + $this->CopyPasteHandler->load_entry_from_queue(); + $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase); + + /* Get dialog */ + $data = $this->CopyPasteHandler->execute(); + + /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */ + if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){ + $s_entry = $this->CopyPasteHandler->last_entry(); + $this->reload(); + foreach($this->list as $key => $entry){ + if($entry['dn'] == $s_entry){ + $this->CPPasswordChange = $key; + } + } } - /* Cut selected object. - Open user object and send it to the copy & paste handler */ - if($s_action == "cut"){ - $this->CopyPasteHandler->Clear(); - $dn= $this->list[trim($s_entry)]['dn']; - $acl= get_permissions ($dn, $this->ui->subtreeACL); - $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn); - $obj->set_acl($acl); - $this->CopyPasteHandler->Cut($obj); + /* Return dialog data */ + if(!empty($data) && $this->CPPasswordChange == ""){ + return($data); } } + + /* Automatically disable status for pasting */ + if(!$this->CopyPasteHandler->entries_queued()){ + $this->start_pasting_copied_objects = FALSE; + } + return(""); } + function save_object() { /* Handle divlist filter && department selection*/ - $this->DivListUsers->save_object(); + if(!is_object($this->usertab)){ + $this->DivListUsers->save_object(); + } } + + function list_get_selected_items() + { + $ids = array(); + foreach($_POST as $name => $value){ + if(preg_match("/^item_selected_[0-9]*$/",$name)){ + $id = preg_replace("/^item_selected_/","",$name); + $ids[$id] = $id; + } + } + return($ids); + } + + /* A set of disabled and therefore overloaded functions. They are not needed in this class. */ function remove_from_parent() { } @@ -816,7 +1111,6 @@ class userManagement extends plugin function save() { } function adapt_from_template($dn) { } function password_change_needed() { } - function show_header($button_text, $text, $disabled= FALSE) { } } /* ... class userManagement */ // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: