Explorar el Código

fixed an ancient bug with permanent deletion of the ip address record from the backend
new bugs have been added...

root hace 6 meses
padre
commit
4dbd1770af

+ 1 - 1
docs/mysql/2-9-0/mysql.sql

@@ -841,7 +841,7 @@ CREATE TABLE `subnets` (
   `static` tinyint(1) NOT NULL DEFAULT 0,
   `static` tinyint(1) NOT NULL DEFAULT 0,
   `dhcp_update_hostname` tinyint(1) NOT NULL DEFAULT 0,
   `dhcp_update_hostname` tinyint(1) NOT NULL DEFAULT 0,
   `discovery` tinyint(1) NOT NULL DEFAULT 1,
   `discovery` tinyint(1) NOT NULL DEFAULT 1,
-  `notify` tinyint(1) NOT NULL DEFAULT '3',
+  `notify` tinyint(1) NOT NULL DEFAULT '7',
   `comment` varchar(250) DEFAULT NULL
   `comment` varchar(250) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 

+ 41 - 3
scripts/eyelib/database.pm

@@ -35,6 +35,7 @@ db_log_info
 db_log_verbose
 db_log_verbose
 delete_record
 delete_record
 record_to_txt
 record_to_txt
+unblock_user
 do_sql
 do_sql
 Get_Variable
 Get_Variable
 Set_Variable
 Set_Variable
@@ -728,7 +729,7 @@ db_log_debug($db,'Delete record from table  '.$table.' value: '.$diff, $rec_id);
 #never delete user ip record!
 #never delete user ip record!
 if ($table eq 'User_auth') {
 if ($table eq 'User_auth') {
     my $sSQL = "UPDATE User_auth SET changed=1, deleted=1, changed_time='".GetNowTime()."' WHERE ".$filter;
     my $sSQL = "UPDATE User_auth SET changed=1, deleted=1, changed_time='".GetNowTime()."' WHERE ".$filter;
-    do_sql($db,$sSQL);
+    my $ret = do_sql($db,$sSQL);
     if ($old_record->{'dns_name'} and $old_record->{'ip'} and !$old_record->{'dns_ptr_only'} and $old_record->{'dns_name'}!~/\.$/) {
     if ($old_record->{'dns_name'} and $old_record->{'ip'} and !$old_record->{'dns_ptr_only'} and $old_record->{'dns_name'}!~/\.$/) {
             my $del_dns;
             my $del_dns;
             $del_dns->{'name_type'}='A';
             $del_dns->{'name_type'}='A';
@@ -747,6 +748,7 @@ if ($table eq 'User_auth') {
             $del_dns->{'auth_id'}=$old_record->{'id'};
             $del_dns->{'auth_id'}=$old_record->{'id'};
             insert_record($db,'dns_queue',$del_dns);
             insert_record($db,'dns_queue',$del_dns);
             }
             }
+    return $ret;
     }
     }
 
 
 if ($table eq 'User_list' and $old_record->{'permanent'}) { return; }
 if ($table eq 'User_list' and $old_record->{'permanent'}) { return; }
@@ -806,7 +808,7 @@ if ($changes) {
     } else {
     } else {
     $msg = "Deleting ip-record: ". $txt_record . "::Fail!\n" . $msg;
     $msg = "Deleting ip-record: ". $txt_record . "::Fail!\n" . $msg;
     }
     }
-db_log_warning($db, $msg, id);
+db_log_warning($db, $msg, $id);
 my $send_alert = isNotifyDelete(get_notify_subnet($db,$record->{ip}));
 my $send_alert = isNotifyDelete(get_notify_subnet($db,$record->{ip}));
 sendEmail("WARN! ".get_first_line($msg),$msg,1) if ($send_alert);
 sendEmail("WARN! ".get_first_line($msg),$msg,1) if ($send_alert);
 return $changes;
 return $changes;
@@ -814,6 +816,42 @@ return $changes;
 
 
 #---------------------------------------------------------------------------------------------------------------
 #---------------------------------------------------------------------------------------------------------------
 
 
+sub unblock_user {
+my $db = shift;
+my $user_id = shift;
+my $user_record = get_record_sql($db,'SELECT * FROM User_list WHERE id='.$user_id);
+my $user_ident = 'id:'. $user_record->{'id'} . ' '. $user_record->{'login'};
+$user_ident = $user_ident . '[' . $user_record->{'fio'} . ']' if ($user_record->{'fio'});
+my $msg = "Amnistuyemo blocked by traffic user $user_ident \nInternet access for the user's IP address has been restored:\n";
+my @user_auth = get_records_sql($db,'SELECT * FROM User_auth WHERE deleted=0 AND user_id='.$user_id);
+my $send_alert = 0;
+if (@user_auth and scalar @user_auth) {
+    foreach my $record (@user_auth) {
+        $send_alert = ($send_alert or isNotifyUpdate(get_notify_subnet($db,$record->{ip})));
+        my $auth_ident = $record->{ip};
+        $auth_ident = $auth_ident . '['.$record->{dns_name} .']' if ($record->{dns_name});
+        $auth_ident = $auth_ident . ' :: '.$record->{comments} if ($record->{dns_name});
+        my $new;
+        $new->{'blocked'}=0;
+        $new->{'changed'}=1;
+        my $ret_id = update_record($db,'User_auth',$new,'id='.$record->{'id'});
+        if ($ret_id) {
+            $msg = $msg ."\n".$auth_ident;
+            }
+        }
+    }
+my $new;
+$new->{'blocked'}=0;
+my $ret_id = update_record($db,'User_list','id='.$user_id);
+if ($ret_id) {
+    db_log_info($dbh,$msg);
+    sendEmail("WARN! ".get_first_line($msg),$msg,1) if ($send_alert);
+    }
+return $ret_id;
+}
+
+#---------------------------------------------------------------------------------------------------------------
+
 sub delete_user {
 sub delete_user {
 my $db = shift;
 my $db = shift;
 my $id = shift;
 my $id = shift;
@@ -882,7 +920,7 @@ my $db = shift;
 my $ip  = shift;
 my $ip  = shift;
 my $subnets = new Net::Patricia;
 my $subnets = new Net::Patricia;
 my @ip_rules = get_records_sql($db,'SELECT * FROM subnets WHERE office=1 AND LENGTH(subnet)>0');
 my @ip_rules = get_records_sql($db,'SELECT * FROM subnets WHERE office=1 AND LENGTH(subnet)>0');
-foreach my $row (@ip_rules) { $subnets->add_string($row->{subnet}); }
+foreach my $row (@ip_rules) { $subnets->add_string($row->{subnet},$row); }
 return $subnets->match_string($ip);
 return $subnets->match_string($ip);
 }
 }
 
 

+ 1 - 3
scripts/garbage.pl

@@ -112,9 +112,7 @@ if ($day==1) {
     foreach my $row (@month_stats) {
     foreach my $row (@month_stats) {
         my $m_quota=$row->{uquota}*$KB*$KB;
         my $m_quota=$row->{uquota}*$KB*$KB;
         next if ($m_quota < $row->{traf_sum});
         next if ($m_quota < $row->{traf_sum});
-        db_log_info($dbh,"Amnistuyemo blocked user $row->{login} [$row->{id}] by traffic for a day");
-        do_sql($dbh,"UPDATE User_list set blocked=0 WHERE id=$row->{id}");
-        do_sql($dbh,"UPDATE User_auth set blocked=0, changed=1 WHERE user_id=$row->{id}");
+        unblock_user($dbh,$row->{id});
         }
         }
     log_info($dbh,'Daily statistics stopped');
     log_info($dbh,'Daily statistics stopped');
     }
     }

+ 1 - 1
scripts/updates/2-9-0/subnets.sql

@@ -1 +1 @@
-ALTER TABLE `subnets` ADD `notify` tinyint(1) NOT NULL DEFAULT '3' AFTER `discovery`;
+ALTER TABLE `subnets` ADD `notify` tinyint(1) NOT NULL DEFAULT '7' AFTER `discovery`;