Forráskód Böngészése

disabled dhcp for auto created ip+mac record in subnets with already exists same mac

Roman Dmitriev 2 éve
szülő
commit
6b3cc36aaf
2 módosított fájl, 40 hozzáadás és 2 törlés
  1. 39 1
      scripts/Rstat/mysql.pm
  2. 1 1
      scripts/dhcp-log.pl

+ 39 - 1
scripts/Rstat/mysql.pm

@@ -834,6 +834,40 @@ return $result;
 
 #---------------------------------------------------------------------------------------------------------------
 
+sub get_ip_subnet {
+    my $db = shift;
+    my $ip = shift;
+    if (!$ip) { return; }
+    my $ip_aton = StrToIp($ip);
+    my $user_subnet = get_record_sql($db, "SELECT * FROM `subnets` WHERE hotspot=1 or office=1 and ( ".$ip_aton." >= ip_int_start and ".$ip_aton." <= ip_int_stop)");
+    return $user_subnet;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
+sub find_mac_in_subnet {
+    my $db = shift;
+    my $ip = shift;
+    my $mac = shift;
+    if (!$ip or !$mac) { return; }
+    $ip_subnet = get_ip_subnet($db, $ip);
+    if (!$ip_subnet) { return; }
+    my @t_auth = get_records_sql($db, "SELECT id,mac,user_id FROM User_auth WHERE ip_int>=" . $ip_subnet->{'ip_int_start'} . " and ip_int<=" . $ip_subnet->{'ip_int_stop'} . " and mac='" . $mac . "' and deleted=0 ORDER BY id");
+    my $auth_count = 0;
+    my $result;
+    $result->{'count'} = 0;
+    foreach my $row (@t_auth) {
+        next if (!$row);
+        $auth_count++;
+        $result->{'count'} = $auth_count;
+        $result->{$auth_count} = $row->{'id'};
+        push(@{$result->{'users_id'}}, $row->{'user_id'});
+        }
+    return $result;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
 sub resurrection_auth {
 my $db = shift;
 my $ip_record = shift;
@@ -873,7 +907,7 @@ if ($record->{user_id}) {
 
 my $user_subnet=$office_networks->match_string($ip);
 if ($user_subnet->{static}) {
-    db_log_warning($db,"Unknown ip+mac found in static subnet! Stop work for ip: $ip mac: [".$mac."]");
+    db_log_warning($db,"Unknown ip+mac found in static subnet! Abort create record for ip: $ip mac: [".$mac."]");
     return 0;
     }
 
@@ -908,6 +942,10 @@ my $new_user_id;
 if ($new_user_info->{user_id}) { $new_user_id = $new_user_info->{user_id}; }
 if (!$new_user_id) { $new_user_id = new_user($db,$new_user_info); }
 
+my $mac_exists=find_mac_in_subnet($db,$ip,$mac);
+#disable dhcp for same mac in one ip subnet
+if ($mac_exists and $mac_exists->{'count'}) { $new_record->{dhcp}=0; }
+
 #seek old auth with same ip and mac
 my $auth_exists=get_count_records($db,'User_auth',"ip_int=".$ip_aton." and mac='".$mac."'");
 $new_record->{ip_int}=$ip_aton;

+ 1 - 1
scripts/dhcp-log.pl

@@ -277,7 +277,7 @@ if (!$pid) {
                         if ($t_circuit_id=~/\s*$port_data->{'ifName'}$/i or $t_circuit_id=~/^$port_data->{'ifName'}\s+/i ) { $switch_port = $port_data; last; }
                         }
 
-                    #detect hex - get last byte
+                    #detect hex - get last 2 byte
                     if (!$switch_port) {
                         my $hex_port = substr($decoded_circuit_id, -2);
                         if ($hex_port) {