luci-base: only render theme specific sysauth template when it exists
authorJo-Philipp Wich <jo@mein.io>
Fri, 25 Nov 2022 14:30:20 +0000 (15:30 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 25 Nov 2022 14:30:20 +0000 (15:30 +0100)
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>
modules/luci-base/ucode/dispatcher.uc
modules/luci-base/ucode/runtime.uc

index 9d310bb5c274cdfc2286ffd8e1d91422fa2dd033..9500528743f0ed1620947ef44275da859662a366 100644 (file)
@@ -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',
index 89e396d468939b48f29b5d8f8e69e05cd48a1d59..e460127e2c9dbdb31b7064dfb2790cdd379b1a26 100644 (file)
@@ -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 });