secubox-openwrt/luci-app-network-modes/htdocs/luci-static/resources/network-modes/api.js
CyberMind-FR 0759c748dd fix: Add missing API functions to resolve module errors
Fixed JavaScript errors in multiple modules by adding missing API functions:

1. auth-guardian:
   - Added getSessions() alias for listSessions compatibility

2. netifyd-dashboard:
   - Added getAllData() aggregating status, stats, flows, applications

3. wireguard-dashboard:
   - Added getAllData() aggregating status, peers, interfaces, traffic

4. network-modes:
   - Added getAllData() aggregating status, mode, available_modes, interfaces

5. netdata-dashboard:
   - Fixed ACL permissions: changed ubus object from 'netdata' to 'luci.netdata-dashboard'
   - Added missing RPC methods to ACL (netdata_status, netdata_alarms, netdata_info)
   - Added write permissions for service control methods

Resolves:
- TypeError: api.getSessions is not a function (auth-guardian)
- TypeError: api.getAllData is not a function (netifyd, wireguard, network-modes)
- RPC error -32002: Access denied (netdata-dashboard)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-26 21:42:09 +01:00

75 lines
1.5 KiB
JavaScript

'use strict';
'require baseclass';
'require rpc';
/**
* Network Modes API
* Package: luci-app-network-modes
* RPCD object: luci.network-modes
*/
// Version: 0.2.2
var callStatus = rpc.declare({
object: 'luci.network-modes',
method: 'status',
expect: { }
});
var callGetCurrentMode = rpc.declare({
object: 'luci.network-modes',
method: 'get_current_mode',
expect: { mode: '' }
});
var callGetAvailableModes = rpc.declare({
object: 'luci.network-modes',
method: 'get_available_modes',
expect: { modes: [] }
});
var callSetMode = rpc.declare({
object: 'luci.network-modes',
method: 'set_mode',
params: ['mode']
});
var callGetInterfaces = rpc.declare({
object: 'luci.network-modes',
method: 'get_interfaces',
expect: { interfaces: [] }
});
var callValidateConfig = rpc.declare({
object: 'luci.network-modes',
method: 'validate_config',
params: ['mode', 'config'],
expect: { valid: false, errors: [] }
});
return baseclass.extend({
getStatus: callStatus,
getCurrentMode: callGetCurrentMode,
getAvailableModes: callGetAvailableModes,
setMode: callSetMode,
getInterfaces: callGetInterfaces,
validateConfig: callValidateConfig,
// Aggregate function for overview page
getAllData: function() {
return Promise.all([
callStatus(),
callGetCurrentMode(),
callGetAvailableModes(),
callGetInterfaces()
]).then(function(results) {
return {
status: results[0] || {},
current_mode: results[1] || { mode: '' },
available_modes: results[2] || { modes: [] },
interfaces: results[3] || { interfaces: [] }
};
});
}
});