mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-26 10:52:57 +02:00
misc-progs: getipstat: Refactor + extend
* Return output of iptables directly instead of writing it to files. * Make iptables wait for 5s if xtables is locked by another iptables process. (--wait 5 argument) * Add optional parameter "-x" to have iptables report exact numbers. * Add optional parameter "-f" to display the filter table (default). * Add optional parameter "-n" to display the nat table. * Add optional parameter "-m" to display the mangle table. * Adapt iptables.cgi and guardian.cgi to catch getipstat output instead of reading temp-files. Signed-off-by: Robin Roevens <robin.roevens@disroot.org> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
committed by
Michael Tremer
parent
d8bf30563f
commit
8b68ed1226
@@ -829,12 +829,9 @@ sub GetBlockedHosts() {
|
||||
my @hosts;
|
||||
|
||||
# Launch helper to get chains from iptables.
|
||||
system('/usr/local/bin/getipstat');
|
||||
open (FILE, '/usr/local/bin/getipstat | ');
|
||||
|
||||
# Open temporary file which contains the chains and rules.
|
||||
open (FILE, '/var/tmp/iptables.txt');
|
||||
|
||||
# Loop through the entire file.
|
||||
# Loop through the entire output.
|
||||
while (<FILE>) {
|
||||
my $line = $_;
|
||||
|
||||
@@ -864,11 +861,6 @@ sub GetBlockedHosts() {
|
||||
# Close filehandle.
|
||||
close(FILE);
|
||||
|
||||
# Remove recently created temporary files of the "getipstat" binary.
|
||||
system("rm -f /var/tmp/iptables.txt");
|
||||
system("rm -f /var/tmp/iptablesmangle.txt");
|
||||
system("rm -f /var/tmp/iptablesnat.txt");
|
||||
|
||||
# Convert entries, sort them, write back and store the sorted entries into new array.
|
||||
my @sorted = map { $_->[0] }
|
||||
sort { $a->[1] <=> $b->[1] }
|
||||
|
||||
@@ -44,8 +44,6 @@ my %cgiparams=();
|
||||
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
|
||||
system('/usr/local/bin/getipstat');
|
||||
|
||||
&Header::showhttpheaders();
|
||||
&Header::openpage($Lang::tr{'ipts'}, 1, '');
|
||||
&Header::openbigbox('100%', 'LEFT');
|
||||
@@ -84,11 +82,11 @@ print <<END
|
||||
END
|
||||
;
|
||||
|
||||
# We´ll open the txt files and extract each line, if the line
|
||||
# We´ll get iptables output and examine each line, if the line
|
||||
# start with an Chain the the name, start- and endline of the
|
||||
# chain is extracted into a hash
|
||||
|
||||
open (FILE, '/var/tmp/iptables.txt');
|
||||
open (FILE, '/usr/local/bin/getipstat | ');
|
||||
while (<FILE>){
|
||||
|
||||
$iplines[$lines] = $_;
|
||||
@@ -206,11 +204,11 @@ print <<END
|
||||
END
|
||||
;
|
||||
|
||||
# We´ll open the txt files and extract each line, if the line
|
||||
# We´ll get iptables output and examine each line, if the line
|
||||
# start with an Chain the the name, start- and endline of the
|
||||
# chain is extracted into a hash
|
||||
|
||||
open (FILE, '/var/tmp/iptablesmangle.txt');
|
||||
open (FILE, '/usr/local/bin/getipstat -m | ');
|
||||
while (<FILE>){
|
||||
|
||||
$ipmlines[$manlines] = $_;
|
||||
@@ -333,11 +331,11 @@ print <<END
|
||||
END
|
||||
;
|
||||
|
||||
# We´ll open the txt files and extract each line, if the line
|
||||
# We´ll get iptables output and examine each line, if the line
|
||||
# start with an Chain the the name, start- and endline of the
|
||||
# chain is extracted into a hash
|
||||
|
||||
open (FILE, '/var/tmp/iptablesnat.txt');
|
||||
open (FILE, '/usr/local/bin/getipstat -n | ');
|
||||
while (<FILE>){
|
||||
|
||||
$ipnatlines[$natlines] = $_;
|
||||
@@ -433,7 +431,3 @@ print "</table></div><br />";
|
||||
&Header::closebox();
|
||||
&Header::closebigbox();
|
||||
&Header::closepage();
|
||||
|
||||
system("rm -f /var/tmp/iptables.txt");
|
||||
system("rm -f /var/tmp/iptablesmangle.txt");
|
||||
system("rm -f /var/tmp/iptablesnat.txt");
|
||||
|
||||
Reference in New Issue
Block a user