mirror of
https://github.com/hassio-addons/addon-wireguard.git
synced 2025-05-05 03:11:22 +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": {
|
"server": {
|
||||||
"host": "hassio.local",
|
"host": "hassio.local",
|
||||||
"addresses": [
|
"addresses": [
|
||||||
"172.244.66.2/24"
|
"172.244.66.1"
|
||||||
],
|
],
|
||||||
"dns": []
|
"dns": []
|
||||||
},
|
},
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
{
|
{
|
||||||
"name": "hassio",
|
"name": "hassio",
|
||||||
"addresses": [
|
"addresses": [
|
||||||
"172.244.66.3/24"
|
"172.244.66.2"
|
||||||
],
|
],
|
||||||
"allowed_ips": []
|
"allowed_ips": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
# Creates the interface configuration
|
# Creates the interface configuration
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
readonly CONFIG="/etc/wireguard/wg0.conf"
|
readonly CONFIG="/etc/wireguard/wg0.conf"
|
||||||
|
declare -a list
|
||||||
declare addresses
|
declare addresses
|
||||||
declare allowed_ips
|
declare allowed_ips
|
||||||
declare config_dir
|
declare config_dir
|
||||||
|
@ -13,11 +14,11 @@ declare host
|
||||||
declare keep_alive
|
declare keep_alive
|
||||||
declare name
|
declare name
|
||||||
declare port
|
declare port
|
||||||
|
declare post_down
|
||||||
|
declare post_up
|
||||||
declare pre_shared_key
|
declare pre_shared_key
|
||||||
declare private_key
|
declare private_key
|
||||||
declare public_key
|
declare public_key
|
||||||
declare post_up
|
|
||||||
declare post_down
|
|
||||||
|
|
||||||
if ! bashio::fs.directory_exists '/ssl/wireguard'; then
|
if ! bashio::fs.directory_exists '/ssl/wireguard'; then
|
||||||
mkdir -p /ssl/wireguard ||
|
mkdir -p /ssl/wireguard ||
|
||||||
|
@ -33,6 +34,7 @@ fi
|
||||||
|
|
||||||
# Add all server addresses to the configuration
|
# Add all server addresses to the configuration
|
||||||
for address in $(bashio::config 'server.addresses'); do
|
for address in $(bashio::config 'server.addresses'); do
|
||||||
|
[[ "${address}" == *"/"* ]] || address="${address}/24"
|
||||||
echo "Address = ${address}" >> "${CONFIG}"
|
echo "Address = ${address}" >> "${CONFIG}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -138,7 +140,13 @@ for peer in $(bashio::config 'peers|keys'); do
|
||||||
echo "PublicKey = ${public_key}" >> "${CONFIG}"
|
echo "PublicKey = ${public_key}" >> "${CONFIG}"
|
||||||
|
|
||||||
# Addresses in peer configuration become AllowedIPS from server side.
|
# 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}"
|
echo "AllowedIPs = ${allowed_ips}" >> "${CONFIG}"
|
||||||
|
|
||||||
if bashio::config.has_value "peers[${peer}].persistent_keep_alive"; then
|
if bashio::config.has_value "peers[${peer}].persistent_keep_alive"; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue