]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
guardian.cgi: Use "getipstat" binary.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 25 Feb 2016 10:22:19 +0000 (11:22 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Fri, 29 Jul 2016 11:17:56 +0000 (13:17 +0200)
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>
html/cgi-bin/guardian.cgi

index 5fadc4562d944c75f1001e80acd07421f0eb9d8a..1941ff48781bd6b07e7e2c25977d7a4037d511e3 100644 (file)
@@ -652,30 +652,49 @@ sub daemonstats() {
 }
 
 sub GetBlockedHosts() {
-
        # Create new, empty array.
        my @hosts;
 
        # Lauch helper to get chains from iptables.
-       open(FILE, "/usr/local/bin/guardianctrl get-chain |");
-
-       # Read file line by line and print out the elements.
-       foreach my $line (<FILE>) {
-
-               # Skip descriptive lines.
-               next if ($line =~ /^Chain/);
-               next if ($line =~ /^ pkts/);
-
-               # Generate array, based on the line content (seperator is a single or multiple space's)
-               my @comps = split(/\s{1,}/, $line);
-               my ($lead, $pkts, $bytes, $target, $prot, $opt, $in, $out, $source, $destination) = @comps;
+       system('/usr/local/bin/getipstat');
+
+       # Open temporary file which contains the chains and rules.
+       open (FILE, '/srv/web/ipfire/html/iptables.txt');
+
+       # Loop through the entire file.
+       while (<FILE>) {
+               my $line = $_;
+
+               # Search for the guardian chain and extract
+               # the lines between it and the next empty line
+               # 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/);
+
+                       # Generate array, based on the line content (seperator is a single or multiple space's)
+                       my @comps = split(/\s{1,}/, $line);
+                       my ($lead, $pkts, $bytes, $target, $prot, $opt, $in, $out, $source, $destination) = @comps;
+
+                       # Assign different variable names.
+                       my $blocked_host = $source;
+
+                       # Add host to our hosts array.
+                       if ($blocked_host) {
+                               push(@hosts, $blocked_host);
+                       }
+               }
+       }
 
-               # Assign different variable names.
-               my $blocked_host = $source;
+       # Close filehandle.
+       close(FILE);
 
-               # Add host to our hosts array.
-               push(@hosts, $blocked_host);
-       }
+       # 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.
        my @sorted = map  { $_->[0] }