mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-05 20:26:38 +02:00
geoip: add quiet flag to xt_geoip_build
Conceivably someone might want to run a refresh of the geoip database from within a script, particularly an unattended script such as a cron job. Do not generate output in that case. Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
This commit is contained in:

committed by
Jan Engelhardt

parent
c9ba3507fc
commit
ca84ee8e15
@@ -17,6 +17,7 @@ my $csv = Text::CSV_XS->new({
|
|||||||
binary => 1,
|
binary => 1,
|
||||||
eol => $/,
|
eol => $/,
|
||||||
}); # or Text::CSV
|
}); # or Text::CSV
|
||||||
|
my $quiet = 0;
|
||||||
my $input_file = "dbip-country-lite.csv";
|
my $input_file = "dbip-country-lite.csv";
|
||||||
my $target_dir = ".";
|
my $target_dir = ".";
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ my $target_dir = ".";
|
|||||||
&GetOptions(
|
&GetOptions(
|
||||||
"D=s" => \$target_dir,
|
"D=s" => \$target_dir,
|
||||||
"i=s" => \$input_file,
|
"i=s" => \$input_file,
|
||||||
|
"q" => \$quiet,
|
||||||
"s" => sub { $target_dir = "/usr/share/xt_geoip"; },
|
"s" => sub { $target_dir = "/usr/share/xt_geoip"; },
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -62,12 +64,12 @@ sub collect
|
|||||||
$country{$cc}->{pool_v6}->add_range($range);
|
$country{$cc}->{pool_v6}->add_range($range);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($. % 4096 == 0) {
|
if (!$quiet && $. % 4096 == 0) {
|
||||||
print STDERR "\r\e[2K$. entries";
|
print STDERR "\r\e[2K$. entries";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print STDERR "\r\e[2K$. entries total\n";
|
print STDERR "\r\e[2K$. entries total\n" unless ($quiet);
|
||||||
|
|
||||||
close($fh);
|
close($fh);
|
||||||
|
|
||||||
@@ -105,7 +107,7 @@ sub writeCountry
|
|||||||
printf "%5u IPv%s ranges for %s\n",
|
printf "%5u IPv%s ranges for %s\n",
|
||||||
scalar(@ranges),
|
scalar(@ranges),
|
||||||
($family == AF_INET ? '4' : '6'),
|
($family == AF_INET ? '4' : '6'),
|
||||||
$iso_code;
|
$iso_code unless ($quiet);
|
||||||
|
|
||||||
my $file = "$target_dir/".uc($iso_code).".iv".($family == AF_INET ? '4' : '6');
|
my $file = "$target_dir/".uc($iso_code).".iv".($family == AF_INET ? '4' : '6');
|
||||||
if (!open($fh, '>', $file)) {
|
if (!open($fh, '>', $file)) {
|
||||||
|
Reference in New Issue
Block a user