mirror of
https://github.com/gSpotx2f/ruantiblock_openwrt.git
synced 2026-05-13 22:20:59 +00:00
ruantiblock-mod-lua, ruantiblock-mod-py: new blacklist source fz139.
This commit is contained in:
@@ -9,8 +9,8 @@ LUA_MODULE=0
|
|||||||
LUCI_APP=1
|
LUCI_APP=1
|
||||||
|
|
||||||
OWRT_VERSION="current"
|
OWRT_VERSION="current"
|
||||||
RUAB_VERSION="1.4-2"
|
RUAB_VERSION="1.4-3"
|
||||||
RUAB_MOD_LUA_VERSION="1.4-2"
|
RUAB_MOD_LUA_VERSION="1.4-3"
|
||||||
RUAB_LUCI_APP_VERSION="1.4-2"
|
RUAB_LUCI_APP_VERSION="1.4-2"
|
||||||
BASE_URL="https://raw.githubusercontent.com/gSpotx2f/packages-openwrt/master"
|
BASE_URL="https://raw.githubusercontent.com/gSpotx2f/packages-openwrt/master"
|
||||||
PKG_DIR="/tmp"
|
PKG_DIR="/tmp"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=ruantiblock-mod-lua
|
PKG_NAME:=ruantiblock-mod-lua
|
||||||
PKG_VERSION:=1.4
|
PKG_VERSION:=1.4
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
|
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|||||||
@@ -70,15 +70,17 @@ local Config = Class(nil, {
|
|||||||
["ZI_ALL_URL"] = true,
|
["ZI_ALL_URL"] = true,
|
||||||
["AF_IP_URL"] = true,
|
["AF_IP_URL"] = true,
|
||||||
["AF_FQDN_URL"] = true,
|
["AF_FQDN_URL"] = true,
|
||||||
["RA_IP_NFTSET_URL"] = true,
|
["FZ_URL"] = true,
|
||||||
|
["RA_IP_IPSET_URL"] = true,
|
||||||
["RA_IP_DMASK_URL"] = true,
|
["RA_IP_DMASK_URL"] = true,
|
||||||
["RA_IP_STAT_URL"] = true,
|
["RA_IP_STAT_URL"] = true,
|
||||||
["RA_FQDN_NFTSET_URL"] = true,
|
["RA_FQDN_IPSET_URL"] = true,
|
||||||
["RA_FQDN_DMASK_URL"] = true,
|
["RA_FQDN_DMASK_URL"] = true,
|
||||||
["RA_FQDN_STAT_URL"] = true,
|
["RA_FQDN_STAT_URL"] = true,
|
||||||
["RBL_ENCODING"] = true,
|
["RBL_ENCODING"] = true,
|
||||||
["ZI_ENCODING"] = true,
|
["ZI_ENCODING"] = true,
|
||||||
["AF_ENCODING"] = true,
|
["AF_ENCODING"] = true,
|
||||||
|
["FZ_ENCODING"] = true,
|
||||||
["RA_ENCODING"] = true,
|
["RA_ENCODING"] = true,
|
||||||
["BLLIST_SUMMARIZE_IP"] = true,
|
["BLLIST_SUMMARIZE_IP"] = true,
|
||||||
["BLLIST_SUMMARIZE_CIDR"] = true,
|
["BLLIST_SUMMARIZE_CIDR"] = true,
|
||||||
@@ -101,15 +103,36 @@ Config.wget_user_agent = (Config.http_send_headers["User-Agent"]) and ' -U "' ..
|
|||||||
-- Loading external config
|
-- Loading external config
|
||||||
|
|
||||||
function Config:load_config(t)
|
function Config:load_config(t)
|
||||||
local config_arrays = {
|
local config_sets = {
|
||||||
["BLLIST_GR_EXCLUDED_SLD"] = true,
|
["BLLIST_GR_EXCLUDED_SLD"] = true,
|
||||||
["BLLIST_GR_EXCLUDED_NETS"] = true,
|
["BLLIST_GR_EXCLUDED_NETS"] = true,
|
||||||
}
|
}
|
||||||
|
local config_arrays = {
|
||||||
|
["RBL_ALL_URL"] = true,
|
||||||
|
["RBL_IP_URL"] = true,
|
||||||
|
["RBL_DPI_URL"] = true,
|
||||||
|
["ZI_ALL_URL"] = true,
|
||||||
|
["AF_IP_URL"] = true,
|
||||||
|
["AF_FQDN_URL"] = true,
|
||||||
|
["FZ_URL"] = true,
|
||||||
|
["RA_IP_IPSET_URL"] = true,
|
||||||
|
["RA_IP_DMASK_URL"] = true,
|
||||||
|
["RA_IP_STAT_URL"] = true,
|
||||||
|
["RA_FQDN_IPSET_URL"] = true,
|
||||||
|
["RA_FQDN_DMASK_URL"] = true,
|
||||||
|
["RA_FQDN_STAT_URL"] = true,
|
||||||
|
}
|
||||||
for k, v in pairs(t) do
|
for k, v in pairs(t) do
|
||||||
if config_arrays[k] then
|
if config_sets[k] then
|
||||||
local value_table = {}
|
local value_table = {}
|
||||||
for v in v:gmatch('[^" ]+') do
|
for i in v:gmatch('[^" ]+') do
|
||||||
value_table[v] = true
|
value_table[i] = true
|
||||||
|
end
|
||||||
|
self[k] = value_table
|
||||||
|
elseif config_arrays[k] then
|
||||||
|
local value_table = {}
|
||||||
|
for i in v:gmatch('[^" ]+') do
|
||||||
|
value_table[#value_table + 1] = i
|
||||||
end
|
end
|
||||||
self[k] = value_table
|
self[k] = value_table
|
||||||
else
|
else
|
||||||
@@ -218,7 +241,7 @@ local BlackListParser = Class(Config, {
|
|||||||
ip_pattern = "%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?",
|
ip_pattern = "%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?",
|
||||||
cidr_pattern = "%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?/%d%d?",
|
cidr_pattern = "%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?/%d%d?",
|
||||||
fqdn_pattern = "[a-z0-9_%.%-]-[a-z0-9_%-]+%.[a-z0-9%.%-]+",
|
fqdn_pattern = "[a-z0-9_%.%-]-[a-z0-9_%-]+%.[a-z0-9%.%-]+",
|
||||||
url = "http://127.0.0.1",
|
url = {[1] = "http://127.0.0.1"},
|
||||||
records_separator = "\n",
|
records_separator = "\n",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -239,6 +262,7 @@ function BlackListParser:new(t)
|
|||||||
instance.fqdn_records_count = 0
|
instance.fqdn_records_count = 0
|
||||||
instance.fqdn_table = {}
|
instance.fqdn_table = {}
|
||||||
instance.iconv_handler = iconv and iconv.open(instance.encoding, instance.site_encoding) or nil
|
instance.iconv_handler = iconv and iconv.open(instance.encoding, instance.site_encoding) or nil
|
||||||
|
instance.buff = ""
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -331,7 +355,6 @@ function BlackListParser:parser_func()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function BlackListParser:chunk_buffer()
|
function BlackListParser:chunk_buffer()
|
||||||
local buff = ""
|
|
||||||
local ret_value = ""
|
local ret_value = ""
|
||||||
local last_chunk
|
local last_chunk
|
||||||
return function(chunk)
|
return function(chunk)
|
||||||
@@ -339,16 +362,16 @@ function BlackListParser:chunk_buffer()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if chunk then
|
if chunk then
|
||||||
buff = buff .. chunk
|
self.buff = self.buff .. chunk
|
||||||
local last_rs_position = select(2, buff:find("^.*" .. self.records_separator))
|
local last_rs_position = select(2, self.buff:find("^.*" .. self.records_separator))
|
||||||
if last_rs_position then
|
if last_rs_position then
|
||||||
ret_value = buff:sub(1, last_rs_position)
|
ret_value = self.buff:sub(1, last_rs_position)
|
||||||
buff = buff:sub((last_rs_position + 1), -1)
|
self.buff = self.buff:sub((last_rs_position + 1), -1)
|
||||||
else
|
else
|
||||||
ret_value = ""
|
ret_value = ""
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ret_value = buff
|
ret_value = self.buff
|
||||||
last_chunk = true
|
last_chunk = true
|
||||||
end
|
end
|
||||||
return (ret_value)
|
return (ret_value)
|
||||||
@@ -372,9 +395,24 @@ function BlackListParser:get_http_data(url)
|
|||||||
return (ret_val == 1) and true or false
|
return (ret_val == 1) and true or false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BlackListParser:download_files(url_list)
|
||||||
|
local ret_list = {}
|
||||||
|
for _, url in ipairs(url_list) do
|
||||||
|
ret_list[#ret_list + 1] = self:get_http_data(url)
|
||||||
|
end
|
||||||
|
local ret_val = true
|
||||||
|
for _, i in ipairs(ret_list) do
|
||||||
|
if not i then
|
||||||
|
ret_val = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ret_val
|
||||||
|
end
|
||||||
|
|
||||||
function BlackListParser:run()
|
function BlackListParser:run()
|
||||||
local return_code = 0
|
local return_code = 0
|
||||||
if self:get_http_data(self.url) then
|
if self:download_files(self.url) then
|
||||||
if (self.fqdn_count + self.ip_count + self.cidr_count) > self.BLLIST_MIN_ENTRIES then
|
if (self.fqdn_count + self.ip_count + self.cidr_count) > self.BLLIST_MIN_ENTRIES then
|
||||||
return_code = 0
|
return_code = 0
|
||||||
else
|
else
|
||||||
@@ -383,6 +421,7 @@ function BlackListParser:run()
|
|||||||
else
|
else
|
||||||
return_code = 1
|
return_code = 1
|
||||||
end
|
end
|
||||||
|
self.buff = ""
|
||||||
return return_code
|
return return_code
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -766,7 +805,7 @@ local function ip_parser_func(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function fqdn_parser_func(self, ip_str, fqdn_str)
|
local function fqdn_parser_func(self, ip_str, fqdn_str)
|
||||||
if #fqdn_str > 0 and not fqdn_str:match("^" .. self.ip_pattern .. "$") then
|
if fqdn_str ~= nil and #fqdn_str > 0 and not fqdn_str:match("^" .. self.ip_pattern .. "$") then
|
||||||
if self:fqdn_value_processing(fqdn_str) then
|
if self:fqdn_value_processing(fqdn_str) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -865,6 +904,53 @@ local AfIp = Class(Af, {
|
|||||||
parser_func = ip_parser_func,
|
parser_func = ip_parser_func,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- fz139
|
||||||
|
|
||||||
|
local Fz = Class(BlackListParser, {
|
||||||
|
url = Config.FZ_URL,
|
||||||
|
site_encoding = Config.FZ_ENCODING,
|
||||||
|
records_separator = "</content>",
|
||||||
|
})
|
||||||
|
|
||||||
|
function Fz:parser_func()
|
||||||
|
return function(chunk)
|
||||||
|
if chunk and chunk ~= "" then
|
||||||
|
for entry in chunk:gmatch("(.-)" .. self.records_separator) do
|
||||||
|
local fqdn_str = entry:match("<domain><%!%[CDATA%[(.-)%]%]></domain>")
|
||||||
|
if fqdn_str ~= nil and #fqdn_str > 0 and not fqdn_str:match("^" .. self.ip_pattern .. "$") and self:fqdn_value_processing(fqdn_str) then
|
||||||
|
else
|
||||||
|
for ip_str in entry:gmatch("<ip>(.-)</ip>") do
|
||||||
|
self:ip_value_processing(ip_str)
|
||||||
|
end
|
||||||
|
for ip_str in entry:gmatch("<ipSubnet>(.-)</ipSubnet>") do
|
||||||
|
self:ip_value_processing(ip_str)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local FzIp = Class(Fz, {
|
||||||
|
})
|
||||||
|
|
||||||
|
function FzIp:parser_func()
|
||||||
|
return function(chunk)
|
||||||
|
if chunk and chunk ~= "" then
|
||||||
|
for entry in chunk:gmatch("(.-)" .. self.records_separator) do
|
||||||
|
for ip_str in entry:gmatch("<ip>(.-)</ip>") do
|
||||||
|
self:ip_value_processing(ip_str)
|
||||||
|
end
|
||||||
|
for ip_str in entry:gmatch("<ipSubnet>(.-)</ipSubnet>") do
|
||||||
|
self:ip_value_processing(ip_str)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- ruantiblock
|
-- ruantiblock
|
||||||
|
|
||||||
local Ra = Class(BlackListParser, {
|
local Ra = Class(BlackListParser, {
|
||||||
@@ -876,7 +962,7 @@ local Ra = Class(BlackListParser, {
|
|||||||
function Ra:download_config(url, file)
|
function Ra:download_config(url, file)
|
||||||
local ret_val = false
|
local ret_val = false
|
||||||
self.current_file_handler = assert(io.open(file, "w"), "Could not open file")
|
self.current_file_handler = assert(io.open(file, "w"), "Could not open file")
|
||||||
if self:get_http_data(url) then
|
if self:download_files(url) then
|
||||||
ret_val = true
|
ret_val = true
|
||||||
end
|
end
|
||||||
self.current_file_handler:close()
|
self.current_file_handler:close()
|
||||||
@@ -919,8 +1005,8 @@ local RaIp = Class(Ra, {
|
|||||||
----------------------------- Main section ------------------------------
|
----------------------------- Main section ------------------------------
|
||||||
|
|
||||||
local parsers_table = {
|
local parsers_table = {
|
||||||
["ip"] = {["rublacklist"] = {RblIp}, ["zapret-info"] = {ZiIp}, ["antifilter"] = {AfIp}, ["ruantiblock"] = {RaIp}},
|
["ip"] = {["rublacklist"] = {RblIp}, ["zapret-info"] = {ZiIp}, ["antifilter"] = {AfIp}, ["fz"] = {FzIp}, ["ruantiblock"] = {RaIp}},
|
||||||
["fqdn"] = {["rublacklist"] = {Rbl, RblDPI}, ["zapret-info"] = {Zi}, ["antifilter"] = {Af}, ["ruantiblock"] = {Ra}},
|
["fqdn"] = {["rublacklist"] = {Rbl, RblDPI}, ["zapret-info"] = {Zi}, ["antifilter"] = {Af}, ["fz"] = {Fz}, ["ruantiblock"] = {Ra}},
|
||||||
}
|
}
|
||||||
|
|
||||||
local ret_list = {}
|
local ret_list = {}
|
||||||
@@ -933,7 +1019,7 @@ if parser_classes then
|
|||||||
for _, i in ipairs(parser_instances) do
|
for _, i in ipairs(parser_instances) do
|
||||||
ret_list[i:run()] = true
|
ret_list[i:run()] = true
|
||||||
end
|
end
|
||||||
return_sum = 0
|
local return_sum = 0
|
||||||
for i, _ in pairs(ret_list) do
|
for i, _ in pairs(ret_list) do
|
||||||
return_sum = return_sum + i
|
return_sum = return_sum + i
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=ruantiblock-mod-py
|
PKG_NAME:=ruantiblock-mod-py
|
||||||
PKG_VERSION:=1.4
|
PKG_VERSION:=1.4
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
|
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|||||||
@@ -54,15 +54,17 @@ class Config:
|
|||||||
"ZI_ALL_URL",
|
"ZI_ALL_URL",
|
||||||
"AF_IP_URL",
|
"AF_IP_URL",
|
||||||
"AF_FQDN_URL",
|
"AF_FQDN_URL",
|
||||||
"RA_IP_NFTSET_URL",
|
"FZ_URL",
|
||||||
|
"RA_IP_IPSET_URL",
|
||||||
"RA_IP_DMASK_URL",
|
"RA_IP_DMASK_URL",
|
||||||
"RA_IP_STAT_URL",
|
"RA_IP_STAT_URL",
|
||||||
"RA_FQDN_NFTSET_URL",
|
"RA_FQDN_IPSET_URL",
|
||||||
"RA_FQDN_DMASK_URL",
|
"RA_FQDN_DMASK_URL",
|
||||||
"RA_FQDN_STAT_URL",
|
"RA_FQDN_STAT_URL",
|
||||||
"RBL_ENCODING",
|
"RBL_ENCODING",
|
||||||
"ZI_ENCODING",
|
"ZI_ENCODING",
|
||||||
"AF_ENCODING",
|
"AF_ENCODING",
|
||||||
|
"FZ_ENCODING",
|
||||||
"RA_ENCODING",
|
"RA_ENCODING",
|
||||||
"BLLIST_SUMMARIZE_IP",
|
"BLLIST_SUMMARIZE_IP",
|
||||||
"BLLIST_SUMMARIZE_CIDR",
|
"BLLIST_SUMMARIZE_CIDR",
|
||||||
@@ -76,14 +78,31 @@ class Config:
|
|||||||
def normalize_string(string):
|
def normalize_string(string):
|
||||||
return re.sub('"', '', string)
|
return re.sub('"', '', string)
|
||||||
|
|
||||||
config_arrays = {
|
config_sets = {
|
||||||
"BLLIST_GR_EXCLUDED_SLD",
|
"BLLIST_GR_EXCLUDED_SLD",
|
||||||
"BLLIST_GR_EXCLUDED_NETS",
|
"BLLIST_GR_EXCLUDED_NETS",
|
||||||
}
|
}
|
||||||
|
config_arrays = {
|
||||||
|
"RBL_ALL_URL",
|
||||||
|
"RBL_IP_URL",
|
||||||
|
"RBL_DPI_URL",
|
||||||
|
"ZI_ALL_URL",
|
||||||
|
"AF_IP_URL",
|
||||||
|
"AF_FQDN_URL",
|
||||||
|
"FZ_URL",
|
||||||
|
"RA_IP_IPSET_URL",
|
||||||
|
"RA_IP_DMASK_URL",
|
||||||
|
"RA_IP_STAT_URL",
|
||||||
|
"RA_FQDN_IPSET_URL",
|
||||||
|
"RA_FQDN_DMASK_URL",
|
||||||
|
"RA_FQDN_STAT_URL",
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
for k, v in cfg_dict.items():
|
for k, v in cfg_dict.items():
|
||||||
if k in config_arrays:
|
if k in config_sets:
|
||||||
value = {normalize_string(i) for i in v.split(" ")}
|
value = {normalize_string(i) for i in v.split(" ")}
|
||||||
|
elif k in config_arrays:
|
||||||
|
value = [normalize_string(i) for i in v.split(" ")]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
value = int(v)
|
value = int(v)
|
||||||
@@ -159,10 +178,11 @@ class BlackListParser(Config):
|
|||||||
self.proxies = None
|
self.proxies = None
|
||||||
self.connect_timeout = None
|
self.connect_timeout = None
|
||||||
self.data_chunk = 2048
|
self.data_chunk = 2048
|
||||||
self.url = "http://127.0.0.1"
|
self.url = ["http://127.0.0.1"]
|
||||||
self.records_separator = "\n"
|
self.records_separator = "\n"
|
||||||
self.default_site_encoding = "utf-8"
|
self.default_site_encoding = "utf-8"
|
||||||
self.site_encoding = self.default_site_encoding
|
self.site_encoding = self.default_site_encoding
|
||||||
|
self.rest = bytes()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _compile_filter_patterns(filters_seq):
|
def _compile_filter_patterns(filters_seq):
|
||||||
@@ -201,14 +221,14 @@ class BlackListParser(Config):
|
|||||||
try:
|
try:
|
||||||
yield (conn_object, http_code, received_headers)
|
yield (conn_object, http_code, received_headers)
|
||||||
except Exception as exception_object:
|
except Exception as exception_object:
|
||||||
raise ParserError(f"Parser error! {exception_object} ( {self.url} )")
|
raise ParserError(f"Parser error! {exception_object} ( {url} )")
|
||||||
finally:
|
finally:
|
||||||
if conn_object:
|
if conn_object:
|
||||||
conn_object.close()
|
conn_object.close()
|
||||||
|
|
||||||
def _download_data(self):
|
def _download_data(self, url):
|
||||||
with self._make_connection(
|
with self._make_connection(
|
||||||
self.url,
|
url,
|
||||||
send_headers_dict=self.send_headers_dict,
|
send_headers_dict=self.send_headers_dict,
|
||||||
timeout=self.connect_timeout
|
timeout=self.connect_timeout
|
||||||
) as conn_params:
|
) as conn_params:
|
||||||
@@ -220,17 +240,16 @@ class BlackListParser(Config):
|
|||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
|
|
||||||
def _align_chunk(self):
|
def _align_chunk(self, url):
|
||||||
rest = bytes()
|
for chunk in self._download_data(url):
|
||||||
for chunk in self._download_data():
|
|
||||||
if chunk is None:
|
if chunk is None:
|
||||||
yield rest
|
yield self.rest
|
||||||
continue
|
continue
|
||||||
data, _, rest = (rest + chunk).rpartition(self.records_separator)
|
data, _, self.rest = (self.rest + chunk).rpartition(self.records_separator)
|
||||||
yield data
|
yield data
|
||||||
|
|
||||||
def _split_entries(self):
|
def _split_entries(self, url):
|
||||||
for chunk in self._align_chunk():
|
for chunk in self._align_chunk(url):
|
||||||
for entry in chunk.split(self.records_separator):
|
for entry in chunk.split(self.records_separator):
|
||||||
try:
|
try:
|
||||||
yield entry.decode(
|
yield entry.decode(
|
||||||
@@ -331,6 +350,7 @@ class BlackListParser(Config):
|
|||||||
ret_value = 0
|
ret_value = 0
|
||||||
else:
|
else:
|
||||||
ret_value = 2
|
ret_value = 2
|
||||||
|
self.rest = bytes()
|
||||||
return ret_value
|
return ret_value
|
||||||
|
|
||||||
|
|
||||||
@@ -545,21 +565,22 @@ class RblFQDN(BlackListParser):
|
|||||||
self.ips_separator = ", "
|
self.ips_separator = ", "
|
||||||
|
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for entry in self._split_entries():
|
for url in self.url:
|
||||||
res = re.search(r'"domains": \["?(.*?)"?\].*?"ips": \[([a-f0-9/.:", ]*)\]', entry)
|
for entry in self._split_entries(url):
|
||||||
if not res:
|
res = re.search(r'"domains": \["?(.*?)"?\].*?"ips": \[([a-f0-9/.:", ]*)\]', entry)
|
||||||
continue
|
if not res:
|
||||||
ip_string = res.group(2).replace('"', "")
|
continue
|
||||||
fqdn_string = res.group(1)
|
ip_string = res.group(2).replace('"', "")
|
||||||
if fqdn_string:
|
fqdn_string = res.group(1)
|
||||||
try:
|
if fqdn_string:
|
||||||
self.fqdn_value_processing(fqdn_string)
|
try:
|
||||||
except FieldValueError:
|
self.fqdn_value_processing(fqdn_string)
|
||||||
|
except FieldValueError:
|
||||||
|
for i in ip_string.split(self.ips_separator):
|
||||||
|
self.ip_value_processing(i)
|
||||||
|
else:
|
||||||
for i in ip_string.split(self.ips_separator):
|
for i in ip_string.split(self.ips_separator):
|
||||||
self.ip_value_processing(i)
|
self.ip_value_processing(i)
|
||||||
else:
|
|
||||||
for i in ip_string.split(self.ips_separator):
|
|
||||||
self.ip_value_processing(i)
|
|
||||||
|
|
||||||
class RblDPI(BlackListParser):
|
class RblDPI(BlackListParser):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -569,17 +590,18 @@ class RblDPI(BlackListParser):
|
|||||||
self.records_separator = '{"domains"'
|
self.records_separator = '{"domains"'
|
||||||
|
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for entry in self._split_entries():
|
for url in self.url:
|
||||||
res = re.search(r': \[(.*?)\]', entry)
|
for entry in self._split_entries(url):
|
||||||
if not res:
|
res = re.search(r': \[(.*?)\]', entry)
|
||||||
continue
|
if not res:
|
||||||
fqdn_string = res.group(1)
|
continue
|
||||||
if fqdn_string:
|
fqdn_string = res.group(1)
|
||||||
for i in fqdn_string.split(', "'):
|
if fqdn_string:
|
||||||
try:
|
for i in fqdn_string.split(', "'):
|
||||||
self.fqdn_value_processing(i.strip('"'))
|
try:
|
||||||
except FieldValueError:
|
self.fqdn_value_processing(i.strip('"'))
|
||||||
pass
|
except FieldValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
class RblIp(BlackListParser):
|
class RblIp(BlackListParser):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -588,8 +610,9 @@ class RblIp(BlackListParser):
|
|||||||
self.records_separator = ","
|
self.records_separator = ","
|
||||||
|
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for entry in self._split_entries():
|
for url in self.url:
|
||||||
self.ip_value_processing(re.sub(r'[\[\]" ]', "", entry))
|
for entry in self._split_entries(url):
|
||||||
|
self.ip_value_processing(re.sub(r'[\[\]" ]', "", entry))
|
||||||
|
|
||||||
|
|
||||||
class ZiFQDN(BlackListParser):
|
class ZiFQDN(BlackListParser):
|
||||||
@@ -601,28 +624,30 @@ class ZiFQDN(BlackListParser):
|
|||||||
self.ips_separator = "|"
|
self.ips_separator = "|"
|
||||||
|
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for entry in self._split_entries():
|
for url in self.url:
|
||||||
entry_list = entry.split(self.fields_separator)
|
for entry in self._split_entries(url):
|
||||||
try:
|
entry_list = entry.split(self.fields_separator)
|
||||||
if entry_list[1]:
|
try:
|
||||||
try:
|
if entry_list[1]:
|
||||||
self.fqdn_value_processing(entry_list[1])
|
try:
|
||||||
except FieldValueError:
|
self.fqdn_value_processing(entry_list[1])
|
||||||
|
except FieldValueError:
|
||||||
|
for i in entry_list[0].split(self.ips_separator):
|
||||||
|
self.ip_value_processing(i)
|
||||||
|
else:
|
||||||
for i in entry_list[0].split(self.ips_separator):
|
for i in entry_list[0].split(self.ips_separator):
|
||||||
self.ip_value_processing(i)
|
self.ip_value_processing(i)
|
||||||
else:
|
except IndexError:
|
||||||
for i in entry_list[0].split(self.ips_separator):
|
pass
|
||||||
self.ip_value_processing(i)
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ZiIp(ZiFQDN):
|
class ZiIp(ZiFQDN):
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for entry in self._split_entries():
|
for url in self.url:
|
||||||
entry_list = entry.split(self.fields_separator)
|
for entry in self._split_entries(url):
|
||||||
for i in entry_list[0].split(self.ips_separator):
|
entry_list = entry.split(self.fields_separator)
|
||||||
self.ip_value_processing(i)
|
for i in entry_list[0].split(self.ips_separator):
|
||||||
|
self.ip_value_processing(i)
|
||||||
|
|
||||||
|
|
||||||
class AfFQDN(BlackListParser):
|
class AfFQDN(BlackListParser):
|
||||||
@@ -631,11 +656,12 @@ class AfFQDN(BlackListParser):
|
|||||||
self.url = self.AF_FQDN_URL
|
self.url = self.AF_FQDN_URL
|
||||||
|
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for entry in self._split_entries():
|
for url in self.url:
|
||||||
try:
|
for entry in self._split_entries(url):
|
||||||
self.fqdn_value_processing(entry)
|
try:
|
||||||
except FieldValueError:
|
self.fqdn_value_processing(entry)
|
||||||
self.ip_value_processing(entry)
|
except FieldValueError:
|
||||||
|
self.ip_value_processing(entry)
|
||||||
|
|
||||||
|
|
||||||
class AfIp(BlackListParser):
|
class AfIp(BlackListParser):
|
||||||
@@ -644,8 +670,50 @@ class AfIp(BlackListParser):
|
|||||||
self.url = self.AF_IP_URL
|
self.url = self.AF_IP_URL
|
||||||
|
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for entry in self._split_entries():
|
for url in self.url:
|
||||||
self.ip_value_processing(entry)
|
for entry in self._split_entries(url):
|
||||||
|
self.ip_value_processing(entry)
|
||||||
|
|
||||||
|
|
||||||
|
class FzFQDN(BlackListParser):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.url = self.FZ_URL
|
||||||
|
self.site_encoding = self.FZ_ENCODING
|
||||||
|
self.records_separator = "</content>"
|
||||||
|
self.fqdn_value_regexp = re.compile(r"<domain><\!\[CDATA\[(.*?)\]\]></domain>", re.U)
|
||||||
|
self.ip_value_regexp = re.compile(r"<ip>(.*?)</ip>")
|
||||||
|
self.cidr_value_regexp = re.compile(r"<ipSubnet>(.*?)</ipSubnet>")
|
||||||
|
|
||||||
|
def parser_func(self):
|
||||||
|
for url in self.url:
|
||||||
|
for entry in self._split_entries(url):
|
||||||
|
res = self.fqdn_value_regexp.search(entry)
|
||||||
|
if res and res.group(1):
|
||||||
|
try:
|
||||||
|
self.fqdn_value_processing(res.group(1))
|
||||||
|
except FieldValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
for i in self.ip_value_regexp.finditer(entry):
|
||||||
|
if i.group(1):
|
||||||
|
self.ip_value_processing(i.group(1))
|
||||||
|
for i in self.cidr_value_regexp.finditer(entry):
|
||||||
|
if i.group(1):
|
||||||
|
self.ip_value_processing(i.group(1))
|
||||||
|
|
||||||
|
|
||||||
|
class FzIp(FzFQDN):
|
||||||
|
def parser_func(self):
|
||||||
|
for url in self.url:
|
||||||
|
for entry in self._split_entries(url):
|
||||||
|
for i in self.ip_value_regexp.finditer(entry):
|
||||||
|
if i.group(1):
|
||||||
|
self.ip_value_processing(i.group(1))
|
||||||
|
for i in self.cidr_value_regexp.finditer(entry):
|
||||||
|
if i.group(1):
|
||||||
|
self.ip_value_processing(i.group(1))
|
||||||
|
|
||||||
|
|
||||||
class RaFQDN(BlackListParser):
|
class RaFQDN(BlackListParser):
|
||||||
@@ -657,7 +725,7 @@ class RaFQDN(BlackListParser):
|
|||||||
self.current_file_handler = None
|
self.current_file_handler = None
|
||||||
|
|
||||||
def parser_func(self):
|
def parser_func(self):
|
||||||
for chunk in self._download_data():
|
for chunk in self._download_data(self.url[0]):
|
||||||
if chunk:
|
if chunk:
|
||||||
self.current_file_handler.write(chunk)
|
self.current_file_handler.write(chunk)
|
||||||
|
|
||||||
@@ -686,8 +754,8 @@ if __name__ == "__main__":
|
|||||||
Config.load_fqdn_filter()
|
Config.load_fqdn_filter()
|
||||||
Config.load_ip_filter()
|
Config.load_ip_filter()
|
||||||
parsers_dict = {
|
parsers_dict = {
|
||||||
"ip": {"rublacklist": [RblIp], "zapret-info": [ZiIp], "antifilter": [AfIp], "ruantiblock": [RaIp]},
|
"ip": {"rublacklist": [RblIp], "zapret-info": [ZiIp], "antifilter": [AfIp], "fz": [FzIp], "ruantiblock": [RaIp]},
|
||||||
"fqdn": {"rublacklist": [RblFQDN, RblDPI], "zapret-info": [ZiFQDN], "antifilter": [AfFQDN], "ruantiblock": [RaFQDN]},
|
"fqdn": {"rublacklist": [RblFQDN, RblDPI], "zapret-info": [ZiFQDN], "antifilter": [AfFQDN], "fz": [FzFQDN], "ruantiblock": [RaFQDN]},
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
parser_classes = parsers_dict[Config.BLLIST_MODE][Config.BLLIST_SOURCE]
|
parser_classes = parsers_dict[Config.BLLIST_MODE][Config.BLLIST_SOURCE]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=ruantiblock
|
PKG_NAME:=ruantiblock
|
||||||
PKG_VERSION:=1.4
|
PKG_VERSION:=1.4
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
|
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
|
||||||
|
|
||||||
include $(INCLUDE_DIR)/package.mk
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ BLLIST_MODULE=""
|
|||||||
|
|
||||||
### Настройки модулей-парсеров ###
|
### Настройки модулей-парсеров ###
|
||||||
|
|
||||||
### Режим обхода блокировок: ruantiblock-fqdn, ruantiblock-ip, zapret-info-fqdn, zapret-info-ip, rublacklist-fqdn, rublacklist-ip, antifilter-ip
|
### Режим обхода блокировок: ruantiblock-fqdn, ruantiblock-ip, zapret-info-fqdn, zapret-info-ip, rublacklist-fqdn, rublacklist-ip, antifilter-ip, fz-fqdn, fz-ip
|
||||||
BLLIST_PRESET=""
|
BLLIST_PRESET=""
|
||||||
### В случае если из источника получено менее указанного кол-ва записей, то обновления списков не происходит
|
### В случае если из источника получено менее указанного кол-ва записей, то обновления списков не происходит
|
||||||
BLLIST_MIN_ENTRIES=3000
|
BLLIST_MIN_ENTRIES=3000
|
||||||
@@ -154,6 +154,7 @@ 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"
|
#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"
|
AF_IP_URL="https://antifilter.download/list/allyouneed.lst"
|
||||||
AF_FQDN_URL="https://antifilter.download/list/domains.lst"
|
AF_FQDN_URL="https://antifilter.download/list/domains.lst"
|
||||||
|
FZ_URL="https://raw.githubusercontent.com/fz139/vigruzki/main/dump.xml.00 https://raw.githubusercontent.com/fz139/vigruzki/main/dump.xml.01 https://raw.githubusercontent.com/fz139/vigruzki/main/dump.xml.02"
|
||||||
RA_IP_IPSET_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.ip"
|
RA_IP_IPSET_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.ip"
|
||||||
RA_IP_DMASK_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.dnsmasq"
|
RA_IP_DMASK_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.dnsmasq"
|
||||||
RA_IP_STAT_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/update_status"
|
RA_IP_STAT_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/update_status"
|
||||||
@@ -163,4 +164,5 @@ RA_FQDN_STAT_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blackli
|
|||||||
RBL_ENCODING=""
|
RBL_ENCODING=""
|
||||||
ZI_ENCODING="CP1251"
|
ZI_ENCODING="CP1251"
|
||||||
AF_ENCODING=""
|
AF_ENCODING=""
|
||||||
|
FZ_ENCODING="CP1251"
|
||||||
RA_ENCODING=""
|
RA_ENCODING=""
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ export BLLIST_MODULE=""
|
|||||||
|
|
||||||
##############################
|
##############################
|
||||||
|
|
||||||
### Режим обхода блокировок: ruantiblock-fqdn, ruantiblock-ip, zapret-info-fqdn, zapret-info-ip, rublacklist-fqdn, rublacklist-ip, antifilter-ip
|
### Режим обхода блокировок: ruantiblock-fqdn, ruantiblock-ip, zapret-info-fqdn, zapret-info-ip, rublacklist-fqdn, rublacklist-ip, antifilter-ip, fz-fqdn, fz-ip
|
||||||
export BLLIST_PRESET=""
|
export BLLIST_PRESET=""
|
||||||
### В случае если из источника получено менее указанного кол-ва записей, то обновления списков не происходит
|
### В случае если из источника получено менее указанного кол-ва записей, то обновления списков не происходит
|
||||||
export BLLIST_MIN_ENTRIES=3000
|
export BLLIST_MIN_ENTRIES=3000
|
||||||
@@ -170,6 +170,7 @@ export RBL_DPI_URL="https://reestr.rublacklist.net/api/v3/dpi/"
|
|||||||
export ZI_ALL_URL="https://raw.githubusercontent.com/zapret-info/z-i/master/dump.csv"
|
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_IP_URL="https://antifilter.download/list/allyouneed.lst"
|
||||||
export AF_FQDN_URL="https://antifilter.download/list/domains.lst"
|
export AF_FQDN_URL="https://antifilter.download/list/domains.lst"
|
||||||
|
export FZ_URL="https://raw.githubusercontent.com/fz139/vigruzki/main/dump.xml.00 https://raw.githubusercontent.com/fz139/vigruzki/main/dump.xml.01 https://raw.githubusercontent.com/fz139/vigruzki/main/dump.xml.02"
|
||||||
export RA_IP_IPSET_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.ip"
|
export RA_IP_IPSET_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.ip"
|
||||||
export RA_IP_DMASK_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.dnsmasq"
|
export RA_IP_DMASK_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/ruantiblock.dnsmasq"
|
||||||
export RA_IP_STAT_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/update_status"
|
export RA_IP_STAT_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_blacklist/master/blacklist-1.1/ip/update_status"
|
||||||
@@ -179,6 +180,7 @@ export RA_FQDN_STAT_URL="https://raw.githubusercontent.com/gSpotx2f/ruantiblock_
|
|||||||
export RBL_ENCODING=""
|
export RBL_ENCODING=""
|
||||||
export ZI_ENCODING="CP1251"
|
export ZI_ENCODING="CP1251"
|
||||||
export AF_ENCODING=""
|
export AF_ENCODING=""
|
||||||
|
export FZ_ENCODING="CP1251"
|
||||||
export RA_ENCODING=""
|
export RA_ENCODING=""
|
||||||
|
|
||||||
############################ Configuration #############################
|
############################ Configuration #############################
|
||||||
@@ -596,9 +598,9 @@ GetDataFiles() {
|
|||||||
if [ "$ENABLE_BLLIST_PROXY" = "1" ]; then
|
if [ "$ENABLE_BLLIST_PROXY" = "1" ]; then
|
||||||
FlushNftSets "$NFTSET_BLLIST_PROXY"
|
FlushNftSets "$NFTSET_BLLIST_PROXY"
|
||||||
fi
|
fi
|
||||||
AddUserEntries
|
|
||||||
AddBypassEntries
|
|
||||||
if [ $_return_code -eq 0 ]; then
|
if [ $_return_code -eq 0 ]; then
|
||||||
|
AddUserEntries
|
||||||
|
AddBypassEntries
|
||||||
_update_string=`$AWK_CMD '{
|
_update_string=`$AWK_CMD '{
|
||||||
printf "Received entries: %s\n", (NF < 3) ? "No data" : "CIDR: "$1", IP: "$2", FQDN: "$3;
|
printf "Received entries: %s\n", (NF < 3) ? "No data" : "CIDR: "$1", IP: "$2", FQDN: "$3;
|
||||||
exit;
|
exit;
|
||||||
@@ -828,6 +830,14 @@ case "$BLLIST_PRESET" in
|
|||||||
export BLLIST_SOURCE="antifilter"
|
export BLLIST_SOURCE="antifilter"
|
||||||
export BLLIST_MODE="ip"
|
export BLLIST_MODE="ip"
|
||||||
;;
|
;;
|
||||||
|
fz-ip)
|
||||||
|
export BLLIST_SOURCE="fz"
|
||||||
|
export BLLIST_MODE="ip"
|
||||||
|
;;
|
||||||
|
fz-fqdn)
|
||||||
|
export BLLIST_SOURCE="fz"
|
||||||
|
export BLLIST_MODE="fqdn"
|
||||||
|
;;
|
||||||
ruantiblock-ip)
|
ruantiblock-ip)
|
||||||
export BLLIST_SOURCE="ruantiblock"
|
export BLLIST_SOURCE="ruantiblock"
|
||||||
export BLLIST_MODE="ip"
|
export BLLIST_MODE="ip"
|
||||||
|
|||||||
Reference in New Issue
Block a user