]>
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}/geoip-functions.pl";
29 require "${General::swroot}/lang.pl";
30 require "${General::swroot}/header.pl";
31 require "/usr/lib/firewall/firewall-lib.pl";
34 my $settingsfile = "${General::swroot}/firewall/geoipblock";
37 my %mainsettings = ();
41 # Read configuration file.
42 &General
::readhash
("$settingsfile", \
%settings);
44 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
45 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
47 &Header
::showhttpheaders
();
50 &Header
::getcgihash
(\
%cgiparams);
52 # Call subfunction to get all available locations.
53 my @locations = &fwlib
::get_geoip_locations
();
55 if ($cgiparams{'ACTION'} eq $Lang::tr
{'save'}) {
56 # Check if we want to disable geoipblock.
57 if (exists $cgiparams{'GEOIPBLOCK_ENABLED'}) {
58 $settings{'GEOIPBLOCK_ENABLED'} = "on";
60 $settings{'GEOIPBLOCK_ENABLED'} = "off";
63 # Loop through our locations array to prevent from
64 # non existing countries or code.
65 foreach my $cn (@locations) {
66 # Check if blocking for this country should be enabled/disabled.
67 if (exists $cgiparams{$cn}) {
68 $settings{$cn} = "on";
70 $settings{$cn} = "off";
74 &General
::writehash
("$settingsfile", \
%settings);
76 # Mark the firewall config as changed.
77 &General
::firewall_config_changed
();
79 # Assign reload notice. We directly can use
80 # the notice from p2p block.
81 $notice = $Lang::tr
{'p2p block save notice'};
84 &Header
::openpage
($Lang::tr
{'geoipblock configuration'}, 1, '');
86 # Print notice that a firewall reload is required.
88 &Header
::openbox
('100%', 'left', $Lang::tr
{'notice'});
89 print "<font class='base'>$notice</font>";
93 # Checkbox pre-selection.
95 if ($settings{'GEOIPBLOCK_ENABLED'} eq "on") {
96 $checked = "checked='checked'";
99 # Print box to enable/disable geoipblock.
100 print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
102 &Header
::openbox
('100%', 'center', $Lang::tr
{'geoipblock'});
106 <td width='25%' class='base'>$Lang::tr{'geoipblock enable feature'}
107 <td><input type='checkbox' name='GEOIPBLOCK_ENABLED' $checked></td>
110 <td colspan='2'><br></td>
118 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
125 &Header
::openbox
('100%', 'center', $Lang::tr
{'geoipblock block countries'});
129 // Function to allow checking all checkboxes at once.
130 function check_all() {
131 \$("#countries").find(":checkbox").prop("checked", true);
134 function uncheck_all() {
135 \$("#countries").find(":checkbox").prop("checked", false);
139 <table width='95%' class='tbl' id="countries">
141 <td width='5%' align='center' bgcolor='$color{'color20'}'></td>
142 <td width='5%' align='center' bgcolor='$color{'color20'}'>
143 <b>$Lang::tr{'flag'}</b>
145 <td width='5%' align='center' bgcolor='$color{'color20'}'>
146 <b>$Lang::tr{'countrycode'}</b>
148 <td with='35%' align='left' bgcolor='$color{'color20'}'>
149 <b>$Lang::tr{'country'}</b>
152 <td width='5%' bgcolor='$color{'color20'}'> </td>
154 <td width='5%' align='center' bgcolor='$color{'color20'}'></td>
155 <td width='5%' align='center' bgcolor='$color{'color20'}'>
156 <b>$Lang::tr{'flag'}</b>
158 <td width='5%' align='center' bgcolor='$color{'color20'}'>
159 <b>$Lang::tr{'countrycode'}</b>
161 <td with='35%' align='left' bgcolor='$color{'color20'}'>
162 <b>$Lang::tr{'country'}</b>
170 foreach my $location (@locations) {
171 # Country code in upper case. (DE)
172 my $ccode_uc = $location;
174 # County code in lower case. (de)
175 my $ccode_lc = lc($location);
177 # Full name of the country based on the country code.
178 my $cname = &GeoIP
::get_full_country_name
($ccode_lc);
180 # Get flag icon for of the country.
181 my $flag_icon = &GeoIP
::get_flag_icon
($ccode_uc);
184 # Check if a flag for the country is available.
186 $flag="<img src='$flag_icon' alt='$ccode_uc' title='$ccode_uc'>";
191 # Checkbox pre-selection.
193 if ($settings{$ccode_uc} eq "on") {
194 $checked = "checked='checked'";
199 $col="bgcolor='$color{'color20'}'";
201 $col="bgcolor='$color{'color22'}'";
208 # Increase lines (background color by once.
211 # Add empty column in front.
212 $line_start="<td $col> </td>";
214 # When the line number can be diveded by "2",
215 # we are going to close the line.
218 # When the line number is not divideable by "2",
219 # we are starting a new line.
224 print "$line_start<td align='center' $col><input type='checkbox' name='$ccode_uc' $checked></td>\n";
225 print "<td align='center' $col>$flag</td>\n";
226 print "<td align='center' $col>$ccode_uc</td>\n";
227 print "<td align='left' $col>$cname</td>$line_end\n";
229 # Finish column when the last element in the array has passed and we have an uneven amount of items.
230 if(! ($lines2 % 2) && ($location eq $locations[-1] )) {
231 print "<td $col> </td>\n";
232 print "<td $col> </td>\n";
233 print "<td $col> </td>\n";
234 print "<td $col> </td>\n";
235 print "<td $col> </td></tr>\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
();