Skip to content

Commit d1b00bb

Browse files
jvandenbroekjuanluisbaptiste
authored andcommitted
Add IPv6 support
1 parent ceab477 commit d1b00bb

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

run.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ if [ "${SMTP_PORT}" = "465" ]; then
4949
add_config_value "smtp_tls_security_level" "encrypt"
5050
fi
5151

52+
# Bind to both IPv4 and IPv4
53+
add_config_value "inet_protocols" "all"
54+
5255
# Create sasl_passwd file with auth credentials
5356
if [ ! -f /etc/postfix/sasl_passwd -a ! -z "${SMTP_USERNAME}" ]; then
5457
grep -q "${SMTP_SERVER}" /etc/postfix/sasl_passwd > /dev/null 2>&1
@@ -76,13 +79,25 @@ fi
7679
#Check for subnet restrictions
7780
nets='10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16'
7881
if [ ! -z "${SMTP_NETWORKS}" ]; then
79-
for i in $(sed 's/,/\ /g' <<<$SMTP_NETWORKS); do
80-
if grep -Eq "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}" <<<$i ; then
81-
nets+=", $i"
82-
else
83-
echo "$i is not in proper IPv4 subnet format. Ignoring."
84-
fi
85-
done
82+
declare ipv6re="^((([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|\
83+
([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|\
84+
([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|\
85+
([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|\
86+
:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}|\
87+
::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|\
88+
(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|\
89+
(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[0-9]{1,3})$"
90+
91+
for i in $(sed 's/,/\ /g' <<<$SMTP_NETWORKS); do
92+
if grep -Eq "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}" <<<$i ; then
93+
nets+=", $i"
94+
elif grep -Eq "$ipv6re" <<<$i ; then
95+
readarray -d \/ -t arr < <(printf '%s' "$i")
96+
nets+=", [${arr[0]}]/${arr[1]}"
97+
else
98+
echo "$i is not in proper IPv4 or IPv6 subnet format. Ignoring."
99+
fi
100+
done
86101
fi
87102
add_config_value "mynetworks" "${nets}"
88103

0 commit comments

Comments
 (0)