Skip to content
Open
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.8.10
PKG_VERSION:=26.8.19
PKG_RELEASE:=1

PKG_CONFIG_DEPENDS:= \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,31 @@ function is_timehhmm(str) {
}

if (typeof cbi_validators !== 'undefined' && cbi_validators !== null) {
cbi_validators['base64'] = function() {
return isBase64(this);
}
cbi_validators['json'] = function() {
return is_json(this);
}
cbi_validators['timehhmm'] = function() {
return is_timehhmm(this);
}
cbi_validators['uuid'] = function() {
return isUUID(this);
}
} else {
L.require('validation').then(function(validation) {
validation.types['base64'] = function() {
return this.assert(isBase64(this.value), _('Must be Base64 text!'));
}
validation.types['json'] = function() {
return this.assert(is_json(this.value), _('Must be JSON text!'));
}
validation.types['timehhmm'] = function() {
return this.assert(is_timehhmm(this.value), _('valid time (hh:mm)'));
}
validation.types['uuid'] = function() {
return this.assert(isUUID(this.value), _('Must be UUID format!'));
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ function arraysEqual(a, b) {
return true;
}

function isBase64(str) {
const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/;
return base64Regex.test(str);
}

function decodeIfBase64(str) {
try {
let s = str.replace(/-/g, '+').replace(/_/g, '/');
Expand All @@ -24,6 +29,11 @@ function decodeIfBase64(str) {
return str;
}

function isUUID(str) {
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
return uuidRegex.test(str);
}

function waitForElement(selector, callback) {
const el = document.querySelector(selector);
if (el) return callback(el);
Expand Down
405 changes: 196 additions & 209 deletions applications/luci-app-passwall/luasrc/controller/passwall.lua

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
local api = require "luci.passwall.api"
local appname = "passwall"
local sys = api.sys

api.set_default_cbi()

m = Map(appname)
api.set_apply_on_parse(m)
m = Map()

s = m:section(TypedSection, "global", translate("ACLs"), "<font color='red'>" .. translate("ACLs is a tools which used to designate specific IP proxy mode.") .. "</font>")
s.anonymous = true
s = m:section(NamedSection, "@global[0]", "global", translate("ACLs"), "<font color='red'>" .. translate("ACLs is a tools which used to designate specific IP proxy mode.") .. "</font>")

o = s:option(Flag, "acl_enable", translate("Main switch"))
o.rmempty = false
o.default = false

-- [[ ACLs Settings ]]--
local cfgname = "acl_rule"
s = m:section(TypedSection, cfgname)
s = m:section(TypedSection, "acl_rule")
s.template = "cbi/tblsection"
s.sortable = true
s.anonymous = true
Expand All @@ -28,7 +23,7 @@ function s.create(e, t)
luci.http.redirect(e.extedit:format(uid))
end
function s.remove(e, t)
sys.call("rm -rf /tmp/etc/passwall_tmp/dns_" .. t .. "*")
api.sys.call("rm -rf /tmp/etc/passwall_tmp/dns_" .. t .. "*")
TypedSection.remove(e, t)
end

Expand All @@ -42,7 +37,7 @@ o = s:option(Value, "remarks", translate("Remarks"))
o.rmempty = true

local mac_t = {}
sys.net.mac_hints(function(e, t)
api.sys.net.mac_hints(function(e, t)
mac_t[e] = {
ip = t,
mac = e
Expand Down Expand Up @@ -85,41 +80,6 @@ i.cfgvalue = function(t, n)
return translate("No Proxy")
end

--[[
---- TCP No Redir Ports
o = s:option(Value, "tcp_no_redir_ports", translate("TCP No Redir Ports"))
o.default = "default"
o:value("disable", translate("No patterns are used"))
o:value("default", translate("Default"))
o:value("1:65535", translate("All"))

---- UDP No Redir Ports
o = s:option(Value, "udp_no_redir_ports", translate("UDP No Redir Ports"))
o.default = "default"
o:value("disable", translate("No patterns are used"))
o:value("default", translate("Default"))
o:value("1:65535", translate("All"))

---- TCP Redir Ports
o = s:option(Value, "tcp_redir_ports", translate("TCP Redir Ports"))
o.default = "default"
o:value("default", translate("Default"))
o:value("1:65535", translate("All"))
o:value("80,443", "80,443")
o:value("80:65535", "80 " .. translate("or more"))
o:value("1:443", "443 " .. translate("or less"))

---- UDP Redir Ports
o = s:option(Value, "udp_redir_ports", translate("UDP Redir Ports"))
o.default = "default"
o:value("default", translate("Default"))
o:value("1:65535", translate("All"))
o:value("53", "53")
]]--

local sortable = Template(appname .. "/cbi/sortable")
sortable.api = api
sortable.target_cfgname = cfgname
m:append(sortable)
m:appendTemplate("/cbi/sortable", {sectiontype = s.sectiontype})

return api.return_map(m)
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
local api = require "luci.passwall.api"
local appname = "passwall"

api.set_default_cbi()

m = Map(appname)
m = Map()
m.redirect = api.url("acl")
api.set_apply_on_parse(m)

local cfgid = arg[1]
if not cfgid or not m:get(cfgid) then
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(m.redirect)
end

m:append(Template(appname .. "/cbi/nodes_listvalue_com"))
m:appendTemplate("/cbi/nodes_listvalue_com")

local fs = api.fs
local sys = api.sys
local has_singbox = api.finded_com("sing-box")
local has_xray = api.finded_com("xray")
local has_gfwlist = fs.access("/usr/share/passwall/rules/gfwlist")
local has_chnlist = fs.access("/usr/share/passwall/rules/chnlist")
local has_chnroute = fs.access("/usr/share/passwall/rules/chnroute")
local has_gfwlist = api.fs.access("/usr/share/passwall/rules/gfwlist")
local has_chnlist = api.fs.access("/usr/share/passwall/rules/chnlist")
local has_chnroute = api.fs.access("/usr/share/passwall/rules/chnroute")

local port_validate = function(self, value, t)
return value:gsub("-", ":")
Expand All @@ -39,18 +33,18 @@ for _, v in pairs(nodes_table) do
end

local socks_list = {}
m.uci:foreach(appname, "socks", function(s)
m:foreach("socks", function(s)
if s.enabled == "1" and s.node then
socks_list[#socks_list + 1] = {
id = "Socks_" .. s[".name"],
id = s[".name"],
remark = translate("Socks Config") .. " " .. string.format("[%s %s]", s.port, translate("Port")),
group = "Socks"
}
end
end)

-- [[ ACLs Settings ]]--
s = m:section(NamedSection, cfgid, translate("ACLs"), translate("ACLs"))
s = m:section(NamedSection, arg[1], translate("ACLs"), translate("ACLs"))
s.addremove = false
s.dynamic = false

Expand All @@ -61,7 +55,7 @@ o.rmempty = false

---- Remarks
o = s:option(Value, "remarks", translate("Remarks"))
o.default = cfgid
o.default = arg[1]
o.rmempty = false

o = s:option(Value, "interface", translate("Source Interface"))
Expand All @@ -78,7 +72,7 @@ o.validate = function(self, value, section)
end

local mac_t = {}
sys.net.mac_hints(function(e, t)
api.sys.net.mac_hints(function(e, t)
mac_t[#mac_t + 1] = {
ip = t,
mac = e
Expand Down Expand Up @@ -188,7 +182,7 @@ o:depends("mode", "1")
o.validate = port_validate

o = s:option(DummyValue, "_hide_node_option", "")
o.template = "passwall/cbi/hidevalue"
o.template = m:template_path("/cbi/hidevalue")
o.value = "1"
o:depends("mode", "0")
o:depends({ tcp_no_redir_ports = "1:65535", udp_no_redir_ports = "1:65535" })
Expand All @@ -204,15 +198,15 @@ o:depends({ _hide_node_option = "1", ['!reverse'] = true })
o = s:option(ListValue, "tcp_node", "<a style='color: red'>" .. translate("TCP Node") .. "</a>")
o.default = ""
o:depends({ _hide_node_option = false, use_global_config = false })
o.template = appname .. "/cbi/nodes_listvalue"
o.template = m:template_path("/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"
o.template = m:template_path("/cbi/hidevalue")
o.value = "1"
o:depends({ tcp_node = "", ['!reverse'] = true })

Expand All @@ -221,7 +215,7 @@ o.default = ""
o:value("", translate("Close"))
o:value("tcp", translate("Same as the tcp node"))
o:depends({ _tcp_node_bool = "1", _node_sel_other = "1" })
o.template = appname .. "/cbi/nodes_listvalue"
o.template = m:template_path("/cbi/nodes_listvalue")
o.group = {"",""}
o.remove = function(self, section)
local v = s.fields["shunt_udp_node"]:formvalue(section)
Expand All @@ -248,7 +242,7 @@ o.write = function(self, section, value)
end

o = s:option(DummyValue, "_udp_node_bool", "")
o.template = "passwall/cbi/hidevalue"
o.template = m:template_path("/cbi/hidevalue")
o.value = "1"
o:depends({ udp_node = "", ['!reverse'] = true })
o:depends({ shunt_udp_node = "tcp" })
Expand Down Expand Up @@ -355,17 +349,17 @@ o:value("proxy", translate("Proxy"))
o:depends({ _udp_node_bool = "1" })

o = s:option(DummyValue, "switch_mode", " ")
o.template = appname .. "/global/proxy"
o.template = m:template_path("/global/proxy")
o:depends({ _tcp_node_bool = "1" })

-- Node → DNS Depends Settings
o = s:option(DummyValue, "_node_sel_shunt", "")
o.template = appname .. "/cbi/hidevalue"
o.template = m:template_path("/cbi/hidevalue")
o.value = "1"
o:depends({ tcp_node = "__always__" })

o = s:option(DummyValue, "_node_sel_other", "")
o.template = appname .. "/cbi/hidevalue"
o.template = m:template_path("/cbi/hidevalue")
o.value = "1"
o:depends({ _node_sel_shunt = "1", ['!reverse'] = true })

Expand Down Expand Up @@ -525,14 +519,19 @@ o.validate = function(self, value, t)
local _dns_mode = s.fields["dns_mode"]:formvalue(t)
local _tcp_node = s.fields["tcp_node"]:formvalue(t)
if _dns_mode and _tcp_node then
if (m:get(_tcp_node, "type") or ""):lower() ~= _dns_mode and not _tcp_node:find("Socks_") then
if (m:get(_tcp_node, "type") or ""):lower() ~= _dns_mode and not _tcp_node:find("socks_") then
return nil, translatef("TCP node must be '%s' type to use FakeDNS.", _dns_mode)
end
end
end
return value
end

o = s:option(Value, "remote_rewrite_ttl", translate("Remote DNS") .. " TTL")
o.datatype = "min(1)"
o.default = "30"
o:depends({dns_mode = "sing-box"})

o = s:option(ListValue, "chinadns_ng_default_tag", translate("Default DNS"))
o.default = "none"
o:value("gfw", translate("Remote DNS"))
Expand Down Expand Up @@ -594,6 +593,7 @@ for k, v in pairs(nodes_table) do

s.fields["singbox_dns_mode"]:depends({ _tcp_node_bool = "1", tcp_node = v.id })
s.fields["_node_sel_shunt"]:depends({ tcp_node = v.id })
s.fields["remote_rewrite_ttl"]:depends({ _tcp_node_bool = "1", tcp_node = v.id })
end
else
tcp:value(v.id, v["remark"])
Expand All @@ -603,9 +603,6 @@ for k, v in pairs(nodes_table) do
end
end

local footer = Template(appname .. "/acl/config_footer")
footer.api = api
footer.cfgid = cfgid
m:append(footer)
m:appendTemplate("/acl/config_footer", {section = arg[1]})

return api.return_map(m)
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
local api = require "luci.passwall.api"
local com = require "luci.passwall.com"
local appname = "passwall"

api.set_default_cbi()

m = Map(appname)
api.set_apply_on_parse(m)
local com = require "luci.passwall.com"

m = Map()

-- [[ App Settings ]]--
s = m:section(TypedSection, "global_app", translate("App Update"))
s.anonymous = true

local app_version = Template(appname .. "/app_update/app_version")
app_version.api = api
app_version.config = m.config
app_version.com = com
s:append(app_version)
s = m:section(NamedSection, "@global_app[0]", "global_app", translate("App Update"))

s:appendTemplate("/app_update/app_version", {com = com})

o = s:option(Flag, "github_proxy", translate("GitHub Proxy"), translate("Use gh-proxy instead of proxy nodes for component updates."))
o.default = 0
Expand Down
Loading
Loading