]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/geoip-block.cgi
Merge remote-tracking branch 'ms/dns-forwarding' into next
[ipfire-2.x.git] / html / cgi-bin / geoip-block.cgi
index eb1871919299c2c0ed604f5fe509f7050d0518e9..056b333e8c955eee667a982c2b227804c75c2d0b 100644 (file)
@@ -25,14 +25,12 @@ use strict;
 #use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/geoip-functions.pl";
 require "${General::swroot}/lang.pl";
 require "${General::swroot}/header.pl";
+require "/usr/lib/firewall/firewall-lib.pl";
 
-# Directory which contains flag icons.
-my $flagdir = "/srv/web/ipfire/html/images/flags";
-# File extension of the country flags.
-my $extension = "png";
-
+my $notice;
 my $settingsfile = "${General::swroot}/firewall/geoipblock";
 
 my %color = ();
@@ -52,7 +50,7 @@ my %cgiparams = ();
 &Header::getcgihash(\%cgiparams);
 
 # Call subfunction to get all available locations.
-my @locations = &get_geoip_locations();
+my @locations = &fwlib::get_geoip_locations();
 
 if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
        # Check if we want to disable geoipblock.
@@ -75,13 +73,23 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) {
 
        &General::writehash("$settingsfile", \%settings);
 
-#      &General::firewall_config_changed();
-#
-#      $notice = $Lang::tr{'p2p block save notice'};
+       # Mark the firewall config as changed.
+       &General::firewall_config_changed();
+
+       # Assign reload notice. We directly can use
+       # the notice from p2p block.
+       $notice = $Lang::tr{'p2p block save notice'};
 }
 
 &Header::openpage($Lang::tr{'geoipblock configuration'}, 1, '');
 
+# Print notice that a firewall reload is required.
+if ($notice) {
+       &Header::openbox('100%', 'left', $Lang::tr{'notice'});
+       print "<font class='base'>$notice</font>";
+       &Header::closebox();
+}
+
 # Checkbox pre-selection.
 my $checked;
 if ($settings{'GEOIPBLOCK_ENABLED'} eq "on") {
@@ -167,20 +175,15 @@ foreach my $location (@locations) {
        my $ccode_lc = lc($location);
 
        # Full name of the country based on the country code.
-       my $cname = &General::get_full_country_name($ccode_lc);
-
-       # Generate flag filename, based on the lower case written contry code
-       # and the defined file extension of the image files. (de.png)
-       my $flagfile = join('.', $ccode_lc,$extension);
+       my $cname = &GeoIP::get_full_country_name($ccode_lc);
 
-       # Generate the full path to the flagfile, based on the given path and
-       # the previously generated filename.
-       my $flagpath = join('/', $flagdir,$flagfile);
+       # Get flag icon for of the country.
+       my $flag_icon = &GeoIP::get_flag_icon($ccode_uc);
 
        my $flag;
        # Check if a flag for the country is available.
-       if (-e "$flagpath") {
-               $flag="<img src='/images/flags/$flagfile' alt='$ccode_uc' title='$ccode_uc'>";
+       if ($flag_icon) {
+               $flag="<img src='$flag_icon' alt='$ccode_uc' title='$ccode_uc'>";
        } else {
                $flag="<b>N/A</b>";
        }
@@ -222,7 +225,16 @@ foreach my $location (@locations) {
        print "<td align='center' $col>$flag</td>\n";
        print "<td align='center' $col>$ccode_uc</td>\n";
        print "<td align='left' $col>$cname</td>$line_end\n";
-                       
+
+       # Finish column when the last element in the array has passed and we have an uneven amount of items.
+       if(! ($lines2 % 2) && ($location eq $locations[-1] )) {
+               print "<td $col>&nbsp;</td>\n";
+               print "<td $col>&nbsp;</td>\n";
+               print "<td $col>&nbsp;</td>\n";
+               print "<td $col>&nbsp;</td>\n";
+               print "<td $col>&nbsp;</td></tr>\n";
+       }
+
 $lines2++;
 }
 
@@ -258,35 +270,3 @@ print"</form>\n";
 
 &Header::closebigbox();
 &Header::closepage();
-
-sub get_geoip_locations() {
-       # Path to the directory which contains the binary geoip
-       # databases.
-       my $directory="/usr/share/xt_geoip/BE";
-
-       # Array with the final contry codes list.
-       my @contry_codes;
-
-       # Open location and do a directory listing.
-       opendir(DIR, "$directory");
-       my @locations = readdir(DIR);
-       closedir(DIR);
-
-       # Loop through the directory listing, and cut of the file extensions.
-       foreach my $location (sort @locations) {        
-               # skip . and ..
-               next if($location =~ /^\.$/);
-               next if($location =~ /^\.\.$/);
-
-               # Remove whitespaces.
-               chomp($location);
-
-               # Cut-off file extension.
-               my ($contry_code, $extension) = split(/\./, $location);
-
-               # Add country code to array.
-               push(@contry_codes, $contry_code);
-       }
-
-       return @contry_codes;
-}