update
This commit is contained in:
@@ -159,7 +159,7 @@ export class DcRouter {
|
||||
|
||||
|
||||
this.opsServer = new OpsServer(this);
|
||||
await this.opsServer.start();
|
||||
// await this.opsServer.start();
|
||||
|
||||
try {
|
||||
// Initialize MetricsManager
|
||||
@@ -387,11 +387,29 @@ export class DcRouter {
|
||||
private generateEmailRoutes(emailConfig: IUnifiedEmailServerOptions): plugins.smartproxy.IRouteConfig[] {
|
||||
const emailRoutes: plugins.smartproxy.IRouteConfig[] = [];
|
||||
|
||||
// Type definitions for SmartProxy
|
||||
type TRouteActionType = 'forward' | 'socket-handler';
|
||||
type TTlsMode = 'passthrough' | 'terminate' | 'terminate-and-reencrypt';
|
||||
|
||||
// Helper function to extract domains from email patterns
|
||||
const extractDomainsFromRecipients = (recipients: string | string[]): string[] => {
|
||||
const recipientArray = Array.isArray(recipients) ? recipients : [recipients];
|
||||
return recipientArray
|
||||
.map(r => {
|
||||
// Handle wildcards: "*@domain.com" -> "domain.com"
|
||||
// Handle normal: "user@domain.com" -> "domain.com"
|
||||
const parts = r.split('@');
|
||||
return parts.length === 2 && parts[1] !== '*' ? parts[1] : null;
|
||||
})
|
||||
.filter((d): d is string => d !== null)
|
||||
.filter((d, i, arr) => arr.indexOf(d) === i); // Remove duplicates
|
||||
};
|
||||
|
||||
// Create routes for each email port
|
||||
for (const port of emailConfig.ports) {
|
||||
// Create a descriptive name for the route based on the port
|
||||
let routeName = 'email-route';
|
||||
let tlsMode = 'passthrough';
|
||||
let tlsMode: TTlsMode = 'passthrough';
|
||||
|
||||
// Handle different email ports differently
|
||||
switch (port) {
|
||||
@@ -407,7 +425,7 @@ export class DcRouter {
|
||||
|
||||
case 465: // SMTPS
|
||||
routeName = 'smtps-route';
|
||||
tlsMode = 'terminate'; // Terminate TLS and re-encrypt to email server
|
||||
tlsMode = 'terminate-and-reencrypt'; // Terminate TLS and re-encrypt to email server
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -438,7 +456,7 @@ export class DcRouter {
|
||||
if (emailConfig.useSocketHandler) {
|
||||
// Socket-handler mode
|
||||
action = {
|
||||
type: 'socket-handler' as any,
|
||||
type: 'socket-handler' as TRouteActionType,
|
||||
socketHandler: this.createMailSocketHandler(port)
|
||||
};
|
||||
} else {
|
||||
@@ -453,15 +471,19 @@ export class DcRouter {
|
||||
const internalPort = portMapping[port] || port + 10000;
|
||||
|
||||
action = {
|
||||
type: 'forward',
|
||||
target: {
|
||||
type: 'forward' as TRouteActionType,
|
||||
targets: [{
|
||||
host: 'localhost', // Forward to internal email server
|
||||
port: internalPort
|
||||
},
|
||||
tls: {
|
||||
mode: tlsMode as any
|
||||
}
|
||||
}]
|
||||
};
|
||||
|
||||
// Add TLS configuration at action level if needed
|
||||
if (tlsMode !== 'passthrough' || port === 465) {
|
||||
action.tls = {
|
||||
mode: tlsMode
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// For TLS terminate mode, add certificate info
|
||||
@@ -485,23 +507,29 @@ export class DcRouter {
|
||||
// Add email domain-based routes if configured
|
||||
if (emailConfig.routes) {
|
||||
for (const route of emailConfig.routes) {
|
||||
emailRoutes.push({
|
||||
name: route.name,
|
||||
match: {
|
||||
ports: emailConfig.ports,
|
||||
domains: route.match.recipients ? [route.match.recipients.toString().split('@')[1]] : []
|
||||
},
|
||||
action: {
|
||||
type: 'forward',
|
||||
target: route.action.type === 'forward' && route.action.forward ? {
|
||||
host: route.action.forward.host,
|
||||
port: route.action.forward.port || 25
|
||||
} : undefined,
|
||||
tls: {
|
||||
mode: 'passthrough'
|
||||
const domains = route.match.recipients ?
|
||||
extractDomainsFromRecipients(route.match.recipients) : [];
|
||||
|
||||
// Only create SmartProxy route if we have domains to match
|
||||
if (domains.length > 0) {
|
||||
emailRoutes.push({
|
||||
name: route.name,
|
||||
match: {
|
||||
ports: emailConfig.ports,
|
||||
domains: domains
|
||||
},
|
||||
action: {
|
||||
type: 'forward' as TRouteActionType,
|
||||
targets: route.action.type === 'forward' && route.action.forward ? [{
|
||||
host: route.action.forward.host,
|
||||
port: route.action.forward.port || 25
|
||||
}] : [],
|
||||
tls: {
|
||||
mode: 'passthrough' as TTlsMode
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user