diff --git a/package/secubox/luci-app-secubox-portal/htdocs/luci-static/resources/view/secubox-portal/index.js b/package/secubox/luci-app-secubox-portal/htdocs/luci-static/resources/view/secubox-portal/index.js index bb8c1a3e..439fe374 100644 --- a/package/secubox/luci-app-secubox-portal/htdocs/luci-static/resources/view/secubox-portal/index.js +++ b/package/secubox/luci-app-secubox-portal/htdocs/luci-static/resources/view/secubox-portal/index.js @@ -84,18 +84,9 @@ return view.extend({ }, scanInitServices: function() { - // Scan /etc/init.d for service status using a temp file approach - // which is more reliable with LuCI's fs.exec - var script = - 'for s in /etc/init.d/*; do ' + - '[ -x "$s" ] || continue; ' + - 'n=$(basename "$s"); ' + - 'r=stopped; ' + - 'pgrep "$n" >/dev/null 2>&1 && r=running; ' + - 'printf "%s:%s\\n" "$n" "$r"; ' + - 'done'; - - return fs.exec('/bin/sh', ['-c', script]).then(function(res) { + // Use helper script for reliable output capture + // Falls back to inline script if helper not available + return fs.exec('/usr/bin/secubox-services-status', []).then(function(res) { var services = {}; if (res && res.stdout) { res.stdout.trim().split('\n').forEach(function(line) { @@ -106,9 +97,25 @@ return view.extend({ }); } return services; - }).catch(function(err) { - console.error('scanInitServices failed:', err); - return {}; + }).catch(function() { + // Fallback: use inline script + return fs.exec('/bin/sh', ['-c', + 'for s in /etc/init.d/*; do [ -x "$s" ] || continue; ' + + 'n=$(basename "$s"); r=stopped; ' + + 'pgrep -f "$n" >/dev/null 2>&1 && r=running; ' + + 'printf "%s:%s\\n" "$n" "$r"; done' + ]).then(function(res) { + var services = {}; + if (res && res.stdout) { + res.stdout.trim().split('\n').forEach(function(line) { + var parts = line.split(':'); + if (parts.length === 2 && parts[0] && parts[1]) { + services[parts[0]] = parts[1]; + } + }); + } + return services; + }).catch(function() { return {}; }); }); }, diff --git a/package/secubox/secubox-core/Makefile b/package/secubox/secubox-core/Makefile index 7ded8fda..d8abdc46 100644 --- a/package/secubox/secubox-core/Makefile +++ b/package/secubox/secubox-core/Makefile @@ -87,6 +87,9 @@ define Package/secubox-core/install $(INSTALL_BIN) ./root/usr/sbin/secubox-feedback $(1)/usr/sbin/ $(INSTALL_BIN) ./root/usr/sbin/secubox-tftp-recovery $(1)/usr/sbin/ + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) ./root/usr/bin/secubox-services-status $(1)/usr/bin/ + # TFTP Recovery init script $(INSTALL_BIN) ./root/etc/init.d/secubox-tftp-recovery $(1)/etc/init.d/ diff --git a/package/secubox/secubox-core/root/usr/bin/secubox-services-status b/package/secubox/secubox-core/root/usr/bin/secubox-services-status new file mode 100755 index 00000000..790bd1fe --- /dev/null +++ b/package/secubox/secubox-core/root/usr/bin/secubox-services-status @@ -0,0 +1,11 @@ +#!/bin/sh +# SecuBox Services Status - List init.d services with running status +# Used by LuCI portal for reliable service enumeration + +for s in /etc/init.d/*; do + [ -x "$s" ] || continue + n=$(basename "$s") + r=stopped + pgrep -f "$n" >/dev/null 2>&1 && r=running + printf "%s:%s\n" "$n" "$r" +done