From 22c87447300ef8aa1e5b281bdd59a6099e61746d Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 8 Apr 2008 07:39:50 +0000 Subject: [PATCH] Updated sudo stuff -Allow adding groups % git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10268 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../sudo/admin/sudo/class_sudoGeneric.inc | 51 +++++++++++++++++-- .../admin/sudo/class_target_list_users.inc | 44 ++++++++++++++-- 2 files changed, 87 insertions(+), 8 deletions(-) diff --git a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc index ffccd2576..02d83b68a 100644 --- a/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc +++ b/gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc @@ -193,9 +193,13 @@ class sudo extends plugin if(isset($_POST['SaveMultiSelectWindow']) && $this->dialog instanceof target_list_users){ if($this->acl_is_writeable("sudoUser")){ foreach($this->dialog->save() as $entry){ - $cn = trim($entry['uid'][0]); - if(!in_array($cn,$this->sudoUser) && !in_array("!".$cn,$this->sudoUser)){ - $this->sudoUser[] = $cn; + if(in_array("posixGroup",$entry['objectClass'])){ + $name = trim("%".$entry['cn'][0]); + }else{ + $name = trim($entry['uid'][0]); + } + if(!in_array($name,$this->sudoUser) && !in_array("!".$name,$this->sudoUser)){ + $this->sudoUser[] = $name; } } } @@ -368,13 +372,18 @@ class sudo extends plugin $neg_img= "!"; $option = ""; $option.= ""; - foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunAs") as $attr){ + foreach(array("sudoCommand","sudoHost","sudoRunAs") as $attr){ if($this->acl_is_readable($attr)){ foreach($this->$attr as $key => $entry){ - $entry = preg_replace("/^!/",$neg_img,$entry); + $neg = ""; + if(preg_match("/^!/",$entry)){ + $neg = $neg_img; + } + $entry = preg_replace("/^!/","",$entry); $list_name = "divlist_".$attr; $$list_name->AddEntry( array( + array("string" => $neg,"attach" => "style='width:18px;'"), array("string" => $entry), array("string" => preg_replace(array("/%KEY%/","/%ATTR%/"),array($key,$attr),$option), "attach" => "style='width:40px; border-right: 0px;'"))); @@ -382,6 +391,38 @@ class sudo extends plugin } } + foreach(array("sudoUser") as $attr){ + $img1 = ""._("User").""; + $img2 = ""._("Group").""; + if($this->acl_is_readable($attr)){ + foreach($this->$attr as $key => $entry){ + $neg = ""; + if(preg_match("/^!/",$entry)){ + $neg = $neg_img; + } + $entry = preg_replace("/^!/","",$entry); + + $img = $img1; + if(preg_match("/^%/",$entry)){ + $img = $img2; + } + $entry = preg_replace("/^%/","",$entry); + + $list_name = "divlist_".$attr; + $$list_name->AddEntry( + array( + array("string" => $neg,"attach" => "style='width:18px;'"), + array("string" => $img,"attach" => "style='width:18px;'"), + array("string" => $entry), + array("string" => preg_replace(array("/%KEY%/","/%ATTR%/"),array($key,$attr),$option), + "attach" => "style='width:40px; border-right: 0px;'"))); + } + } + } + + + + /* Tell smarty about our divlists */ $smarty->assign("divlist_sudoUser", $divlist_sudoUser->DrawList()); diff --git a/gosa-plugins/sudo/admin/sudo/class_target_list_users.inc b/gosa-plugins/sudo/admin/sudo/class_target_list_users.inc index 227e328bd..1640c3d74 100644 --- a/gosa-plugins/sudo/admin/sudo/class_target_list_users.inc +++ b/gosa-plugins/sudo/admin/sudo/class_target_list_users.inc @@ -35,6 +35,7 @@ class target_list_users extends MultiSelectWindow /* CheckBoxes, to change default values modify $this->AddCheckBox */ var $user ; + var $group ; /* Subsearch checkbox */ @@ -62,6 +63,12 @@ class target_list_users extends MultiSelectWindow $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); $this->AddHeader(array("string" => _("Object name"), "attach" => "style=''")); + $this->AddCheckBox("user", _("Select to see users") ,_("Show users"), true); + $this->AddCheckBox("group", _("Select to see groups"),_("Show groups"), true); + + /* Add SubSearch checkbox */ + $this->AddCheckBox(SEPERATOR); + /* Add SubSearch checkbox */ $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false); @@ -174,7 +181,14 @@ class target_list_users extends MultiSelectWindow $desc = " - [ ".$val['description'][0]." ]"; } - $img = ""._("Use").""; + $img1 = ""._("User").""; + $img2 = ""._("Group").""; + + if(in_array("posixGroup",$val['objectClass'])){ + $img = $img2; + }else{ + $img = $img1; + } /* Create each field */ $field0 = array("string" => "" , @@ -218,11 +232,35 @@ class target_list_users extends MultiSelectWindow $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); + $res = array(); + if($this->user){ + $filter = "(&(objectClass=person)(objectClass=gosaAccount))"; + $filter= "(&(cn=".$Regex.")(|".$filter."))"; + $res= array_merge($res,get_sub_list($filter, array("users"), array(get_people_ou()),$base, + array("cn","uid","objectClass","description"), GL_SIZELIMIT | GL_SUBSEARCH)); + } + if($this->group){ + $filter = "(objectClass=posixGroup)"; + $filter= "(&(cn=".$Regex.")(|".$filter."))"; + $res= array_merge($res,get_sub_list($filter, array("groups"), array(get_groups_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 ); + $res = array(); + if($this->user){ + $filter = "(&(objectClass=person)(objectClass=gosaAccount))"; + $filter= "(&(cn=".$Regex.")(|".$filter."))"; + $res= array_merge($res,get_list($filter, array("users"), get_people_ou().$base, + array("cn","uid","objectClass","description"), GL_SIZELIMIT )); + } + if($this->group){ + $filter = "(objectClass=posixGroup)"; + $filter= "(&(cn=".$Regex.")(|".$filter."))"; + $res= array_merge($res,get_list($filter, array("groups"), get_groups_ou().$base, + array("cn","uid","objectClass","description"), GL_SIZELIMIT )); + } } $this->list= $res; -- 2.30.2