-
Notifications
You must be signed in to change notification settings - Fork 8
/
fw-redirect.sh
33 lines (28 loc) · 867 Bytes
/
fw-redirect.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
#!/bin/sh
#
# OpenWrt script to enabled/disabled Firewall - Port Forwards
# ~/fw-redirect.sh Allow-http=off Allow-NAS-http=on
#
for V in "$@"; do
name=$(echo $V | awk -F= '{print $1}')
value=$(echo $V | awk -F= '{print $2}')
# firewall.@redirect[1].name='Allow-http'
# firewall.@redirect[1].enabled='1'
L=$(uci show firewall | grep @redirect | grep ".name='$name'")
if [ -n "$L" ]; then
I=$(echo "$L" | awk -F'[][]' '{print $2}')
# echo "* firewall.@redirect[$I].name='$name'"
if [ "$value" == "on" ]; then
# echo "* firewall.@redirect[$I].enabled='1'"
uci -q del firewall.@redirect[$I].enabled
else
# echo "* firewall.@redirect[$I].enabled='0'"
uci set firewall.@redirect[$I].enabled='0'
fi
fi
done
#echo "* uci commit firewall"
uci commit firewall
#echo "* reload firewall"
fw3 -q reload
exit 0