From 618d303662c9ff66681d4885f44a87fc35f5582b Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Fri, 23 Jan 2026 07:02:39 +0100 Subject: [PATCH] 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 --- package/secubox/secubox-app-webapp/Makefile | 2 +- .../files/www/secubox-dashboard/index.html | 65 +++++++++++++++---- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/package/secubox/secubox-app-webapp/Makefile b/package/secubox/secubox-app-webapp/Makefile index 47d1e24a..2769849b 100644 --- a/package/secubox/secubox-app-webapp/Makefile +++ b/package/secubox/secubox-app-webapp/Makefile @@ -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 diff --git a/package/secubox/secubox-app-webapp/files/www/secubox-dashboard/index.html b/package/secubox/secubox-app-webapp/files/www/secubox-dashboard/index.html index ed7b990e..a2cef359 100644 --- a/package/secubox/secubox-app-webapp/files/www/secubox-dashboard/index.html +++ b/package/secubox/secubox-app-webapp/files/www/secubox-dashboard/index.html @@ -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 = '--'; }