🔨 Default value handling for allowed_ips and DNS

This commit is contained in:
Franck Nijhof 2019-08-27 13:09:18 +02:00
parent 36e48fec7f
commit 907089110e
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 30 additions and 16 deletions

View file

@ -32,23 +32,17 @@
"server": { "server": {
"host": "hassio.local", "host": "hassio.local",
"addresses": [ "addresses": [
"10.200.100.8/24", "172.244.66.2/24"
"10.10.0.1/16"
], ],
"dns": [ "dns": []
"1.1.1.1",
"9.9.9.9"
]
}, },
"peers": [ "peers": [
{ {
"name": "", "name": "hassio",
"addresses": [ "addresses": [
"10.200.100.9/24" "172.244.66.3/24"
], ],
"allowed_ips": [ "allowed_ips": []
"0.0.0.0/0"
]
} }
] ]
}, },

View file

@ -37,9 +37,14 @@ for address in $(bashio::config 'server.addresses'); do
done done
# Add all server DNS addresses to the configuration # Add all server DNS addresses to the configuration
for dns in $(bashio::config 'server.dns'); do if bashio::config.has_value 'server.dns'; then
echo "DNS = ${dns}" >> "${CONFIG}" for dns in $(bashio::config 'server.dns'); do
done echo "DNS = ${dns}" >> "${CONFIG}"
done
else
dns=$(bashio::dns.host)
echo "DNS = ${dns}" >> ${CONFIG}
fi
# Add the server's private key to the configuration # Add the server's private key to the configuration
if bashio::config.has_value 'server.private_key'; then if bashio::config.has_value 'server.private_key'; then
@ -100,6 +105,11 @@ fi
# Fetch all the peers # Fetch all the peers
for peer in $(bashio::config 'peers|keys'); do for peer in $(bashio::config 'peers|keys'); do
# Check if at least 1 address is specified
if ! bashio::config.has_value "peers[${peer}].addresses"; then
bashio::exit.nok "You need at least 1 address configured for ${name}"
fi
name=$(bashio::config "peers[${peer}].name") name=$(bashio::config "peers[${peer}].name")
config_dir="/ssl/wireguard/${name}" config_dir="/ssl/wireguard/${name}"
@ -157,12 +167,22 @@ for peer in $(bashio::config 'peers|keys'); do
echo "PrivateKey = ${private_key}" >> "${config_dir}/client.conf" echo "PrivateKey = ${private_key}" >> "${config_dir}/client.conf"
fi fi
if bashio::config.has_value 'server.dns'; then
dns=$(bashio::config "server.dns | join(\", \")")
else
dns=$(bashio::dns.host)
fi
if bashio::config.has_value "peers[${peer}].allowed_ips"; then
allowed_ips=$(bashio::config "peers[${peer}].allowed_ips | join(\", \")")
else
allowed_ips="0.0.0.0/0"
fi
addresses=$(bashio::config "peers[${peer}].addresses | join(\", \")") addresses=$(bashio::config "peers[${peer}].addresses | join(\", \")")
dns=$(bashio::config "server.dns | join(\", \")")
public_key=$(wg pubkey < /ssl/wireguard/private_key) public_key=$(wg pubkey < /ssl/wireguard/private_key)
host=$(bashio::config 'server.host') host=$(bashio::config 'server.host')
port=$(bashio::addon.port "51820/udp") port=$(bashio::addon.port "51820/udp")
allowed_ips=$(bashio::config "peers[${peer}].allowed_ips | join(\", \")")
{ {
echo "Address = ${addresses}" echo "Address = ${addresses}"