Code

Updated sudo stuff
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 8 Apr 2008 07:39:50 +0000 (07:39 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 8 Apr 2008 07:39:50 +0000 (07:39 +0000)
-Allow adding groups %

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10268 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/sudo/admin/sudo/class_sudoGeneric.inc
gosa-plugins/sudo/admin/sudo/class_target_list_users.inc

index ffccd2576e83f8bb7c777795d3b4b87fdabeeafb..02d83b68a3080376c9ba97556fafa51cea7491e2 100644 (file)
@@ -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= "<img src='images/negate.png' alt='!' class='center'>"; 
     $option = "<input type='image' src='images/negate.png'     name='neg_%ATTR%_%KEY%' class='center'>"; 
     $option.= "<input type='image' src='images/edittrash.png'  name='del_%ATTR%_%KEY%' class='center'>"; 
-    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 = "<img src='images/select_user.png'   alt='"._("User")."'>";
+      $img2 = "<img src='images/select_groups.png' alt='"._("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());
index 227e328bd0fc914109e0cd333fd511b2723e41bc..1640c3d74ebe16c9297d0574fb1e2eea86cbc133 100644 (file)
@@ -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" => "&nbsp;", "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 = "<img src='images/select_user.png' alt='"._("Use")."' ".$title.">";
+      $img1 = "<img src='images/select_user.png'  alt='"._("User")."'  ".$title.">";
+      $img2 = "<img src='images/select_groups.png' alt='"._("Group")."' ".$title.">";
+
+      if(in_array("posixGroup",$val['objectClass'])){
+        $img = $img2;
+      }else{
+        $img = $img1;
+      }
 
       /* Create each field */
       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
@@ -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;