💐 Sync 2024-12-13 10:02

This commit is contained in:
github-actions[bot] 2024-12-13 10:02:12 +08:00
parent 0b82a480c3
commit 3fe20681c4
4 changed files with 89 additions and 72 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, "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]]
entry({"admin", "services", appname, "check_passwall"}, call("app_check")).leaf = true
local coms = require "luci.passwall.com"
@ -475,3 +480,19 @@ function com_update(comname)
http_write_json(json)
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
s:tab("gfw_list", translate("GFW List"))
o = s:taboption("gfw_list", TextValue, "gfw_list", "")
o.readonly = true
o.rows = 45
o.wrap = "off"
o.cfgvalue = function(self, section)
local limit = 100 -- 限制行数
local cmd = string.format("head -n %d %s", limit, gfwlist_path)
return api.sys.exec(cmd) or ""
-- return fs.readfile(gfwlist_path) or ""
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)
o = s:taboption("gfw_list", DummyValue, "_gfw_fieldset")
o.rawhtml = true
o.default = string.format([[
<div style="display: flex; align-items: center;">
<input class="btn cbi-button cbi-button-add" type="button" onclick="read_gfw()" value="%s" />
<label id="gfw_total_lines" style="margin-left: auto; margin-right: 10px;"></label>
</div>
<textarea id="gfw_textarea" class="cbi-input-textarea" style="width: 100%%; margin-top: 10px;" rows="40" wrap="off" readonly="readonly"></textarea>
]], translate("Read List"))
end
if api.fs.access(chnlist_path) then
s:tab("chn_list", translate("China List") .. "(" .. translate("Domain") .. ")")
o = s:taboption("chn_list", TextValue, "chn_list", "")
o.readonly = true
o.rows = 45
o.wrap = "off"
o.cfgvalue = function(self, section)
local limit = 100 -- 限制行数
local cmd = string.format("head -n %d %s", limit, chnlist_path)
return api.sys.exec(cmd) or ""
-- return fs.readfile(chnlist_path) or ""
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)
o = s:taboption("chn_list", DummyValue, "_chn_fieldset")
o.rawhtml = true
o.default = string.format([[
<div style="display: flex; align-items: center;">
<input class="btn cbi-button cbi-button-add" type="button" onclick="read_chn()" value="%s" />
<label id="chn_total_lines" style="margin-left: auto; margin-right: 10px;"></label>
</div>
<textarea id="chn_textarea" class="cbi-input-textarea" style="width: 100%%; margin-top: 10px;" rows="40" wrap="off" readonly="readonly"></textarea>
]], translate("Read List"))
end
if api.fs.access(chnroute_path) then
s:tab("chnroute_list", translate("China List") .. "(IP)")
o = s:taboption("chnroute_list", TextValue, "chnroute_list", "")
o.readonly = true
o.rows = 45
o.wrap = "off"
o.cfgvalue = function(self, section)
local limit = 100 -- 限制行数
local cmd = string.format("head -n %d %s", limit, chnroute_path)
return api.sys.exec(cmd) or ""
-- return fs.readfile(chnroute_path) or ""
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)
o = s:taboption("chnroute_list", DummyValue, "_chnroute_fieldset")
o.rawhtml = true
o.default = string.format([[
<div style="display: flex; align-items: center;">
<input class="btn cbi-button cbi-button-add" type="button" onclick="read_chnroute()" value="%s" />
<label id="chnroute_total_lines" style="margin-left: auto; margin-right: 10px;"></label>
</div>
<textarea id="chnroute_textarea" class="cbi-input-textarea" style="width: 100%%; margin-top: 10px;" rows="40" wrap="off" readonly="readonly"></textarea>
]], translate("Read List"))
end
m:append(Template(appname .. "/rule_list/js"))

View File

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

View File

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