mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
firewall: Add support for geoipblock to rules.pl.
This commit is contained in:
38
config/firewall/rules.pl
Executable file → Normal file
38
config/firewall/rules.pl
Executable file → Normal file
@@ -60,6 +60,7 @@ my $configfwdfw = "${General::swroot}/firewall/config";
|
||||
my $configinput = "${General::swroot}/firewall/input";
|
||||
my $configoutgoing = "${General::swroot}/firewall/outgoing";
|
||||
my $p2pfile = "${General::swroot}/firewall/p2protocols";
|
||||
my $geoipfile = "${General::swroot}/firewall/geoipblock";
|
||||
my $configgrp = "${General::swroot}/fwhosts/customgroups";
|
||||
my $netsettings = "${General::swroot}/ethernet/settings";
|
||||
|
||||
@@ -94,6 +95,9 @@ sub main {
|
||||
# Load P2P block rules.
|
||||
&p2pblock();
|
||||
|
||||
# Load GeoIP block rules.
|
||||
&geoipblock();
|
||||
|
||||
# Reload firewall policy.
|
||||
run("/usr/sbin/firewall-policy");
|
||||
}
|
||||
@@ -570,6 +574,40 @@ sub p2pblock {
|
||||
}
|
||||
}
|
||||
|
||||
sub geoipblock {
|
||||
my %geoipsettings = ();
|
||||
|
||||
# Check if the geoip settings file exists
|
||||
if (-e "$geoipfile") {
|
||||
# Read settings file
|
||||
&General::readhash("$geoipfile", \%geoipsettings);
|
||||
} else {
|
||||
# Exit submodule, go on processing the remaining script
|
||||
return;
|
||||
}
|
||||
|
||||
# If geoip blocking is not enabled, we are finished here.
|
||||
if ($geoipsettings{'GEOIPBLOCK_ENABLED'} ne "on") {
|
||||
# Exit submodule. Process remaining script.
|
||||
return;
|
||||
}
|
||||
|
||||
# Get supported locations.
|
||||
my @locations = &fwlib::get_geoip_locations();
|
||||
|
||||
# Create iptables chain.
|
||||
run("$IPTABLES -F GEOIPBLOCK");
|
||||
|
||||
# Loop through all supported geoip locations and
|
||||
# create iptables rules, if blocking this country
|
||||
# is enabled.
|
||||
foreach my $location (@locations) {
|
||||
if($geoipsettings{$location} eq "on") {
|
||||
run("$IPTABLES -A GEOIPBLOCK -m geoip --src-cc $location -j DROP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub get_protocols {
|
||||
my $hash = shift;
|
||||
my $key = shift;
|
||||
|
||||
Reference in New Issue
Block a user