-
Notifications
You must be signed in to change notification settings - Fork 12
/
x3mRouting_client_nvram.sh
66 lines (56 loc) · 2.53 KB
/
x3mRouting_client_nvram.sh
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
#!/bin/sh
####################################################################################################
# Script: x3mRouting_rules.sh
# VERSION=2.0.0
# Author: Xentrk
# Date: 5-August-2020
#
#####################################################################################################
# Description:
# Create nvram LAN client files based on the routing configuration defined in the file
# /jffs/configs/x3mRouting_lan_client_rules
#
#####################################################################################################
Cleanup_OLD_LAN_Client_Routes() {
for VPN_ID in 1 2 3 4 5; do
[ -f "$ADDONS_DIR/ovpnc${VPN_ID}.nvram" ] && rm -rf "$ADDONS_DIR/ovpnc${VPN_ID}.nvram"
done
}
Create_LAN_Client_Routes() {
CONFIG_FILE="/jffs/scripts/x3mRouting/x3mRouting_client_rules"
OLDIFS="$IFS"
IFS=" "
DEST="0.0.0.0"
VPN="VPN"
RECORD_BEGIN="<"
FIELD_SEPARATOR=">"
[ ! -s "$CONFIG_FILE" ] && echo "No $CONFIG_FILE found to process" | exit 1
while IFS=" " read -r OVPNC IP DESCRIPTION; do
if [ "$(echo "$OVPNC" | cut -c 1)" != "#" ]; then
if [ "$OVPNC" -ge "0" ]; then
case "$OVPNC" in
1) printf '%s%s%s%s%s%s%s%s\n' "$RECORD_BEGIN" "$DESCRIPTION" "$FIELD_SEPARATOR" "$IP" "$FIELD_SEPARATOR" "$DEST" "$FIELD_SEPARATOR" "$VPN" >>/tmp/ovpnc1.$$ ;;
2) printf '%s%s%s%s%s%s%s%s\n' "$RECORD_BEGIN" "$DESCRIPTION" "$FIELD_SEPARATOR" "$IP" "$FIELD_SEPARATOR" "$DEST" "$FIELD_SEPARATOR" "$VPN" >>/tmp/ovpnc2.$$ ;;
3) printf '%s%s%s%s%s%s%s%s\n' "$RECORD_BEGIN" "$DESCRIPTION" "$FIELD_SEPARATOR" "$IP" "$FIELD_SEPARATOR" "$DEST" "$FIELD_SEPARATOR" "$VPN" >>/tmp/ovpnc3.$$ ;;
4) printf '%s%s%s%s%s%s%s%s\n' "$RECORD_BEGIN" "$DESCRIPTION" "$FIELD_SEPARATOR" "$IP" "$FIELD_SEPARATOR" "$DEST" "$FIELD_SEPARATOR" "$VPN" >>/tmp/ovpnc4.$$ ;;
5) printf '%s%s%s%s%s%s%s%s\n' "$RECORD_BEGIN" "$DESCRIPTION" "$FIELD_SEPARATOR" "$IP" "$FIELD_SEPARATOR" "$DEST" "$FIELD_SEPARATOR" "$VPN" >>/tmp/ovpnc5.$$ ;;
esac
fi
fi
done <"$CONFIG_FILE"
IFS=$OLDIFS
for VPN_ID in 1 2 3 4 5; do
if [ -s "/tmp/ovpnc${VPN_ID}.$$" ]; then
awk '{ print }' ORS='' <"/tmp/ovpnc${VPN_ID}.$$" >"$ADDONS_DIR/ovpnc${VPN_ID}.nvram"
echo "Created nvram file for OpenVPN Client $VPN_ID" && echo "Restarting OpenVPN Client $VPN_ID to apply assignments"
service restart_vpnclient${VPN_ID}
rm /tmp/ovpnc${VPN_ID}.$$
fi
done
}
# End of functions
# Begin
ADDONS_DIR=/jffs/addons/x3mRouting
Cleanup_OLD_LAN_Client_Routes
Create_LAN_Client_Routes
echo "Script completed"