X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fadmin%2Fusers%2Fclass_userManagement.inc;h=b1c2c1b2b519ec1cef8151cc422d19733a23ea76;hb=32e8775e7e268170aafa198c43191c495a85156d;hp=98f434fce14a6cd30426c90673c12a859904e655;hpb=4593861bc36a58f609bd02f5de5f14e2a1daf75d;p=gosa.git diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc index 98f434fce..b1c2c1b2b 100644 --- a/plugins/admin/users/class_userManagement.inc +++ b/plugins/admin/users/class_userManagement.inc @@ -1,7 +1,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,182 +17,164 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* Include user tab class */ require "tabs_user.inc"; + class userManagement extends plugin { - /* Definitions */ + /* Plugin definitions */ var $plHeadline= "Users"; var $plDescription= "This does something"; /* Dialog attributes */ - var $usertab= NULL; - var $userlist= array(); - var $ui= NULL; - var $acl= ""; - var $templates= array(); - var $got_uid= false; - var $departments=array(); - - function userManagement ($config, $ui) + 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) { /* Save configuration for internal use */ $this->config= $config; $this->ui= $ui; - /* Get global filter config */ - if (!isset($_SESSION["userfilter"])){ - $base= get_base_from_people($ui->dn); - $userfilter= array( "mailusers" => "checked", - "unixusers" => "checked", - "templates" => "", - "subsearch" => "", - "proxyusers" => "checked", - "sambausers" => "checked", - "faxusers" => "checked", - "functionalusers" => "checked", - "depselect" => $base, - "regex" => "*"); - $_SESSION["userfilter"] = $userfilter; + /* Copy & Paste handler */ + if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){ + $this->CopyPasteHandler= new CopyPasteHandler($this->config); } + + /* Creat dialog object */ + $this->DivListUsers = new divListUsers($this->config,$this); + } + function execute() { - $smarty = get_smarty(); // Smarty instance - $userfilter = get_global("userfilter"); // contains Filter Settings - $s_action = ""; // Contains the action to proceed - $s_entry = ""; // The value for s_action - $base_back = ""; // The Link for Backbutton + /* Call parent execute */ + plugin::execute(); + + /* LOCK MESSAGE Vars */ + $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/"); - /* Start for New List Managment */ - if(isset($_GET['act'])&&($_GET['act']=="dep_open")){ - $s_action="open"; - $s_entry = base64_decode($_GET['dep_id']); - $userfilter['depselect']= "".$this->config->departments[trim($s_entry)]; + $smarty = get_smarty(); // Smarty instance + $s_action = ""; // Contains the action to be taken + $s_entry = ""; // The value for s_action + + /* Edit entry button pressed? */ + if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){ + $s_action= "edit"; + $s_entry= validate($_GET['id']); } - /* Test Posts */ + /* Test relevant POST values */ foreach($_POST as $key => $val){ - // Post for delete - if(preg_match("/user_del.*/",$key)){ - $s_action = "del"; - $s_entry = preg_replace("/user_".$s_action."_/i","",$key); - // Post for edit - }elseif(preg_match("/user_edit_.*/",$key)){ - $s_action="edit"; - $s_entry = preg_replace("/user_".$s_action."_/i","",$key); - // Post for new - }elseif(preg_match("/dep_back.*/i",$key)){ - $s_action="back"; - }elseif(preg_match("/user_new.*/",$key)){ - $s_action="new"; - }elseif(preg_match("/dep_home.*/i",$key)){ - $s_action="home"; - }elseif(preg_match("/user_tplnew.*/i",$key)){ - $s_action="new_tpl"; - }elseif(preg_match("/user_chgpw.*/i",$key)){ - $s_action="change_pw"; - $s_entry = preg_replace("/user_chgpw_/i","",$key); - }elseif(preg_match("/dep_root.*/i",$key)){ - $s_action="root"; - } - } - - if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){ - $s_action ="edit"; - $s_entry = $_GET['id']; - } - $s_entry = preg_replace("/_.$/","",$s_entry); + /* Get every possible POST combination and set s_action/s_entry accordingly */ + foreach(array("del" => "user_del", "edit" => "user_edit", + "new" => "user_new", + "new_tpl" => "user_tplnew", + "create_user_from_tpl" => "userfrom_tpl", + "change_pw" => "user_chgpw", + "editPaste" => "editPaste", "copy" => "copy", + "cut" => "cut") as $act => $name){ + + if (preg_match("/".$name.".*/", $key)){ + $s_action= $act; + $s_entry= preg_replace("/".$name."_/i", "", $key); + break; + } + } + + } /* ...Test POST */ - /* Department changed? */ - if(isset($_POST['depselect']) && $_POST['depselect']){ - $userfilter['depselect']= $_POST['depselect']; - } + /* Remove coordinate prefix from POST, required by some browsers */ + $s_entry= preg_replace("/_.$/", "", $s_entry); - /* Homebutton is posted */ - if($s_action=="home"){ - $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn)); - $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect'])); + /* Seperate possibly encoded tab and entry, default to tab "user" */ + if(preg_match("/.*-.*/", $s_entry)){ + $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry); + $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry); + }else{ + $s_tab= "user"; } - if($s_action=="root"){ - $userfilter['depselect']=($this->config->current['BASE']); + /* Some may be active but diabled in gosa.conf. */ + if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){ + $s_tab = "user"; } + /* Get 'dn' from posted 'uid' */ + if(in_array_ics($s_action,array("editPaste","cut","copy"))){ - /* If Backbutton is Posted */ - if($s_action=="back"){ - $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']); - $base_back = convert_department_dn($base_back); - - if(isset($this->config->departments[trim($base_back)])){ - $userfilter['depselect']= $this->config->departments[trim($base_back)]; + if(isset($this->list[trim($s_entry)]['dn'])){ + $dn= $this->list[trim($s_entry)]['dn']; }else{ - $userfilter['depselect']= $this->config->departments["/"]; + $dn = $this->DivListUsers->selectedBase; } - } - /* End for new List Managment */ - /* Save filter data if we are in the headpage */ - if (!isset($this->usertab)){ - if (isset($_POST['regexit'])){ - $userfilter["regex"]= $_POST['regexit']; - } - } - if(isset($_POST['regexit'])){ - foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){ - if (isset($_POST[$type])) { - $userfilter[$type]= "checked"; - } else { - $userfilter[$type]= ""; + $acl= get_permissions ($dn, $this->ui->subtreeACL); + $acl= get_module_permission($acl, "user", $dn); + + if($acl != "#all#"){ + print_red (_("You are not allowed to execute this method!")); + }else{ + /* Display the copy & paste dialog, if it is currently open */ + $ret = $this->copyPasteHandling($s_action,$s_entry); + if($ret){ + return($ret); } } } - if (isset($_GET['search'])){ - $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*"; - if ($s == "**"){ - $s= "*"; - } - $userfilter['regex']= $s; - } - register_global("userfilter", $userfilter); - + - /* React on user interaction here */ - if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){ + /******************** + Edit existing entry + ********************/ - /* User wants to edit data? */ - if ($s_action=="edit"){ + /* 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']; + /* 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)); - } + /* 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); + /* 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); + /* 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); - $this->usertab->set_acl($acl); + /* Register usertab to trigger edit dialog */ + $this->usertab= new usertabs($this->config, + $this->config->data['TABS']['USERTABS'], $this->dn); - $_SESSION['objectinfo']= $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; } - /* Reset requested? */ + + /******************** + 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); @@ -206,8 +188,18 @@ class userManagement extends plugin unset ($_SESSION['objectinfo']); } + + /******************** + Change password requested + ********************/ + /* Password change requested */ - if ($s_action=="change_pw"){ + 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']; @@ -230,6 +222,11 @@ class userManagement extends plugin } } + + /******************** + Change password confirmed + ********************/ + /* Perform password change */ if (isset($_POST['password_finish'])){ @@ -252,7 +249,7 @@ class userManagement extends plugin } } - /* Errors, or change password? */ + /* Errors, or password change? */ if (count($message) != 0){ /* Show error message and continue editing */ @@ -260,18 +257,38 @@ class userManagement extends plugin return($smarty->fetch(get_template_path('password.tpl', TRUE))); } + $config= $this->config; + $ldap_ui= $this->config->get_ldap_link(); + if(isset($this->usertab->dn)){ + $ldap_ui->cat($this->usertab->dn,array("uid")); + $user = $ldap_ui->fetch(); + }else{ + $ldap_ui->cat($this->dn,array("uid")); + $user = $ldap_ui->fetch(); + } + if((is_array($user))&&(isset($user['uid']))){ + $username= $user['uid'][0]; + } + /* Set password, perform required steps */ if ($this->usertab){ if ($this->usertab->password_change_needed()){ $obj= $this->usertab->by_object['user']; - change_password ($this->usertab->dn, $_POST['new_password'], - 0, $obj->pw_storage); + change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage); + 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"); unset($this->usertab); $this->usertab= NULL; } } else { change_password ($this->dn, $_POST['new_password']); + 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"); } } else { @@ -282,7 +299,6 @@ class userManagement extends plugin /* Clean session, delete lock */ del_lock ($this->dn); - $this->reload(); unset ($this->usertab); $this->usertab= NULL; $this->lognames= array();; @@ -293,6 +309,10 @@ class userManagement extends plugin } + /******************** + Delete entry requested, display confirm dialog + ********************/ + /* Remove user was requested */ if ($s_action=="del"){ @@ -313,7 +333,7 @@ class userManagement extends plugin /* 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."), $this->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 { @@ -324,6 +344,9 @@ class userManagement extends plugin } + /******************** + Delete entry confirmed + ********************/ /* Confirmation for deletion has been passed. User should be deleted. */ if (isset($_POST['delete_user_confirm'])){ @@ -333,16 +356,12 @@ class userManagement extends plugin if (chkacl($this->acl, "delete") == ""){ /* Delete request is permitted, perform LDAP action */ - $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], - $this->dn); + $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn); $this->usertab->set_acl(array($this->acl)); $this->usertab->delete (); gosa_log ("User object '".$this->dn."' has been removed"); unset ($this->usertab); $this->usertab= NULL; - - /* User list has changed, reload it. */ - $this->reload (); } else { /* Normally this shouldn't be reached, send some extra @@ -358,6 +377,10 @@ class userManagement extends plugin del_lock ($this->dn); } + + /******************** + Delete entry Canceled + ********************/ /* Delete user canceled? */ if (isset($_POST['delete_cancel'])){ @@ -365,10 +388,14 @@ class userManagement extends plugin } + /******************** + Edit entry finished (Save) + ********************/ + /* Finish user edit is triggered by the tabulator dialog, so the user wants to save edited data. Check and save at this point. */ - if (isset($_POST['edit_finish'])){ + if ((isset($_POST['edit_finish'])) && (isset($this->usertab->config))){ /* Check tabs, will feed message array */ $this->usertab->last= $this->usertab->current; @@ -394,26 +421,19 @@ class userManagement extends plugin } gosa_log ("User object '".$this->dn."' has been saved"); - /* User has been saved successfully, remove lock from - LDAP. */ + /* User has been saved successfully, remove lock from LDAP. */ if ($this->dn != "new"){ del_lock ($this->dn); } - /* In case of new users, ask for a password */ - if (($set_pass || $this->usertab->password_change_needed()) && - !$this->is_template){ - + /* In case of new users, ask for a password, skip this for templates */ + if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){ return($smarty->fetch(get_template_path('password.tpl', TRUE))); } - /* There's no page reload so we have to read new users at - this point. */ - $this->reload (); unset ($this->usertab); $this->usertab= NULL; unset ($_SESSION['objectinfo']); - } else { /* Ok. There seem to be errors regarding to the tab data, show message and continue as usual. */ @@ -421,32 +441,54 @@ class userManagement extends plugin } } + + /******************** + We want to create a new user, so fetch all available user templates + ********************/ + /* Generate template list */ - if ($s_action=="new"){ + if (($s_action=="new")||($s_action=="create_user_from_tpl")){ + $this->templates= array(); $ldap= $this->config->get_ldap_link(); + + /* Create list of templates */ 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); + + /* If creation of a new user is allowed, append this template */ if (chkacl($acl, "create") == ""){ + + /* Search all templates from the current dn */ $ldap->cd (get_people_ou().$value); $ldap->search ("(objectClass=gosaUserTemplate)", array("uid")); + /* Append */ if ($ldap->count() != 0){ while ($attrs= $ldap->fetch()){ $this->templates[$ldap->getDN()]= - $attrs['uid'][0]." - $key"; + $attrs['uid'][0]." - ".@LDAP::fix($key); } $this->templates['none']= _("none"); } } } + + /* Sort templates */ natcasesort ($this->templates); reset ($this->templates); } + + /******************** + Create a new user,template, user from template + ********************/ + /* New user/template request */ - if (($s_action=="new") || ($s_action=="new_tpl")){ + 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"; @@ -457,9 +499,9 @@ class userManagement extends plugin } /* Create new usertab object */ - $this->usertab= new usertabs($this->config, - $this->config->data['TABS']['USERTABS'], $this->dn); + $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; /* Take care about templates */ if ($s_action=="new_tpl"){ @@ -468,26 +510,30 @@ class userManagement extends plugin } else { $this->is_template= FALSE; } - + /* Use template if there are any of them */ - if (count($this->templates) && !isset($_POST['new_template'])){ + if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){ foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){ $smarty->assign("$attr", $this->$attr); } - if (isset($_POST['template'])){ - $smarty->assign("template", $_POST['template']); + if ($s_action=="create_user_from_tpl"){ + $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']); } else { - $smarty->assign("template", ""); + $smarty->assign("template", "none"); } $smarty->assign("edit_uid", ""); return($smarty->fetch(get_template_path('template.tpl', TRUE))); } } + /******************** + Template selected continue edit + ********************/ + /* Continue template editing */ - if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){ - $this->sn= $_POST['sn']; - $this->givenName= $_POST['givenName']; + if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){ + $this->sn = $_POST['sn']; + $this->givenName = $_POST['givenName']; /* Check for requred values */ $message= array(); @@ -502,7 +548,7 @@ class userManagement extends plugin $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']); $ldap= $this->config->get_ldap_link(); $ldap->cd ($dn); - $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName")); + $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName")); if ($ldap->count () != 0){ $message[]= _("A person with the choosen name is already used in this tree."); } @@ -521,7 +567,7 @@ class userManagement extends plugin $this->uid= current($uids); } } else { - $smarty->assign("edit_uid", ""); + $smarty->assign("edit_uid", ""); $this->uid= ""; } $this->got_uid= true; @@ -536,6 +582,11 @@ class userManagement extends plugin return($smarty->fetch(get_template_path('template.tpl', TRUE))); } + + /******************** + No template selected continue edit + ********************/ + /* No template. Ok. Lets fill data into the normal user dialog */ if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){ foreach(array("sn", "givenName", "uid") as $attr){ @@ -545,369 +596,250 @@ class userManagement extends plugin } } + + /******************** + Template selected continue edit + ********************/ + /* Finish template preamble */ if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){ /* Might not be filled if IDGEN is unset */ - $this->sn= $_POST['sn']; - $this->givenName= $_POST['givenName']; + $this->sn = $_POST['sn']; + $this->givenName = $_POST['givenName']; /* Move user supplied data to sub plugins */ - $this->uid= $_POST['uid']; - $this->usertab->uid= $this->uid; - $this->usertab->sn= $this->sn; - $this->usertab->givenName= $this->givenName; - $template_dn= $_POST['template']; + $this->uid = $_POST['uid']; + $this->usertab->uid = $this->uid; + $this->usertab->sn = $this->sn; + $this->usertab->givenName = $this->givenName; + $template_dn = $_POST['template']; $this->usertab->adapt_from_template($template_dn); - $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $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); } + + + /******************** + If no template was selected set base + ********************/ + + if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){ + $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase; + } + + + /******************** + Display subdialog + ********************/ /* Show tab dialog if object is present */ - if ($this->usertab){ + if(isset($this->usertab->config)){ $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"; $display.= " \n"; $display.= "\n"; $display.= "
"; } return ($display); } - - $smarty= get_smarty(); - - /* Check sorting variable */ - if (!isset($this->usertab) && - !isset($_POST['new_user']) && - !isset($_POST['new_template']) && - !isset($_POST['delete_user']) && - !isset($_POST['setpass_user']) && - !isset($_POST['select_user'])){ - $this->reload(); - } - - /* Check for exeeded sizelimit */ - if (($message= check_sizelimit()) != ""){ - return($message); - } - - /* Prepare departments */ - $options= ""; - foreach ($this->config->idepartments as $key => $value){ - if ($userfilter['depselect'] == $key){ - $options.= ""; - } else { - $options.= ""; - } - } - - /* NEW LIST MANAGMENT */ - $listhead = "