summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d08b305)
raw | patch | inline | side by side (parent: d08b305)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 1 Feb 2006 09:32:25 +0000 (09:32 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 1 Feb 2006 09:32:25 +0000 (09:32 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2610 594d385d-05f5-0310-b6e9-bd551577e9d8
plugins/admin/systems/class_termDNS.inc | patch | blob | history | |
plugins/admin/systems/network.tpl | patch | blob | history | |
plugins/admin/systems/termdns.tpl | [deleted file] | patch | blob | history |
index f3cfc4ed6693935e0c90cb9d5d4f98bbe50781b8..156cafee90ddd59bb7469e5503dc70df6bf6d2ad 100644 (file)
/* attribute list for save action */
var $ignore_account= TRUE;
+ var $DNSattributes = array("dNSClass","zoneName","dNSTTL");
var $attributes= array("ipHostNumber","macAddress");
var $objectclasses= array("whatever");
- var $ipHostNumber ="";
- var $macAddress ="";
+ var $ipHostNumber =""; // IP address
+ var $macAddress =""; // Mac address
+ var $cn =""; // CN of currently edited device
+
+ var $Zones = array(); // All Available Zones like array("3.2.1.in-addr.arpa"=>"MyServer.de")
+ var $RecordTypes= array(); // Possible record types
+
+ var $dNSClass = "IN"; // dNSClass name
+ var $zoneName = ""; // Used ZoneName
+ var $dNSTTL = 7200; // TTL settings for the created entries
+
+ /* Used records */
+ var $types = array();
+ var $DNSinitially_was_account = false;
function termDNS ($config, $dn,$objectClasses)
{
+ /* We need to know which objectClasses are used, to store the ip/mac*/
$this->objectclasses= $objectClasses;
plugin::plugin ($config, $dn);
+
+ /* All types with required attrs */
+ $this->RecordTypes['aRecord'] ="aRecord";
+ $this->RecordTypes['MDRecord'] ="";
+ $this->RecordTypes['mXRecord'] ="mXRecord";
+ $this->RecordTypes['nSRecord'] ="nSRecord";
+ $this->RecordTypes['pTRRecord'] ="relativeDomainName";
+ $this->RecordTypes['HINFORecord'] ="";
+ $this->RecordTypes['MINFORecord'] ="";
+ $this->RecordTypes['cNAMERecord'] ="relativeDomainName";
+ $this->RecordTypes['tXTRecord'] ="tXTRecord";
+ $this->RecordTypes['AFSDBRecord'] ="";
+ $this->RecordTypes['SIGRecord'] ="";
+ $this->RecordTypes['KEYRecord'] ="";
+ $this->RecordTypes['AAAARecord'] ="";
+ $this->RecordTypes['LOCRecord'] ="";
+ $this->RecordTypes['NXTRecord'] ="";
+ $this->RecordTypes['SRVRecord'] ="";
+ $this->RecordTypes['NAPTRRecord'] ="";
+ $this->RecordTypes['KXRecord'] ="";
+ $this->RecordTypes['CERTRecord'] ="";
+ $this->RecordTypes['A6Record'] ="";
+ $this->RecordTypes['DSRecord'] ="";
+ $this->RecordTypes['SSHFPRecord'] ="";
+ $this->RecordTypes['RRSIGRecord'] ="";
+ $this->RecordTypes['NSECRecord'] ="";
+
+ /* Get all available zones */
+ $this->cn = $this->attrs['cn'][0];
+ $this->Zones = $this->get_Zones();
+ $types = array();
+
+ /* Get all records */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->dn);
+ $ldap->search("(&(objectClass=dNSZone)(zoneName=*))",array("*"));
+
+ while($attrs = $ldap->fetch()){
+ /* If relative domainname == cn
+ * Try to read dnsclass / TTl / zone
+ */
+ if($attrs['relativeDomainName'][0] == $this->cn){
+ /* Get class */
+ if(isset($attrs['dNSClass'][0])){
+ $this->dNSClass = $attrs['dNSClass'][0];
+ }
+ /* Get Zone*/
+ if(isset($attrs['zoneName'][0])){
+ $this->zoneName = $attrs['zoneName'][0];
+ }
+ /* Get ttl */
+ if(isset($attrs['dNSTTL'][0])){
+ $this->dNSTTL = $attrs['dNSTTL'][0];
+ }
+ }
+
+ /* Create list with all used records */
+ foreach($this->RecordTypes as $name => $value){
+
+ /* If there is a record attribute */
+ if(isset($attrs[$name])){
+
+ /* get all entries */
+ for($i = 0 ; $i < $attrs[$value]['count']; $i ++){
+ $types[] =array("type"=>$name,"value"=>$attrs[$value][$i],"status"=>"edited","dn"=>$attrs['dn']);
+ }
+ }
+ }
+ }
+
+ /* If there is at least one entry in this -> types, we have DNS enabled */
+ $this->types = $types;
+ if(count($this->types) == 0){
+ $this->DNS_is_account = false;
+ }else{
+ $this->DNS_is_account = true;
+ }
+
+ /* Store initally account settings */
+ $this->DNSinitially_was_account = $this->DNS_is_account;
}
function execute()
{
- /* Call parent execute */
+ /* Call parent execute */
$smarty= get_smarty();
$display= "";
+
+ /* Add new empty array with status new, to our record list */
+ if(isset($_POST['AddNewRecord'])){
+ $this->types[] =array("type"=>"aRecord","value"=>"","status"=>"new");
+ }
+
+ /* Handle all posts */
+ $only_once =true;
+ foreach($_POST as $name => $value){
+
+ /* Check if we have to delete a record entry */
+ if((preg_match("/RemoveRecord_/",$name))&&($only_once)) {
+
+ /* Avoid performing this once again */
+ $only_once = false;
+
+ /* Extract id for specified entry */
+ $id = preg_replace("/RemoveRecord_/","",$name);
+ $id = preg_replace("/_.*$/","",$id);
+
+ /* Delete this record, mark edited entries to be able to delete them */
+ if(isset($this->types[$id])){
+ if($this->types[$id]['status'] == "edited"){
+ $this->types[$id]['status'] = "deleted";
+ }else{
+ unset($this->types[$id]);
+ }
+ }
+ }
+ }
+
+ /* Assign smarty all non DNs attributes */
foreach($this->attributes as $attr){
$smarty->assign($attr,$this->$attr);
}
+
+ /* Assign smarty all DNS attributes */
+ foreach($this->DNSattributes as $attr){
+ $smarty->assign($attr,$this->$attr);
+ }
+
+ /* Assign all needed vars */
+ $smarty->assign("DNSAccount",$this->DNS_is_account);
+ $smarty->assign("Zones",$this->Zones);
+ $smarty->assign("ZoneKeys",($this->Zones));
+ $changeStateForRecords ="";
+ $smarty->assign("records",$this->generateRecordsList(&$changeStateForRecords));
+ $smarty->assign("changeStateForRecords",$changeStateForRecords);
+ $smarty->assign("dNSClasses",array("IN"=>"IN"));
$smarty->assign("staticAddress","<font class=\"must\">*</font>");
$display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
return($display);
function remove_from_parent()
{
- /* This cannot be removed... */
+ /* This cannot be removed... */
}
-
/* Save data to object */
function save_object()
{
+ /* Save all posted vars */
plugin::save_object();
+
+ /* Ge all non dns attributes (IP/MAC)*/
foreach($this->attributes as $attr){
if(isset($_POST[$attr])){
$this->$attr = $_POST[$attr];
}
}
+
+ /* Get dns attributes */
+ if(isset($_POST['network_tpl_posted'])){
+
+ /* Check for posted record changes */
+ foreach($this->types as $key => $value){
+
+ /* Check if type has changed */
+ if(isset($_POST['RecordTypeSelectedFor_'.$key])){
+ $this->types[$key]['type'] = $_POST['RecordTypeSelectedFor_'.$key];
+ }
+ /* Check if value has changed */
+ if(isset($_POST['RecordValue_'.$key])){
+ $this->types[$key]['value'] = $_POST['RecordValue_'.$key];
+ }
+ }
+
+ /* Get all basic DNS attributes (TTL, Clas ..)*/
+ foreach($this->DNSattributes as $attr){
+ if(isset($_POST[$attr])){
+ $this->$attr = $_POST[$attr];
+ }
+ }
+
+ /* Enable diable DNS */
+ if(isset($_POST['enableDNS'])){
+ $this->DNS_is_account = true;
+ }else{
+ $this->DNS_is_account = false;
+ }
+ }
}
function check()
{
$message= array();
-
return ($message);
}
/* Save to LDAP */
function save($dn)
{
- $org_dn = $dn;
+ $ldap= $this->config->get_ldap_link();
+
+ /*******************/
+ /* IP-MAC HANDLING */
+ /*******************/
+
+ /* $dn was posted as parameter */
$this->dn = $dn;
+
+ /* Save DNS setting & ip/Mac*/
plugin::save();
/* Write back to ldap */
- $ldap= $this->config->get_ldap_link();
$ldap->cd($this->dn);
$ldap->modify($this->attrs);
+
+ /****************/
+ /* DNS HANDLING */
+ /****************/
+
+ /* If isn't DNS account but initially was DNS account
+ remove all DNS entries
+ */
+ if(!$this->DNS_is_account){
+ if($this->DNSinitially_was_account){
+ foreach($this->types as $type){
+ $dn = $type['dn'];
+ $ldap->cd($dn);
+ $ldap->rmDir($dn);
+ }
+ }
+ }else{
+
+ /* DNS is enabled, check what we have to do */
+ $delete = array();
+
+ /* Generate a list of new ldap entries,
+ & $delete contains all dns which should be deleted
+ */
+ $entries = $this->generate_LDAP_entries(&$delete);
+
+ /* Delete dns */
+ foreach($delete as $dn => $del){
+ $ldap->cd($dn);
+ $ldap->rmDir($dn);
+ }
+
+ /* Add || Update new DNS entries */
+ foreach($entries as $dn => $attrs){
+ $ldap->cd($dn);
+ $ldap->cat($dn);
+
+ if(count($ldap->fetch())){
+ $ldap->cd($dn);
+ $ldap->modify($attrs);
+ }else{
+ $ldap->cd($dn);
+ $ldap->add($attrs);
+ }
+ }
+ }
+ if($ldap->get_error() != "Success"){
+ print_red($ldap->get_error());
+ }
+
+ }
+
+
+ function generateRecordsList($changeStateForRecords)
+ {
+ $changeStateForRecords = "";
+
+ if(!$this->DNS_is_account) {
+ $str = "<input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord' disabled>";
+ return $str;
+ }
+
+ $str = "<table summary=''>";
+ foreach($this->types as $key => $entry){
+ if($entry['status'] == "deleted") continue;
+
+ $changeStateForRecords.= "changeState('RecordTypeSelectedFor_".$key."');\n";
+ $changeStateForRecords.= "changeState('RecordValue_".$key."');\n";
+ $changeStateForRecords.= "changeState('RemoveRecord_".$key."');\n";
+
+ $str.=" <tr>".
+ " <td>".$this->generateRecordListBox($entry['type'],"RecordTypeSelectedFor_".$key)."</td>".
+ " <td><input type='text' value='".$entry['value']."' name='RecordValue_".$key."' id='RecordValue_".$key."'></td>".
+ " <td><input type='submit' name='RemoveRecord_".$key."' value='"._("Delete")."' id='RemoveRecord_".$key."'></td>".
+ "</tr>";
+ }
+
+ $str.= " <tr>".
+ " <td colspan=2></td><td>".
+ " <input type='submit' value='"._("Add")."' name='AddNewRecord'>".
+ " </td>".
+ " </tr>".
+ "</table>";
+ return($str);
+ }
+
+ function generateRecordListBox($selected,$name)
+ {
+ $str = "<select name='".$name."' id='".$name."'>";
+ foreach($this->RecordTypes as $type => $value){
+ $use = "";
+ if($type == $selected){
+ $use = " selected ";
+ }
+ $str.="\n <option value='".$type."' ".$use.">".$type."</option>";
+ }
+ $str.="</select>";
+ return($str);
+ }
+
+ function get_Zones()
+ {
+ $ret = array();
+ $ldap = $this->config->get_ldap_link();
+ $ldap-> cd ($this->config->current['BASE']);
+ $ldap->search("(&(objectClass=dNSZone)(sOARecord=*))",array("*"));
+
+ while($at = $ldap->fetch()){
+ if(preg_match("/\.in\-addr\.arpa/",$at['zoneName'][0])){
+ $ret[$at['relativeDomainName'][0]]['addr']= $at['zoneName'][0];
+ }else{
+ $ret[$at['relativeDomainName'][0]]['name']= $at['zoneName'][0];
+ }
+ }
+
+ $tmp =array();
+ foreach($ret as $name => $entry){
+ $tmp[$entry['addr']]=$entry['name'];
+ }
+ $ret = $tmp;
+ return($ret);
+ }
+
+ function generate_LDAP_entries($delete)
+ {
+
+ $entries = array();
+
+ $delete = array();
+
+ /* Generate Main Entry */
+ $dn = "relativeDomainName=".$this->cn.",".$this->dn;
+ $entries[$dn]['dNSClass'] = $this->dNSClass;
+ $entries[$dn]['zoneName'] = $this->zoneName;
+ $entries[$dn]['dNSTTL'] = $this->dNSTTL;
+ $entries[$dn]['relativeDomainName'] = $this->cn;
+
+ /* Generate cNAMERecord */
+ $aRecords = array();
+ foreach($this->types as $type){
+ if($type['type'] == "cNAMERecord"){
+
+ $Cdn = "relativeDomainName=".$type['value'].",".$this->dn;
+ if($type['status']=="deleted"){
+ $delete [$type['dn']] = $Cdn;
+ }else{
+ $entries[$Cdn] = $entries[$dn];
+ $entries[$Cdn]['relativeDomainName'] = $type['value'];
+ $entries[$Cdn]['cNAMERecord'] = $this->cn.".".$this->zoneName;
+ }
+ }
+ }
+
+ /* Generate tXTRecord */
+ $aRecords = array();
+ foreach($this->types as $type){
+ if(($type['type'] == "tXTRecord")&&($type['status']!="deleted")){
+ $entries[$dn]['tXTRecord'][] = $type['value'];
+ }
+ }
+
+ /* Generate A Records (IP Address relation) */
+ $aRecords = array();
+ foreach($this->types as $type){
+ if(($type['type'] == "aRecord")&&($type['status']!="deleted")){
+ $aRecords[] = $type['value'];
+ }
+ }
+ if(count($aRecords)){
+ $dn = "relativeDomainName=".$this->cn.",".$this->dn;
+ foreach($aRecords as $rec){
+ $entries[$dn]['aRecord'][] = $rec;
+ }
+ }
+
+ /* Generate pTRRecord Records */
+ foreach($this->types as $type){
+ if($type['type'] == "pTRRecord"){
+ $PTRdn= "relativeDomainName=".$type['value'].",".$this->dn;
+ if($type['status']=="deleted"){
+ $delete [$type['dn']] = $PTRdn;
+ }else{
+ $zones = array_flip($this->Zones);
+ $zone = $zones[$this->zoneName];
+ $entries[$PTRdn]['relativeDomainName'] = $type['value'];
+ $entries[$PTRdn]['pTRRecord'] = $this->cn.".".$this->zoneName;
+ $entries[$PTRdn]['zoneName'] = $zone;
+ }
+ }
+ }
+
+ foreach($entries as $key => $entry ){
+ $entries[$key]['objectClass']=array("top","dNSZone");
+ $entries[$key] = array_reverse($entries[$key]);
+ }
+
+ return($entries);
}
}
index 89c776ea3b973b48e97a3ae91176d066a4c1ccd0..93b7fbc25c826208a2b79844939628195b0d601b 100644 (file)
-<h2><img class="center" alt="" align="middle" src="images/network.png"> {t}Network settings{/t}</h2>
+<h2><img class="center" alt="" align="middle" src="images/network.png"> {t}Network settings{/t}</h2>
-<table summary="" width="100%">
- <tr>
- <td style="border-right:1px solid #b0b0b0; width:50%">
- <table summary="">
- <tr>
- <td><LABEL for="ipHostNumber">{t}IP-address{/t}{$staticAddress}</LABEL></td>
- <td><input id="ipHostNumber" name="ipHostNumber" size=25 maxlength=80 value="{$ipHostNumber}"></td>
- </tr>
- </table>
- </td>
- <td>
- <table summary="">
- <tr>
- <td><LABEL for="macAddress">{t}MAC-address{/t}</LABEL>{$staticAddress}</td>
- <td><input name="macAddress" id="macAddress" size=25 maxlength=80 value="{$macAddress}"></td>
- </tr>
- </table>
- </td>
- </tr>
+<table summary="" width="100%">
+ <tr>
+ <td style="border-right:1px solid #b0b0b0; width:50%; vertical-align: top;">
+ <table summary="">
+ <tr>
+ <td><LABEL for="ipHostNumber">{t}IP-address{/t}{$staticAddress}</LABEL></td>
+ <td><input id="ipHostNumber" name="ipHostNumber" size=25 maxlength=80 value="{$ipHostNumber}"></td>
+ </tr>
+ </table>
+ </td>
+ <td style="border-right:1px solid #b0b0b0; width:50%">
+ <table summary="">
+ <tr>
+ <td><LABEL for="macAddress">{t}MAC-address{/t}</LABEL>{$staticAddress}</td>
+ <td><input name="macAddress" id="macAddress" size=25 maxlength=80 value="{$macAddress}"></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
</table>
-<br>
+<p class="seperator"> </p>
+</br>
+<table summary="" width="100%">
+ <tr>
+ <td style="border-right:1px solid #b0b0b0; width:50%; vertical-align: top; ">
+ <h2>{t}Domain name service{/t}</h2>
+ <input type="checkbox" name="enableDNS" value="1"
+ {if $DNSAccount==true}checked{/if}
+ onClick="
+ changeState('zoneName');
+ changeState('dNSTTL');
+ changeState('dNSClass');
+ changeState('AddNewRecord');
+ {$changeStateForRecords}
+ ">
+ {t}Enable DNS for this device.{/t}
+ <input type="submit" name="reloadThisDNSStuff" value="{t}Refresh{/t}">
+ <table summary="" style="padding-left:10px;" cellspacing=4>
+ <tr>
+ <td><LABEL for="zoneName">{t}DNS-Zone{/t}</LABEL></td>
+ <td>
+ <select name="zoneName" id="zoneName" {if $DNSAccount == false} disabled {/if}>
+ {html_options values=$ZoneKeys output=$Zones}
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>{t}DNS-TTL{/t}</td>
+ <td><input type="text" name="dNSTTL" value="{$dNSTTL}" id="dNSTTL" {if $DNSAccount == false} disabled {/if}>
+ </td>
+ </tr>
+ <tr>
+ <td>{t}DNS Class{/t}
+ </td>
+ <td>
+ <select name="dNSClass" id="dNSClass" {if $DNSAccount == false} disabled {/if}>
+ {html_options values=$dNSClasses output=$dNSClasses selected=$dNSClass}
+ </select>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td style="border-right:1px solid #b0b0b0; width:50%; vertical-align:top;">
+ <h2>{t}Records{/t}</h2>
+ {$records}
+ </td>
+ </tr>
+</table>
+<input type="hidden" name="network_tpl_posted" value="1">
+<!--
+vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+-->
diff --git a/plugins/admin/systems/termdns.tpl b/plugins/admin/systems/termdns.tpl
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-<h2></h2>