Code

Added non working version of sharedNetworks
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 8 Aug 2007 15:04:28 +0000 (15:04 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 8 Aug 2007 15:04:28 +0000 (15:04 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@7005 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_dhcpNewSectionDialog.inc
plugins/admin/systems/class_dhcpSharedNetwork.inc [new file with mode: 0644]
plugins/admin/systems/dhcp_sharedNetwork.tpl [new file with mode: 0644]

index 26188f5145a42d4461f05bb189b3b58040d50b22..32291f83e451f635e208fbe7cbdcdee942abe71b 100644 (file)
@@ -10,13 +10,13 @@ class dhcpNewSectionDialog extends plugin
   /* Mapping array */
   var $types= array();
   var $classtype= "";
-  static $sectionMap= array(  "dhcpService" => array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost", "dhcpClass"),
-                              "dhcpClass" => array("dhcpSubClass"),
+  static $sectionMap= array(  "dhcpService" => array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost" /*, "dhcpClass"*/),
+                              #"dhcpClass" => array("dhcpSubClass"),
                               "dhcpSubClass" => array(),
                               "dhcpHost" => array(),
                               "dhcpGroup" => array("dhcpHost"),
                               "dhcpPool" => array(),
-                              "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost", "dhcpClass"),
+                              "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost" /*, "dhcpClass"*/),
                               "dhcpSharedNetwork" => array("dhcpSubnet", "dhcpPool"));
 
 
@@ -24,7 +24,7 @@ class dhcpNewSectionDialog extends plugin
   function dhcpNewSectionDialog($type)
   {
     $this->types= array(  "dhcpService" => _("Global options"),
-                          "dhcpClass" => _("Class"),
+                          /*"dhcpClass" => _("Class"),*/
                           "dhcpSubClass" => _("Subclass"),
                           "dhcpHost" => _("Host"),
                           "dhcpGroup" => _("Group"),
diff --git a/plugins/admin/systems/class_dhcpSharedNetwork.inc b/plugins/admin/systems/class_dhcpSharedNetwork.inc
new file mode 100644 (file)
index 0000000..3e82b81
--- /dev/null
@@ -0,0 +1,260 @@
+<?php
+/*
+  This code is part of GOsa (https://gosa.gonicus.de)
+  Copyright (C) 2003  Cajus Pollmeier
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+class dhcpSharedNetwork extends plugin
+{
+  /* Used attributes */
+  var $cn= "";
+  var $options= array();
+  var $statements= array();
+
+  /* Subobjects */
+  var $network;
+  var $advanced;
+
+  /* attribute list for save action */
+  var $attributes= array();
+  var $objectclasses= array();
+
+  function dhcpSharedNetwork($attrs)
+  {
+    /* Load statements / options */
+    if (is_array($attrs)){
+      $this->dn= $attrs['dn'];
+      $this->cn= $attrs['cn'][0];
+      $this->new= FALSE;
+
+      /* Load options */
+      if (isset($attrs['dhcpOption'])){
+        foreach ($attrs['dhcpOption'] as $opt){
+          $idx= preg_replace('/\s.+$/', '', $opt);
+          $value= preg_replace('/^[^\s]+\s/', '', $opt);
+          $this->options[$idx]= $value;
+        }
+      }
+
+      /* Load statements */
+      if (isset($attrs['dhcpStatements'])){
+        foreach ($attrs['dhcpStatements'] as $opt){
+          $idx= preg_replace('/\s.+$/', '', $opt);
+          $value= preg_replace('/^[^\s]+\s/', '', $opt);
+          $this->statements[$idx]= $value;
+        }
+      }
+
+    } else {
+      /* We keep the parent dn here if it's new */
+      $this->dn= $attrs;
+      $this->new= TRUE;
+    }
+
+    /* Load network module */
+    $this->network= new dhcpNetwork();
+    $this->network->options= $this->options;
+    $this->network->statements= $this->statements;
+    $this->advanced= new dhcpAdvanced();
+    $this->advanced->options= $this->options;
+    $this->advanced->statements= $this->statements;
+
+    /* Save CN for later reference */
+    $this->orig_cn= $this->cn;
+  }
+
+
+  function execute()
+  {
+    $smarty= get_smarty();
+
+    /* Fill template */
+    $smarty->assign ("cn", $this->cn);
+    foreach (array("server-identifier", "default-lease-time", 
+          "max-lease-time", "min-lease-time") as $attr){
+      if (isset($this->statements[$attr])){
+        $smarty->assign(preg_replace('/-/', '_', $attr), $this->statements[$attr]);
+      }
+    }
+    if ($this->dn != 'new'){
+      $smarty->assign("mode", "readonly");
+    }
+    if (isset($this->statements["authoritative"])){
+      $smarty->assign("authoritative", "checked");
+    }
+    if (!isset($this->statements["deny-unknown-clients"])){
+      $smarty->assign("allow_unknown_state", "checked");
+    }
+    if (!isset($this->statements["deny-bootp"])){
+      $smarty->assign("allow_bootp_state", "checked");
+    }
+    if (!isset($this->statements["deny-booting"])){
+      $smarty->assign("allow_booting_state", "checked");
+    }
+
+    /* Show main page */
+    $display= $smarty->fetch(get_template_path('dhcp_sharedNetwork.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>";
+
+
+    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()
+  {
+       if (isset($_POST['cn'])){
+               plugin::save_object();
+
+               foreach (array("server-identifier", "default-lease-time",
+                               "max-lease-time", "min-lease-time") as $attr){
+                       if (isset($_POST[$attr]) && $_POST[$attr] != ""){
+                               $this->statements[$attr]= $_POST[$attr];
+                       } else {
+                               unset($this->statements[$attr]);
+                       }
+               }
+       
+               if (isset($_POST["authoritative"])){
+                       $this->statements["authoritative"]= "";
+               } else {
+                       unset ($this->statements["authoritative"]);
+               }
+       
+               foreach(array("unknown-clients", "bootp", "booting") as $name){
+                       if (isset($_POST[$name])){
+                               $this->statements["allow-$name"]= "";
+                               unset($this->statements["deny-$name"]);
+                       } else {
+                               $this->statements["deny-$name"]= "";
+                               unset($this->statements["allow-$name"]);
+                       }
+               }
+       }
+  }
+
+
+  /* Check values */
+  function check()
+  {
+       $message= array();
+
+       /* Check lease times */
+       foreach (array("default-lease-time" => _("Default lease time"),
+                       "max-lease-time" => _("Max. lease time"),
+                       "min-lease-time" => _("Min. lease time")) as $key => $val){
+               if (isset($this->statements[$key]) && $this->statements[$key] != "" && 
+                       !is_id($this->statements[$key])){
+                       $message[]= sprintf(_("The value specified as '%s' is no valid integer!"), $val);
+               }
+       }
+
+       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;
+        }
+
+        /* 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){
+                       if (preg_match('/^allow-/', $key) || preg_match('/^deny-/', $key)){
+                               $val= preg_replace('/^[^-]+-/', '', $key);
+                               $key= preg_replace('/^([^-]+)-.*$/', '\\1', $key);
+                       }
+                        $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());
+  }
+  
+}
+
+?>
diff --git a/plugins/admin/systems/dhcp_sharedNetwork.tpl b/plugins/admin/systems/dhcp_sharedNetwork.tpl
new file mode 100644 (file)
index 0000000..339db41
--- /dev/null
@@ -0,0 +1,108 @@
+{* GOsa dhcp sharedNetwork - smarty template *}
+<p><b>{t}Generic{/t}</b></p>
+<table width="100%" border="0">
+ <tr>
+
+  <td width="50%">
+
+   <table>
+    <tr>
+     <td>{t}Name{/t}{$must}</td>
+     <td>
+      <input type='text' name='cn' size='25' maxlength='80' value='{$cn}'
+       title='{t}Name for shared network{/t}' {$mode}>
+     </td>
+    </tr>
+    <tr>
+     <td>{t}Server identifier{/t}</td>
+     <td>
+      <input type='text' name='server-identifier' size='25' maxlength='80' value='{$server_identifier}'
+       title='{t}Propagated server identifier for this shared network{/t}'>
+     </td>
+    </tr>
+   </table>
+  
+  </td>
+  
+  <td style="vertical-align:top;">
+   <table>
+    <tr>
+     <td>
+      <input type=checkbox name="authoritative" value="1" {$authoritative}
+       title="{t}Select if this server is authoritative for this shared network{/t}">{t}Authoritative server{/t}
+     </td>
+    </tr>
+   </table>
+  </td>
+  
+ </tr>
+</table>
+
+<p class="seperator">&nbsp;</p>
+
+<table width="100%">
+ <tr>
+  <td width="50%">
+  
+  <p><b>{t}Leases{/t}</b></p>
+   <table>
+    <tr>
+     <td>{t}Default lease time{/t}</td>
+     <td>
+      <input type='text' name='default-lease-time' size='10' maxlength='25' value='{$default_lease_time}'
+        title='{t}Default lease time{/t}'>&nbsp;{t}seconds{/t}
+     </td>
+    </tr>
+    <tr>
+     <td>{t}Max. lease time{/t}</td>
+     <td>
+      <input type='text' name='max-lease-time' size='10' maxlength='25' value='{$max_lease_time}'
+        title='{t}Maximum lease time{/t}'>&nbsp;{t}seconds{/t}
+     </td>
+    </tr>
+    <tr>
+     <td>{t}Min. lease time{/t}</td>
+     <td>
+      <input type='text' name='min-lease-time' size='10' maxlength='25' value='{$min_lease_time}'
+        title='{t}Minimum lease time{/t}'>&nbsp;{t}seconds{/t}
+     </td>
+    </tr>
+   </table>
+   
+  </td>
+
+  <td style="vertical-align:top">
+   <p><b>{t}Access control{/t}</b></p>
+   <table>
+    <tr>
+     <td>
+     <input type=checkbox name="unknown-clients" value="1" {$allow_unknown_state}
+        title="{t}Select if unknown clients should get dynamic IP addresses{/t}">{t}Allow unknown clients{/t}
+     </td>
+    </tr>
+    <tr>
+     <td>
+     <input type=checkbox name="bootp" value="1" {$allow_bootp_state}
+        title="{t}Select if bootp clients should get dynamic IP addresses{/t}">{t}Allow bootp clients{/t}
+     </td>
+    </tr>
+    <tr>
+     <td>
+     <input type=checkbox name="booting" value="1" {$allow_booting_state}
+        title="{t}Select if clients are allowed to boot using this DHCP server{/t}">{t}Allow booting{/t}
+     </td>
+    </tr>
+   </table>
+  </td>
+  
+ </tr> 
+</table>
+
+<p class="seperator">&nbsp;</p>
+
+<!-- Place cursor in correct field -->
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+  document.mainform.cn.focus();
+  -->
+</script>