aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Hainke <vincent@systemli.org>2021-03-13 20:55:02 +0100
committerPolynomdivision <vincent@systemli.org>2021-03-14 11:27:07 +0100
commit36dc9b3f797dd04d075d9b6c36fece68d03470fe (patch)
treef202a3deee1d8facda2b9f8dd6c5260405d9d569
parent17b18d825cc385fc2df0fa2f6a5e7775d778ef65 (diff)
wg-installer: delete old interfaces
Add "wg_check_interfaces" and specify a timeout in the config file. This allows to delete not used wireguard-interfaces automatically. For example a cronjob can be installed that calls: . /usr/share/wginstaller/wg_functions.sh && wg_check_interfaces Signed-off-by: Nick Hainke <vincent@systemli.org>
-rw-r--r--net/wg-installer/wg-server/config/wgserver.conf1
-rw-r--r--net/wg-installer/wg-server/lib/wg_functions.sh27
2 files changed, 28 insertions, 0 deletions
diff --git a/net/wg-installer/wg-server/config/wgserver.conf b/net/wg-installer/wg-server/config/wgserver.conf
index a88a8f94e..c68f0d0c0 100644
--- a/net/wg-installer/wg-server/config/wgserver.conf
+++ b/net/wg-installer/wg-server/config/wgserver.conf
@@ -4,3 +4,4 @@ config server
option base_prefix '2002::/64'
option wg_key '/root/wg.key'
option wg_pub '/root/wg.pub'
+ 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 65f94e5c2..2d38c60c9 100644
--- a/net/wg-installer/wg-server/lib/wg_functions.sh
+++ b/net/wg-installer/wg-server/lib/wg_functions.sh
@@ -1,6 +1,33 @@
. /usr/share/libubox/jshn.sh
. /usr/share/wginstaller/wg.sh
+wg_timeout () {
+ local int=$1
+
+ handshake=$(wg show $int latest-handshakes | awk '{print $2}')
+ timeout=$(uci get wgserver.@server[0].timeout_handshake)
+
+ if [ $handshake -ge $timeout ]; then
+ echo "1"
+ else
+ echo "0"
+ fi
+}
+
+wg_check_interface () {
+ local int=$1
+ if [ $(wg_timeout $int) -eq "1" ]; then
+ ip link del dev $int
+ fi
+}
+
+wg_check_interfaces () {
+ wg_interfaces=$(wg show interfaces)
+ for interface in $wg_interfaces; do
+ wg_check_interface $interface
+ done
+}
+
wg_get_usage () {
num_interfaces=$(wg show interfaces | wc -w)
json_init