luci-base, luci-mod-status: expose LuCI version via ubus
authorJo-Philipp Wich <jo@mein.io>
Sat, 17 Dec 2022 14:00:24 +0000 (15:00 +0100)
committerJo-Philipp Wich <jo@mein.io>
Sat, 17 Dec 2022 14:01:46 +0000 (15:01 +0100)
Instead of scraping the LuCI version from Lua sources, fetch it via ubus
in order to be independent from the Lua runtime.

Fixes: #6154
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/root/usr/share/rpcd/ucode/luci
modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js
modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status-index.json

index e2379793528b96722528dc71635ac3206e0da1f7..a30e276b8087c44124c622fc7728b7eafba12711 100644 (file)
@@ -7,6 +7,7 @@ import { stdin, access, dirname, basename, open, popen, glob, lsdir, readfile, r
 import { cursor } from 'uci';
 
 import { init_list, init_index, init_enabled, init_action, conntrack_list, process_list } from 'luci.sys';
+import { revision, branch } from 'luci.version';
 import { statvfs } from 'luci.core';
 
 import timezones from 'luci.zoneinfo';
@@ -17,6 +18,12 @@ function shellquote(s) {
 }
 
 const methods = {
+       getVersion: {
+               call: function(request) {
+                       return { revision, branch };
+               }
+       },
+
        getInitList: {
                args: { name: 'name' },
                call: function(request) {
index ae7efa3e75c29832d11248b3421cc4aacda47a11..45f7b4acae6d4593ad077adf33685e101796f1b4 100644 (file)
@@ -3,6 +3,11 @@
 'require fs';
 'require rpc';
 
+var callLuciVersion = rpc.declare({
+       object: 'luci',
+       method: 'getVersion'
+});
+
 var callSystemBoard = rpc.declare({
        object: 'system',
        method: 'board'
@@ -20,7 +25,7 @@ return baseclass.extend({
                return Promise.all([
                        L.resolveDefault(callSystemBoard(), {}),
                        L.resolveDefault(callSystemInfo(), {}),
-                       fs.lines('/usr/lib/lua/luci/version.lua')
+                       L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' })
                ]);
        },
 
@@ -29,11 +34,7 @@ return baseclass.extend({
                    systeminfo  = data[1],
                    luciversion = data[2];
 
-               luciversion = luciversion.filter(function(l) {
-                       return l.match(/^\s*(luciname|luciversion)\s*=/);
-               }).map(function(l) {
-                       return l.replace(/^\s*\w+\s*=\s*['"]([^'"]+)['"].*$/, '$1');
-               }).join(' ');
+               luciversion = luciversion.branch + ' ' + luciversion.revision;
 
                var datestr = null;
 
index a9ae0cef49e837418256116ff071d7ac841c5ae0..7c2cd0998f3395576cc45f4d0f783bbc052bebf4 100644 (file)
@@ -5,10 +5,10 @@
                        "file": {
                                "/proc/sys/net/netfilter/nf_conntrack_count": [ "read" ],
                                "/proc/sys/net/netfilter/nf_conntrack_max": [ "read" ],
-                               "/usr/lib/lua/luci/version.lua": [ "read" ],
                                "/www/luci-static/resources/view/status/include": [ "list" ]
                        },
                        "ubus": {
+                               "luci": [ "getVersion" ],
                                "file": [ "list", "read" ],
                                "system": [ "board", "info" ]
                        }