From: Stefan Schantl Date: Sat, 3 Jan 2015 19:15:28 +0000 (+0100) Subject: general-functions.pl: Add function to get full country name. X-Git-Tag: v2.17-core91~128^2~6^2~12^2~24 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=cebb1b7cb1327b87e3fa6932eee151a26a9f85c2;ds=sidebyside general-functions.pl: Add function to get full country name. This function will return the full name a country specified by it's country shortcut. It also will provide some additional names which are not handled by the perl locale module but are parts of ISO 3166. --- diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 35ae7c0930..bd5ad0ac86 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -17,6 +17,7 @@ package General; use strict; use Socket; use IO::Socket; +use Locale::Country; use Net::SSLeay; use Net::IPv4Addr qw(:all); $|=1; # line buffering @@ -1123,4 +1124,30 @@ sub get_red_interface() { return $interface; } +# Function to get the county name by a given country code. +sub get_full_country_name($) { + my ($input) = @_; + my $name; + + # Remove whitespaces. + chomp($input); + + # Convert input into lower case format. + my $code = lc($input); + + # Handle country codes which are not in the list. + if ($code eq "a1") { $name = "Anonymous Proxy" } + elsif ($code eq "a2") { $name = "Satellite Provider" } + elsif ($code eq "o1") { $name = "Other Country" } + elsif ($code eq "ap") { $name = "Asia/Pacific Region" } + elsif ($code eq "eu") { $name = "Europe" } + elsif ($code eq "yu") { $name = "Yugoslavia" } + else { + # Use perl built-in module to get the country code. + $name = &Locale::Country::code2country($code); + } + + return $name; +} + 1;