zapret/init.d/openwrt/custom-tpws4http-nfqws4https

66 lines
1.5 KiB
Plaintext
Raw Normal View History

2021-03-04 16:30:38 +05:00
# this custom script demonstrates how to apply tpws to http and nfqws to https
2021-03-20 20:54:16 +05:00
# it preserves config settings : MODE_HTTP, MODE_HTTPS, MODE_FILTER, TPWS_OPT, NFQWS_OPT_DESYNC, NFQWS_OPT_DESYNC_HTTPS
2021-03-04 16:30:38 +05:00
zapret_custom_daemons()
{
2022-02-15 19:15:36 +05:00
# stop logic is managed by procd
2021-03-04 16:30:38 +05:00
local opt
[ "$MODE_HTTP" = "1" ] && {
opt="--port=$TPPORT $TPWS_OPT"
2021-03-04 16:30:38 +05:00
filter_apply_hostlist_target opt
run_tpws 1 "$opt"
}
[ "$MODE_HTTPS" = "1" ] && {
2021-03-20 20:54:16 +05:00
opt="--qnum=$QNUM $NFQWS_OPT_BASE $NFQWS_OPT_DESYNC_HTTPS"
2021-03-04 16:30:38 +05:00
filter_apply_hostlist_target opt
run_daemon 2 $NFQWS "$opt"
}
}
zapret_custom_firewall()
{
2022-02-15 19:15:36 +05:00
# $1 - 1 - run, 0 - stop
2021-03-04 16:30:38 +05:00
local f4 f6
2021-03-12 16:33:48 +05:00
local first_packet_only="-m connbytes --connbytes-dir=original --connbytes-mode=packets --connbytes 1:4"
2021-03-04 16:30:38 +05:00
local desync="-m mark ! --mark $DESYNC_MARK/$DESYNC_MARK"
[ "$MODE_HTTP" = "1" ] && {
f4="-p tcp --dport 80"
2021-03-04 16:30:38 +05:00
f6=$f4
filter_apply_ipset_target f4 f6
2022-02-15 19:15:36 +05:00
fw_tpws $1 "$f4" "$f6" $TPPORT
2021-03-04 16:30:38 +05:00
}
[ "$MODE_HTTPS" = "1" ] && {
f4="-p tcp --dport 443 $first_packet_only"
2021-03-04 16:30:38 +05:00
f6=$f4
filter_apply_ipset_target f4 f6
2022-02-15 19:15:36 +05:00
fw_nfqws_post $1 "$f4 $desync" "$f6 $desync" $QNUM
}
}
zapret_custom_firewall_nft()
{
# stop logic is not required
local f4 f6
local first_packet_only="ct original packets 1-4"
local desync="mark and $DESYNC_MARK == 0"
[ "$MODE_HTTP" = "1" ] && {
f4="tcp dport 80"
f6=$f4
nft_filter_apply_ipset_target f4 f6
nft_fw_tpws "$f4" "$f6" $TPPORT
}
[ "$MODE_HTTPS" = "1" ] && {
f4="tcp dport 443 $first_packet_only"
f6=$f4
nft_filter_apply_ipset_target f4 f6
nft_fw_nfqws_post "$f4 $desync" "$f6 $desync" $QNUM
2021-03-04 16:30:38 +05:00
}
}