From 3599f53aee70643bcac6c8a89dca9bf0231b9b40 Mon Sep 17 00:00:00 2001 From: gitea-action Date: Thu, 7 Nov 2024 00:02:22 +0800 Subject: [PATCH] luci-app-ssr-plus: sync upstream last commit: https://github.com/fw876/helloworld/commit/04bb122a0a4fae809f2f4f1b81409c3204d819f7 --- .../root/usr/share/shadowsocksr/update.lua | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua b/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua index 7a179b87a..70bf2249c 100755 --- a/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua +++ b/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua @@ -10,6 +10,7 @@ local icount = 0 local args = arg[1] local uci = luci.model.uci.cursor() local TMP_DNSMASQ_PATH = "${DNSMASQ_CONF_DIR%*/}/dnsmasq-ssrplus.d" +luci.sys.call("mkdir -p " .. TMP_DNSMASQ_PATH) local TMP_PATH = "/var/etc/ssrplus" -- match comments/title/whitelist/ip address/excluded_domain local comment_pattern = "^[!\\[@]+" @@ -54,22 +55,23 @@ local function check_excluded_domain(value) end -- gfwlist转码至dnsmasq格式 local function generate_gfwlist(type) - local domains = {} - local out = io.open("/tmp/ssr-update." .. type, "w") - for line in io.lines("/tmp/ssr-update.tmp") do - if not (string.find(line, comment_pattern) or string.find(line, ip_pattern) or check_excluded_domain(line)) then - local start, finish, match = string.find(line, domain_pattern) - if (start) then - domains[match] = true - end - end - end - for k, v in pairs(domains) do - out:write(string.format("server=/%s/%s#%s\n", k, mydnsip, mydnsport)) - out:write(string.format("ipset=/%s/%s\n", k, ipsetname)) - end - out:close() - os.remove("/tmp/ssr-update.tmp") + local domains, domains_map = {}, {} + local out = io.open("/tmp/ssr-update." .. type, "w") + for line in io.lines("/tmp/ssr-update.tmp") do + if not (string.find(line, comment_pattern) or string.find(line, ip_pattern) or check_excluded_domain(line)) then + local start, finish, match = string.find(line, domain_pattern) + if start and not domains_map[match] then + domains_map[match] = true + table.insert(domains, match) + end + end + end + for _, domain in ipairs(domains) do + out:write(string.format("server=/%s/%s#%s\n", domain, mydnsip, mydnsport)) + out:write(string.format("ipset=/%s/%s\n", domain, ipsetname)) + end + out:close() + os.remove("/tmp/ssr-update.tmp") end -- adblock转码至dnsmasq格式