luci-app-passwall: sync upstream

last commit: 2a398f588c
This commit is contained in:
gitea-action 2025-01-13 23:30:21 +08:00
parent b901e29c0c
commit 248a8ec158
7 changed files with 55 additions and 8 deletions

View File

@ -2,9 +2,11 @@ local api = require "luci.passwall.api"
local appname = "passwall" local appname = "passwall"
m = Map(appname) m = Map(appname)
m.redirect = api.url("acl")
api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(api.url("acl")) luci.http.redirect(m.redirect)
end end
local fs = api.fs local fs = api.fs

View File

@ -2,10 +2,11 @@ local api = require "luci.passwall.api"
local appname = "passwall" local appname = "passwall"
m = Map(appname, translate("Node Config")) m = Map(appname, translate("Node Config"))
m.redirect = api.url() m.redirect = api.url("node_list")
api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(api.url("node_list")) luci.http.redirect(m.redirect)
end end
s = m:section(NamedSection, arg[1], "nodes", "") s = m:section(NamedSection, arg[1], "nodes", "")

View File

@ -144,6 +144,7 @@ s.sortable = true
s.template = "cbi/tblsection" s.template = "cbi/tblsection"
s.extedit = api.url("node_subscribe_config", "%s") s.extedit = api.url("node_subscribe_config", "%s")
function s.create(e, t) function s.create(e, t)
m.no_commit = true
local id = TypedSection.create(e, t) local id = TypedSection.create(e, t)
luci.http.redirect(e.extedit:format(id)) luci.http.redirect(e.extedit:format(id))
end end

View File

@ -1,4 +1,5 @@
local api = require "luci.passwall.api" local api = require "luci.passwall.api"
local uci = require "luci.model.uci".cursor()
local appname = "passwall" local appname = "passwall"
m = Map(appname) m = Map(appname)
@ -8,6 +9,25 @@ if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(m.redirect) luci.http.redirect(m.redirect)
end end
function m.commit_handler(self)
self:del(arg[1], "md5")
end
if api.is_js_luci() then
m.apply_on_parse = false
m.on_after_apply = function(self)
uci:delete(appname, arg[1], "md5")
uci:commit(appname)
luci.http.write([[
<script type="text/javascript">
setTimeout(function() {
window.location.href = ']] .. self.redirect .. [[';
}, 1000);
</script>
]])
end
end
local has_ss = api.is_finded("ss-redir") local has_ss = api.is_finded("ss-redir")
local has_ss_rust = api.is_finded("sslocal") local has_ss_rust = api.is_finded("sslocal")
local has_trojan_plus = api.is_finded("trojan-plus") local has_trojan_plus = api.is_finded("trojan-plus")
@ -55,10 +75,6 @@ s = m:section(NamedSection, arg[1])
s.addremove = false s.addremove = false
s.dynamic = false s.dynamic = false
function m.commit_handler(self)
self:del(arg[1], "md5")
end
o = s:option(Value, "remark", translate("Subscribe Remark")) o = s:option(Value, "remark", translate("Subscribe Remark"))
o.rmempty = false o.rmempty = false

View File

@ -2,9 +2,11 @@ local api = require "luci.passwall.api"
local appname = "passwall" local appname = "passwall"
m = Map(appname) m = Map(appname)
m.redirect = api.url()
api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(api.url()) luci.http.redirect(m.redirect)
end end
local has_singbox = api.finded_com("singbox") local has_singbox = api.finded_com("singbox")

View File

@ -4,6 +4,11 @@ local types_dir = "/usr/lib/lua/luci/model/cbi/passwall/server/type/"
m = Map("passwall_server", translate("Server Config")) m = Map("passwall_server", translate("Server Config"))
m.redirect = api.url("server") m.redirect = api.url("server")
api.set_apply_on_parse(m)
if not arg[1] or not m:get(arg[1]) then
luci.http.redirect(m.redirect)
end
s = m:section(NamedSection, arg[1], "user", "") s = m:section(NamedSection, arg[1], "user", "")
s.addremove = false s.addremove = false

View File

@ -38,6 +38,26 @@ function is_old_uci()
return sys.call("grep 'require \"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0 return sys.call("grep 'require \"uci\"' /usr/lib/lua/luci/model/uci.lua >/dev/null 2>&1") == 0
end end
function set_apply_on_parse(map)
if not map then
return
end
if is_js_luci() then
map.apply_on_parse = false
map.on_after_apply = function(self)
if self.redirect then
luci.http.write([[
<script type="text/javascript">
setTimeout(function() {
window.location.href = ']] .. self.redirect .. [[';
}, 1000);
</script>
]])
end
end
end
end
function uci_save(cursor, config, commit, apply) function uci_save(cursor, config, commit, apply)
if is_old_uci() then if is_old_uci() then
cursor:save(config) cursor:save(config)