From 83918288f1b518f9ac74ff91b626088041373900 Mon Sep 17 00:00:00 2001 From: gSpot Date: Sun, 25 Dec 2022 19:45:07 +0300 Subject: [PATCH] v0.9.5. Changes for rublacklist API v3 --- autoinstall/autoinstall.sh | 6 +++--- luci-app-ruantiblock/Makefile | 2 +- ruantiblock-mod-lua/Makefile | 4 ++-- .../usr/libexec/ruantiblock/ruab_parser.lua | 14 ++++++++------ ruantiblock-mod-py/Makefile | 4 ++-- .../usr/libexec/ruantiblock/ruab_parser.py | 18 ++++++++++++------ ruantiblock/Makefile | 4 ++-- .../files/etc/ruantiblock/ruantiblock.conf | 4 ++-- ruantiblock/files/usr/bin/ruantiblock | 4 ++-- 9 files changed, 34 insertions(+), 26 deletions(-) diff --git a/autoinstall/autoinstall.sh b/autoinstall/autoinstall.sh index d9ff30c..1049c5f 100755 --- a/autoinstall/autoinstall.sh +++ b/autoinstall/autoinstall.sh @@ -8,9 +8,9 @@ LUA_MODULE=1 LUCI_APP=1 OWRT_VERSION="current" -RUAB_VERSION="0.9.4-1" -RUAB_MOD_LUA_VERSION="0.9.4-1" -RUAB_LUCI_APP_VERSION="0.9.4-1" +RUAB_VERSION="0.9.5-0" +RUAB_MOD_LUA_VERSION="0.9.5-0" +RUAB_LUCI_APP_VERSION="0.9.5-0" BASE_URL="https://raw.githubusercontent.com/gSpotx2f/packages-openwrt/master" PKG_DIR="/tmp" diff --git a/luci-app-ruantiblock/Makefile b/luci-app-ruantiblock/Makefile index d8b57da..82bd7ef 100644 --- a/luci-app-ruantiblock/Makefile +++ b/luci-app-ruantiblock/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk -PKG_VERSION:=0.9.4-1 +PKG_VERSION:=0.9.5-0 LUCI_TITLE:=LuCI support for ruantiblock LUCI_DEPENDS:=+ruantiblock LUCI_PKGARCH:=all diff --git a/ruantiblock-mod-lua/Makefile b/ruantiblock-mod-lua/Makefile index f362062..a5bf058 100644 --- a/ruantiblock-mod-lua/Makefile +++ b/ruantiblock-mod-lua/Makefile @@ -5,8 +5,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ruantiblock-mod-lua -PKG_VERSION:=0.9.4 -PKG_RELEASE:=1 +PKG_VERSION:=0.9.5 +PKG_RELEASE:=0 PKG_MAINTAINER:=gSpot include $(INCLUDE_DIR)/package.mk diff --git a/ruantiblock-mod-lua/files/usr/libexec/ruantiblock/ruab_parser.lua b/ruantiblock-mod-lua/files/usr/libexec/ruantiblock/ruab_parser.lua index aec476b..77cb938 100755 --- a/ruantiblock-mod-lua/files/usr/libexec/ruantiblock/ruab_parser.lua +++ b/ruantiblock-mod-lua/files/usr/libexec/ruantiblock/ruab_parser.lua @@ -182,9 +182,9 @@ local iconv = prequire("iconv") local si, it if prequire("bit") then - it = prequire("iptool") + it = require("iptool") if it then - si = prequire("ruab_sum_ip") + si = require("ruab_sum_ip") end end if not si then @@ -509,14 +509,14 @@ end local Rbl = Class(BlackListParser, { url = Config.RBL_ALL_URL, + records_separator = '%{"authority": ', ips_separator = ", ", - ip_string_pattern = "([a-f0-9/.:]+),?\n?", }) function Rbl:sink() return function(chunk) if chunk and chunk ~= "" then - for ip_str, fqdn_str in chunk:gmatch("%[([a-f0-9/.:', ]+)%],([^,]-),.-" .. self.records_separator .. "?") do + for fqdn_str, ip_str in chunk:gmatch('"domains": %["?(.-)"?%].-"ips": %[([a-f0-9/.:", ]*)%].-' .. self.records_separator .. "?") do fqdn_sink_func(self, ip_str, fqdn_str) end end @@ -526,6 +526,8 @@ end local RblIp = Class(Rbl, { url = Config.RBL_IP_URL, + records_separator = ",", + ip_string_pattern = "([a-f0-9/.:]+)", sink = ip_sink, }) @@ -533,7 +535,6 @@ local RblIp = Class(Rbl, { local Zi = Class(BlackListParser, { url = Config.ZI_ALL_URL, - ip_string_pattern = "([a-f0-9%.:/ |]+);.-\n", site_encoding = Config.ZI_ENCODING, }) @@ -549,6 +550,7 @@ function Zi:sink() end local ZiIp = Class(Zi, { + ip_string_pattern = "([a-f0-9%.:/ |]+);.-\n", sink = ip_sink, }) @@ -556,7 +558,6 @@ local ZiIp = Class(Zi, { local Af = Class(BlackListParser, { url = Config.AF_FQDN_URL, - ip_string_pattern = "(.-)\n", }) function Af:sink() @@ -573,6 +574,7 @@ end local AfIp = Class(Af, { url = Config.AF_IP_URL, + ip_string_pattern = "(.-)\n", sink = ip_sink, BLLIST_MIN_ENTRIES = 100, }) diff --git a/ruantiblock-mod-py/Makefile b/ruantiblock-mod-py/Makefile index f6fc638..4781fe4 100644 --- a/ruantiblock-mod-py/Makefile +++ b/ruantiblock-mod-py/Makefile @@ -5,8 +5,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ruantiblock-mod-py -PKG_VERSION:=0.9.4 -PKG_RELEASE:=2 +PKG_VERSION:=0.9.5 +PKG_RELEASE:=0 PKG_MAINTAINER:=gSpot include $(INCLUDE_DIR)/package.mk diff --git a/ruantiblock-mod-py/files/usr/libexec/ruantiblock/ruab_parser.py b/ruantiblock-mod-py/files/usr/libexec/ruantiblock/ruab_parser.py index 9ef77fd..a695362 100755 --- a/ruantiblock-mod-py/files/usr/libexec/ruantiblock/ruab_parser.py +++ b/ruantiblock-mod-py/files/usr/libexec/ruantiblock/ruab_parser.py @@ -372,14 +372,16 @@ class RblFQDN(BlackListParser): def __init__(self): super().__init__() self.url = self.RBL_ALL_URL - self.fields_separator = "]," - self.ips_separator = "," + self.records_separator = '{"authority": ' + self.ips_separator = ", " def parser_func(self): for entry in self._split_entries(): - entry_list = entry.partition(self.fields_separator) - ip_string = re.sub(r"[' \]\[]", "", entry_list[0]) - fqdn_string = re.sub(",.*$", "", entry_list[2]) + res = re.search(r'"domains": \["?(.*?)"?\].*?"ips": \[([a-f0-9/.:", ]*)\]', entry) + if not res: + continue + ip_string = res.group(2).replace('"', "") + fqdn_string = res.group(1) if fqdn_string: try: self.fqdn_field_processing(fqdn_string) @@ -393,10 +395,11 @@ class RblIp(BlackListParser): def __init__(self): super().__init__() self.url = self.RBL_IP_URL + self.records_separator = "," def parser_func(self): for entry in self._split_entries(): - self.ip_field_processing(entry.rstrip(",")) + self.ip_field_processing(re.sub(r'[\[\]" ]', "", entry)) class ZiFQDN(BlackListParser): @@ -450,6 +453,7 @@ class AfIp(BlackListParser): for entry in self._split_entries(): self.ip_field_processing(entry) + class RaFQDN(BlackListParser): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -474,6 +478,7 @@ class RaFQDN(BlackListParser): self.download_config(self.url_stat, self.UPDATE_STATUS_FILE) return 0 + class RaIp(RaFQDN): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -481,6 +486,7 @@ class RaIp(RaFQDN): self.url_dnsmasq = self.RA_IP_DMASK_URL self.url_stat = self.RA_IP_STAT_URL + class WriteConfigFiles(Config): def __init__(self): self.write_buffer = -1 diff --git a/ruantiblock/Makefile b/ruantiblock/Makefile index 5a66c98..58d670c 100644 --- a/ruantiblock/Makefile +++ b/ruantiblock/Makefile @@ -5,8 +5,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ruantiblock -PKG_VERSION:=0.9.4 -PKG_RELEASE:=1 +PKG_VERSION:=0.9.5 +PKG_RELEASE:=0 PKG_MAINTAINER:=gSpot include $(INCLUDE_DIR)/package.mk diff --git a/ruantiblock/files/etc/ruantiblock/ruantiblock.conf b/ruantiblock/files/etc/ruantiblock/ruantiblock.conf index 4af9bca..93530cd 100644 --- a/ruantiblock/files/etc/ruantiblock/ruantiblock.conf +++ b/ruantiblock/files/etc/ruantiblock/ruantiblock.conf @@ -96,8 +96,8 @@ BLLIST_ALT_NSLOOKUP=0 BLLIST_ALT_DNS_ADDR="8.8.8.8" ### Источники блэклиста -RBL_ALL_URL="https://reestr.rublacklist.net/api/v2/current/csv/" -RBL_IP_URL="https://reestr.rublacklist.net/api/v2/ips/csv/" +RBL_ALL_URL="https://reestr.rublacklist.net/api/v3/snapshot/" +RBL_IP_URL="https://reestr.rublacklist.net/api/v3/ips/" ZI_ALL_URL="https://raw.githubusercontent.com/zapret-info/z-i/master/dump.csv" #ZI_ALL_URL="https://app.assembla.com/spaces/z-i/git/source/master/dump.csv?_format=raw" AF_IP_URL="https://antifilter.download/list/allyouneed.lst" diff --git a/ruantiblock/files/usr/bin/ruantiblock b/ruantiblock/files/usr/bin/ruantiblock index d6fc264..a88d742 100755 --- a/ruantiblock/files/usr/bin/ruantiblock +++ b/ruantiblock/files/usr/bin/ruantiblock @@ -110,8 +110,8 @@ export BLLIST_ALT_NSLOOKUP=0 export BLLIST_ALT_DNS_ADDR="8.8.8.8" ### Источники блэклиста -export RBL_ALL_URL="https://reestr.rublacklist.net/api/v2/current/csv/" -export RBL_IP_URL="https://reestr.rublacklist.net/api/v2/ips/csv/" +export RBL_ALL_URL="https://reestr.rublacklist.net/api/v3/snapshot/" +export RBL_IP_URL="https://reestr.rublacklist.net/api/v3/ips/" export ZI_ALL_URL="https://raw.githubusercontent.com/zapret-info/z-i/master/dump.csv" export AF_IP_URL="https://antifilter.download/list/allyouneed.lst" export AF_FQDN_URL="https://antifilter.download/list/domains.lst"