]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/location-block.cgi
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2020 IPFire 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}/location-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/locationblock";
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/ipfire/include/colors.txt", \
%color);
47 &Header
::showhttpheaders
();
50 &Header
::getcgihash
(\
%cgiparams);
52 # Call subfunction to get all available locations.
53 my @locations = &Location
::Functions
::get_locations
();
55 if ($cgiparams{'ACTION'} eq $Lang::tr
{'save'}) {
56 # Check if we want to disable locationblock.
57 if (exists $cgiparams{'LOCATIONBLOCK_ENABLED'}) {
58 $settings{'LOCATIONBLOCK_ENABLED'} = "on";
60 $settings{'LOCATIONBLOCK_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.
80 $notice = $Lang::tr
{'fw rules reload notice'};
83 &Header
::openpage
($Lang::tr
{'locationblock configuration'}, 1, '');
85 # Print notice that a firewall reload is required.
87 &Header
::openbox
('100%', 'left', $Lang::tr
{'notice'});
88 print "<font class='base'>$notice</font>";
92 # Checkbox pre-selection.
94 if ($settings{'LOCATIONBLOCK_ENABLED'} eq "on") {
95 $checked = "checked='checked'";
98 # Print box to enable/disable locationblock.
99 print"<form method='POST' action='$ENV{'SCRIPT_NAME'}'>\n";
101 &Header
::openbox
('100%', 'center', $Lang::tr
{'locationblock'});
105 <td width='50%' class='base'>$Lang::tr{'locationblock enable feature'}
106 <td><input type='checkbox' name='LOCATIONBLOCK_ENABLED' $checked></td>
109 <td colspan='2'><br></td>
117 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
124 &Header
::openbox
('100%', 'center', $Lang::tr
{'locationblock block countries'});
128 // Function to allow checking all checkboxes at once.
129 function check_all() {
130 \$("#countries").find(":checkbox").prop("checked", true);
133 function uncheck_all() {
134 \$("#countries").find(":checkbox").prop("checked", false);
138 <table width='95%' class='tbl' id="countries">
140 <td width='5%' align='center' bgcolor='$color{'color20'}'></td>
141 <td width='5%' align='center' bgcolor='$color{'color20'}'>
142 <b>$Lang::tr{'flag'}</b>
144 <td width='5%' align='center' bgcolor='$color{'color20'}'>
145 <b>$Lang::tr{'countrycode'}</b>
147 <td with='35%' align='left' bgcolor='$color{'color20'}'>
148 <b>$Lang::tr{'country'}</b>
151 <td width='5%' bgcolor='$color{'color20'}'> </td>
153 <td width='5%' align='center' bgcolor='$color{'color20'}'></td>
154 <td width='5%' align='center' bgcolor='$color{'color20'}'>
155 <b>$Lang::tr{'flag'}</b>
157 <td width='5%' align='center' bgcolor='$color{'color20'}'>
158 <b>$Lang::tr{'countrycode'}</b>
160 <td with='35%' align='left' bgcolor='$color{'color20'}'>
161 <b>$Lang::tr{'country'}</b>
169 foreach my $location (@locations) {
170 # Country code in upper case. (DE)
171 my $ccode_uc = $location;
173 # County code in lower case. (de)
174 my $ccode_lc = lc($location);
176 # Full name of the country based on the country code.
177 my $cname = &Location
::Functions
::get_full_country_name
($ccode_lc);
179 # Get flag icon for of the country.
180 my $flag_icon = &Location
::Functions
::get_flag_icon
($ccode_uc);
183 # Check if a flag for the country is available.
185 $flag="<img src='$flag_icon' alt='$ccode_uc' title='$ccode_uc'>";
190 # Checkbox pre-selection.
192 if ($settings{$ccode_uc} eq "on") {
193 $checked = "checked='checked'";
198 $col="bgcolor='$color{'color20'}'";
200 $col="bgcolor='$color{'color22'}'";
207 # Increase lines (background color by once.
210 # Add empty column in front.
211 $line_start="<td $col> </td>";
213 # When the line number can be diveded by "2",
214 # we are going to close the line.
217 # When the line number is not divideable by "2",
218 # we are starting a new line.
223 print "$line_start<td align='center' $col><input type='checkbox' name='$ccode_uc' $checked></td>\n";
224 print "<td align='center' $col>$flag</td>\n";
225 print "<td align='center' $col>$ccode_uc</td>\n";
226 print "<td align='left' $col>$cname</td>$line_end\n";
228 # Finish column when the last element in the array has passed and we have an uneven amount of items.
229 if(! ($lines2 % 2) && ($location eq $locations[-1] )) {
230 print "<td $col> </td>\n";
231 print "<td $col> </td>\n";
232 print "<td $col> </td>\n";
233 print "<td $col> </td>\n";
234 print "<td $col> </td></tr>\n";
246 <a href="javascript:check_all()">$Lang::tr{'check all'}</a> /
247 <a href="javascript:uncheck_all()">$Lang::tr{'uncheck all'}</a>
251 <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}'></td>
259 <td width='5%'><img src='/images/on.gif'></td>
260 <td>$Lang::tr{'locationblock country is blocked'}</td>
261 <td width='5%'><img src='/images/off.gif'></td>
262 <td>$Lang::tr{'locationblock country is allowed'}</td>
270 &Header
::closebigbox
();
271 &Header
::closepage
();