-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathntios_wln_ipv46forwardingfunc.sh
executable file
·82 lines (70 loc) · 3.18 KB
/
ntios_wln_ipv46forwardingfunc.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
#---FUNCTIONS
WLN_Ipv46_Forwarding_Enable() {
#Define constants
local PHASE_IPV46FORWARDINGFUNC_IPV4_FORWARDING_ENABLE=1
local PHASE_IPV46FORWARDINGFUNC_IPV6_FORWARDING_ENABLE=2
local PHASE_IPV46FORWARDINGFUNC_SYSCTL_EXEC=3
local PHASE_IPV46FORWARDINGFUNC_EXIT=4
#Define variables
local phase="${PHASE_IPV46FORWARDINGFUNC_IPV4_FORWARDING_ENABLE}"
local cmd=${WLN_EMPTYSTRING}
local ret="${REJECTED}"
#Start phase
while true
do
case "${phase}" in
"${PHASE_IPV46FORWARDINGFUNC_IPV4_FORWARDING_ENABLE}")
#Enable ipv4- and ipv6-forwarding
if [[ $(IpIsForwarded "${WLN_PATTERN_NET_IPV4_IP_FORWARD_ENABLED}") == false ]]; then
#Remove leading hash (#)
sudo sed -i "s/^#${WLN_PATTERN_NET_IPV4_IP_FORWARD_ENABLED}/${WLN_PATTERN_NET_IPV4_IP_FORWARD_ENABLED}/g" ${WLN_SYSCTL_CONF_FPATH}
#Print
echo -e "${WLN_PRINTMSG_STATUS}: ${WLN_LIGHTGREY}Forwarding IPv4${WLN_RESETCOLOR}: ${WLN_PRINTMSG_DONE}"
#Double-check if remove was successful
if [[ $(IpIsForwarded "${WLN_PATTERN_NET_IPV4_IP_FORWARD_ENABLED}") == false ]]; then
ret="${REJECTED}"
phase="${PHASE_IPV46FORWARDINGFUNC_EXIT}"
else
phase="${PHASE_IPV46FORWARDINGFUNC_IPV6_FORWARDING_ENABLE}"
fi
else
phase="${PHASE_IPV46FORWARDINGFUNC_IPV6_FORWARDING_ENABLE}"
fi
;;
"${PHASE_IPV46FORWARDINGFUNC_IPV6_FORWARDING_ENABLE}")
if [[ $(IpIsForwarded "${WLN_PATTERN_NET_IPV6_CONF_ALL_FORWARDING_ENABLED}") == false ]]; then
sudo sed -i "s/^#${WLN_PATTERN_NET_IPV6_CONF_ALL_FORWARDING_ENABLED}/${WLN_PATTERN_NET_IPV6_CONF_ALL_FORWARDING_ENABLED}/g" ${WLN_SYSCTL_CONF_FPATH}
#Print
echo -e "${WLN_PRINTMSG_STATUS}: ${WLN_LIGHTGREY}Forwarding IPv6${WLN_RESETCOLOR}: ${WLN_PRINTMSG_DONE}"
#Double-check if remove was successful
if [[ $(IpIsForwarded "${WLN_PATTERN_NET_IPV4_IP_FORWARD_ENABLED}") == false ]]; then
ret="${REJECTED}"
phase="${PHASE_IPV46FORWARDINGFUNC_EXIT}"
else
phase="${PHASE_IPV46FORWARDINGFUNC_SYSCTL_EXEC}"
fi
else
phase="${PHASE_IPV46FORWARDINGFUNC_SYSCTL_EXEC}"
fi
;;
"${PHASE_IPV46FORWARDINGFUNC_SYSCTL_EXEC}")
#Set command
cmd="${WLN_SYSCTL_P}"
#Execute command
if [[ $(CmdExec "${cmd}" "false") == false ]]; then
ret="${REJECTED}"
else
ret="${ACCEPTED}"
fi
phase="${PHASE_IPV46FORWARDINGFUNC_EXIT}"
;;
"${PHASE_IPV46FORWARDINGFUNC_EXIT}")
break
;;
esac
done
#Output
echo "${ret}"
return 0;
}