2026-02-02 22:21:55 +00:00
# @serve.zone/dcrouter
2024-05-11 12:33:14 +02:00
2025-06-20 00:44:04 +00:00

2026-02-02 22:21:55 +00:00
**dcrouter: A powerful traffic router designed to be the gateway for your datacenter.** 🚀
2025-05-22 13:10:45 +00:00
2026-02-02 22:21:55 +00:00
A comprehensive traffic routing solution that provides unified gateway capabilities for HTTP/HTTPS, TCP/SNI, email (SMTP), DNS protocols, and RADIUS authentication. Designed for enterprises requiring robust traffic management, automatic certificate provisioning, and enterprise-grade email infrastructure.
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/ ](https://community.foss.global/ ). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/ ](https://code.foss.global/ ) account to submit Pull Requests directly.
2025-05-22 13:10:45 +00:00
## Table of Contents
- [Features ](#features )
- [Installation ](#installation )
- [Quick Start ](#quick-start )
- [Architecture ](#architecture )
- [Configuration ](#configuration )
2026-02-02 22:21:55 +00:00
- [Socket-Handler Mode ](#socket-handler-mode )
2025-05-22 13:10:45 +00:00
- [Email System ](#email-system )
- [SmartProxy Routing ](#smartproxy-routing )
2026-02-02 22:21:55 +00:00
- [RADIUS Server ](#radius-server )
- [Storage System ](#storage-system )
2025-05-22 13:10:45 +00:00
- [Security Features ](#security-features )
2026-02-02 22:21:55 +00:00
- [OpsServer Dashboard ](#opsserver-dashboard )
2025-05-22 13:10:45 +00:00
- [API Reference ](#api-reference )
- [Examples ](#examples )
2026-02-02 22:21:55 +00:00
- [Testing ](#testing )
2025-05-22 13:10:45 +00:00
- [Troubleshooting ](#troubleshooting )
## Features
### 🌐 **Universal Traffic Router**
- **HTTP/HTTPS routing** with pattern matching and virtual hosts
- **TCP/SNI proxy** for any protocol with TLS termination/passthrough
- **DNS server** with authoritative and dynamic record management
- **Multi-protocol support** on the same infrastructure
### 🔒 **Enterprise Security**
- **Automatic TLS certificates** via ACME with DNS-01 challenges
- **IP reputation checking** and real-time threat detection
- **Content scanning** for spam, viruses, and malicious content
- **Comprehensive security logging** with correlation tracking
### 📧 **Complete Email Infrastructure**
- **Multi-domain SMTP server** on standard ports (25, 587, 465)
2026-02-02 22:21:55 +00:00
- **Pattern-based email routing** with four processing modes (forward, process, deliver, reject)
2025-05-22 13:10:45 +00:00
- **DKIM, SPF, DMARC** authentication and verification
- **Enterprise deliverability** with IP warmup and reputation management
2026-02-02 22:21:55 +00:00
- **Bounce handling** with suppression lists
2025-05-22 13:10:45 +00:00
2026-02-02 00:36:19 +00:00
### 📡 **RADIUS Server**
- **MAC Authentication Bypass (MAB)** for network device authentication
- **VLAN assignment** based on MAC address or OUI patterns
- **RADIUS accounting** for session tracking and billing
2026-02-02 22:21:55 +00:00
- **OpsServer API integration** for real-time management
2026-02-02 00:36:19 +00:00
2025-05-22 13:10:45 +00:00
### ⚡ **High Performance**
- **Connection pooling** and efficient resource management
- **Load balancing** with automatic failover
- **Rate limiting** at multiple levels
- **Real-time metrics** and monitoring
2025-05-30 07:06:00 +00:00
### 💾 **Flexible Storage System**
- **Multiple storage backends**: filesystem, custom functions, or memory
- **Unified storage interface** for all components
- **Automatic data migration** between backends
- **Persistent configuration** for domains, routes, and security data
2026-02-02 22:21:55 +00:00
### 🖥️ **OpsServer Dashboard**
- **Web-based management interface** for real-time monitoring
- **JWT authentication** with secure admin access
- **Live statistics** for connections, email, DNS, and RADIUS
- **Configuration management** via TypedRequest API
2025-05-22 13:10:45 +00:00
## Installation
```bash
npm install @serve .zone/dcrouter --save
2026-02-02 22:21:55 +00:00
# or
pnpm add @serve .zone/dcrouter
2025-05-22 13:10:45 +00:00
```
### Prerequisites
- Node.js 18+ with ES modules support
- Valid domain with DNS control (for ACME certificates)
- Cloudflare API token (for DNS challenges)
## Quick Start
2024-02-15 20:30:38 +01:00
2025-05-22 13:10:45 +00:00
### Basic HTTP/HTTPS Router
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```typescript
import { DcRouter } from '@serve .zone/dcrouter';
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
const router = new DcRouter({
smartProxyConfig: {
routes: [
{
name: 'web-service',
match: { domains: ['example.com'], ports: [443] },
action: {
type: 'forward',
2026-02-02 00:36:19 +00:00
targets: [{ host: '192.168.1.10', port: 8080 }],
2025-05-22 13:10:45 +00:00
tls: { mode: 'terminate', certificate: 'auto' }
}
}
],
acme: {
email: 'admin@example .com',
enabled: true,
useProduction: true
}
}
});
await router.start();
console.log('DcRouter started successfully');
2024-05-11 12:33:14 +02:00
```
2025-05-22 13:10:45 +00:00
### Basic Email Router
```typescript
import { DcRouter } from '@serve .zone/dcrouter';
const router = new DcRouter({
emailConfig: {
ports: [25, 587, 465],
hostname: 'mail.example.com',
2025-05-28 14:12:50 +00:00
routes: [
2025-05-22 13:10:45 +00:00
{
2025-05-28 14:12:50 +00:00
name: 'local-mail',
match: { recipients: '*@example .com' },
action: {
type: 'process',
process: {
scan: true,
dkim: true,
queue: 'normal'
}
2025-05-22 13:10:45 +00:00
}
}
],
tls: {
keyPath: './certs/key.pem',
certPath: './certs/cert.pem'
}
}
});
2024-02-15 20:30:38 +01:00
2025-05-22 13:10:45 +00:00
await router.start();
```
2024-02-15 20:30:38 +01:00
2026-02-02 22:21:55 +00:00
### With OpsServer Dashboard
```typescript
import { DcRouter } from '@serve .zone/dcrouter';
const router = new DcRouter({
// Enable OpsServer for web dashboard
opsServerConfig: {
port: 3000,
admin: {
username: 'admin',
password: 'your-secure-password'
}
},
// Your routing configuration...
smartProxyConfig: { /* ... */ },
emailConfig: { /* ... */ }
});
await router.start();
// Dashboard available at http://localhost:3000
```
2025-05-22 13:10:45 +00:00
## Architecture
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
### System Overview
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```mermaid
graph TB
subgraph "External Traffic"
HTTP[HTTP/HTTPS Clients]
SMTP[SMTP Clients]
TCP[TCP Clients]
DNS[DNS Queries]
2026-02-02 22:21:55 +00:00
RADIUS[RADIUS Clients]
2025-05-22 13:10:45 +00:00
end
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
subgraph "DcRouter Core"
DcRouter[DcRouter Orchestrator]
SmartProxy[SmartProxy Engine]
EmailServer[Unified Email Server]
DnsServer[DNS Server]
2026-02-02 22:21:55 +00:00
RadiusServer[RADIUS Server]
2025-05-22 13:10:45 +00:00
CertManager[Certificate Manager]
2026-02-02 22:21:55 +00:00
OpsServer[OpsServer Dashboard]
2025-05-22 13:10:45 +00:00
end
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
subgraph "Backend Services"
WebServices[Web Services]
MailServers[Mail Servers]
Databases[Databases]
APIs[Internal APIs]
end
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
HTTP --> SmartProxy
TCP --> SmartProxy
SMTP --> EmailServer
DNS --> DnsServer
2026-02-02 22:21:55 +00:00
RADIUS --> RadiusServer
2025-05-22 13:10:45 +00:00
DcRouter --> SmartProxy
DcRouter --> EmailServer
DcRouter --> DnsServer
2026-02-02 22:21:55 +00:00
DcRouter --> RadiusServer
2025-05-22 13:10:45 +00:00
DcRouter --> CertManager
2026-02-02 22:21:55 +00:00
DcRouter --> OpsServer
2025-05-22 13:10:45 +00:00
SmartProxy --> WebServices
SmartProxy --> APIs
EmailServer --> MailServers
EmailServer --> Databases
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
CertManager -.-> SmartProxy
CertManager -.-> EmailServer
```
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
### Core Components
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
#### **DcRouter Orchestrator**
Central coordination engine that manages all services and provides unified configuration.
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
#### **SmartProxy Engine**
High-performance HTTP/HTTPS and TCP/SNI proxy with:
- Pattern-based routing
- TLS termination/passthrough
- Load balancing
- Connection pooling
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
#### **Unified Email Server**
Enterprise-grade SMTP server with:
- Multi-domain support
- Pattern-based routing
2026-02-02 22:21:55 +00:00
- Four processing modes (forward, process, deliver, reject)
- Complete authentication stack (DKIM, SPF, DMARC)
#### **DNS Server**
Authoritative DNS server with:
- Dynamic record management
- DNS-over-HTTPS (DoH) support
- ACME DNS-01 challenge handling
#### **RADIUS Server**
Network authentication server with:
- MAC Authentication Bypass (MAB)
- VLAN assignment
- Accounting support
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
#### **Certificate Manager**
Automatic TLS certificate provisioning via ACME with DNS-01 challenges.
2026-02-02 22:21:55 +00:00
#### **OpsServer Dashboard**
Web-based management interface with:
- JWT-secured API
- Real-time statistics
- Configuration management
2025-05-22 13:10:45 +00:00
## Configuration
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
### Complete Configuration Interface
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```typescript
interface IDcRouterOptions {
// SmartProxy configuration for HTTP/HTTPS/TCP routing
smartProxyConfig?: {
routes: IRouteConfig[];
acme?: IAcmeConfig;
allowSessionTicket?: boolean;
};
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// Email system configuration
emailConfig?: {
ports: number[];
hostname: string;
2025-05-30 07:06:00 +00:00
domains?: IEmailDomainConfig[]; // Domain infrastructure setup
2026-02-02 22:21:55 +00:00
routes: IEmailRoute[]; // Route-based email handling
2025-05-22 13:10:45 +00:00
auth?: IAuthConfig;
tls?: ITlsConfig;
2025-05-28 14:12:50 +00:00
maxMessageSize?: number;
rateLimits?: IRateLimitConfig;
2026-02-02 22:21:55 +00:00
useSocketHandler?: boolean; // Enable socket-handler mode (no port binding)
defaults?: { // Global defaults for all domains
2025-05-30 07:06:00 +00:00
dnsMode?: 'forward' | 'internal-dns' | 'external-dns';
dkim?: IDkimConfig;
rateLimits?: IRateLimitConfig;
};
2025-05-22 13:10:45 +00:00
};
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// DNS server configuration
dnsServerConfig?: {
port?: number;
authoritative?: boolean;
records?: IDnsRecord[];
};
2026-02-02 22:21:55 +00:00
2025-05-29 16:26:19 +00:00
// DNS domain for automatic DNS-over-HTTPS setup
dnsDomain?: string; // e.g., 'dns.example.com'
2026-02-02 22:21:55 +00:00
// DNS nameserver domains (enables authoritative DNS)
dnsNsDomains?: string[]; // e.g., ['ns1.example.com', 'ns2.example.com']
// RADIUS server configuration
radiusConfig?: {
port?: number;
secret: string;
clients?: IRadiusClient[];
macAuth?: IMacAuthConfig;
vlanAssignment?: IVlanAssignment[];
};
// OpsServer configuration
opsServerConfig?: {
port?: number;
admin: {
username: string;
password: string;
};
};
2025-05-22 13:10:45 +00:00
// TLS and certificate configuration
tls?: {
contactEmail: string;
domain: string;
};
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// DNS challenge configuration
dnsChallenge?: {
cloudflareApiKey: string;
};
2026-02-02 22:21:55 +00:00
2025-05-30 07:06:00 +00:00
// Storage configuration
storage?: {
fsPath?: string; // Filesystem storage path
readFunction?: (key: string) => Promise<string>; // Custom read function
writeFunction?: (key: string, value: string) => Promise<void>; // Custom write function
};
2025-05-22 13:10:45 +00:00
}
```
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
### Route Configuration
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```typescript
interface IRouteConfig {
name: string;
priority?: number;
match: {
domains?: string[];
ports?: number | number[] | { from: number; to: number }[];
2024-05-11 12:33:14 +02:00
};
2025-05-22 13:10:45 +00:00
action: {
type: 'forward' | 'redirect' | 'serve';
2026-02-02 00:36:19 +00:00
targets?: Array<{
2025-05-22 13:10:45 +00:00
host: string;
port: number | 'preserve' | ((context: any) => number);
2026-02-02 00:36:19 +00:00
}>;
2025-05-22 13:10:45 +00:00
tls?: {
mode: 'terminate' | 'passthrough';
certificate?: 'auto' | string;
};
security?: {
ipAllowList?: string[];
ipBlockList?: string[];
};
};
}
```
2024-05-11 12:33:14 +02:00
2025-05-29 16:26:19 +00:00
## Socket-Handler Mode
DcRouter supports an advanced socket-handler mode that eliminates internal port binding for both DNS and email services. Instead of services listening on internal ports, SmartProxy passes sockets directly to the services.
### DNS Socket-Handler
When `dnsDomain` is configured, DcRouter automatically:
- Sets up DNS server for UDP on port 53
- Creates SmartProxy routes for DNS-over-HTTPS (DoH) on the specified domain
- Uses socket-handler for HTTPS/DoH traffic (no HTTPS port binding)
```typescript
const router = new DcRouter({
dnsDomain: 'dns.example.com', // Enables DNS with DoH
smartProxyConfig: {
// DNS routes are automatically created
}
});
```
This creates:
- UDP DNS service on port 53 (standard DNS queries)
- HTTPS routes for `dns.example.com/dns-query` and `dns.example.com/resolve`
- Automatic TLS certificates via Let's Encrypt
### Email Socket-Handler
When `useSocketHandler` is enabled in email config:
- Email server doesn't bind to any ports
- SmartProxy passes sockets directly to email handlers
- Reduces latency and resource usage
```typescript
const router = new DcRouter({
emailConfig: {
ports: [25, 587, 465],
hostname: 'mail.example.com',
useSocketHandler: true, // Enable socket-handler mode
routes: [/* email routes */]
}
});
```
### Benefits of Socket-Handler Mode
1. **Performance ** : Eliminates internal port forwarding overhead
2. **Security ** : No exposed internal ports
3. **Resource Efficiency ** : Fewer open ports and listeners
4. **Simplified Networking ** : Direct socket passing
5. **Automatic Configuration ** : Routes created automatically
### Traditional vs Socket-Handler Mode
**Traditional Mode (default):**
```
External Port → SmartProxy → Internal Port → Service
25 → 10025 → Email
```
**Socket-Handler Mode:**
```
External Port → SmartProxy → Socket Handler → Service
25 → (direct socket) → Email
```
2025-05-22 13:10:45 +00:00
## Email System
2025-05-30 07:06:00 +00:00
### Email Domain Configuration
DcRouter separates email infrastructure (which domains to handle) from routing logic (how to handle emails):
#### **DNS Modes**
**Forward Mode** - Simple mail forwarding without local DNS:
```typescript
{
domain: 'forwarded.com',
dnsMode: 'forward',
dns: {
forward: {
skipDnsValidation: true,
targetDomain: 'mail.target.com'
}
}
}
```
**Internal DNS Mode** - Use built-in DNS server (requires `dnsDomain` in DcRouter config):
```typescript
{
domain: 'mail.example.com',
dnsMode: 'internal-dns',
dns: {
internal: {
mxPriority: 10,
ttl: 3600
}
},
dkim: {
selector: 'mail2024',
keySize: 2048,
rotateKeys: true,
rotationInterval: 90
}
}
```
**External DNS Mode** - Use existing DNS infrastructure:
```typescript
{
domain: 'mail.external.com',
dnsMode: 'external-dns',
dns: {
external: {
requiredRecords: ['MX', 'SPF', 'DKIM', 'DMARC']
}
},
rateLimits: {
inbound: {
messagesPerMinute: 100,
connectionsPerIp: 10
}
}
}
```
#### **DKIM Management**
DKIM is always enabled for all domains. Keys are automatically:
- Generated on first use
- Stored persistently via StorageManager
- Rotated based on configuration
- Cleaned up after grace period
2025-05-28 14:12:50 +00:00
### Email Route Actions
2025-05-22 13:10:45 +00:00
2025-05-28 14:12:50 +00:00
#### **Forward Action**
Routes emails to external SMTP servers.
2025-05-22 13:10:45 +00:00
```typescript
{
2025-05-28 14:12:50 +00:00
name: 'forward-to-internal',
match: { recipients: '*@company .com' },
action: {
type: 'forward',
forward: {
host: 'internal-mail.company.com',
port: 25,
auth: {
username: 'relay-user',
password: 'relay-pass'
},
addHeaders: {
'X-Forwarded-By': 'dcrouter'
}
2025-05-22 13:10:45 +00:00
}
}
2024-05-11 12:33:14 +02:00
}
2025-05-22 13:10:45 +00:00
```
2024-05-11 12:33:14 +02:00
2025-05-28 14:12:50 +00:00
#### **Process Action**
Full Mail Transfer Agent functionality with scanning and delivery queues.
2025-05-22 13:10:45 +00:00
```typescript
{
2025-05-28 14:12:50 +00:00
name: 'process-notifications',
match: { recipients: '*@notifications .company.com' },
action: {
type: 'process',
process: {
scan: true,
dkim: true,
queue: 'priority'
2025-05-22 13:10:45 +00:00
}
}
}
2024-05-11 12:33:14 +02:00
```
2025-05-28 14:12:50 +00:00
#### **Deliver Action**
Local delivery for mailbox storage.
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```typescript
{
2025-05-28 14:12:50 +00:00
name: 'deliver-local',
match: { recipients: '*@marketing .company.com' },
action: {
type: 'deliver'
}
}
```
#### **Reject Action**
Reject emails with custom SMTP responses.
```typescript
{
name: 'reject-spam',
2026-02-02 22:21:55 +00:00
match: {
2025-05-28 14:12:50 +00:00
senders: '*@spam -domain.com',
sizeRange: { min: 1000000 } // > 1MB
},
action: {
type: 'reject',
reject: {
code: 550,
message: 'Message rejected due to policy'
2025-05-22 13:10:45 +00:00
}
2025-05-28 14:12:50 +00:00
}
}
```
### Common Email Routing Patterns
#### **IP-Based Relay**
Allow internal networks to relay through the server:
```typescript
{
name: 'office-relay',
priority: 100,
match: { clientIp: ['192.168.0.0/16', '10.0.0.0/8'] },
action: {
type: 'forward',
forward: { host: 'internal-mail.company.com', port: 25 }
}
}
```
#### **Domain-Based Routing**
Route different domains to different servers:
```typescript
{
name: 'partner-domain',
match: { recipients: '*@partner .com' },
action: {
2026-02-02 22:21:55 +00:00
type: 'forward',
2025-05-28 14:12:50 +00:00
forward: { host: 'partner-mail.com', port: 587 }
}
}
```
#### **Authentication-Based Processing**
Different handling for authenticated vs unauthenticated senders:
```typescript
{
name: 'authenticated-users',
match: { authenticated: true },
action: {
type: 'process',
process: { scan: false, dkim: true, queue: 'priority' }
}
},
{
name: 'unauthenticated-reject',
match: { authenticated: false },
action: {
type: 'reject',
reject: { code: 550, message: 'Authentication required' }
}
}
```
2025-05-22 13:10:45 +00:00
### Email Security Features
2025-05-28 14:12:50 +00:00
#### **Route Matching Patterns**
**Glob Pattern Matching**
2025-05-22 13:10:45 +00:00
```typescript
2025-05-28 14:12:50 +00:00
// Email address patterns
match: { recipients: '*@example .com' } // All addresses at domain
match: { recipients: 'admin@*' } // Admin at any domain
match: { senders: ['*@trusted .com', '*@partner .com'] } // Multiple patterns
// CIDR IP matching
match: { clientIp: '192.168.0.0/16' } // Private subnet
match: { clientIp: ['10.0.0.0/8', '172.16.0.0/12'] } // Multiple ranges
// Header matching
2026-02-02 22:21:55 +00:00
match: {
2025-05-28 14:12:50 +00:00
headers: {
'X-Priority': 'high',
'Subject': /urgent|emergency/i
2025-05-22 13:10:45 +00:00
}
2025-05-28 14:12:50 +00:00
}
// Size and content matching
match: {
sizeRange: { min: 1000, max: 5000000 }, // 1KB to 5MB
hasAttachments: true,
subject: /invoice|receipt/i
}
2025-05-22 13:10:45 +00:00
```
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
#### **Content Scanning**
```typescript
const scanners = [
{
type: 'spam',
threshold: 5.0,
action: 'tag',
headers: ['X-Spam-Score', 'X-Spam-Status']
},
{
type: 'virus',
action: 'reject',
quarantine: true
},
{
type: 'attachment',
blockedExtensions: ['.exe', '.bat', '.scr'],
maxSize: 25 * 1024 * 1024 // 25MB
}
];
```
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
## SmartProxy Routing
### HTTP/HTTPS Routing
```typescript
const routes = [
// API routing with path-based forwarding
{
name: 'api-gateway',
match: {
domains: ['api.example.com'],
ports: [443]
},
action: {
type: 'forward',
2026-02-02 00:36:19 +00:00
targets: [{ host: '192.168.1.20', port: 8080 }],
2025-05-22 13:10:45 +00:00
tls: {
mode: 'terminate',
certificate: 'auto'
}
}
},
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// Static file serving
{
name: 'static-assets',
match: {
domains: ['cdn.example.com'],
ports: [443]
},
action: {
type: 'serve',
root: '/var/www/static',
tls: {
mode: 'terminate',
certificate: 'auto'
}
}
}
];
```
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
### TCP/SNI Routing
```typescript
const tcpRoutes = [
// Database connection routing
{
name: 'database-cluster',
match: {
ports: [{ from: 5432, to: 5439 }]
},
action: {
type: 'forward',
2026-02-02 00:36:19 +00:00
targets: [{ host: '192.168.1.30', port: 'preserve' }],
2025-05-22 13:10:45 +00:00
security: {
ipAllowList: ['192.168.1.0/24']
}
}
},
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// SNI-based routing for TLS services
{
name: 'secure-service',
match: {
domains: ['secure.example.com'],
ports: [8443]
},
action: {
type: 'forward',
2026-02-02 00:36:19 +00:00
targets: [{ host: '192.168.1.40', port: 8443 }],
2025-05-22 13:10:45 +00:00
tls: {
mode: 'passthrough'
}
}
}
];
2024-05-11 12:33:14 +02:00
```
2026-02-02 22:21:55 +00:00
## RADIUS Server
DcRouter includes a RADIUS server for network access control:
### Basic RADIUS Configuration
```typescript
const router = new DcRouter({
radiusConfig: {
port: 1812,
secret: 'your-radius-secret',
clients: [
{
name: 'switch-1',
ip: '192.168.1.1',
secret: 'client-secret'
}
]
}
});
```
### MAC Authentication Bypass (MAB)
```typescript
const router = new DcRouter({
radiusConfig: {
port: 1812,
secret: 'radius-secret',
macAuth: {
enabled: true,
allowedMacs: [
'aa:bb:cc:dd:ee:ff',
'aa:bb:cc:*' // Wildcard for OUI matching
],
defaultVlan: 100,
guestVlan: 999
}
}
});
```
### VLAN Assignment
```typescript
const router = new DcRouter({
radiusConfig: {
secret: 'radius-secret',
vlanAssignment: [
{
match: { mac: 'aa:bb:cc:*' }, // Vendor OUI match
vlan: 100
},
{
match: { mac: 'dd:ee:ff:*' },
vlan: 200
},
{
match: { default: true },
vlan: 999 // Guest VLAN
}
]
}
});
```
2025-05-30 07:06:00 +00:00
## Storage System
### StorageManager
DcRouter includes a flexible storage system that supports multiple backends:
#### **Filesystem Storage**
```typescript
const router = new DcRouter({
storage: {
fsPath: '/var/lib/dcrouter/data'
}
});
```
#### **Custom Storage Backend**
```typescript
const router = new DcRouter({
storage: {
readFunction: async (key) => {
// Read from Redis, S3, etc.
return await myDatabase.get(key);
},
writeFunction: async (key, value) => {
// Write to Redis, S3, etc.
await myDatabase.set(key, value);
}
}
});
```
#### **Memory Storage (Development)**
```typescript
const router = new DcRouter({
// No storage config = memory storage with warning
});
```
### Storage Usage
The storage system is used for:
- **DKIM Keys**: `/email/dkim/{domain}/private.key` , `/email/dkim/{domain}/public.key`
- **Email Routes**: `/email/routes/{routeId}.json`
- **Bounce Lists**: `/email/bounces/suppression.json`
- **IP Reputation**: `/security/ip-reputation/{ip}.json`
- **Domain Configs**: `/email/domains/{domain}.json`
2025-05-22 13:10:45 +00:00
## Security Features
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
### IP Reputation Checking
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```typescript
import { IpReputationChecker } from '@serve .zone/dcrouter';
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
const ipChecker = new IpReputationChecker({
providers: ['spamhaus', 'barracuda', 'surbl'],
cacheTimeout: 3600000, // 1 hour
threshold: 0.7
});
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
// Check IP reputation
const result = await ipChecker.checkIp('192.0.2.1');
if (result.isBlocked) {
console.log(`IP blocked: ${result.reason}` );
2024-05-11 12:33:14 +02:00
}
2025-05-22 13:10:45 +00:00
```
2026-02-02 22:21:55 +00:00
### Rate Limiting
2025-05-22 13:10:45 +00:00
```typescript
2026-02-02 22:21:55 +00:00
const router = new DcRouter({
emailConfig: {
rateLimits: {
inbound: {
messagesPerMinute: 100,
connectionsPerIp: 10,
recipientsPerMessage: 50
},
outbound: {
messagesPerHour: 1000,
messagesPerDay: 10000
}
}
2025-05-22 13:10:45 +00:00
}
});
2026-02-02 22:21:55 +00:00
```
## OpsServer Dashboard
The OpsServer provides a web-based management interface:
### Features
- **Real-time Statistics**: View connections, email throughput, DNS queries, RADIUS sessions
2026-02-03 23:26:51 +00:00
- **Configuration Display**: View current configuration (read-only)
2026-02-02 22:21:55 +00:00
- **Log Viewer**: Access system logs with filtering
- **Security Dashboard**: Monitor threats and blocked connections
### API Endpoints
The OpsServer exposes TypedRequest endpoints:
```typescript
// Health check
POST /typedrequest { method: 'getHealthStatus' }
// Server statistics
POST /typedrequest { method: 'getServerStatistics' }
2024-05-11 12:33:14 +02:00
2026-02-03 23:26:51 +00:00
// Configuration (read-only)
2026-02-02 22:21:55 +00:00
POST /typedrequest { method: 'getConfiguration' }
// Logs
POST /typedrequest { method: 'getLogs', data: { level: 'info', limit: 100 } }
// RADIUS
POST /typedrequest { method: 'getRadiusSessions' }
POST /typedrequest { method: 'getRadiusClients' }
2024-05-11 12:33:14 +02:00
```
2025-05-22 13:10:45 +00:00
## API Reference
2025-03-15 16:09:18 +00:00
2025-05-22 13:10:45 +00:00
### DcRouter Class
2025-03-15 16:09:18 +00:00
2025-05-22 13:10:45 +00:00
#### Constructor
```typescript
constructor(options: IDcRouterOptions)
2025-03-15 16:09:18 +00:00
```
2025-05-22 13:10:45 +00:00
#### Methods
##### `start(): Promise<void>`
2026-02-02 22:21:55 +00:00
Starts all configured services (SmartProxy, email server, DNS server, RADIUS server, OpsServer).
2025-05-22 13:10:45 +00:00
##### `stop(): Promise<void>`
Gracefully stops all services.
##### `updateRoutes(routes: IRouteConfig[]): Promise<void>`
Updates SmartProxy routes dynamically.
##### `updateDomainRules(rules: IDomainRule[]): Promise<void>`
Updates email domain routing rules.
##### `getStats(): IStatsResponse`
Returns real-time statistics for all services.
### Email Service API
#### `sendEmail(options: IEmailOptions): Promise<string>`
```typescript
const emailId = await router.emailService.sendEmail({
from: 'sender@example .com',
to: 'recipient@example .com',
subject: 'Test Email',
html: '<p>Hello World</p>',
attachments: []
});
```
#### `getEmailStatus(emailId: string): IEmailStatus`
```typescript
const status = router.emailService.getEmailStatus(emailId);
console.log(status.status); // 'pending', 'sent', 'delivered', 'bounced'
```
## Examples
### Complete Enterprise Setup
```typescript
import { DcRouter } from '@serve .zone/dcrouter';
const router = new DcRouter({
2026-02-02 22:21:55 +00:00
// OpsServer dashboard
opsServerConfig: {
port: 3000,
admin: {
username: 'admin',
password: process.env.ADMIN_PASSWORD
}
},
2025-05-22 13:10:45 +00:00
// HTTP/HTTPS routing
smartProxyConfig: {
routes: [
// Main website
{
name: 'website',
priority: 100,
match: { domains: ['example.com', 'www.example.com'], ports: [443] },
action: {
type: 'forward',
2026-02-02 00:36:19 +00:00
targets: [{ host: '192.168.1.10', port: 80 }],
2025-05-22 13:10:45 +00:00
tls: { mode: 'terminate', certificate: 'auto' }
}
2025-05-08 00:39:43 +00:00
},
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// API services
{
name: 'api',
priority: 110,
match: { domains: ['api.example.com'], ports: [443] },
action: {
type: 'forward',
2026-02-02 00:36:19 +00:00
targets: [{ host: '192.168.1.20', port: 8080 }],
2025-05-22 13:10:45 +00:00
tls: { mode: 'terminate', certificate: 'auto' }
}
}
],
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// ACME certificate automation
acme: {
email: 'ssl@example .com',
enabled: true,
useProduction: true,
autoRenew: true
2025-05-08 00:39:43 +00:00
}
2025-05-22 13:10:45 +00:00
},
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// Enterprise email system
emailConfig: {
ports: [25, 587, 465],
hostname: 'mail.example.com',
2026-02-02 22:21:55 +00:00
2025-05-30 07:06:00 +00:00
// Domain configuration
domains: [
{
domain: 'example.com',
dnsMode: 'external-dns',
dkim: {
selector: 'mail',
rotateKeys: true
}
}
],
2026-02-02 22:21:55 +00:00
2025-05-28 14:12:50 +00:00
// Email routing rules
routes: [
// Relay from office network
2025-05-22 13:10:45 +00:00
{
2025-05-28 14:12:50 +00:00
name: 'office-relay',
priority: 100,
match: { clientIp: '192.168.0.0/16' },
action: {
type: 'forward',
2026-02-02 22:21:55 +00:00
forward: { host: 'internal-mail.example.com', port: 25 }
2025-05-28 14:12:50 +00:00
}
},
2026-02-02 22:21:55 +00:00
// Process transactional emails
2025-05-28 14:12:50 +00:00
{
name: 'notifications',
priority: 50,
match: { recipients: '*@notifications .example.com' },
action: {
type: 'process',
2026-02-02 22:21:55 +00:00
process: { scan: true, dkim: true, queue: 'priority' }
2025-05-22 13:10:45 +00:00
}
},
2026-02-02 22:21:55 +00:00
2025-05-28 14:12:50 +00:00
// Default reject
2025-05-22 13:10:45 +00:00
{
2025-05-28 14:12:50 +00:00
name: 'default-reject',
match: { recipients: '*' },
action: {
type: 'reject',
2026-02-02 22:21:55 +00:00
reject: { code: 550, message: 'Relay denied' }
2025-05-28 14:12:50 +00:00
}
2025-05-08 00:39:43 +00:00
}
2025-05-28 14:12:50 +00:00
]
2025-05-22 13:10:45 +00:00
},
2026-02-02 22:21:55 +00:00
// RADIUS for network devices
radiusConfig: {
port: 1812,
secret: process.env.RADIUS_SECRET,
macAuth: {
enabled: true,
defaultVlan: 100,
guestVlan: 999
}
},
2025-05-22 13:10:45 +00:00
// DNS server for ACME challenges
dnsServerConfig: {
port: 53,
authoritative: true
},
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// Cloudflare DNS challenges
dnsChallenge: {
cloudflareApiKey: process.env.CLOUDFLARE_API_KEY
2025-05-30 07:06:00 +00:00
},
2026-02-02 22:21:55 +00:00
2025-05-30 07:06:00 +00:00
// Persistent storage
storage: {
fsPath: '/var/lib/dcrouter/data'
2025-05-22 13:10:45 +00:00
}
});
// Start the router
await router.start();
console.log('Enterprise DcRouter started');
// Monitor statistics
setInterval(() => {
const stats = router.getStats();
console.log('Active connections:', stats.activeConnections);
console.log('Emails processed:', stats.emailsProcessed);
}, 60000);
```
2025-05-08 00:39:43 +00:00
2026-02-02 22:21:55 +00:00
## Testing
2025-05-22 13:10:45 +00:00
2026-02-02 22:21:55 +00:00
### Comprehensive Test Suite
2025-05-22 13:10:45 +00:00
2026-02-02 22:21:55 +00:00
DcRouter includes a comprehensive test suite with 195 test files covering all aspects of the system:
#### SMTP Protocol Tests
- **Commands**: EHLO, HELO, MAIL FROM, RCPT TO, DATA, RSET, NOOP, QUIT, VRFY, EXPN, HELP
- **Extensions**: SIZE, PIPELINING, STARTTLS
- **Connection Management**: TLS/plain connections, timeouts, limits, rejection handling
- **Error Handling**: Syntax errors, invalid sequences, temporary/permanent failures
- **Email Processing**: Basic sending, multiple recipients, large emails, invalid addresses
- **Security**: Authentication, rate limiting
- **Performance**: Throughput testing
- **Edge Cases**: Very large emails, special characters
#### Running Tests
```bash
# Run all tests
pnpm test
# Run specific test categories
tsx test/suite/smtpserver_commands/test.cmd-01.ehlo-command.ts
# Run with verbose output
tstest test/test.integration.ts --verbose
2025-05-08 00:39:43 +00:00
```
2025-05-22 13:10:45 +00:00
## Troubleshooting
2025-03-15 16:09:18 +00:00
2025-05-22 13:10:45 +00:00
### Common Issues
2025-03-15 16:09:18 +00:00
2025-05-22 13:10:45 +00:00
#### Certificate Issues
```bash
# Check certificate status
curl -I https://your-domain.com
2025-03-15 16:09:18 +00:00
2025-05-22 13:10:45 +00:00
# Verify ACME challenge accessibility
curl http://your-domain.com/.well-known/acme-challenge/test
```
2025-03-15 16:09:18 +00:00
2025-05-22 13:10:45 +00:00
#### Email Delivery Issues
```bash
# Test SMTP connectivity
telnet your-server.com 25
# Check DKIM record
dig TXT mail._domainkey.your-domain.com
# Verify SPF record
dig TXT your-domain.com
2025-03-15 16:09:18 +00:00
```
2025-05-28 14:12:50 +00:00
#### Email Routing Issues
**Route Not Matching**
- Check route priority order (higher priority = evaluated first)
- Verify glob patterns: `*@example.com` matches domain, `admin@*` matches user
- Test CIDR notation: `192.168.0.0/16` includes all 192.168.x.x addresses
- Confirm authentication state matches your expectations
2025-05-22 13:10:45 +00:00
#### DNS Issues
```bash
# Test DNS server
dig @your -server.com your-domain.com
2025-03-15 16:09:18 +00:00
2025-05-22 13:10:45 +00:00
# Check DNS propagation
dig your-domain.com @8 .8.8.8
```
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
### Performance Tuning
```typescript
const performanceConfig = {
// Connection limits
maxConnections: 1000,
connectionTimeout: 30000,
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// Email queue settings
emailQueue: {
concurrency: 10,
maxRetries: 3,
retryDelay: 300000
},
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
// Cache settings
cache: {
ipReputation: { ttl: 3600000 }, // 1 hour
dns: { ttl: 300000 }, // 5 minutes
certificates: { ttl: 86400000 } // 24 hours
}
};
```
2026-02-02 22:21:55 +00:00
## License and Legal Information
2025-05-22 13:10:45 +00:00
2026-02-02 22:21:55 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE ](./LICENSE ) file.
2025-05-23 19:03:44 +00:00
2026-02-02 22:21:55 +00:00
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
2025-05-23 19:03:44 +00:00
2026-02-02 22:21:55 +00:00
### Trademarks
2025-05-23 19:03:44 +00:00
2026-02-02 22:21:55 +00:00
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
2025-05-23 19:03:44 +00:00
2026-02-02 22:21:55 +00:00
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
2025-05-23 19:03:44 +00:00
2026-02-02 22:21:55 +00:00
### Company Information
2025-05-23 19:03:44 +00:00
2026-02-02 22:21:55 +00:00
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
2025-05-23 19:03:44 +00:00
2026-02-02 22:21:55 +00:00
For any legal inquiries or further information, please contact us via email at hello@task .vc.
2025-05-22 13:10:45 +00:00
2026-02-02 22:21:55 +00:00
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.