Explorar el Código

fill comments in user ip records by fio field corresponded user

root hace 2 años
padre
commit
5d9b2ff4d8
Se han modificado 4 ficheros con 37 adiciones y 34 borrados
  1. 4 2
      html/admin/users/editauth.php
  2. 2 3
      html/admin/users/edituser.php
  3. 22 22
      html/inc/common.php
  4. 9 7
      scripts/eyelib/mysql.pm

+ 4 - 2
html/admin/users/editauth.php

@@ -109,7 +109,9 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
 
 if (isset($_POST["moveauth"]) and !$old_auth_info['deleted']) {
     $new_parent_id = $_POST["f_new_parent"] * 1;
-    $changes = apply_auth_rule($db_link, $id, $new_parent_id);
+    $moved_auth = get_record_sql($db_link,"SELECT comments FROM User_auth WHERE id=".$id);
+    $changes = apply_auth_rule($db_link, $moved_auth, $new_parent_id);
+    update_record($db_link, "User_auth", "id='$id'", $changes);
     LOG_WARNING($db_link, "IP-address moved to another user! Applyed: " . get_rec_str($changes), $id);
     run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$old_auth_info["user_id"]." AND rule='".$old_auth_info["mac"]."' AND type=2");
     run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$old_auth_info["user_id"]." AND rule='".$old_auth_info["ip"]."' AND type=1");
@@ -205,8 +207,8 @@ if (isset($_POST["recovery"]) and $old_auth_info['deleted']) {
         if (!empty($changes)) {
             LOG_WARNING($db_link, "Recovered ip-address. Applyed: $changes", $id);
         }
+        $new = apply_auth_rule($db_link, $new, $new['user_id']);
         update_record($db_link, "User_auth", "id='$id'", $new);
-        apply_auth_rule($db_link, $id, $new['user_id']);
     } else {
         $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx/xx";
         $_SESSION[$page_url]['msg'] = $msg_error;

+ 2 - 3
html/admin/users/edituser.php

@@ -160,7 +160,6 @@ if (isset($_POST["addauth"])) {
                 $new['dhcp']=$f_dhcp;
                 $new["dhcp_action"]='manual';
                 update_record($db_link,"User_auth","id=".$fid,$new);
-                apply_auth_rule($db_link,$fid,$id);
                 LOG_WARNING($db_link,"Add ip for login: ".$user_info["login"].": ip => $fip, mac => $fmac",$fid);
                 header("Location: /admin/users/editauth.php?id=".$fid);
                 exit;
@@ -195,7 +194,7 @@ if (isset($_POST["new_user"])) {
     $save_traf = get_option($db_link, 23) * 1;
     foreach ($auth_id as $key => $val) {
         if ($val) {
-	        $auth_info = get_record_sql($db_link,"SELECT ip, mac, comments, dns_name, dhcp_hostname FROM User_auth WHERE id=$val");
+	    $auth_info = get_record_sql($db_link,"SELECT ip, mac, comments, dns_name, dhcp_hostname FROM User_auth WHERE id=$val");
             $ou_id = $user_info["ou_id"];
             $login = NULL;
             if (!empty($auth_info["dns_name"])) { $login = $auth_info["dns_name"]; }
@@ -209,8 +208,8 @@ if (isset($_POST["new_user"])) {
                 $auth["user_id"] = $new_user["id"];
                 $auth["ou_id"] = $new_user["ou_id"];
                 $auth["save_traf"] = $save_traf;
+                $auth=apply_auth_rule($db_link,$auth,$l_id);
                 update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
-                apply_auth_rule($db_link,$val,$l_id);
                 LOG_WARNING($db_link,"ip from id: $val moved to another user user_id: ".$new_user["id"], $val);
             } else {
                 $new["login"] = $login;

+ 22 - 22
html/inc/common.php

@@ -1611,27 +1611,25 @@ function find_mac_in_subnet($db, $ip, $mac)
     return $result;
 }
 
-function apply_auth_rule($db, $auth_id, $user_id)
+function apply_auth_rule($db, $auth_record, $user_id)
 {
-    if (empty($auth_id)) {
-        return;
-    }
-    if (empty($user_id)) {
-        return;
-    }
+    if (empty($auth_record)) { return; }
+    if (empty($user_id)) { return $auth_record; }
+
     $user_rec = get_record($db, 'User_list', "id=" . $user_id);
-    if (empty($user_rec)) {
-        return;
-    }
+    if (empty($user_rec)) { return $auth_record; }
+
     //set filter and status by user
-    $set_auth['ou_id'] = $user_rec['ou_id'];
-    $set_auth['user_id'] = $user_rec['id'];
-    $set_auth['filter_group_id'] = $user_rec['filter_group_id'];
-    $set_auth['queue_id'] = $user_rec['queue_id'];
-    $set_auth['enabled'] = $user_rec['enabled'];
-    $set_auth['changed'] = 1;
-    update_record($db, "User_auth", "id=$auth_id", $set_auth);
-    return $set_auth;
+    $auth_record['ou_id'] = $user_rec['ou_id'];
+    $auth_record['user_id'] = $user_rec['id'];
+    $auth_record['filter_group_id'] = $user_rec['filter_group_id'];
+    $auth_record['queue_id'] = $user_rec['queue_id'];
+    $auth_record['enabled'] = $user_rec['enabled'];
+    $auth_record['changed'] = 1;
+    //maybe fill comments?
+    if (!empty($user_rec['fio']) and empty($auth_record['comments'])) { $auth_record['comments'] = $user_rec['fio']; }
+
+    return $auth_record;
 }
 
 function fix_auth_rules($db)
@@ -1709,7 +1707,7 @@ function new_auth($db, $ip, $mac, $user_id)
         }
     }
 
-    // default id
+    // save traffic detailization
     $save_traf = get_option($db, 23);
     $resurrection_id = NULL;
 
@@ -1735,7 +1733,8 @@ function new_auth($db, $ip, $mac, $user_id)
 
     //check rules, update filter and state for new record
     if (!empty($resurrection_id)) {
-        apply_auth_rule($db, $resurrection_id, $user_id);
+        $auth=apply_auth_rule($db, $auth, $user_id);
+        update_record($db, "User_auth", "id=$resurrection_id", $auth);
         if (!is_hotspot($db, $ip) and !empty($msg)) {
             LOG_WARNING($db, $msg);
         }
@@ -1854,8 +1853,9 @@ function resurrection_auth($db, $ip_record)
     }
     //check rules, update filter and state for new record
     if (!empty($resurrection_id)) {
-        $user_rec = apply_auth_rule($db, $resurrection_id, $new_user_id);
-        $msg .= "filter: " . $user_rec['filter_group_id'] . "\r\n queue_id: " . $user_rec['queue_id'] . "\r\n enabled: " . $user_rec['enabled'] . "\r\nid: $resurrection_id";
+        $auth = apply_auth_rule($db, $auth, $new_user_id);
+        update_record($db, "User_auth", "id=$resurrection_id", $auth);
+        $msg .= "filter: " . $auth['filter_group_id'] . "\r\n queue_id: " . $auth['queue_id'] . "\r\n enabled: " . $auth['enabled'] . "\r\nid: $resurrection_id";
         if (!$hotspot_found and !empty($msg)) {
             LOG_WARNING($db, $msg);
         }

+ 9 - 7
scripts/eyelib/mysql.pm

@@ -1025,13 +1025,14 @@ if ($auth_exists) {
 #filter and status
 my $cur_auth_id=get_id_record($db,'User_auth',"ip='$ip' and mac='$mac' and deleted=0 ORDER BY last_found DESC");
 if ($cur_auth_id) {
-    $record=get_record_sql($db,"SELECT * FROM User_list WHERE id=".$new_user_id);
-    if ($record) {
-	    $new_record->{ou_id}=$record->{ou_id};
-	    $new_record->{filter_group_id}=$record->{filter_group_id};
-	    $new_record->{queue_id}=$record->{queue_id};
-	    $new_record->{enabled}="$record->{enabled}";
-        update_record($db,'User_auth',$new_record,"id=$cur_auth_id");
+    my $user_record=get_record_sql($db,"SELECT * FROM User_list WHERE id=".$new_user_id);
+    if ($user_record) {
+	    $new_record->{ou_id}=$user_record->{ou_id};
+	    $new_record->{comments}=$user_record->{fio};
+	    $new_record->{filter_group_id}=$user_record->{filter_group_id};
+	    $new_record->{queue_id}=$user_record->{queue_id};
+	    $new_record->{enabled}="$user_record->{enabled}";
+            update_record($db,'User_auth',$new_record,"id=$cur_auth_id");
 	    }
     } else { return; }
 return $cur_auth_id;
@@ -1063,6 +1064,7 @@ $new_record->{ou_id}=$user_record->{ou_id};
 $new_record->{filter_group_id}=$user_record->{filter_group_id};
 $new_record->{queue_id}=$user_record->{queue_id};
 $new_record->{enabled}="$user_record->{enabled}";
+$new_record->{comments}=$user_record->{fio};
 my $cur_auth_id=insert_record($db,'User_auth',$new_record);
 db_log_warning($db,"New ip created by netflow! ip: $ip") if ($cur_auth_id);
 return $cur_auth_id;