secubox-openwrt/luci-app-client-guardian/htdocs/luci-static/resources/client-guardian/api.js
CyberMind-FR cf39eb6e1d fix: resolve validation issues across all modules
- Fixed minified RPC declaration in secubox/modules.js that caused false positive in validation
- Added 30 missing menu entries across 10 modules:
  * bandwidth-manager: clients, schedules
  * client-guardian: zones, portal, logs, alerts, parental
  * crowdsec-dashboard: metrics
  * netdata-dashboard: system, processes, realtime, network
  * netifyd-dashboard: talkers, risks, devices
  * network-modes: router, accesspoint, relay, sniffer
  * secubox: settings
  * system-hub: components, diagnostics, health, remote, settings
  * vhost-manager: internal, ssl, redirects
  * wireguard-dashboard: traffic, config
- All modules now pass comprehensive validation (0 errors, 0 warnings)

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

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

200 lines
4.4 KiB
JavaScript

'use strict';
'require baseclass';
'require rpc';
/**
* Client Guardian API
* Package: luci-app-client-guardian
* RPCD object: luci.client-guardian
*/
var callStatus = rpc.declare({
object: 'luci.client-guardian',
method: 'status',
expect: { }
});
var callClients = rpc.declare({
object: 'luci.client-guardian',
method: 'clients',
expect: { clients: [] }
});
var callGetClient = rpc.declare({
object: 'luci.client-guardian',
method: 'get_client',
params: ['mac'],
expect: { }
});
var callZones = rpc.declare({
object: 'luci.client-guardian',
method: 'zones',
expect: { zones: [] }
});
var callParental = rpc.declare({
object: 'luci.client-guardian',
method: 'parental',
expect: { }
});
var callPortal = rpc.declare({
object: 'luci.client-guardian',
method: 'portal',
expect: { }
});
var callAlerts = rpc.declare({
object: 'luci.client-guardian',
method: 'alerts',
expect: { }
});
var callLogs = rpc.declare({
object: 'luci.client-guardian',
method: 'logs',
params: ['limit', 'level'],
expect: { logs: [] }
});
var callApproveClient = rpc.declare({
object: 'luci.client-guardian',
method: 'approve_client',
params: ['mac', 'name', 'zone', 'notes'],
expect: { success: false }
});
var callBanClient = rpc.declare({
object: 'luci.client-guardian',
method: 'ban_client',
params: ['mac', 'reason'],
expect: { success: false }
});
var callQuarantineClient = rpc.declare({
object: 'luci.client-guardian',
method: 'quarantine_client',
params: ['mac'],
expect: { success: false }
});
var callUpdateClient = rpc.declare({
object: 'luci.client-guardian',
method: 'update_client',
params: ['section', 'name', 'zone', 'notes', 'daily_quota', 'static_ip'],
expect: { success: false }
});
var callUpdateZone = rpc.declare({
object: 'luci.client-guardian',
method: 'update_zone',
params: ['id', 'name', 'bandwidth_limit', 'content_filter'],
expect: { success: false }
});
var callUpdatePortal = rpc.declare({
object: 'luci.client-guardian',
method: 'update_portal',
params: ['title', 'subtitle', 'accent_color'],
expect: { success: false }
});
var callSendTestAlert = rpc.declare({
object: 'luci.client-guardian',
method: 'send_test_alert',
params: ['type'],
expect: { success: false }
});
// Nodogsplash Captive Portal Methods
var callListSessions = rpc.declare({
object: 'luci.client-guardian',
method: 'list_sessions',
expect: { sessions: [] }
});
var callGetPolicy = rpc.declare({
object: 'luci.client-guardian',
method: 'get_policy',
expect: { }
});
var callSetPolicy = rpc.declare({
object: 'luci.client-guardian',
method: 'set_policy',
params: ['policy', 'portal_enabled', 'auto_approve', 'session_timeout'],
expect: { success: false }
});
var callAuthorizeClient = rpc.declare({
object: 'luci.client-guardian',
method: 'authorize_client',
params: ['mac', 'ip'],
expect: { success: false }
});
var callDeauthorizeClient = rpc.declare({
object: 'luci.client-guardian',
method: 'deauthorize_client',
params: ['mac', 'ip'],
expect: { success: false }
});
function formatMac(mac) {
if (!mac) return '';
return mac.toUpperCase().replace(/(.{2})(?=.)/g, '$1:');
}
function formatDuration(seconds) {
if (!seconds) return 'Unlimited';
var h = Math.floor(seconds / 3600);
var m = Math.floor((seconds % 3600) / 60);
if (h > 24) return Math.floor(h / 24) + 'd';
if (h > 0) return h + 'h ' + m + 'm';
return m + 'm';
}
function formatBytes(bytes) {
if (!bytes || bytes === 0) return '0 B';
var units = ['B', 'KB', 'MB', 'GB', 'TB'];
var i = Math.floor(Math.log(bytes) / Math.log(1024));
i = Math.min(i, units.length - 1);
return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + units[i];
}
return baseclass.extend({
// Core methods
getStatus: callStatus,
getClients: callClients,
getClient: callGetClient,
getZones: callZones,
getParental: callParental,
getPortal: callPortal,
getAlerts: callAlerts,
getLogs: callLogs,
// Client management
approveClient: callApproveClient,
banClient: callBanClient,
quarantineClient: callQuarantineClient,
updateClient: callUpdateClient,
// Configuration
updateZone: callUpdateZone,
updatePortal: callUpdatePortal,
sendTestAlert: callSendTestAlert,
// Nodogsplash Captive Portal
listSessions: callListSessions,
getPolicy: callGetPolicy,
setPolicy: callSetPolicy,
authorizeClient: callAuthorizeClient,
deauthorizeClient: callDeauthorizeClient,
// Utility functions
formatMac: formatMac,
formatDuration: formatDuration,
formatBytes: formatBytes
});