]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/geoip-block.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2014 IPFire Developemnt Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
23 # enable only the following on debugging purpose
25 #use CGI::Carp 'fatalsToBrowser';
27 require '/var/ipfire/general-functions.pl';
28 require "${General::swroot}/lang.pl";
29 require "${General::swroot}/header.pl";
30 require "/usr/lib/firewall/firewall-lib.pl";
32 # Directory which contains flag icons.
33 my $flagdir = "/srv/web/ipfire/html/images/flags";
34 # File extension of the country flags.
35 my $extension = "png";
38 my $settingsfile = "${General::swroot}/firewall/geoipblock";
41 my %mainsettings = ();
45 # Read configuration file.
46 &General
::readhash
("$settingsfile", \
%settings);
48 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
49 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
51 &Header
::showhttpheaders
();
54 &Header
::getcgihash
(\
%cgiparams);
56 # Call subfunction to get all available locations.
57 my @locations = &fwlib
::get_geoip_locations
();
59 if ($cgiparams{'ACTION'} eq $Lang::tr
{'save'}) {
60 # Check if we want to disable geoipblock.
61 if (exists $cgiparams{'GEOIPBLOCK_ENABLED'}) {
62 $settings{'GEOIPBLOCK_ENABLED'} = "on";
64 $settings{'GEOIPBLOCK_ENABLED'} = "off";
67 # Loop through our locations array to prevent from
68 # non existing countries or code.
69 foreach my $cn (@locations) {
70 # Check if blocking for this country should be enabled/disabled.
71 if (exists $cgiparams{$cn}) {
72 $settings{$cn} = "on";
74 $settings{$cn} = "off";
78 &General
::writehash
("$settingsfile", \
%settings);
80 # Mark the firewall config as changed.
81 &General
::firewall_config_changed
();
83 # Assign reload notice. We directly can use
84 # the notice from p2p block.
85 $notice = $Lang::tr
{'p2p block save notice'};
88 &Header
::openpage
($Lang::tr
{'geoipblock configuration'}, 1, '');
90 # Print notice that a firewall reload is required.
92 &Header
::openbox
('100%', 'left', $Lang::tr
{'notice'});
93 print "<font class='base'>$notice</font>";
97 # Checkbox pre-selection.
99 if ($settings{'GEOIPBLOCK_ENABLED'} eq "on") {
100 $checked = "checked='checked'";
103 # Print box to enable/disable geoipblock.
104 print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
106 &Header
::openbox
('100%', 'center', $Lang::tr
{'geoipblock'});
110 <td width='25%' class='base'>$Lang::tr{'geoipblock enable feature'}
111 <td><input type='checkbox' name='GEOIPBLOCK_ENABLED' $checked></td>
114 <td colspan='2'><br></td>
122 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
129 &Header
::openbox
('100%', 'center', $Lang::tr
{'geoipblock block countries'});
133 // Function to allow checking all checkboxes at once.
134 function check_all() {
135 \$("#countries").find(":checkbox").prop("checked", true);
138 function uncheck_all() {
139 \$("#countries").find(":checkbox").prop("checked", false);
143 <table width='95%' class='tbl' id="countries">
145 <td width='5%' align='center' bgcolor='$color{'color20'}'></td>
146 <td width='5%' align='center' bgcolor='$color{'color20'}'>
147 <b>$Lang::tr{'flag'}</b>
149 <td width='5%' align='center' bgcolor='$color{'color20'}'>
150 <b>$Lang::tr{'countrycode'}</b>
152 <td with='35%' align='left' bgcolor='$color{'color20'}'>
153 <b>$Lang::tr{'country'}</b>
156 <td width='5%' bgcolor='$color{'color20'}'> </td>
158 <td width='5%' align='center' bgcolor='$color{'color20'}'></td>
159 <td width='5%' align='center' bgcolor='$color{'color20'}'>
160 <b>$Lang::tr{'flag'}</b>
162 <td width='5%' align='center' bgcolor='$color{'color20'}'>
163 <b>$Lang::tr{'countrycode'}</b>
165 <td with='35%' align='left' bgcolor='$color{'color20'}'>
166 <b>$Lang::tr{'country'}</b>
174 foreach my $location (@locations) {
175 # Country code in upper case. (DE)
176 my $ccode_uc = $location;
178 # County code in lower case. (de)
179 my $ccode_lc = lc($location);
181 # Full name of the country based on the country code.
182 my $cname = &General
::get_full_country_name
($ccode_lc);
184 # Generate flag filename, based on the lower case written contry code
185 # and the defined file extension of the image files. (de.png)
186 my $flagfile = join('.', $ccode_lc,$extension);
188 # Generate the full path to the flagfile, based on the given path and
189 # the previously generated filename.
190 my $flagpath = join('/', $flagdir,$flagfile);
193 # Check if a flag for the country is available.
194 if (-e
"$flagpath") {
195 $flag="<img src='/images/flags/$flagfile' alt='$ccode_uc' title='$ccode_uc'>";
200 # Checkbox pre-selection.
202 if ($settings{$ccode_uc} eq "on") {
203 $checked = "checked='checked'";
208 $col="bgcolor='$color{'color20'}'";
210 $col="bgcolor='$color{'color22'}'";
217 # Increase lines (background color by once.
220 # Add empty column in front.
221 $line_start="<td $col> </td>";
223 # When the line number can be diveded by "2",
224 # we are going to close the line.
227 # When the line number is not divideable by "2",
228 # we are starting a new line.
233 print "$line_start<td align='center' $col><input type='checkbox' name='$ccode_uc' $checked></td>\n";
234 print "<td align='center' $col>$flag</td>\n";
235 print "<td align='center' $col>$ccode_uc</td>\n";
236 print "<td align='left' $col>$cname</td>$line_end\n";
247 <a href="javascript:check_all()">$Lang::tr{'check all'}</a> /
248 <a href="javascript:uncheck_all()">$Lang::tr{'uncheck all'}</a>
252 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
260 <td width='5%'><img src='/images/on.gif'></td>
261 <td>$Lang::tr{'geoipblock country is blocked'}</td>
262 <td width='5%'><img src='/images/off.gif'></td>
263 <td>$Lang::tr{'geoipblock country is allowed'}</td>
271 &Header
::closebigbox
();
272 &Header
::closepage
();