Code

Added tsig stuff from gosa-contrib
authorcajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sat, 8 May 2010 11:18:49 +0000 (11:18 +0000)
committercajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8>
Sat, 8 May 2010 11:18:49 +0000 (11:18 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18182 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpDnsZone.inc [new file with mode: 0644]
gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpNewSectionDialog.inc
gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpTSigKey.inc [new file with mode: 0644]
gosa-plugins/dhcp/admin/systems/services/dhcp/class_servDHCP.inc
gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_dnszone.tpl [new file with mode: 0644]
gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_tsigkey.tpl [new file with mode: 0644]

diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpDnsZone.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpDnsZone.inc
new file mode 100644 (file)
index 0000000..ddf3687
--- /dev/null
@@ -0,0 +1,201 @@
+<?php
+/*
+  This code is part of GOsa (https://gosa.gonicus.de)
+  Copyright (C) 2003-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 dhcpDnsZone extends dhcpPlugin
+{
+  /* Used attributes */
+  var $dhcpKeyDN="";
+  var $dhcpDnsZone="";
+  var $dhcpDnsZoneServer="";
+  var $cn="";
+
+  var $drop_down_domain= array();
+  var $drop_down_nameserver= array();
+  var $drop_down_tsigkey= array();
+               
+  /* attribute list for save action */
+  var $objectclasses= array("top", "dhcpDnsZone");
+
+
+  function dhcpDnsZone($parent,$attrs,$host_exists_in_gosa = FALSE)
+  {
+    global $config;
+    dhcpPlugin::dhcpPlugin($parent,$attrs);
+
+    /* Load attributes */
+    if (!$this->new){
+      $this->dhcpDnsZoneServer= $attrs['dhcpDnsZoneServer'][0];
+      $this->dhcpKeyDN= base64_encode($attrs['dhcpKeyDN'][0]);
+    }
+
+    // Prepare LDAP link
+    $ldap= $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+
+    /* Search for all objects, recursive, that match the given ldap filter.
+       each dyndns zoen have to depent of an alreday DNS Zone created so we search it
+     */
+
+    // Search for domain
+    $ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@))",array("zoneName"));
+    while($attrs = $ldap->fetch()){
+      $this->drop_down_domain[$attrs["zoneName"][0]]= $attrs["zoneName"][0];
+    }
+
+    $ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@))",array("nSRecord"));
+    while($attrs = $ldap->fetch()){
+      $this->drop_down_nameserver[$attrs["nSRecord"][0]]=$attrs["nSRecord"][0];
+    }
+
+    $ldap->search("(objectClass=dhcpTSigKey)",array("dn","cn"));
+    if ($ldap->count() != 0){
+      while($attrs = $ldap->fetch()){
+        $this->drop_down_tsigkey[base64_encode($attrs["dn"])]=$attrs["cn"][0];
+      }
+    }
+  }
+
+
+  function execute()
+  {
+    $smarty= get_smarty();
+    $smarty->assign("cn", $this->cn);
+    $smarty->assign("cns",$this->drop_down_domain);
+
+    $smarty->assign("dhcpDnsZoneServer", $this->dhcpDnsZoneServer);
+    $smarty->assign("dhcpDnsZoneServers",$this->drop_down_nameserver);
+
+    $smarty->assign("dhcpKeyDN", $this->dhcpKeyDN);
+    $smarty->assign("dhcpKeyDNs",$this->drop_down_tsigkey);
+
+    /* Assign ACLs */
+    $smarty->assign("acl",$this->parent->getacl(""));
+
+    /* Show main page */
+    $display= $smarty->fetch(get_template_path('dhcp_dnszone.tpl', TRUE,dirname(__FILE__)));
+
+    /* Add footer */
+    $display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
+    if(preg_match("/w/",$this->parent->getacl(""))){
+        $display.=   "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>&nbsp;";
+    }
+    $display.=   "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
+    $display.= "</div>";
+
+    return ($display);
+  }
+
+
+
+  function remove_from_parent()
+  {
+  }
+
+
+  /* Save data to object */
+  function save_object()
+  {
+    /* Save remaining attributes */
+    if (isset($_POST['dhcp_dnszone_posted']) && preg_match("/w/", $this->parent->getacl(""))){
+
+      if (isset($_POST['dhcpKeyDN'])){
+        $this->dhcpKeyDN= get_post('dhcpKeyDN');
+      }
+
+      if (isset($_POST['dhcpDnsZoneServer'])){
+        $this->dhcpDnsZoneServer= get_post('dhcpDnsZoneServer');
+      }
+      if (isset($_POST['cn'])){
+        $this->cn= get_post('cn');
+      }
+               
+    }
+
+    dhcpPlugin::save_object();
+  }
+
+
+  /* Check values */
+  function check()
+  {
+    $message= array();
+
+    $cache = array();
+    if(isset($this->parent) && isset($this->parent->dhcpObjectCache)){
+      $cache = $this->parent->dhcpObjectCache;
+    }
+  
+    /* All required fields are set? */
+    if ($this->cn == ""){
+      $message[]= msgPool::required(_("DNS zone"));
+    }
+
+    if ($this->dhcpDnsZoneServer == ""){
+      $message[]= msgPool::required(_("DNS server"));
+    }
+
+    if ($this->dhcpKeyDN == ""){
+      $message[]= msgPool::required(_("Key DN"));
+    }
+    
+
+    /* 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[]= msgPool::duplicated(_("Name"));
+          break;
+        }
+      }
+    }
+    
+    /* Check external plugins */
+    $net= $this->network->check();
+    $adv= $this->advanced->check();
+    $message= array_merge($message, $net, $adv);
+
+    return $message;
+  }
+
+
+  /* Save to LDAP */
+  function save()
+  {
+    dhcpPlugin::save();
+
+    if ($this->dhcpKeyDN != ""){
+      $this->attrs['dhcpKeyDN']= array(base64_decode($this->dhcpKeyDN));
+    } else {
+      $this->attrs['dhcpKeyDN']= array();
+    }
+
+    if ($this->dhcpDnsZoneServer != ""){
+      $this->attrs['dhcpDnsZoneServer']= array($this->dhcpDnsZoneServer);
+    } else {
+      $this->attrs['dhcpDnsZoneServer']= array();
+    }
+
+    return ($this->attrs);
+  }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 99f9af4bd04b913440835d974feb2ec25cc732d2..6a81c9e8c2ac984f00d242c951c4ff07751103d8 100644 (file)
@@ -10,14 +10,16 @@ class dhcpNewSectionDialog extends plugin
   /* Mapping array */
   var $types= array();
   var $classtype= "";
-  var $sectionMap= array(  "dhcpService" => array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost", "dhcpClass"),
+  var $sectionMap= array(  "dhcpService" => array("dhcpSharedNetwork", "dhcpSubnet", "dhcpGroup", "dhcpHost", "dhcpClass", "dhcpTSigKey", "dhcpDnsZone"),
                               "dhcpClass" => array("dhcpSubClass"),
                               "dhcpSubClass" => array(),
                               "dhcpHost" => array(),
                               "dhcpGroup" => array("dhcpHost"),
                               "dhcpPool" => array(),
-                              "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost", "dhcpClass"),
-                              "dhcpSharedNetwork" => array("dhcpSubnet", "dhcpPool"));
+                              "dhcpSubnet" => array("dhcpPool", "dhcpGroup", "dhcpHost", "dhcpClass", "dhcpTSigKey", "dhcpDnsZone"),
+                              "dhcpSharedNetwork" => array("dhcpSubnet", "dhcpPool", "dhcpTsigKey", "dhcpDnsZone"),
+                              "dhcpTSigKey"=> array(),
+                              "dhcpDnsZone" => array());
 
 
 
@@ -30,7 +32,9 @@ class dhcpNewSectionDialog extends plugin
                           "dhcpGroup" => _("Group"),
                           "dhcpPool" => _("Pool"),
                           "dhcpSubnet" => _("Subnet"),
-                          "dhcpSharedNetwork" => _("Shared network"));
+                          "dhcpSharedNetwork" => _("Shared network"),
+                          "dhcpTSigKey" => _("DNS update key"),
+                          "dhcpDnsZone" => _("DNS update zone") );
 
     $this->classtype= $type;
   }
diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpTSigKey.inc b/gosa-plugins/dhcp/admin/systems/services/dhcp/class_dhcpTSigKey.inc
new file mode 100644 (file)
index 0000000..900df11
--- /dev/null
@@ -0,0 +1,162 @@
+<?php
+/*
+  This code is part of GOsa (https://gosa.gonicus.de)
+  Copyright (C) 2003-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 dhcpTSigKey extends dhcpPlugin
+{
+  /* Used attributes */
+  var $dhcpKeyAlgorithm="";
+  var $dhcpKeySecret="";
+       
+  /* attribute list for save action */
+  var $objectclasses= array("top", "dhcpTSigKey");
+
+  function dhcpTSigKey($parent,$attrs)
+  {
+    dhcpPlugin::dhcpPlugin($parent,$attrs);
+
+    /* Load attributes */
+    if (!$this->new){
+      $this->dhcpKeyAlgorithm= $attrs['dhcpKeyAlgorithm'][0];
+      $this->dhcpKeySecret= $attrs['dhcpKeySecret'][0];
+    }
+
+  }
+
+  function execute()
+  {
+    $smarty= get_smarty();
+    $smarty->assign("cn", $this->cn);
+    $dhcpKeyAlgorithm=preg_replace('/\s.*$/', '', $this->dhcpKeyAlgorithm);
+    $smarty->assign("dhcpKeyAlgorithm",$dhcpKeyAlgorithm);
+    $smarty->assign("dhcpKeyAlgorithms",array("HMAC-MD5" => _("HMAC-MD5"),"RSAMD5" => _("RSAMD5"),"RSASHA1" => _("RSASHA1"),"DSA" => _("DSA"),"DH" => _("DH")));
+    $smarty->assign("dhcpKeySecret",$this->dhcpKeySecret);
+
+    /* Assign ACLs */
+    $smarty->assign("acl",$this->parent->getacl(""));
+
+
+    /* Show main page */
+    $display= $smarty->fetch(get_template_path('dhcp_tsigkey.tpl', TRUE,dirname(__FILE__)));
+
+
+    /* Add footer */
+    $display.= "<div style='width:100%;text-align:right;margin-top:5px;'>";
+    if(preg_match("/w/",$this->parent->getacl(""))){
+        $display.=   "<input type=submit name='save_dhcp' value='".msgPool::saveButton()."'>&nbsp;";
+    }
+    $display.=   "<input type=submit name='cancel_dhcp' value='".msgPool::cancelButton()."'>";
+    $display.= "</div>";
+
+    return ($display);
+  }
+
+
+  function remove_from_parent()
+  {
+  }
+
+
+  /* Save data to object */
+  function save_object()
+  {
+    /* Save remaining attributes */
+    if (isset($_POST['dhcp_tsigkey_posted']) && preg_match("/w/",$this->parent->getacl(""))){
+
+      if (isset($_POST['dhcpKeyAlgorithm'])){
+        $this->dhcpKeyAlgorithm=get_post('dhcpKeyAlgorithm');
+      }
+
+      if (isset($_POST['dhcpKeySecret'])){
+        $this->dhcpKeySecret=get_post('dhcpKeySecret');
+      }
+      if (isset($_POST['cn'])){
+        $this->cn=get_post('cn');
+      }
+               
+    }
+
+    dhcpPlugin::save_object();
+  }
+
+
+  /* Check values */
+  function check()
+  {
+    $message= array();
+
+    $cache = array();
+    if(isset($this->parent) && isset($this->parent->dhcpObjectCache)){
+      $cache = $this->parent->dhcpObjectCache;
+    }
+  
+    /* All required fields are set? */
+    if ($this->cn == ""){
+      $message[]= msgPool::required(_("Key name"));
+    }
+
+    if ($this->dhcpKeySecret == ""){
+      $message[]= msgPool::required(_("Key"));
+    }
+    
+
+    /* 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[]= msgPool::duplicated(_("Key name"));
+          break;
+        }
+      }
+    }
+    
+    /* Check external plugins */
+    $net= $this->network->check();
+    $adv= $this->advanced->check();
+    $message= array_merge($message, $net, $adv);
+
+    return $message;
+  }
+
+
+  /* Save to LDAP */
+  function save()
+  {
+    dhcpPlugin::save();
+
+     if ($this->dhcpKeyAlgorithm != ""){
+      $this->attrs['dhcpKeyAlgorithm']= array($this->dhcpKeyAlgorithm);
+    } else {
+      $this->attrs['dhcpKeyAlgorithm']= array();
+    }
+
+
+     if ($this->dhcpKeySecret != ""){
+      $this->attrs['dhcpKeySecret']= array($this->dhcpKeySecret);
+    } else {
+      $this->attrs['dhcpKeySecret']= array();
+    }
+
+    return ($this->attrs);
+  }
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index 656d9c8494d089d05f13fc022869c6ca88f2f80f..5c8d010868957bb492982516712e59a32aefc7e1 100644 (file)
@@ -44,7 +44,9 @@ class servdhcp extends goService
             "dhcpPool" => _("Pool"),
             "dhcpSubnet" => _("Subnet"),
             "dhcpFailOverPeer" => _("Failover peer"),
-            "dhcpSharedNetwork" => _("Shared network"));
+            "dhcpSharedNetwork" => _("Shared network"),
+            "dhcpTSigKey" => _("DNS update key"),
+            "dhcpDnsZone" => _("DNS update zone") );
 
 
     /* Backport: PHP4 compatibility  */
@@ -692,7 +694,8 @@ class servdhcp extends goService
   {
     $type= "";
     $types= array("dhcpService", "dhcpClass", "dhcpSubClass", "dhcpHost",
-                  "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork");
+                  "dhcpGroup", "dhcpPool", "dhcpSubnet", "dhcpSharedNetwork",
+                  "dhcpTSigKey", "dhcpDnsZone");
 
     foreach ($this->dhcpObjectCache[$dn]['objectClass'] as $oc){
       if (in_array($oc, $types)){
diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_dnszone.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_dnszone.tpl
new file mode 100644 (file)
index 0000000..4c8d32f
--- /dev/null
@@ -0,0 +1,39 @@
+{* GOsa dhcp host - smarty template *}
+<h3>{t}DNS update zone{/t}</h3>
+
+<table>
+ <tr>
+   <td>{t}DNS zone{/t}{$must}</td>
+   <td>
+     <select name='cn' > 
+       {html_options options=$cns selected=$cn}
+     </select>
+   </td>
+ </tr>
+   <td>{t}DNS server{/t}{$must}</td>
+   <td>
+     <select name='dhcpDnsZoneServer'  >
+       {html_options options=$dhcpDnsZoneServers selected=$dhcpDnsZoneServer}
+     </select>
+   </td>
+ </tr>
+ <tr>
+   <td>{t}Key DN{/t}{$must}</td>
+   <td>
+     <select name='dhcpKeyDN'>
+       {html_options options=$dhcpKeyDNs selected=$dhcpKeyDN}
+     </select>
+  </td>
+ </tr>
+</table>
+
+<input type='hidden' name='dhcp_dnszone_posted' value='1'>
+
+<hr>
+
+<!-- Place cursor in correct field -->
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+        focus_field('cn');
+  -->
+</script>
diff --git a/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_tsigkey.tpl b/gosa-plugins/dhcp/admin/systems/services/dhcp/dhcp_tsigkey.tpl
new file mode 100644 (file)
index 0000000..77f9861
--- /dev/null
@@ -0,0 +1,36 @@
+{* GOsa dhcp host - smarty template *}
+<h3>{t}DNS update key{/t}</h3>
+
+<table width="100%">
+ <tr>
+  <td>{t}Key name{/t}{$must}</td>
+  <td>
+   <input id='cn' type='text' name='cn' size='25' maxlength='80' value='{$cn}'
+          title='{t}Name of Key{/t}'>
+  </td>
+ </tr>
+ <tr>
+  <td>{t}Encryption method{/t}</td>
+  <td>
+   <select name='dhcpKeyAlgorithm'>
+    {html_options options=$dhcpKeyAlgorithms selected=$dhcpKeyAlgorithm}
+   </select>
+  </td>
+ </tr>
+ <tr>
+  <td>{t}Key{/t}{$must}</td>
+  <td>
+   <input  type='text' name='dhcpKeySecret' size='30' maxlength='30' value='{$dhcpKeySecret}'>
+  </td>
+ </tr>
+</table>
+
+<input type='hidden' name='dhcp_tsigkey_posted' value='1'>
+<hr>
+
+<!-- Place cursor in correct field -->
+<script language="JavaScript" type="text/javascript">
+  <!-- // First input field on page
+        focus_field('cn');
+  -->
+</script>