]> git.ipfire.org Git - thirdparty/xtables-addons.git/commitdiff
geoip: replace xt_geoip_build's -S option by new option -i
authorJan Engelhardt <jengelh@inai.de>
Tue, 12 May 2020 20:43:58 +0000 (22:43 +0200)
committerJan Engelhardt <jengelh@inai.de>
Tue, 12 May 2020 20:47:00 +0000 (22:47 +0200)
The Maxmind DB came with potentially multiple files, but DBIP is
currently just one. Drop the -S argument and instead introduce -i.

geoip/xt_geoip_build
geoip/xt_geoip_build.1

index e7ad9bfdcc1e3b617ada77872f9be87e126b885f..750bf9835424d5bad6c2ebdbb90b845e52767b7d 100755 (executable)
@@ -17,19 +17,15 @@ my $csv = Text::CSV_XS->new({
        binary => 1,
        eol => $/,
 }); # or Text::CSV
-my $source_dir = ".";
+my $input_file = "dbip-country-lite.csv";
 my $target_dir = ".";
 
 &Getopt::Long::Configure(qw(bundling));
 &GetOptions(
        "D=s" => \$target_dir,
-       "S=s" => \$source_dir,
+       "i=s" => \$input_file,
 );
 
-if (!-d $source_dir) {
-       print STDERR "Source directory \"$source_dir\" does not exist.\n";
-       exit 1;
-}
 if (!-d $target_dir) {
        print STDERR "Target directory \"$target_dir\" does not exist.\n";
        exit 1;
@@ -41,9 +37,11 @@ sub collect
 {
        my ($file, $fh, $row);
        my (%country);
-
-       $file = "$source_dir/dbip-country-lite.csv";
-       open($fh, '<', $file) || die "Can't open DBIP database\n";
+       if ($input_file eq "-") {
+               open($fh, "<&STDIN");
+       } else {
+               open($fh, "<", $input_file) || die "Cannot open $input_file: $!\n";
+       }
 
        while ($row = $csv->getline($fh)) {
                my ($cc, $range);
index 3b6ead31edd405688e692d1244fd6726dd529875..ac3e6d38692b1e7ea202af8b05575a502f61acd6 100644 (file)
@@ -5,7 +5,7 @@ xt_geoip_build \(em convert GeoIP.csv to packed format for xt_geoip
 .SH Syntax
 .PP
 \fI/usr/libexec/xt_geoip/\fP\fBxt_geoip_build\fP [\fB\-D\fP
-\fItarget_dir\fP] [\fB\-S\fP \fIsource_dir\fP]
+\fItarget_dir\fP] [\fB\-i\fP \fIinput_file\fP]
 .SH Description
 .PP
 xt_geoip_build is used to build packed raw representations of the range
@@ -24,11 +24,9 @@ script requires it to be called with a path.
 \fB\-D\fP \fItarget_dir\fP
 Specifies the target directory into which the files are to be put. Defaults to ".".
 .TP
-\fB\-S\fP \fIsource_dir\fP
-Specifies the source directory from which to read the three files by the name
-of \fBGeoLite2\-Country\-Blocks\-IPv4.csv\fP,
-\fBGeoLite2\-Country\-Blocks\-IPv6.csv\fP and
-\fBGeoLite2\-Country\-Locations\-en.csv\fP. Defaults to ".".
+\fB\-i\fP \fIinput_file\fP
+Specifies the source location of the DBIP CSV file. Defaults to
+"dbip-country-lite.csv". Use "-" to read from stdin.
 .SH Application
 .PP
 Shell commands to build the databases and put them to where they are expected: