* [PATCH 1/2] geoip-locations.pl: Add get_geoip_locations().
@ 2019-01-10 19:40 Stefan Schantl
2019-01-10 19:40 ` [PATCH 2/2] firewall-lib.pl: Use get_geoip_locations from geoip-functions.pl Stefan Schantl
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Schantl @ 2019-01-10 19:40 UTC (permalink / raw)
To: development
[-- Attachment #1: Type: text/plain, Size: 1566 bytes --]
This function is used to get all available GeoIP locations.
The functions returns them as array, sorted in alphabetical order.
Reference #11959
Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
config/cfgroot/geoip-functions.pl | 33 +++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/config/cfgroot/geoip-functions.pl b/config/cfgroot/geoip-functions.pl
index e8ce8377f..9f86a09ba 100644
--- a/config/cfgroot/geoip-functions.pl
+++ b/config/cfgroot/geoip-functions.pl
@@ -178,4 +178,37 @@ sub get_full_country_name($) {
return $name;
}
+# Function to get all available GeoIP locations.
+sub get_geoip_locations() {
+ my @locations;
+
+ # Open the location database.
+ open(LOCATION, "$geoip_database_dir/$location_database") or die "Could not open $geoip_database_dir/$location_database. $!\n";
+
+ # Loop through the file.
+ while(my $line = <LOCATION>) {
+ # Remove newlines.
+ chomp($line);
+
+ # Split the line content.
+ my ($geoname_id, $locale_code, $continent_code, $continent_name, $country_iso_code, $country_name, $is_in_european_union) = split(/\,/, $line);
+
+ # Check if the country_iso_code is upper case.
+ if($country_iso_code =~ /[A-Z]/) {
+ # Add the current ISO code.
+ push(@locations, $country_iso_code);
+ }
+ }
+
+ # Close filehandle.
+ close(LOCATION);
+
+ # Sort locations array in alphabetical order.
+ my @sorted_locations = sort(@locations);
+
+ # Return the array..
+ return @sorted_locations;
+}
+
+
1;
--
2.19.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] firewall-lib.pl: Use get_geoip_locations from geoip-functions.pl
2019-01-10 19:40 [PATCH 1/2] geoip-locations.pl: Add get_geoip_locations() Stefan Schantl
@ 2019-01-10 19:40 ` Stefan Schantl
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Schantl @ 2019-01-10 19:40 UTC (permalink / raw)
To: development
[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]
Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
config/firewall/firewall-lib.pl | 32 ++------------------------------
1 file changed, 2 insertions(+), 30 deletions(-)
diff --git a/config/firewall/firewall-lib.pl b/config/firewall/firewall-lib.pl
index 9b7f55c9d..c14023e7b 100644
--- a/config/firewall/firewall-lib.pl
+++ b/config/firewall/firewall-lib.pl
@@ -39,6 +39,7 @@ my %ovpnsettings=();
my %aliases=();
require '/var/ipfire/general-functions.pl';
+require '${General::swroot}/geoip-locations.pl';
my $confignet = "${General::swroot}/fwhosts/customnetworks";
my $confighost = "${General::swroot}/fwhosts/customhosts";
@@ -591,36 +592,7 @@ sub get_internal_firewall_ip_address
}
sub get_geoip_locations() {
- # Path to the directory which contains the binary geoip
- # databases.
- my $directory="/usr/share/xt_geoip/LE";
-
- # Array to store the final country list.
- my @country_codes = ();
-
- # Open location and do a directory listing.
- opendir(DIR, "$directory");
- my @locations = readdir(DIR);
- closedir(DIR);
-
- # Loop through the directory listing, and cut of the file extensions.
- foreach my $location (sort @locations) {
- # skip . and ..
- next if($location =~ /^\.$/);
- next if($location =~ /^\.\.$/);
-
- # Remove whitespaces.
- chomp($location);
-
- # Cut-off file extension.
- my ($country_code, $extension) = split(/\./, $location);
-
- # Add country code to array.
- push(@country_codes, $country_code);
- }
-
- # Return final array.
- return @country_codes;
+ return &GeoIP::get_geoip_locations();
}
return 1;
--
2.19.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-01-10 19:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10 19:40 [PATCH 1/2] geoip-locations.pl: Add get_geoip_locations() Stefan Schantl
2019-01-10 19:40 ` [PATCH 2/2] firewall-lib.pl: Use get_geoip_locations from geoip-functions.pl Stefan Schantl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox