From 2371bd5c34d357165291331ecfa1a96ce40aa133 Mon Sep 17 00:00:00 2001 From: sbwml Date: Sat, 5 Oct 2024 04:24:14 +0800 Subject: [PATCH] adapt openwrt-24.10 Signed-off-by: sbwml --- Makefile | 1 + files/generic/090-cover-index_files | 8 +- files/generic/luci | 47 +++++- files/generic/luci-mod-status-autocore.json | 2 +- files/generic/sys.uc | 159 ++++++++++++++++++++ 5 files changed, 210 insertions(+), 7 deletions(-) create mode 100644 files/generic/sys.uc diff --git a/Makefile b/Makefile index 8242911..1a9cf59 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ define Package/autocore/install/Default $(INSTALL_DIR) $(1)/etc $(CP) ./files/generic/10_system.js $(1)/etc/rpcd_10_system.js $(CP) ./files/generic/luci $(1)/etc/rpcd_luci + $(CP) ./files/generic/sys.uc $(1)/etc/ucode_sys $(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_BIN) ./files/generic/090-cover-index_files $(1)/etc/uci-defaults/ diff --git a/files/generic/090-cover-index_files b/files/generic/090-cover-index_files index feff66a..1b0abae 100755 --- a/files/generic/090-cover-index_files +++ b/files/generic/090-cover-index_files @@ -1,9 +1,9 @@ #!/bin/sh -[ ! -f '/etc/rpcd_10_system.js' ] || \ - mv -f '/etc/rpcd_10_system.js' '/www/luci-static/resources/view/status/include/10_system.js' -[ ! -f '/etc/rpcd_luci' ] || \ - mv -f '/etc/rpcd_luci' '/usr/share/rpcd/ucode/luci' +[ -f '/etc/rpcd_10_system.js' ] && mv -f '/etc/rpcd_10_system.js' '/www/luci-static/resources/view/status/include/10_system.js' +[ -f '/etc/rpcd_luci' ] && mv -f '/etc/rpcd_luci' '/usr/share/rpcd/ucode/luci' +[ -f '/etc/ucode_sys' ] && mv -f '/etc/ucode_sys' '/usr/share/ucode/luci/sys.uc' + /etc/init.d/rpcd restart exit 0 diff --git a/files/generic/luci b/files/generic/luci index f2ee672..5036dea 100755 --- a/files/generic/luci +++ b/files/generic/luci @@ -8,7 +8,7 @@ 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 { statvfs, uname } from 'luci.core'; import timezones from 'luci.zoneinfo'; @@ -211,7 +211,7 @@ const methods = { relayd: access('/usr/sbin/relayd') == true, }; - const wifi_features = [ 'eap', '11ac', '11ax', '11r', 'acs', 'sae', 'owe', 'suiteb192', 'wep', 'wps' ]; + const wifi_features = [ 'eap', '11ac', '11ax', '11r', 'acs', 'sae', 'owe', 'suiteb192', 'wep', 'wps', 'ocv' ]; if (access('/usr/sbin/hostapd')) { result.hostapd = { cli: access('/usr/sbin/hostapd_cli') == true }; @@ -543,6 +543,49 @@ const methods = { } }, + getBuiltinEthernetPorts: { + call: function() { + let fd = open('/etc/board.json', 'r'); + let board = fd ? json(fd) : {}; + let ports = []; + + for (let k in [ 'lan', 'wan' ]) { + if (!board?.network?.[k]) + continue; + + if (type(board.network[k].ports) == 'array') { + for (let ifname in board.network[k].ports) { + push(ports, { role: k, device: ifname }); + } + } + else if (type(board.network[k].device) == 'string') { + push(ports, { role: k, device: board.network[k].device }); + } + } + + /* Workaround for targets that do not enumerate all netdevs in board.json */ + if (uname().machine in [ 'x86_64' ] && + match(ports[0]?.device, /^eth\d+$/)) { + let bus = readlink(`/sys/class/net/${ports[0].device}/device/subsystem`); + + for (let netdev in lsdir('/sys/class/net')) { + if (!match(netdev, /^eth\d+$/)) + continue; + + if (length(filter(ports, port => port.device == netdev))) + continue; + + if (readlink(`/sys/class/net/${netdev}/device/subsystem`) != bus) + continue; + + push(ports, { role: 'unknown', device: netdev }); + } + } + + return { result: ports }; + } + }, + getCPUBench: { call: function() { return { cpubench: readfile('/etc/bench.log') || '' }; diff --git a/files/generic/luci-mod-status-autocore.json b/files/generic/luci-mod-status-autocore.json index 47c4d33..4e496d8 100644 --- a/files/generic/luci-mod-status-autocore.json +++ b/files/generic/luci-mod-status-autocore.json @@ -3,7 +3,7 @@ "description": "Grant access to autocore", "read": { "ubus": { - "luci": [ "getCPUInfo", "getETHInfo", "getTempInfo", "getCPUBench", "getCPUUsage" ] + "luci": [ "getCPUInfo", "getETHInfo", "getTempInfo", "getCPUBench", "getCPUUsage", "getOnlineUsers" ] } } } diff --git a/files/generic/sys.uc b/files/generic/sys.uc new file mode 100644 index 0000000..24944f5 --- /dev/null +++ b/files/generic/sys.uc @@ -0,0 +1,159 @@ +// Copyright 2022 Jo-Philipp Wich +// Licensed to the public under the Apache License 2.0. + +import { basename, readlink, readfile, open, popen, stat, glob } from 'fs'; + +export function process_list() { + const top = popen('/bin/busybox top -bn1'); + let line, list = []; + + for (let line = top.read('line'); length(line); line = top.read('line')) { + let m = match(trim(line), /^([0-9]+) +([0-9]+) +(.+) +([RSDZTWI][ { + const s = stat(path); + + return s?.type == 'file' && s?.perm?.user_exec; + }), basename); +}; + +export function init_index(name) { + const src = readfile(`/etc/init.d/${basename(name)}`, 2048); + const idx = []; + + for (let m in match(src, /^[[:space:]]*(START|STOP)=('[0-9][0-9]'|"[0-9][0-9]"|[0-9][0-9])[[:space:]]*$/gs)) { + switch (m[1]) { + case 'START': idx[0] = +trim(m[2], '"\''); break; + case 'STOP': idx[1] = +trim(m[2], '"\''); break; + } + } + + return length(idx) ? idx : null; +}; + +export function init_enabled(name) { + for (let path in glob(`/etc/rc.d/[SK][0-9][0-9]${basename(name)}`)) { + const ln = readlink(path); + const s1 = stat(index(ln, '/') == 0 ? ln : `/etc/rc.d/${ln}`); + const s2 = stat(`/etc/init.d/${basename(name)}`); + + if (s1?.inode == s2?.inode && s1?.type == 'file' && s1?.perm?.user_exec) + return true; + } + + return false; +}; + +export function init_action(name, action) { + const s = stat(`/etc/init.d/${basename(name)}`); + + if (s?.type != 'file' || s?.user_exec == false) + return false; + + return system(`env -i /etc/init.d/${basename(name)} ${action} >/dev/null`); +};