Quellcode durchsuchen

bugfix: allow empty dns_name for user auth record

root vor 2 Jahren
Ursprung
Commit
3e25b3b9a5
2 geänderte Dateien mit 17 neuen und 14 gelöschten Zeilen
  1. 11 14
      html/admin/users/editauth.php
  2. 6 0
      html/inc/common.php

+ 11 - 14
html/admin/users/editauth.php

@@ -52,26 +52,23 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
         $new['comments'] = $_POST["f_comments"];
         $new['comments'] = $_POST["f_comments"];
         $new['WikiName'] = $_POST["f_wiki"];
         $new['WikiName'] = $_POST["f_wiki"];
         $f_dnsname = trim($_POST["f_dns_name"]);
         $f_dnsname = trim($_POST["f_dns_name"]);
+
         if (!empty($f_dnsname)) {
         if (!empty($f_dnsname)) {
             $domain_zone = get_option($db_link, 33);
             $domain_zone = get_option($db_link, 33);
             $f_dnsname = preg_replace('/'.$domain_zone.'/','',$f_dnsname);
             $f_dnsname = preg_replace('/'.$domain_zone.'/','',$f_dnsname);
             $f_dnsname = preg_replace('/\.$/','',$f_dnsname);
             $f_dnsname = preg_replace('/\.$/','',$f_dnsname);
             $f_dnsname = preg_replace('/\s+/','-',$f_dnsname);
             $f_dnsname = preg_replace('/\s+/','-',$f_dnsname);
             $f_dnsname = preg_replace('/\./','-',$f_dnsname);
             $f_dnsname = preg_replace('/\./','-',$f_dnsname);
-            }
-
-        if (!empty($f_dnsname) and checkValidHostname($f_dnsname) and checkUniqHostname($db_link,$id,$f_dnsname)) {
-            $new['dns_name'] = $f_dnsname;
-        } else {
-            $msg_error = "DNS $f_dnsname already exists at: ".searchHostname($db_link,$id,$f_dnsname)." Discard changes!";
-            $_SESSION[$page_url]['msg'] = $msg_error;
-            LOG_ERROR($db_link, $msg_error);
-            header("Location: " . $_SERVER["REQUEST_URI"]);
-            exit;
-        }
-        if (empty($f_dnsname)) {
-            $new['dns_name'] = '';
-        }
+            if (checkValidHostname($f_dnsname) and checkUniqHostname($db_link,$id,$f_dnsname)) {
+                    $new['dns_name'] = $f_dnsname;
+                } else {
+                    $msg_error = "DNS $f_dnsname already exists at: ".searchHostname($db_link,$id,$f_dnsname)." Discard changes!";
+                    $_SESSION[$page_url]['msg'] = $msg_error;
+                    LOG_ERROR($db_link, $msg_error);
+                    header("Location: " . $_SERVER["REQUEST_URI"]);
+                    exit;
+                }
+            } else { $new['dns_name'] = ''; }
 
 
         $new['save_traf'] = $_POST["f_save_traf"] * 1;
         $new['save_traf'] = $_POST["f_save_traf"] * 1;
         $new['dhcp_acl'] = trim($_POST["f_acl"]);
         $new['dhcp_acl'] = trim($_POST["f_acl"]);

+ 6 - 0
html/inc/common.php

@@ -168,6 +168,8 @@ function checkValidMac($mac)
 
 
 function checkValidHostname($dnsname)
 function checkValidHostname($dnsname)
 {
 {
+    if (empty($dnsname)) { return TRUE; }
+
     $host_pattern = "/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/";
     $host_pattern = "/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/";
     if (!preg_match($host_pattern, $dnsname)) {
     if (!preg_match($host_pattern, $dnsname)) {
         $result = FALSE;
         $result = FALSE;
@@ -179,6 +181,8 @@ function checkValidHostname($dnsname)
 
 
 function searchHostname($db, $id, $hostname) 
 function searchHostname($db, $id, $hostname) 
 {
 {
+    if (empty($hostname)) { return NULL; }
+
     $result = '';
     $result = '';
     $domain_zone = get_option($db, 33);
     $domain_zone = get_option($db, 33);
 
 
@@ -205,6 +209,8 @@ function searchHostname($db, $id, $hostname)
 
 
 function checkUniqHostname($db, $id, $hostname)
 function checkUniqHostname($db, $id, $hostname)
 {
 {
+    if (empty($hostname)) { return TRUE; }
+
     $domain_zone = get_option($db, 33);
     $domain_zone = get_option($db, 33);
 
 
     $check_A_filter = 'deleted=0 and id !="' . $id . '" and (dns_name ="' . mysqli_real_escape_string($db, $hostname) . '" or dns_name ="' . mysqli_real_escape_string($db, $hostname.'.'.$domain_zone) . '")';
     $check_A_filter = 'deleted=0 and id !="' . $id . '" and (dns_name ="' . mysqli_real_escape_string($db, $hostname) . '" or dns_name ="' . mysqli_real_escape_string($db, $hostname.'.'.$domain_zone) . '")';