]>
Commit | Line | Data |
---|---|---|
1dcd8715 SS |
1 | #!/usr/bin/perl -w |
2 | ############################################################################ | |
3 | # # | |
4 | # This file is part of the IPFire Firewall. # | |
5 | # # | |
6 | # IPFire is free software; you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation; either version 2 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # IPFire is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with IPFire; if not, write to the Free Software # | |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # | |
19 | # # | |
20 | # Copyright (C) 2015 IPFire Team <info@ipfire.org>. # | |
21 | # # | |
22 | ############################################################################ | |
23 | ||
24 | package GeoIP; | |
25 | ||
26 | use Locale::Country; | |
27 | ||
28 | # Function to get the flag icon for a specified country code. | |
29 | sub get_flag_icon($) { | |
30 | my ($input) = @_; | |
31 | ||
32 | # Webserver's root dir. (Required for generating full path) | |
33 | my $webroot = "/srv/web/ipfire/html"; | |
34 | ||
35 | # Directory which contains the flag icons. | |
36 | my $flagdir = "/images/flags"; | |
37 | ||
38 | # File extension of the country flags. | |
39 | my $ext = "png"; | |
40 | ||
41 | # Remove whitespaces. | |
42 | chomp($input); | |
43 | ||
44 | # Convert given country code to lower case. | |
45 | my $ccode = lc($input); | |
46 | ||
47 | # Generate filename, based on the contry code in lower case | |
48 | # and the defined file extension. | |
49 | my $file = join('.', $ccode,$ext); | |
50 | ||
51 | # Generate path inside webroot to the previously generated file. | |
52 | my $flag_icon = join('/', $flagdir,$file); | |
53 | ||
54 | # Generate absolute path to the icon file. | |
55 | my $absolute_path = join('', $webroot,$flag_icon); | |
56 | ||
57 | # Check if the a icon file exists. | |
58 | if (-e "$absolute_path") { | |
59 | # Return content of flag_icon. | |
60 | return $flag_icon; | |
61 | } | |
62 | } | |
63 | ||
64 | # Function to get the county name by a given country code. | |
65 | sub get_full_country_name($) { | |
66 | my ($input) = @_; | |
67 | my $name; | |
68 | ||
69 | # Remove whitespaces. | |
70 | chomp($input); | |
71 | ||
72 | # Convert input into lower case format. | |
73 | my $code = lc($input); | |
74 | ||
75 | # Handle country codes which are not in the list. | |
76 | if ($code eq "a1") { $name = "Anonymous Proxy" } | |
77 | elsif ($code eq "a2") { $name = "Satellite Provider" } | |
78 | elsif ($code eq "o1") { $name = "Other Country" } | |
79 | elsif ($code eq "ap") { $name = "Asia/Pacific Region" } | |
80 | elsif ($code eq "eu") { $name = "Europe" } | |
81 | elsif ($code eq "yu") { $name = "Yugoslavia" } | |
82 | else { | |
83 | # Use perl built-in module to get the country code. | |
84 | $name = &Locale::Country::code2country($code); | |
85 | } | |
86 | ||
87 | return $name; | |
88 | } | |
89 | ||
90 | 1; |