X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=blobdiff_plain;f=config%2Fcfgroot%2Fgeneral-functions.pl;h=bd5ad0ac86aadc20a8eba574c07ec79a54fe2eba;hp=66286ed1e0ac09c2a4c553c46f49cd5ef1a59904;hb=cebb1b7cb1327b87e3fa6932eee151a26a9f85c2;hpb=4616ecceced8208c695e697395f0b916d875fb91 diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 66286ed1e0..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 @@ -286,7 +287,7 @@ sub validip sub validmask { my $mask = shift; - return &Network::check_netmask($mask) or &Network::check_prefix($mask); + return &Network::check_netmask($mask) || &Network::check_prefix($mask); } sub validipormask @@ -388,7 +389,9 @@ sub iporsubtocidr } sub getnetworkip { - return &Network::get_netaddress(shift); + my $arg = join("/", @_); + + return &Network::get_netaddress($arg); } sub getccdbc @@ -627,9 +630,8 @@ sub validdomainname my @parts = split (/\./, $domainname); # Split hostname at the '.' foreach $part (@parts) { - # Each part should be at least two characters in length - # but no more than 63 characters - if (length ($part) < 2 || length ($part) > 63) { + # Each part should be no more than 63 characters in length + if (length ($part) < 1 || length ($part) > 63) { return 0;} # Only valid characters are a-z, A-Z, 0-9 and - if ($part !~ /^[a-zA-Z0-9-]*$/) { @@ -1122,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;