mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-13 12:32:59 +02:00
geoip-locations.pl: Add get_geoip_locations().
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@ipfire.org> Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
committed by
Michael Tremer
parent
e3429b4aad
commit
30c59cbb0b
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user