Code

Some changes for dns plugin
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Feb 2006 08:21:33 +0000 (08:21 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Feb 2006 08:21:33 +0000 (08:21 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2623 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/systems/class_servDNS.inc
plugins/admin/systems/class_servDNSeditZone.inc [new file with mode: 0644]
plugins/admin/systems/servdns.tpl
plugins/admin/systems/servdnseditzone.tpl [new file with mode: 0644]

index be1cea9ee72b9f922b907073485dd75a185ff7e4..c4e7f178daa7111e4560c2bbbb0775ab1924148b 100644 (file)
@@ -9,132 +9,132 @@ class servdns extends plugin
 
   /* attribute list for save action */
   var $ignore_account= TRUE;
-  var $attributes= array("zoneName","relativeDomainName","dNSTTL","dNSClass","sOARecord"); 
-  var $objectclasses= array("whatever");
+  var $attributes       = array(""); 
+  var $objectclasses    = array("whatever");
 
-  var $RecordTypes = array();
-  var $usedRecords = array();
+  var $RecordTypes      = array();
 
-  var $Zones = array();
-  var $editMode = false;
+  var $Zones  = array();
+  var $dialog = NULL;
 
   function servdns ($config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
-    
-    $RecordTypes['ARecord']     ['name']  ="A Record";
-    $RecordTypes['ARecord']     ['type']  ="string";
-    $RecordTypes['MDRecord']    ['name']  ="MD Record";
-    $RecordTypes['MDRecord']    ['type']  ="string";
-    $RecordTypes['MXRecord']    ['name']  ="MX Record";
-    $RecordTypes['MXRecord']    ['type']  ="string";
-    $RecordTypes['NSRecord']    ['name']  ="NS Record";
-    $RecordTypes['NSRecord']    ['type']  ="string";
-    $RecordTypes['CNAMERecord'] ['name']  ="CNAME Record";
-    $RecordTypes['CNAMERecord'] ['type']  ="string";
-    $RecordTypes['PTRRecord']   ['name']  ="PTR Record";
-    $RecordTypes['PTRRecord']   ['type']  ="string";
-    $RecordTypes['HINFORecord'] ['name']  ="HINFO Record";
-    $RecordTypes['HINFORecord'] ['type']  ="string";
-    $RecordTypes['MINFORecord'] ['name']  ="MINFO Record";
-    $RecordTypes['MINFORecord'] ['type']  ="string";
-    $RecordTypes['TXTRecord']   ['name']  ="TXT Record";
-    $RecordTypes['TXTRecord']   ['type']  ="string";
-    $RecordTypes['AFSDBRecord'] ['name']  ="AFSDB Record";
-    $RecordTypes['AFSDBRecord'] ['type']  ="string";
-    $RecordTypes['SIGRecord']   ['name']  ="SIG Record";
-    $RecordTypes['SIGRecord']   ['type']  ="string";
-    $RecordTypes['KEYRecord']   ['name']  ="KEY Record";
-    $RecordTypes['KEYRecord']   ['type']  ="string";
-    $RecordTypes['AAAARecord']  ['name']  ="AAAA Record";
-    $RecordTypes['AAAARecord']  ['type']  ="string";
-    $RecordTypes['LOCRecord']   ['name']  ="LOC Record";
-    $RecordTypes['LOCRecord']   ['type']  ="string";
-    $RecordTypes['NXTRecord']   ['name']  ="NXT Record";
-    $RecordTypes['NXTRecord']   ['type']  ="string";
-    $RecordTypes['SRVRecord']   ['name']  ="SRV Record";
-    $RecordTypes['SRVRecord']   ['type']  ="string";
-    $RecordTypes['NAPTRRecord'] ['name']  ="NAPTR Record";
-    $RecordTypes['NAPTRRecord'] ['type']  ="string";
-    $RecordTypes['KXRecord']    ['name']  ="KX Record";
-    $RecordTypes['KXRecord']    ['type']  ="string";
-    $RecordTypes['CERTRecord']  ['name']  ="CERT Record";
-    $RecordTypes['CERTRecord']  ['type']  ="string";
-    $RecordTypes['A6Record']    ['name']  ="A6 Record";
-    $RecordTypes['A6Record']    ['type']  ="string";
-    $RecordTypes['DNAMERecord'] ['name']  ="DBNAME Record";
-    $RecordTypes['DNAMERecord'] ['type']  ="string";
-    $RecordTypes['DSRecord']    ['name']  ="DS Record";
-    $RecordTypes['DSRecord']    ['type']  ="string";
-    $RecordTypes['SSHFPRecord'] ['name']  ="SSHFP Record";
-    $RecordTypes['SSHFPRecord'] ['type']  ="string";
-    $RecordTypes['RRSIGRecord'] ['name']  ="RRSIG Record";
-    $RecordTypes['RRSIGRecord'] ['type']  ="string";
-    $RecordTypes['NSECRecord']  ['name']  ="NSEC Record";
-    $RecordTypes['NSECRecord']  ['type']  ="string";
-    $RecordTypes['mXRecord']  ['name']  ="MX Record";
-    $RecordTypes['mXRecord']  ['type']  ="string";
-    $RecordTypes['nSRecord']  ['name']  ="nS Record";
-    $RecordTypes['nSRecord']  ['type']  ="string";
-
-    $this->RecordTypes = $RecordTypes;
-
-    $attrs  = $this->attributes;
-    foreach($RecordTypes as $name => $att){
-      $attrs2[] = $name;
-    } 
-    $attrs3 = array_merge($attrs,$attrs2);
 
+    /* All types with required attrs */
+    $this->RecordTypes['aRecord']       = "aRecord";           // ok
+    $this->RecordTypes['mDRecord']      = "mDRecord";          // ok
+    $this->RecordTypes['mXRecord']      = "mXRecord";          // ok
+    $this->RecordTypes['nSRecord']      = "nSRecord";          // ok
+    $this->RecordTypes['pTRRecord']     = "relativeDomainName";// ok
+    $this->RecordTypes['hInfoRecord']   = "hInfoRecord";       // ok
+    $this->RecordTypes['mInfoRecord']   = "mInfoRecord";       // ok
+    $this->RecordTypes['tXTRecord']     = "tXTRecord";         // ok
+    $this->RecordTypes['aFSDBRecord']   = "aFSDBRecord";       // ok
+    $this->RecordTypes['SigRecord']     = "SigRecord";         // ok
+    $this->RecordTypes['KeyRecord']     = "KeyRecord";         // ok
+    $this->RecordTypes['aAAARecord']    = "aAAARecord";        // ok
+    $this->RecordTypes['LocRecord']     = "LocRecord";         // ok
+    $this->RecordTypes['nXTRecord']     = "nXTRecord";         // ok
+    $this->RecordTypes['sRVRecord']     = "sRVRecord";         // ok
+    $this->RecordTypes['nAPTRRecord']   = "nAPTRRecord";       // ok
+    $this->RecordTypes['kXRecord']      = "kXRecord";          // ok
+    $this->RecordTypes['certRecord']    = "certRecord";        // ok
+    $this->RecordTypes['a6Record']      = "a6Record";          // ok
+    $this->RecordTypes['dSRecord']      = "dSRecord";          // ok
+    $this->RecordTypes['sSHFPRecord']   = "sSHFPRecord";       // ok
+    $this->RecordTypes['rRSIGRecord']   = "rRSIGRecord";       // ok
+    $this->RecordTypes['nSECRecord']    = "nSECRecord";        // ok
+
+    $this->cn = $this->attrs['cn'][0];
+
+    $types = array();
+
+    /* Get all records */
     $ldap = $this->config->get_ldap_link();
     $ldap->cd($this->dn);
-    $ldap->search("(&(objectClass=dNSZone)(sOARecord=*))",$attrs3);
-    while($zone = $ldap->fetch()){
-      $tmp = array();
-      foreach($attrs as $att){
-        if(isset($zone[$att]['count'])&&(is_array($zone[$att])))
-        unset($zone[$att]['count']);
-        
-        if(isset($zone[$att])){ 
-          $tmp[$att] = $zone[$att][0];
-        }else{
-          $tmp[$att] = "";
+    $ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@))",array("*"));
+
+    while($attrs = $ldap->fetch()){
+      /* If relative domainname == cn
+       * Try to read dnsclass / TTl / zone
+       */
+      if((isset($attrs['tXTRecord'][0]))&&(preg_match("/zoneName\=/",$attrs['tXTRecord'][0]))){
+        $zoneName= preg_replace("/zoneName\=/","",$attrs['tXTRecord'][0]);  
+        $types[$zoneName]['ReverseZone']  = $attrs['zoneName'][0];
+        $types[$zoneName]['ReverseDN']    = $attrs['dn']; 
+      }else{
+
+        /* Generate SOA entry */
+        if(isset($attrs['sOARecord'][0])){
+          $tmp = split("\ ",$attrs['sOARecord'][0]) ;
+          $tmp2 = array();
+          $ar = array("0"=>"sOAprimary","1"=>"sOAmail","2"=>"sOAserial","3"=>"sOArefresh","4"=>"sOAretry","5"=>"sOAexpire","6"=>"sOAttl");
+
+          /* Assign soa vars */
+          foreach($ar as $key => $name){
+            if(isset($tmp[$key])){
+              $types[$attrs['zoneName'][0]][$name] = $tmp[$key];
+            }else{
+              $types[$attrs['zoneName'][0]][$name] = "";
+            }
+          }
         }
-      }
 
-      if(isset($tmp['sOARecord'])){
-        $tmp2 = split("\ ",$tmp['sOARecord']);
-        unset($tmp['sOARecord']);
-        $tmp['sOARecord'] = array();
-        $tmp['sOARecord']['sOAprimary'] = $tmp2[0];
-        $tmp['sOARecord']['sOAmail']    = $tmp2[1];
-        $tmp['sOARecord']['sOAserial']  = $tmp2[2];
-        $tmp['sOARecord']['sOArefresh'] = $tmp2[3];
-        $tmp['sOARecord']['sOAretry']   = $tmp2[4];
-        $tmp['sOARecord']['sOAexpire']  = $tmp2[5];
-        $tmp['sOARecord']['sOAttl']     = $tmp2[6];
-      }
+        /* Set TTL value */
+        if(isset($attrs['dNSTTL'][0])){
+          $types[$attrs['zoneName'][0]]['dNSTTL'] = $attrs['dNSTTL'][0];
+        }
+
+        /* Set dns Class*/
+        if(isset($attrs['dNSClass'][0])){
+          $types[$attrs['zoneName'][0]]['dNSClass'] = $attrs['dNSClass'][0];
+        }
 
-      $tmp['usedRecords'] = array();
-      foreach($attrs2 as $name){
-        if(isset($zone[$name])){
-          for($i = 0 ; $i < $zone[$name]['count'] ; $i++ ){
-            $tmp['usedRecords'][] =  array("type"=> $name,"value"=>$zone[$name][$i]);
+        /* Set zone Name */
+        if(isset($attrs['zoneName'][0])){
+          $types[$attrs['zoneName'][0]]['zoneName'] = $attrs['zoneName'][0];
+        }
+
+        /* Set status */
+        $types[$attrs['zoneName'][0]]['status']   ="edited"; 
+        $types[$attrs['zoneName'][0]]['ReverseDN']= $attrs['dn']; 
+
+        /* 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[$attrs['zoneName'][0]]['Records'][] =array("type"      =>$name,
+                  "inittype"  =>$name,
+                  "value"     =>$attrs[$value][$i],
+                  "status"    =>"edited",
+                  "dn"        =>$attrs['dn']);
+            }
           }
         }
       }
-      $this->Zones[$zone['zoneName'][0]] = $tmp;
     }
-    if(count($this->Zones > 0)){
+
+    /* If there is at least one entry in this -> types, we have DNS enabled */
+    $this->Zones = $types;
+    if(count($this->Zones) == 0){
+      $this->is_account = false;
+    }else{
       $this->is_account = true;
     }
+
+    /* Store initally account settings */
+    $this->DNSinitially_was_account = $this->is_account;
   }
 
   function execute()
   {
-
-  print_a($this->Zones);
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     /* Fill templating stuff */
     $smarty= get_smarty();
@@ -155,72 +155,96 @@ class servdns extends plugin
       return ($display);
     }
 
+    if(isset($_POST['SaveZoneChanges'])){
+      $this->dialog->save_object();
+    
+      if(count($this->dialog->check())){
+        foreach($this->dialog->check() as $msgs){
+          print_red($msgs); 
+        }
+      }else{
+        $ret = $this->dialog->save();
+        if($this->dialog->isNew == true){
+          $this->Zones[$ret['zoneName']] = $ret;
+          $this->Zones[$ret['zoneName']] = "new";
+        }else{
+
+          if(!$this->dialog->isNew){
+
+            /* Edited but not renamed */
+            if($ret['zoneName'] == $this->dialog->InitiallyZoneName){
+              $this->Zones[$ret['zoneName']] = $ret;
+
+            }else{
+              /* Edited and renamed, we have to check if we must delete the old entry from ldap */
+
+              if($this->Zones[$this->dialog->InitiallyZoneName]['status'] == "new"){
+                /* this was a new entry (currently not saved to ldap) so we can simply unset the zone */
+                unset($this->Zones[$this->dialog->InitiallyZoneName]);
+              
+              }elseif($this->Zones[$this->dialog->InitiallyZoneName]['status'] == "edited") {
+                $this->Zones[$this->dialog->InitiallyZoneName]['status'] = "deleted";
+              } 
+              $this->Zones[$ret['zoneName']] = $ret;
+              $this->Zones[$ret['zoneName']]['status'] = "new";
+            }
+          }else{
+            $this->Zones[$ret['zoneName']] = $ret;
+            $this->Zones[$ret['zoneName']]['status'] = "new";
+          }
+        }
+        $this->dialog = NULL;
+      }
+    }
+    if(isset($_POST['CancelZoneChanges'])){
+      $this->dialog = NULL;
+    }
+    /* Add empty new zone */
+    if(isset($_POST['AddZone'])){
+      $this->dialog = new servdnseditZone($this->config,$this->dn,$this->RecordTypes);
+    }
+
     $once = false;
     foreach( $_POST as $name => $value){
       if(preg_match("/^editZone_/",$name)&&!$once){
         $once =true;
         $tmp = preg_replace("/^editZone_/","",$name);
-        $tmp = base64_decode(preg_replace("/_.*$/","...",$tmp));
-        $this->editMode = $this->Zones[$tmp];
+        $tmp = base64_decode(preg_replace("/_.*$/","",$tmp));
+        $this->dialog= new servdnseditZone($this->config,$this->dn,$this->RecordTypes,$this->Zones[$tmp]);
       }
     }
 
+    if($this->dialog!= NULL){
+      $this->dialog->save_object();
+      $this->dialog->parent = $this;
+      return($this->dialog->execute());
+    }
 
-    $smarty->assign("editMode",$this->editMode);
-    if($this->editMode){
-
-      foreach($this->attributes as $attrs){
-        $smarty->assign($attrs,$this->editMode[$attrs]);
-      }
-      
-      foreach($this->editMode['sOARecord'] as $name => $value){
-        $smarty->assign($name,$value);
-      }
-      $smarty->assign("records","");
-
-    }else{
-      $ZoneList = new divSelectBox("dNSZones");
-      $ZoneList -> SetHeight(254);
-
-      $editImg = "<input type='image' src='images/edit.png' name='editZone_%s'>";
-
-      foreach($this->Zones as $zone => $values ){
-        $ZoneList->AddEntry(array(array("string" => $zone.str_replace("%s",base64_encode($zone),$editImg))));
-      }    
-
+    /* Create Listbox with existing Zones */
+    $ZoneList = new divSelectBox("dNSZones");
+    $ZoneList -> SetHeight(254);
 
-      $smarty->assign("ZoneList",$ZoneList->DrawList());
-    }
+    /* Add entries to divlist*/
+    $editImg = "<input type='image' src='images/edit.png' name='editZone_%s'>";
+    foreach($this->Zones as $zone => $values ){
+      if($values['status'] == "deleted") continue;
+      $ZoneList->AddEntry(array(array("string" => $zone.str_replace("%s",base64_encode($zone),$editImg))));
+    }    
 
+    /* Display tempalte */
+    $smarty->assign("ZoneList",$ZoneList->DrawList());
     $display.= $smarty->fetch(get_template_path('servdns.tpl', TRUE));
     return($display);
   }
 
   function remove_from_parent()
   {
-    /* This cannot be removed... */
   }
 
 
   /* Save data to object */
   function save_object()
   {
-    //plugin::save_object();
-
-    if(!$this->editMode){return;}
-
-    foreach($this->attributes as $attr){
-      if(isset($_POST[$attr])){
-        $this->editMode[$attr] = $_POST[$attr];
-      }
-    }
-
-    foreach($this->editMode['sOARecord'] as $name => $value){
-      if(isset($_POST[$name])){
-        $this->editMode['sOARecord'][$name] = $_POST[$name];
-      }
-    }
-
   }
 
 
@@ -228,7 +252,6 @@ class servdns extends plugin
   function check()
   {
     $message= array();
-
     return ($message);
   }
 
@@ -236,12 +259,64 @@ class servdns extends plugin
   /* Save to LDAP */
   function save()
   {
-    plugin::save();
+  return(true);
+//    plugin::save();
+    foreach($this->Zones as $zone){
+      $tmp = array();
+      if($zone['status'] == "deleted"){
+        echo "deleted";
+      }elseif($zone['status'] == "new" ){
+        echo "new";
+      }elseif($zone['status'] == "edited"){  
+        echo "edit";
+      }else{
+        echo "undefined type";
+      }
+
+      //$tmp = $this->generate_LDAP_entries($tmp,$zone,$delete);
+    }
+  }
+
+  function generate_LDAP_entries($tmp,$zone,$delete)
+  {
+    $delete  = array();
 
-    /* Optionally execute a command after we're done */
-    #$this->handle_post_events($mode);
+    $tmp['objectClass']           = array("top","dNSZone");
+    $tmp['dNSTTL']                = $zone['dNSTTL']; 
+    $tmp['dNSClass']              = $zone['dNSClass']; 
+    $tmp['relativeDomainName']    = $zone['relativeDomainName']; 
+
+    $str = "";
+    foreach($zone['sOARecord'] as $name => $value){
+      $str .= $value." "; 
+    }
+    $tmp['sOARecord'] = $str;
+
+    $dn = "zoneName=".$zone['zoneName'].",".$this->dn;
+
+    /* Generate some attrs  */
+    $arr = array("SigRecord","KeyRecord","aAAARecord","nSRecord","iaFSDBRecord","mInfoRecord","hInfoRecord","mXRecord","mDRecord","tXTRecord",
+        "LocRecord","nXTRecord","sRVRecord","nAPTRRecord","kXRecord","certRecord","a6Record","dSRecord","sSHFPRecord","rRSIGRecord","nSECRecord");
+    $aRecords = array();
+    foreach($arr as $ar){
+      foreach($zone['types'] as $type){
+        if(($type['type'] == $ar)&&($type['status']!="deleted")){
+          $tmp[$ar][] = $type['value'];
+        }
+      }
+    }
+    foreach($zone['types'] as $type){
+      if(isset($type['inittype'])){
+        if($type['type'] != $type['inittype']){
+          $tmp[$type['inittype']] = array();
+        }
+      }
+    }
+    return($tmp);
   }
 
+
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
diff --git a/plugins/admin/systems/class_servDNSeditZone.inc b/plugins/admin/systems/class_servDNSeditZone.inc
new file mode 100644 (file)
index 0000000..6e79f46
--- /dev/null
@@ -0,0 +1,217 @@
+<?php
+
+class servdnseditZone extends plugin
+{
+  /* CLI vars */
+  var $cli_summary= "Manage server basic objects";
+  var $cli_description= "Some longer text\nfor help";
+  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+
+  /* attribute list for save action */
+  var $ignore_account= TRUE;
+  var $attributes     = array("zoneName","ReverseZone","dNSTTL","dNSClass",
+      "sOAprimary","sOAmail","sOAserial","sOArefresh","sOAretry","sOAexpire","sOAttl"); 
+  var $objectclasses  = array("whatever");
+
+  var $RecordTypes = array();
+
+  var $ReverseZone              = "";
+  var $ReverseDN                = "";
+  var $zoneName                 = "";
+  var $dNSTTL                   = "7200";
+  var $dNSClass                 = "IN";
+  var $status                   = "new";
+
+  var $sOAprimary               = "";
+  var $sOAmail                  = "";
+  var $sOAserial                = "";
+  var $sOArefresh               = "3600";
+  var $sOAretry                 = "1800";
+  var $sOAexpire                = "";
+  var $sOAttl                   = "6400";
+
+  var $Records                  = array();
+
+  var $InitiallyZoneName      = "";
+  var $isNew                    = true;
+
+  function servdnseditZone ($config, $dn= NULL,$recordtypes,$attrs = array())
+  {
+    plugin::plugin ($config, $dn);
+
+    /* All types with required attrs */
+    $this->RecordTypes = $recordtypes; 
+
+    if(!count($attrs)){
+      $this->InitiallyZoneName  = "";
+      $this->isNew              = true;
+    }else{
+      $this->InitiallyZoneName  = $attrs['zoneName'];
+      $this->isNew              = false;
+
+      foreach($this->attributes as $value){
+        $this->$value = $attrs[$value];
+      }
+      $this->Records = $attrs['Records']; 
+    }
+  }
+
+  function execute()
+  {
+    /* Call parent execute */
+    plugin::execute();
+
+    /* Fill templating stuff */
+    $smarty= get_smarty();
+    $display= "";
+
+    /* Handle Post events */
+    $once = true;
+    foreach($_POST as $name => $value){
+
+      /* Delete record if requested */
+      if((preg_match("/RemoveRecord_/",$name))&&($once)){
+        $once = false;
+        $id= preg_replace("/RemoveRecord_/","",$name);
+        if($this->Records[$id]['status']!= "new"){
+          $this->Records[$id]['status']= "deleted";
+        }else{
+          unset($this->Records[$id]);
+        }
+      }
+    }
+
+    /* Add new Zonerecord */
+    if(isset($_POST['AddNewRecord'])){
+      $this->Records[] = array("type"=>"aRecord","inittype"=>"","value"=>"","status"=>"new");
+    }
+
+    /* Fill in values */
+    foreach($this->attributes as $name){
+      $smarty->assign($name,$this->$name);
+    }
+
+    /* Assign records list */
+    $smarty->assign("records",$this->generateRecordsList());
+
+    /* Display tempalte */
+    $display.= $smarty->fetch(get_template_path('servdnseditzone.tpl', TRUE));
+    return($display);
+  }
+
+  function remove_from_parent()
+  {
+  }
+
+  /* Save data to object */
+  function save_object()
+  {
+    //plugin::save_object();
+    foreach($this->attributes as $attr){
+      if(isset($_POST[$attr])){
+        $this->$attr = $_POST[$attr];
+      }
+    }
+
+    foreach($this->Records as $id => $value){  
+      if(isset($_POST['RecordTypeSelectedFor_'.$id])){
+        $this->Records[$id]['type'] = $_POST['RecordTypeSelectedFor_'.$id];
+      }
+      if(isset($_POST['RecordValue_'.$id])){
+        $this->Records[$id]['value'] = $_POST['RecordValue_'.$id];
+      }
+    }
+  }
+
+
+  /* Check supplied data */
+  function check()
+  {
+    $message= array();
+    /* Check if zoneName is already in use */
+    $usedZones = $this->getUsedZoneNames();
+    if(($this->isNew == true)||($this->zoneName  != $this->InitiallyZoneName)){
+      if(isset($usedZones[$this->zoneName])){
+        $message[] =_("This zoneName is already in use");
+      }
+      if(in_array($this->ReverseZone,$usedZones)){
+        $message[] =_("This reverse zone is already in use");
+      }
+    }
+    return ($message);
+  }
+
+  function getUsedZoneNames()
+  {
+    $ret = array();
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(&(objectClass=dNSZone)(relativeDomainName=@)(zoneName=*))",array("zoneName","tXTRecord"));
+    while($attr = $ldap->fetch()){
+      if(preg_match("/in-addr\.arpa/",$attr['zoneName'][0])){
+        $zn = preg_replace("/zoneName\=/","",$attr['tXTRecord'][0]);
+        $ret[$zn] = preg_replace("/\.in-addr\.arpa/","",$attr['zoneName'][0]);
+      }else{
+        $ret[$attr['zoneName'][0]]="";
+      }
+    }
+    return($ret);
+  }
+  
+
+  /* Save to LDAP */
+  function save()
+  {
+    $ret =array();
+    foreach($this->attributes as $name){
+      $ret[$name] = $this->$name;
+    }
+    $ret['Records'] = $this->Records; 
+    return($ret);
+  }
+
+  function generateRecordsList($changeStateForRecords="")
+  {
+    $changeStateForRecords = "";
+
+    $str = "<table summary=''>";
+    foreach($this->Records 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);
+  }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
index cef8a50d0b71d550adb8cd24e5bd809e8d1e71a5..8e5f94b49425e26e841e92c8b3a53f0aa5ae8ba2 100644 (file)
@@ -1,4 +1,3 @@
-{if $editMode == false}
 <h2>{t}Zones{/t}</h2>
 <table summary="" width="100%">
 <tr>
        </td>
 </tr>
 </table>
-{else}
-<h2>{t}Zone settings{/t}</h2>
-<table summary="" width="100%">
-       <tr>
-               <td style="width:50%;vertical-align:top;">
-                       <table summary="">
-                               <tr>
-                                       <td>{t}Zone name{/t}
-                                       </td>
-                                       <td><input type="text" name="zoneName" value="{$zoneName}">
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-               <td style="vertical-align:top;">
-                       <table summary="">
-                               <tr>
-                                       <td>{t}Subnet{/t}
-                                       </td>
-                                       <td><input type="text" name="ReverseZone" value="{$ReverseZone}">
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-       </tr>
-</table>
-<p class="seperator">&nbsp;</p>
-<h2>{t}SOA record for this zone{/t}</h2>
-<table summary="" width="100%">
-       <tr>
-               <td style="vertical-align:top;width:50%">
-                       <table summary="">
-                               <tr>
-                                       <td>{t}Primary dns server for this zone{/t}
-                                       </td>
-                                       <td><input type="text" name="sOAprimary" value="{$sOAprimary}">
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>{t}Mail address{/t}
-                                       </td>
-                                       <td><input type="text" name="sOAmail" value="{$sOAmail}">
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>{t}Serialnumber (automatically generated){/t}
-                                       </td>
-                                       <td><input type="text" name="sOAserial" value="{$sOAserial}">
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-               <td style="vertical-align:top;">
-                       <table summary="">
-                               <tr>
-                                       <td>{t}Refresh{/t}
-                                       </td>
-                                       <td><input type="text" name="sOArefresh" value="{$sOArefresh}">
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>{t}Retry{/t}
-                                       </td>
-                                       <td><input type="text" name="sOAretry" value="{$sOAretry}">
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>{t}Expire{/t}
-                                       </td>
-                                       <td><input type="text" name="sOAexpire" value="{$sOAexpire}">
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>{t}TTL{/t}
-                                       </td>
-                                       <td><input type="text" name="sOAttl" value="{$sOAttl}">
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-       </tr>
-</table>
-
-<p class="seperator">&nbsp;</p>
-<br>
-<table summary="" width="100%">
-       <tr>
-               <td style="vertical-align:top;width:50%;">
-                       <h2>{t}Parameter{/t}</h2>
-                       <table summary="">
-                               <tr>
-                                       <td>{t}DNS TTL{/t}
-                                       </td>
-                                       <td>
-                                               <input type="text" name="dNSTTL" value="{$dNSTTL}">
-                                       </td>
-                               </tr>
-                               <tr>
-                                       <td>{t}DNS Class{/t}
-                                       </td>
-                                       <td>
-                                               <input type="text" name="dNSClass" value="{$dNSClass}">
-                                       </td>
-                               </tr>
-                       </table>
-               </td>
-               <td style="vertical-align:top;">
-                       <h2>{t}Records{/t}</h2>
-                       <table summary="">
-                         {$records}
-                       </table>
-               </td>
-       </tr>
-</table>
-<div style="text-algin:right;" align="right">
-       <p>
-               <input type="submit" name="SaveZoneChanges" value="{t}Save{/t}">
-               <input type="submit" name="CancelZoneChanges" value="{t}Cancel{/t}">
-       </p>
-</div>
-{/if}
diff --git a/plugins/admin/systems/servdnseditzone.tpl b/plugins/admin/systems/servdnseditzone.tpl
new file mode 100644 (file)
index 0000000..9f7d5f1
--- /dev/null
@@ -0,0 +1,119 @@
+<h2>{t}Zone settings{/t}</h2>
+<table summary="" width="100%">
+       <tr>
+               <td style="width:50%;vertical-align:top;">
+                       <table summary="">
+                               <tr>
+                                       <td>{t}Zone name{/t}
+                                       </td>
+                                       <td><input type="text" name="zoneName" value="{$zoneName}">
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td style="vertical-align:top;">
+                       <table summary="">
+                               <tr>
+                                       <td>{t}Subnet{/t}
+                                       </td>
+                                       <td><input type="text" name="ReverseZone" value="{$ReverseZone}">
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+       </tr>
+</table>
+<p class="seperator">&nbsp;</p>
+<h2>{t}SOA record for this zone{/t}</h2>
+<table summary="" width="100%">
+       <tr>
+               <td style="vertical-align:top;width:50%">
+                       <table summary="">
+                               <tr>
+                                       <td>{t}Primary dns server for this zone{/t}
+                                       </td>
+                                       <td><input type="text" name="sOAprimary" value="{$sOAprimary}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Mail address{/t}
+                                       </td>
+                                       <td><input type="text" name="sOAmail" value="{$sOAmail}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Serialnumber (automatically generated){/t}
+                                       </td>
+                                       <td><input type="text" name="sOAserial" value="{$sOAserial}">
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td style="vertical-align:top;">
+                       <table summary="">
+                               <tr>
+                                       <td>{t}Refresh{/t}
+                                       </td>
+                                       <td><input type="text" name="sOArefresh" value="{$sOArefresh}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Retry{/t}
+                                       </td>
+                                       <td><input type="text" name="sOAretry" value="{$sOAretry}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}Expire{/t}
+                                       </td>
+                                       <td><input type="text" name="sOAexpire" value="{$sOAexpire}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}TTL{/t}
+                                       </td>
+                                       <td><input type="text" name="sOAttl" value="{$sOAttl}">
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+       </tr>
+</table>
+
+<p class="seperator">&nbsp;</p>
+<br>
+<table summary="" width="100%">
+       <tr>
+               <td style="vertical-align:top;width:50%;">
+                       <h2>{t}Parameter{/t}</h2>
+                       <table summary="">
+                               <tr>
+                                       <td>{t}DNS TTL{/t}
+                                       </td>
+                                       <td>
+                                               <input type="text" name="dNSTTL" value="{$dNSTTL}">
+                                       </td>
+                               </tr>
+                               <tr>
+                                       <td>{t}DNS Class{/t}
+                                       </td>
+                                       <td>
+                                               <input type="text" name="dNSClass" value="{$dNSClass}">
+                                       </td>
+                               </tr>
+                       </table>
+               </td>
+               <td style="vertical-align:top;">
+                       <h2>{t}Records{/t}</h2>
+                       <table summary="">
+                         {$records}
+                       </table>
+               </td>
+       </tr>
+</table>
+<div style="text-algin:right;" align="right">
+       <p>
+               <input type="submit" name="SaveZoneChanges" value="{t}Save{/t}">
+               <input type="submit" name="CancelZoneChanges" value="{t}Cancel{/t}">
+       </p>
+</div>