Code

Reverted last commit.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 26 Jun 2009 11:14:07 +0000 (11:14 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 26 Jun 2009 11:14:07 +0000 (11:14 +0000)
-Modifying the dhcp plugin to supprot multiple options of the same type, is not that easy.

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

gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpAdvanced.inc
gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpHost.inc
gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNetwork.inc
gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpPlugin.inc

index 8dd90a62774767c2d53641b9caaf539082c78e1f..755214411ca6755a50ef79febf51316bd4c0c99d 100644 (file)
@@ -32,23 +32,6 @@ class dhcpAdvanced extends plugin
   var $objectclasses= array();
   var $parent;
 
-  static function getOption($needle, $heystack, $value_only = false){
-    foreach($heystack as $key => $val){
-      if($val != $key){
-        echo "<b>$key => $val</b>";
-      }
-
-      if(preg_match("/^{$needle} /i",$val)){
-        if($value_only){
-          return(trim(preg_replace('/^[^\s]*/')));
-        }else{
-          return($val);
-        }
-      }
-    }
-    return("");
-  }
-
   function dhcpAdvanced()
   {
     /* This is always an account */
@@ -70,22 +53,22 @@ class dhcpAdvanced extends plugin
     if ($acl_writeable && isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){
       $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpstatements'));
       if (in_array($key, $this->autoStatements)){
-        msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
+       msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
       } else {
         unset($this->statements[$key]);        
       }
     }
     if ($acl_writeable && isset($_POST['add_option']) && $_POST['addoption'] != ""){
-      $val= trim(get_post('addoption'));
-      $this->options[$val]= $val;
+      $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', get_post('addoption'));
+      $val= preg_replace("/^$key\s*/", '', get_post('addoption'));
+      $this->options[$key]= $val;
     }
     if ($acl_writeable && isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){
       $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', get_post('dhcpoptions'));
-      $val= get_post('dhcpoptions');
       if (in_array($key, $this->autoOptions)){
-        msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
+       msg_dialog::display(_("Error"), _("Cannot delete automatic statements!"), ERROR_DIALOG);
       } else {
-        unset($this->options[$val]);   
+        unset($this->options[$key]);   
       }
     }
 
@@ -106,11 +89,10 @@ class dhcpAdvanced extends plugin
     $smarty->assign("dhcpstatements", $statements);
     $options= array();
     foreach ($this->options as $key => $val){
-      $key = preg_replace("/ .*$/","",$val);
       if (in_array($key, $this->autoOptions)){
-        $options[$val]= "$val ["._("automatic")."]";
+        $options[$key]= "$key $val ["._("automatic")."]";
       } else {
-        $options[$val]= "$val";
+        $options[$key]= "$key $val";
       }
     }
     $smarty->assign("dhcpoptions", $options);
index e407ba54d2bbbaed06379cb6438916c56f9c704f..c7569d2c95f46da2445ff64076f60cc721ba2dd5 100644 (file)
@@ -121,8 +121,7 @@ class dhcpHost extends dhcpPlugin
           unset ($this->statements['fixed-address']);
         }
       }
-      $hn = "host-name {$this->cn}";
-      $this->options[$hn]= $hn;
+      $this->options['host-name']= $this->cn;
     }
 
     dhcpPlugin::save_object();
index dce548ba3a5af1b64fb58e103c8ca6ee4613dc91..0f99ce23b3b6ec4f4b99525ef4bc26391b78b756 100644 (file)
@@ -46,9 +46,8 @@ class dhcpNetwork extends plugin
               htmlentities(get_post('addserver')),"/[0-9a-z.-]/"), ERROR_DIALOG);
       } else {
         $servers= array();
-        $chk = dhcpAdvanced::getOption('domain-name-servers',$this->options,true);
-        if($chk != ""){
-          foreach(split(",", $chk) as $val){
+        if (isset($this->options['domain-name-servers'])){
+          foreach(split(",", $this->options['domain-name-servers']) as $val){
             $servers[$val]= $val;
           }
         }
@@ -58,28 +57,18 @@ class dhcpNetwork extends plugin
         foreach($servers as $val){
           $tmp.= $val.",";
         }
-        $chk = dhcpAdvanced::getOption('domain-name-servers',$this->options);
-        if($chk != ""){
-          unset($this->options[$chk]);
-        }
-        $new = "domain-name-servers ".preg_replace('/,$/', '', $tmp);
-        $this->options[$new]=$new; 
+        $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp);
       }
     }
     if ($acl_writeable && isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
-      $val = dhcpAdvanced::getOption('domain-name-servers', $this->options, true);
-      $key = dhcpAdvanced::getOption('domain-name-servers', $this->options);
-  
-      if($key != ""){
-        unset($this->options[$key]);
-        $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i",'', $val);
-        $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp);
-        if ($tmp != ""){
-          $tmp ="domain-name-servers {$tmp}";
-          $this->options[$tmp]= $tmp;
-        }
+      $tmp= preg_replace("/(\s*,\s*)?".get_post('dnsserver')."/i", '',
+          $this->options['domain-name-servers']);
+      $tmp= preg_replace("/(\s*)?,(\s*)?$/", '', $tmp);
+      if ($tmp != ""){
+        $this->options['domain-name-servers']= $tmp;
+      } else {
+        unset($this->options['domain-name-servers']);
       }
-
     }
 
     /* Show main page */
@@ -93,13 +82,21 @@ class dhcpNetwork extends plugin
      */
 
     /* Router */
-    $smarty->assign("routers", dhcpAdvanced::getOption('router',$this->options));
+    if (isset($this->options['routers'])){
+      $smarty->assign("routers", $this->options['routers']);
+    } else {
+      $smarty->assign("routers", "");
+    }
 
     /* DNS */
-    $smarty->assign("domain", dhcpAdvanced::getOption('domain-name',$this->options));
-    if (dhcpAdvanced::getOption('domain-name-servers',$this->options) != ""){
+    if (isset($this->options['domain-name'])){
+      $smarty->assign("domain", trim($this->options['domain-name'], '"'));
+    } else {
+      $smarty->assign("domain", "");
+    }
+    if (isset($this->options['domain-name-servers'])){
       $servers= array();
-      foreach(split(",", dhcpAdvanced::getOption('domain-name-servers',$this->options, true)) as $val){
+      foreach(split(",", $this->options['domain-name-servers']) as $val){
         $servers[$val]= $val;
       }
       $smarty->assign("dnsservers", $servers);
@@ -108,18 +105,17 @@ class dhcpNetwork extends plugin
     }
 
     /* Netmask / Broadcast */
-    if (dhcpAdvanced::getOption('subnet-mask', $this->options) != ""){
-      $key = dhcpAdvanced::getOption('subnet-mask', $this->options);
-      $val = dhcpAdvanced::getOption('subnet-mask', $this->options,true);
-
-      unset($this->options[$key]);
-      $new = 'subnet-mask '.normalize_netmask($val);
-      $this->options[$new]=$new;
-      $smarty->assign("subnet_mask", $new);
+    if (isset($this->options['subnet-mask'])){
+      $this->options['subnet-mask']= normalize_netmask($this->options['subnet-mask']);
+      $smarty->assign("subnet_mask", $this->options['subnet-mask']);
     } else {
       $smarty->assign("subnet_mask", "");
     }
-    $smarty->assign("broadcast_address", dhcpAdvanced::getOption('broadcast-address',$this->options));
+    if (isset($this->options['broadcast-address'])){
+      $smarty->assign("broadcast_address", $this->options['broadcast-address']);
+    } else {
+      $smarty->assign("broadcast_address", "");
+    }
 
     /* Boot stuff */
     if (isset($this->statements['filename'])){
@@ -169,13 +165,10 @@ class dhcpNetwork extends plugin
       foreach (array("routers" => "routers", "domain-name" => "domain", "subnet-mask" => "subnet_mask",
                      "broadcast-address" => "broadcast_address") as $key => $val){
 
-        $ikey = dhcpAdvanced::getOption($key, $this->options);
-        if($ikey != ""){
-          unset($this->options[$ikey]);
-        }
-        if ($_POST["$val"] != ''){
-          $new = $key." ".$get_post($val);
-          $this->options[$new]=$new; 
+        if ($_POST["$val"] == ''){
+          unset($this->options["$key"]);
+        } else {
+          $this->options["$key"]= get_post("$val");
         }
       }
 
@@ -216,12 +209,11 @@ class dhcpNetwork extends plugin
 
     /* Check netmask and broadcast */
     foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
-      $ikey = dhcpAdvanced::getOption($key,$this->options);
-      $ival = dhcpAdvanced::getOption($key,$this->options,true);
-      if ($ikey == ""){
+      if (!isset($this->options["$key"])){
         continue;
       }
-      $tmp= preg_replace('/^[^\s]+\s/', '', $ival);
+      $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
+
       if (!tests::is_ip($tmp)){
         $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
       }
index 89575229dc8911978a0ad446a71643cf9ab9a8f7..f6b9f39b3c5d0e819e37e97b388cce5d35ae349e 100644 (file)
@@ -47,8 +47,13 @@ class dhcpPlugin extends plugin
       /* Load options */
       if (isset($attrs['dhcpOption'])){
         foreach ($attrs['dhcpOption'] as $opt){
-          $opt = trim($opt);
-          $this->options[$opt]= $opt;
+          $idx= preg_replace('/\s.+$/', '', $opt);
+          if ($idx == $opt){
+            $value= "";
+          } else {
+            $value= preg_replace('/^[^\s]+\s/', '', $opt);
+          }
+          $this->options[$idx]= $value;
         }
       }
 
@@ -106,10 +111,7 @@ class dhcpPlugin extends plugin
   {
     /* Strip network objects */
     foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){
-      $ikey = dhcpAdvanced::getOption($toberemoved, $this->options);
-      if($ikey != ""){
-        unset($this->options[$ikey]);
-      }
+      unset($this->options[$toberemoved]);
     }
     foreach (array("filename", "next-server","get-lease-hostnames","use-host-decl-names") as $toberemoved){
       unset($this->statements[$toberemoved]);
@@ -153,7 +155,7 @@ class dhcpPlugin extends plugin
     $this->attrs['dhcpOption']= array();
     if (isset ($this->options) && count ($this->options)){
       foreach ($this->options as $key => $val){
-        $this->attrs['dhcpOption'][]= "$val";
+        $this->attrs['dhcpOption'][]= "$key $val";
       }
     }
 
@@ -206,10 +208,7 @@ class dhcpPlugin extends plugin
   function fix_options()
   {
     foreach (array('domain-name-servers') as $key){
-      $ikey = dhcpAdvanced::getOption($key,$this->options);
-      if($ikey != ""){
-        unset ($this->options[$ikey]);
-      }
+      unset ($this->options[$key]);
     }
   }