Code

Corrected FAQ
[gosa.git] / plugins / admin / systems / class_termDNS.inc
index a90f65c2b5d75b172b6fb256732399d3da50327f..0f76e2f131c27845aa0b34d3a76e5e868b5aeb6b 100644 (file)
@@ -8,7 +8,8 @@ class termDNS extends plugin
   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* attribute list for save action */
-  var $ignore_account = TRUE;
+  var $ignore_account = true;
+  var $autonet        = false;
 
   /* Basic informations 
    */
@@ -44,6 +45,12 @@ class termDNS extends plugin
 
     if(isset($this->attrs['cn'][0])){
       $this->OrigCn = $this->attrs['cn'][0];
+      $this->cn = $this->attrs['cn'][0];
+    }
+
+    /* Do we have autonet support? */
+    if (isset($this->config->data['MAIN']['AUTO_NETWORK_HOOK'])){
+      $this->autonet= true;
     }
 
     /* Hide all dns specific code, if dns is not available 
@@ -114,7 +121,27 @@ class termDNS extends plugin
     $display= "";
 
     $smarty->assign("staticAddress", ""); 
+    $smarty->assign("autonet", "");
  
+    /* Check for autonet button */
+    if ($this->autonet && isset($_POST['autonet'])){
+      $cmd= $this->config->data['MAIN']['AUTO_NETWORK_HOOK'];
+      if(!empty($cmd) && $this->cn != ""){
+        $res = shell_exec($cmd." ".$this->cn);
+        if(!$res){
+          print_red(sprintf(_("Can't execute specified AUTO_NETWORK_HOOK '%s'. Please check your gosa.conf."),$cmd));
+        } else {
+          $res= split(';', trim($res));
+          if (isset($res[0]) && $res[0] != ""){
+            $this->ipHostNumber= $res[0];
+          }
+          if (isset($res[1]) && $res[1] != ""){
+            $this->macAddress= $res[1];
+          }
+        }
+      }
+    }
+
     /* There is no dns available 
      */
     if($this->DNSenabled == false){
@@ -127,7 +154,9 @@ class termDNS extends plugin
       foreach($this->attributes as $attr){
         $smarty->assign($attr,$this->$attr);
       }
-      $smarty->assign("staticAddress", "");
+      $smarty->assign("staticAddress","<font class=\"must\">*</font>");
+
+      $smarty->assign("autonet", $this->autonet);
       $display.= $smarty->fetch(get_template_path('network.tpl', TRUE));
       return($display);
     }else{
@@ -197,6 +226,7 @@ class termDNS extends plugin
     while($attr = $ldap->fetch()){  
       $ldap->cd($attr['dn']);
       $ldap->rmDir($attr['dn']);
+      show_ldap_error("Record:".$ldap->get_error(), _("Removing terminal from DNS object failed")); 
     }
     */
   }
@@ -264,12 +294,11 @@ class termDNS extends plugin
         $message[]= _("The required field 'IP-address' is not set.");
       }
 
-      /* check if given ip is valid ipi
-       */
-      $num="(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])";
-      if (!preg_match("/^$num\\.$num\\.$num\\.$num$/", $this->ipHostNumber)){
-        $message[]= _("Wrong IP format in field IP-address.");
-      }
+    }
+
+    /* check if given ip is valid ip */
+    if ($this->ipHostNumber != "" && !is_ip($this->ipHostNumber)){
+      $message[]= _("Wrong IP format in field IP-address.");
     }
 
     /* Check if mac is empty 
@@ -280,8 +309,7 @@ class termDNS extends plugin
 
     /* Check if given mac is valid mac 
      */
-    $tr = count(split(":",$this->macAddress));
-    if($tr!=6){
+    if(!is_mac($this->macAddress)){
       $message[]=(_("The given macaddress is invalid. There must be 6 2byte segments seperated by ':'."));
     }
 
@@ -291,7 +319,8 @@ class termDNS extends plugin
       $checkArray = array();
       $onlyOnce   = array();
 
-      $onlyOnce['cNAMERecord'] = 0;
+                       // There can be many CNAME records
+      //$onlyOnce['cNAMERecord'] = 0;
 
       /* Walk through all entries and detect duplicates or mismatches
        */  
@@ -398,7 +427,7 @@ class termDNS extends plugin
        */
       foreach($tmp['add'] as $dn => $attrs){
         $ldap->cd($dn);
-        $ldap->cat($dn);
+        $ldap->cat($dn, array('dn'));
         if(count($ldap->fetch())){
           $ldap->cd($dn);
           $ldap->modify ($attrs); 
@@ -411,7 +440,7 @@ class termDNS extends plugin
       /* Display errors 
        */
       if($ldap->get_error() != "Success"){
-        show_ldap_error("Record:".$ldap->get_error()); 
+        show_ldap_error("Record:".$ldap->get_error(), _("Saving terminal to DNS object failed")); 
       }
     }
   }
@@ -423,7 +452,7 @@ class termDNS extends plugin
     $changeStateForRecords = "";
     
     if(!$this->DNS_is_account) {
-      $str = "<input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord' disabled>";
+      $str = "<input type='submit' value='"._("Add")."' name='AddNewRecord' id='AddNewRecord' disabled='disabled'>";
       return $str;
     }