Code

Updated sudo
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_sudoGeneric.inc
index 7af22e569453f9572b2cfd7d5dc95c457bb8c2de..0544cf64d8223392a86a218b44192937efdb96df 100644 (file)
@@ -35,9 +35,10 @@ class sudo extends plugin
   var $sudoHost   = array("ALL");
   var $sudoRunAs  = array("ALL");
 
-  var $accessTo       = array();
-  var $trustModel     = "";
-  var $show_ws_dialog = FALSE;
+  var $accessTo         = array();
+  var $trustModel       = "";
+  var $show_ws_dialog   = FALSE;
+  var $was_trust_account= FALSE;
 
   var $objectclasses = array("top","sudoRole");
   var $attributes    = array("cn","description","sudoUser","sudoCommand","sudoHost","sudoRunAs","accessTo","trustModel");
@@ -192,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;
           }
         }   
       }
@@ -367,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;'")));
@@ -381,6 +391,38 @@ class sudo extends plugin
       }
     }
 
+    foreach(array("sudoUser") as $attr){
+      $img1 = "<img src='images/select_user.png'   alt='"._("User")."' class='center'>";
+      $img2 = "<img src='images/select_groups.png' alt='"._("Group")."' class='center'>";
+      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());
@@ -411,6 +453,10 @@ class sudo extends plugin
   function save_object()
   {
     plugin::save_object();
+    
+    if($this->is_default){
+      $this->cn = "default";
+    }  
 
     if(is_object($this->dialog)){
       $this->dialog->save_object();
@@ -473,6 +519,7 @@ class sudo extends plugin
     $this->attrs['sudoRunAs']   = array_values($this->attrs['sudoRunAs']);
     $this->attrs['sudoUser']    = array_values($this->attrs['sudoUser']);
     $this->attrs['sudoCommand'] = array_values($this->attrs['sudoCommand']);
+
     $this->cleanup();
 
     $ldap = $this->config->get_ldap_link();
@@ -510,6 +557,11 @@ class sudo extends plugin
       $message[] = msgPool::required(_("Name"));
     }
 
+    /* Check if name is reserved */
+    if(!$this->is_default && preg_match("/^default$/i",$this->cn)){
+      $message[] = msgPool::reserved(_("Name"));
+    }
+
     /* Check name */
     if(!preg_match("/^[a-z]*$/i",$this->cn)){
       $message[] = msgPool::invalid(_("Name"),$this->cn,"/[a-z]/i");
@@ -593,6 +645,13 @@ class sudo extends plugin
   }
 
 
+  public function set_default($state)
+  {
+    $this->is_default = TRUE;
+    $this->cn = "default";
+  }
+
+
   /*! \brief  Add ACL object
       @return Returns the ACL object.
    */