update 2025-03-04 04:23:36
This commit is contained in:
parent
c0bcb90923
commit
eec891efcb
|
@ -12,7 +12,6 @@ PKG_RELEASE:=1
|
|||
PKG_CONFIG_DEPENDS:= \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_Nftables_Transparent_Proxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Geoview \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Haproxy \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_Hysteria \
|
||||
CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_NaiveProxy \
|
||||
|
@ -36,7 +35,7 @@ LUCI_PKGARCH:=all
|
|||
LUCI_DEPENDS:=+coreutils +coreutils-base64 +coreutils-nohup +curl \
|
||||
+chinadns-ng +dns2socks +dnsmasq-full +ip-full \
|
||||
+libuci-lua +lua +luci-compat +luci-lib-jsonc \
|
||||
+microsocks +resolveip +tcping
|
||||
+microsocks +resolveip +tcping +geoview
|
||||
|
||||
define Package/$(PKG_NAME)/config
|
||||
menu "Configuration"
|
||||
|
@ -64,11 +63,6 @@ config PACKAGE_$(PKG_NAME)_Nftables_Transparent_Proxy
|
|||
select PACKAGE_kmod-nft-nat
|
||||
default y if PACKAGE_firewall4
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_Geoview
|
||||
bool "Include Geoview"
|
||||
select PACKAGE_geoview
|
||||
default y if aarch64||arm||i386||x86_64
|
||||
|
||||
config PACKAGE_$(PKG_NAME)_INCLUDE_Haproxy
|
||||
bool "Include Haproxy"
|
||||
select PACKAGE_haproxy
|
||||
|
|
|
@ -242,42 +242,6 @@ if has_singbox then
|
|||
o.default = 0
|
||||
o.rmempty = false
|
||||
o.description = translate("Override the connection destination address with the sniffed domain.<br />When enabled, traffic will match only by domain, ignoring IP rules.<br />If using shunt nodes, configure the domain shunt rules correctly.")
|
||||
|
||||
o = s:option(Value, "geoip_path", translate("Custom geoip Path"))
|
||||
o.default = "/usr/share/singbox/geoip.db"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "geoip_url", translate("Custom geoip URL"))
|
||||
o.default = "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.db"
|
||||
o:value("https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.db")
|
||||
o:value("https://github.com/1715173329/sing-geoip/releases/latest/download/geoip.db")
|
||||
o:value("https://github.com/lyc8503/sing-box-rules/releases/latest/download/geoip.db")
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "geosite_path", translate("Custom geosite Path"))
|
||||
o.default = "/usr/share/singbox/geosite.db"
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Value, "geosite_url", translate("Custom geosite URL"))
|
||||
o.default = "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.db"
|
||||
o:value("https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.db")
|
||||
o:value("https://github.com/1715173329/sing-geosite/releases/latest/download/geosite.db")
|
||||
o:value("https://github.com/lyc8503/sing-box-rules/releases/latest/download/geosite.db")
|
||||
o.rmempty = false
|
||||
|
||||
o = s:option(Button, "_remove_resource", translate("Remove resource files"))
|
||||
o.description = translate("Sing-Box will automatically download resource files when starting, you can use this feature achieve upgrade resource files.")
|
||||
o.inputstyle = "remove"
|
||||
function o.write(self, section, value)
|
||||
local geoip_path = s.fields["geoip_path"] and s.fields["geoip_path"]:formvalue(section) or nil
|
||||
if geoip_path then
|
||||
os.remove(geoip_path)
|
||||
end
|
||||
local geosite_path = s.fields["geosite_path"] and s.fields["geosite_path"]:formvalue(section) or nil
|
||||
if geosite_path then
|
||||
os.remove(geosite_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return m
|
||||
|
|
|
@ -10,6 +10,41 @@ local split = api.split
|
|||
local local_version = api.get_app_version("singbox")
|
||||
local version_ge_1_11_0 = api.compare_versions(local_version:match("[^v]+"), ">=", "1.11.0")
|
||||
|
||||
local geosite_all_tag = {}
|
||||
local geoip_all_tag = {}
|
||||
local srss_path = "/tmp/etc/" .. appname .."/srss/"
|
||||
|
||||
local function convert_geofile()
|
||||
local geo_path = uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"
|
||||
local geosite_path = geo_path:match("^(.*)/") .. "/geosite.dat"
|
||||
local geoip_path = geo_path:match("^(.*)/") .. "/geoip.dat"
|
||||
if not api.is_finded("geoview") then
|
||||
api.log("* 注意:缺少 geoview 组件,Sing-Box 分流将无法启用!")
|
||||
return
|
||||
end
|
||||
if not fs.access(srss_path) then
|
||||
fs.mkdir(srss_path)
|
||||
end
|
||||
if next(geosite_all_tag) and fs.access(geosite_path) then
|
||||
for k,v in pairs(geosite_all_tag) do
|
||||
local srs_file = srss_path .. "geosite-" .. k ..".srs"
|
||||
if not fs.access(srs_file) then
|
||||
sys.exec("geoview -type geosite -action convert -input " .. geosite_path .. " -list '" .. k .. "' -output " .. srs_file .. " -lowmem=true")
|
||||
--api.log("* 转换geosite:" .. k .. " 到 Sing-Box 规则集二进制文件")
|
||||
end
|
||||
end
|
||||
end
|
||||
if next(geoip_all_tag) and fs.access(geoip_path) then
|
||||
for k,v in pairs(geoip_all_tag) do
|
||||
local srs_file = srss_path .. "geoip-" .. k ..".srs"
|
||||
if not fs.access(srs_file) then
|
||||
sys.exec("geoview -type geoip -action convert -input " .. geoip_path .. " -list '" .. k .. "' -output " .. srs_file .. " -lowmem=true")
|
||||
--api.log("* 转换geoip:" .. k .. " 到 Sing-Box 规则集二进制文件")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local new_port
|
||||
|
||||
local function get_new_port()
|
||||
|
@ -802,17 +837,7 @@ function gen_config(var)
|
|||
local singbox_settings = uci:get_all(appname, "@global_singbox[0]") or {}
|
||||
|
||||
local route = {
|
||||
rules = {},
|
||||
geoip = {
|
||||
path = singbox_settings.geoip_path or "/usr/share/singbox/geoip.db",
|
||||
download_url = singbox_settings.geoip_url or nil,
|
||||
download_detour = nil,
|
||||
},
|
||||
geosite = {
|
||||
path = singbox_settings.geosite_path or "/usr/share/singbox/geosite.db",
|
||||
download_url = singbox_settings.geosite_url or nil,
|
||||
download_detour = nil,
|
||||
},
|
||||
rules = {}
|
||||
}
|
||||
|
||||
local experimental = nil
|
||||
|
@ -1183,17 +1208,21 @@ function gen_config(var)
|
|||
end
|
||||
|
||||
if e.source then
|
||||
local source_geoip = {}
|
||||
local source_ip_cidr = {}
|
||||
local is_private = false
|
||||
string.gsub(e.source, '[^' .. " " .. ']+', function(w)
|
||||
if w:find("geoip") == 1 then
|
||||
table.insert(source_geoip, w)
|
||||
local _geoip = w:sub(1 + #"geoip:") --适配srs
|
||||
if _geoip == "private" then
|
||||
is_private = true
|
||||
end
|
||||
else
|
||||
table.insert(source_ip_cidr, w)
|
||||
end
|
||||
end)
|
||||
rule.source_geoip = #source_geoip > 0 and source_geoip or nil
|
||||
rule.source_ip_is_private = is_private and true or nil
|
||||
rule.source_ip_cidr = #source_ip_cidr > 0 and source_ip_cidr or nil
|
||||
if is_private or #source_ip_cidr > 0 then rule.rule_set_ip_cidr_match_source = true end
|
||||
end
|
||||
|
||||
if e.sourcePort then
|
||||
|
@ -1224,6 +1253,8 @@ function gen_config(var)
|
|||
rule.port_range = #port_range > 0 and port_range or nil
|
||||
end
|
||||
|
||||
local rule_set_tag = {}
|
||||
|
||||
if e.domain_list then
|
||||
local domain_table = {
|
||||
outboundTag = outboundTag,
|
||||
|
@ -1231,12 +1262,15 @@ function gen_config(var)
|
|||
domain_suffix = {},
|
||||
domain_keyword = {},
|
||||
domain_regex = {},
|
||||
geosite = {},
|
||||
rule_set = {},
|
||||
}
|
||||
string.gsub(e.domain_list, '[^' .. "\r\n" .. ']+', function(w)
|
||||
if w:find("#") == 1 then return end
|
||||
if w:find("geosite:") == 1 then
|
||||
table.insert(domain_table.geosite, w:sub(1 + #"geosite:"))
|
||||
local _geosite = w:sub(1 + #"geosite:") --适配srs
|
||||
geosite_all_tag[_geosite] = true
|
||||
table.insert(rule_set_tag, "geosite-" .. _geosite)
|
||||
table.insert(domain_table.rule_set, "geosite-" .. _geosite)
|
||||
elseif w:find("regexp:") == 1 then
|
||||
table.insert(domain_table.domain_regex, w:sub(1 + #"regexp:"))
|
||||
elseif w:find("full:") == 1 then
|
||||
|
@ -1251,7 +1285,6 @@ function gen_config(var)
|
|||
rule.domain_suffix = #domain_table.domain_suffix > 0 and domain_table.domain_suffix or nil
|
||||
rule.domain_keyword = #domain_table.domain_keyword > 0 and domain_table.domain_keyword or nil
|
||||
rule.domain_regex = #domain_table.domain_regex > 0 and domain_table.domain_regex or nil
|
||||
rule.geosite = #domain_table.geosite > 0 and domain_table.geosite or nil
|
||||
|
||||
if outboundTag then
|
||||
table.insert(dns_domain_rules, api.clone(domain_table))
|
||||
|
@ -1260,20 +1293,28 @@ function gen_config(var)
|
|||
|
||||
if e.ip_list then
|
||||
local ip_cidr = {}
|
||||
local geoip = {}
|
||||
local is_private = false
|
||||
string.gsub(e.ip_list, '[^' .. "\r\n" .. ']+', function(w)
|
||||
if w:find("#") == 1 then return end
|
||||
if w:find("geoip:") == 1 then
|
||||
table.insert(geoip, w:sub(1 + #"geoip:"))
|
||||
local _geoip = w:sub(1 + #"geoip:") --适配srs
|
||||
if _geoip == "private" then
|
||||
is_private = true
|
||||
else
|
||||
geoip_all_tag[_geoip] = true
|
||||
table.insert(rule_set_tag, "geoip-" .. _geoip)
|
||||
end
|
||||
else
|
||||
table.insert(ip_cidr, w)
|
||||
end
|
||||
end)
|
||||
|
||||
rule.ip_is_private = is_private and true or nil
|
||||
rule.ip_cidr = #ip_cidr > 0 and ip_cidr or nil
|
||||
rule.geoip = #geoip > 0 and geoip or nil
|
||||
end
|
||||
|
||||
rule.rule_set = #rule_set_tag > 0 and rule_set_tag or nil --适配srs
|
||||
|
||||
table.insert(rules, rule)
|
||||
end
|
||||
end)
|
||||
|
@ -1281,6 +1322,34 @@ function gen_config(var)
|
|||
for index, value in ipairs(rules) do
|
||||
table.insert(route.rules, rules[index])
|
||||
end
|
||||
|
||||
local rule_set = {} --适配srs
|
||||
if next(geosite_all_tag) then
|
||||
for k,v in pairs(geosite_all_tag) do
|
||||
local srs_file = srss_path .. "geosite-" .. k ..".srs"
|
||||
local _rule_set = {
|
||||
tag = "geosite-" .. k,
|
||||
type = "local",
|
||||
format = "binary",
|
||||
path = srs_file
|
||||
}
|
||||
table.insert(rule_set, _rule_set)
|
||||
end
|
||||
end
|
||||
if next(geoip_all_tag) then
|
||||
for k,v in pairs(geoip_all_tag) do
|
||||
local srs_file = srss_path .. "geoip-" .. k ..".srs"
|
||||
local _rule_set = {
|
||||
tag = "geoip-" .. k,
|
||||
type = "local",
|
||||
format = "binary",
|
||||
path = srs_file
|
||||
}
|
||||
table.insert(rule_set, _rule_set)
|
||||
end
|
||||
end
|
||||
route.rule_set = #rule_set >0 and rule_set or nil
|
||||
|
||||
elseif node.protocol == "_urltest" then
|
||||
if node.urltest_node then
|
||||
COMMON.default_outbound_tag = gen_urltest(node)
|
||||
|
@ -1470,14 +1539,14 @@ function gen_config(var)
|
|||
--按分流顺序DNS
|
||||
if dns_domain_rules and #dns_domain_rules > 0 then
|
||||
for index, value in ipairs(dns_domain_rules) do
|
||||
if value.outboundTag and (value.domain or value.domain_suffix or value.domain_keyword or value.domain_regex or value.geosite) then
|
||||
if value.outboundTag and (value.domain or value.domain_suffix or value.domain_keyword or value.domain_regex or value.rule_set) then
|
||||
local dns_rule = {
|
||||
server = value.outboundTag,
|
||||
domain = (value.domain and #value.domain > 0) and value.domain or nil,
|
||||
domain_suffix = (value.domain_suffix and #value.domain_suffix > 0) and value.domain_suffix or nil,
|
||||
domain_keyword = (value.domain_keyword and #value.domain_keyword > 0) and value.domain_keyword or nil,
|
||||
domain_regex = (value.domain_regex and #value.domain_regex > 0) and value.domain_regex or nil,
|
||||
geosite = (value.geosite and #value.geosite > 0) and value.geosite or nil,
|
||||
rule_set = (value.rule_set and #value.rule_set > 0) and value.rule_set or nil, --适配srs
|
||||
disable_cache = false,
|
||||
}
|
||||
if value.outboundTag ~= "block" and value.outboundTag ~= "direct" then
|
||||
|
@ -1737,5 +1806,8 @@ if arg[1] then
|
|||
local func =_G[arg[1]]
|
||||
if func then
|
||||
print(func(api.get_function_args(arg)))
|
||||
if next(geosite_all_tag) or next(geoip_all_tag) then
|
||||
convert_geofile()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1633,24 +1633,6 @@ msgstr "端口跳跃额外端口"
|
|||
msgid "HeartbeatPeriod(second)"
|
||||
msgstr "心跳周期(单位:秒)"
|
||||
|
||||
msgid "Custom geoip Path"
|
||||
msgstr "自定义 geoip 文件路径"
|
||||
|
||||
msgid "Custom geoip URL"
|
||||
msgstr "自定义 geoip 文件更新链接"
|
||||
|
||||
msgid "Custom geosite Path"
|
||||
msgstr "自定义 geosite 文件路径"
|
||||
|
||||
msgid "Custom geosite URL"
|
||||
msgstr "自定义 geosite 文件更新链接"
|
||||
|
||||
msgid "Remove resource files"
|
||||
msgstr "删除资源文件"
|
||||
|
||||
msgid "Sing-Box will automatically download resource files when starting, you can use this feature achieve upgrade resource files."
|
||||
msgstr "Sing-Box 会在启动时自动下载资源文件,您可以使用此功能实现升级资源文件。"
|
||||
|
||||
msgid "Override the connection destination address"
|
||||
msgstr "覆盖连接目标地址"
|
||||
|
||||
|
|
|
@ -51,10 +51,6 @@ config global_xray
|
|||
|
||||
config global_singbox
|
||||
option sniff_override_destination '0'
|
||||
option geoip_path '/usr/share/singbox/geoip.db'
|
||||
option geoip_url 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.db'
|
||||
option geosite_path '/usr/share/singbox/geosite.db'
|
||||
option geosite_url 'https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.db'
|
||||
|
||||
config global_other
|
||||
option auto_detection_time 'tcping'
|
||||
|
|
|
@ -777,8 +777,9 @@ run_redir() {
|
|||
sing-box)
|
||||
local protocol=$(config_n_get $node protocol)
|
||||
[ "$protocol" = "_shunt" ] && {
|
||||
local geoip_path="$(config_t_get global_singbox geoip_path)"
|
||||
local geosite_path="$(config_t_get global_singbox geosite_path)"
|
||||
local geo_path="$(config_t_get global_rules v2ray_location_asset)"
|
||||
local geoip_path="${geo_path%*/}/geoip.dat"
|
||||
local geosite_path="${geo_path%*/}/geosite.dat"
|
||||
if [ ! -s "$geoip_path" ] || [ ! -s "$geosite_path" ]; then
|
||||
echolog "* 缺少Geo规则文件,UDP Sing-Box分流节点无法正常使用!"
|
||||
fi
|
||||
|
@ -895,8 +896,9 @@ run_redir() {
|
|||
}
|
||||
|
||||
[ "$protocol" = "_shunt" ] && {
|
||||
local geoip_path="$(config_t_get global_singbox geoip_path)"
|
||||
local geosite_path="$(config_t_get global_singbox geosite_path)"
|
||||
local geo_path="$(config_t_get global_rules v2ray_location_asset)"
|
||||
local geoip_path="${geo_path%*/}/geoip.dat"
|
||||
local geosite_path="${geo_path%*/}/geosite.dat"
|
||||
if [ ! -s "$geoip_path" ] || [ ! -s "$geosite_path" ]; then
|
||||
echolog "* 缺少Geo规则文件,TCP Sing-Box分流节点无法正常使用!"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue