-
Notifications
You must be signed in to change notification settings - Fork 12
/
openvpn-event
79 lines (72 loc) · 2.46 KB
/
openvpn-event
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
###########################################################################################################
# Script: openvpn-event
# VERSION=2.0.0
# Author: John9527, Martineau, Xentrk
# Last Updated Date: 29-August-2020
#
# Description:
# Original Script by John9527:
# https://www.snbforums.com/threads/fork-asuswrt-merlin-374-43-lts-releases-v39e3.18914/page-238#post-294825
#
# Updated Script by John9527
# https://www.snbforums.com/threads/solved-protocol-based-vpn-port-5060-blocked.41585/page-2#post-352772
#
# Implemented additional patches suggested by Martineau
# https://www.snbforums.com/threads/solved-protocol-based-vpn-port-5060-blocked.41585/page-2#post-352834
# https://www.snbforums.com/threads/x3mrouting-selective-routing-for-asuswrt-merlin-firmware.57793/page-7#post-520433
#
# Modified by Xentrk for x3mRouting project
############################################################################################################
# shellcheck disable=SC2154
PROJECT_REPO="/jffs/scripts/x3mRouting"
scr_name="$(basename "$0")[$$]"
#Determine Caller
case "$1" in
"tun11")
vpn_name="client1"
;;
"tun12")
vpn_name="client2"
;;
"tun13")
vpn_name="client3"
;;
"tun14")
vpn_name="client4"
;;
"tun15")
vpn_name="client5"
;;
"tun21")
vpn_name="server1"
;;
"tun22")
vpn_name="server2"
;;
*)
vpn_name=""
;;
esac
# Call appropriate script based on script_type
vpn_script_name="vpn$vpn_name-$script_type"
vpn_script_log="/tmp/vpn${vpn_name}_state"
VPN_UNIT=$(echo "$dev" | awk '{ string=substr($0, 5, 5); print string; }')
[ -s /jffs/addons/x3mRouting/updown-dns.sh ] && sh /jffs/addons/x3mRouting/updown-dns.sh "$VPN_UNIT" "$script_type"
[ -s /jffs/addons/x3mRouting/x3mvpnrouting.sh ] && sh /jffs/addons/x3mRouting/x3mvpnrouting.sh "$VPN_UNIT" "$script_type"
# Check script state
vpn_script_state=$(cat $vpn_script_log 2>/dev/null)
if [ "$vpn_script_name" = "$vpn_script_state" ]; then
echo "VPN script $vpn_script_name already run" | logger -t "$scr_name"
exit 0
fi
# Execute and log script state
if [ -f "$PROJECT_REPO/$vpn_script_name" ]; then
echo "$vpn_script_name" >"$vpn_script_log"
sh "$PROJECT_REPO/$vpn_script_name" "$*" && logger -t "$scr_name" "Running $PROJECT_REPO/$vpn_script_name $*"
else
logger -t "$scr_name" "No scripts found to run for openvpn-event: $vpn_script_name"
echo "${vpn_script_name}-NOSCRIPT" >"$vpn_script_log" # (or nvram set vpn_script_state="${vpn_script_name}-NOSCRIPT"")
exit 0
fi
exit 0