Explorar o código

bugfix: fixed an old logging bug - printing a DB hash instead of a message in some cases

root hai 3 meses
pai
achega
673e193c1c
Modificáronse 3 ficheiros con 35 adicións e 35 borrados
  1. 2 2
      scripts/eye-statd.pl
  2. 2 2
      scripts/fetch_new_arp.pl
  3. 31 31
      scripts/garbage.pl

+ 2 - 2
scripts/eye-statd.pl

@@ -996,9 +996,9 @@ log_verbose("Finished");
 @batch_wan_stats=();
 
 if ($config_ref{enable_quotes}) {
-    log_info($hdb,"Recalc quotes started");
+    log_info("Recalc quotes started");
     foreach my $router_id (keys %routers_found) { recalc_quotes($hdb,$router_id); }
-    log_info($hdb,"Recalc quotes stopped");
+    log_info("Recalc quotes stopped");
     }
 
 if (scalar(@detail_traffic)) {

+ 2 - 2
scripts/fetch_new_arp.pl

@@ -45,7 +45,7 @@ if ($config_ref{config_mode}) {
 # Clean up empty user accounts and associated devices for dynamic users and hotspot
 db_log_verbose($dbh, 'Clearing empty records.');
 
-log_info($dbh, 'Clearing empty user accounts and associated devices for dynamic users and hotspot');
+db_log_info($dbh, 'Clearing empty user accounts and associated devices for dynamic users and hotspot');
 my $u_sql = "SELECT * FROM user_list AS U WHERE (U.ou_id = ? OR U.ou_id = ?) AND (SELECT COUNT(*) FROM user_auth WHERE user_auth.deleted = 0 AND user_auth.user_id = U.id) = 0";
 my @u_ref = get_records_sql($dbh, $u_sql, $default_user_ou_id, $default_hotspot_ou_id);
 foreach my $row (@u_ref) {
@@ -55,7 +55,7 @@ foreach my $row (@u_ref) {
 
 # Clean up empty non-permanent user accounts that have no authentications or auth rules
 #if ($config_ref{clean_empty_user}) {
-#    log_info($dbh, 'Clearing empty non-permanent user accounts and associated devices');
+#    db_log_info($dbh, 'Clearing empty non-permanent user accounts and associated devices');
 #    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) {

+ 31 - 31
scripts/garbage.pl

@@ -55,7 +55,7 @@ my $debug_history = 3;
 #    $optimize = 1;
 #}
 
-log_info($dbh, 'Garbage collection started.');
+db_log_info($dbh, 'Garbage collection started.');
 
 # Helper: Check if a given IP (as integer) belongs to any DHCP pool
 sub is_dhcp_pool {
@@ -111,14 +111,14 @@ foreach my $subnet (@subnets) {
 
 # On the 1st of the month: perform "monthly amnesty" — unblock all traffic-blocked users
 if ($day == 1) {
-    log_info($dbh, 'Monthly amnesty started');
-    db_log_info($dbh, "Unblocking all users blocked due to traffic quota");
+    db_log_info($dbh, 'Monthly amnesty started');
+    db_db_log_info($dbh, "Unblocking all users blocked due to traffic quota");
     do_sql($dbh, "UPDATE user_list SET blocked = 0");
     do_sql($dbh, "UPDATE user_auth SET blocked = 0, changed = 1 WHERE blocked = 1 AND deleted = 0");
-    log_info($dbh, 'Monthly amnesty completed');
+    db_log_info($dbh, 'Monthly amnesty completed');
 } else {
     # Daily: unblock users whose monthly traffic is now below quota
-    log_info($dbh, 'Daily traffic-based unblocking started');
+    db_log_info($dbh, 'Daily traffic-based unblocking started');
 
     my $month_sql = "
     SELECT
@@ -138,11 +138,11 @@ if ($day == 1) {
         next if ($m_quota < $row->{traf_sum});     # Skip if still over quota
         unblock_user($dbh, $row->{id});
     }
-    log_info($dbh, 'Daily traffic-based unblocking completed');
+    db_log_info($dbh, 'Daily traffic-based unblocking completed');
 }
 
 # Clean expired DHCP leases for dynamic users (hotspot and default OU only)
-log_info($dbh, 'Cleaning DHCP leases with overdue expiration for dynamic hosts');
+db_log_info($dbh, 'Cleaning DHCP leases with overdue expiration for dynamic hosts');
 
 my $users_sql = "SELECT * FROM user_auth WHERE deleted = 0 AND (ou_id = ? OR ou_id = ?)";
 my @users_auth = get_records_sql($dbh, $users_sql, $default_user_ou_id, $default_hotspot_ou_id);
@@ -157,14 +157,14 @@ foreach my $row (@users_auth) {
         my $clean_dhcp_time = $last_dhcp_time + 60 * $dhcp_networks->match_string($row->{ip});
 
         if (time() > $clean_dhcp_time) {
-            db_log_verbose($dbh, "Cleaning overdue DHCP lease for IP: $row->{ip}, auth_id: $row->{id}, last DHCP: $row->{dhcp_time}, clean time: " . GetTimeStrByUnixTime($clean_dhcp_time) . ", now: " . GetNowTime());
+            db_db_log_verbose($dbh, "Cleaning overdue DHCP lease for IP: $row->{ip}, auth_id: $row->{id}, last DHCP: $row->{dhcp_time}, clean time: " . GetTimeStrByUnixTime($clean_dhcp_time) . ", now: " . GetNowTime());
             delete_user_auth($dbh, $row->{id});
 
             # Also delete parent user if no other active sessions remain
             my $u_count = get_count_records($dbh, 'user_auth', "deleted = 0 AND user_id = ? ", $row->{user_id});
             if (!$u_count) {
                 delete_user($dbh, $row->{'user_id'});
-                db_log_info($dbh, "Removed dynamic user id: $row->{'user_id'} due to DHCP lease timeout");
+                db_db_log_info($dbh, "Removed dynamic user id: $row->{'user_id'} due to DHCP lease timeout");
             }
         }
     }
@@ -177,27 +177,27 @@ if ($history_dhcp) {
     my $day_dur = DateTime::Duration->new(days => $history_dhcp);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
-    log_info($dbh, 'Clearing outdated DHCP log records');
+    db_log_info($dbh, 'Clearing outdated DHCP log records');
     do_sql($dbh, "DELETE FROM dhcp_log WHERE ts < ?",$clean_str);
-    log_verbose($dbh, "Removed DHCP log entries older than $clean_str");
+    db_log_verbose($dbh, "Removed DHCP log entries older than $clean_str");
 }
 
 # Clean old connection records (based on $connections_history setting)
 if ($connections_history) {
-    log_info($dbh, 'Clearing outdated connection records');
+    db_log_info($dbh, 'Clearing outdated connection records');
     my $day_dur = DateTime::Duration->new(days => $connections_history);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
     $users_sql = "SELECT id FROM user_auth WHERE last_found < ? AND last_found IS NOT NULL";
     @users_auth = get_records_sql($dbh, $users_sql, $clean_str);
     foreach my $row (@users_auth) {
-        log_debug($dbh, "Clearing old connection for auth_id: " . $row->{id});
+        log_debug( "Clearing old connection for auth_id: " . $row->{id});
         do_sql($dbh, "DELETE FROM connections WHERE auth_id = ?", $row->{id});
     }
 }
 
 # Remove duplicate connection records (same auth_id + port_id)
-log_info($dbh, 'Clearing duplicate connection records');
+db_log_info($dbh, 'Clearing duplicate connection records');
 my $conn_sql = "SELECT id, port_id, auth_id FROM connections ORDER BY port_id";
 my @conn_ref = get_records_sql($dbh, $conn_sql);
 my $old_port_id = 0;
@@ -216,7 +216,7 @@ foreach my $row (@conn_ref) {
     # If we're still on the same (port, auth) pair, this is a duplicate
     if ($old_port_id == $c_port_id && $old_auth_id == $c_auth_id) {
         do_sql($dbh, "DELETE FROM connections WHERE id = ?",$c_id);
-        log_info($dbh, "Removed duplicate connection id=$c_id: port=$c_port_id auth=$c_auth_id");
+        db_log_info($dbh, "Removed duplicate connection id=$c_id: port=$c_port_id auth=$c_auth_id");
     } else {
         $old_port_id = $c_port_id;
         $old_auth_id = $c_auth_id;
@@ -224,21 +224,21 @@ foreach my $row (@conn_ref) {
 }
 
 # Clean empty dynamic/hotspot user accounts (no active authentications)
-log_info($dbh, 'Clearing empty user accounts and associated devices for dynamic users and hotspot');
+db_log_info($dbh, 'Clearing empty user accounts and associated devices for dynamic users and hotspot');
 my $u_sql = "SELECT * FROM user_list AS U WHERE (U.ou_id = ? OR U.ou_id = ? ) AND (SELECT COUNT(*) FROM user_auth WHERE user_auth.deleted = 0 AND user_auth.user_id = U.id) = 0";
 my @u_ref = get_records_sql($dbh, $u_sql, $default_hotspot_ou_id, $default_user_ou_id);
 foreach my $row (@u_ref) {
-    db_log_info($dbh, "Removing empty dynamic user with id: $row->{id}, login: $row->{login}");
+    db_db_log_info($dbh, "Removing empty dynamic user with id: $row->{id}, login: $row->{login}");
     delete_user($dbh, $row->{id});
 }
 
 # Clean empty non-permanent user accounts (if enabled in config)
 if ($config_ref{clean_empty_user}) {
-    log_info($dbh, 'Clearing empty non-permanent user accounts and associated devices');
+    db_log_info($dbh, 'Clearing empty non-permanent user accounts and associated devices');
     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, "Removing empty user with id: $row->{id}, login: $row->{login}");
+        db_db_log_info($dbh, "Removing empty user with id: $row->{id}, login: $row->{login}");
         delete_user($dbh, $row->{id});
     }
 }
@@ -247,7 +247,7 @@ if ($config_ref{clean_empty_user}) {
 do_sql($dbh, "DELETE FROM auth_rules WHERE user_id NOT IN (SELECT id FROM user_list)");
 
 # Clean unknown MAC entries that now belong to known users
-log_info($dbh, 'Removing unknown MAC records that are now associated with active users');
+db_log_info($dbh, 'Removing unknown MAC records that are now associated with active users');
 $users_sql = "SELECT mac FROM user_auth WHERE deleted = 0";
 @users_auth = get_records_sql($dbh, $users_sql);
 foreach my $row (@users_auth) {
@@ -260,7 +260,7 @@ if ($history) {
     my $day_dur = DateTime::Duration->new(days => $history);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
-    log_info($dbh, "Cleaning traffic detail records older than $clean_str");
+    db_log_info($dbh, "Cleaning traffic detail records older than $clean_str");
     do_sql($dbh, "DELETE FROM traffic_detail WHERE ts < ?", $clean_str);
 }
 
@@ -269,7 +269,7 @@ if ($history_log_day) {
     my $day_dur = DateTime::Duration->new(days => $history_log_day);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
-    log_info($dbh, "Cleaning VERBOSE worklog entries older than $clean_str");
+    db_log_info($dbh, "Cleaning VERBOSE worklog entries older than $clean_str");
     do_sql($dbh, "DELETE FROM worklog WHERE level > ? AND ts < ?", $L_INFO, $clean_str);
 }
 
@@ -278,7 +278,7 @@ if ($debug_history) {
     my $day_dur = DateTime::Duration->new(days => 3);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
-    log_info($dbh, "Cleaning debug worklog entries older than $clean_str");
+    db_log_info($dbh, "Cleaning debug worklog entries older than $clean_str");
     do_sql($dbh, "DELETE FROM worklog WHERE level >= ? AND ts < ?",$L_DEBUG, $clean_str);
 }
 
@@ -287,7 +287,7 @@ if ($history_syslog_day) {
     my $day_dur = DateTime::Duration->new(days => $history_syslog_day);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
-    log_info($dbh, "Cleaning syslog entries older than $clean_str");
+    db_log_info($dbh, "Cleaning syslog entries older than $clean_str");
     do_sql($dbh, "DELETE FROM remote_syslog WHERE ts < ?",$clean_str);
 }
 
@@ -296,7 +296,7 @@ if ($history_trafstat_day) {
     my $day_dur = DateTime::Duration->new(days => $history_trafstat_day);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
-    log_info($dbh, "Cleaning traffic statistics older than $clean_str");
+    db_log_info($dbh, "Cleaning traffic statistics older than $clean_str");
     do_sql($dbh, "DELETE FROM user_stats WHERE ts < ?",$clean_str);
 }
 
@@ -306,7 +306,7 @@ if ($iptraf_history) {
     my $day_dur = DateTime::Duration->new(days => $iptraf_history);
     my $clean_date = $now - $day_dur;
     my $clean_str = $clean_date->ymd("-") . " 00:00:00";
-    log_info($dbh, "Cleaning full traffic statistics older than $clean_str");
+    db_log_info($dbh, "Cleaning full traffic statistics older than $clean_str");
     do_sql($dbh, "DELETE FROM user_stats_full WHERE ts < ?",$clean_str);
 }
 
@@ -348,7 +348,7 @@ foreach my $auth (@auth_full_list) {
         $new->{ip}        = $auth->{ip};
         $new->{mac}       = $auth_mac;
         $new->{ts}        = $auth->{mac_found};
-        db_log_info($dbh, "Auth id: $auth->{id} ($auth_mac) found at location: device_id=$new->{device_id}, port_id=$new->{port_id}");
+        db_db_log_info($dbh, "Auth id: $auth->{id} ($auth_mac) found at location: device_id=$new->{device_id}, port_id=$new->{port_id}");
         insert_record($dbh, "mac_history", $new);
         next;
     }
@@ -362,14 +362,14 @@ foreach my $auth (@auth_full_list) {
         $new->{ip}        = $auth->{ip};
         $new->{mac}       = $auth_mac;
         $new->{ts}        = $auth->{mac_found};
-        db_log_info($dbh, "Auth id: $auth->{id} ($auth_mac) moved to new location: device_id=$new->{device_id}, port_id=$new->{port_id}");
+        db_db_log_info($dbh, "Auth id: $auth->{id} ($auth_mac) moved to new location: device_id=$new->{device_id}, port_id=$new->{port_id}");
         insert_record($dbh, "mac_history", $new);
     }
 }
 
 # Optional: Optimize database tables to reclaim space and improve performance
 #if ($optimize) {
-#    log_info($dbh, 'Starting table optimization');
+#    db_log_info($dbh, 'Starting table optimization');
 #    foreach my $table (@db_tables) {
 #        my $opt_sql = "OPTIMIZE TABLE $table";
 #        my $opt_rf = $dbh->prepare($opt_sql) or die "Unable to prepare $opt_sql: " . $dbh->errstr;
@@ -380,9 +380,9 @@ foreach my $auth (@auth_full_list) {
 #        # RENAME TABLE $table TO $table.backup, $table.new TO $table;
 #        # DROP TABLE $table.backup;
 #    }
-#    log_info($dbh, 'Table optimization completed.');
+#    db_log_info($dbh, 'Table optimization completed.');
 #}
 
-log_info($dbh, 'Garbage collection finished.');
+db_log_info($dbh, 'Garbage collection finished.');
 $dbh->disconnect;
 exit 0;