From 86eb09d0bbd289f53fa2605ffe0abbb54796f587 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 30 Jul 2024 00:06:23 +0200 Subject: [PATCH] luci-theme-openwrt: convert Lua templates to ucode Convert the theme's Lua templates to ucode to avoid the implicit dependency on the luci-lua-runtime package. Signed-off-by: Jo-Philipp Wich (cherry picked from commit 79a7012dce62624d61bb50934f1b382518455cdc) --- .../luasrc/view/themes/openwrt.org/header.htm | 95 ------------------- .../template/themes/openwrt.org/footer.ut} | 7 +- .../template/themes/openwrt.org/header.ut | 88 +++++++++++++++++ 3 files changed, 91 insertions(+), 99 deletions(-) delete mode 100644 themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm rename themes/luci-theme-openwrt/{luasrc/view/themes/openwrt.org/footer.htm => ucode/template/themes/openwrt.org/footer.ut} (73%) create mode 100644 themes/luci-theme-openwrt/ucode/template/themes/openwrt.org/header.ut diff --git a/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm b/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm deleted file mode 100644 index 1d95bae886..0000000000 --- a/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/header.htm +++ /dev/null @@ -1,95 +0,0 @@ -<%# - Copyright 2008 Steven Barth - Copyright 2008-2010 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - -<% - local sys = require "luci.sys" - local util = require "luci.util" - local http = require "luci.http" - local disp = require "luci.dispatcher" - local ver = require "luci.version" - - local sysinfo = util.ubus("system", "info") or { } - local loadinfo = sysinfo.load or { 0, 0, 0 } - local boardinfo = util.ubus("system", "board") or { } - - local node = disp.context.dispatched - - http.prepare_content("application/xhtml+xml") --%> - - - - - - - - - -<% if node and node.css then %> -<% end -%> -<% if css then %> -<% end -%> - - - -<%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI - -"> - - - - - -
- - -
- - - - - <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%> -
-

<%:No password set!%>

-

<%:There is no password set on this router. Please configure a root password to protect the web interface.%>

- <% if disp.lookup("admin/system/admin") then %> - - <% end %> -
- <%- end -%> - - <%- if boardinfo.rootfs_type == "initramfs" then -%> -
-

<%:System running in recovery (initramfs) mode.%>

-

<%:No changes to settings will be stored and are lost after rebooting. This mode should only be used to install a firmware upgrade%>

- <% if disp.lookup("admin/system/flash") then %> - - <% end %> -
- <%- end -%> diff --git a/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/footer.htm b/themes/luci-theme-openwrt/ucode/template/themes/openwrt.org/footer.ut similarity index 73% rename from themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/footer.htm rename to themes/luci-theme-openwrt/ucode/template/themes/openwrt.org/footer.ut index 356b6dac10..1b6bfff5bb 100644 --- a/themes/luci-theme-openwrt/luasrc/view/themes/openwrt.org/footer.htm +++ b/themes/luci-theme-openwrt/ucode/template/themes/openwrt.org/footer.ut @@ -1,16 +1,15 @@ -<%# +{# Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich Licensed to the public under the Apache License 2.0. --%> +-#}

- <% local ver = require "luci.version" -%> - Powered by <%= ver.luciname %> (<%= ver.luciversion %>) + Powered by {{ version.luciname }} ({{ version.luciversion }})

diff --git a/themes/luci-theme-openwrt/ucode/template/themes/openwrt.org/header.ut b/themes/luci-theme-openwrt/ucode/template/themes/openwrt.org/header.ut new file mode 100644 index 0000000000..f6c20be188 --- /dev/null +++ b/themes/luci-theme-openwrt/ucode/template/themes/openwrt.org/header.ut @@ -0,0 +1,88 @@ +{# + Copyright 2008 Steven Barth + Copyright 2008-2010 Jo-Philipp Wich + Licensed to the public under the Apache License 2.0. +-#} + +{% + import { getuid, getspnam } from 'luci.core'; + + const boardinfo = ubus.call('system', 'board'); + const loadinfo = ubus.call("system", "info")?.load; + + http.prepare_content("application/xhtml+xml"); +-%} + + + + + + + + + +{% if (node?.css): %} + +{% endif %} +{% if (css): %} + +{% endif %} + + + +{{ striptags(`${boardinfo.hostname ?? '?'}${node ? ` - ${_(node.title)}` : ''}`) }} - LuCI + + + + + + + +
+ + +
+ + + + + {% if (getuid() == 0 && getspnam('root')?.pwdp === '' && join('-', ctx.request_path) != 'admin-system-admin'): %} +
+

{{ _('No password set!') }}

+

{{ _('There is no password set on this router. Please configure a root password to protect the web interface.') }}

+ {% if (dispatcher.lookup("admin/system/admin")): %} + + {% endif %} +
+ {% endif %} + + {% if (boardinfo.rootfs_type == "initramfs"): %} +
+

{{ _('System running in recovery (initramfs) mode.') }}

+

{{ _('No changes to settings will be stored and are lost after rebooting. This mode should only be used to install a firmware upgrade') }}

+ {% if (dispatcher.lookup("admin/system/flash")): %} + + {% endif %} +
+ {% endif %} -- 2.30.2