feat(smartproxy): Update documentation and configuration guides to adopt new route-based SmartProxy architecture

This commit is contained in:
2025-05-16 15:50:46 +00:00
parent 0ad5dfd6ee
commit fb424d814c
8 changed files with 785 additions and 1516 deletions

View File

@ -239,73 +239,57 @@ export class SmtpPortConfig {
}
/**
* Apply port configurations to SmartProxy settings
* @param smartProxy SmartProxy instance
* Convert port configurations to SmartProxy routes
* @returns Array of SmartProxy routes
*/
public applyToSmartProxy(smartProxy: plugins.smartproxy.SmartProxy): void {
if (!smartProxy) return;
public toSmartProxyRoutes(): plugins.smartproxy.IRouteConfig[] {
const enabledPorts = this.getEnabledPortConfigs();
const settings = smartProxy.settings;
const routes: plugins.smartproxy.IRouteConfig[] = [];
// Initialize globalPortRanges if needed
if (!settings.globalPortRanges) {
settings.globalPortRanges = [];
}
// Add configured ports to globalPortRanges
// Add configured ports as routes
for (const portConfig of enabledPorts) {
// Add port to global port ranges if not already present
if (!settings.globalPortRanges.some((r) => r.from <= portConfig.port && portConfig.port <= r.to)) {
settings.globalPortRanges.push({ from: portConfig.port, to: portConfig.port });
}
// Apply TLS settings at SmartProxy level
// Create a route for each SMTP port
const route: plugins.smartproxy.IRouteConfig = {
name: `smtp-port-${portConfig.port}`,
match: {
ports: [portConfig.port]
},
action: {
type: 'forward',
target: {
host: 'localhost',
port: portConfig.port + 10000 // Map to internal port (e.g., 25 -> 10025)
}
}
};
// Apply TLS settings
if (portConfig.port === 465 && portConfig.tls?.enabled) {
// For implicit TLS on port 465
settings.sniEnabled = true;
route.action.tls = {
mode: 'terminate',
certificate: 'auto'
};
} else if (portConfig.tls?.useStartTls) {
// For STARTTLS on ports 25 and 587
route.action.tls = {
mode: 'passthrough'
};
}
routes.push(route);
}
// Group ports by TLS configuration to log them
const starttlsPorts = enabledPorts
.filter(p => p.tls?.enabled && p.tls?.useStartTls)
.map(p => p.port);
return routes;
}
const implicitTlsPorts = enabledPorts
.filter(p => p.tls?.enabled && !p.tls?.useStartTls)
.map(p => p.port);
const nonTlsPorts = enabledPorts
.filter(p => !p.tls?.enabled)
.map(p => p.port);
if (starttlsPorts.length > 0) {
console.log(`Configured STARTTLS SMTP ports: ${starttlsPorts.join(', ')}`);
}
if (implicitTlsPorts.length > 0) {
console.log(`Configured Implicit TLS SMTP ports: ${implicitTlsPorts.join(', ')}`);
}
if (nonTlsPorts.length > 0) {
console.log(`Configured Plain SMTP ports: ${nonTlsPorts.join(', ')}`);
}
// Setup connection listeners for different port types
smartProxy.on('connection', (connection) => {
const port = connection.localPort;
// Check which type of port this is
if (implicitTlsPorts.includes(port)) {
console.log(`Implicit TLS SMTP connection on port ${port} from ${connection.remoteIP}`);
} else if (starttlsPorts.includes(port)) {
console.log(`STARTTLS SMTP connection on port ${port} from ${connection.remoteIP}`);
} else if (nonTlsPorts.includes(port)) {
console.log(`Plain SMTP connection on port ${port} from ${connection.remoteIP}`);
}
});
console.log(`Applied SMTP port configurations to SmartProxy: ${enabledPorts.map(p => p.port).join(', ')}`);
/**
* Apply port configurations to SmartProxy settings
* @param smartProxy SmartProxy instance
* @deprecated Use toSmartProxyRoutes() instead to generate routes
*/
public applyToSmartProxy(smartProxy: plugins.smartproxy.SmartProxy): void {
console.warn('SmtpPortConfig.applyToSmartProxy() is deprecated. Use toSmartProxyRoutes() instead.');
// This method is deprecated and no longer functional
}
}