fix(webapp): Add robust fallback methods for disk usage display

- Add 4 fallback methods for disk stats when primary RPC fails
- Method 1: luci.system-hub RPC (primary)
- Method 2: file.exec with df command
- Method 3: LuCI CGI realtime disk endpoint
- Method 4: luci-rpc getSystemInfo

Bump to v1.5.0-7

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-01-23 07:02:39 +01:00
parent 35eb1f79b2
commit 618d303662
2 changed files with 54 additions and 13 deletions

View File

@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=secubox-app-webapp
PKG_VERSION:=1.5.0
PKG_RELEASE:=6
PKG_RELEASE:=7
PKG_LICENSE:=MIT
PKG_MAINTAINER:=CyberMind.FR <contact@cybermind.fr>

View File

@ -3901,19 +3901,22 @@
}
}
// Get real disk usage via df command
// Get real disk usage via multiple fallback methods
async function updateDiskUsage() {
const setDiskValue = (percent) => {
document.getElementById('diskValue').textContent = percent;
updateGauge('diskGauge', percent);
};
try {
// Use luci.system-hub RPC for disk info
// Method 1: Use luci.system-hub RPC for disk info
const result = await UBUS.call('luci.system-hub', 'get_system_status').catch(() => null);
if (result && result.disk) {
const percent = result.disk.usage || 0;
document.getElementById('diskValue').textContent = percent;
updateGauge('diskGauge', percent);
if (result && result.disk && typeof result.disk.usage === 'number') {
setDiskValue(result.disk.usage);
return;
}
// Fallback: try file.exec with df
// Method 2: Try file.exec with df
const dfResult = await UBUS.execCommand('/bin/df', ['-P', '/']).catch(() => null);
if (dfResult && dfResult.stdout) {
const lines = dfResult.stdout.trim().split('\n');
@ -3923,17 +3926,55 @@
const used = parseInt(parts[2]) || 0;
const available = parseInt(parts[3]) || 0;
const total = used + available;
const percent = total > 0 ? Math.round((used / total) * 100) : 0;
document.getElementById('diskValue').textContent = percent;
updateGauge('diskGauge', percent);
return;
if (total > 0) {
setDiskValue(Math.round((used / total) * 100));
return;
}
}
}
}
// Method 3: Try reading file directly via file.read
const statResult = await UBUS.call('file', 'read', { path: '/proc/mounts' }).catch(() => null);
if (statResult && statResult.data) {
// Found mounts, try statfs on root
const statfsResult = await UBUS.call('file', 'stat', { path: '/' }).catch(() => null);
if (statfsResult) {
// If we got here, at least the file API works - try df via CGI
const cgiResult = await fetch(`${CONFIG.serverUrl}/cgi-bin/luci/admin/status/realtime/disk`, {
credentials: 'include'
}).then(r => r.json()).catch(() => null);
if (cgiResult && Array.isArray(cgiResult) && cgiResult.length > 1) {
// LuCI realtime disk format: [timestamp, [[device, free, used], ...]]
const diskData = cgiResult[1];
if (diskData && diskData[0]) {
const [, free, used] = diskData[0];
const total = free + used;
if (total > 0) {
setDiskValue(Math.round((used / total) * 100));
return;
}
}
}
}
}
// Method 4: Try luci-rpc sys namespace
const sysResult = await UBUS.call('luci-rpc', 'getSystemInfo').catch(() => null);
if (sysResult && sysResult.root) {
const total = sysResult.root.total || 0;
const free = sysResult.root.free || 0;
const used = total - free;
if (total > 0) {
setDiskValue(Math.round((used / total) * 100));
return;
}
}
} catch (e) {
console.warn('Disk usage error:', e);
}
// Fallback to showing '--'
// All methods failed - show '--'
document.getElementById('diskValue').textContent = '--';
}