<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# Parse the firewall log and rotate it

$no_acl_check++;
require './bandwidth-lib.pl';
use Time::Local;

# Detect firewall system if needed
if (!$config{'firewall_system'}) {
	$sys = &amp;detect_firewall_system();
	if ($sys) {
		$config{'firewall_system'} = $sys;
		&amp;save_module_config();
		}
	else {
		die "Failed to detect firewall system!";
		}
	}

# See if this process is already running
if ($pid = &amp;check_pid_file($pid_file)) {
	print STDERR "rotate.pl process $pid is already running\n";
	exit;
	}
open(PID, "&gt;$pid_file");
print PID $$,"\n";
close(PID);

$time_now = time();
@time_now = localtime($time_now);
@hours = ( );

# Scan the entries in the log file
&amp;pre_process();
open(LOG, $bandwidth_log);
while(&lt;LOG&gt;) {
	if (&amp;process_line($_, \@hours, $time_now)) {
		# Found a valid line
		$lastline = $_;
		}
	elsif (/last\s+message\s+repeated\s+(\d+)/) {
		# re-process the last line N-1 times
		for($i=0; $i&lt;$1-1; $i++) {
			&amp;process_line($lastline, \@hours, $time_now);
			}
		}
	else {
		#print "skipping $_";
		}
	}
close(LOG);

# Save all hours
foreach $hour (@hours) {
	&amp;save_hour($hour);
	}

# Truncate the file (if it exists) and notify syslog
if (-r $bandwidth_log) {
	open(LOG, "&gt;$bandwidth_log");
	close(LOG);
	}
&amp;foreign_call($syslog_module, "signal_syslog");

# Remove PID file
unlink($pid_file);

</pre></body></html>