PKG_NAME:=openvpn
PKG_VERSION:=2.4.9
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_SOURCE_URL:=\
https://build.openvpn.net/downloads/releases/ \
define Package/openvpn-$(BUILD_VARIANT)/conffiles
/etc/config/openvpn
+/etc/openvpn.user
endef
define Package/openvpn-$(BUILD_VARIANT)/install
$(1)/etc/init.d \
$(1)/etc/config \
$(1)/etc/openvpn \
- $(1)/lib/upgrade/keep.d
+ $(1)/lib/upgrade/keep.d \
+ $(1)/usr/libexec \
+ $(1)/etc/hotplug.d/openvpn
$(INSTALL_BIN) \
$(PKG_INSTALL_DIR)/usr/sbin/openvpn \
$(INSTALL_BIN) \
files/openvpn.init \
$(1)/etc/init.d/openvpn
+
+ $(INSTALL_BIN) \
+ files/usr/libexec/openvpn-hotplug \
+ $(1)/usr/libexec/openvpn-hotplug
+
+ $(INSTALL_DATA) \
+ files/etc/hotplug.d/openvpn/01-user \
+ $(1)/etc/hotplug.d/openvpn/01-user
+
+ $(INSTALL_DATA) \
+ files/etc/openvpn.user \
+ $(1)/etc/openvpn.user
+
$(INSTALL_DATA) \
files/openvpn.options \
$(1)/usr/share/openvpn/openvpn.options
--- /dev/null
+#!/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
--- /dev/null
+#!/bin/sh
+#
+# This file is interpreted as shell script.
+# Put your custom openvpn action here, they will
+# be executed with each opevnp event.
+#
+# $ACTION
+# <down> down action is generated after the TUN/TAP device is closed
+# <up> up action is generated after the TUN/TAP device is opened
+# $INSTANCE Name of the openvpn instance which went up or down
+
local name="$1"
local dir="$2"
local conf="$3"
+ local security="$4"
procd_open_instance "$name"
procd_set_param command "$PROG" \
--syslog "openvpn($name)" \
--status "/var/run/openvpn.$name.status" \
--cd "$dir" \
- --config "$conf"
+ --config "$conf" \
+ --up "/usr/libexec/openvpn-hotplug up $name" \
+ --down "/usr/libexec/openvpn-hotplug down $name" \
+ --script-security "${security:-2}"
procd_set_param file "$dir/$conf"
procd_set_param term_timeout 15
procd_set_param respawn
return 1
}
+ local script_security
+ config_get script_security "$s" script_security
+
[ ! -d "/var/run" ] && mkdir -p "/var/run"
if [ ! -z "$config" ]; then
append UCI_STARTED "$config" "$LIST_SEP"
- openvpn_add_instance "$s" "${config%/*}" "$config"
+ openvpn_add_instance "$s" "${config%/*}" "$config" "$script_security"
return
fi
append_params "$s" $OPENVPN_PARAMS
append_list "$s" $OPENVPN_LIST
- openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf"
+ openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf" "$script_security"
}
start_service() {
dev_node
dev_type
dh
-down
ecdh_curve
echo
engine
route_pre_down
route_up
rport
-script_security
secret
server
server_bridge
tun_mtu
tun_mtu_extra
txqueuelen
-up
user
verb
verify_client_cert
--- /dev/null
+#!/bin/sh
+
+ACTION=$1
+shift
+INSTANCE=$1
+shift
+
+export ACTION=$ACTION
+export INSTANCE=$INSTANCE
+exec /sbin/hotplug-call openvpn "$@"