瀏覽代碼

bugfix: During garbage collection, the user's "non-deleted" records were also deleted.

root 1 年之前
父節點
當前提交
3a62b509f3
共有 4 個文件被更改,包括 23 次插入18 次删除
  1. 4 6
      Readme.en.md
  2. 4 6
      Readme.ru.md
  3. 2 1
      scripts/garbage.pl
  4. 13 5
      scripts/print-dnsmasq.pl

+ 4 - 6
Readme.en.md

@@ -138,15 +138,13 @@ You can use a dhcp server both on mirkotik and on a server with Linux. Imho, dns
 apt install dnsmasq -y
 
 cp docs/systemd/dhcp-log.service /etc/systemd/system
+cp docs/systemd/dhcp-log-truncate.service /etc/systemd/system
 cp /etc/dnsmasq.conf /etc/dnsmasq.conf.default
 cat docs/addons/dnsmasq.conf >/etc/dnsmasq.conf
 
 #edit /etc/dnsmasq.conf for you network
 
-systemctl enable dnsmasq
-systemctl enable dhcp-log
-systemctl start dnsmasq
-systemctl start dhcp-log
+systemctl enable dnsmasq dhcp-log dhcp-log-truncate --now
 
 ######################################### Additional ##################################################################
 
@@ -220,9 +218,9 @@ The script will create filtering and shaper rules
 
 #dhcp script sampling
 #ROS6
-/tool fetch mode=http keep-result=no url="http://<STAT_IP_OR_HOSTNAME>/api.php\?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname""
+/tool fetch mode=http keep-result=no url="http://<STAT_IP_OR_HOSTNAME>/api.php\?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&send=dhcp&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname""
 #ROS7
-/tool fetch url="http://<STAT_IP_OR_HOSTNAME>/api.php?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&send=dhcp&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname"" mode=http keep-result=no
+/tool fetch mode=http keep-result=no url="http://<STAT_IP_OR_HOSTNAME>/api.php?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&send=dhcp&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname""
 
 
 #########################################################################################################################

+ 4 - 6
Readme.ru.md

@@ -135,15 +135,13 @@ cp docs/logrotate/scripts /etc/logrotate.d/scripts
 apt install dnsmasq -y
 
 cp docs/systemd/dhcp-log.service /etc/systemd/system
+cp docs/systemd/dhcp-log-truncate.service /etc/systemd/system
 cp /etc/dnsmasq.conf /etc/dnsmasq.conf.default
 cat docs/addons/dnsmasq.conf >/etc/dnsmasq.conf
 
 #edit /etc/dnsmasq.conf for you network
 
-systemctl enable dnsmasq
-systemctl enable dhcp-log
-systemctl start dnsmasq
-systemctl start dhcp-log
+systemctl enable dnsmasq dhcp-log dhcp-log-truncate --now
 
 ######################################### Additional ##################################################################
 
@@ -217,8 +215,8 @@ add name=download_root_[LAN_INTERFACE_NAME] parent=[LAN_INTERFACE_NAME] queue=pc
 
 #dhcp script
 #ROS6
-/tool fetch mode=http keep-result=no url="http://<STAT_IP_OR_HOSTNAME>/api.php\?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname""
+/tool fetch mode=http keep-result=no url="http://<STAT_IP_OR_HOSTNAME>/api.php\?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&send=dhcp&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname""
 #ROS7
-/tool fetch url="http://<STAT_IP_OR_HOSTNAME>/api.php?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&send=dhcp&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname"" mode=http keep-result=no
+/tool fetch mode=http keep-result=no url="http://<STAT_IP_OR_HOSTNAME>/api.php?login=<LOGIN>&api_key=<API_CUSTOMER_KEY>&send=dhcp&mac=$leaseActMAC&ip=$leaseActIP&action=$leaseBound&hostname=$"lease-hostname""
 
 #########################################################################################################################

+ 2 - 1
scripts/garbage.pl

@@ -199,7 +199,8 @@ delete_user($dbh,$row->{id});
 if ($config_ref{clean_empty_user}) {
     db_log_info($dbh,'Clearing empty user account and corresponded devices');
 #    my $u_sql = "SELECT * FROM User_list as U WHERE (SELECT COUNT(*) FROM User_auth WHERE User_auth.deleted=0 AND User_auth.user_id = U.id)=0 AND (SELECT COUNT(*) FROM auth_rules WHERE auth_rules.user_id = U.id)=0";
-    my $u_sql = "SELECT * FROM User_list as U WHERE (SELECT COUNT(*) FROM User_auth WHERE User_auth.deleted=0 AND User_auth.user_id = U.id)=0";
+#    my $u_sql = "SELECT * FROM User_list as U WHERE (SELECT COUNT(*) FROM User_auth WHERE User_auth.deleted=0 AND User_auth.user_id = U.id)=0";
+    my $u_sql = "SELECT * FROM User_list as U WHERE U.permanent=0 AND (SELECT COUNT(*) FROM User_auth WHERE User_auth.deleted=0 AND User_auth.user_id = U.id)=0 AND (SELECT COUNT(*) FROM auth_rules WHERE auth_rules.user_id = U.id)=0;"
     my @u_ref = get_records_sql($dbh,$u_sql);
     foreach my $row (@u_ref) {
         db_log_info($dbh,"Remove empty user with id: $row->{id} login: $row->{login}");

+ 13 - 5
scripts/print-dnsmasq.pl

@@ -45,6 +45,7 @@ if ($address=~/inet\s+(.*)\s+brd/i) {
 }
 
 my %static_hole;
+my %mac_subnets;
 
 my @subnets=get_records_sql($dbh,'SELECT * FROM subnets WHERE dhcp=1 and office=1 and vpn=0 and hotspot=0 ORDER BY ip_int_start');
 foreach my $subnet (@subnets) {
@@ -67,21 +68,28 @@ print "dhcp-option=net:net-$subnet_name,option:router,$dhcp_conf{$subnet_name}->
 }
 
 #get userid list
-my $sSQL="SELECT id,ip,ip_int,mac,comments,dns_name,dhcp_option_set,dhcp_acl FROM User_auth where dhcp=1 and deleted=0 and ou_id !=".$default_user_ou_id." and ou_id !=".$default_hotspot_ou_id." ORDER by ip_int";
+my $sSQL="SELECT id,ip,ip_int,mac,comments,dns_name,dhcp_option_set,dhcp_acl,ou_id FROM User_auth where dhcp=1 and deleted=0 ORDER by ip_int";
 my @users = get_records_sql($dbh,$sSQL);
 foreach my $row (@users) {
 next if (!$row);
 next if (!$dhcp_networks->match_string($row->{ip}));
 next if (!$row->{mac});
 next if (!$row->{ip});
+next if (is_default_ou($dbh,$row->{ou_id}));
 if (exists $static_hole{$row->{ip}}) { $static_hole{$row->{ip}}{skip}=1; }
 print '#Comment:'.$row->{comments}."\n" if ($row->{comments});
-print '#DNS:'.$row->{dns_name}."\n" if ($row->{dns_name});
-print 'dhcp-host='.$row->{mac}.', '.$row->{ip}."\n";
+my $dns_name = '';
+if ($row->{dns_name}) {
+    print '#DNS:'.$row->{dns_name}."\n";
+    $dns_name = ','.$row->{dns_name};
+    }
+
+my $dhcp_set = '';
 if ($row->{dhcp_option_set}) {
-    print '#DHCP group:'.$row->{dhcp_option_set}."\n";
-    print 'dhcp-host=set:'.$row->{dhcp_option_set}.','.$row->{ip}."\n";
+    $dhcp_set = ',set:'.$row->{dhcp_option_set};
     }
+
+print 'dhcp-host='.$row->{mac}.$dns_name.','.$row->{ip}.$dhcp_set."\n";
 }
 
 foreach my $ip (keys %static_hole) {