mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 16:44:23 +08:00
🍉 Sync 2026-04-27 08:33:04
This commit is contained in:
1 parent
576eeccfeb
commit
7ae30bfa80
1284 files changed
+652917
-268
No files matched your search
File renamed without changes.
+81
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2016 fw867 <ffkykzs@gmail.com>
|
||||
# Copyright (C) 2024 Lienol
|
||||
|
||||
START=99
|
||||
|
||||
CONFIG="luci-app-control-webrestriction"
|
||||
ipt="iptables -w"
|
||||
ip6t="ip6tables -w"
|
||||
|
||||
iptables_w(){
|
||||
$ipt 1 "$@"
|
||||
$ip6t 1 "$@"
|
||||
}
|
||||
|
||||
add_rule(){
|
||||
action=$1
|
||||
local items=$(uci show ${CONFIG} | grep "=macbind" | cut -d '.' -sf 2 | cut -d '=' -sf 1)
|
||||
for i in $items; do
|
||||
enable=$(uci -q get ${CONFIG}.${i}.enable)
|
||||
macaddr=$(uci -q get ${CONFIG}.${i}.macaddr)
|
||||
if [ -z $enable ] || [ -z $macaddr ]; then
|
||||
continue
|
||||
fi
|
||||
if [ "$enable" == "1" ]; then
|
||||
iptables_w -A WEB_RESTRICTION -m mac --mac-source $macaddr -j $action
|
||||
[ "$limit_type" == "blacklist" ] && {
|
||||
iptables_w -t nat -A WEB_RESTRICTION -m mac --mac-source $macaddr -j RETURN
|
||||
}
|
||||
fi
|
||||
unset enable macaddr
|
||||
done
|
||||
}
|
||||
|
||||
start(){
|
||||
stop
|
||||
ENABLED=$(uci -q get ${CONFIG}.@basic[0].enable || echo "0")
|
||||
[ "${ENABLED}" != "1" ] && exit 0
|
||||
limit_type=$(uci -q get ${CONFIG}.@basic[0].limit_type)
|
||||
|
||||
iptables_w -N WEB_RESTRICTION
|
||||
if [ "$limit_type" == "blacklist" ]; then
|
||||
iptables_w -t nat -N WEB_RESTRICTION
|
||||
add_rule DROP
|
||||
else
|
||||
add_rule ACCEPT
|
||||
iptables_w -A WEB_RESTRICTION -j DROP
|
||||
fi
|
||||
|
||||
FW3_INDEX_4=$($ipt -L FORWARD --line-numbers | tail -n +3 | grep -E ACCEPT | grep ctstate | grep fw3 | awk '{print $1}')
|
||||
[ -n "$FW3_INDEX_4" ] && let FW3_INDEX_4+=1
|
||||
$ipt -I FORWARD $FW3_INDEX_4 -j WEB_RESTRICTION
|
||||
|
||||
FW3_INDEX_6=$($ip6t -L FORWARD --line-numbers | tail -n +3 | grep -E ACCEPT | grep ctstate | grep fw3 | awk '{print $1}')
|
||||
[ -n "$FW3_INDEX_6" ] && let FW3_INDEX_6+=1
|
||||
$ip6t -I FORWARD $FW3_INDEX_6 -j WEB_RESTRICTION
|
||||
|
||||
[ "$limit_type" == "blacklist" ] && {
|
||||
iptables_w -t nat -I PREROUTING 1 -j WEB_RESTRICTION
|
||||
}
|
||||
}
|
||||
|
||||
stop(){
|
||||
ipt_del() {
|
||||
for i in $(seq 1 $($1 -nL $2 | grep -c "WEB_RESTRICTION")); do
|
||||
local index=$($1 --line-number -nL $2 | grep "WEB_RESTRICTION" | head -1 | awk '{print $1}')
|
||||
$1 -w -D $2 $index 2>/dev/null
|
||||
done
|
||||
}
|
||||
ipt_del "$ipt" "FORWARD"
|
||||
ipt_del "$ipt" "INPUT"
|
||||
ipt_del "$ipt -t nat" "PREROUTING"
|
||||
ipt_del "$ip6t" "FORWARD"
|
||||
ipt_del "$ip6t" "INPUT"
|
||||
ipt_del "$ip6t -t nat" "PREROUTING"
|
||||
|
||||
iptables_w -F WEB_RESTRICTION 2>/dev/null
|
||||
iptables_w -X WEB_RESTRICTION 2>/dev/null
|
||||
iptables_w -t nat -F WEB_RESTRICTION 2>/dev/null
|
||||
iptables_w -t nat -X WEB_RESTRICTION 2>/dev/null
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2016 fw867 <ffkykzs@gmail.com>
|
||||
# Copyright (C) 2024 Lienol
|
||||
|
||||
START=99
|
||||
|
||||
CONFIG=webrestriction
|
||||
ipt="iptables -w"
|
||||
ip6t="ip6tables -w"
|
||||
|
||||
add_rule(){
|
||||
action=$1
|
||||
local items=$(uci show ${CONFIG} | grep "=macbind" | cut -d '.' -sf 2 | cut -d '=' -sf 1)
|
||||
for i in $items; do
|
||||
enable=$(uci -q get ${CONFIG}.${i}.enable)
|
||||
macaddr=$(uci -q get ${CONFIG}.${i}.macaddr)
|
||||
if [ -z $enable ] || [ -z $macaddr ]; then
|
||||
continue
|
||||
fi
|
||||
if [ "$enable" == "1" ]; then
|
||||
$ipt -A WEB_RESTRICTION -m mac --mac-source $macaddr -j $action
|
||||
$ip6t -A WEB_RESTRICTION -m mac --mac-source $macaddr -j $action 2>/dev/null
|
||||
[ "$limit_type" == "blacklist" ] && {
|
||||
$ipt -t nat -A WEB_RESTRICTION -m mac --mac-source $macaddr -j RETURN
|
||||
$ip6t -t nat -A WEB_RESTRICTION -m mac --mac-source $macaddr -j RETURN 2>/dev/null
|
||||
}
|
||||
fi
|
||||
unset enable macaddr
|
||||
done
|
||||
}
|
||||
|
||||
start(){
|
||||
stop
|
||||
ENABLED=$(uci -q get ${CONFIG}.@basic[0].enable || echo "0")
|
||||
[ "${ENABLED}" != "1" ] && exit 0
|
||||
limit_type=$(uci -q get ${CONFIG}.@basic[0].limit_type)
|
||||
|
||||
$ipt -N WEB_RESTRICTION
|
||||
$ip6t -N WEB_RESTRICTION 2>/dev/null
|
||||
if [ "$limit_type" == "blacklist" ]; then
|
||||
$ipt -t nat -N WEB_RESTRICTION
|
||||
$ip6t -t nat -N WEB_RESTRICTION 2>/dev/null
|
||||
add_rule DROP
|
||||
else
|
||||
add_rule ACCEPT
|
||||
$ipt -A WEB_RESTRICTION -j DROP
|
||||
$ip6t -A WEB_RESTRICTION -j DROP 2>/dev/null
|
||||
fi
|
||||
|
||||
#获取FORWARD ACCEPT规则行号
|
||||
FA_INDEX=`$ipt -L FORWARD --line-numbers | tail -n +3 | grep -E ACCEPT | grep ctstate | grep fw3 | awk '{print $1}'`
|
||||
[ -n "$FA_INDEX" ] && let FA_INDEX+=1
|
||||
$ipt -I FORWARD $FA_INDEX -j WEB_RESTRICTION
|
||||
|
||||
#获取FORWARD ACCEPT规则行号
|
||||
FA_INDEX=`$ip6t -L FORWARD --line-numbers | tail -n +3 | grep -E ACCEPT | grep ctstate | grep fw3 | awk '{print $1}'`
|
||||
[ -n "$FA_INDEX" ] && let FA_INDEX+=1
|
||||
$ip6t -I FORWARD $FA_INDEX -j WEB_RESTRICTION
|
||||
|
||||
[ "$limit_type" == "blacklist" ] && {
|
||||
$ipt -t nat -I PREROUTING 1 -j WEB_RESTRICTION
|
||||
$ip6t -t nat -I PREROUTING 1 -j WEB_RESTRICTION 2>/dev/null
|
||||
}
|
||||
}
|
||||
stop(){
|
||||
ipt_del() {
|
||||
for i in $(seq 1 $($1 -nL $2 | grep -c "WEB_RESTRICTION")); do
|
||||
local index=$($1 --line-number -nL $2 | grep "WEB_RESTRICTION" | head -1 | awk '{print $1}')
|
||||
$1 -w -D $2 $index 2>/dev/null
|
||||
done
|
||||
}
|
||||
ipt_del "$ipt" "FORWARD"
|
||||
ipt_del "$ipt" "INPUT"
|
||||
ipt_del "$ipt -t nat" "PREROUTING"
|
||||
ipt_del "$ip6t" "FORWARD"
|
||||
ipt_del "$ip6t" "INPUT"
|
||||
ipt_del "$ip6t -t nat" "PREROUTING"
|
||||
$ipt -F WEB_RESTRICTION 2>/dev/null
|
||||
$ipt -X WEB_RESTRICTION 2>/dev/null
|
||||
$ipt -t nat -F WEB_RESTRICTION 2>/dev/null
|
||||
$ipt -t nat -X WEB_RESTRICTION 2>/dev/null
|
||||
$ip6t -F WEB_RESTRICTION 2>/dev/null
|
||||
$ip6t -X WEB_RESTRICTION 2>/dev/null
|
||||
$ip6t -t nat -F WEB_RESTRICTION 2>/dev/null
|
||||
$ip6t -t nat -X WEB_RESTRICTION 2>/dev/null
|
||||
}
|
||||
+8
-8
@@ -1,19 +1,19 @@
|
||||
#!/bin/sh
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-webrestriction.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-webrestriction.json << EEOF
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-luci_app_control_webrestriction.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-luci_app_control_webrestriction.json << EEOF
|
||||
{
|
||||
"config": "webrestriction",
|
||||
"init": "webrestriction"
|
||||
"config": "luci_app_control_webrestriction",
|
||||
"init": "luci_app_control_webrestriction"
|
||||
}
|
||||
EEOF
|
||||
}
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@webrestriction[-1]
|
||||
add ucitrack webrestriction
|
||||
set ucitrack.@webrestriction[-1].init=webrestriction
|
||||
delete ucitrack.@luci_app_control_webrestriction[-1]
|
||||
add ucitrack luci_app_control_webrestriction
|
||||
set ucitrack.@luci_app_control_webrestriction[-1].init=luci-app-control-webrestriction
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -f /tmp/luci-indexcache
|
||||
rm -rf /tmp/luci-*cache
|
||||
exit 0
|
||||
Reference in new issue
Block a user