Sfoglia il codice sorgente

The function of assigning a new address to a user/group has been redesigned. Now, no other rules apply to addresses from the hotspot range. Any match stops processing the remaining rules.

root 1 anno fa
parent
commit
46d6f6428e
2 ha cambiato i file con 23 aggiunte e 20 eliminazioni
  1. 11 7
      html/inc/common.php
  2. 12 13
      scripts/eyelib/database.pm

+ 11 - 7
html/inc/common.php

@@ -2960,6 +2960,11 @@ function get_new_user_id($db, $ip, $mac, $hostname)
     $result['ou_id'] = NULL;
     $ip_aton = ip2long($ip);
 
+    if (is_hotspot($db, $ip)) {
+            $result['ou_id'] = get_const('default_hotspot_ou_id');
+            return $result;
+        }
+
     //personal user rules
     //ip
     if (!empty($ip)) {
@@ -2967,6 +2972,7 @@ function get_new_user_id($db, $ip, $mac, $hostname)
         foreach ($t_rules as $row) {
             if (!empty($row['rule']) and is_subnet_aton($row['rule'], $ip_aton)) {
                 $result['user_id'] = $row['user_id'];
+                return $result;
             }
         }
     }
@@ -2977,6 +2983,7 @@ function get_new_user_id($db, $ip, $mac, $hostname)
             $pattern = '/' . mac_simplify($row['rule']) . '/';
             if (!empty($row['rule']) and preg_match($pattern, mac_simplify($mac))) {
                 $result['user_id'] = $row['user_id'];
+                return $result;
             }
         }
     }
@@ -2986,24 +2993,19 @@ function get_new_user_id($db, $ip, $mac, $hostname)
         foreach ($mac_rules as $row) {
             if (!empty($row['rule']) and preg_match($row['rule'], $hostname)) {
                 $result['user_id'] = $row['user_id'];
+                return $result;
             }
         }
     }
 
-    if (!empty($result['user_id'])) {
-        return $result;
-    }
-
     //ou rules
     //ip
     if (!empty($ip)) {
-        if (is_hotspot($db, $ip)) {
-            $result['ou_id'] = get_const('default_hotspot_ou_id');
-        }
         $t_rules = get_records_sql($db, "SELECT * FROM auth_rules WHERE type=1 and LENGTH(rule)>0 AND ou_id IS NOT NULL");
         foreach ($t_rules as $row) {
             if (!empty($row['rule']) and is_subnet_aton($row['rule'], $ip_aton)) {
                 $result['ou_id'] = $row['ou_id'];
+                return $result;
             }
         }
     }
@@ -3014,6 +3016,7 @@ function get_new_user_id($db, $ip, $mac, $hostname)
             $pattern = '/' . mac_simplify($row['rule']) . '/';
             if (!empty($row['rule']) and preg_match($pattern, mac_simplify($mac))) {
                 $result['ou_id'] = $row['ou_id'];
+                return $result;
             }
         }
     }
@@ -3023,6 +3026,7 @@ function get_new_user_id($db, $ip, $mac, $hostname)
         foreach ($mac_rules as $row) {
             if (!empty($row['rule']) and preg_match($row['rule'], $hostname)) {
                 $result['ou_id'] = $row['ou_id'];
+                return $result;
             }
         }
     }

+ 12 - 13
scripts/eyelib/database.pm

@@ -799,13 +799,19 @@ $result->{dhcp_hostname} = $hostname;
 $result->{ou_id}=undef;
 $result->{user_id}=undef;
 
+my $hotspot_users = new Net::Patricia;
+#check hotspot
+my @hotspot_rules = get_records_sql($db,'SELECT * FROM subnets WHERE hotspot=1 AND LENGTH(subnet)>0');
+foreach my $row (@hotspot_rules) { $hotspot_users->add_string($row->{subnet},$default_hotspot_ou_id); }
+if ($hotspot_users->match_string($ip)) { $result->{ou_id}=$hotspot_users->match_string($ip); return $result; }
+
 #check ip
 if (defined $ip and $ip) {
     my $users = new Net::Patricia;
     #check ip rules
     my @ip_rules = get_records_sql($db,'SELECT * FROM auth_rules WHERE type=1 and LENGTH(rule)>0 AND user_id IS NOT NULL');
     foreach my $row (@ip_rules) { eval { $users->add_string($row->{rule},$row->{user_id}); }; }
-    if ($users->match_string($ip)) { $result->{user_id}=$users->match_string($ip); }
+    if ($users->match_string($ip)) { $result->{user_id}=$users->match_string($ip); return $result; }
     }
 
 #check mac
@@ -813,33 +819,26 @@ if (defined $mac and $mac) {
     my @user_rules=get_records_sql($db,'SELECT * FROM auth_rules WHERE type=2 AND LENGTH(rule)>0 AND user_id IS NOT NULL');
     foreach my $user (@user_rules) {
 	my $rule = mac_simplify($user->{rule});
-        if ($mac=~/$rule/i) { $result->{user_id}=$user->{user_id}; }
+        if ($mac=~/$rule/i) { $result->{user_id}=$user->{user_id}; return $result; }
         }
     }
 #check hostname
 if (defined $hostname and $hostname) {
     my @user_rules=get_records_sql($db,'SELECT * FROM auth_rules WHERE type=3 AND LENGTH(rule)>0 AND user_id IS NOT NULL');
     foreach my $user (@user_rules) {
-        if ($hostname=~/$user->{rule}/i) { $result->{user_id}=$user->{user_id}; }
+        if ($hostname=~/$user->{rule}/i) { $result->{user_id}=$user->{user_id}; return $result; }
         }
     }
 
-#
-if ($result->{user_id}) { return $result; }
-
 #check ou rules
 
 #check ip
 if (defined $ip and $ip) {
     my $users = new Net::Patricia;
-    #check hotspot
-    my @ip_rules = get_records_sql($db,'SELECT * FROM subnets WHERE hotspot=1 AND LENGTH(subnet)>0');
-    foreach my $row (@ip_rules) { $users->add_string($row->{subnet},$default_hotspot_ou_id); }
-    if ($users->match_string($ip)) { $result->{ou_id}=$users->match_string($ip); }
     #check ip rules
     @ip_rules = get_records_sql($db,'SELECT * FROM auth_rules WHERE type=1 and LENGTH(rule)>0 AND ou_id IS NOT NULL');
     foreach my $row (@ip_rules) { eval { $users->add_string($row->{rule},$row->{ou_id}); }; }
-    if ($users->match_string($ip)) { $result->{ou_id}=$users->match_string($ip); }
+    if ($users->match_string($ip)) { $result->{ou_id}=$users->match_string($ip); return $result; }
     }
 
 #check mac
@@ -847,7 +846,7 @@ if (defined $mac and $mac) {
     my @user_rules=get_records_sql($db,'SELECT * FROM auth_rules WHERE type=2 AND LENGTH(rule)>0 AND ou_id IS NOT NULL');
     foreach my $user (@user_rules) {
 	my $rule = mac_simplify($user->{rule});
-        if ($mac=~/$rule/i) { $result->{ou_id}=$user->{ou_id}; }
+        if ($mac=~/$rule/i) { $result->{ou_id}=$user->{ou_id}; return $result; }
         }
     }
 
@@ -855,7 +854,7 @@ if (defined $mac and $mac) {
 if (defined $hostname and $hostname) {
     my @user_rules=get_records_sql($db,'SELECT * FROM auth_rules WHERE type=3 AND LENGTH(rule)>0 AND ou_id IS NOT NULL');
     foreach my $user (@user_rules) {
-        if ($hostname=~/$user->{rule}/i) { $result->{ou_id}=$user->{ou_id}; }
+        if ($hostname=~/$user->{rule}/i) { $result->{ou_id}=$user->{ou_id}; return $result; }
         }
     }