From d096dee06b36a80a8771b783d806ee4c85c6ccf5 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 27 Aug 2019 20:27:19 +0200 Subject: [PATCH] :sparkles: Makes CIDR notation of addresses optional, defaults to /24 --- wireguard/config.json | 4 ++-- wireguard/rootfs/etc/cont-init.d/config.sh | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/wireguard/config.json b/wireguard/config.json index 5d6d529..61c7aea 100755 --- a/wireguard/config.json +++ b/wireguard/config.json @@ -32,7 +32,7 @@ "server": { "host": "hassio.local", "addresses": [ - "172.244.66.2/24" + "172.244.66.1" ], "dns": [] }, @@ -40,7 +40,7 @@ { "name": "hassio", "addresses": [ - "172.244.66.3/24" + "172.244.66.2" ], "allowed_ips": [] } diff --git a/wireguard/rootfs/etc/cont-init.d/config.sh b/wireguard/rootfs/etc/cont-init.d/config.sh index b87f5d7..51a46b8 100644 --- a/wireguard/rootfs/etc/cont-init.d/config.sh +++ b/wireguard/rootfs/etc/cont-init.d/config.sh @@ -4,6 +4,7 @@ # Creates the interface configuration # ============================================================================== readonly CONFIG="/etc/wireguard/wg0.conf" +declare -a list declare addresses declare allowed_ips declare config_dir @@ -13,11 +14,11 @@ declare host declare keep_alive declare name declare port +declare post_down +declare post_up declare pre_shared_key declare private_key declare public_key -declare post_up -declare post_down if ! bashio::fs.directory_exists '/ssl/wireguard'; then mkdir -p /ssl/wireguard || @@ -33,6 +34,7 @@ fi # Add all server addresses to the configuration for address in $(bashio::config 'server.addresses'); do + [[ "${address}" == *"/"* ]] || address="${address}/24" echo "Address = ${address}" >> "${CONFIG}" done @@ -138,7 +140,13 @@ for peer in $(bashio::config 'peers|keys'); do echo "PublicKey = ${public_key}" >> "${CONFIG}" # Addresses in peer configuration become AllowedIPS from server side. - allowed_ips=$(bashio::config "peers[${peer}].addresses | join(\", \")") + list=() + for address in $(bashio::config "peers[${peer}].addresses"); do + [[ "${address}" == *"/"* ]] || address="${address}/24" + list+=("${address}") + done + allowed_ips=$(IFS=", "; echo "${list[*]}") + echo "AllowedIPs = ${allowed_ips}" >> "${CONFIG}" if bashio::config.has_value "peers[${peer}].persistent_keep_alive"; then