From 7a4350cd97ebec796d0b36a31266802365b3c444 Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 7 Apr 2008 08:26:47 +0000 Subject: [PATCH] Updated sudo classes -Added target list users git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10221 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../sudo/admin/sudo/class_sudoGeneric.inc | 85 +++--- .../admin/sudo/class_target_list_users.inc | 258 ++++++++++++++++++ 2 files changed, 301 insertions(+), 42 deletions(-) create mode 100644 gosa-plugins/sudo/admin/sudo/class_target_list_users.inc diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc index 3debbed1d..4c19b95b9 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc @@ -91,47 +91,9 @@ class sudo extends plugin } } } - - /******* - Prepare Flags - *******/ - - $options = array(); - // BOOLEAN - $options[]=array("NAME"=>"long_otp_prompt" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"ignore_dot" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"mail_always" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"mail_badpass" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"mail_no_user" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"mail_no_host" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"mail_no_perms" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"tty_tickets" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"authenticate" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"root_sudo" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"log_host" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"log_year" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"shell_noargs" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"set_home" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"always_set_home" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"path_info" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"preserve_groups" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"fqdn" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"insults" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"requiretty" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"env_editor" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"rootpw" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"runaspw" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"targetpw" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"set_logname" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"stay_setuid" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"env_reset" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"use_loginclass" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"noexec" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - $options[]=array("NAME"=>"ignore_local_sudoers" , "TYPE"=>"BOOLEAN", "VALUE" => "1"); - - //STRINGS } + /*! \brief Creates the sudo generic ui. @return String The generated HTML content for this plugin. */ @@ -140,19 +102,48 @@ class sudo extends plugin /* Call parent execute */ plugin::execute(); + /********************* + Add users + *********************/ + + if(isset($_POST['list_sudoUser']) && !is_object($this->dialog)){ + $used = array(); + foreach($this->sudoUser as $name){ + $used[] = preg_replace("/^!/","",$name); + } + $this->dialog =new target_list_users($this->config,$used); + } + + /* Add selected hosts to the sudoUser list */ + if(isset($_POST['SaveMultiSelectWindow']) && $this->dialog instanceof target_list_users){ + foreach($this->dialog->list_get_selected_items() as $id){ + $cn = trim($this->dialog->list[$id]['uid'][0]); + if(!in_array($cn,$this->sudoUser) && !in_array("!".$cn,$this->sudoUser)){ + $this->sudoUser[] = $cn; + } + } + unset($this->dialog); + $this->dialog = NULL; + } + + /********************* Add systems *********************/ if(isset($_POST['list_sudoHost']) && !is_object($this->dialog)){ - $this->dialog =new target_list_systems($this->config,array()); + $used = array(); + foreach($this->sudoHost as $name){ + $used[] = preg_replace("/^!/","",$name); + } + $this->dialog =new target_list_systems($this->config,$used); } /* Add selected hosts to the sudoHost list */ - if(isset($_POST['SaveMultiSelectWindow']) && is_object($this->dialog)){ + if(isset($_POST['SaveMultiSelectWindow']) && $this->dialog instanceof target_list_systems){ foreach($this->dialog->list_get_selected_items() as $id){ $cn = trim($this->dialog->list[$id]['cn'][0]); - if(!in_array($cn,$this->sudoHost)){ + if(!in_array($cn,$this->sudoHost) && !in_array("!".$cn,$this->sudoHost)){ $this->sudoHost[] = $cn; } } @@ -160,6 +151,11 @@ class sudo extends plugin $this->dialog = NULL; } + + /********************* + Dialog handling / display / close + *********************/ + if(isset($_POST['CloseMultiSelectWindow']) && is_object($this->dialog)){ unset($this->dialog); $this->dialog = NULL; @@ -168,6 +164,7 @@ class sudo extends plugin if(is_object($this->dialog)){ return($this->dialog->execute()); } + /********************* NEGATE values @@ -320,6 +317,10 @@ class sudo extends plugin /* Send signal to the world that we've done */ $this->handle_post_events("modify"); } + + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); + } } diff --git a/gosa-plugins/sudo/admin/sudo/class_target_list_users.inc b/gosa-plugins/sudo/admin/sudo/class_target_list_users.inc new file mode 100644 index 000000000..227e328bd --- /dev/null +++ b/gosa-plugins/sudo/admin/sudo/class_target_list_users.inc @@ -0,0 +1,258 @@ +AddCheckBox */ + var $user ; + + + /* Subsearch checkbox */ + var $SubSearch ; + var $parent ; + var $ui ; + + + function target_list_users(&$config,$Targets_used) + { + MultiSelectWindow::MultiSelectWindow($config, "Targetselection", array("users")); + + $this->Targets_used = $Targets_used; + + $this->SetInformation( _("Select the target objects")); + $this->SetTitle( _("Available targets")); + $this->SetSummary( _("Available targets")); + $this->SetHeadpageMode(FALSE); + + /* set Page header */ + $chk = ""; + $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); + + $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); + $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''")); + + /* Add SubSearch checkbox */ + $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false); + + /* Name,Text,Default , Connect with alphabet */ + $this->AddRegex ("Regex", _("Regular expression for matching group names"), "*" , true); + $this->EnableAplhabet(TRUE); + } + + + function GenHeader() + { + $options= ""; + + /* Get all departments within this subtree */ + $ui= get_userinfo(); + $first = ""; + $found = FALSE; + $base = $this->config->current['BASE']; + + /* Add base */ + $tmp = array(); + $tmp[] = array("dn"=>$this->config->current['BASE']); + $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base, + array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + + $deps = array(); + foreach($tmp as $tm){ + $deps[$tm['dn']] = $tm['dn']; + } + + /* Load possible departments */ + $ui= get_userinfo(); + $tdeps= $ui->get_module_departments("users"); + $ids = $this->config->idepartments; + $first = ""; + $found = FALSE; + foreach($ids as $dep => $name){ + if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){ + + /* Keep first base dn in mind, we could need this + * info if no valid base was found + */ + if(empty($first)) { + $first = $dep['dn']; + } + + $value = $ids[$dep]; + if ($this->selectedBase == $dep){ + $found = TRUE; + $options.= ""; + } else { + $options.= ""; + } + } + } + + /* The currently used base is not visible with your acl setup. + * Set base to first useable base. + */ + if(!$found){ + $this->selectedBase = $first; + } + + /* Get copy & paste icon */ + $acls = $ui->get_permissions($this->selectedBase,"user/user"); + $acl_all= $ui->has_complete_category_acls($this->selectedBase,"users"); + + /* Add default header */ + $listhead = MultiSelectWindow::get_default_header(); + + /* Add department selector */ + $listhead .= _("Base")." ". + "  "; + $listhead .=""; + + $this->SetListHeader($listhead); + } + + + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + $this->reload(); + $this->SetEntries($this->list); + return($this->Draw()); + } + + + function SetEntries($list) + { + /* Add Copy & Paste buttons if copy&paste is enabled + */ + // Defining Links + $linkopen = "%s"; + $editlink = "%s"; + + $ui = get_userinfo(); + + // Assigning users + foreach($list as $key => $val){ + + if(in_array($val['cn'][0],$this->Targets_used)) continue; + + $title = "title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'"; + if(!isset($val['description'][0])){ + $desc = ""; + }else{ + $desc = " - [ ".$val['description'][0]." ]"; + } + + $img = ""._("Use").""; + + /* Create each field */ + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + $field1 = array("string" => $img, + "attach" => "style='text- align:center;width: 20px;'"); + $field2 = array("string" => $val['cn'][0].$desc, + "attach" => "style='border-right:0px;' ".$title); + + $this->AddElement(array($field0,$field1,$field2)); + } + } + + + function save() + { + $ret = array(); + $items = $this->list_get_selected_items(); + foreach($items as $item){ + $ret[] = $this->list[$item]; + } + return($ret); + } + + + function save_object() + { + MultiSelectWindow::save_object(); + } + + + function reload() + { + /* Set base for all searches && initialise some vars */ + $this->list= array(); + $base = $this->selectedBase; + $filter = "(&(objectClass=person)(objectClass=gosaAccount))"; + $Regex = $this->Regex; + + /* Create filter */ + $filter= "(&(cn=".$Regex.")(|".$filter."))"; + + if($this->SubSearch){ + $res= get_sub_list($filter, array("users"), array(get_people_ou()),$base, + array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH); + }else{ + $res= get_list($filter, array("users"), get_people_ou().$base, + array("cn","uid","objectClass","description"), GL_SIZELIMIT ); + } + + $this->list= $res; + ksort ($this->list); + reset ($this->list); + $tmp=array(); + foreach($this->list as $tkey => $val ){ + $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val; + } + ksort($tmp); + $this->list=array(); + foreach($tmp as $val){ + $this->list[]=$val; + } + reset ($this->list); + } + + 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); + } +} + + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> -- 2.30.2