mirror of
https://git.openwrt.org/openwrt/openwrt.git
synced 2024-06-13 10:49:13 +02:00
8fe9940db6
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>
33 lines
839 B
Bash
33 lines
839 B
Bash
#!/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
|