2025-06-08 07:04:35 +00:00
|
|
|
import * as plugins from '../../plugins.js';
|
|
|
|
|
import type { OpsServer } from '../classes.opsserver.js';
|
|
|
|
|
import * as interfaces from '../../../ts_interfaces/index.js';
|
|
|
|
|
|
|
|
|
|
export class ConfigHandler {
|
|
|
|
|
public typedrouter = new plugins.typedrequest.TypedRouter();
|
2026-02-03 23:26:51 +00:00
|
|
|
|
2025-06-08 07:04:35 +00:00
|
|
|
constructor(private opsServerRef: OpsServer) {
|
|
|
|
|
// Add this handler's router to the parent
|
|
|
|
|
this.opsServerRef.typedrouter.addTypedRouter(this.typedrouter);
|
|
|
|
|
this.registerHandlers();
|
|
|
|
|
}
|
2026-02-03 23:26:51 +00:00
|
|
|
|
2025-06-08 07:04:35 +00:00
|
|
|
private registerHandlers(): void {
|
2026-02-03 23:26:51 +00:00
|
|
|
// Get Configuration Handler (read-only)
|
2025-06-08 07:04:35 +00:00
|
|
|
this.typedrouter.addTypedHandler(
|
|
|
|
|
new plugins.typedrequest.TypedHandler<interfaces.requests.IReq_GetConfiguration>(
|
|
|
|
|
'getConfiguration',
|
|
|
|
|
async (dataArg, toolsArg) => {
|
|
|
|
|
const config = await this.getConfiguration(dataArg.section);
|
|
|
|
|
return {
|
|
|
|
|
config,
|
|
|
|
|
section: dataArg.section,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async getConfiguration(section?: string): Promise<{
|
|
|
|
|
email: {
|
|
|
|
|
enabled: boolean;
|
|
|
|
|
ports: number[];
|
|
|
|
|
maxMessageSize: number;
|
|
|
|
|
rateLimits: {
|
|
|
|
|
perMinute: number;
|
|
|
|
|
perHour: number;
|
|
|
|
|
perDay: number;
|
|
|
|
|
};
|
2025-06-29 18:47:44 +00:00
|
|
|
domains?: string[];
|
2025-06-08 07:04:35 +00:00
|
|
|
};
|
|
|
|
|
dns: {
|
|
|
|
|
enabled: boolean;
|
|
|
|
|
port: number;
|
|
|
|
|
nameservers: string[];
|
|
|
|
|
caching: boolean;
|
|
|
|
|
ttl: number;
|
|
|
|
|
};
|
|
|
|
|
proxy: {
|
|
|
|
|
enabled: boolean;
|
|
|
|
|
httpPort: number;
|
|
|
|
|
httpsPort: number;
|
|
|
|
|
maxConnections: number;
|
|
|
|
|
};
|
|
|
|
|
security: {
|
|
|
|
|
blockList: string[];
|
|
|
|
|
rateLimit: boolean;
|
|
|
|
|
spamDetection: boolean;
|
|
|
|
|
tlsRequired: boolean;
|
|
|
|
|
};
|
|
|
|
|
}> {
|
|
|
|
|
const dcRouter = this.opsServerRef.dcRouterRef;
|
|
|
|
|
|
2025-06-29 18:47:44 +00:00
|
|
|
// Get email domains if email server is configured
|
|
|
|
|
let emailDomains: string[] = [];
|
|
|
|
|
if (dcRouter.emailServer && dcRouter.emailServer.domainRegistry) {
|
|
|
|
|
emailDomains = dcRouter.emailServer.domainRegistry.getAllDomains();
|
|
|
|
|
} else if (dcRouter.options.emailConfig?.domains) {
|
|
|
|
|
// Fallback: get domains from email config options
|
|
|
|
|
emailDomains = dcRouter.options.emailConfig.domains.map(d =>
|
|
|
|
|
typeof d === 'string' ? d : d.domain
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 07:04:35 +00:00
|
|
|
return {
|
|
|
|
|
email: {
|
|
|
|
|
enabled: !!dcRouter.emailServer,
|
|
|
|
|
ports: dcRouter.emailServer ? [25, 465, 587, 2525] : [],
|
|
|
|
|
maxMessageSize: 10 * 1024 * 1024, // 10MB default
|
|
|
|
|
rateLimits: {
|
|
|
|
|
perMinute: 10,
|
|
|
|
|
perHour: 100,
|
|
|
|
|
perDay: 1000,
|
|
|
|
|
},
|
2025-06-29 18:47:44 +00:00
|
|
|
domains: emailDomains,
|
2025-06-08 07:04:35 +00:00
|
|
|
},
|
|
|
|
|
dns: {
|
|
|
|
|
enabled: !!dcRouter.dnsServer,
|
|
|
|
|
port: 53,
|
|
|
|
|
nameservers: dcRouter.options.dnsNsDomains || [],
|
|
|
|
|
caching: true,
|
|
|
|
|
ttl: 300,
|
|
|
|
|
},
|
|
|
|
|
proxy: {
|
|
|
|
|
enabled: !!dcRouter.smartProxy,
|
|
|
|
|
httpPort: 80,
|
|
|
|
|
httpsPort: 443,
|
|
|
|
|
maxConnections: 1000,
|
|
|
|
|
},
|
|
|
|
|
security: {
|
|
|
|
|
blockList: [],
|
|
|
|
|
rateLimit: true,
|
|
|
|
|
spamDetection: true,
|
|
|
|
|
tlsRequired: false,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|