From 62ec3bfa9de27bffd60de389f8f445b2807021b3 Mon Sep 17 00:00:00 2001 From: Max Zhao Date: Sat, 22 Feb 2020 12:45:34 +0800 Subject: [PATCH] luci-app-ssr-plus: support custom url to update chnroute (#3221) * luci-app-ssr-plus: support custom url to update chnroute * Update ssr-plus.po * Update update.lua * Update advanced.lua * Update Makefile Co-authored-by: coolsnowwolf <31687149+coolsnowwolf@users.noreply.github.com> --- package/lean/luci-app-ssr-plus/Makefile | 3 +- .../luasrc/controller/shadowsocksr.lua | 30 +++++++++++-------- .../model/cbi/shadowsocksr/advanced.lua | 10 +++++++ .../luci-app-ssr-plus/po/zh-cn/ssr-plus.po | 9 ++++++ .../root/usr/share/shadowsocksr/update.lua | 12 +++++--- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/package/lean/luci-app-ssr-plus/Makefile b/package/lean/luci-app-ssr-plus/Makefile index 9d826919f..680b2c13d 100644 --- a/package/lean/luci-app-ssr-plus/Makefile +++ b/package/lean/luci-app-ssr-plus/Makefile @@ -2,7 +2,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-ssr-plus PKG_VERSION:=150 -PKG_RELEASE:=1 +PKG_RELEASE:=2 + PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) include $(INCLUDE_DIR)/package.mk diff --git a/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua b/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua index 16312f251..d882b2ed2 100644 --- a/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua +++ b/package/lean/luci-app-ssr-plus/luasrc/controller/shadowsocksr.lua @@ -99,21 +99,25 @@ else retstring ="-1" end elseif set == "ip_data" then -refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" -sret=luci.sys.call(refresh_cmd) -icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") -if sret== 0 and tonumber(icount)>1000 then - oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") - if tonumber(icount) ~= tonumber(oldcount) then - luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt") - retstring=tostring(tonumber(icount)) + if (luci.model.uci.cursor():get_first('shadowsocksr', 'global', 'chnroute', '0') == '1') then + refresh_cmd="wget-ssl --no-check-certificate -O - " .. luci.model.uci.cursor():get_first('shadowsocksr', 'global', 'chnroute_url', 'https://pexcn.me/daily/chnroute/chnroute.txt') .. ' > /tmp/china_ssr.txt 2>/dev/null' else - retstring ="0" + refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" end -else - retstring ="-1" -end -luci.sys.exec("rm -f /tmp/china_ssr.txt ") + sret=luci.sys.call(refresh_cmd) + icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") + if sret== 0 and tonumber(icount)>1000 then + oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") + if tonumber(icount) ~= tonumber(oldcount) then + luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt") + retstring=tostring(tonumber(icount)) + else + retstring ="0" + end + else + retstring ="-1" + end + luci.sys.exec("rm -f /tmp/china_ssr.txt ") else if nixio.fs.access("/usr/bin/wget-ssl") then refresh_cmd="wget-ssl --no-check-certificate -O - ".. luci.model.uci.cursor():get_first('shadowsocksr', 'global', 'adblock_url','https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt') .." > /tmp/adnew.conf" diff --git a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua index c72cc5875..7e1070cb1 100644 --- a/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua +++ b/package/lean/luci-app-ssr-plus/luasrc/model/cbi/shadowsocksr/advanced.lua @@ -54,6 +54,16 @@ o.rmempty = false o = s:option(Value, "adblock_url", translate("adblock_url")) o.default = "https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt" +-- [[ chnroute ]] +s = m:section(TypedSection, "global", translate("Chnroute Setting")) +s.anonymous = true + +o = s:option(Flag, "chnroute", translate("Enable custom chnroute")) +o.rmempty = false + +o = s:option(Value, "chnroute_url", translate("Update url")) +o.default = "https://cdn.jsdelivr.net/gh/17mon/china_ip_list/china_ip_list.txt" + -- [[ SOCKS Proxy ]]-- if nixio.fs.access("/usr/bin/srelay") then s = m:section(TypedSection, "socks5_proxy", translate("SOCKS Proxy")) diff --git a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po index 48088fecb..4dfe6366c 100644 --- a/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po +++ b/package/lean/luci-app-ssr-plus/po/zh-cn/ssr-plus.po @@ -337,6 +337,15 @@ msgstr "启用进程自动守护" msgid "Advertising Data" msgstr "【广告屏蔽】数据库" +msgid "Chnroute Setting" +msgstr "国内IP段数据库更新设置" + +msgid "Enable custom chnroute" +msgstr "启用自定义更新地址" + +msgid "Update url" +msgstr "更新链接" + msgid "DNS Server IP and Port" msgstr "DNS服务器地址和端口" diff --git a/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua b/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua index 8c2958ad9..8ac39a2ec 100644 --- a/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua +++ b/package/lean/luci-app-ssr-plus/root/usr/share/shadowsocksr/update.lua @@ -42,13 +42,17 @@ else end log('正在更新【国内IP段】数据库') -refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" +if (ucic:get_first('shadowsocksr', 'global', 'chnroute','0') == '1' ) then + refresh_cmd="wget-ssl --no-check-certificate -O - ".. ucic:get_first('shadowsocksr', 'global', 'chnroute_url','https://cdn.jsdelivr.net/gh/17mon/china_ip_list/china_ip_list.txt') .." > /tmp/china_ssr.txt 2>/dev/null" +else + refresh_cmd="wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' 2>/dev/null| awk -F\\| '/CN\\|ipv4/ { printf(\"%s/%d\\n\", $4, 32-log($5)/log(2)) }' > /tmp/china_ssr.txt" +end sret=luci.sys.call(refresh_cmd) icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") - if sret== 0 then +if sret== 0 then icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") if tonumber(icount)>1000 then - oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") + oldcount=luci.sys.exec("cat /etc/china_ssr.txt | wc -l") if tonumber(icount) ~= tonumber(oldcount) then luci.sys.exec("cp -f /tmp/china_ssr.txt /etc/china_ssr.txt") -- retstring=tostring(math.ceil(tonumber(icount)/2)) @@ -57,7 +61,7 @@ icount = luci.sys.exec("cat /tmp/china_ssr.txt | wc -l") log('你已经是最新数据,无需更新!') end else - log('更新失败!') + log('更新失败!') end luci.sys.exec("rm -f /tmp/china_ssr.txt") else