浏览代码

and again

Roman Dmitriev 3 月之前
父节点
当前提交
d5d14eb806
共有 4 个文件被更改,包括 44 次插入41 次删除
  1. 0 37
      scripts/eyelib/common.pm
  2. 29 1
      scripts/eyelib/database.pm
  3. 13 0
      scripts/eyelib/main.pm
  4. 2 3
      scripts/fetch_new_arp.pl

+ 0 - 37
scripts/eyelib/common.pm

@@ -42,11 +42,9 @@ get_default_ou
 get_device_by_ip
 get_dns_name
 get_dynamic_ou
-get_first_line
 get_ip_subnet
 get_new_user_id
 GetNowTime
-get_office_subnet
 get_subnets_ref
 GetTimeStrByUnixTime
 GetUnixTimeByStr
@@ -74,18 +72,6 @@ BEGIN
 
 #---------------------------------------------------------------------------------------------------------------
 
-sub get_first_line {
-my $msg = shift;
-if (!$msg) { return; }
-if ($msg=~ /(.*)(\n|\<br\>)/) {
-    $msg = $1 if ($1);
-    chomp($msg);
-    }
-return $msg;
-}
-
-#---------------------------------------------------------------------------------------------------------------
-
 sub unbind_ports {
     my ($db, $device_id) = @_;
     return unless $db && defined $device_id && $device_id =~ /^\d+$/;  
@@ -273,29 +259,6 @@ sub delete_device {
 
 #---------------------------------------------------------------------------------------------------------------
 
-sub get_office_subnet {
-    my ($db, $ip) = @_;
-    return undef unless $db && defined $ip;
-
-    my @rows = get_records_sql(
-        $db,
-        "SELECT * FROM subnets WHERE office = 1 AND LENGTH(subnet) > 0"
-    );
-
-    return undef unless @rows;
-
-    my $pat = Net::Patricia->new;
-    for my $row (@rows) {
-        next unless defined $row->{subnet};
-        # Защита от некорректных подсетей в БД
-        eval { $pat->add_string($row->{subnet}, $row); 1 } or next;
-    }
-
-    return $pat->match_string($ip);
-}
-
-#---------------------------------------------------------------------------------------------------------------
-
 sub get_new_user_id {
     my ($db, $ip, $mac, $hostname) = @_;
     return unless $db;

+ 29 - 1
scripts/eyelib/database.pm

@@ -20,6 +20,9 @@ package eyelib::database;
 #}
 #$db->{AutoCommit} = 1;
 
+use warnings FATAL => 'all';
+use feature ':5.20';
+
 use utf8;
 use open ":encoding(utf8)";
 use strict;
@@ -43,6 +46,7 @@ use Text::CSV;
 our @ISA = qw(Exporter);
 
 our @EXPORT = qw(
+get_office_subnet
 get_notify_subnet
 is_hotspot
 get_queue
@@ -149,6 +153,29 @@ our %db_schema;
 
 #---------------------------------------------------------------------------------------------------------------
 
+sub get_office_subnet {
+    my ($db, $ip) = @_;
+    return undef unless $db && defined $ip;
+
+    my @rows = get_records_sql(
+        $db,
+        "SELECT * FROM subnets WHERE office = 1 AND LENGTH(subnet) > 0"
+    );
+
+    return undef unless @rows;
+
+    my $pat = Net::Patricia->new;
+    for my $row (@rows) {
+        next unless defined $row->{subnet};
+        # Защита от некорректных подсетей в БД
+        eval { $pat->add_string($row->{subnet}, $row); 1 } or next;
+    }
+
+    return $pat->match_string($ip);
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
 sub get_notify_subnet {
 my $db = shift;
 my $ip  = shift;
@@ -1553,7 +1580,8 @@ if ($table eq "user_auth") {
 
 for my $field (keys %$record) {
         my $old_val = defined $old_record->{$field} ? $old_record->{$field} : '';
-        my $new_val =  normalize_value($record->{$field}, $db_schema{$db_info->{db_type}}{$db_info->{db_name}}{$table}{$field});
+        my $new_val =  normalize_value( $record->{$field}, $db_schema{$db_info->{db_type}}{$db_info->{db_name}}{$table}{$field});
+        $new_val = defined $new_val ? $new_val : '';
         if ($new_val ne $old_val) {
             $set_clause .= " $field = ?, ";
             push @update_params, $new_val;

+ 13 - 0
scripts/eyelib/main.pm

@@ -23,6 +23,7 @@ use MIME::Base64;
 
 our @ISA = qw(Exporter);
 our @EXPORT = qw(
+get_first_line
 isNotifyCreate
 isNotifyUpdate
 isNotifyDelete
@@ -74,6 +75,18 @@ GetTimeStrByUnixTime
 BEGIN
 {
 
+#---------------------------------------------------------------------------------------------------------------
+
+sub get_first_line {
+my $msg = shift;
+if (!$msg) { return; }
+if ($msg=~ /(.*)(\n|\<br\>)/) {
+    $msg = $1 if ($1);
+    chomp($msg);
+    }
+return $msg;
+}
+
 #---------------------------------------------------------------------------------------------------------
 # Проверяет, установлен ли флаг создания
 

+ 2 - 3
scripts/fetch_new_arp.pl

@@ -210,6 +210,7 @@ foreach my $arp_table (@arp_array) {
         db_log_debug($dbh, "Analyze ip: $ip mac: $mac") if ($debug);
 
         my $auth_id = $users->match_string($ip);
+	
         my $arp_record;
         $arp_record->{ip}        = $ip;
         $arp_record->{mac}       = $mac;
@@ -225,9 +226,7 @@ foreach my $arp_table (@arp_array) {
             $mac_history{$simple_mac}{auth_id} = $cur_auth_id;
             $arp_record->{auth_id} = $cur_auth_id;
             # Mark as changed if IP-to-auth mapping differs from previous state
-            if ($auth_id ne $cur_auth_id) {
-                $mac_history{$simple_mac}{changed} = 1;
-            }
+            if (!$auth_id || $auth_id ne $cur_auth_id) { $mac_history{$simple_mac}{changed} = 1; }
         }
     }
 }