diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-11-25 15:30:20 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-11-25 15:30:20 +0100 |
commit | bed67dc0006d8869748a738a9f1a2f17e2b3d038 (patch) | |
tree | 0b4ae1cdea38f9fdd971091805c0a94e9c0dc317 /modules/luci-base/ucode | |
parent | 885e3a5f0b3323f007cb265be210e9efe939530b (diff) |
luci-base: only render theme specific sysauth template when it exists
Avoid displaying non-fatal "File not found" exceptions when a theme is not
shipping an own sysauth template.
Fixes: #6118
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/ucode')
-rw-r--r-- | modules/luci-base/ucode/dispatcher.uc | 16 | ||||
-rw-r--r-- | modules/luci-base/ucode/runtime.uc | 6 |
2 files changed, 15 insertions, 7 deletions
diff --git a/modules/luci-base/ucode/dispatcher.uc b/modules/luci-base/ucode/dispatcher.uc index 9d310bb5c2..9500528743 100644 --- a/modules/luci-base/ucode/dispatcher.uc +++ b/modules/luci-base/ucode/dispatcher.uc @@ -922,16 +922,18 @@ dispatch = function(_http, path) { http.header('X-LuCI-Login-Required', 'yes'); let scope = { duser: 'root', fuser: user }; + let theme_sysauth = `themes/${basename(runtime.env.media)}/sysauth`; - try { - runtime.render(`themes/${basename(runtime.env.media)}/sysauth`, scope); - } - catch (e) { - runtime.env.media_error = `${e}`; - runtime.render('sysauth', scope); + if (runtime.is_ucode_template(theme_sysauth) || runtime.is_lua_template(theme_sysauth)) { + try { + return runtime.render(theme_sysauth, scope); + } + catch (e) { + runtime.env.media_error = `${e}`; + } } - return; + return runtime.render('sysauth', scope); } let cookie_name = (http.getenv('HTTPS') == 'on') ? 'sysauth_https' : 'sysauth_http', diff --git a/modules/luci-base/ucode/runtime.uc b/modules/luci-base/ucode/runtime.uc index 89e396d468..e460127e2c 100644 --- a/modules/luci-base/ucode/runtime.uc +++ b/modules/luci-base/ucode/runtime.uc @@ -65,6 +65,12 @@ const Class = { return access(`${template_directory}/${path}.ut`); }, + is_lua_template: function(path) { + let vm = this.init_lua(true); + + return vm && access(`${vm.get('_G', 'luci', 'template', 'viewdir')}/${path}.htm`); + }, + render_ucode: function(path, scope) { let tmplfunc = loadfile(path, { raw_mode: false }); |