mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 03:33:25 +02:00
guardian.cgi: Use "getipstat" binary.
Rework the GetBlockedHosts() to use the "getipstat" binary instead of the not longer available "guardianctrl" binary. Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
This commit is contained in:
@@ -652,31 +652,50 @@ sub daemonstats() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub GetBlockedHosts() {
|
sub GetBlockedHosts() {
|
||||||
|
|
||||||
# Create new, empty array.
|
# Create new, empty array.
|
||||||
my @hosts;
|
my @hosts;
|
||||||
|
|
||||||
# Lauch helper to get chains from iptables.
|
# Lauch helper to get chains from iptables.
|
||||||
open(FILE, "/usr/local/bin/guardianctrl get-chain |");
|
system('/usr/local/bin/getipstat');
|
||||||
|
|
||||||
# Read file line by line and print out the elements.
|
# Open temporary file which contains the chains and rules.
|
||||||
foreach my $line (<FILE>) {
|
open (FILE, '/srv/web/ipfire/html/iptables.txt');
|
||||||
|
|
||||||
# Skip descriptive lines.
|
# Loop through the entire file.
|
||||||
next if ($line =~ /^Chain/);
|
while (<FILE>) {
|
||||||
next if ($line =~ /^ pkts/);
|
my $line = $_;
|
||||||
|
|
||||||
# Generate array, based on the line content (seperator is a single or multiple space's)
|
# Search for the guardian chain and extract
|
||||||
my @comps = split(/\s{1,}/, $line);
|
# the lines between it and the next empty line
|
||||||
my ($lead, $pkts, $bytes, $target, $prot, $opt, $in, $out, $source, $destination) = @comps;
|
# which is placed before the next firewall
|
||||||
|
# chain starts.
|
||||||
|
if ($line =~ /^Chain GUARDIAN/ .. /^\s*$/) {
|
||||||
|
# Skip descriptive lines.
|
||||||
|
next if ($line =~ /^Chain/);
|
||||||
|
next if ($line =~ /^ pkts/);
|
||||||
|
|
||||||
# Assign different variable names.
|
# Generate array, based on the line content (seperator is a single or multiple space's)
|
||||||
my $blocked_host = $source;
|
my @comps = split(/\s{1,}/, $line);
|
||||||
|
my ($lead, $pkts, $bytes, $target, $prot, $opt, $in, $out, $source, $destination) = @comps;
|
||||||
|
|
||||||
# Add host to our hosts array.
|
# Assign different variable names.
|
||||||
push(@hosts, $blocked_host);
|
my $blocked_host = $source;
|
||||||
|
|
||||||
|
# Add host to our hosts array.
|
||||||
|
if ($blocked_host) {
|
||||||
|
push(@hosts, $blocked_host);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Close filehandle.
|
||||||
|
close(FILE);
|
||||||
|
|
||||||
|
# Remove recently created temporary files of the "getipstat" binary.
|
||||||
|
system(rm -f "/srv/web/ipfire/html/iptables.txt");
|
||||||
|
system(rm -f "/srv/web/ipfire/html/iptablesmangle.txt");
|
||||||
|
system(rm -f "/srv/web/ipfire/html/iptablesnat.txt");
|
||||||
|
|
||||||
# Convert entries, sort them, write back and store the sorted entries into new array.
|
# Convert entries, sort them, write back and store the sorted entries into new array.
|
||||||
my @sorted = map { $_->[0] }
|
my @sorted = map { $_->[0] }
|
||||||
sort { $a->[1] <=> $b->[1] }
|
sort { $a->[1] <=> $b->[1] }
|
||||||
|
|||||||
Reference in New Issue
Block a user