feat(radius): add RADIUS server with MAC authentication (MAB), VLAN assignment, accounting and OpsServer API handlers
This commit is contained in:
@@ -14,6 +14,7 @@ import { StorageManager, type IStorageConfig } from './storage/index.js';
|
||||
|
||||
import { OpsServer } from './opsserver/index.js';
|
||||
import { MetricsManager } from './monitoring/index.js';
|
||||
import { RadiusServer, type IRadiusServerConfig } from './radius/index.js';
|
||||
|
||||
export interface IDcRouterOptions {
|
||||
/**
|
||||
@@ -109,6 +110,12 @@ export interface IDcRouterOptions {
|
||||
|
||||
/** Storage configuration */
|
||||
storage?: IStorageConfig;
|
||||
|
||||
/**
|
||||
* RADIUS server configuration for network authentication
|
||||
* Enables MAC Authentication Bypass (MAB) and VLAN assignment
|
||||
*/
|
||||
radiusConfig?: IRadiusServerConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,6 +139,7 @@ export class DcRouter {
|
||||
public smartProxy?: plugins.smartproxy.SmartProxy;
|
||||
public dnsServer?: plugins.smartdns.dnsServerMod.DnsServer;
|
||||
public emailServer?: UnifiedEmailServer;
|
||||
public radiusServer?: RadiusServer;
|
||||
public storageManager: StorageManager;
|
||||
public opsServer: OpsServer;
|
||||
public metricsManager?: MetricsManager;
|
||||
@@ -181,11 +189,16 @@ export class DcRouter {
|
||||
}
|
||||
|
||||
// Set up DNS server if configured with nameservers and scopes
|
||||
if (this.options.dnsNsDomains && this.options.dnsNsDomains.length > 0 &&
|
||||
if (this.options.dnsNsDomains && this.options.dnsNsDomains.length > 0 &&
|
||||
this.options.dnsScopes && this.options.dnsScopes.length > 0) {
|
||||
await this.setupDnsWithSocketHandler();
|
||||
}
|
||||
|
||||
|
||||
// Set up RADIUS server if configured
|
||||
if (this.options.radiusConfig) {
|
||||
await this.setupRadiusServer();
|
||||
}
|
||||
|
||||
this.logStartupSummary();
|
||||
} catch (error) {
|
||||
console.error('❌ Error starting DcRouter:', error);
|
||||
@@ -261,12 +274,23 @@ export class DcRouter {
|
||||
}
|
||||
}
|
||||
|
||||
// RADIUS service summary
|
||||
if (this.radiusServer && this.options.radiusConfig) {
|
||||
console.log('\n🔐 RADIUS Service:');
|
||||
console.log(` ├─ Auth Port: ${this.options.radiusConfig.authPort || 1812}`);
|
||||
console.log(` ├─ Acct Port: ${this.options.radiusConfig.acctPort || 1813}`);
|
||||
console.log(` ├─ Clients configured: ${this.options.radiusConfig.clients?.length || 0}`);
|
||||
const vlanStats = this.radiusServer.getVlanManager().getStats();
|
||||
console.log(` ├─ VLAN mappings: ${vlanStats.totalMappings}`);
|
||||
console.log(` └─ Accounting: ${this.options.radiusConfig.accounting?.enabled ? 'Enabled' : 'Disabled'}`);
|
||||
}
|
||||
|
||||
// Storage summary
|
||||
if (this.storageManager && this.options.storage) {
|
||||
console.log('\n💾 Storage:');
|
||||
console.log(` └─ Path: ${this.options.storage.fsPath || 'default'}`);
|
||||
}
|
||||
|
||||
|
||||
console.log('\n✅ All services are running\n');
|
||||
}
|
||||
|
||||
@@ -582,16 +606,21 @@ export class DcRouter {
|
||||
await Promise.all([
|
||||
// Stop metrics manager if running
|
||||
this.metricsManager ? this.metricsManager.stop().catch(err => console.error('Error stopping MetricsManager:', err)) : Promise.resolve(),
|
||||
|
||||
|
||||
// Stop unified email server if running
|
||||
this.emailServer ? this.emailServer.stop().catch(err => console.error('Error stopping email server:', err)) : Promise.resolve(),
|
||||
|
||||
|
||||
// Stop HTTP SmartProxy if running
|
||||
this.smartProxy ? this.smartProxy.stop().catch(err => console.error('Error stopping SmartProxy:', err)) : Promise.resolve(),
|
||||
|
||||
|
||||
// Stop DNS server if running
|
||||
this.dnsServer ?
|
||||
this.dnsServer.stop().catch(err => console.error('Error stopping DNS server:', err)) :
|
||||
this.dnsServer ?
|
||||
this.dnsServer.stop().catch(err => console.error('Error stopping DNS server:', err)) :
|
||||
Promise.resolve(),
|
||||
|
||||
// Stop RADIUS server if running
|
||||
this.radiusServer ?
|
||||
this.radiusServer.stop().catch(err => console.error('Error stopping RADIUS server:', err)) :
|
||||
Promise.resolve()
|
||||
]);
|
||||
|
||||
@@ -1338,9 +1367,47 @@ export class DcRouter {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up RADIUS server for network authentication
|
||||
*/
|
||||
private async setupRadiusServer(): Promise<void> {
|
||||
if (!this.options.radiusConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.log('info', 'Setting up RADIUS server...');
|
||||
|
||||
this.radiusServer = new RadiusServer(this.options.radiusConfig, this.storageManager);
|
||||
await this.radiusServer.start();
|
||||
|
||||
logger.log('info', `RADIUS server started on ports ${this.options.radiusConfig.authPort || 1812} (auth) and ${this.options.radiusConfig.acctPort || 1813} (acct)`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update RADIUS configuration at runtime
|
||||
*/
|
||||
public async updateRadiusConfig(config: IRadiusServerConfig): Promise<void> {
|
||||
// Stop existing RADIUS server if running
|
||||
if (this.radiusServer) {
|
||||
await this.radiusServer.stop();
|
||||
this.radiusServer = undefined;
|
||||
}
|
||||
|
||||
// Update configuration
|
||||
this.options.radiusConfig = config;
|
||||
|
||||
// Start with new configuration
|
||||
await this.setupRadiusServer();
|
||||
|
||||
logger.log('info', 'RADIUS configuration updated');
|
||||
}
|
||||
}
|
||||
|
||||
// Re-export email server types for convenience
|
||||
export type { IUnifiedEmailServerOptions };
|
||||
|
||||
// Re-export RADIUS types for convenience
|
||||
export type { IRadiusServerConfig };
|
||||
|
||||
export default DcRouter;
|
||||
|
||||
Reference in New Issue
Block a user