Kaynağa Gözat

mute email event for hotspot network

rajven 3 yıl önce
ebeveyn
işleme
1cca9edb9d

+ 0 - 2
docs/iptables/parse_ulog.pl

@@ -195,8 +195,6 @@ $user_ip_aton=StrToIp($user_ip);
 my $auth_id=new_auth($dbh,$user_ip);
 next if (!$auth_id);
 
-db_log_warning($dbh,"New ip $user_ip added by netflow!");
-
 my $new_user = get_record_sql($dbh,"SELECT * FROM User_auth WHERE id=$auth_id");
 
 $users->add_string($user_ip,$auth_id);

+ 15 - 10
html/admin/users/add_dhcp.php

@@ -11,28 +11,33 @@ if (!empty($_GET["ip"]) and !empty($_GET["mac"])) {
     if ($faction == 1) { $action = 'add'; }
     if ($faction == 0) { $action = 'del'; }
 
+	$dhcp_record['ip']=$ip;
+	$dhcp_record['mac']=$mac;
+	$dhcp_record['type']=$action;
+	$dhcp_record['hostname']=$dhcp_hostname;
+	$dhcp_record['hotspot']=is_hotspot($db_link,$ip);
+	$dhcp_record['ip_aton']=ip2long($ip);
+
     LOG_VERBOSE($db_link, "external dhcp request for $ip [$mac] $action");
     if (checkValidIp($ip) and is_our_network($db_link, $ip)) {
 		$log_dhcp = 1;
-        $ip_aton = ip2long($ip);
 		//check hotspot
-		$hotspot_user = is_hotspot($db_link,$ip);
-		if ($hotspot_user) {
+		if ($dhcp_record['hotspot']) {
 			LOG_DEBUG($db_link,"Hotspot user found!");
 			$log_dhcp_hotspot = get_option($db_link,44);
 			if (!isset($log_dhcp_hotspot)) { $log_dhcp_hotspot = 0; }
 			$log_dhcp = !$log_dhcp_hotspot;
 			}
-		$auth = get_record_sql($db_link,"SELECT * FROM User_auth WHERE ip_int=" . $ip_aton . " AND deleted=0");
+		$auth = get_record_sql($db_link,"SELECT * FROM User_auth WHERE ip_int=" . $dhcp_record['ip_aton'] . " AND deleted=0");
 		$aid = NULL;
 		if (!empty($auth)) {
 	    	$aid = $auth['id'];
 	    	LOG_VERBOSE($db_link,"Found auth for dhcp id: $aid with ip: $ip mac: $mac",$aid);
             } else {
 	    	LOG_VERBOSE($db_link,"User ip record not found for ip: $ip mac: $mac action: $action. Create it!",0);
-	    	$aid = resurrection_auth($db_link, $ip, $mac, $action, $dhcp_hostname);
+	    	$aid = resurrection_auth($db_link, $dhcp_record);
 	    	if (empty($aid)) {
-                LOG_ERRROR($db_link,"Failed create new user record",0);
+                LOG_ERROR($db_link,"Failed create new user record for ip: $ip mac: $mac",0);
                 exit;
                 }
 	    	LOG_VERBOSE($db_link,"Add user by dhcp request ip: $ip mac: $mac action: $action",$aid);
@@ -53,11 +58,11 @@ if (!empty($_GET["ip"]) and !empty($_GET["mac"])) {
 	    	}
         	if ($log_dhcp) {
     	        $dhcp_log['auth_id'] = $aid;
-                $dhcp_log['ip'] = $ip;
-	        	$dhcp_log['ip_int'] = $ip_aton;
-                $dhcp_log['mac'] = $mac;
-	        	$dhcp_log['action'] = $action;
 	        	$dhcp_log['dhcp_hostname'] = $dhcp_hostname;
+				$dhcp_log['ip']=$dhcp_record['ip'];
+				$dhcp_log['mac']=$dhcp_record['mac'];
+				$dhcp_log['action']=$dhcp_record['type'];
+				$dhcp_log['ip_int']=$dhcp_record['ip_aton'];
     	        insert_record($db_link, "dhcp_log", $dhcp_log); 
     	        }
         } else { LOG_ERROR($db_link, "$ip - wrong network!"); }

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

@@ -85,18 +85,18 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
         }
         if ($new['nagios'] == 0) {
             $new['nagios_status'] = 'UP';
-        }
+            }
         $changes = get_diff_rec($db_link, "User_auth", "id='$id'", $new, 0);
         if (!empty($changes)) {
             LOG_WARNING($db_link, "Changed record for $ip! Log: " . $changes, $id);
-        }
+            }
         if (is_auth_bind_changed($db_link, $id, $ip, $mac)) {
             $new_id = copy_auth($db_link, $id, $new);
             header("Location: /admin/users/editauth.php?id=" . $new_id, TRUE, 302);
             exit;
-        } else {
+            } else {
             update_record($db_link, "User_auth", "id='$id'", $new);
-        }
+            }
     } else {
         $msg_error = "$msg_ip_error xxx.xxx.xxx.xxx";
         $_SESSION[$page_url]['msg'] = $msg_error;

+ 19 - 10
html/inc/common.php

@@ -1379,11 +1379,11 @@ function new_auth($db, $ip, $mac, $user_id)
 
     if (!empty($mac)) {
         $auth_record = get_record_sql($db, "SELECT * FROM User_auth WHERE ip_int=$ip_aton AND mac='" . mac_dotted($mac) . "' AND deleted=0");
-	if (!empty($auth_record)) {
+	    if (!empty($auth_record)) {
 	        LOG_WARNING($db, "Pair ip-mac already exists! Skip creating $ip [$mac] auth_id: ".$auth_record["id"]);
     		return $auth_record['id'];
+	        }
 	    }
-	}
 
     // default id
     $save_traf = get_option($db, 23);
@@ -1392,14 +1392,14 @@ function new_auth($db, $ip, $mac, $user_id)
     // seek old auth with same ip and mac
     $resurrection_id = get_id_record($db, 'User_auth', " deleted=1 AND ip_int=" . $ip_aton . " AND mac='" . $mac . "'");
     if (!empty($resurrection_id)) {
-        $msg.="Восстанавливаем доступ для auth_id: $resurrection_id with ip: $ip and mac: $mac ";
+        $msg.="Recovered auth_id: $resurrection_id with ip: $ip and mac: $mac ";
         $auth['user_id'] = $user_id;
         $auth['deleted'] = 0;
         $auth['save_traf'] = $save_traf *1;
         update_record($db, "User_auth", "id=$resurrection_id", $auth);
         } else {
         // not found ->create new record
-        $msg.="Создаём новый ip-адрес \r\nip: $ip\r\nmac: $mac\r\n";
+        $msg.="Create new ip record \r\nip: $ip\r\nmac: $mac\r\n";
         $auth['deleted'] = 0;
         $auth['user_id'] = $user_id;
         $auth['ip'] = $ip;
@@ -1418,9 +1418,16 @@ function new_auth($db, $ip, $mac, $user_id)
     return $resurrection_id;
 }
 
-function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
+function resurrection_auth($db, $ip_record )
 {
+    $ip = $ip_record['ip'];
+    $mac = $ip_record['mac'];
+    $action = $ip_record['type'];
+    $dhcp_hostname = $ip_record['hostname'];
+    $hotspot_found = $ip_record['hotspot'];
+
     $ip_aton = ip2long($ip);
+    
     $auth_record= get_record_sql($db, "SELECT * FROM User_auth WHERE ip_int=$ip_aton AND mac='" . $mac . "' AND deleted=0");
     if (!empty($auth_record)) {
         $user_info = get_record_sql($db, "SELECT * FROM User_list WHERE id=".$auth_record['user_id']);
@@ -1453,7 +1460,9 @@ function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
             update_record($db, "User_auth", "id=" . $auth_record['id'], $auth);
             return $auth_record['id'];
         } else {
-            LOG_WARNING($db, "for ip: $ip mac change detected! Old mac: [".$auth_record['mac']."] New mac: [".mac_dotted($mac)."]. Disable old auth_id: ".$auth_record['id']);
+            if (!$hotspot_found) {
+                LOG_WARNING($db, "for ip: $ip mac change detected! Old mac: [".$auth_record['mac']."] New mac: [".mac_dotted($mac)."]. Disable old auth_id: ".$auth_record['id']);
+                }
             run_sql($db, "UPDATE User_auth SET changed=1, deleted=1 WHERE id=" . $auth_record['id']);
         }
     }
@@ -1471,7 +1480,7 @@ function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
     if (!empty($auth_record)) {
         // found ->Resurrection old record
         $resurrection_id = $auth_record['id'];
-        $msg .="Восстанавливаем доступ для auth_id: $resurrection_id with ip: $ip and mac: $mac ";
+        $msg .="Recovered auth_id: $resurrection_id with ip: $ip and mac: $mac ";
         $auth['dhcp_action'] = $action;
         $auth['user_id'] = $new_user_id;
         $auth['deleted'] = 0;
@@ -1497,10 +1506,10 @@ function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
     }
     //check rules, update filter and state for new record
     if (!empty($resurrection_id)) {
-            $user_rec=apply_auth_rule($db,$resurrection_id,$new_user_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";
-	    if (!is_hotspot($db,$ip) and !empty($msg)) { LOG_WARNING($db, $msg); }
-	    if (is_hotspot($db,$ip) and !empty($msg)) { LOG_INFO($db, $msg); }
+	    if (!$hotspot_found and !empty($msg)) { LOG_WARNING($db, $msg); }
+	    if ($hotspot_found and !empty($msg)) { LOG_INFO($db, $msg); }
 	    }
 
     return $resurrection_id;

+ 2 - 4
scripts/Rstat/config.pm

@@ -120,8 +120,6 @@ if (! -e "$config_file") { die "Config $config_file not found!"; }
 my $Config = Config::Tiny->new;
 $Config = Config::Tiny->read($config_file, 'utf8' );
 
-#print Dumper($Config);
-
 our %config_ref;
 
 ### current script pathname
@@ -197,8 +195,8 @@ our $DBUSER 		= $Config->{_}->{DBUSER} || "rstat";
 our $DBPASS 		= $Config->{_}->{DBPASS} || "rstat";
 
 our $domain_auth	= $Config->{_}->{domain_auth} || 'Administrator%password';
-our $winexe		= $Config->{_}->{winexe} || '/usr/bin/winexe';
-our $fping		= $Config->{_}->{fping} || '/sbin/fping';
+our $winexe		    = $Config->{_}->{winexe} || '/usr/bin/winexe';
+our $fping		    = $Config->{_}->{fping} || '/sbin/fping';
 
 our @subnets=();
 

+ 24 - 21
scripts/Rstat/mysql.pm

@@ -829,12 +829,15 @@ return $result;
 
 sub resurrection_auth {
 my $db = shift;
-my $ip = shift;
-my $mac = shift;
-my $action = shift;
-my $hostname = shift;
+my $ip_record = shift;
 
-my $ip_aton=StrToIp($ip);
+my $ip = $ip_record->{ip};
+my $mac = $ip_record->{mac};
+my $action = $ip_record->{type};
+my $hostname = $ip_record->{hostname};
+
+if (!exists $ip_record->{ip_aton}) { $ip_record->{ip_aton}=StrToIp($ip); }
+my $ip_aton=$ip_record->{ip_aton};
 
 my $timestamp=GetNowTime();
 
@@ -870,18 +873,18 @@ if ($record->{id}) {
     if (!$record->{mac}) {
         db_log_verbose($db,"use empty auth record...");
         $new_record->{mac}=$mac;
-	if ($action!~/arp/i) {
-	    $new_record->{dhcp_action}=$action;
-	    $new_record->{dhcp_time}=$timestamp;
-	    if ($hostname) { $new_record->{dhcp_hostname} = $hostname; }
-	    update_record($db,'User_auth',$new_record,"id=$record->{id}");
-            } else {
-	    update_record($db,'User_auth',$new_record,"id=$record->{id}");
-	    }
+	    if ($action!~/arp/i) {
+	        $new_record->{dhcp_action}=$action;
+	        $new_record->{dhcp_time}=$timestamp;
+	        if ($hostname) { $new_record->{dhcp_hostname} = $hostname; }
+	            update_record($db,'User_auth',$new_record,"id=$record->{id}");
+                } else {
+	            update_record($db,'User_auth',$new_record,"id=$record->{id}");
+	            }
         return $record->{id};
         }
     if ($record->{mac}) {
-        db_log_warning($db,"For ip: $ip mac change detected! Old mac: [".$record->{mac}."] New mac: [".$mac."]. Disable old auth_id: $record->{id}");
+        db_log_warning($db,"For ip: $ip mac change detected! Old mac: [".$record->{mac}."] New mac: [".$mac."]. Disable old auth_id: $record->{id}") if (!$ip_record->{hotspot});
         my $disable_record;
         $disable_record->{deleted}="1";
         update_record($db,'User_auth',$disable_record,"id=".$record->{id});
@@ -907,12 +910,12 @@ $new_record->{dhcp_time}=$timestamp;
 if ($auth_exists) {
     #found ->Resurrection old record
     my $resurrection_id = get_id_record($db,'User_auth',"ip_int=".$ip_aton." and mac='".$mac."'");
-    if (!is_hotspot($db,$ip)) { db_log_warning($db,"Resurrection auth_id: $resurrection_id with ip: $ip and mac: $mac"); }
+    if (!$ip_record->{hotspot}) { db_log_warning($db,"Resurrection auth_id: $resurrection_id with ip: $ip and mac: $mac"); }
 	    else { db_log_info($db,"Resurrection auth_id: $resurrection_id with ip: $ip and mac: $mac"); }
     update_record($db,'User_auth',$new_record,"id=$resurrection_id");
     } else {
     #not found ->create new record
-    if (!is_hotspot($db,$ip)) { db_log_warning($db,"New ip created! ip: $ip mac: $mac"); } else { db_log_info($db,"New ip created! ip: $ip mac: $mac"); }
+    if (!$ip_record->{hotspot}) { db_log_warning($db,"New ip created! ip: $ip mac: $mac"); } else { db_log_info($db,"New ip created! ip: $ip mac: $mac"); }
     insert_record($db,'User_auth',$new_record);
     }
 #filter and status
@@ -920,12 +923,12 @@ my $cur_auth_id=get_id_record($db,'User_auth',"ip='$ip' and mac='$mac' and delet
 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}";
+	    $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");
-	}
+	    }
     } else { return; }
 return $cur_auth_id;
 }

+ 5 - 4
scripts/dhcp-log.pl

@@ -146,6 +146,7 @@ if (!$pid) {
             $dhcp_record->{hostname_utf8}=$converter->convert($client_hostname);
             $dhcp_record->{timestamp} = $timestamp;
             $dhcp_record->{last_time} = time();
+            $dhcp_record->{hotspot}=is_hotspot($dbh,$dhcp_record->{ip});
             $leases{$ip}=$dhcp_record;
 
             log_debug(uc($type).">>");
@@ -159,17 +160,17 @@ if (!$pid) {
             log_debug("END GET");
 
             my $auth_record = get_record_sql($hdb,'SELECT * FROM User_auth WHERE ip="'.$dhcp_record->{ip}.'" and mac="'.$mac.'" and deleted=0 ORDER BY last_found DESC');
-	    if (!$auth_record and $type eq 'old' ) { $type='add'; }
+	        if (!$auth_record and $type eq 'old' ) { $type='add'; }
 
             if ($type eq 'add') {
-                my $res_id = resurrection_auth($hdb,$dhcp_record->{ip},$mac,$type,$dhcp_record->{hostname_utf8});
+                my $res_id = resurrection_auth($hdb,$dhcp_record);
                 next if (!$res_id);
                 $auth_record = get_record_sql($hdb,'SELECT * FROM User_auth WHERE id='.$res_id);
                 db_log_info($hdb,"Check for new auth. Found id: $res_id",$res_id);
                 } else { $auth_record = get_record_sql($hdb,'SELECT * FROM User_auth WHERE ip="'.$dhcp_record->{ip}.'" and mac="'.$mac.'" and deleted=0 ORDER BY last_found DESC'); }
 
             my $auth_id = $auth_record->{id};
-	    my $auth_ou_id = $auth_record->{ou_id};
+	        my $auth_ou_id = $auth_record->{ou_id};
 
             update_dns_record($hdb,$dhcp_record,$auth_record);
 
@@ -181,7 +182,7 @@ if (!$pid) {
                 update_record($hdb,'User_auth',$auth_rec,"id=$auth_id");
                 }
 
-            if ($hotspot_networks->match_string($dhcp_record->{ip}) and $ignore_hotspot_dhcp_log) { next; }
+            if ($dhcp_record->{hotspot} and $ignore_hotspot_dhcp_log) { next; }
 
             if ($ignore_update_dhcp_event and $type=~/old/i) { next; }
 

+ 7 - 2
scripts/fetch_new_arp.pl

@@ -129,14 +129,19 @@ foreach my $arp_table (@arp_array) {
         next if (!$office_networks->match_string($ip));
         db_log_debug($dbh,"Analyze ip: $ip mac: $mac") if ($debug);
         my $auth_id = $users->match_string($ip);
-        my $cur_auth_id=resurrection_auth($dbh,$ip,$mac,'arp');
+        my $arp_record;
+        $arp_record->{ip} = $ip;
+        $arp_record->{mac} = $mac;
+        $arp_record->{type} = 'arp';
+        $arp_record->{ip_aton} = $ip_aton;
+        $arp_record->{hotspot} = is_hotspot($dbh,$ip);
+        my $cur_auth_id=resurrection_auth($dbh,$arp_record);
         next if (!$cur_auth_id);
         $mac_history{$simple_mac}{auth_id}=$cur_auth_id;
         if ($auth_id ne $cur_auth_id) { $mac_history{$simple_mac}{changed}=1; }
     }
 }
 
-
 db_log_verbose($dbh,'Arp discovery stopped.');
 }