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-11 16:32:49 +00:00
**dcrouter: The all-in-one gateway for your datacenter.** 🚀
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
A comprehensive traffic routing solution that provides unified gateway capabilities for HTTP/HTTPS, TCP/SNI, email (SMTP), DNS, and RADIUS protocols. Designed for enterprises requiring robust traffic management, automatic TLS certificate provisioning, and enterprise-grade email infrastructure — all from a single process.
2026-02-02 22:21:55 +00:00
## 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 )
2026-02-11 16:32:49 +00:00
- [Configuration Reference ](#configuration-reference )
- [HTTP/HTTPS & TCP/SNI Routing ](#httphttps--tcpsni-routing )
2025-05-22 13:10:45 +00:00
- [Email System ](#email-system )
2026-02-11 16:32:49 +00:00
- [DNS Server ](#dns-server )
2026-02-02 22:21:55 +00:00
- [RADIUS Server ](#radius-server )
2026-02-11 16:32:49 +00:00
- [Storage & Caching ](#storage--caching )
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 )
2026-02-11 16:32:49 +00:00
- [Sub-Modules ](#sub-modules )
2026-02-02 22:21:55 +00:00
- [Testing ](#testing )
2026-02-11 16:32:49 +00:00
- [License and Legal Information ](#license-and-legal-information )
2025-05-22 13:10:45 +00:00
## Features
2026-02-11 16:32:49 +00:00
### 🌐 Universal Traffic Router
- **HTTP/HTTPS routing** with domain matching, path-based forwarding, and automatic TLS
- **TCP/SNI proxy** for any protocol with TLS termination or passthrough
- **DNS server** with authoritative zones, dynamic record management, and DNS-over-HTTPS
- **Multi-protocol support** on the same infrastructure via [SmartProxy ](https://code.foss.global/push.rocks/smartproxy )
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
### 📧 Complete Email Infrastructure
2025-05-22 13:10:45 +00:00
- **Multi-domain SMTP server** on standard ports (25, 587, 465)
2026-02-11 16:32:49 +00:00
- **Pattern-based email routing** with four action types: forward, process, deliver, reject
- **DKIM signing & verification**, SPF, DMARC authentication stack
- **Enterprise deliverability** with IP warmup schedules and sender reputation tracking
- **Bounce handling** with automatic suppression lists
- **Hierarchical rate limiting** — global, per-domain, per-sender
### 🔒 Enterprise Security
- **Automatic TLS certificates** via ACME with Cloudflare DNS-01 challenges
- **IP reputation checking** with caching and configurable thresholds
- **Content scanning** for spam, viruses, and malicious attachments
- **Security event logging** with structured audit trails
### 📡 RADIUS Server
2026-02-02 00:36:19 +00:00
- **MAC Authentication Bypass (MAB)** for network device authentication
2026-02-11 16:32:49 +00:00
- **VLAN assignment** based on exact MAC, OUI prefix, or wildcard patterns
- **RADIUS accounting** for session tracking, traffic metering, and billing
- **Real-time management** via OpsServer API
### ⚡ High Performance
- **Rust-powered proxy engine** via SmartProxy for maximum throughput
- **Connection pooling** for outbound SMTP and backend services
- **Socket-handler mode** — direct socket passing eliminates internal port hops
- **Real-time metrics** via SmartMetrics (CPU, memory, connections, throughput)
### 💾 Persistent Storage & Caching
- **Multiple storage backends**: filesystem, custom functions, or in-memory
- **Embedded cache database** via smartdata + TsmDb (MongoDB-compatible)
- **Automatic TTL-based cleanup** for cached emails, IP reputation, DKIM keys, and more
### 🖥️ OpsServer Dashboard
- **Web-based management interface** with real-time monitoring
- **JWT authentication** with session persistence
- **Live views** for connections, email queues, DNS queries, RADIUS sessions, and security events
- **Read-only configuration display** — DcRouter is configured through code
2026-02-02 22:21:55 +00:00
2025-05-22 13:10:45 +00:00
## Installation
```bash
2026-02-02 22:21:55 +00:00
pnpm add @serve .zone/dcrouter
2026-02-11 16:32:49 +00:00
# or
npm install @serve .zone/dcrouter
2025-05-22 13:10:45 +00:00
```
### Prerequisites
2026-02-11 16:32:49 +00:00
- **Node.js 18+** with ES module support
- Valid domain with DNS control (for ACME certificate automation)
- Cloudflare API token (for DNS-01 challenges) — optional
2025-05-22 13:10:45 +00:00
## 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: [
{
2026-02-11 16:32:49 +00:00
name: 'web-app',
match: { domains: ['example.com', 'www.example.com'], ports: [443] },
2025-05-22 13:10:45 +00:00
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();
2024-05-11 12:33:14 +02:00
```
2026-02-11 16:32:49 +00:00
### Basic Email Server
2025-05-22 13:10:45 +00:00
```typescript
import { DcRouter } from '@serve .zone/dcrouter';
const router = new DcRouter({
emailConfig: {
ports: [25, 587, 465],
hostname: 'mail.example.com',
2026-02-11 16:32:49 +00:00
domains: [
{
domain: 'example.com',
dnsMode: 'external-dns'
}
],
2025-05-28 14:12:50 +00:00
routes: [
2025-05-22 13:10:45 +00:00
{
2026-02-11 16:32:49 +00:00
name: 'process-all',
2025-05-28 14:12:50 +00:00
match: { recipients: '*@example .com' },
action: {
type: 'process',
2026-02-11 16:32:49 +00:00
process: { scan: true, dkim: true, queue: 'normal' }
2025-05-22 13:10:45 +00:00
}
}
2026-02-11 16:32:49 +00:00
]
2025-05-22 13:10:45 +00:00
}
});
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-11 16:32:49 +00:00
### Full Stack with Dashboard
2026-02-02 22:21:55 +00:00
```typescript
import { DcRouter } from '@serve .zone/dcrouter';
const router = new DcRouter({
2026-02-11 16:32:49 +00:00
// HTTP/HTTPS routing
smartProxyConfig: {
routes: [
{
name: 'website',
match: { domains: ['example.com'], ports: [443] },
action: {
type: 'forward',
targets: [{ host: '192.168.1.10', port: 80 }],
tls: { mode: 'terminate', certificate: 'auto' }
}
}
],
acme: { email: 'ssl@example .com', enabled: true, useProduction: true }
2026-02-02 22:21:55 +00:00
},
2026-02-11 16:32:49 +00:00
// Email system
emailConfig: {
ports: [25, 587, 465],
hostname: 'mail.example.com',
domains: [{ domain: 'example.com', dnsMode: 'external-dns' }],
routes: [
{
name: 'inbound-mail',
match: { recipients: '*@example .com' },
action: { type: 'process', process: { scan: true, dkim: true, queue: 'normal' } }
}
]
},
// Authoritative DNS
dnsNsDomains: ['ns1.example.com', 'ns2.example.com'],
dnsScopes: ['example.com'],
publicIp: '203.0.113.1',
dnsRecords: [
{ name: 'example.com', type: 'A', value: '203.0.113.1' },
{ name: 'www.example.com', type: 'CNAME', value: 'example.com' }
],
// RADIUS authentication
radiusConfig: {
authPort: 1812,
acctPort: 1813,
clients: [
{ name: 'switch-1', ipRange: '192.168.1.0/24', secret: 'radius-secret', enabled: true }
],
vlanAssignment: {
defaultVlan: 100,
allowUnknownMacs: true,
mappings: [
{ mac: 'aa:bb:cc:dd:ee:ff', vlan: 10, enabled: true },
{ mac: 'aa:bb:cc', vlan: 20, enabled: true } // OUI prefix
]
},
accounting: { enabled: true, retentionDays: 30 }
},
// Persistent storage
storage: { fsPath: '/var/lib/dcrouter/data' },
// Cache database
cacheConfig: { enabled: true, storagePath: '/etc/dcrouter/tsmdb' },
// TLS & ACME
tls: { contactEmail: 'admin@example .com' },
dnsChallenge: { cloudflareApiKey: process.env.CLOUDFLARE_API_KEY }
2026-02-02 22:21:55 +00:00
});
await router.start();
2026-02-11 16:32:49 +00:00
// OpsServer dashboard available at http://localhost:3000
2026-02-02 22:21:55 +00:00
```
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-11 16:32:49 +00:00
RAD[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"
2026-02-11 16:32:49 +00:00
DC[DcRouter Orchestrator]
SP[SmartProxy Engine]
ES[Unified Email Server]
DS[DNS Server]
RS[RADIUS Server]
CM[Certificate Manager]
OS[OpsServer Dashboard]
MM[Metrics Manager]
SM[Storage Manager]
CD[Cache Database]
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"
2026-02-11 16:32:49 +00:00
WEB[Web Services]
MAIL[Mail Servers]
DB[Databases]
API[Internal APIs]
2025-05-22 13:10:45 +00:00
end
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
HTTP --> SP
TCP --> SP
SMTP --> ES
DNS --> DS
RAD --> RS
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
DC --> SP
DC --> ES
DC --> DS
DC --> RS
DC --> CM
DC --> OS
DC --> MM
DC --> SM
DC --> CD
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
SP --> WEB
SP --> API
ES --> MAIL
ES --> DB
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
CM -.-> SP
CM -.-> ES
```
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
### Core Components
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
| Component | Description |
|-----------|-------------|
| **DcRouter ** | Central orchestrator — starts, stops, and coordinates all services |
| **SmartProxy ** | High-performance HTTP/HTTPS and TCP/SNI proxy with route-based config |
| **UnifiedEmailServer ** | Full SMTP server with pattern-based routing, DKIM, queue management |
| **DNS Server ** | Authoritative DNS with dynamic records, DKIM TXT auto-generation |
| **RADIUS Server ** | Network authentication with MAB, VLAN assignment, and accounting |
| **OpsServer ** | Web dashboard + TypedRequest API for monitoring and management |
| **MetricsManager ** | Real-time metrics collection (CPU, memory, email, DNS, security) |
| **StorageManager ** | Pluggable key-value storage (filesystem, custom, or in-memory) |
| **CacheDb ** | Embedded MongoDB-compatible database for persistent caching |
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
## Configuration Reference
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
### `IDcRouterOptions`
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```typescript
interface IDcRouterOptions {
2026-02-11 16:32:49 +00:00
// ── Traffic Routing ────────────────────────────────────────────
/** SmartProxy config for HTTP/HTTPS and TCP/SNI routing */
smartProxyConfig?: ISmartProxyOptions;
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
// ── Email ──────────────────────────────────────────────────────
/** Unified email server configuration */
2025-05-22 13:10:45 +00:00
emailConfig?: {
2026-02-11 16:32:49 +00:00
ports: number[]; // e.g. [25, 587, 465]
hostname: string; // e.g. 'mail.example.com'
domains: IEmailDomainConfig[]; // Domain infrastructure
routes: IEmailRoute[]; // Routing rules
useSocketHandler?: boolean; // Direct socket passing (no port binding)
auth?: { required?: boolean; methods?: ('PLAIN'|'LOGIN'|'OAUTH2')[]; users?: Array<{username: string; password: string}> };
tls?: { certPath?: string; keyPath?: string; caPath?: string };
2025-05-28 14:12:50 +00:00
maxMessageSize?: number;
2026-02-11 16:32:49 +00:00
defaults?: {
2025-05-30 07:06:00 +00:00
dnsMode?: 'forward' | 'internal-dns' | 'external-dns';
2026-02-11 16:32:49 +00:00
dkim?: IEmailDomainConfig['dkim'];
rateLimits?: IEmailDomainConfig['rateLimits'];
2025-05-30 07:06:00 +00:00
};
2025-05-22 13:10:45 +00:00
};
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
/** Custom email port mapping overrides */
emailPortConfig?: {
portMapping?: Record<number, number>;
portSettings?: Record<number, any>;
receivedEmailsPath?: string;
2025-05-22 13:10:45 +00:00
};
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
// ── DNS ────────────────────────────────────────────────────────
/** Nameserver domains — get A records automatically */
dnsNsDomains?: string[]; // e.g. ['ns1.example.com', 'ns2.example.com']
/** Domains this server is authoritative for */
dnsScopes?: string[]; // e.g. ['example.com']
/** Public IP for NS A records */
publicIp?: string;
/** Ingress proxy IPs (hides real server IP) */
proxyIps?: string[];
/** Custom DNS records */
dnsRecords?: Array<{
name: string;
type: 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT' | 'NS' | 'SOA';
value: string;
ttl?: number;
useIngressProxy?: boolean;
}>;
// ── RADIUS ─────────────────────────────────────────────────────
/** RADIUS server for network authentication */
2026-02-02 22:21:55 +00:00
radiusConfig?: {
2026-02-11 16:32:49 +00:00
authPort?: number; // default: 1812
acctPort?: number; // default: 1813
clients: IRadiusClient[];
vlanAssignment?: IVlanManagerConfig;
accounting?: { enabled: boolean; retentionDays?: number };
2026-02-02 22:21:55 +00:00
};
2026-02-11 16:32:49 +00:00
// ── TLS & Certificates ────────────────────────────────────────
2025-05-22 13:10:45 +00:00
tls?: {
contactEmail: string;
2026-02-11 16:32:49 +00:00
domain?: string;
certPath?: string;
keyPath?: string;
2025-05-22 13:10:45 +00:00
};
2026-02-11 16:32:49 +00:00
dnsChallenge?: { cloudflareApiKey?: string };
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
// ── Storage & Caching ─────────────────────────────────────────
2025-05-30 07:06:00 +00:00
storage?: {
2026-02-11 16:32:49 +00:00
fsPath?: string;
readFunction?: (key: string) => Promise<string>;
writeFunction?: (key: string, value: string) => Promise<void>;
2024-05-11 12:33:14 +02:00
};
2026-02-11 16:32:49 +00:00
cacheConfig?: {
enabled?: boolean; // default: true
storagePath?: string; // default: '/etc/dcrouter/tsmdb'
dbName?: string; // default: 'dcrouter'
cleanupIntervalHours?: number; // default: 1
ttlConfig?: {
emails?: number; // default: 30 days
ipReputation?: number; // default: 1 day
bounces?: number; // default: 30 days
dkimKeys?: number; // default: 90 days
suppression?: number; // default: 30 days
2025-05-22 13:10:45 +00:00
};
};
}
```
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
## HTTP/HTTPS & TCP/SNI Routing
2025-05-29 16:26:19 +00:00
2026-02-11 16:32:49 +00:00
DcRouter uses [SmartProxy ](https://code.foss.global/push.rocks/smartproxy ) for all HTTP/HTTPS and TCP/SNI routing. Routes are pattern-matched by domain, port, or both.
2025-05-29 16:26:19 +00:00
2026-02-11 16:32:49 +00:00
### HTTPS with Auto-TLS
2025-05-29 16:26:19 +00:00
```typescript
2026-02-11 16:32:49 +00:00
{
name: 'api-gateway',
match: { domains: ['api.example.com'], ports: [443] },
action: {
type: 'forward',
targets: [{ host: '192.168.1.20', port: 8080 }],
tls: { mode: 'terminate', certificate: 'auto' }
2025-05-29 16:26:19 +00:00
}
2026-02-11 16:32:49 +00:00
}
2025-05-29 16:26:19 +00:00
```
2026-02-11 16:32:49 +00:00
### TLS Passthrough (SNI Routing)
2025-05-29 16:26:19 +00:00
```typescript
2026-02-11 16:32:49 +00:00
{
name: 'secure-backend',
match: { domains: ['secure.example.com'], ports: [8443] },
action: {
type: 'forward',
targets: [{ host: '192.168.1.40', port: 8443 }],
tls: { mode: 'passthrough' }
2025-05-29 16:26:19 +00:00
}
2026-02-11 16:32:49 +00:00
}
2025-05-29 16:26:19 +00:00
```
2026-02-11 16:32:49 +00:00
### TCP Port Range Forwarding
2025-05-29 16:26:19 +00:00
2026-02-11 16:32:49 +00:00
```typescript
{
name: 'database-cluster',
match: { ports: [{ from: 5432, to: 5439 }] },
action: {
type: 'forward',
targets: [{ host: '192.168.1.30', port: 'preserve' }],
security: { ipAllowList: ['192.168.1.0/24'] }
}
}
2025-05-29 16:26:19 +00:00
```
2026-02-11 16:32:49 +00:00
### HTTP Redirect
```typescript
{
name: 'http-to-https',
match: { ports: [80] },
action: { type: 'redirect', redirect: { to: 'https://{domain}{path}' } }
}
2025-05-29 16:26:19 +00:00
```
2025-05-22 13:10:45 +00:00
## Email System
2026-02-11 16:32:49 +00:00
The email system is built around the **UnifiedEmailServer ** , which handles SMTP sessions, route matching, delivery queuing, DKIM signing, and all email processing in a single unified component.
2025-05-30 07:06:00 +00:00
2026-02-11 16:32:49 +00:00
### Email Domain Configuration
2025-05-30 07:06:00 +00:00
2026-02-11 16:32:49 +00:00
Domains define _ infrastructure _ — how DNS and DKIM are handled for each domain:
2025-05-30 07:06:00 +00:00
2026-02-11 16:32:49 +00:00
#### Forward Mode
Simple forwarding without local DNS management:
2025-05-30 07:06:00 +00:00
```typescript
{
domain: 'forwarded.com',
dnsMode: 'forward',
2026-02-11 16:32:49 +00:00
dns: { forward: { skipDnsValidation: true, targetDomain: 'mail.target.com' } }
2025-05-30 07:06:00 +00:00
}
```
2026-02-11 16:32:49 +00:00
#### Internal DNS Mode
Uses DcRouter's built-in DNS server (requires `dnsNsDomains` + `dnsScopes` ):
2025-05-30 07:06:00 +00:00
```typescript
{
domain: 'mail.example.com',
dnsMode: 'internal-dns',
2026-02-11 16:32:49 +00:00
dns: { internal: { mxPriority: 10, ttl: 3600 } },
dkim: { selector: 'mail2024', keySize: 2048, rotateKeys: true, rotationInterval: 90 }
2025-05-30 07:06:00 +00:00
}
```
2026-02-11 16:32:49 +00:00
#### External DNS Mode
Uses existing DNS infrastructure with validation:
2025-05-30 07:06:00 +00:00
```typescript
{
domain: 'mail.external.com',
dnsMode: 'external-dns',
2026-02-11 16:32:49 +00:00
dns: { external: { requiredRecords: ['MX', 'SPF', 'DKIM', 'DMARC'] } },
2025-05-30 07:06:00 +00:00
rateLimits: {
2026-02-11 16:32:49 +00:00
inbound: { messagesPerMinute: 100, connectionsPerIp: 10 },
outbound: { messagesPerMinute: 200 }
2025-05-30 07:06:00 +00:00
}
}
```
2025-05-28 14:12:50 +00:00
### Email Route Actions
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
Routes define _ behavior _ — what happens when an email matches:
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
#### Forward 📤
Routes emails to an external SMTP server:
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,
2026-02-11 16:32:49 +00:00
auth: { user: 'relay-user', pass: '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
2026-02-11 16:32:49 +00:00
#### Process ⚙️
Full MTA processing with content 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',
2026-02-11 16:32:49 +00:00
process: { scan: true, dkim: true, queue: 'priority' }
2025-05-22 13:10:45 +00:00
}
}
2024-05-11 12:33:14 +02:00
```
2026-02-11 16:32:49 +00:00
#### Deliver 📥
Local mailbox delivery:
2025-05-22 13:10:45 +00:00
```typescript
{
2025-05-28 14:12:50 +00:00
name: 'deliver-local',
2026-02-11 16:32:49 +00:00
match: { recipients: '*@local .company.com' },
action: { type: 'deliver' }
2025-05-28 14:12:50 +00:00
}
```
2026-02-11 16:32:49 +00:00
#### Reject 🚫
Reject with custom SMTP response code:
2025-05-28 14:12:50 +00:00
```typescript
{
2026-02-11 16:32:49 +00:00
name: 'reject-spam-domain',
match: { senders: '*@spam -domain.com', sizeRange: { min: 1000000 } },
2025-05-28 14:12:50 +00:00
action: {
type: 'reject',
2026-02-11 16:32:49 +00:00
reject: { code: 550, message: 'Message rejected due to policy' }
2025-05-28 14:12:50 +00:00
}
}
```
2026-02-11 16:32:49 +00:00
### Route Matching
2025-05-28 14:12:50 +00:00
2026-02-11 16:32:49 +00:00
Routes support powerful matching criteria:
2025-05-28 14:12:50 +00:00
```typescript
2026-02-11 16:32:49 +00:00
// Recipient patterns
match: { recipients: '*@example .com' } // All addresses at domain
match: { recipients: 'admin@*' } // "admin" at any domain
match: { senders: ['*@trusted .com', '*@vip .com'] } // Multiple sender patterns
// IP-based matching (CIDR)
match: { clientIp: '192.168.0.0/16' }
match: { clientIp: ['10.0.0.0/8', '172.16.0.0/12'] }
// Authentication state
match: { authenticated: true }
// Header matching
match: { headers: { 'X-Priority': 'high', 'Subject': /urgent|emergency/i } }
// Size and content
match: { sizeRange: { min: 1000, max: 5000000 }, hasAttachments: true }
match: { subject: /invoice|receipt/i }
2025-05-28 14:12:50 +00:00
```
2026-02-11 16:32:49 +00:00
### Socket-Handler Mode 🔌
When `useSocketHandler: true` is set, SmartProxy passes sockets directly to the email server — no internal port binding, lower latency, and fewer open ports:
```
Traditional: External Port → SmartProxy → Internal Port → Email Server
Socket Mode: External Port → SmartProxy → (direct socket) → Email Server
2025-05-28 14:12:50 +00:00
```
2026-02-11 16:32:49 +00:00
### Email Security Stack
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
- **DKIM** — Automatic key generation, signing, and rotation for all domains
- **SPF** — Sender Policy Framework verification on inbound mail
- **DMARC** — Domain-based Message Authentication verification
- **IP Reputation** — Real-time IP reputation checking with caching
- **Content Scanning** — Spam, virus, and attachment scanning
- **Rate Limiting** — Hierarchical limits (global → domain → sender)
- **Bounce Management** — Automatic bounce detection and suppression lists
2025-05-28 14:12:50 +00:00
2026-02-11 16:32:49 +00:00
### Email Deliverability
2025-05-28 14:12:50 +00:00
2026-02-11 16:32:49 +00:00
- **IP Warmup Manager** — Multi-stage warmup schedules for new IPs
- **Sender Reputation Monitor** — Per-domain reputation tracking and scoring
- **Connection Pooling** — Pooled outbound SMTP connections per destination
2025-05-28 14:12:50 +00:00
2026-02-11 16:32:49 +00:00
## DNS Server
2025-05-28 14:12:50 +00:00
2026-02-11 16:32:49 +00:00
DcRouter includes an authoritative DNS server built on [smartdns ](https://code.foss.global/push.rocks/smartdns ). It handles standard UDP DNS on port 53 and DNS-over-HTTPS via SmartProxy socket handler.
### Enabling DNS
DNS is activated when both `dnsNsDomains` and `dnsScopes` are configured:
2024-05-11 12:33:14 +02:00
2025-05-22 13:10:45 +00:00
```typescript
2026-02-11 16:32:49 +00:00
const router = new DcRouter({
dnsNsDomains: ['ns1.example.com', 'ns2.example.com'],
dnsScopes: ['example.com'],
publicIp: '203.0.113.1',
dnsRecords: [
{ name: 'example.com', type: 'A', value: '203.0.113.1' },
{ name: 'www.example.com', type: 'CNAME', value: 'example.com' },
{ name: 'example.com', type: 'MX', value: '10:mail.example.com' },
{ name: 'example.com', type: 'TXT', value: 'v=spf1 a mx ~all' }
]
});
2025-05-22 13:10:45 +00:00
```
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
### Automatic DNS Records
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
DcRouter auto-generates:
- **NS records** for all domains in `dnsScopes`
- **SOA records** for authoritative zones
- **A records** for nameserver domains (`dnsNsDomains` )
- **MX, SPF, DKIM, DMARC records** for email domains with `internal-dns` mode
- **ACME challenge records** for certificate provisioning
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
### Ingress Proxy Support
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
When `proxyIps` is configured, A records with `useIngressProxy: true` (default) will use the proxy IP instead of the real server IP — hiding your origin:
2025-05-22 13:10:45 +00:00
```typescript
2026-02-11 16:32:49 +00:00
{
proxyIps: ['198.51.100.1', '198.51.100.2'],
dnsRecords: [
{ name: 'example.com', type: 'A', value: '203.0.113.1' }, // Will resolve to 198.51.100.1
{ name: 'ns1.example.com', type: 'A', value: '203.0.113.1', useIngressProxy: false } // Stays real IP
]
}
2024-05-11 12:33:14 +02:00
```
2026-02-02 22:21:55 +00:00
## RADIUS Server
2026-02-11 16:32:49 +00:00
DcRouter includes a RADIUS server for network access control, built on [smartradius ](https://code.foss.global/push.rocks/smartradius ).
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
### Configuration
2026-02-02 22:21:55 +00:00
```typescript
const router = new DcRouter({
radiusConfig: {
2026-02-11 16:32:49 +00:00
authPort: 1812,
acctPort: 1813,
2026-02-02 22:21:55 +00:00
clients: [
{
2026-02-11 16:32:49 +00:00
name: 'core-switch',
ipRange: '192.168.1.0/24',
secret: 'shared-secret',
enabled: true
2026-02-02 22:21:55 +00:00
}
2026-02-11 16:32:49 +00:00
],
vlanAssignment: {
2026-02-02 22:21:55 +00:00
defaultVlan: 100,
2026-02-11 16:32:49 +00:00
allowUnknownMacs: true,
mappings: [
{ mac: 'aa:bb:cc:dd:ee:ff', vlan: 10, enabled: true }, // Exact MAC
{ mac: 'aa:bb:cc', vlan: 20, enabled: true }, // OUI prefix
]
},
accounting: {
enabled: true,
retentionDays: 30
2026-02-02 22:21:55 +00:00
}
}
});
```
2026-02-11 16:32:49 +00:00
### Components
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
| Component | Purpose |
|-----------|---------|
| **RadiusServer ** | Main RADIUS server handling auth + accounting requests |
| **VlanManager ** | MAC-to-VLAN mapping with exact, OUI, and wildcard patterns |
| **AccountingManager ** | Session tracking, traffic metering, start/stop/interim updates |
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
### OpsServer API
RADIUS is fully manageable at runtime via the OpsServer API:
- Client management (add/remove/list NAS devices)
- VLAN mapping CRUD operations
- Session monitoring and forced disconnects
- Accounting summaries and statistics
## Storage & Caching
2025-05-30 07:06:00 +00:00
### StorageManager
2026-02-11 16:32:49 +00:00
Provides a unified key-value interface with three backends:
2025-05-30 07:06:00 +00:00
```typescript
2026-02-11 16:32:49 +00:00
// Filesystem backend
storage: { fsPath: '/var/lib/dcrouter/data' }
2025-05-30 07:06:00 +00:00
2026-02-11 16:32:49 +00:00
// Custom backend (Redis, S3, etc.)
storage: {
readFunction: async (key) => await redis.get(key),
writeFunction: async (key, value) => await redis.set(key, value)
}
// In-memory (development only — data lost on restart)
// Simply omit the storage config
2025-05-30 07:06:00 +00:00
```
2026-02-11 16:32:49 +00:00
Used for: DKIM keys, email routes, bounce/suppression lists, IP reputation data, domain configs.
### Cache Database
An embedded MongoDB-compatible database (via smartdata + TsmDb) for persistent caching with automatic TTL cleanup:
2025-05-30 07:06:00 +00:00
```typescript
2026-02-11 16:32:49 +00:00
cacheConfig: {
enabled: true,
storagePath: '/etc/dcrouter/tsmdb',
dbName: 'dcrouter',
cleanupIntervalHours: 1,
ttlConfig: {
emails: 30, // days
ipReputation: 1, // days
bounces: 30, // days
dkimKeys: 90, // days
suppression: 30 // days
}
}
2025-05-30 07:06:00 +00:00
```
2026-02-11 16:32:49 +00:00
Cached document types: `CachedEmail` , `CachedIPReputation` , `CachedBounce` , `CachedSuppression` , `CachedDKIMKey` .
2025-05-30 07:06:00 +00:00
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
2026-02-11 16:32:49 +00:00
Automatic IP reputation checks on inbound connections with configurable caching:
2025-05-22 13:10:45 +00:00
```typescript
2026-02-11 16:32:49 +00:00
// IP reputation is checked automatically for inbound SMTP connections.
// Results are cached according to cacheConfig.ttlConfig.ipReputation.
```
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
### Rate Limiting
2024-05-11 12:33:14 +02:00
2026-02-11 16:32:49 +00:00
Hierarchical rate limits with three levels of specificity:
```typescript
// Global defaults (via emailConfig.defaults.rateLimits)
defaults: {
rateLimits: {
inbound: { messagesPerMinute: 50, connectionsPerIp: 5, recipientsPerMessage: 50 },
outbound: { messagesPerMinute: 100 }
}
}
// Per-domain overrides (in domain config)
{
domain: 'high-volume.com',
rateLimits: {
outbound: { messagesPerMinute: 500 } // Override for this domain
}
2024-05-11 12:33:14 +02:00
}
2025-05-22 13:10:45 +00:00
```
2026-02-11 16:32:49 +00:00
**Precedence**: Domain-specific > Pattern-specific > Global
### Content Scanning
2025-05-22 13:10:45 +00:00
```typescript
2026-02-11 16:32:49 +00:00
action: {
type: 'process',
options: {
contentScanning: true,
scanners: [
{ type: 'spam', threshold: 5.0, action: 'tag' },
{ type: 'virus', action: 'reject' },
{ type: 'attachment', blockedExtensions: ['.exe', '.bat', '.scr'], action: 'reject' }
]
2025-05-22 13:10:45 +00:00
}
2026-02-11 16:32:49 +00:00
}
2026-02-02 22:21:55 +00:00
```
## OpsServer Dashboard
2026-02-11 16:32:49 +00:00
The OpsServer provides a web-based management interface served on port 3000. It's built with modern web components using [@design.estate/dees-catalog ](https://code.foss.global/design.estate/dees-catalog ).
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
### Dashboard Views
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
| View | Description |
|------|-------------|
| 📊 **Overview ** | Real-time server stats, CPU/memory, connection counts, email throughput |
| 🌐 **Network ** | Active connections, top IPs, throughput rates, SmartProxy metrics |
| 📧 **Email ** | Queue monitoring (queued/sent/failed), bounce records, security incidents |
| 📜 **Logs ** | Real-time log viewer with level filtering and search |
| ⚙️ **Configuration ** | Read-only view of current system configuration |
| 🛡️ **Security ** | IP reputation, rate limit status, blocked connections |
2026-02-02 22:21:55 +00:00
### API Endpoints
2026-02-11 16:32:49 +00:00
All management is done via TypedRequest over HTTP POST to `/typedrequest` :
2026-02-02 22:21:55 +00:00
```typescript
2026-02-11 16:32:49 +00:00
// Authentication
{ method: 'adminLogin', data: { username, password } }
{ method: 'verifyIdentity', data: { identity } }
// Statistics
{ method: 'getServerStatistics', data: { identity } }
{ method: 'getCombinedMetrics', data: { identity } }
{ method: 'getHealthStatus', data: { identity } }
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
// Email Operations
{ method: 'getQueuedEmails', data: { identity } }
{ method: 'getSentEmails', data: { identity } }
{ method: 'getFailedEmails', data: { identity } }
{ method: 'resendEmail', data: { identity, emailId } }
{ method: 'getBounceRecords', data: { identity } }
2024-05-11 12:33:14 +02:00
2026-02-03 23:26:51 +00:00
// Configuration (read-only)
2026-02-11 16:32:49 +00:00
{ method: 'getConfiguration', data: { identity } }
2026-02-02 22:21:55 +00:00
// Logs
2026-02-11 16:32:49 +00:00
{ method: 'getLogs', data: { identity, level, limit } }
2026-02-02 22:21:55 +00:00
// RADIUS
2026-02-11 16:32:49 +00:00
{ method: 'getRadiusSessions', data: { identity } }
{ method: 'getRadiusClients', data: { identity } }
{ method: 'getRadiusStatistics', data: { identity } }
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
```typescript
2026-02-11 16:32:49 +00:00
import { DcRouter } from '@serve .zone/dcrouter';
const router = new DcRouter(options: IDcRouterOptions);
2025-03-15 16:09:18 +00:00
```
2025-05-22 13:10:45 +00:00
#### Methods
2026-02-11 16:32:49 +00:00
| Method | Description |
|--------|-------------|
| `start(): Promise<void>` | Start all configured services |
| `stop(): Promise<void>` | Gracefully stop all services |
| `updateSmartProxyConfig(config): Promise<void>` | Hot-update SmartProxy routes |
| `updateEmailConfig(config): Promise<void>` | Hot-update email configuration |
| `updateEmailRoutes(routes): Promise<void>` | Update email routing rules at runtime |
| `updateRadiusConfig(config): Promise<void>` | Hot-update RADIUS configuration |
| `getStats(): any` | Get real-time statistics from all services |
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
#### Properties
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
| Property | Type | Description |
|----------|------|-------------|
| `options` | `IDcRouterOptions` | Current configuration |
| `smartProxy` | `SmartProxy` | SmartProxy instance |
| `emailServer` | `UnifiedEmailServer` | Email server instance |
| `dnsServer` | `DnsServer` | DNS server instance |
| `radiusServer` | `RadiusServer` | RADIUS server instance |
| `storageManager` | `StorageManager` | Storage backend |
| `opsServer` | `OpsServer` | OpsServer/dashboard instance |
| `metricsManager` | `MetricsManager` | Metrics collector |
| `cacheDb` | `CacheDb` | Cache database instance |
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
## Sub-Modules
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
DcRouter is published as a monorepo with separately-installable interface and web packages:
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
| Package | Description | Install |
|---------|-------------|---------|
| [`@serve.zone/dcrouter` ](https://www.npmjs.com/package/@serve.zone/dcrouter ) | Main package — the full router | `pnpm add @serve.zone/dcrouter` |
| [`@serve.zone/dcrouter-interfaces` ](https://www.npmjs.com/package/@serve.zone/dcrouter-interfaces ) | TypedRequest interfaces for the OpsServer API | `pnpm add @serve.zone/dcrouter-interfaces` |
| [`@serve.zone/dcrouter-web` ](https://www.npmjs.com/package/@serve.zone/dcrouter-web ) | Web dashboard components | `pnpm add @serve.zone/dcrouter-web` |
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
You can also import interfaces directly from the main package:
2025-05-22 13:10:45 +00:00
```typescript
2026-02-11 16:32:49 +00:00
import { data, requests } from '@serve .zone/dcrouter/interfaces';
2025-05-22 13:10:45 +00:00
```
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-11 16:32:49 +00:00
DcRouter includes a comprehensive test suite with **198 test files ** covering all system components:
2025-05-22 13:10:45 +00:00
2026-02-11 16:32:49 +00:00
- **SMTP Protocol** — EHLO, MAIL FROM, RCPT TO, DATA, STARTTLS, AUTH, pipelining
- **Email Routing** — Pattern matching, route priorities, all action types
- **Email Security** — DKIM, SPF, DMARC, content scanning, rate limiting
- **DNS** — Record management, socket handler, validation, mode switching
- **RADIUS** — Authentication, VLAN assignment, accounting
- **Deliverability** — IP warmup, reputation monitoring, bounce management
- **Storage & Cache** — All backends, TTL cleanup, persistence
- **OpsServer** — API authentication, protected endpoints, statistics
- **Integration** — Full end-to-end workflows
2026-02-02 22:21:55 +00:00
2026-02-11 16:32:49 +00:00
### Running Tests
2026-02-02 22:21:55 +00:00
```bash
# Run all tests
pnpm test
2026-02-11 16:32:49 +00:00
# Run a specific test file
tstest test/test.email.router.ts --verbose
2025-03-15 16:09:18 +00:00
2026-02-11 16:32:49 +00:00
# Run SMTP protocol suite
tstest test/suite/smtpserver_commands/test.cmd-01.ehlo-command.ts --verbose
2025-05-22 13:10:45 +00:00
```
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.