diff --git a/net/wg-installer/common/wg.sh b/net/wg-installer/common/wg.sh index 60bc7109a..b4f884dce 100644 --- a/net/wg-installer/common/wg.sh +++ b/net/wg-installer/common/wg.sh @@ -20,6 +20,8 @@ cleanup_wginterfaces() { delete_wg_interface() { ip link del dev "$1" + [ -f "/tmp/run/wgserver/$1.key" ] && rm "/tmp/run/wgserver/$1.key" + [ -f "/tmp/run/wgserver/$1.pub" ] && rm "/tmp/run/wgserver/$1.pub" } check_wg_neighbors() { diff --git a/net/wg-installer/wg-server/config/wgserver.conf b/net/wg-installer/wg-server/config/wgserver.conf index 638ac19d8..41cafa288 100644 --- a/net/wg-installer/wg-server/config/wgserver.conf +++ b/net/wg-installer/wg-server/config/wgserver.conf @@ -5,4 +5,5 @@ config server option base_v4prefix '10.0.0.1/24' option wg_key '/root/wg.key' option wg_pub '/root/wg.pub' + option wg_tmp_key '1' option timeout_handshake '600' diff --git a/net/wg-installer/wg-server/lib/wg_functions.sh b/net/wg-installer/wg-server/lib/wg_functions.sh index e431eca98..845bfb729 100644 --- a/net/wg-installer/wg-server/lib/wg_functions.sh +++ b/net/wg-installer/wg-server/lib/wg_functions.sh @@ -53,6 +53,13 @@ wg_register () { gw_key=$(uci get wgserver.@server[0].wg_key) gw_pub=$(uci get wgserver.@server[0].wg_pub) + + if [ $(uci get wgserver.@server[0].wg_tmp_key) -eq 1]; then + [ -d "/tmp/run/wgserver" ] || mkdir -p /tmp/run/wgserver + gw_key="/tmp/run/wgserver/${ifname}.key" + gw_pub="/tmp/run/wgserver/${ifname}.pub" + wg genkey | tee $gw_key | wg pubkey > $gw_pub + fi wg_server_pubkey=$(cat $gw_pub) # create wg tunnel