From f3b8746b0af8a7615086b7c0e93fa61b2c46b2be Mon Sep 17 00:00:00 2001
From: xiaorouji <60100640+xiaorouji@users.noreply.github.com>
Date: Mon, 8 Apr 2024 01:17:45 +0800
Subject: [PATCH] luci: rule list show readonly gfwlist chnlist
---
.../model/cbi/passwall/client/rule_list.lua | 41 ++++++++++++++++++-
.../luasrc/view/passwall/rule_list/js.htm | 18 ++++++++
2 files changed, 57 insertions(+), 2 deletions(-)
create mode 100644 luci-app-passwall/luasrc/view/passwall/rule_list/js.htm
diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua
index 2497d32e0..3fac86c29 100644
--- a/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua
+++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/rule_list.lua
@@ -4,7 +4,9 @@ local fs = api.fs
local sys = api.sys
local datatypes = api.datatypes
local path = string.format("/usr/share/%s/rules/", appname)
-local route_hosts_path = "/etc/"
+local gfwlist_path = "/usr/share/passwall/rules/gfwlist"
+local chnlist_path = "/usr/share/passwall/rules/chnlist"
+local chnroute_path = "/usr/share/passwall/rules/chnroute"
m = Map(appname)
@@ -247,7 +249,7 @@ o.validate = function(self, value)
end
---- Route Hosts
-local hosts = route_hosts_path .. "hosts"
+local hosts = "/etc/hosts"
o = s:taboption("route_hosts", TextValue, "hosts", "", "" .. translate("Configure routing etc/hosts file, if you don't know what you are doing, please don't change the content.") .. "")
o.rows = 15
o.wrap = "off"
@@ -261,6 +263,41 @@ o.remove = function(self, section, value)
fs.writefile(hosts, "")
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)
+ return fs.readfile(gfwlist_path) or ""
+ end
+end
+
+if api.fs.access(chnlist_path) then
+ s:tab("chn_list", translate("China List"))
+ o = s:taboption("chn_list", TextValue, "chn_list", "")
+ o.readonly = true
+ o.rows = 45
+ o.wrap = "off"
+ o.cfgvalue = function(self, section)
+ return fs.readfile(chnlist_path) or ""
+ end
+end
+
+if api.fs.access(chnroute_path) then
+ s:tab("chnroute_list", translate("China List"))
+ o = s:taboption("chnroute_list", TextValue, "chnroute_list", "")
+ o.readonly = true
+ o.rows = 45
+ o.wrap = "off"
+ o.cfgvalue = function(self, section)
+ return fs.readfile(chnroute_path) or ""
+ end
+end
+
+m:append(Template(appname .. "/rule_list/js"))
+
if sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0 then
m.apply_on_parse = true
function m.on_apply(self)
diff --git a/luci-app-passwall/luasrc/view/passwall/rule_list/js.htm b/luci-app-passwall/luasrc/view/passwall/rule_list/js.htm
new file mode 100644
index 000000000..096fe8635
--- /dev/null
+++ b/luci-app-passwall/luasrc/view/passwall/rule_list/js.htm
@@ -0,0 +1,18 @@
+<%
+local api = require "luci.passwall.api"
+-%>
+