openvpn: fix arguments passing to wrapped up and down scripts
[openwrt/staging/zorun.git] / package / network / services / openvpn / files / etc / hotplug.d / openvpn / 01-user
index 6d45f0b7c69059a220db2e6d791f50be70f6eb32..f93823e5c55559be61352b096995b9a828e45fdd 100644 (file)
@@ -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,8 +12,9 @@ get_option() {
 # 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 $*"
+               if get_openvpn_option "$config" command "$ACTION"; then
+                       shift
+                       exec /bin/sh -c "$command $*"
                fi
        ;;
 esac