mirror of
https://github.com/IgorKha/wireguard-mikrotik.git
synced 2025-08-07 11:44:26 +02:00
fix(#7): validation and ipv6 square brackets
- Input validation for both IPv6 and IPv4 is being performed. - IPv6 in the ENDPOINT section has been corrected.
This commit is contained in:
parent
325cfc3881
commit
76c374e9b3
1 changed files with 13 additions and 1 deletions
|
@ -106,7 +106,19 @@ function installQuestions() {
|
||||||
# Detect public IPv6 address
|
# Detect public IPv6 address
|
||||||
SERVER_PUB_IP=$(ip -6 addr | sed -ne 's|^.* inet6 \([^/]*\)/.* scope global.*$|\1|p' | head -1)
|
SERVER_PUB_IP=$(ip -6 addr | sed -ne 's|^.* inet6 \([^/]*\)/.* scope global.*$|\1|p' | head -1)
|
||||||
fi
|
fi
|
||||||
read -rp "IPv4 or IPv6 public address: " -e -i "${SERVER_PUB_IP}" SERVER_PUB_IP
|
|
||||||
|
while true; do
|
||||||
|
read -rp "Enter IPv4 or IPv6 public address: " -e -i "${SERVER_PUB_IP}" SERVER_PUB_IP
|
||||||
|
|
||||||
|
if [[ ${SERVER_PUB_IP} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
break
|
||||||
|
elif [[ ${SERVER_PUB_IP} =~ ^[0-9a-fA-F:]+:[0-9a-fA-F:]*$ ]]; then
|
||||||
|
SERVER_PUB_IP="[${SERVER_PUB_IP}]"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "Invalid IP address. Please enter a valid IPv4 or IPv6 address."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
until [[ ${SERVER_WG_IPV4} =~ ^([0-9]{1,3}\.){3} ]]; do
|
until [[ ${SERVER_WG_IPV4} =~ ^([0-9]{1,3}\.){3} ]]; do
|
||||||
read -rp "Server's WireGuard IPv4: " -e -i 10."$(shuf -i 0-250 -n 1)"."$(shuf -i 0-250 -n 1)".1 SERVER_WG_IPV4
|
read -rp "Server's WireGuard IPv4: " -e -i 10."$(shuf -i 0-250 -n 1)"."$(shuf -i 0-250 -n 1)".1 SERVER_WG_IPV4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue