Skip to content

Commit 6ec1d11

Browse files
authored
Merge pull request #7 from bolemo/dev
Dev
2 parents 568596a + a743f5c commit 6ec1d11

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Firewall blocklist script for Netgear R7800 Router with Voxel firmware.
33
Should work with several other Netgear routers as well.
44

55
## Version
6-
3.0.0
6+
3.0.1
77

88
## Prerequisite
99
* You need to have Voxel's Firmware: https://www.voxel-firmware.com
@@ -14,7 +14,7 @@ Should work with several other Netgear routers as well.
1414
## Install
1515
* Connect to router's terminal with ssh or telnet
1616
* Go to the attached drive (USB): `cd /mnt/optware/` (or change optware by the mountpoint of your drive)
17-
* Copy and paste the following command: `wget -qO- https://github.com/bolemo/firewall-blocklist/archive/v3.0.0.tar.gz | tar xzf - --one-top-level=fbl --strip-components 1`
17+
* Copy and paste the following command: `wget -qO- https://github.com/bolemo/firewall-blocklist/archive/v3.0.1.tar.gz | tar xzf - --one-top-level=fbl --strip-components 1`
1818
* Make install script executable: `chmod +x fbl/install.sh`
1919
* Run install script: `fbl/install.sh`
2020
* Answer `y` if you want to install iprange

firewall-blocklist

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ WAN_NETMASK="$(nvram get wan_netmask)"
1313

1414
#we are called from firewall_start.sh
1515
if [ $1 ] && [ $1 = "_fws" ]; then
16-
# create ipset blocklist
17-
if ! ipset -q list "$IPSET_NAME"; then
18-
# ipset is not here
16+
17+
# creating ipset blocklist if needed
18+
if ! ipset -q -n list "$IPSET_NAME">/dev/null; then
1919
if [ -r $IP_LIST ]; then
2020
# netset file exists, so creating blocklist ipset from it
2121
echo -e "create "$IPSET_NAME" hash:net family inet\n$(sed "s/^/add $IPSET_NAME /" "$IP_LIST")" | ipset restore
@@ -24,21 +24,23 @@ if [ $1 ] && [ $1 = "_fws" ]; then
2424
ipset -q create "$IPSET_NAME" hash:net family inet
2525
fi
2626
fi
27+
28+
# checking if WAN gateway is in blocklist
2729
if ipset -q test "$IPSET_NAME" "$WAN_GATEWAY"
28-
# check if WAN gateway is in ipset blocklist
2930
then WGW_IN_BL='y'
3031
else WGW_IN_BL=''
3132
fi
33+
34+
# creating whitelist if WAN gateway is in blocklist
3235
if [ $WGW_IN_BL ]; then
33-
# WAN gateway is in blocklist so create ipset whitelist
3436
# Calculate WAN_RANGE (IP & CIDR)
3537
_CIDR=0
3638
for _OCTET in $(echo $WAN_NETMASK| sed 's/\./ /g'); do
3739
_BINBITS=$(echo "obase=2; ibase=10; ${_OCTET}"| bc | sed 's/0//g')
3840
let _CIDR+=${#_BINBITS}
3941
done
4042
WAN_RANGE="$WAN_GATEWAY/$_CIDR"
41-
if ipset -q list "$IPSET_WL_NAME"; then
43+
if ipset -q -n list "$IPSET_WL_NAME">/dev/null; then
4244
# whitelist ipset is already here, make new one and swap
4345
ipset -q destroy "$IPSET_TMP"
4446
ipset -q create "$IPSET_TMP" hash:net family inet maxelem 1
@@ -54,11 +56,16 @@ if [ $1 ] && [ $1 = "_fws" ]; then
5456
# no need for whitelist, just destroy if exists
5557
ipset -q destroy "$IPSET_WL_NAME"
5658
fi
57-
# create the filtering (blocking) iptables chain
59+
60+
#checking if IPTBL_NAME is already set (should not); if it is, exit
61+
iptables -L "$IPTBL_NAME" >/dev/null 2>/dev/null && exit 1
62+
63+
# creating the filtering (blocking) iptables chain
5864
iptables -N "$IPTBL_NAME"
5965
[ $IPTBL_LOGGING ] && iptables -A "$IPTBL_NAME" -j LOG --log-prefix "[$SC_NAME] "
6066
iptables -A "$IPTBL_NAME" -j DROP
61-
# create the required iptables
67+
68+
# creating the required iptables
6269
if [ $WGW_IN_BL ]; then
6370
# creating iptables with whitelist
6471
iptables -I INPUT 1 -i brwan -m set --match-set "$IPSET_WL_NAME" src -j ACCEPT
@@ -80,7 +87,7 @@ if [ $1 ] && [ $1 = "_fws" ]; then
8087
exit 0
8188
fi
8289

83-
SC_VERS="v3.0.0"
90+
SC_VERS="v3.0.1"
8491
SC_PATH="$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
8592
IPR_BIN="$(command -v iprange)"
8693
# IPT_MD5 & IPT_MD5_NO_WL depends on IPTBL_NAME, IPSET_NAME and IPSET_WL_NAME
@@ -198,10 +205,10 @@ fw_restart() {
198205
[ $VERBOSE ] && echo -e "\033[1;36mRestarting firewall...\033[0m"
199206
if [ $LOG_ACT ]; then
200207
if [ "$LOG_ACT" = 'ON' ]; then
201-
echo "- Enabling logging."
208+
[ $VERBOSE ] && echo "- Enabling logging."
202209
nvram set log_firewall_blocklist=1
203210
else
204-
echo "- Disabling logging."
211+
[ $VERBOSE ] && echo "- Disabling logging."
205212
nvram unset log_firewall_blocklist
206213
fi
207214
fi

0 commit comments

Comments
 (0)