2021-03-04 14:30:38 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
IPSET_DIR="$(dirname "$0")"
|
|
|
|
IPSET_DIR="$(cd "$IPSET_DIR"; pwd)"
|
|
|
|
|
|
|
|
. "$IPSET_DIR/def.sh"
|
|
|
|
|
|
|
|
ZREESTR="$TMPDIR/zapret.txt"
|
2023-11-26 14:31:37 +03:00
|
|
|
IPB="$TMPDIR/ipb.txt"
|
2022-12-11 09:58:04 +03:00
|
|
|
ZURL_REESTR=https://raw.githubusercontent.com/zapret-info/z-i/master/dump.csv
|
2021-03-04 14:30:38 +03:00
|
|
|
|
2023-11-26 14:31:37 +03:00
|
|
|
dl_checked()
|
2021-03-04 14:30:38 +03:00
|
|
|
{
|
2023-11-26 14:31:37 +03:00
|
|
|
# $1 - url
|
|
|
|
# $2 - file
|
|
|
|
# $3 - minsize
|
|
|
|
# $4 - maxsize
|
|
|
|
# $5 - maxtime
|
2024-06-19 09:03:15 +03:00
|
|
|
curl -k --fail --max-time $5 --connect-timeout 10 --retry 4 --max-filesize $4 -o "$2" "$1" ||
|
2023-11-26 14:31:37 +03:00
|
|
|
{
|
|
|
|
echo list download failed : $1
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
dlsize=$(LANG=C wc -c "$2" | xargs | cut -f 1 -d ' ')
|
|
|
|
if test $dlsize -lt $3; then
|
|
|
|
echo list is too small : $dlsize bytes. can be bad.
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
return 0
|
2021-03-04 14:30:38 +03:00
|
|
|
}
|
2021-12-12 12:58:58 +03:00
|
|
|
|
|
|
|
reestr_list()
|
|
|
|
{
|
|
|
|
LANG=C cut -s -f2 -d';' "$ZREESTR" | LANG=C nice -n 5 sed -Ee 's/^\*\.(.+)$/\1/' -ne 's/^[a-z0-9A-Z._-]+$/&/p' | $AWK '{ print tolower($0) }'
|
|
|
|
}
|
2023-11-26 14:31:37 +03:00
|
|
|
reestr_extract_ip()
|
|
|
|
{
|
|
|
|
LANG=C nice -n 5 $AWK -F ';' '($1 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}/) && (($2 == "" && $3 == "") || ($1 == $2)) {gsub(/ \| /, RS); print $1}' "$ZREESTR" | LANG=C $AWK '{split($1, a, /\|/); for (i in a) {print a[i]}}'
|
|
|
|
}
|
2021-12-12 12:58:58 +03:00
|
|
|
|
2023-11-26 14:31:37 +03:00
|
|
|
ipban_fin()
|
|
|
|
{
|
|
|
|
getipban
|
|
|
|
"$IPSET_DIR/create_ipset.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
dl_checked "$ZURL_REESTR" "$ZREESTR" 204800 251658240 600 || {
|
|
|
|
ipban_fin
|
2021-03-04 14:30:38 +03:00
|
|
|
exit 2
|
2023-11-26 14:31:37 +03:00
|
|
|
}
|
2021-12-12 12:58:58 +03:00
|
|
|
|
2022-07-27 16:35:05 +03:00
|
|
|
reestr_list | sort -u | zz "$ZHOSTLIST"
|
2021-12-12 12:58:58 +03:00
|
|
|
|
2023-11-26 14:31:37 +03:00
|
|
|
reestr_extract_ip <"$ZREESTR" >"$IPB"
|
2023-11-26 16:32:37 +03:00
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
rm -f "$ZREESTR"
|
2023-11-27 16:12:23 +03:00
|
|
|
[ "$DISABLE_IPV4" != "1" ] && $AWK '/^([0-9]{1,3}\.){3}[0-9]{1,3}($|(\/[0-9]{2}$))/' "$IPB" | cut_local | ip2net4 | zz "$ZIPLIST_IPBAN"
|
|
|
|
[ "$DISABLE_IPV6" != "1" ] && $AWK '/^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}($|(\/[0-9]{2,3}$))/' "$IPB" | cut_local6 | ip2net6 | zz "$ZIPLIST_IPBAN6"
|
2023-11-26 14:31:37 +03:00
|
|
|
rm -f "$IPB"
|
2021-03-04 14:30:38 +03:00
|
|
|
|
|
|
|
hup_zapret_daemons
|
|
|
|
|
2023-11-26 14:31:37 +03:00
|
|
|
ipban_fin
|
|
|
|
|
2021-03-04 14:30:38 +03:00
|
|
|
exit 0
|