Skip to content

Commit aa2fd58

Browse files
committed
Merge branch 'main' into feature/config-tests-drone
2 parents e334204 + 1280c82 commit aa2fd58

File tree

3 files changed

+92
-10
lines changed

3 files changed

+92
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
## [Development]
55

6+
### Features
7+
8+
- Added v-delete-firewall-ban ip all #2031
9+
610
### Bugfixes
711

812
- Fix UI issues after upgrade jQuery + jQuery UI to last version (#2021 and #2032)

bin/v-delete-firewall-ban

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,35 @@ check_hestia_demo_mode
5050
# Self heal iptables links
5151
heal_iptables_links
5252

53-
# Checking ip in banlist
5453
conf="$HESTIA/data/firewall/banlist.conf"
55-
check_ip=$(grep "IP='$ip' CHAIN='$chain'" $conf 2>/dev/null)
56-
if [ -z "$check_ip" ]; then
57-
exit
54+
if [ "$chain" == "ALL" ]; then
55+
check_ip=$(grep "IP='$ip' CHAIN='*'" $conf)
56+
if [ -z "$check_ip" ]; then
57+
exit;
58+
fi
59+
grep "IP='$ip' CHAIN='*'" $conf | while read -r line ; do
60+
parse_object_kv_list $line
61+
62+
# Deleting ip from banlist
63+
sip=$(echo "$IP"| sed "s|/|\\\/|g")
64+
sed -i "/IP='$sip' CHAIN='$CHAIN'/d" $conf
65+
b=$($iptables -L fail2ban-$CHAIN --line-number -n|grep -w $ip|awk '{print $1}')
66+
$iptables -D fail2ban-$CHAIN $b 2>/dev/null
67+
done
68+
else
69+
# Checking ip in banlist
70+
check_ip=$(grep "IP='$ip' CHAIN='$chain'" $conf 2>/dev/null)
71+
if [ -z "$check_ip" ]; then
72+
exit
73+
fi
74+
75+
# Deleting ip from banlist
76+
sip=$(echo "$ip"| sed "s|/|\\\/|g")
77+
sed -i "/IP='$sip' CHAIN='$chain'/d" $conf
78+
b=$($iptables -L fail2ban-$chain --line-number -n|grep -w $ip|awk '{print $1}')
79+
$iptables -D fail2ban-$chain $b 2>/dev/null
5880
fi
5981

60-
# Deleting ip from banlist
61-
sip=$(echo "$ip"| sed "s|/|\\\/|g")
62-
sed -i "/IP='$sip' CHAIN='$chain'/d" $conf
63-
b=$($iptables -L fail2ban-$chain --line-number -n|grep -w $ip|awk '{print $1}')
64-
$iptables -D fail2ban-$chain $b 2>/dev/null
65-
6682
# Changing permissions
6783
chmod 660 $conf
6884

test/test.bats

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ function validate_database(){
237237
fi
238238
}
239239

240+
function check_ip_banned(){
241+
local ip=$1
242+
local chain=$2
243+
244+
run grep "IP='$ip' CHAIN='$chain'" $HESTIA/data/firewall/banlist.conf
245+
assert_success
246+
assert_output --partial "$ip"
247+
}
248+
249+
function check_ip_not_banned(){
250+
local ip=$1
251+
local chain=$2
252+
run grep "IP='$ip' CHAIN='$chain'" $HESTIA/data/firewall/banlist.conf
253+
assert_failure E_ARGS
254+
refute_output
255+
}
256+
257+
240258
#----------------------------------------------------------#
241259
# IP #
242260
#----------------------------------------------------------#
@@ -1397,6 +1415,50 @@ function validate_database(){
13971415
refute_output
13981416
}
13991417

1418+
#----------------------------------------------------------#
1419+
# Firewall #
1420+
#----------------------------------------------------------#
1421+
1422+
@test "Firewall: Add ip to banlist" {
1423+
run v-add-firewall-ban '1.2.3.4' 'HESTIA'
1424+
assert_success
1425+
refute_output
1426+
1427+
check_ip_banned '1.2.3.4' 'HESTIA'
1428+
}
1429+
1430+
@test "Firewall: Delete ip to banlist" {
1431+
run v-delete-firewall-ban '1.2.3.4' 'HESTIA'
1432+
assert_success
1433+
refute_output
1434+
check_ip_not_banned '1.2.3.4' 'HESTIA'
1435+
}
1436+
1437+
@test "Firewall: Add ip to banlist for ALL" {
1438+
run v-add-firewall-ban '1.2.3.4' 'HESTIA'
1439+
assert_success
1440+
refute_output
1441+
run v-add-firewall-ban '1.2.3.4' 'MAIL'
1442+
assert_success
1443+
refute_output
1444+
check_ip_banned '1.2.3.4' 'HESTIA'
1445+
}
1446+
1447+
@test "Firewall: Delete ip to banlist CHAIN = ALL" {
1448+
run v-delete-firewall-ban '1.2.3.4' 'ALL'
1449+
assert_success
1450+
refute_output
1451+
check_ip_not_banned '1.2.3.4' 'HESTIA'
1452+
}
1453+
1454+
@test "Test Whitelist Fail2ban" {
1455+
1456+
echo "1.2.3.4" >> $HESTIA/data/firewall/excludes.conf
1457+
run v-add-firewall-ban '1.2.3.4' 'HESTIA'
1458+
rm $HESTIA/data/firewall/excludes.conf
1459+
check_ip_not_banned '1.2.3.4' 'HESTIA'
1460+
}
1461+
14001462
#----------------------------------------------------------#
14011463
# CLEANUP #
14021464
#----------------------------------------------------------#

0 commit comments

Comments
 (0)