Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/luci-app-passwall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-passwall
PKG_VERSION:=26.1.25
PKG_VERSION:=26.2.6
PKG_RELEASE:=1

PKG_CONFIG_DEPENDS:= \
Expand Down
70 changes: 59 additions & 11 deletions applications/luci-app-passwall/luasrc/controller/passwall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function index()
entry({"admin", "services", appname, "save_node_order"}, call("save_node_order")).leaf = true
entry({"admin", "services", appname, "save_node_list_opt"}, call("save_node_list_opt")).leaf = true
entry({"admin", "services", appname, "update_rules"}, call("update_rules")).leaf = true
entry({"admin", "services", appname, "rollback_rules"}, call("rollback_rules")).leaf = true
entry({"admin", "services", appname, "subscribe_del_node"}, call("subscribe_del_node")).leaf = true
entry({"admin", "services", appname, "subscribe_del_all"}, call("subscribe_del_all")).leaf = true
entry({"admin", "services", appname, "subscribe_manual"}, call("subscribe_manual")).leaf = true
Expand Down Expand Up @@ -341,19 +342,19 @@ function connect_status()
local e = {}
e.use_time = ""
local url = http.formvalue("url")
local baidu = string.find(url, "baidu")
local aliyun = string.find(url, "aliyun")
local chn_list = uci:get(appname, "@global[0]", "chn_list") or "direct"
local gfw_list = uci:get(appname, "@global[0]", "use_gfw_list") or "1"
local proxy_mode = uci:get(appname, "@global[0]", "tcp_proxy_mode") or "proxy"
local localhost_proxy = uci:get(appname, "@global[0]", "localhost_proxy") or "1"
local socks_server = (localhost_proxy == "0") and api.get_cache_var("GLOBAL_TCP_SOCKS_server") or ""
url = "-w %{http_code}:%{time_pretransfer} " .. url
if socks_server and socks_server ~= "" then
if (chn_list == "proxy" and gfw_list == "0" and proxy_mode ~= "proxy" and baidu ~= nil) or (chn_list == "0" and gfw_list == "0" and proxy_mode == "proxy") then
-- 中国列表+百度 or 全局
if (chn_list == "proxy" and gfw_list == "0" and proxy_mode ~= "proxy" and aliyun ~= nil) or (chn_list == "0" and gfw_list == "0" and proxy_mode == "proxy") then
-- 中国列表+阿里 or 全局
url = "-x socks5h://" .. socks_server .. " " .. url
elseif baidu == nil then
-- 其他代理模式+百度以外网站
elseif aliyun == nil then
-- 其他代理模式+阿里以外网站
url = "-x socks5h://" .. socks_server .. " " .. url
end
end
Expand Down Expand Up @@ -424,7 +425,7 @@ function add_node()
uci:set(appname, uuid, "group", group)
end

uci:set(appname, uuid, "type", "Xray")
uci:set(appname, uuid, "type", "Socks")

if redirect == "1" then
api.uci_save(uci, appname)
Expand Down Expand Up @@ -702,6 +703,24 @@ function update_rules()
http_write_json()
end

function rollback_rules()
local arg_type = http.formvalue("type")
local rules = http.formvalue("rules") or ""
if arg_type ~= "geoip" and arg_type ~= "geosite" then
http_write_json_error()
return
end
local bak_dir = "/tmp/bak_v2ray/"
local geo_dir = (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/")
local geo2rule = uci:get(appname, "@global_rules[0]", "geo2rule") or "0"
fs.move(bak_dir .. arg_type .. ".dat", geo_dir .. arg_type .. ".dat")
fs.rmdir(bak_dir)
if geo2rule == "1" and rules ~= "" then
luci.sys.call("lua /usr/share/passwall/rule_update.lua log '" .. rules .. "' rollback > /dev/null")
end
http_write_json_ok()
end

function server_user_status()
local e = {}
e.index = http.formvalue("index")
Expand Down Expand Up @@ -864,27 +883,56 @@ function geo_view()
http.write(i18n.translate("Please enter query content!"))
return
end
local function get_rules(str, type)
local rules_id = {}
uci:foreach(appname, "shunt_rules", function(s)
local list
if type == "geoip" then list = s.ip_list else list = s.domain_list end
for line in string.gmatch((list or ""), "[^\r\n]+") do
if line ~= "" and not line:find("#") then
local prefix, main = line:match("^(.-):(.*)")
if not main then main = line end
if type == "geoip" and (api.datatypes.ipaddr(str) or api.datatypes.ip6addr(str)) then
if main:find(str, 1, true) then rules_id[#rules_id + 1] = s[".name"] end
else
if main == str then rules_id[#rules_id + 1] = s[".name"] end
end
end
end
end)
return rules_id
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 = ""
local bin = api.get_app_path("geoview")
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' -lowmem=true", geo_type, file_path, value)
cmd = string.format(bin .. " -type %s -action lookup -input '%s' -value '%s' -lowmem=true", 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)
local lines, rules, seen = {}, {}, {}
for line in geo_string:gmatch("([^\n]+)") do
lines[#lines + 1] = geo_type .. ":" .. line
for _, r in ipairs(get_rules(line, geo_type) or {}) do
if not seen[r] then seen[r] = true; rules[#rules + 1] = r end
end
end
for _, r in ipairs(get_rules(value, geo_type) or {}) do
if not seen[r] then seen[r] = true; rules[#rules + 1] = r end
end
geo_string = table.concat(lines, "\n")
if #rules > 0 then
geo_string = geo_string .. "\n--------------------\n"
geo_string = geo_string .. i18n.translate("Rules containing this value:") .. "\n"
geo_string = geo_string .. table.concat(rules, "\n")
end
end
elseif action == "extract" then
local prefix, list = value:match("^(geoip:)(.*)$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ o.default = ""
o:depends({ _hide_node_option = false, use_global_config = false })
o.template = appname .. "/cbi/nodes_listvalue"
o.group = {}
o.remove = function(self, section)
m:del(section, self.option)
m:del(section, "udp_node")
end

o = s:option(DummyValue, "_tcp_node_bool", "")
o.template = "passwall/cbi/hidevalue"
Expand All @@ -219,14 +223,36 @@ o = s:option(ListValue, "udp_node", "<a style='color: red'>" .. translate("UDP N
o.default = ""
o:value("", translate("Close"))
o:value("tcp", translate("Same as the tcp node"))
o:depends({ _tcp_node_bool = "1" })
o:depends({ _tcp_node_bool = "1", _node_sel_other = "1" })
o.template = appname .. "/cbi/nodes_listvalue"
o.group = {"",""}
o.remove = function(self, section)
local v = s.fields["shunt_udp_node"]:formvalue(section)
if not f then
return m:del(section, self.option)
end
end

o = s:option(ListValue, "shunt_udp_node", "<a style='color: red'>" .. translate("UDP Node") .. "</a>")
o:value("close", translate("Close"))
o:value("tcp", translate("Same as the tcp node"))
o:depends({ _tcp_node_bool = "1", _node_sel_shunt = "1" })
o.cfgvalue = function(self, section)
local v = m:get(section, "udp_node") or ""
if v == "" then v = "close" end
if v ~= "close" and v ~= "tcp" then v = "tcp" end
return v
end
o.write = function(self, section, value)
if value == "close" then value = "" end
return m:set(section, "udp_node", value)
end

o = s:option(DummyValue, "_udp_node_bool", "")
o.template = "passwall/cbi/hidevalue"
o.value = "1"
o:depends({ udp_node = "", ['!reverse'] = true })
o:depends({ shunt_udp_node = "tcp" })

---- TCP Proxy Drop Ports
local TCP_PROXY_DROP_PORTS = m:get("@global_forwarding[0]", "tcp_proxy_drop_ports")
Expand Down Expand Up @@ -471,7 +497,7 @@ o:depends({dns_mode = "sing-box"})
o:depends({dns_mode = "xray"})
o:depends({_node_sel_shunt = "1"})

o = s:option(Flag, "remote_fakedns", "FakeDNS", translate("Use FakeDNS work in the shunt domain that proxy."))
o = s:option(Flag, "remote_fakedns", "FakeDNS", translate("Use FakeDNS work in the domain that proxy."))
o.default = "0"
o.rmempty = false
o:depends({dns_mode = "sing-box"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local k, v
local com = require "luci.passwall.com"
for _, k in ipairs(com.order) do
v = com[k]
if k ~= "geoview" and k ~= "chinadns-ng" then
if k ~= "chinadns-ng" then
o = s:option(Value, k:gsub("%-","_") .. "_file", translatef("%s App Path", v.name))
o.default = v.default_path or ("/usr/bin/" .. k)
o.rmempty = false
Expand Down
Loading