aboutsummaryrefslogtreecommitdiff
path: root/templates/manage_wg_peers.sh.j2
diff options
context:
space:
mode:
Diffstat (limited to 'templates/manage_wg_peers.sh.j2')
-rw-r--r--templates/manage_wg_peers.sh.j217
1 files changed, 9 insertions, 8 deletions
diff --git a/templates/manage_wg_peers.sh.j2 b/templates/manage_wg_peers.sh.j2
index ed2f800..fd27370 100644
--- a/templates/manage_wg_peers.sh.j2
+++ b/templates/manage_wg_peers.sh.j2
@@ -1,11 +1,12 @@
#!/bin/bash
set -e
-WG_SERVER_HOME="{{ wireguard_server_home }}"
-WG_PEERS_HOME="${WG_SERVER_HOME}/peers.d"
-IP_FILE="${WG_SERVER_HOME}/ips.txt"
-SUBNET_PREFIX="{{ wireguard_subnet_prefix }}"
-DEFAULT_PORT="{{ wireguard_port }}"
+WG_SERVER_HOME="{{ wg_server_home }}"
+WG_PEERS_HOME="{{ wg_peers_home }}"
+IP_FILE="{{ wg_ip_file }}"
+WIREGUARD_SUBNET_PREFIX="{{ wg_subnet_prefix }}"
+NAT_SUBNET="{{ nat_subnet }}"
+DEFAULT_PORT="{{ wg_port }}"
DEFAULT_DNS="8.8.8.8"
test "${EUID}" -ne 0 && printf "%s\n" "run as root" && exit 1
@@ -62,14 +63,14 @@ function get_next_available_ip() {
flock -x 200
touch "${IP_FILE}"
for i in {2..254}; do
- ip="${SUBNET_PREFIX}.${i}"
+ ip="${WIREGUARD_SUBNET_PREFIX}.${i}"
if ! grep -q "${ip}" "${IP_FILE}"; then
printf "%s\n" "${ip}"
printf "%s\n" "${ip}" >> "${IP_FILE}"
exit 0
fi
done
- printf "%s\n" "[err] no available ips in range ${SUBNET_PREFIX}.2 - ${SUBNET_PREFIX}.254"
+ printf "%s\n" "[err] no available ips in range ${WIREGUARD_SUBNET_PREFIX}.2 - ${WIREGUARD_SUBNET_PREFIX}.254"
exit 1
) 200>"${IP_FILE}.lock"
}
@@ -102,7 +103,7 @@ DNS = ${dns}
PublicKey = $(wg pubkey < "${WG_SERVER_HOME}/server.key")
PresharedKey = $(cat "${WG_SERVER_HOME}/psk.key")
Endpoint = ${server}:${port}
-AllowedIPs = 0.0.0.0/0
+AllowedIPs = ${WIREGUARD_SUBNET_PREFIX}.0/24, ${NAT_SUBNET}
PersistentKeepalive = 25
EOF
printf "%s\n" \