Przeglądaj źródła

dont create few auto rules in user edit form

Roman Dmitriev 2 lat temu
rodzic
commit
df46bceeab
1 zmienionych plików z 19 dodań i 11 usunięć
  1. 19 11
      html/admin/users/edituser.php

+ 19 - 11
html/admin/users/edituser.php

@@ -46,11 +46,15 @@ if (isset($_POST["addMacRule"])) {
     unset($new);
     $first_auth = get_record_sql($db_link,"SELECT mac FROM User_auth WHERE user_id=".$id." AND deleted=0 AND LENGTH(mac)>0 ORDER BY id");
     if (!empty($first_auth) and !empty($first_auth['mac'])) {
-        $new['user_id']=$id;
-        $new['type']=2;
-        $new['rule']=$first_auth['mac'];
-	    insert_record($db_link,"auth_rules",$new);
-	    LOG_INFO($db_link,"Create auto rule at id: ".$id." login: ".$user_info["login"]." for mac ".$first_auth['mac']);
+        $auth_rules_user = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$id." AND type=2");
+        $auth_rules_mac = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE rule='".$first_auth['mac']."' AND type=2");
+        if (empty($auth_rules_user) and empty($auth_rules_mac)) {
+            $new['user_id']=$id;
+            $new['type']=2;
+            $new['rule']=$first_auth['mac'];
+	        insert_record($db_link,"auth_rules",$new);
+	        LOG_INFO($db_link,"Create auto rule at id: ".$id." login: ".$user_info["login"]." for mac ".$first_auth['mac']);
+            }
 	    }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
@@ -67,12 +71,16 @@ if (isset($_POST["addIPRule"])) {
     unset($new);
     $first_auth = get_record_sql($db_link,"SELECT ip FROM User_auth WHERE user_id=".$id." AND deleted=0 AND LENGTH(ip)>0 ORDER BY id");
     if (!empty($first_auth) and !empty($first_auth['ip'])) {
-        $new['user_id']=$id;
-        $new['type']=1;
-        $new['rule']=$first_auth['ip'];
-	    insert_record($db_link,"auth_rules",$new);
-	    LOG_INFO($db_link,"Create auto rule id: ".$id." login: ".$user_info["login"]." for ip ".$first_auth['IP']);
-	}
+        $auth_rules_user = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$id." AND type=1");
+        $auth_rules_ip = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE rule='".$first_auth['ip']."' AND type=1");
+        if (empty($auth_rules_user) and empty($auth_rules_ip)) {
+            $new['user_id']=$id;
+            $new['type']=1;
+            $new['rule']=$first_auth['ip'];
+	        insert_record($db_link,"auth_rules",$new);
+	        LOG_INFO($db_link,"Create auto rule id: ".$id." login: ".$user_info["login"]." for ip ".$first_auth['ip']);
+            }
+	    }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }