diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index e4c4318a6..1712f4dd7 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -95,6 +95,9 @@ function index() --[[Backup]] entry({"admin", "services", appname, "backup"}, call("create_backup")).leaf = true + + --[[geoview]] + entry({"admin", "services", appname, "geo_view"}, call("geo_view")).leaf = true end local function http_write_json(content) @@ -561,3 +564,53 @@ function create_backup() http.write(fs.readfile(tar_file)) fs.remove(tar_file) end + +function geo_view() + local action = luci.http.formvalue("action") + local value = luci.http.formvalue("value") + if not value or value == "" then + http.prepare_content("text/plain") + http.write(i18n.translate("Please enter query content!")) + return + end + local geo_dir = (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") + local geosite_path = geo_dir .. "/geosite.dat" + local geoip_path = geo_dir .. "/geoip.dat" + local geo_type, file_path, cmd + local geo_string = "" + if action == "lookup" then + if api.datatypes.ipaddr(value) or api.datatypes.ip6addr(value) then + geo_type, file_path = "geoip", geoip_path + else + geo_type, file_path = "geosite", geosite_path + end + cmd = string.format("geoview -type %s -action lookup -input '%s' -value '%s'", geo_type, file_path, value) + geo_string = luci.sys.exec(cmd):lower() + if geo_string ~= "" then + local lines = {} + for line in geo_string:gmatch("([^\n]*)\n?") do + if line ~= "" then + table.insert(lines, geo_type .. ":" .. line) + end + end + geo_string = table.concat(lines, "\n") + end + elseif action == "extract" then + local prefix, list = value:match("^(geoip:)(.*)$") + if not prefix then + prefix, list = value:match("^(geosite:)(.*)$") + end + if prefix and list and list ~= "" then + geo_type = prefix:sub(1, -2) + file_path = (geo_type == "geoip") and geoip_path or geosite_path + cmd = string.format("geoview -type %s -action extract -input '%s' -list '%s'", geo_type, file_path, list) + geo_string = luci.sys.exec(cmd) + end + end + http.prepare_content("text/plain") + if geo_string and geo_string ~="" then + http.write(geo_string) + else + http.write(i18n.translate("No results were found!")) + end +end 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 ed099dd2b..15f04bd8a 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 @@ -313,6 +313,13 @@ end m:append(Template(appname .. "/rule_list/js")) +if api.is_finded("geoview") then + s:tab("geoview", translate("Geo View")) + o = s:taboption("geoview", DummyValue, "_geoview_fieldset") + o.rawhtml = true + o.template = appname .. "/rule_list/geoview" +end + function m.on_before_save(self) m:set("@global[0]", "flush_set", "1") end diff --git a/luci-app-passwall/luasrc/view/passwall/rule_list/geoview.htm b/luci-app-passwall/luasrc/view/passwall/rule_list/geoview.htm new file mode 100644 index 000000000..f5fc86901 --- /dev/null +++ b/luci-app-passwall/luasrc/view/passwall/rule_list/geoview.htm @@ -0,0 +1,81 @@ +<% +local api = require "luci.passwall.api" +-%> + + + +
+ +
+
+
+ + +
+
+ <%:Enter a domain or IP to query the Geo rule list they belong to.%> +
+
+
+
+
+ + +
+
+ <%:Enter a GeoIP or Geosite to extract the domains/IPs they contain. Format: geoip:cn or geosite:gfw%> +
+
+
+
+ +
+ + \ No newline at end of file diff --git a/luci-app-passwall/po/zh-cn/passwall.po b/luci-app-passwall/po/zh-cn/passwall.po index 9b51c09f3..3c6c3e2de 100644 --- a/luci-app-passwall/po/zh-cn/passwall.po +++ b/luci-app-passwall/po/zh-cn/passwall.po @@ -1833,3 +1833,42 @@ msgstr "端口跳跃范围" msgid "Format as 1000:2000 Multiple groups are separated by commas (,)." msgstr "格式为:1000:2000 多组时用逗号(,)隔开。" + +msgid "Geo View" +msgstr "Geo 查询" + +msgid "Query" +msgstr "查询" + +msgid "Querying" +msgstr "查询中" + +msgid "Please enter query content!" +msgstr "请输入查询内容!" + +msgid "No results were found!" +msgstr "未找到任何结果!" + +msgid "Domain/IP Query" +msgstr "域名/IP 查询" + +msgid "GeoIP/Geosite Query" +msgstr "GeoIP/Geosite 查询" + +msgid "Enter a domain or IP to query the Geo rule list they belong to." +msgstr "输入域名/IP,查询它们所在的 Geo 规则列表。" + +msgid "Enter a GeoIP or Geosite to extract the domains/IPs they contain. Format: geoip:cn or geosite:gfw" +msgstr "输入 GeoIP/Geosite,提取它们所包含的域名/IP。格式:geoip:cn 或 geosite:gfw" + +msgid "Tips:" +msgstr "小贴士:" + +msgid "By entering a domain or IP, you can query the Geo rule list they belong to." +msgstr "可以通过输入域名/IP,查询它们所在的 Geo 规则列表。" + +msgid "By entering a GeoIP or Geosite, you can extract the domains/IPs they contain." +msgstr "可以通过输入 GeoIP/Geosite,提取它们所包含的域名/IP。" + +msgid "Use the GeoIP/Geosite query function to verify if the entered Geo rules are correct." +msgstr "利用 GeoIP/Geosite 查询功能,可以验证输入的 Geo 规则是否正确。"