Code

Updated (still non-working) dhcp service plugin
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 1 Aug 2007 16:22:29 +0000 (16:22 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 1 Aug 2007 16:22:29 +0000 (16:22 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@6955 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_dhcpAdvanced.inc [new file with mode: 0644]
plugins/admin/systems/class_dhcpHost.inc
plugins/admin/systems/class_dhcpNetwork.inc [new file with mode: 0644]
plugins/admin/systems/dhcp_advanced.tpl [new file with mode: 0644]
plugins/admin/systems/dhcp_network.tpl [new file with mode: 0644]
plugins/admin/systems/dhcphost.tpl

diff --git a/plugins/admin/systems/class_dhcpAdvanced.inc b/plugins/admin/systems/class_dhcpAdvanced.inc
new file mode 100644 (file)
index 0000000..e9a40c1
--- /dev/null
@@ -0,0 +1,104 @@
+<?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 dhcpAdvanced extends plugin
+{
+  /* Used attributes */
+  var $options= array();
+  var $statements= array();
+
+  /* attribute list for save action */
+  var $attributes= array();
+  var $objectclasses= array();
+
+  function dhcpAdvanced()
+  {
+    /* This is always an account */
+    $this->is_account= TRUE;
+  }
+
+  function execute()
+  {
+    /* Check for interaction */
+    if (isset($_POST['add_statement']) && $_POST['addstatement'] != ""){
+      $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['addstatement']);
+      $val= preg_replace("/^$key\s*/", '', $_POST['addstatement']);
+      $this->statements[$key]= $val;
+    }
+    if (isset($_POST['delete_statement']) && isset($_POST['dhcpstatements'])){
+      $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['dhcpstatements']);
+      unset($this->statements[$key]);  
+    }
+    if (isset($_POST['add_option']) && $_POST['addoption'] != ""){
+      $key= preg_replace('/^([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['addoption']);
+      $val= preg_replace("/^$key\s*/", '', $_POST['addoption']);
+      $this->options[$key]= $val;
+    }
+    if (isset($_POST['delete_option']) && isset($_POST['dhcpoptions'])){
+      $key= preg_replace('/([a-z0-9-]+)\s(.*)$/', '\\1', $_POST['dhcpoptions']);
+      unset($this->options[$key]);     
+    }
+
+    $smarty= get_smarty();
+
+    /* Assign arrays */
+    $statements= array();
+    foreach ($this->statements as $key => $val){
+      $statements[$key]= "$key $val";
+    }
+    $smarty->assign("dhcpstatements", $statements);
+    $options= array();
+    foreach ($this->options as $key => $val){
+      $options[$key]= "$key $val";
+    }
+    $smarty->assign("dhcpoptions", $options);
+
+    /* Show main page */
+    return ($smarty->fetch (get_template_path('dhcp_advanced.tpl', TRUE)));
+  }
+
+  function remove_from_parent()
+  {
+  }
+
+
+  /* Save data to object */
+  function save_object()
+  {
+  }
+
+
+  /* Check values */
+  function check()
+  {
+    /* Nothing to check here */
+    $message= array();
+    return $message;
+  }
+
+
+  /* Save to LDAP */
+  function save()
+  {
+  }
+
+}
+
+?>
index 6a3092dc544429f8f6ba4e7046f5981074217eed..2f65738567d1c1b537f9e690cda01e5571fe2016 100644 (file)
@@ -74,6 +74,9 @@ class dhcpHost extends plugin
     $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;
   }
 
   function execute()
@@ -97,7 +100,7 @@ class dhcpHost extends plugin
           "token-ring" => _("Token Ring")));
 
     /* Show main page */
-    return($smarty->fetch(get_template_path('dhcphost.tpl', TRUE)).$this->network->execute());
+    return($smarty->fetch(get_template_path('dhcphost.tpl', TRUE)).$this->network->execute().$this->advanced->execute());
   }
 
 
diff --git a/plugins/admin/systems/class_dhcpNetwork.inc b/plugins/admin/systems/class_dhcpNetwork.inc
new file mode 100644 (file)
index 0000000..c3d97de
--- /dev/null
@@ -0,0 +1,245 @@
+<?php
+/*
+  This code is part of GOsa (https://gosa.gonicus.de)
+  Copyright (C) 2004-2007  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 dhcpNetwork extends plugin
+{
+  /* Used attributes */
+  var $options= array();
+  var $statements= array();
+
+  /* attribute list for save action */
+  var $attributes= array();
+  var $objectclasses= array();
+
+  function dhcpNetwork()
+  {
+    /* This is always an account */
+    $this->is_account= TRUE;
+  }
+
+  function execute()
+  {
+    /* Check for iteraction */
+    if (isset($_POST['add_dns']) && $_POST['addserver'] != ""){
+      if (!preg_match('/^[0-9a-z.-]+$/', $_POST['addserver'])){
+        print_red(_("The name of the DNS server your're going to add is not valid!"));
+      } else {
+        $servers= array();
+        if (isset($this->options['domain-name-servers'])){
+          foreach(split(",", $this->options['domain-name-servers']) as $val){
+            $servers[$val]= $val;
+          }
+        }
+        $servers[$_POST['addserver']]= $_POST['addserver'];
+        $tmp= "";
+        foreach($servers as $val){
+          $tmp.= $val.",";
+        }
+        $this->options['domain-name-servers']= preg_replace('/,$/', '', $tmp);
+      }
+    }
+    if (isset($_POST['delete_dns']) && isset($_POST['dnsserver'])){
+      $tmp= preg_replace("/(\s*,\s*)?".$_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 */
+    $smarty= get_smarty();
+
+    /*
+     * Assemble options
+     */
+
+    /* Router */
+    if (isset($this->options['routers'])){
+      $smarty->assign("routers", $this->options['routers']);
+    } else {
+      $smarty->assign("routers", "");
+    }
+
+    /* DNS */
+    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(",", $this->options['domain-name-servers']) as $val){
+        $servers[$val]= $val;
+      }
+      $smarty->assign("dnsservers", $servers);
+    } else {
+      $smarty->assign("dnsservers", "");
+    }
+
+    /* Netmask / Broadcast */
+    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", "");
+    }
+    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'])){
+      $smarty->assign("filename", trim($this->statements['filename'], '"'));
+    } else {
+      $smarty->assign("filename", "");
+    }
+    if (isset($this->statements['next-server'])){
+      $smarty->assign("nextserver", trim($this->statements['next-server'], '"'));
+    } else {
+      $smarty->assign("nextserver", "");
+    }
+
+    /* Set flags */
+    $smarty->assign("autohost", "");
+    if (isset($this->statements['get-lease-hostnames'])){
+      if (preg_match('/^(true|on|yes)$/', $this->statements['get-lease-hostnames'])){
+        $smarty->assign("autohost", "checked");
+      }
+    }
+    $smarty->assign("autohostdecl", "");
+    if (isset($this->statements['use-host-decl-names'])){
+      if (preg_match('/^(true|on|yes)$/', $this->statements['use-host-decl-names'])){
+        $smarty->assign("autohostdecl", "checked");
+      }
+    }
+
+    return $smarty->fetch(get_template_path('dhcp_network.tpl', TRUE));
+  }
+
+  function remove_from_parent()
+  {
+  }
+
+
+  /* Save data to object */
+  function save_object()
+  {
+    /* Only save, if we are "active" */
+    if (isset($_POST['routers'])){
+
+      /*
+       * Assemble options
+       */
+
+      /* Options */
+      foreach (array("routers" => "routers", "domain-name" => "domain") as $key => $val){
+
+        if ($_POST["$val"] == ''){
+          unset($this->options["$key"]);
+        } else {
+          $this->options["$key"]= $_POST["$val"];
+        }
+      }
+
+      /* Statements */
+      foreach (array("filename" => "filename", "next-server" => "nextserver") as $key => $val){
+        if ($_POST["$val"] == ''){
+          unset($this->statements["$key"]);
+        } else {
+          $this->statements["$key"]= '"'.$_POST["$val"].'"';
+        }
+      }
+
+      /* Netmask / Broadcast */
+      foreach (array("subnet-mask" => "nm", "broadcast-address" => "bc")
+          as $key => $val){
+
+        $tmp= "";
+        for ($i= 0; $i<4; $i++){
+          $tmp.= $_POST["$val$i"].".";
+        }
+        if ($tmp == "...."){
+          unset($this->options["$key"]);
+        } else {
+          $this->options["$key"]= preg_replace('/\.$/', '', $tmp);
+        }
+      }
+
+      /* Flags */
+      if (isset ($_POST['autohost'])){
+        $this->statements['get-lease-hostnames']= "true";
+      } else {
+        unset($this->statements['get-lease-hostnames']);
+      }
+      if (isset ($_POST['autohostdecl'])){
+        $this->statements['use-host-decl-names']= "on";
+      } else {
+        unset($this->statements['use-host-decl-names']);
+      }
+    }
+  }
+
+
+  /* Check values */
+  function check()
+  {
+    $message= array();
+
+    /* Check netmask and broadcast */
+    foreach(array("subnet-mask" => _("Netmask"), "broadcast-address" => _("Broadcast")) as $key => $typ){
+      if (!isset($this->options["$key"])){
+        continue;
+      }
+      $tmp= preg_replace('/^[^\s]+\s/', '', $this->options["$key"]);
+
+      list($n0,$n1,$n2,$n3)= split('\.', $tmp);
+      for ($i= 0; $i<4; $i++){
+        $name= "n$i";
+        if (preg_match('/^[0-9]+$/', $$name)){
+          $val= (int)($$name);
+          if ($val < 0 || $val > 255){
+            $message[]= sprintf(_("Error in definition of '%s'!"), $typ);
+            break;
+          }
+        } else {
+          $message[]= sprintf(_("Illegal characters in definition of '%s'!"), $typ);
+          break;
+        }
+      }
+    }
+
+    #FIXME: There are some more things we could test -> valid netmask, range
+    return $message;
+  }
+
+
+  /* Save to LDAP */
+  function save()
+  {
+  }
+  
+}
+
+?>
diff --git a/plugins/admin/systems/dhcp_advanced.tpl b/plugins/admin/systems/dhcp_advanced.tpl
new file mode 100644 (file)
index 0000000..e155a4c
--- /dev/null
@@ -0,0 +1,33 @@
+{* GOsa dhcp sharedNetwork - smarty template *}
+
+<table width="100%">
+ <tr>
+
+  <td width="50%">
+   <br>
+   <b>{t}DHCP statements{/t}</b>
+   <br>
+   <select name='dhcpstatements' style="width:350px;" size="14">
+    {html_options values=$dhcpstatements output=$dhcpstatements}
+   </select>
+   <br>
+   <input type='text' name='addstatement' size='25' maxlength='80'>&nbsp;
+   <input type='submit' name='add_statement' value='{t}Add{/t}'>&nbsp;
+   <input type='submit' name='delete_statement' value='{t}Delete{/t}'> 
+  </td>
+
+  <td>
+   <br>
+   <b>{t}DHCP options{/t}</b>
+   <br>
+   <select name='dhcpoptions' style="width:350px;" size="14">
+    {html_options values=$dhcpoptions output=$dhcpoptions}
+   </select>
+   <br>
+   <input type='text' name='addoption' size='25' maxlength='80'>&nbsp;
+   <input type='submit' name='add_option' value='{t}Add{/t}'>&nbsp;
+   <input type='submit' name='delete_option' value='{t}Delete{/t}'> 
+  </td>
+ </tr>
+</table>
+
diff --git a/plugins/admin/systems/dhcp_network.tpl b/plugins/admin/systems/dhcp_network.tpl
new file mode 100644 (file)
index 0000000..b00ed71
--- /dev/null
@@ -0,0 +1,88 @@
+{* 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>
+   <table>
+    <tr>
+     <td>{t}Router{/t}</td>
+     <td>
+      <input type='text' name='routers' size='25' maxlength='80' value='{$routers}'
+              title='{t}Enter name or IP address of router to be used in this section{/t}'>
+     </td>
+    </tr>
+    <tr>
+     <td>{t}Netmask{/t}</td>
+     <td>
+      <input type='text' name='subnet_mask' size='18' maxlength='15' value='{$subnet_mask}'>
+     </td>
+    </tr>
+    <tr>
+     <td>{t}Broadcast{/t}</td>
+     <td>
+      <input type='text' name='broadcast_address' size='18' maxlength='15' value='{$broadcast_address}'>
+     </td>
+    </tr>
+   </table>
+   <br>
+   <br>
+   <b>{t}Bootup{/t}</b>
+   <table>
+    <tr>
+     <td>{t}Filename{/t}</td>
+     <td>
+      <input type='text' name='filename' size='25' maxlength='80' value='{$filename}'
+              title='{t}Enter name of file that will be loaded via tftp after client has started{/t}'>
+     </td>
+    </tr>
+    <tr>
+     <td>{t}Next server{/t}</td>
+     <td>
+      <input type='text' name='nextserver' size='25' maxlength='80' value='{$nextserver}'
+              title='{t}Enter name of server to retrieve bootimages from{/t}'>
+     </td>
+    </tr>
+   </table>
+  
+  </td>
+  <td style="vertical-align:top">
+   <b>{t}Domain Name Service{/t}</b>
+   <br>
+   <table>
+    <tr>
+     <td>{t}Domain{/t}</td>
+     <td>
+      <input type='text' name='domain' size='25' maxlength='80' value='{$domain}'
+              title='{t}Name of domain{/t}'>
+     </td>
+    </tr>
+    <tr>
+     <td colspan=2>
+      <br>
+      {t}Server{/t}<br>
+      <select name='dnsserver'  title='{t}List of DNS servers to be propagated{/t}' style="width:350px;" size="4">
+       {html_options options=$dnsservers}
+      </select>
+      <br>
+      <input type='text' name='addserver' size='25' maxlength='80' title='{t}DNS server do be added{/t}'>&nbsp;
+      <input type='submit' name='add_dns' value='{t}Add{/t}' title='{t}Click here add the selected server to the list{/t}'>
+      <input type='submit' name='delete_dns' value='{t}Delete{/t}' title='{t}Click here remove the selected servers from the list{/t}'>
+     </td>
+    </tr>
+    <tr>
+     <td colspan=2>
+      <br>
+      <b>{t}Domain Name Service options{/t}</b><br>
+      <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}
+     </td>
+    </tr>
+   </table>
+  
+  </td>
+ </tr>
+</table>
+
index 21511c0d4efc2a7d50f9754c24ef61ee6bfa1d84..dc1b1912a0183b81d8589431d4e2b2a13b1936ff 100644 (file)
 <!-- Include advanced settings -->
 
 
+<div style='background-color:#F09090;width:100%;height:20px;text-align:right'>
 Temporary escape:
 <input type=submit name="cancel_section" value="{t}Escape{/t}">
-
+</div>
 
 <!-- Place cursor in correct field -->
 <script language="JavaScript" type="text/javascript">