adapt openwrt-24.10

Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
sbwml 2024-10-05 04:24:14 +08:00
parent 28cc41185e
commit 2371bd5c34
5 changed files with 210 additions and 7 deletions

View File

@ -39,6 +39,7 @@ define Package/autocore/install/Default
$(INSTALL_DIR) $(1)/etc $(INSTALL_DIR) $(1)/etc
$(CP) ./files/generic/10_system.js $(1)/etc/rpcd_10_system.js $(CP) ./files/generic/10_system.js $(1)/etc/rpcd_10_system.js
$(CP) ./files/generic/luci $(1)/etc/rpcd_luci $(CP) ./files/generic/luci $(1)/etc/rpcd_luci
$(CP) ./files/generic/sys.uc $(1)/etc/ucode_sys
$(INSTALL_DIR) $(1)/etc/uci-defaults $(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/generic/090-cover-index_files $(1)/etc/uci-defaults/ $(INSTALL_BIN) ./files/generic/090-cover-index_files $(1)/etc/uci-defaults/

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/bin/sh
[ ! -f '/etc/rpcd_10_system.js' ] || \ [ -f '/etc/rpcd_10_system.js' ] && mv -f '/etc/rpcd_10_system.js' '/www/luci-static/resources/view/status/include/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_luci' ] || \ [ -f '/etc/ucode_sys' ] && mv -f '/etc/ucode_sys' '/usr/share/ucode/luci/sys.uc'
mv -f '/etc/rpcd_luci' '/usr/share/rpcd/ucode/luci'
/etc/init.d/rpcd restart /etc/init.d/rpcd restart
exit 0 exit 0

View File

@ -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 { init_list, init_index, init_enabled, init_action, conntrack_list, process_list } from 'luci.sys';
import { revision, branch } from 'luci.version'; import { revision, branch } from 'luci.version';
import { statvfs } from 'luci.core'; import { statvfs, uname } from 'luci.core';
import timezones from 'luci.zoneinfo'; import timezones from 'luci.zoneinfo';
@ -211,7 +211,7 @@ const methods = {
relayd: access('/usr/sbin/relayd') == true, 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')) { if (access('/usr/sbin/hostapd')) {
result.hostapd = { cli: access('/usr/sbin/hostapd_cli') == true }; 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: { getCPUBench: {
call: function() { call: function() {
return { cpubench: readfile('/etc/bench.log') || '' }; return { cpubench: readfile('/etc/bench.log') || '' };

View File

@ -3,7 +3,7 @@
"description": "Grant access to autocore", "description": "Grant access to autocore",
"read": { "read": {
"ubus": { "ubus": {
"luci": [ "getCPUInfo", "getETHInfo", "getTempInfo", "getCPUBench", "getCPUUsage" ] "luci": [ "getCPUInfo", "getETHInfo", "getTempInfo", "getCPUBench", "getCPUUsage", "getOnlineUsers" ]
} }
} }
} }

159
files/generic/sys.uc Normal file
View File

@ -0,0 +1,159 @@
// Copyright 2022 Jo-Philipp Wich <jo@mein.io>
// 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][<NW ][<N ]) +([0-9]+m?) +([0-9]+%) +([0-9]+%) +(.+)$/);
if (m && m[8] != '/bin/busybox top -bn1') {
push(list, {
PID: m[1],
PPID: m[2],
USER: trim(m[3]),
STAT: m[4],
VSZ: m[5],
'%MEM': m[6],
'%CPU': m[7],
COMMAND: m[8]
});
}
}
top.close();
return list;
};
export function conntrack_list(callback) {
const etcpr = open('/etc/protocols');
const protos = {};
if (etcpr) {
for (let line = etcpr.read('line'); length(line); line = etcpr.read('line')) {
const m = match(line, /^([^# \t\n]+)\s+([0-9]+)\s+/);
if (m)
protos[m[2]] = m[1];
}
etcpr.close();
}
const nfct = open('/proc/net/nf_conntrack', 'r');
let connt;
if (nfct) {
let lineCount = 0;
for (let line = nfct.read('line'); length(line) && lineCount < 1200; line = nfct.read('line')) {
lineCount++;
let m = match(line, /^(ipv[46]) +([0-9]+) +\S+ +([0-9]+)( +.+)\n$/);
if (!m)
continue;
let fam = m[1];
let l3 = m[2];
let l4 = m[3];
let tuples = m[4];
let timeout = null;
m = match(tuples, /^ +([0-9]+)( .+)$/);
if (m) {
timeout = m[1];
tuples = m[2];
}
if (index(tuples, 'TIME_WAIT') !== -1)
continue;
let e = {
bytes: 0,
packets: 0,
layer3: fam,
layer4: protos[l4] ?? 'unknown',
timeout: +timeout
};
for (let kv in match(tuples, / (\w+)=(\S+)/g)) {
switch (kv[1]) {
case 'bytes':
case 'packets':
e[kv[1]] += +kv[2];
break;
case 'src':
case 'dst':
e[kv[1]] ??= arrtoip(iptoarr(kv[2]));
break;
case 'sport':
case 'dport':
e[kv[1]] ??= +kv[2];
break;
default:
e[kv[1]] = kv[2];
}
}
if (callback)
callback(e);
else
push(connt ??= [], e);
}
nfct.close();
}
return callback ? true : (connt ?? []);
};
export function init_list() {
return map(filter(glob('/etc/init.d/*'), path => {
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`);
};