Przeglądaj źródła

bugfix: Fixed auto-cleaning of rules for linking to hotspot and dhcp groups
bugfix: Fixed programming of the dhcp server on mikrotik for some configuration options
bugfix: Fixed deleting entries from the list of duplicates
added: Auto-release of old recordings has been added to the list of duplicates.

root 1 rok temu
rodzic
commit
46b7d68c39

+ 52 - 20
html/admin/iplist/doubles.php

@@ -2,26 +2,31 @@
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/cidrfilter.php");
 
 if (isset($_POST["removeauth"])) {
     $auth_id = $_POST["f_auth_id"];
     foreach ($auth_id as $key => $val) {
-        if ($val) {
-                run_sql($db_link, 'DELETE FROM connections WHERE auth_id='.$val);
-                run_sql($db_link, 'DELETE FROM User_auth_alias WHERE auth_id='.$val);
-                $changes=delete_record($db_link, "User_auth", "id=" . $val);
-                if (!empty($changes)) { LOG_INFO($db_link,"Remove user ip: $changes"); }
-                }
-            }
+        if ($val) { delete_user_auth($db_link,$val); }
+        }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
     }
 
 print_ip_submenu($page_url);
+
+if (empty($rcidr)) { $cidr_filter = ''; } else {
+    $cidr_range = cidrToRange($rcidr);
+    if (!empty($cidr_range)) { $cidr_filter = " AND (U.ip_int>=".ip2long($cidr_range[0])." AND U.ip_int<=".ip2long($cidr_range[1]).")"; }
+    }
+
 ?>
 <div id="cont">
 <br>
 <form name="def" action="doubles.php" method="post">
+<b><?php print WEB_network_subnet; ?> - </b><?php print_subnet_select_office_splitted($db_link, 'cidr', $rcidr); ?>
+<input id="btn_filter" name="btn_filter" type="submit" value="<?php echo WEB_btn_show; ?>">
+
 <table class="data">
 <tr>
     <td class="data"><input type="checkbox" onClick="checkAll(this.checked);"></td>
@@ -35,63 +40,89 @@ print_ip_submenu($page_url);
     <td align=right><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="removeauth" value="<?php echo WEB_btn_delete; ?>"></td>
 </tr>
 <?php
-$sSQL = "SELECT U.id, U.ip, U.mac, U.last_found, S.subnet as net FROM User_auth U, subnets S WHERE (U.mac IS NOT NULL AND U.mac<>'') AND (U.ip_int BETWEEN S.ip_int_start AND S.ip_int_stop) AND S.office=1 AND deleted=0 ORDER BY net,mac,last_found";
+$sSQL = "SELECT U.id, U.ip, U.mac, U.arp_found, S.subnet as net FROM User_auth U, subnets S WHERE (U.mac IS NOT NULL AND U.mac<>'') AND (U.ip_int BETWEEN S.ip_int_start AND S.ip_int_stop) $cidr_filter AND S.office=1 AND U.deleted=0 ORDER BY net,mac,arp_found";
 $users = get_records_sql($db_link,$sSQL);
 $f_subnet=NULL;
 $f_mac=NULL;
 $f_id=NULL;
 $printed = NULL;
+$f_index = 0;
+$f_count = 0;
 foreach ($users as $row) {
-    if (empty($f_subnet)) { $f_subnet = $row['net']; $f_mac=$row['mac']; $f_id=$row['id']; continue; }
+    //инициализируем перебор по первой записи
+    if (empty($f_subnet)) { 
+        //сохраняем для обработки
+        $f_subnet = $row['net'];
+        $f_mac=$row['mac'];
+        $f_id=$row['id'];
+        $f_index=0;
+        continue;
+        }
+    //начинаем перебор - проверяем 
     if ($row['net'] === $f_subnet and $row['mac']===$f_mac) {
+        //если первая запись не выводилась - выводим на печать
         if (!isset($printed[$f_id])) {
+            //считаем сколько у нас дублей
+            $dSQL = "SELECT  U.id, U.ip, U.mac, U.arp_found FROM User_auth U WHERE U.mac='".$f_mac."' $cidr_filter AND U.deleted=0";
+            $doubles = get_records_sql($db_link,$dSQL);
+            $f_count = count($doubles);
+
+            $f_index++;
             $user = get_record_sql($db_link,"SELECT * FROM User_auth WHERE id=".$f_id);
-            if (empty($user['last_found']) or $user['last_found'] === '0000-00-00 00:00:00') { $user['last_found'] = ''; }
+            if (empty($user['arp_found']) or $user['arp_found'] === '0000-00-00 00:00:00') { $user['arp_found'] = ''; }
             if (empty($user['timestamp']) or $user['timestamp'] === '0000-00-00 00:00:00') { $user['timestamp'] = ''; }
             if (empty($user['changed_time']) or $user['changed_time'] === '0000-00-00 00:00:00') { $user['changed_time'] = ''; }
             print "<tr align=center>\n";
             $cl = "data";
-            print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$user["id"]." ></td>\n";
+            print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$user["id"];
+            if ($f_index != $f_count) { print " checked"; }
+            print "></td>\n";
             print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$user['user_id'].">" . get_login($db_link,$user['user_id']) . "</a></td>\n";
             print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$user['id'].">" . $user['ip'] . "</a></td>\n";
             print "<td class=\"$cl\" >" . expand_mac($db_link,$user['mac']) . "</td>\n";
             if (isset($user['dhcp_hostname']) and strlen($user['dhcp_hostname']) > 0) {
                 print "<td class=\"$cl\" >".$user['comments']." [" . $user['dhcp_hostname'] . "]</td>\n";
                 } else {
-                print "<td class=\"$cl\" >".$user['comments']."</td>\n";
+                print "<td class=\"$cl\" >".$user['comments']." $f_index => $f_count </td>\n";
                 }
             print "<td class=\"$cl\" >".$user['dns_name']."</td>\n";
             print "<td class=\"$cl\" >".$user['timestamp']."</td>\n";
-            print "<td class=\"$cl\" >".$user['last_found']."</td>\n";
+            print "<td class=\"$cl\" >".$user['arp_found']."</td>\n";
             print "</tr>\n";
             $printed[$f_id] = 1;
             }
+        //проверяем текущую запись
         if (!isset($printed[$row['id']])) {
+            $f_index++;
             $user = get_record_sql($db_link,"SELECT * FROM User_auth WHERE id=".$row['id']);
-            if (empty($user['last_found']) or $user['last_found'] === '0000-00-00 00:00:00') { $user['last_found'] = ''; }
+            if (empty($user['arp_found']) or $user['arp_found'] === '0000-00-00 00:00:00') { $user['arp_found'] = ''; }
             if (empty($user['timestamp']) or $user['timestamp'] === '0000-00-00 00:00:00') { $user['timestamp'] = ''; }
             if (empty($user['changed_time']) or $user['changed_time'] === '0000-00-00 00:00:00') { $user['changed_time'] = ''; }
             print "<tr align=center>\n";
             $cl = "data";
-            print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$user["id"]." ></td>\n";
+            print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_auth_id[] value=".$user["id"];
+            if ($f_index != $f_count) { print " checked"; }
+            print " ></td>\n";
             print "<td class=\"$cl\" ><a href=/admin/users/edituser.php?id=".$user['user_id'].">" . get_login($db_link,$user['user_id']) . "</a></td>\n";
             print "<td class=\"$cl\" ><a href=/admin/users/editauth.php?id=".$user['id'].">" . $user['ip'] . "</a></td>\n";
             print "<td class=\"$cl\" >" . expand_mac($db_link,$user['mac']) . "</td>\n";
             if (isset($user['dhcp_hostname']) and strlen($user['dhcp_hostname']) > 0) {
-                print "<td class=\"$cl\" >".$user['comments']." [" . $user['dhcp_hostname'] . "]</td>\n";
+                print "<td class=\"$cl\" >".$user['comments']." [" . $user['dhcp_hostname'] . "] $f_index => $f_count </td>\n";
                 } else {
                 print "<td class=\"$cl\" >".$user['comments']."</td>\n";
                 }
             print "<td class=\"$cl\" >".$user['dns_name']."</td>\n";
             print "<td class=\"$cl\" >".$user['timestamp']."</td>\n";
-            print "<td class=\"$cl\" >".$user['last_found']."</td>\n";
+            print "<td class=\"$cl\" >".$user['arp_found']."</td>\n";
             print "</tr>\n";
             $printed[$row['id']] = 1;
             }
+        } else {
+        $f_subnet = $row['net'];
+        $f_mac = $row['mac'];
+        $f_id = $row['id'];
+        $f_index = 0;
         }
-    $f_subnet = $row['net'];
-    $f_mac=$row['mac'];
-    $f_id=$row['id'];
     }
 print "</table>\n";
 ?>
@@ -100,3 +131,4 @@ print "</table>\n";
 <?php
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
 ?>
+uh

+ 1 - 0
html/admin/users/edituser.php

@@ -402,6 +402,7 @@ require_once($_SERVER["DOCUMENT_ROOT"] . "/inc/header.php");
                     $cl = "data_green";
                     if (!$row["dhcp"]) { $cl = "data_red"; }
                     print "<td class=\"$cl\" >" . get_qa($row["dhcp"]);
+                    if (!empty($row["dhcp_acl"])) { print "<p class='timestamp'>".$row["dhcp_acl"]. "</p>"; }
                     if (!empty($dhcp_str)) { print "<p class='timestamp'>".$dhcp_str. "</p>"; }
                     print "</td>";
 

+ 6 - 2
html/inc/common.php

@@ -1946,8 +1946,12 @@ function apply_auth_rule($db, $auth_record, $user_id)
 function fix_auth_rules($db)
 {
     //cleanup hotspot subnet rules
-    delete_record($db, "auth_rules", "ou_id=" . get_const('default_user_ou_id'));
-    delete_record($db, "auth_rules", "ou_id=" . get_const('default_hotspot_ou_id'));
+    $t_hotspot = get_records_sql($db, "SELECT * FROM `OU` WHERE default_users=1 or default_hotspot=1");
+    if (!empty($t_hotspot)) {
+        foreach ($t_hotspot as $row) {
+            delete_record($db, "auth_rules", "ou_id='" . $row['id'] . "'");
+        }
+    }
     $t_hotspot = get_records_sql($db, "SELECT * FROM subnets WHERE hotspot=1");
     if (!empty($t_hotspot)) {
         foreach ($t_hotspot as $row) {

+ 2 - 0
html/inc/languages/english.php

@@ -269,6 +269,8 @@ define("WEB_btn_apply_selected","Apply for selected");
 define("WEB_btn_save_filters","Save filters");
 define("WEB_btn_on","On");
 define("WEB_btn_off","Off");
+define("WEB_btn_auto_clean","Auto clean");
+define("WEB_btn_auto_mark","Mark old");
 
 /* control options */
 define("WEB_config_remove_option","Parameter removed");

+ 2 - 0
html/inc/languages/russian.php

@@ -269,6 +269,8 @@ define("WEB_btn_apply_selected","Поменять у выделения");
 define("WEB_btn_save_filters","Сохранить фильтры");
 define("WEB_btn_on","Включить");
 define("WEB_btn_off","Выключить");
+define("WEB_btn_auto_clean","АвтоОчистка");
+define("WEB_btn_auto_mark","Выбрать старые");
 
 /* control options */
 define("WEB_config_remove_option","Удалён параметр");

+ 2 - 1
scripts/sync_mikrotik.pl

@@ -192,7 +192,7 @@ next if ($fact_connected_nets->match_string($gw_subnet));
 push(@relayed_subnets,$gw_subnet);
 }
 
-if (scalar @relayed_subnets) {
+if (scalar @relayed_subnets and $relayed_dhcp_interface) {
     my $dhcp_state;
     $dhcp_state->{interface} = $relayed_dhcp_interface;
     $dhcp_state->{subnet} = join(",",@relayed_subnets);
@@ -228,6 +228,7 @@ if ($str=~/^\d/) {
 my @auth_records=();
 foreach my $dhcp_subnet (@dhcp_subnets) {
     next if (!$dhcp_subnet);
+    next if (!exists $dhcp_conf{$dhcp_subnet});
     my @tmp1=get_records_sql($dbh,"SELECT * from User_auth WHERE dhcp=1 and `ip_int`>=".$dhcp_conf{$dhcp_subnet}->{first_ip_aton}." and `ip_int`<=".$dhcp_conf{$dhcp_subnet}->{last_ip_aton}." and deleted=0 and ou_id !=".$default_user_ou_id." and ou_id !=".$default_hotspot_ou_id." ORDER BY ip_int");
     push(@auth_records,@tmp1);
     undef @tmp1;