Code

Updated dhcp stuff
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 7 Aug 2007 12:21:20 +0000 (12:21 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 7 Aug 2007 12:21:20 +0000 (12:21 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6986 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_dhcpHost.inc
plugins/admin/systems/class_dhcpSubnet.inc
plugins/admin/systems/class_servDHCP.inc
plugins/admin/systems/dhcp_network.tpl
plugins/admin/systems/dhcp_subnet.tpl

index a6d10b73efe58a57c0107dee1366b3ecd1414e38..a88859c4d8cf74a8f45eb40fb5908145bcfec539 100644 (file)
@@ -140,8 +140,6 @@ class dhcpHost extends plugin
   /* Save data to object */
   function save_object()
   {
-    plugin::save_object();
-
     /* Save remaining attributes */
     if (isset($_POST['hwtype'])){
 
index 316763fe6b5e75948380f0a02f595f253c158eea..28ed6b79c54093f2fe6340d2e28923f0835087c4 100644 (file)
@@ -23,10 +23,17 @@ class dhcpSubnet extends plugin
   /* Used attributes */
   var $cn= "";
   var $orig_cn= "";
-  var $dhcpNetMask= "";
+  var $dhcpNetMask= 24;
   var $dhcpRange= "";
+  var $range_start= "";
+  var $range_stop= "";
   var $options= array();
   var $statements= array();
+  var $use_range= FALSE;
+
+  /* Subobjects */
+  var $network;
+  var $advanced;
 
   /* attribute list for save action */
   var $attributes= array();
@@ -36,7 +43,7 @@ class dhcpSubnet extends plugin
   {
     if (is_array($attrs)){
       $this->dn= $attrs['dn'];
-      $this->new= FALSE;
+
 
       /* Load attributes */
       foreach (array("cn", "dhcpNetMask", "dhcpRange") as $attr){
@@ -44,6 +51,10 @@ class dhcpSubnet extends plugin
           $this->$attr= $attrs[$attr][0];
         }
       }
+      if (isset($attrs['dhcpRange'])){
+        $this->use_range= TRUE;
+        list($this->range_start, $this->range_stop)= preg_split('/\s+/', $this->dhcpRange);
+      }
 
       /* Load options */
       if (isset($attrs['dhcpOption'])){
@@ -86,160 +97,162 @@ class dhcpSubnet extends plugin
 
   function execute()
   {
-       $smarty= get_smarty();
-       $smarty->assign("cn", $this->cn);
-
-       if ($this->dn != "new"){
-               $smarty->assign("mode", "readonly");
-
-               list($na0, $na1, $na2, $na3)= split('\.', $this->cn);
-                for ($i= 0; $i<4; $i++){
-                        $name= "na$i";
-                        $smarty->assign("na$i", $$name);
-                }
-
-               /* Assign netmask */
-               list($nm0, $nm1, $nm2, $nm3)= split('\.', $this->dhcpNetMask);
-               for ($i= 0; $i<4; $i++){
-                       $name= "nm$i";
-                       $smarty->assign("nm$i", $$name);
-               }
-
-               /* Prepare range */
-               if ($this->dhcpRange != ""){
-                       list($r1, $r2)= preg_split('/\s+/', $this->dhcpRange);
-                       list($r00, $r01, $r02, $r03)= split('\.', $r1);
-                       for ($i= 0; $i<4; $i++){
-                               $name= "r0$i";
-                               $smarty->assign("r0$i", $$name);
-                       }
-                       list($r10, $r11, $r12, $r13)= split('\.', $r2);
-                       for ($i= 0; $i<4; $i++){
-                               $name= "r1$i";
-                               $smarty->assign("r1$i", $$name);
-                       }
-               }
-       }
-
-       /* Show main page */
-       return $smarty->fetch (get_template_path('dhcp_subnet.tpl', TRUE));
+    $smarty= get_smarty();
+    $smarty->assign("cn", $this->cn);
+    $smarty->assign("dhcp_netmask", $this->dhcpNetMask);
+
+    /* Prepare range */
+    if ($this->use_range){
+      $smarty->assign("use_range", "checked");
+      $smarty->assign("range_disabled", "");
+    } else {
+      $smarty->assign("use_range", "");
+      $smarty->assign("range_disabled", "disabled");
+    }
+    $smarty->assign("range_start", $this->range_start);
+    $smarty->assign("range_stop", $this->range_stop);
+
+    /* Show main page */
+    $display= $smarty->fetch(get_template_path('dhcp_subnet.tpl', TRUE)).$this->network->execute();
+
+    /* Merge arrays for advanced view */
+    foreach (array("options", "statements") as $type){
+      $tmp= array_merge($this->$type, $this->network->$type);
+      $this->advanced->$type= $tmp;
+    }
+
+    $display.= $this->advanced->execute();
+
+    /* Merge back for removals */
+    foreach (array("options", "statements") as $type){
+      $this->$type= $this->advanced->$type;
+      $this->network->$type= $this->advanced->$type;
+    }
+
+    /* Add footer */
+    $display.= "<div style='width:100%;text-align:right;margin-top:5px;'><input type=submit name='save_dhcp' value='"._("Save")."'>".
+               "&nbsp;<input type=submit name='cancel_dhcp' value='"._("Cancel")."'></div>";
+
+    /* Show main page */
+    return $display;
   }
 
+
   function remove_from_parent()
   {
-       /* Just remove the dn from the ldap, then we're done. Host
-          entries do not have any entries below themselfes. */
-       $ldap= $this->config->get_ldap_link();
-       $ldap->cd($this->dn);
-       $ldap->recursive_remove();
-       show_ldap_error($ldap->get_error());
-
-       /* Optionally execute a command after we're done */
-       $this->postremove();
   }
 
 
   /* Save data to object */
   function save_object()
   {
-       plugin::save_object();
+    if (isset($_POST['cn'])){
+      $this->cn= validate($_POST['cn']);
+    } 
+    if (isset($_POST['dhcp_netmask'])){
+      $this->dhcpNetMask= validate($_POST['dhcp_netmask']);
+    } 
+    if (isset($_POST['use_range'])){
+      $this->use_range= TRUE;
+      $this->range_start= validate($_POST['range_start']);
+      $this->range_stop= validate($_POST['range_stop']);
+    } else {
+      $this->use_range= FALSE;
+    }
+
+    /* Save sub-objects */
+    $this->network->save_object();
+    $this->advanced->save_object();
+
+    /* Merge arrays for advanced view */
+    foreach (array("options", "statements") as $type){
+      $tmp= array_merge($this->$type, $this->network->$type);
+      $this->advanced->$type= $tmp;
+    }
 
-       if (isset($_POST['na0'])){
-               $this->cn= $_POST['na0'].".".$_POST['na1'].".".$_POST['na2'].".".$_POST['na3'];
-               $this->dhcpNetMask= $_POST['nm0'].".".$_POST['nm1'].".".$_POST['nm2'].".".$_POST['nm3'];
-               $this->dhcpRange= $_POST['r00'].".".$_POST['r01'].".".$_POST['r02'].".".$_POST['r03']." ".$_POST['r10'].".".$_POST['r11'].".".$_POST['r12'].".".$_POST['r13'];
-       }
   }
 
 
   /* Check values */
-  function check()
+  function check($cache)
   {
-       $message= array();
-
-       /* All required fields are set? */
-       if ($this->cn == ""){
-               $message[]= _("Required field 'Network address' is not filled.");
-       }
-       if ($this->dhcpNetMask == ""){
-               $message[]= _("Required field 'Netmask' is not filled.");
-       }
-
-       /* cn already used? */
-       if ($this->dn != "new"){
-               $ldap= $this->config->get_ldap_link();
-               $ldap->cd($this->config->current['BASE']);
-               $ldap->search("(&(objectClass=dhcpSubnet)(cn=".$this->cn."))");
-               if ($ldap->count() >= 1){
-                       while ($attrs= $ldap->fetch()){
-                               if ($ldap->getDN() != $this->dn){
-                                       $message[]= _("The network defined in this section is already used!");
-                                       break;
-                               }
-
-                       }
-               }
-               $ldap->fetch();
-       }
-
-       #FIXME: There are some more things we could test -> valid netmask, range
-       return $message;
+    $message= array();
+
+    /* All required fields are set? */
+    if ($this->cn == ""){
+      $message[]= _("Required field 'Network address' is not filled.");
+    }
+    if ($this->dhcpNetMask == ""){
+      $message[]= _("Required field 'Netmask' is not filled.");
+    }
+
+    /* cn already used? */
+    if ($this->orig_cn != $this->cn || $this->new){
+
+      foreach($cache as $dn => $dummy){
+        if (preg_match("/^cn=".$this->cn.",/", $dn) && count($dummy)){
+          $message[]= _("The name for this section is already used!");
+          break;
+        }
+      }
+    }
+
+    /* IP's? */
+    foreach(array('dhcpNetMask' => _("Netmask"), 'cn' => _("Network address"), 'range_start' => _("Range"), 'range_stop' => _("Range")) as $attr => $str){
+      if ($this->$attr != "" && !is_ip($this->$attr)){
+        print_red(sprintf(_("The field '%s' contains an invalid IP address"), $str));
+      }
+    }
+
+    return $message;
   }
 
 
   /* Save to LDAP */
   function save()
   {
-       plugin::save();
-
-       /* Get ldap mode */
-       if ($this->dn == "new"){
-               $mode= "add";
-       } else {
-               $mode= "modify";
-       }
-
-       /* Generate new dn */
-       if ($this->parent->parent != NULL && $this->dn == "new"){
-                $this->dn= "cn=".$this->cn.",".$this->parent->parent;
-        }
+    /* Merge arrays for network and advanced view */
+    foreach (array("options", "statements") as $type){
+      $tmp= array_merge($this->$type, $this->network->$type, $this->advanced->$type);
+      $this->$type= $tmp;
+    }
 
-       /* Reconvert netmask to number of filled bits */
-       $this->attrs['dhcpNetMask']= netmask_to_bits($this->dhcpNetMask);
-       
-       /* Assemble new entry - options */
-       if (isset ($this->options) && count ($this->options)){
-               $this->attrs['dhcpOption']= array();
-               foreach ($this->options as $key => $val){
-                       $this->attrs['dhcpOption'][]= "$key $val";
-               }
-       } else {
-               if ($mode == "modify"){
-                       $this->attrs['dhcpOption']= array();
-               }
-       }
-       
-       /* Assemble new entry - statements */
-       if (isset ($this->statements) && count ($this->statements)){
-               $this->attrs['dhcpStatements']= array();
-               foreach ($this->statements as $key => $val){
-                       $this->attrs['dhcpStatements'][]= "$key $val";
-               }
-       } else {
-               if ($mode == "modify"){
-                       $this->attrs['dhcpStatements']= array();
-               }
-       }
-
-       /* Do LDAP action */
-       $ldap= $this->config->get_ldap_link();
-        if ($mode == "add"){
-               $ldap->cd($this->config->current['BASE']);
-                $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
-        }
-       $ldap->cd($this->dn);
-       $ldap->$mode($this->attrs);
-       show_ldap_error($ldap->get_error());
+    /* Add cn if we're new */
+    if ($this->new){
+      $this->dn= "cn=".$this->cn.",".$this->dn;
+    } else {
+      $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn);
+    }
+
+    /* Assemble new entry - options */
+    $this->attrs['dhcpOption']= array();
+    if (isset ($this->options) && count ($this->options)){
+      foreach ($this->options as $key => $val){
+        $this->attrs['dhcpOption'][]= "$key $val";
+      }
+    }
+
+    /* Assemble new entry - statements */
+    $this->attrs['dhcpStatements']= array();
+    if (isset ($this->statements) && count ($this->statements)){
+      foreach ($this->statements as $key => $val){
+        $this->attrs['dhcpStatements'][]= "$key $val";
+      }
+    }
+
+    /* Move dn to the result */
+    $this->attrs['dn']= $this->dn;
+    $this->attrs['cn']= array($this->cn);
+    $this->attrs['dhcpNetMask']= array(netmask_to_bits($this->dhcpNetMask));
+    if ($this->dhcpRange != ""){
+      $this->attrs['dhcpRange']= array($this->range_start." ".$this->range_stop);
+    } else {
+      $this->attrs['dhcpRange']= array();
+    }
+    $this->attrs['objectClass']= array('top', 'dhcpSubnet', 'dhcpOptions');
+    $this->attrs['MODIFIED']= TRUE;
+
+    return ($this->attrs);
   }
   
 }
index 37988c3a3c83707096bcc31e8f179c07ae046de3..f4749767e77a0e04272883db875991ca9b27bada 100644 (file)
@@ -22,7 +22,6 @@ class servdhcp extends plugin
             "dhcpService" => _("Global options"),
             "dhcpClass" => _("Class"),
             "dhcpSubClass" => _("Subclass"),
-            "dhcpLeases" => _("Lease"),
             "dhcpHost" => _("Host"),
             "dhcpGroup" => _("Group"),
             "dhcpPool" => _("Pool"),
@@ -334,7 +333,7 @@ class servdhcp extends plugin
 
       /* Read all sub entries to place here */
       $ldap->cd($value['dn']);
-      $ldap->search("(|(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(objectClass=dhcpLeases)(objectClass=dhcpHost)(objectClass=dhcpGroup)(objectClass=dhcpPool)(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork)(objectClass=dhcpOptions)(objectClass=dhcpTSigKey)(objectClass=dhcpDnsZone)(objectClass=dhcpFailOverPeer))", array());
+      $ldap->search("(|(objectClass=dhcpLog)(objectClass=dhcpClass)(objectClass=dhcpSubClass)(objectClass=dhcpHost)(objectClass=dhcpGroup)(objectClass=dhcpPool)(objectClass=dhcpSubnet)(objectClass=dhcpSharedNetwork)(objectClass=dhcpOptions)(objectClass=dhcpTSigKey)(objectClass=dhcpDnsZone)(objectClass=dhcpFailOverPeer))", array());
       $this->serviceDN= $value['dn'];
 
       while ($attrs= $ldap->fetch()){
index b00ed71c5c43aa0c5a0d7f3e92bb3727766edaf6..a392861b7b921d2fdcd2f1522623842becf1a693 100644 (file)
@@ -1,10 +1,8 @@
 {* GOsa dhcp sharedNetwork - smarty template *}
-<br>
 <table width="100%">
  <tr>
   <td width="50%" style="vertical-align:top">
-   <b>{t}Network base configuration{/t}</b>
-   <br>
+   <p><b>{t}Network configuration{/t}</b></p>
    <table>
     <tr>
      <td>{t}Router{/t}</td>
@@ -28,7 +26,7 @@
    </table>
    <br>
    <br>
-   <b>{t}Bootup{/t}</b>
+   <p><b>{t}Bootup{/t}</b></p>
    <table>
     <tr>
      <td>{t}Filename{/t}</td>
@@ -48,8 +46,7 @@
   
   </td>
   <td style="vertical-align:top">
-   <b>{t}Domain Name Service{/t}</b>
-   <br>
+   <p><b>{t}Domain Name Service{/t}</b></p>
    <table>
     <tr>
      <td>{t}Domain{/t}</td>
@@ -73,8 +70,7 @@
     </tr>
     <tr>
      <td colspan=2>
-      <br>
-      <b>{t}Domain Name Service options{/t}</b><br>
+      <p><b>{t}Domain Name Service options{/t}</b></p>
       <input type=checkbox name="autohost" value="1" {$autohost}>{t}Assign hostnames found via reverse mapping{/t}
       <br>
       <input type=checkbox name="autohostdecl" value="1" {$autohostdecl}>{t}Assign hostnames from host declarations{/t}
index 8a68a2b761ac6f6af58de43a163fc69ce06f5282..9174d152ac329137c3d1dfb69ae8734147124b49 100644 (file)
@@ -1,47 +1,41 @@
 {* GOsa dhcp subnet - smarty template *}
-<br>
+<p><b>{t}Generic{/t}</b></p>
 <table width="100%">
  <tr>
   <td width="50%">
-   <b>{t}Network address{/t}{$must}</b>&nbsp;
-   <input type='text' name='na0' size='3' maxlength='3' value='{$na0}' {$mode}><b>.</b>
-   <input type='text' name='na1' size='3' maxlength='3' value='{$na1}' {$mode}><b>.</b>
-   <input type='text' name='na2' size='3' maxlength='3' value='{$na2}' {$mode}><b>.</b>
-   <input type='text' name='na3' size='3' maxlength='3' value='{$na3}' {$mode}>
+   <table>
+    <tr>
+     <td>{t}Network address{/t}{$must}</td>
+     <td><input type='text' name='cn' size='25' maxlength='80' value='{$cn}'></td>
+    </tr>
+    <tr>
+     <td>{t}Netmask{/t}{$must}</td>
+     <td><input type='text' name='dhcp_netmask' size='25' maxlength='80' value='{$dhcp_netmask}'></tr>
+   </table>
   </td>
-  <td>
-   <b>{t}Netmask{/t}{$must}</b>&nbsp;
-   <input type='text' name='nm0' size='3' maxlength='3' value='{$nm0}'><b>.</b>
-   <input type='text' name='nm1' size='3' maxlength='3' value='{$nm1}'><b>.</b>
-   <input type='text' name='nm2' size='3' maxlength='3' value='{$nm2}'><b>.</b>
-   <input type='text' name='nm3' size='3' maxlength='3' value='{$nm3}'>
+  <td style='vertical-align:top'>
+   <table>
+    <tr>
+     <td><input type="checkbox" name="use_range" value="1" onChange="changeState('range_start');changeState('range_stop');" {$use_range}></td>
+     <td>{t}Range for dynamic address assignement{/t}</td>
+  </tr>
+  <tr>
+  <td>&nbsp;</td>
+  <td><input type='text' id='range_start' name='range_start' size='25' maxlength='80' value='{$range_start}' {$range_disabled}>
+  &nbsp;<b>-</b>&nbsp;
+  <input type='text' id='range_stop' name='range_stop' size='25' maxlength='80' value='{$range_stop}' {$range_disabled}>
   </td>
- </tr>
-</table>
-
-<p class="seperator">&nbsp;</p>
-
-<table width="100%">
- <tr>
-  <td>
-   <b>{t}Range for dynamic address assignement{/t}</b>&nbsp;
-   <input type='text' name='r00' size='3' maxlength='3' value='{$r00}'><b>.</b>
-   <input type='text' name='r01' size='3' maxlength='3' value='{$r01}'><b>.</b>
-   <input type='text' name='r02' size='3' maxlength='3' value='{$r02}'><b>.</b>
-   <input type='text' name='r03' size='3' maxlength='3' value='{$r03}'>&nbsp;<b>-</b>&nbsp;
-   <input type='text' name='r10' size='3' maxlength='3' value='{$r10}'><b>.</b>
-   <input type='text' name='r11' size='3' maxlength='3' value='{$r11}'><b>.</b>
-   <input type='text' name='r12' size='3' maxlength='3' value='{$r12}'><b>.</b>
-   <input type='text' name='r13' size='3' maxlength='3' value='{$r13}'>
+  </tr>
+  </table>
   </td>
- </tr>
 </tr>
 </table>
 
-<div style="height:150px;"></div>
+<p class="seperator"></p>
 
 <!-- Place cursor in correct field -->
 <script language="JavaScript" type="text/javascript">
   <!-- // First input field on page
-  document.mainform.na0.focus();
+  document.mainform.cn.focus();
   -->
 </script>