Code

Added "Force localboot"
[gosa.git] / plugins / admin / systems / class_termDNS.inc
index 86f56a7639c4719219b1d63d2e46c17cc5e1384e..cb678cbccdff2900cf757a87e80b5298bd66a738 100644 (file)
@@ -2,11 +2,6 @@
 
 class termDNS 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 $autonet        = false;
@@ -44,10 +39,10 @@ class termDNS extends plugin
     plugin::plugin ($config, $dn);
 
     if(isset($this->attrs['cn'][0])){
-      $this->OrigCn = $this->attrs['cn'][0];
-      $this->cn = $this->attrs['cn'][0];
+      $this->OrigCn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
+      $this->cn = preg_replace("/\\\$\$/","",$this->attrs['cn'][0]);
     }
-
+  
     /* Do we have autonet support? */
     if (isset($this->config->data['MAIN']['AUTO_NETWORK_HOOK'])){
       $this->autonet= true;
@@ -103,6 +98,17 @@ class termDNS extends plugin
   }
 
 
+  function netmaskIsCoherent($idZone) 
+  {
+    $netmask = FlipIp(str_replace(".in-addr.arpa","",getNameFromMix($idZone)));
+    if(!strstr($this->ipHostNumber, $netmask)){
+      return false;
+    }else{
+      return true;
+    }
+  }
+
+
   function getVarsForSaving($attrs) 
   {
     foreach($this->attributes as $attr){
@@ -221,7 +227,19 @@ class termDNS extends plugin
     $smarty->assign("Zones",$this->Zones);
     $smarty->assign("ZoneKeys",($this->Zones));
     $smarty->assign("IPisMust",(($this->IPisMust)||($this->DNS_is_account)));
-  
+    /* Create zone array */
+    $idZones = array();
+    foreach($this->Zones as $id => $zone){
+      if($this->netmaskIsCoherent($id)) {
+        $idZones[$id] = $zone;
+      }else{
+        $idZones[$id] = $zone." ("._("Not matching").")";
+      }
+    }    
+    $smarty->assign("Zones",$idZones);
+    $smarty->assign("ZoneKeys", $this->Zones);
+
     $tmp = $this->generateRecordsList();
     
     $changeStateForRecords = $tmp['changeStateForRecords'];
@@ -234,20 +252,26 @@ class termDNS extends plugin
     return($display);
   }
 
+
   function remove_from_parent()
   {
-    /*
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->orig_dn);
-    $ldap->search("(&(objectClass=dNSZone)(zoneName=*)(!(relativeDomainName=@)))",array("relativeDomainName","zoneName"));
-    while($attr = $ldap->fetch()){  
-    $ldap->cd($attr['dn']);
-    $ldap->rmDir($attr['dn']);
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of terminal/dns acoount with dn '%s' failed."),$this->dn));
+    if($this->initially_was_account){
+
+      $ldap = $this->config->get_ldap_link();
+
+      $tmp = array();
+      $this->dnsEntry['exists'] = false;
+      $tmp = getDNSHostEntriesDiff($this->config,$this->OrigCn,$this->dnsEntry,$this->cn);
+
+      /* Delete dns */
+      foreach($tmp['del'] as $dn => $del){
+        $ldap->cd($dn);
+        $ldap->rmdir_recursive($dn);
+      }
     }
-     */
   }
 
+
   /* Save data to object */
   function save_object()
   {
@@ -309,29 +333,20 @@ class termDNS extends plugin
     /* Check if ip must be given
      */  
     if(($this->IPisMust)||($this->DNS_is_account)){
-  
-      /* Check if ip is empty 
-       */
-      if ($this->ipHostNumber == "" && $this->acl_is_writeable("ipHostNumber")){
+      if (empty($this->ipHostNumber)){
         $message[]= _("The required field 'IP-address' is not set.");
       }
-    }
 
-     
-    /* check if given ip is valid ip */
-    if ($this->ipHostNumber != "" && !is_ip($this->ipHostNumber)){
-      $message[]= _("Wrong IP format in field IP-address.");
+      if (!is_ip($this->ipHostNumber)){
+        $message[]= _("Wrong IP format in field IP-address.");
+      }
     }
 
     /* Check if mac is empty 
      */
-    if ($this->macAddress == "" && $this->acl_is_writeable("macAddress")){
+    if ($this->macAddress == "" ){
       $message[]= _("The required field 'MAC-address' is not set.");
     }
-
-    /* Check if given mac is valid mac 
-     */
-    $tr = count(split(":",$this->macAddress));
     if(!is_mac($this->macAddress)){
       $message[]=(_("The given macaddress is invalid. There must be 6 2byte segments seperated by ':'."));
     }
@@ -342,7 +357,13 @@ class termDNS extends plugin
       $checkArray = array();
       $onlyOnce   = array();
 
-    //  $onlyOnce['cNAMERecord'] = 0;
+      //  $onlyOnce['cNAMERecord'] = 0;
+       $tmp = array_flip($this->Zones);
+       $tmp2 = $tmp[$this->dnsEntry['zoneName']];
+       if(!$this->netmaskIsCoherent($tmp2)){ //this->dnsEntry['zoneName'])){
+         $tmp2 = preg_replace("/^.*\//","",$tmp2);
+         $message[] =sprintf(_("The specified IP address '%s' is not matching the selected reverse zone entry '%s'."),$this->ipHostNumber,$tmp2);
+       }
 
       /* Walk through all entries and detect duplicates or mismatches
        */  
@@ -420,6 +441,7 @@ class termDNS extends plugin
 
       /* Add ipHostNumber to aRecords
        */
+      $backup_dnsEntry = $this->dnsEntry;
       $this->dnsEntry['RECORDS'][] = array("type"=>"aRecord","value"=>$this->ipHostNumber);
 
       /* Create diff and follow instructions 
@@ -464,6 +486,8 @@ class termDNS extends plugin
       if($ldap->get_error() != "Success"){
         show_ldap_error($ldap->get_error(), sprintf(_("Saving of terminal/dns account with dn '%s' failed."),$this->dn));
       }
+
+      $this->dnsEntry =  $backup_dnsEntry;
     }
   }