Code

Updated sudo stuff
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 3 Apr 2008 09:14:43 +0000 (09:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 3 Apr 2008 09:14:43 +0000 (09:14 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10132 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/admin/sudo/class_sudoGeneric.inc
gosa-core/plugins/admin/sudo/class_sudoOptions.inc
gosa-core/plugins/admin/sudo/generic.tpl
gosa-core/plugins/admin/sudo/options.tpl

index a14d87c8f6cfa11449928fee5044725bcbc7b2cc..6f62286b597e8c7eca0cc0463ca459539912c739 100644 (file)
@@ -28,12 +28,11 @@ class sudo extends plugin
 
   var $sudoUser   = array();
   var $sudoCommand= array();
-  var $sudoOption = array();
   var $sudoHost   = array();
   var $sudoRunas  = array();
 
   var $objectclasses = array("top","sudoRole");
-  var $attributes    = array("cn","description","sudoUser","sudoCommand","sudoOption","sudoHost","sudoRunas");
+  var $attributes    = array("cn","description","sudoUser","sudoCommand","sudoHost","sudoRunas");
 
   var $is_account = TRUE;
 
@@ -41,7 +40,7 @@ class sudo extends plugin
   {
     plugin::plugin ($config, $dn);
 
-    foreach(array("sudoUser","sudoCommand","sudoOption","sudoHost","sudoRunas") as $attr){
+    foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunas") as $attr){
       $this->$attr = array();
       if(isset($this->attrs[$attr])){
         $tmp = array();
@@ -171,15 +170,13 @@ class sudo extends plugin
     $divlist_sudoHost->Setheight("90");
     $divlist_sudoRunas = new divSelectBox("divlist_sudoRunas");
     $divlist_sudoRunas->Setheight("90");
-    $divlist_sudoOption = new divSelectBox("divlist_sudoOption");
-    $divlist_sudoOption->Setheight("90");
     $divlist_sudoCommand = new divSelectBox("divlist_sudoCommand");
     $divlist_sudoCommand->Setheight("90");
 
     $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","sudoOption","sudoHost","sudoRunas") as $attr){
+    foreach(array("sudoUser","sudoCommand","sudoHost","sudoRunas") as $attr){
       foreach($this->$attr as $key => $entry){
         $entry = preg_replace("/^!/",$neg_img,$entry);
         $list_name = "divlist_".$attr;
@@ -194,7 +191,6 @@ class sudo extends plugin
     $smarty->assign("divlist_sudoUser",$divlist_sudoUser->DrawList());
     $smarty->assign("divlist_sudoHost",$divlist_sudoHost->DrawList());
     $smarty->assign("divlist_sudoRunas",$divlist_sudoRunas->DrawList());
-    $smarty->assign("divlist_sudoOption",$divlist_sudoOption->DrawList());
     $smarty->assign("divlist_sudoCommand",$divlist_sudoCommand->DrawList());
     
     return($smarty->fetch(get_template_path('generic.tpl', TRUE)));
@@ -265,8 +261,7 @@ class sudo extends plugin
             "sudoUser"          => _("Users"),
             "sudoHost"          => _("Host"),
             "sudoCommand"       => _("Command"),
-            "sudoRunas"         => _("Run as user"),
-            "sudoOption"        => _("Flags"))
+            "sudoRunas"         => _("Run as user"))
         ));
   }
 }
index 8c003e4a9a5c2c0c7f3d81337092e170c002297e..0b1572211b94b18e4d0da7e5706c217ed6201ad9 100644 (file)
@@ -180,6 +180,30 @@ class sudo_options extends plugin
         $option['VALUE']  = array($value);
         $option['NEGATE'] = $negation;
 
+        /*  Special handling for mixed flag types. 
+            Some attributes like (BOOL_INTEGER) can be TRUE/FALSE and INTEGER.
+            This means, if the value is empty it is BOOL and $negation defines its boolean value.
+         */
+        if(in_array($this->options[$opt]['TYPE'],array("BOOL_INTEGER","STRING_BOOL"))){
+          if(empty($value)){
+            $option['NEGATE'] = FALSE;
+            if($negation){
+              $option['VALUE'] = array(0 => "FALSE");
+            }else{
+              $option['VALUE'] = array(0 => "TRUE");
+            }
+          }
+        }
+
+        if(in_array($this->options[$opt]['TYPE'],array("BOOLEAN"))){
+          $option['NEGATE'] = FALSE;
+          if($negation){
+            $option['VALUE'] = array(0 => "FALSE");
+          }else{
+            $option['VALUE'] = array(0 => "TRUE");
+          }
+        }
+
         if(!isset($this->sudoOption[$opt])){
           $this->sudoOption[$opt] = $option;
         }else{
@@ -193,6 +217,51 @@ class sudo_options extends plugin
   {
     /* Call parent execute */
     plugin::execute();
+
+    foreach($_POST as $name => $value){
+      if(preg_match("/^negOption_/",$name)){
+        $opt = preg_replace("/^negOption_/","",$name);
+        $opt = preg_replace("/_[^_]*$/","",$opt);
+        if(isset($this->sudoOption[$opt])){
+          $val = $this->sudoOption[$opt]['VALUE'][0];
+
+          /*****
+            Negate STRING_BOOL && BOOL_INTEGER
+           *****/
+          if(in_array($this->options[$opt]['TYPE'],array('STRING_BOOL','BOOL_INTEGER'))){
+            if(in_array($val, array("TRUE","FALSE"))){
+              if($val == "TRUE"){
+                $this->sudoOption[$opt]['VALUE'][0] = "FALSE";
+              }else{
+                $this->sudoOption[$opt]['VALUE'][0] = "TRUE";
+              }
+            }else{
+               $this->sudoOption[$opt]['NEGATE'] = !$this->sudoOption[$opt]['NEGATE']; 
+            }
+          }
+
+          /*****
+            Negate STRING / INTEGER
+           *****/
+          if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER'))){
+            $this->sudoOption[$opt]['NEGATE'] = !$this->sudoOption[$opt]['NEGATE']; 
+          }
+
+          /*****
+            Negate BOOLEAN
+           *****/
+          if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){
+            if($val == "TRUE"){
+              $this->sudoOption[$opt]['VALUE'][0] = "FALSE";
+            }else{
+              $this->sudoOption[$opt]['VALUE'][0] = "TRUE";
+            }
+          }
+        }
+        break;
+      }
+    }
+
  
     $smarty = get_smarty();
     $smarty->assign("map",  array("STRINGS" => _("string"), "BOOLEAN" => _("bool"),
@@ -213,9 +282,40 @@ class sudo_options extends plugin
     plugin::save_object();
 
     foreach($this->sudoOption as $name => $opt){
+
+      /****
+        Get posted value for BOOLEAN
+       ****/
+      if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){
+        $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name);
+      }
+
+      /****
+        Get posted value for STRING / INTEGER
+       ****/
       if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){
         if(isset($_POST['option_value__'.$name])){
-          $this->sudoOption[$name]['VALUE'] = get_post('option_value__'.$name);
+          $this->sudoOption[$name]['VALUE'][0] = get_post('option_value__'.$name);
+        }
+      }
+
+      /****
+        Get posted value for STRING_BOOL / BOOL_INTEGER
+       ****/
+      if(in_array($this->options[$name]['TYPE'],array("BOOL_INTEGER","STRING_BOOL"))){
+        if(isset($_POST['option_selection__'.$name])){
+          $sel = get_post('option_selection__'.$name);
+          $val = "";
+          if(isset($_POST['option_value__'.$name])){
+            $val = get_post('option_value__'.$name);
+          }
+
+          if($sel == "FALSE" || $sel == "TRUE"){
+            $this->sudoOption[$name]['VALUE'] = array($sel);
+            $this->sudoOption[$name]['NEGATE'] = FALSE;
+          }else{
+            $this->sudoOption[$name]['VALUE'] = array($val);
+          }
         }
       }
     }
@@ -225,9 +325,55 @@ class sudo_options extends plugin
   function save()
   {
     plugin::save(); 
+
+    $this->attrs['sudoOption'] = array();
+    foreach($this->sudoOption as $name => $opt){
+
+      $type   = $this->options[$name]['TYPE'];
+      $neg    = $opt['NEGATE'];
+      $value  = $opt['VALUE'][0];
+      $option = "";
+
+      /****
+        Save BOOLEAN
+       ****/
+      if(in_array($type,array("BOOLEAN"))){ 
+        $option = $name;
+        if($value == "FALSE"){
+          $option = "!".$option;
+        }
+      }
+
+      /****
+        Save STRING / INTEGER
+       ****/
+      if(in_array($type,array("STRING","INTEGER"))){ 
+        $option = $name."=".$value;
+        if($neg){
+          $option = "!".$option;
+        }
+      }
+
+      /****
+        Save STRING_BOOL / BOOL_INTEGER
+       ****/
+      if(in_array($type,array("STRING_BOOL","BOOL_INTEGER"))){
+        if($value == "FALSE"){
+          $option = "!".$name;
+        }elseif($value == "TRUE"){
+          $option = $name;
+        }else{
+          $option = $name."=".$value;
+          if($neg){
+            $option = "!".$option;
+          }
+        }
+      }
+
+      $this->attrs['sudoOption'][] = $option;
+    }
     $this->cleanup();
     $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);
     $ldap->cd($this->dn);
     $ldap->modify($this->attrs);;
   }
index e0849e8dba41a5043fe84a0e664e55206cc86702..be45c1709dcd613dad0c3a374bc80132c0bd6978 100644 (file)
   </td>
  </tr> 
  <tr><td style="width:100%;"colspan="2"><p class="seperator">&nbsp;</p></td></tr>
- <tr>
-  <td colspan="2"><b>Flags</b>
-   {$divlist_sudoOption}
-   <input type='submit' name='list_sudoOption' value='{t}Add from list{/t}'>
-  </td>
- </tr>
- <tr><td style="width:100%;"colspan="2"><p class="seperator">&nbsp;</p></td></tr>
  <tr>
   <td><b>Hosts</b>
    {$divlist_sudoHost}
index 2cac4f0e07bd99676e73cea3884e954a389d63c2..94685e32e3988ebc431f6f0acd9308b7a5cd9d30 100644 (file)
   <td>
 
   {if $options[$item.NAME].TYPE == "STRING"}
+   <!-- STRING  
+    -->
    <input type='text' name='option_value__{$key}' value="{$item.VALUE.0}" style='width:280px;'> 
   {elseif $options[$item.NAME].TYPE == "INTEGER"}
+   <!-- INTEGER  
+    -->
    <input type='text' name='option_value__{$key}' value="{$item.VALUE.0}" style='width:280px;'>
   {elseif $options[$item.NAME].TYPE == "BOOLEAN"}
-   <input type='checkbox' value="1" name='option_value__{$key}'>
+   <!-- BOOLEAN  
+    -->
+   <select name="option_value__{$key}">
+    <option {if $item.VALUE.0 == "FALSE"} selected {/if}value="FALSE">FALSE</option>
+    <option {if $item.VALUE.0 == "TRUE"} selected {/if}value="TRUE">TRUE</option>
+   </select>
   {elseif $options[$item.NAME].TYPE == "BOOL_INTEGER"}
-   <select name="option_selection__{$key}">
-    <option {if $item.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
-    <option {if $item.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
-    <option {if $item.VALUE != "TRUE" && $item.VALUE != "FALSE"} selected {/if}value="STRING">STRING</option>
-    <input type='text' value="{$item.VALUE.0}" style='width:280px;' name='option_value__{$key}'>
+   <!-- BOOLEAN_INTEGER 
+    -->
+   <select name="option_selection__{$key}" id="option_selection__{$key}"
+       onChange="toggle_bool_fields('option_selection__{$key}','option_value__{$key}');">
+    <option {if $item.VALUE.0 == "FALSE"} selected {/if}value="FALSE">FALSE</option>
+    <option {if $item.VALUE.0 == "TRUE"} selected {/if}value="TRUE">TRUE</option>
+    <option {if $item.VALUE.0 != "TRUE" && $item.VALUE.0 != "FALSE"} selected {/if}
+       value="STRING">STRING</option>
+    <input type='text' value="{$item.VALUE.0}" style='width:280px;' name='option_value__{$key}'
+       id="option_value__{$key}"
+        {if $item.VALUE.0 == "FALSE" ||  $item.VALUE.0 == "TRUE"} disabled {/if}>
    </select> 
   {elseif $options[$item.NAME].TYPE == "STRING_BOOL"}
-   <select name="option_selection__{$key}">
-    <option {if $item.VALUE == "FALSE"} selected {/if}value="FALSE">FALSE</option>
-    <option {if $item.VALUE == "TRUE"} selected {/if}value="TRUE">TRUE</option>
-    <option {if $item.VALUE != "TRUE" && $item.VALUE != "FALSE"} selected {/if}value="STRING">STRING</option>
-    <input type='text' value="{$item.VALUE.0}" style='width:280px;' name='option_value__{$key}'>
+   <!-- STRING_BOOLEAN 
+    -->
+   <select name="option_selection__{$key}" id="option_selection__{$key}"
+       onChange="toggle_bool_fields('option_selection__{$key}','option_value__{$key}');">
+    <option {if $item.VALUE.0 == "FALSE"} selected {/if}value="FALSE">FALSE</option>
+    <option {if $item.VALUE.0 == "TRUE"} selected {/if}value="TRUE">TRUE</option>
+    <option {if $item.VALUE.0 != "TRUE" && $item.VALUE.0 != "FALSE"} selected {/if}
+       value="STRING">STRING</option>
+    <input type='text' value="{$item.VALUE.0}" style='width:280px;' name='option_value__{$key}'
+       id="option_value__{$key}" 
+        {if $item.VALUE.0 == "FALSE" ||  $item.VALUE.0 == "TRUE"} disabled {/if}>
    </select> 
   {else}
    {$options[$item.NAME].TYPE} 
   {/if}
   </td>
+  <td style='width: 40px;'>
+   <input type='image' src='images/negate.png'     name='negOption_{$key}' class='center'>
+   <input type='image' src='images/edittrash.png'  name='delOption_{$key}' class='center'>
+  </td>
  </tr>
 {/foreach}
 </table>
+
+<script language="JavaScript" type="text/javascript">
+ <!-- 
+  {literal}
+  function toggle_bool_fields(source_select,target_input)
+  {
+   var select= document.getElementById(source_select); 
+   var input = document.getElementById(target_input); 
+   if(select.value == "TRUE" || select.value == "FALSE"){
+    input.disabled = true;
+    input.value = select.value;
+   }else{
+    input.disabled = false;
+    input.value = "";
+   }
+  }
+  {/literal}
+ -->
+</script>
+
+