Skip to content

Commit d2bb4c4

Browse files
asmccroot
andauthored
Add IPV4 regex to func/ip.sh for best robustness against wrong and IPV6 addresses (hestiacp#3290)
Co-authored-by: root <root@test.hestiacp.com>
1 parent 8763d7e commit d2bb4c4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

func/ip.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# #
77
#===========================================================================#
88

9+
# Global definitions
10+
REGEX_IPV4="^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}$"
11+
912
# Check ip ownership
1013
is_ip_owner() {
1114
owner=$(grep 'OWNER=' $HESTIA/data/ips/$ip | cut -f 2 -d \')
@@ -224,9 +227,9 @@ get_broadcast() {
224227
# Get user ips
225228
get_user_ips() {
226229
dedicated=$(grep -H "OWNER='$user'" $HESTIA/data/ips/*)
227-
dedicated=$(echo "$dedicated" | cut -f 1 -d : | sed 's=.*/==')
230+
dedicated=$(echo "$dedicated" | cut -f 1 -d : | sed 's=.*/==' | grep -E ${REGEX_IPV4})
228231
shared=$(grep -H -A1 "OWNER='admin'" $HESTIA/data/ips/* | grep shared)
229-
shared=$(echo "$shared" | cut -f 1 -d : | sed 's=.*/==' | cut -f 1 -d \-)
232+
shared=$(echo "$shared" | cut -f 1 -d : | sed 's=.*/==' | cut -f 1 -d \- | grep -E ${REGEX_IPV4})
230233
for dedicated_ip in $dedicated; do
231234
shared=$(echo "$shared" | grep -v $dedicated_ip)
232235
done

0 commit comments

Comments
 (0)