secubox-openwrt/package/secubox/luci-app-secubox/htdocs/luci-static/resources/secubox/api.js
CyberMind-FR 5a856e5da2 feat(monitoring): Add empty-state loading and dynamic bandwidth units
- Add animated "Collecting data..." overlay with pulsing dots during
  5-second chart warmup period
- Chart legend transitions from "Waiting" to "Live" when data arrives
- Add formatBits() helper for network rate display (Kbps/Mbps/Gbps)
- Network rates now use SI units (bits) instead of bytes
- Cyberpunk theme support for empty state styling

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 04:04:32 +01:00

365 lines
8.0 KiB
JavaScript

'use strict';
'require baseclass';
'require rpc';
/**
* SecuBox Master API
* Package: luci-app-secubox
* RPCD object: luci.secubox
*/
// Version: 0.7.1 - Fixed RPCD method names
var callStatus = rpc.declare({
object: 'luci.secubox',
method: 'getStatus',
expect: { }
});
var callModules = rpc.declare({
object: 'luci.secubox',
method: 'getModules',
expect: {}
});
var callModulesByCategory = rpc.declare({
object: 'luci.secubox',
method: 'modules_by_category',
params: ['category'],
expect: {}
});
var callModuleInfo = rpc.declare({
object: 'luci.secubox',
method: 'getModuleInfo',
params: ['module'],
expect: { }
});
var callStartModule = rpc.declare({
object: 'luci.secubox',
method: 'start_module',
params: ['module']
});
var callStopModule = rpc.declare({
object: 'luci.secubox',
method: 'stop_module',
params: ['module']
});
var callRestartModule = rpc.declare({
object: 'luci.secubox',
method: 'restart_module',
params: ['module']
});
// NEW v0.3.1: Enable/Disable module methods
var callEnableModule = rpc.declare({
object: 'luci.secubox',
method: 'enable_module',
params: ['module'],
expect: { success: false, message: '' }
});
var callDisableModule = rpc.declare({
object: 'luci.secubox',
method: 'disable_module',
params: ['module'],
expect: { success: false, message: '' }
});
var callCheckModuleEnabled = rpc.declare({
object: 'luci.secubox',
method: 'check_module_enabled',
params: ['module'],
expect: { enabled: false }
});
var callHealth = rpc.declare({
object: 'luci.secubox',
method: 'getHealth',
expect: { checks: [], overall: '' }
});
var callDiagnostics = rpc.declare({
object: 'luci.secubox',
method: 'diagnostics',
expect: { }
});
var callSystemHealth = rpc.declare({
object: 'luci.secubox',
method: 'get_system_health',
expect: { }
});
var callPublicIPs = rpc.declare({
object: 'luci.secubox',
method: 'get_public_ips',
expect: { }
});
var callAlerts = rpc.declare({
object: 'luci.secubox',
method: 'get_alerts',
expect: { alerts: [] }
});
var callQuickAction = rpc.declare({
object: 'luci.secubox',
method: 'quick_action',
params: ['action'],
expect: { }
});
var callDashboardData = rpc.declare({
object: 'luci.secubox',
method: 'get_dashboard_data',
expect: { }
});
var callGetTheme = rpc.declare({
object: 'luci.secubox',
method: 'get_theme',
expect: { }
});
var callSetTheme = rpc.declare({
object: 'luci.secubox',
method: 'set_theme',
params: ['theme'],
expect: { success: false, theme: '' }
});
var callDismissAlert = rpc.declare({
object: 'luci.secubox',
method: 'dismiss_alert',
params: ['alert_id'],
expect: { }
});
var callClearAlerts = rpc.declare({
object: 'luci.secubox',
method: 'clear_alerts',
expect: { }
});
var callFixPermissions = rpc.declare({
object: 'luci.secubox',
method: 'fix_permissions',
expect: { success: false, message: '', output: '' }
});
var callFirstRunStatus = rpc.declare({
object: 'luci.secubox',
method: 'first_run_status',
expect: { }
});
var callApplyFirstRun = rpc.declare({
object: 'luci.secubox',
method: 'apply_first_run'
});
var callListApps = rpc.declare({
object: 'luci.secubox',
method: 'list_apps',
expect: { apps: [] }
});
var callGetAppManifest = rpc.declare({
object: 'luci.secubox',
method: 'get_app_manifest',
params: ['app_id']
});
var callApplyAppWizard = rpc.declare({
object: 'luci.secubox',
method: 'apply_app_wizard',
params: ['app_id', 'values']
});
var callListProfiles = rpc.declare({
object: 'luci.secubox',
method: 'listProfiles',
expect: { profiles: [] }
});
var callApplyProfile = rpc.declare({
object: 'luci.secubox',
method: 'applyProfile',
params: ['profile'],
expect: { success: false, message: '' }
});
var callRollbackProfile = rpc.declare({
object: 'luci.secubox',
method: 'rollbackProfile',
expect: { success: false, message: '' }
});
// App Store methods
var callGetAppstoreApps = rpc.declare({
object: 'luci.secubox',
method: 'get_appstore_apps',
expect: { }
});
var callGetAppstoreApp = rpc.declare({
object: 'luci.secubox',
method: 'get_appstore_app',
params: ['app_id'],
expect: { }
});
var callInstallAppstoreApp = rpc.declare({
object: 'luci.secubox',
method: 'install_appstore_app',
params: ['app_id'],
expect: { success: false }
});
var callRemoveAppstoreApp = rpc.declare({
object: 'luci.secubox',
method: 'remove_appstore_app',
params: ['app_id'],
expect: { success: false }
});
// P2P Hub methods - Collaborative peer-to-peer app catalog sharing
var callGetP2PPeers = rpc.declare({
object: 'luci.secubox',
method: 'p2p_get_peers',
expect: { peers: [] }
});
var callP2PDiscover = rpc.declare({
object: 'luci.secubox',
method: 'p2p_discover',
expect: { peers: [], discovered: 0 }
});
var callP2PAddPeer = rpc.declare({
object: 'luci.secubox',
method: 'p2p_add_peer',
params: ['address', 'name'],
expect: { success: false }
});
var callP2PRemovePeer = rpc.declare({
object: 'luci.secubox',
method: 'p2p_remove_peer',
params: ['peer_id'],
expect: { success: false }
});
var callP2PGetPeerCatalog = rpc.declare({
object: 'luci.secubox',
method: 'p2p_get_peer_catalog',
params: ['peer_id'],
expect: { apps: [] }
});
var callP2PShareCatalog = rpc.declare({
object: 'luci.secubox',
method: 'p2p_share_catalog',
params: ['enabled'],
expect: { success: false }
});
var callP2PGetSettings = rpc.declare({
object: 'luci.secubox',
method: 'p2p_get_settings',
expect: { }
});
var callP2PSetSettings = rpc.declare({
object: 'luci.secubox',
method: 'p2p_set_settings',
params: ['settings'],
expect: { success: false }
});
function formatUptime(seconds) {
if (!seconds) return '0s';
var d = Math.floor(seconds / 86400);
var h = Math.floor((seconds % 86400) / 3600);
var m = Math.floor((seconds % 3600) / 60);
if (d > 0) return d + 'd ' + h + 'h';
if (h > 0) return h + 'h ' + m + 'm';
return m + 'm';
}
function formatBytes(bytes) {
if (!bytes) return '0 B';
var k = 1024;
var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
}
function formatBits(bytes, decimals) {
if (!bytes) return '0 bps';
var bits = bytes * 8;
var k = 1000; // SI units (1000, not 1024)
var sizes = ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps'];
var i = Math.floor(Math.log(bits) / Math.log(k));
var d = (decimals !== undefined) ? decimals : 1;
return (bits / Math.pow(k, i)).toFixed(d) + ' ' + sizes[i];
}
return baseclass.extend({
getStatus: callStatus,
getModules: callModules,
getModulesByCategory: callModulesByCategory,
getModuleInfo: callModuleInfo,
// DEPRECATED: Use enable/disable instead
startModule: callStartModule,
stopModule: callStopModule,
restartModule: callRestartModule,
// NEW v0.3.1: Enable/Disable methods
enableModule: callEnableModule,
disableModule: callDisableModule,
checkModuleEnabled: callCheckModuleEnabled,
// Health & diagnostics
getHealth: callHealth,
getDiagnostics: callDiagnostics,
getSystemHealth: callSystemHealth,
getPublicIPs: callPublicIPs,
getAlerts: callAlerts,
quickAction: callQuickAction,
getDashboardData: callDashboardData,
getTheme: callGetTheme,
setTheme: callSetTheme,
dismissAlert: callDismissAlert,
clearAlerts: callClearAlerts,
fixPermissions: callFixPermissions,
getFirstRunStatus: callFirstRunStatus,
applyFirstRun: callApplyFirstRun,
listApps: callListApps,
getAppManifest: callGetAppManifest,
applyAppWizard: callApplyAppWizard,
listProfiles: callListProfiles,
applyProfile: callApplyProfile,
rollbackProfile: callRollbackProfile,
// App Store
getAppstoreApps: callGetAppstoreApps,
getAppstoreApp: callGetAppstoreApp,
installAppstoreApp: callInstallAppstoreApp,
removeAppstoreApp: callRemoveAppstoreApp,
// P2P Hub - Collaborative catalog sharing
getP2PPeers: callGetP2PPeers,
p2pDiscover: callP2PDiscover,
p2pAddPeer: callP2PAddPeer,
p2pRemovePeer: callP2PRemovePeer,
p2pGetPeerCatalog: callP2PGetPeerCatalog,
p2pShareCatalog: callP2PShareCatalog,
p2pGetSettings: callP2PGetSettings,
p2pSetSettings: callP2PSetSettings,
// Utilities
formatUptime: formatUptime,
formatBytes: formatBytes,
formatBits: formatBits
});