import * as interfaces from '../ts_interfaces/index.js'; import type { DcRouterApiClient } from './classes.dcrouterapiclient.js'; // ===================== // Sub-managers // ===================== export class RadiusClientManager { private clientRef: DcRouterApiClient; constructor(clientRef: DcRouterApiClient) { this.clientRef = clientRef; } public async list(): Promise> { const response = await this.clientRef.request( 'getRadiusClients', this.clientRef.buildRequestPayload() as any, ); return response.clients; } public async set(client: { name: string; ipRange: string; secret: string; description?: string; enabled: boolean; }): Promise { const response = await this.clientRef.request( 'setRadiusClient', this.clientRef.buildRequestPayload({ client }) as any, ); if (!response.success) { throw new Error(response.message || 'Failed to set RADIUS client'); } } public async remove(name: string): Promise { const response = await this.clientRef.request( 'removeRadiusClient', this.clientRef.buildRequestPayload({ name }) as any, ); if (!response.success) { throw new Error(response.message || 'Failed to remove RADIUS client'); } } } export class RadiusVlanManager { private clientRef: DcRouterApiClient; constructor(clientRef: DcRouterApiClient) { this.clientRef = clientRef; } public async list(): Promise { return this.clientRef.request( 'getVlanMappings', this.clientRef.buildRequestPayload() as any, ); } public async set(mapping: { mac: string; vlan: number; description?: string; enabled: boolean; }): Promise { const response = await this.clientRef.request( 'setVlanMapping', this.clientRef.buildRequestPayload({ mapping }) as any, ); if (!response.success) { throw new Error(response.message || 'Failed to set VLAN mapping'); } } public async remove(mac: string): Promise { const response = await this.clientRef.request( 'removeVlanMapping', this.clientRef.buildRequestPayload({ mac }) as any, ); if (!response.success) { throw new Error(response.message || 'Failed to remove VLAN mapping'); } } public async updateConfig(options: { defaultVlan?: number; allowUnknownMacs?: boolean; }): Promise<{ defaultVlan: number; allowUnknownMacs: boolean }> { const response = await this.clientRef.request( 'updateVlanConfig', this.clientRef.buildRequestPayload(options) as any, ); if (!response.success) { throw new Error('Failed to update VLAN config'); } return response.config; } public async testAssignment(mac: string): Promise { return this.clientRef.request( 'testVlanAssignment', this.clientRef.buildRequestPayload({ mac }) as any, ); } } export class RadiusSessionManager { private clientRef: DcRouterApiClient; constructor(clientRef: DcRouterApiClient) { this.clientRef = clientRef; } public async list(filter?: { username?: string; nasIpAddress?: string; vlanId?: number; }): Promise { return this.clientRef.request( 'getRadiusSessions', this.clientRef.buildRequestPayload({ filter }) as any, ); } public async disconnect(sessionId: string, reason?: string): Promise { const response = await this.clientRef.request( 'disconnectRadiusSession', this.clientRef.buildRequestPayload({ sessionId, reason }) as any, ); if (!response.success) { throw new Error(response.message || 'Failed to disconnect session'); } } } // ===================== // Main RADIUS Manager // ===================== export class RadiusManager { private clientRef: DcRouterApiClient; public clients: RadiusClientManager; public vlans: RadiusVlanManager; public sessions: RadiusSessionManager; constructor(clientRef: DcRouterApiClient) { this.clientRef = clientRef; this.clients = new RadiusClientManager(clientRef); this.vlans = new RadiusVlanManager(clientRef); this.sessions = new RadiusSessionManager(clientRef); } public async getAccountingSummary( startTime: number, endTime: number, ): Promise { const response = await this.clientRef.request( 'getRadiusAccountingSummary', this.clientRef.buildRequestPayload({ startTime, endTime }) as any, ); return response.summary; } public async getStatistics(): Promise { return this.clientRef.request( 'getRadiusStatistics', this.clientRef.buildRequestPayload() as any, ); } }