luci-app-passwall: sync upstream

last commit: a258272240
This commit is contained in:
gitea-action 2024-12-13 02:00:19 +08:00
parent dfb8bf8e82
commit dd1c0fb6ba
5 changed files with 91 additions and 74 deletions

View File

@ -77,6 +77,11 @@ function index()
entry({"admin", "services", appname, "delete_select_nodes"}, call("delete_select_nodes")).leaf = true entry({"admin", "services", appname, "delete_select_nodes"}, call("delete_select_nodes")).leaf = true
entry({"admin", "services", appname, "update_rules"}, call("update_rules")).leaf = true entry({"admin", "services", appname, "update_rules"}, call("update_rules")).leaf = true
--[[rule_list]]
entry({"admin", "services", appname, "read_gfwlist"}, call("read_rulelist", "gfw")).leaf = true
entry({"admin", "services", appname, "read_chnlist"}, call("read_rulelist", "chn")).leaf = true
entry({"admin", "services", appname, "read_chnroute"}, call("read_rulelist", "chnroute")).leaf = true
--[[Components update]] --[[Components update]]
entry({"admin", "services", appname, "check_passwall"}, call("app_check")).leaf = true entry({"admin", "services", appname, "check_passwall"}, call("app_check")).leaf = true
local coms = require "luci.passwall.com" local coms = require "luci.passwall.com"
@ -475,3 +480,19 @@ function com_update(comname)
http_write_json(json) http_write_json(json)
end end
function read_rulelist(list)
local rule_path
if list == "gfw" then
rule_path = "/usr/share/passwall/rules/gfwlist"
elseif list == "chn" then
rule_path = "/usr/share/passwall/rules/chnlist"
else
rule_path = "/usr/share/passwall/rules/chnroute"
end
if api.fs.access(rule_path) then
luci.http.prepare_content("text/plain")
luci.http.write(api.fs.readfile(rule_path))
end
end

View File

@ -273,71 +273,41 @@ end
if api.fs.access(gfwlist_path) then if api.fs.access(gfwlist_path) then
s:tab("gfw_list", translate("GFW List")) s:tab("gfw_list", translate("GFW List"))
o = s:taboption("gfw_list", TextValue, "gfw_list", "") o = s:taboption("gfw_list", DummyValue, "_gfw_fieldset")
o.readonly = true o.rawhtml = true
o.rows = 45 o.default = string.format([[
o.wrap = "off" <div style="display: flex; align-items: center;">
o.cfgvalue = function(self, section) <input class="btn cbi-button cbi-button-add" type="button" onclick="read_gfw()" value="%s" />
local limit = 100 -- 限制行数 <label id="gfw_total_lines" style="margin-left: auto; margin-right: 10px;"></label>
local cmd = string.format("head -n %d %s", limit, gfwlist_path) </div>
return api.sys.exec(cmd) or "" <textarea id="gfw_textarea" class="cbi-input-textarea" style="width: 100%%; margin-top: 10px;" rows="40" wrap="off" readonly="readonly"></textarea>
-- return fs.readfile(gfwlist_path) or "" ]], translate("Read List"))
end
local total_lines_cmd = string.format("wc -l < %s", gfwlist_path)
local total_lines = tonumber(api.sys.exec(total_lines_cmd)) or 0
local displayed_lines = 100
local total_lines_label = s:taboption("gfw_list", DummyValue, "total_lines", translate("Total Lines"))
total_lines_label.value = translatef("%d lines", total_lines)
local displayed_lines_label = s:taboption("gfw_list", DummyValue, "displayed_lines", translate("Displayed Lines"))
displayed_lines_label.value = translatef("%d lines", displayed_lines)
end end
if api.fs.access(chnlist_path) then if api.fs.access(chnlist_path) then
s:tab("chn_list", translate("China List") .. "(" .. translate("Domain") .. ")") s:tab("chn_list", translate("China List") .. "(" .. translate("Domain") .. ")")
o = s:taboption("chn_list", TextValue, "chn_list", "") o = s:taboption("chn_list", DummyValue, "_chn_fieldset")
o.readonly = true o.rawhtml = true
o.rows = 45 o.default = string.format([[
o.wrap = "off" <div style="display: flex; align-items: center;">
o.cfgvalue = function(self, section) <input class="btn cbi-button cbi-button-add" type="button" onclick="read_chn()" value="%s" />
local limit = 100 -- 限制行数 <label id="chn_total_lines" style="margin-left: auto; margin-right: 10px;"></label>
local cmd = string.format("head -n %d %s", limit, chnlist_path) </div>
return api.sys.exec(cmd) or "" <textarea id="chn_textarea" class="cbi-input-textarea" style="width: 100%%; margin-top: 10px;" rows="40" wrap="off" readonly="readonly"></textarea>
-- return fs.readfile(chnlist_path) or "" ]], translate("Read List"))
end
local total_lines_cmd = string.format("wc -l < %s", chnlist_path)
local total_lines = tonumber(api.sys.exec(total_lines_cmd)) or 0
local displayed_lines = 100
local total_lines_label = s:taboption("chn_list", DummyValue, "total_lines", translate("Total Lines"))
total_lines_label.value = translatef("%d lines", total_lines)
local displayed_lines_label = s:taboption("chn_list", DummyValue, "displayed_lines", translate("Displayed Lines"))
displayed_lines_label.value = translatef("%d lines", displayed_lines)
end end
if api.fs.access(chnroute_path) then if api.fs.access(chnroute_path) then
s:tab("chnroute_list", translate("China List") .. "(IP)") s:tab("chnroute_list", translate("China List") .. "(IP)")
o = s:taboption("chnroute_list", TextValue, "chnroute_list", "") o = s:taboption("chnroute_list", DummyValue, "_chnroute_fieldset")
o.readonly = true o.rawhtml = true
o.rows = 45 o.default = string.format([[
o.wrap = "off" <div style="display: flex; align-items: center;">
o.cfgvalue = function(self, section) <input class="btn cbi-button cbi-button-add" type="button" onclick="read_chnroute()" value="%s" />
local limit = 100 -- 限制行数 <label id="chnroute_total_lines" style="margin-left: auto; margin-right: 10px;"></label>
local cmd = string.format("head -n %d %s", limit, chnroute_path) </div>
return api.sys.exec(cmd) or "" <textarea id="chnroute_textarea" class="cbi-input-textarea" style="width: 100%%; margin-top: 10px;" rows="40" wrap="off" readonly="readonly"></textarea>
-- return fs.readfile(chnroute_path) or "" ]], translate("Read List"))
end
local total_lines_cmd = string.format("wc -l < %s", chnroute_path)
local total_lines = tonumber(api.sys.exec(total_lines_cmd)) or 0
local displayed_lines = 100
local total_lines_label = s:taboption("chnroute_list", DummyValue, "total_lines", translate("Total Lines"))
total_lines_label.value = translatef("%d lines", total_lines)
local displayed_lines_label = s:taboption("chnroute_list", DummyValue, "displayed_lines", translate("Displayed Lines"))
displayed_lines_label.value = translatef("%d lines", displayed_lines)
end end
m:append(Template(appname .. "/rule_list/js")) m:append(Template(appname .. "/rule_list/js"))

View File

@ -1,18 +1,47 @@
<% <%
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local translate = luci.i18n.translate
local total_lines_text = translate("Total Lines")
-%> -%>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
let dom = document.getElementById("cbi-passwall-global_rules"); function read_gfw() {
if (dom) { fetch('<%= api.url("read_gfwlist") %>')
let textareas = dom.getElementsByTagName("textarea"); .then(response => response.text())
for (let i = 0; i < textareas.length; i++) { .then(data => {
let o = textareas[i]; var total_lines = data.split("\n").length;
if (o.readOnly) { var textarea = document.getElementById('gfw_textarea');
o.removeAttribute("name"); textarea.innerHTML = data;
o.removeAttribute("id"); //textarea.scrollTop = textarea.scrollHeight;
var totalLinesLabel = document.getElementById('gfw_total_lines');
totalLinesLabel.innerHTML = "<%= total_lines_text %> " + total_lines;
})
} }
function read_chn() {
fetch('<%= api.url("read_chnlist") %>')
.then(response => response.text())
.then(data => {
var total_lines = data.split("\n").length;
var textarea = document.getElementById('chn_textarea');
textarea.innerHTML = data;
//textarea.scrollTop = textarea.scrollHeight;
var totalLinesLabel = document.getElementById('chn_total_lines');
totalLinesLabel.innerHTML = "<%= total_lines_text %> " + total_lines;
})
} }
function read_chnroute() {
fetch('<%= api.url("read_chnroute") %>')
.then(response => response.text())
.then(data => {
var total_lines = data.split("\n").length;
var textarea = document.getElementById('chnroute_textarea');
textarea.innerHTML = data;
//textarea.scrollTop = textarea.scrollHeight;
var totalLinesLabel = document.getElementById('chnroute_total_lines');
totalLinesLabel.innerHTML = "<%= total_lines_text %> " + total_lines;
})
} }
//]]> //]]>
</script> </script>

View File

@ -1729,8 +1729,5 @@ msgstr "为 sing-box 节点设置默认的域名解析策略。"
msgid "Total Lines" msgid "Total Lines"
msgstr "总行数:" msgstr "总行数:"
msgid "Displayed Lines" msgid "Read List"
msgstr "展示行数:" msgstr "读取列表"
msgid "%d lines"
msgstr "%d 行"

View File

@ -20,10 +20,10 @@ index fa1cd41..eac8656 100644
define Package/$(PKG_NAME)/postrm define Package/$(PKG_NAME)/postrm
diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua
index ce89a37..a3b132b 100644 index 02ce26c..83cbafc 100644
--- a/luci-app-passwall/luasrc/controller/passwall.lua --- a/luci-app-passwall/luasrc/controller/passwall.lua
+++ b/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua
@@ -274,7 +274,7 @@ function connect_status() @@ -279,7 +279,7 @@ function connect_status()
url = "-x socks5h://" .. socks_server .. " " .. url url = "-x socks5h://" .. socks_server .. " " .. url
end end
end end