Fixes #11441
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
assert [ $# -eq 1 ]
local peer=${1}
- # TODO Accept also FQDNs
+ # IP addresses are accepted
if ip_is_valid ${peer}; then
return ${EXIT_TRUE}
- else
- return ${EXIT_FALSE}
fi
+
+ # FQDNs are okay, too
+ if fqdn_is_valid "${peer}"; then
+ return ${EXIT_TRUE}
+ fi
+
+ # We cannot use anything else
+ return ${EXIT_FALSE}
}
# This function checks if a VPN IPsec connection name is valid
[[ ${mac} =~ ^([0-9a-f]{2}\:){5}[0-9a-f]{2}$ ]]
}
+# Converts the given string to lowercase and returns true if it is a valid FQDN
+fqdn_is_valid() {
+ local fqdn="${1}"
+
+ if grep -qP "^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$" <<< "${fqdn,,}"; then
+ return ${EXIT_TRUE}
+ fi
+
+ return ${EXIT_FALSE}
+}
+
uuid() {
echo $(</proc/sys/kernel/random/uuid)
}