This commit is contained in:
2025-08-19 13:43:32 +00:00
parent dd4ac9fa3d
commit 8785536950
3 changed files with 1677 additions and 1598 deletions

View File

@@ -16,41 +16,41 @@
"bundle": "(tsbundle website --production --bundler=esbuild)"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.6.4",
"@git.zone/tsbuild": "^2.6.7",
"@git.zone/tsbundle": "^2.5.1",
"@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^2.3.1",
"@git.zone/tswatch": "^2.1.2",
"@types/node": "^24.0.10",
"@git.zone/tstest": "^2.3.5",
"@git.zone/tswatch": "^2.2.1",
"@types/node": "^22",
"node-forge": "^1.3.1"
},
"dependencies": {
"@api.global/typedrequest": "^3.0.19",
"@api.global/typedrequest-interfaces": "^3.0.19",
"@api.global/typedserver": "^3.0.74",
"@api.global/typedserver": "^3.0.77",
"@api.global/typedsocket": "^3.0.0",
"@apiclient.xyz/cloudflare": "^6.4.1",
"@design.estate/dees-catalog": "^1.10.10",
"@design.estate/dees-element": "^2.0.45",
"@design.estate/dees-element": "^2.1.2",
"@push.rocks/projectinfo": "^5.0.1",
"@push.rocks/qenv": "^6.1.0",
"@push.rocks/qenv": "^6.1.3",
"@push.rocks/smartacme": "^8.0.0",
"@push.rocks/smartdata": "^5.15.1",
"@push.rocks/smartdata": "^5.16.4",
"@push.rocks/smartdns": "^7.5.0",
"@push.rocks/smartfile": "^11.2.5",
"@push.rocks/smartfile": "^11.2.7",
"@push.rocks/smartguard": "^3.1.0",
"@push.rocks/smartjwt": "^2.2.1",
"@push.rocks/smartlog": "^3.1.8",
"@push.rocks/smartmail": "^2.1.0",
"@push.rocks/smartmetrics": "^2.0.10",
"@push.rocks/smartnetwork": "^4.0.2",
"@push.rocks/smartpath": "^5.0.5",
"@push.rocks/smartnetwork": "^4.1.2",
"@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/smartproxy": "^19.6.15",
"@push.rocks/smartproxy": "21.1.6",
"@push.rocks/smartrequest": "^2.1.0",
"@push.rocks/smartrule": "^2.0.1",
"@push.rocks/smartrx": "^3.0.10",
"@push.rocks/smartstate": "^2.0.21",
"@push.rocks/smartstate": "^2.0.26",
"@push.rocks/smartunique": "^3.0.9",
"@serve.zone/interfaces": "^5.0.4",
"@tsclass/tsclass": "^9.2.0",

3169
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -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
}
}
}
});
});
}
}
}