aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/services/openvpn/files/etc/hotplug.d
diff options
context:
space:
mode:
authorFlorian Eckert <fe@dev.tdt.de>2018-11-30 14:03:50 +0100
committerJo-Philipp Wich <jo@mein.io>2020-06-17 22:43:48 +0200
commit8fe9940db66517679f09fa1d2f6f79229b6a8361 (patch)
tree4d58657e38d19f2ec01b7ff21524688deb62e3e0 /package/network/services/openvpn/files/etc/hotplug.d
parent9c16c46e58b9758a91ba68d8acea052a5375546f (diff)
downloadupstream-8fe9940db66517679f09fa1d2f6f79229b6a8361.tar.gz
upstream-8fe9940db66517679f09fa1d2f6f79229b6a8361.tar.bz2
upstream-8fe9940db66517679f09fa1d2f6f79229b6a8361.zip
openvpn: add generic hotplug mechanism
Pass a default --up and --down executable to each started OpenVPN instance which triggers /etc/hotplug.d/openvpn/ scripts whenever an instance goes up or down. User-configured up and down scripts are invoked by the default shipped 01-user hotplug handler to ensure that existing setups continue to work as before. As a consequence of this change, the up, down and script_security OpenVPN options are removed from the option file, since we're always passing them via the command line, they do not need to get included into the generated configuration. Signed-off-by: Florian Eckert <fe@dev.tdt.de> [reword commit message, move hotplug executable to /usr/libexec] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'package/network/services/openvpn/files/etc/hotplug.d')
-rw-r--r--package/network/services/openvpn/files/etc/hotplug.d/openvpn/01-user32
1 files changed, 32 insertions, 0 deletions
diff --git a/package/network/services/openvpn/files/etc/hotplug.d/openvpn/01-user b/package/network/services/openvpn/files/etc/hotplug.d/openvpn/01-user
new file mode 100644
index 0000000000..6d45f0b7c6
--- /dev/null
+++ b/package/network/services/openvpn/files/etc/hotplug.d/openvpn/01-user
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+get_option() {
+ local variable="$1"
+ local option="$2"
+
+ local value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+(([^ \t\\]|\\.)+)[ \t]*$/\1/p' "$config" | tail -n1 | sed -re 's/\\(.)/\1/g')"
+ [ -n "$value" ] || value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+'"'([^']+)'"'[ \t]*$/\1/p' "$config" | tail -n1)"
+ [ -n "$value" ] || value="$(sed -rne 's/^[ \t]*'"$option"'[ \t]+"(([^"\\]|\\.)+)"[ \t]*$/\1/p' "$config" | tail -n1 | sed -re 's/\\(.)/\1/g')"
+ [ -n "$value" ] || return 1
+
+ export -n "$variable=$value"
+ return 0
+}
+
+[ -e "/etc/openvpn.user" ] && {
+ env -i ACTION="$ACTION" INSTANCE="$INSTANCE" \
+ /bin/sh \
+ /etc/openvpn.user \
+ $*
+}
+
+# Wrap user defined scripts on up/down events
+case "$ACTION" in
+ up|down)
+ if get_option command "$ACTION"; then
+ exec /bin/sh -c "$command $ACTION $INSTANCE $*"
+ fi
+ ;;
+esac
+
+exit 0