diff options
Diffstat (limited to 'package/network/services/openvpn/files')
-rw-r--r-- | package/network/services/openvpn/files/etc/hotplug.d/openvpn/01-user | 15 | ||||
-rw-r--r-- | package/network/services/openvpn/files/lib/functions/openvpn.sh | 16 |
2 files changed, 18 insertions, 13 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 index 6d45f0b7c6..86be69e805 100644 --- a/package/network/services/openvpn/files/etc/hotplug.d/openvpn/01-user +++ b/package/network/services/openvpn/files/etc/hotplug.d/openvpn/01-user @@ -1,17 +1,6 @@ #!/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 -} +. /lib/functions/openvpn.sh [ -e "/etc/openvpn.user" ] && { env -i ACTION="$ACTION" INSTANCE="$INSTANCE" \ @@ -23,7 +12,7 @@ get_option() { # Wrap user defined scripts on up/down events case "$ACTION" in up|down) - if get_option command "$ACTION"; then + if get_openvpn_option "$config" command "$ACTION"; then exec /bin/sh -c "$command $ACTION $INSTANCE $*" fi ;; diff --git a/package/network/services/openvpn/files/lib/functions/openvpn.sh b/package/network/services/openvpn/files/lib/functions/openvpn.sh new file mode 100644 index 0000000000..83fb1bb453 --- /dev/null +++ b/package/network/services/openvpn/files/lib/functions/openvpn.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +get_openvpn_option() { + local config="$1" + local variable="$2" + local option="$3" + + 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 +} + |