Code

Updated Sudo Roles
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 20 Oct 2008 09:14:38 +0000 (09:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 20 Oct 2008 09:14:38 +0000 (09:14 +0000)
-Added ACLs to option tab

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

gosa-plugins/sudo/admin/sudo/class_sudoOption.inc
gosa-plugins/sudo/admin/sudo/options.tpl

index bbac63d1be563ac04d330d76906d8af72eafdc7f..00907172080f864c00d69b2199f26b4b10f3f050 100644 (file)
@@ -206,75 +206,79 @@ class sudoOption extends plugin
     /*****
       Handle Posts 
      *****/
-    foreach($_POST as $name => $value){
-
-      if(preg_match("/^negOption_/",$name)){
-
-        $opt = preg_replace("/^negOption_/","",$name);
-        $opt = preg_replace("/_[^_]*$/","",$opt);
-        $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
-        $opt = preg_replace("/_[0-9]*$/","",$opt);
+    if($this->acl_is_writeable("")){
+
+      foreach($_POST as $name => $value){
+
+        if(preg_match("/^negOption_/",$name)){
+
+          $opt = preg_replace("/^negOption_/","",$name);
+          $opt = preg_replace("/_[^_]*$/","",$opt);
+          $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
+          $opt = preg_replace("/_[0-9]*$/","",$opt);
+
+          if(isset($this->sudoOption[$opt][$id])){
+            $val = $this->sudoOption[$opt][$id]["VALUE"];
+
+            /*****
+              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][$id]["VALUE"] = "FALSE";
+                }else{
+                  $this->sudoOption[$opt][$id]["VALUE"] = "TRUE";
+                }
+              }else{
+                $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
+              }
+            }
 
-        if(isset($this->sudoOption[$opt][$id])){
-          $val = $this->sudoOption[$opt][$id]["VALUE"];
+            /*****
+              Negate STRING / INTEGER
+             *****/
+            if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER','LISTS'))){
+              $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
+            }
 
-          /*****
-            Negate STRING_BOOL && BOOL_INTEGER
-           *****/
-          if(in_array($this->options[$opt]['TYPE'],array('STRING_BOOL','BOOL_INTEGER'))){
-            if(in_array($val, array("TRUE","FALSE"))){
+            /*****
+              Negate BOOLEAN
+             *****/
+            if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){
               if($val == "TRUE"){
                 $this->sudoOption[$opt][$id]["VALUE"] = "FALSE";
               }else{
                 $this->sudoOption[$opt][$id]["VALUE"] = "TRUE";
               }
-            }else{
-               $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
             }
           }
+          break;
+        }
 
-          /*****
-            Negate STRING / INTEGER
-           *****/
-          if(in_array($this->options[$opt]['TYPE'],array('STRING','INTEGER','LISTS'))){
-            $this->sudoOption[$opt][$id]['NEGATE'] = !$this->sudoOption[$opt][$id]['NEGATE']; 
+        /*****
+          Remove options
+         *****/
+        if(preg_match("/^delOption/",$name)){
+          $opt = preg_replace("/^delOption_/","",$name);
+          $opt = preg_replace("/_[^_]*$/","",$opt);
+          $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
+          $opt = preg_replace("/_[0-9]*$/","",$opt);
+
+          if(isset($this->sudoOption[$opt][$id])){
+            unset($this->sudoOption[$opt][$id]);
           }
-
-          /*****
-            Negate BOOLEAN
-           *****/
-          if(in_array($this->options[$opt]['TYPE'],array('BOOLEAN'))){
-            if($val == "TRUE"){
-              $this->sudoOption[$opt][$id]["VALUE"] = "FALSE";
-            }else{
-              $this->sudoOption[$opt][$id]["VALUE"] = "TRUE";
-            }
+          if(!count($this->sudoOption[$opt])){
+            unset($this->sudoOption[$opt]);
           }
+          break;
         }
-        break;
-      }
-
-      /*****
-        Remove options
-       *****/
-      if(preg_match("/^delOption/",$name)){
-        $opt = preg_replace("/^delOption_/","",$name);
-        $opt = preg_replace("/_[^_]*$/","",$opt);
-        $id  = preg_replace("/^.*_([0-9])*$/","\\1",$opt);
-        $opt = preg_replace("/_[0-9]*$/","",$opt);
-
-        if(isset($this->sudoOption[$opt][$id])){
-          unset($this->sudoOption[$opt][$id]);
-        }
-        if(!count($this->sudoOption[$opt])){
-          unset($this->sudoOption[$opt]);
-        }
-        break;
       }
     }
 
  
     $smarty = get_smarty();
+    $smarty->assign("ACL",$this->getacl(""));
     $smarty->assign("map",  array("STRING" => _("string"), "BOOLEAN" => _("bool"),
       "INTEGER" => _("integer") , "BOOL_INTEGER" => _("integer")."-"._("bool") ,
       "STRING_BOOL" => _("string")."-"._("bool"),"LISTS" => _("list")));
@@ -310,71 +314,73 @@ class sudoOption extends plugin
    */
   function save_object()
   {
-    plugin::save_object();
-
-    if(isset($_POST['add_option']) && isset($_POST['option'])){
-      $opt = get_post("option");
-
-      /* Append attribute only once, lists are handled below */
-      if(isset($this->options[$opt])){
-        $type = $this->options[$opt]['TYPE'];
-        $val  = $this->options[$opt]['DEFAULT'];
-        $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE);
-        $this->sudoOption[$opt][] = $option;
+    if($this->acl_is_writeable("")){
+      plugin::save_object();
+
+      if(isset($_POST['add_option']) && isset($_POST['option'])){
+        $opt = get_post("option");
+
+        /* Append attribute only once, lists are handled below */
+        if(isset($this->options[$opt])){
+          $type = $this->options[$opt]['TYPE'];
+          $val  = $this->options[$opt]['DEFAULT'];
+          $option = array("NAME" => $opt, "VALUE" => $val , "NEGATE" => FALSE);
+          $this->sudoOption[$opt][] = $option;
+        }
       }
-    }
-
-    foreach($this->sudoOption as $name => $opts){
-      foreach($opts as $id => $opt){
 
-        /****
-          Get posted value for BOOLEAN
-         ****/
-        if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){
-          if(isset($_POST['option_value__'.$name.'_'.$id])){
-            $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id);
-          }
-        }
+      foreach($this->sudoOption as $name => $opts){
+        foreach($opts as $id => $opt){
 
-        /****
-          Get posted value for STRING / INTEGER
-         ****/
-        if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){
-          if(isset($_POST['option_value__'.$name.'_'.$id])){
-            $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id);
+          /****
+            Get posted value for BOOLEAN
+           ****/
+          if(in_array($this->options[$name]['TYPE'],array("BOOLEAN"))){
+            if(isset($_POST['option_value__'.$name.'_'.$id])){
+              $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id);
+            }
           }
-        }
 
-        /****
-          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.'_'.$id])){
-            $sel = get_post('option_selection__'.$name.'_'.$id);
-            $val = "";
+          /****
+            Get posted value for STRING / INTEGER
+           ****/
+          if(in_array($this->options[$name]['TYPE'],array("STRING","INTEGER"))){
             if(isset($_POST['option_value__'.$name.'_'.$id])){
-              $val = get_post('option_value__'.$name.'_'.$id);
+              $this->sudoOption[$name][$id]["VALUE"] = get_post('option_value__'.$name.'_'.$id);
             }
+          }
 
-            if($sel == "FALSE" || $sel == "TRUE"){
-              $this->sudoOption[$name][$id]['VALUE'] = $sel;
-              $this->sudoOption[$name][$id]['NEGATE'] = FALSE;
-            }else{
-              $this->sudoOption[$name][$id]['VALUE'] = $val;
+          /****
+            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.'_'.$id])){
+              $sel = get_post('option_selection__'.$name.'_'.$id);
+              $val = "";
+              if(isset($_POST['option_value__'.$name.'_'.$id])){
+                $val = get_post('option_value__'.$name.'_'.$id);
+              }
+
+              if($sel == "FALSE" || $sel == "TRUE"){
+                $this->sudoOption[$name][$id]['VALUE'] = $sel;
+                $this->sudoOption[$name][$id]['NEGATE'] = FALSE;
+              }else{
+                $this->sudoOption[$name][$id]['VALUE'] = $val;
+              }
             }
           }
-        }
 
-        /****
-          Get posted value for LISTS
-         ****/
-        if(in_array($this->options[$name]['TYPE'],array("LISTS"))){
-          foreach($this->sudoOption[$name] as $entry_key => $entry){
-            if(isset($_POST['list_value__'.$name.'_'.$entry_key])){
-              $val = get_post('list_value__'.$name.'_'.$entry_key);
-              $this->sudoOption[$name][$entry_key]["VALUE"] = $val;
-            }
-          } 
+          /****
+            Get posted value for LISTS
+           ****/
+          if(in_array($this->options[$name]['TYPE'],array("LISTS"))){
+            foreach($this->sudoOption[$name] as $entry_key => $entry){
+              if(isset($_POST['list_value__'.$name.'_'.$entry_key])){
+                $val = get_post('list_value__'.$name.'_'.$entry_key);
+                $this->sudoOption[$name][$entry_key]["VALUE"] = $val;
+              }
+            } 
+          }
         }
       }
     }
@@ -521,6 +527,23 @@ class sudoOption extends plugin
   }
 
 
+  /*! \brief  Add ACL object
+      @return Returns the ACL object.
+   */
+  static function plInfo()
+  {
+    return (array(  
+          "plShortName" => _("Options"),
+          "plDescription" => _("Sudo options"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 2,
+          "plSection"     => array("admin"),
+          "plCategory"    => array("sudo"),
+          "plProvidedAcls"    => array()
+        ));
+  }
+
   /*!  \brief   Unescape special chars in function parameters.
        @param   String the string to that must be unescaped.
    */
index 701c48343b48ea276cc7f7f3a24e0a5afcabbb39..6df2a0b36aaa197b6ffd3a995d5a59910ed973dd 100644 (file)
@@ -17,7 +17,7 @@
      {/if}
     </td>
     <td>
-   
+{render acl=$ACL}   
     {if $options[$entry.NAME].TYPE == "STRING"}
      <!-- STRING  
       -->
       id="option_value__{$key}_{$entry_key}" 
           {if $entry.VALUE == "FALSE" ||  $entry.VALUE == "TRUE"} disabled {/if}>
     {/if}
+{/render}
     </td>
     <td style='width: 40px; text-align:right;'>
+{render acl=$ACL}   
      <input type='image' src='plugins/sudo/images/negate.png'     name='negOption_{$key}_{$entry_key}' class='center'>
+{/render}
+{render acl=$ACL}   
      <input type='image' src='images/lists/trash.png'  name='delOption_{$key}_{$entry_key}' class='center'>
+{/render}
     </td>
    </tr>
   {/foreach}
@@ -79,6 +84,7 @@
 <p class="seperator">&nbsp;</p>
 <br>
 <h2>{t}Available options{/t}:</h2>
+{render acl=$ACL}   
 <select name='option'>
 {foreach from=$options item=item key=key}
  {if !isset($sudoOption.$key) || ($sudoOption.$key && $item.TYPE == "LISTS")}
  {/if}
 {/foreach}
 </select>
+{/render}
 
+{render acl=$ACL}   
 <input type="submit" name="add_option" value="{msgPool type=addButton}">
-
+{/render}
 
 <script language="JavaScript" type="text/javascript">
  <!--