mirror of
https://github.com/hassio-addons/addon-wireguard.git
synced 2025-05-04 19:01:31 +00:00
✨ Makes CIDR notation of addresses optional, defaults to /24
This commit is contained in:
parent
907089110e
commit
d096dee06b
2 changed files with 13 additions and 5 deletions
|
@ -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": []
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue