@serve.zone/dcrouter 15.0.1 → 15.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +1 -1
- package/dist_serve/bundle.js +768 -768
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/acme/classes.smartacme-lifecycle.d.ts +25 -0
- package/dist_ts/acme/classes.smartacme-lifecycle.js +144 -0
- package/dist_ts/acme/index.d.ts +1 -0
- package/dist_ts/acme/index.js +2 -1
- package/dist_ts/classes.dcrouter.d.ts +21 -139
- package/dist_ts/classes.dcrouter.js +71 -1585
- package/dist_ts/dns/classes.dns-server-runtime.d.ts +37 -0
- package/dist_ts/dns/classes.dns-server-runtime.js +449 -0
- package/dist_ts/dns/index.d.ts +1 -0
- package/dist_ts/dns/index.js +2 -1
- package/dist_ts/email/classes.accepted-email-spool.d.ts +55 -0
- package/dist_ts/email/classes.accepted-email-spool.js +345 -0
- package/dist_ts/email/classes.email-route-builder.d.ts +28 -0
- package/dist_ts/email/classes.email-route-builder.js +260 -0
- package/dist_ts/email/index.d.ts +2 -0
- package/dist_ts/email/index.js +3 -1
- package/dist_ts/opsserver/handlers/gatewayclient.handler.js +10 -8
- package/dist_ts/remoteingress/classes.hub-lifecycle.d.ts +27 -0
- package/dist_ts/remoteingress/classes.hub-lifecycle.js +241 -0
- package/dist_ts/remoteingress/classes.remoteingress-manager.d.ts +1 -2
- package/dist_ts/remoteingress/index.d.ts +1 -0
- package/dist_ts/remoteingress/index.js +2 -1
- package/dist_ts/security/classes.route-policy-augmenter.d.ts +22 -0
- package/dist_ts/security/classes.route-policy-augmenter.js +120 -0
- package/dist_ts/security/index.d.ts +1 -0
- package/dist_ts/security/index.js +2 -1
- package/dist_ts/vpn/classes.vpn-access-resolver.d.ts +34 -0
- package/dist_ts/vpn/classes.vpn-access-resolver.js +101 -0
- package/dist_ts/vpn/index.d.ts +1 -0
- package/dist_ts/vpn/index.js +2 -1
- package/dist_ts_migrations/index.js +92 -9
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/appstate/acme.d.ts +17 -0
- package/dist_ts_web/appstate/acme.js +64 -0
- package/dist_ts_web/appstate/certificates.d.ts +37 -0
- package/dist_ts_web/appstate/certificates.js +107 -0
- package/dist_ts_web/appstate/config.d.ts +9 -0
- package/dist_ts_web/appstate/config.js +35 -0
- package/dist_ts_web/appstate/domains.d.ts +80 -0
- package/dist_ts_web/appstate/domains.js +324 -0
- package/dist_ts_web/appstate/email-domains.d.ts +25 -0
- package/dist_ts_web/appstate/email-domains.js +104 -0
- package/dist_ts_web/appstate/email-ops.d.ts +10 -0
- package/dist_ts_web/appstate/email-ops.js +40 -0
- package/dist_ts_web/appstate/login.d.ts +30 -0
- package/dist_ts_web/appstate/login.js +83 -0
- package/dist_ts_web/appstate/logs.d.ts +16 -0
- package/dist_ts_web/appstate/logs.js +27 -0
- package/dist_ts_web/appstate/network.d.ts +50 -0
- package/dist_ts_web/appstate/network.js +122 -0
- package/dist_ts_web/appstate/profiles-targets.d.ts +45 -0
- package/dist_ts_web/appstate/profiles-targets.js +173 -0
- package/dist_ts_web/appstate/remoteingress.d.ts +47 -0
- package/dist_ts_web/appstate/remoteingress.js +204 -0
- package/dist_ts_web/appstate/routes.d.ts +76 -0
- package/dist_ts_web/appstate/routes.js +316 -0
- package/dist_ts_web/appstate/runtime.d.ts +1 -0
- package/dist_ts_web/appstate/runtime.js +276 -0
- package/dist_ts_web/appstate/security.d.ts +29 -0
- package/dist_ts_web/appstate/security.js +167 -0
- package/dist_ts_web/appstate/shared.d.ts +3 -0
- package/dist_ts_web/appstate/shared.js +13 -0
- package/dist_ts_web/appstate/stats.d.ts +15 -0
- package/dist_ts_web/appstate/stats.js +59 -0
- package/dist_ts_web/appstate/target-profiles.d.ts +37 -0
- package/dist_ts_web/appstate/target-profiles.js +118 -0
- package/dist_ts_web/appstate/ui.d.ts +11 -0
- package/dist_ts_web/appstate/ui.js +55 -0
- package/dist_ts_web/appstate/users.d.ts +27 -0
- package/dist_ts_web/appstate/users.js +85 -0
- package/dist_ts_web/appstate/vpn.d.ts +44 -0
- package/dist_ts_web/appstate/vpn.js +148 -0
- package/dist_ts_web/appstate.d.ts +20 -568
- package/dist_ts_web/appstate.js +24 -2418
- package/package.json +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/acme/classes.smartacme-lifecycle.ts +155 -0
- package/ts/acme/index.ts +1 -0
- package/ts/classes.dcrouter.ts +118 -1919
- package/ts/dns/classes.dns-server-runtime.ts +525 -0
- package/ts/dns/index.ts +1 -0
- package/ts/email/classes.accepted-email-spool.ts +434 -0
- package/ts/email/classes.email-route-builder.ts +312 -0
- package/ts/email/index.ts +2 -0
- package/ts/opsserver/handlers/gatewayclient.handler.ts +9 -7
- package/ts/remoteingress/classes.hub-lifecycle.ts +278 -0
- package/ts/remoteingress/classes.remoteingress-manager.ts +1 -1
- package/ts/remoteingress/index.ts +1 -0
- package/ts/security/classes.route-policy-augmenter.ts +140 -0
- package/ts/security/index.ts +1 -0
- package/ts/vpn/classes.vpn-access-resolver.ts +126 -0
- package/ts/vpn/index.ts +1 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/appstate/acme.ts +93 -0
- package/ts_web/appstate/certificates.ts +159 -0
- package/ts_web/appstate/config.ts +49 -0
- package/ts_web/appstate/domains.ts +429 -0
- package/ts_web/appstate/email-domains.ts +155 -0
- package/ts_web/appstate/email-ops.ts +57 -0
- package/ts_web/appstate/login.ts +128 -0
- package/ts_web/appstate/logs.ts +50 -0
- package/ts_web/appstate/network.ts +161 -0
- package/ts_web/appstate/profiles-targets.ts +240 -0
- package/ts_web/appstate/remoteingress.ts +300 -0
- package/ts_web/appstate/routes.ts +447 -0
- package/ts_web/appstate/runtime.ts +308 -0
- package/ts_web/appstate/security.ts +229 -0
- package/ts_web/appstate/shared.ts +15 -0
- package/ts_web/appstate/stats.ts +79 -0
- package/ts_web/appstate/target-profiles.ts +164 -0
- package/ts_web/appstate/ui.ts +75 -0
- package/ts_web/appstate/users.ts +133 -0
- package/ts_web/appstate/vpn.ts +234 -0
- package/ts_web/appstate.ts +24 -3403
package/package.json
CHANGED
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
import { logger } from '../logger.js';
|
|
3
|
+
import type { DcRouter } from '../classes.dcrouter.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Background start/retry/stop lifecycle for the DcRouter-owned SmartAcme
|
|
7
|
+
* instance. SmartAcme startup can hit ACME rate limits, so startup runs in
|
|
8
|
+
* the background with generation-guarded exponential retry, and certificate
|
|
9
|
+
* provisioning is re-triggered once DNS-01 becomes ready.
|
|
10
|
+
*/
|
|
11
|
+
export class SmartAcmeLifecycle {
|
|
12
|
+
/** True once the SmartAcme DNS-01 provider finished starting. */
|
|
13
|
+
public ready = false;
|
|
14
|
+
/** Tracks whether the taskbuffer SmartAcme service is started, so SmartProxy rebuilds can re-kick startup. */
|
|
15
|
+
public serviceStarted = false;
|
|
16
|
+
|
|
17
|
+
private startGeneration = 0;
|
|
18
|
+
private startPromise?: Promise<void>;
|
|
19
|
+
private retryTimer?: ReturnType<typeof setTimeout>;
|
|
20
|
+
private retryAttempt = 0;
|
|
21
|
+
|
|
22
|
+
constructor(private dcRouterRef: DcRouter) {}
|
|
23
|
+
|
|
24
|
+
public startInBackground(): void {
|
|
25
|
+
if (!this.dcRouterRef.smartAcme) {
|
|
26
|
+
this.ready = false;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const generation = ++this.startGeneration;
|
|
31
|
+
this.ready = false;
|
|
32
|
+
this.retryAttempt = 0;
|
|
33
|
+
this.clearRetryTimer();
|
|
34
|
+
this.scheduleStart(generation, 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async stop(): Promise<void> {
|
|
38
|
+
this.startGeneration++;
|
|
39
|
+
this.ready = false;
|
|
40
|
+
this.retryAttempt = 0;
|
|
41
|
+
this.clearRetryTimer();
|
|
42
|
+
|
|
43
|
+
const smartAcme = this.dcRouterRef.smartAcme;
|
|
44
|
+
if (!smartAcme) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await smartAcme.stop();
|
|
50
|
+
} catch (err) {
|
|
51
|
+
logger.log('error', 'Error stopping SmartAcme', { error: String(err) });
|
|
52
|
+
} finally {
|
|
53
|
+
if (this.dcRouterRef.smartAcme === smartAcme) {
|
|
54
|
+
this.dcRouterRef.smartAcme = undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private scheduleStart(generation: number, delayMs: number): void {
|
|
60
|
+
this.clearRetryTimer();
|
|
61
|
+
const retryTimer = setTimeout(() => {
|
|
62
|
+
this.retryTimer = undefined;
|
|
63
|
+
this.runStartAttempt(generation).catch((err) => {
|
|
64
|
+
logger.log('error', `Unexpected SmartAcme startup error: ${(err as Error).message}`);
|
|
65
|
+
});
|
|
66
|
+
}, delayMs);
|
|
67
|
+
this.retryTimer = retryTimer;
|
|
68
|
+
const unrefableTimer = retryTimer as any;
|
|
69
|
+
if (typeof unrefableTimer?.unref === 'function') {
|
|
70
|
+
unrefableTimer.unref();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private async runStartAttempt(generation: number): Promise<void> {
|
|
75
|
+
const smartAcme = this.dcRouterRef.smartAcme;
|
|
76
|
+
if (!smartAcme || generation !== this.startGeneration) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const startPromise = smartAcme.start();
|
|
81
|
+
this.startPromise = startPromise;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
await startPromise;
|
|
85
|
+
if (generation !== this.startGeneration || this.dcRouterRef.smartAcme !== smartAcme) {
|
|
86
|
+
await smartAcme.stop().catch((err) => {
|
|
87
|
+
logger.log('warn', `Failed to stop stale SmartAcme instance: ${(err as Error).message}`);
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.ready = true;
|
|
93
|
+
this.retryAttempt = 0;
|
|
94
|
+
logger.log('info', 'SmartAcme DNS-01 provider is now ready');
|
|
95
|
+
this.retriggerCertificateProvisioning();
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (generation !== this.startGeneration || this.dcRouterRef.smartAcme !== smartAcme) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.ready = false;
|
|
102
|
+
await smartAcme.stop().catch((stopErr) => {
|
|
103
|
+
logger.log('warn', `Failed to clean up SmartAcme after startup failure: ${(stopErr as Error).message}`);
|
|
104
|
+
});
|
|
105
|
+
this.retryAttempt++;
|
|
106
|
+
if (this.retryAttempt > 20) {
|
|
107
|
+
logger.log('error', `SmartAcme DNS-01 provider failed after 20 startup attempts: ${(err as Error).message}`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const baseDelayMs = 5000;
|
|
112
|
+
const maxDelayMs = 3_600_000;
|
|
113
|
+
const delayMs = Math.min(baseDelayMs * Math.pow(2, this.retryAttempt - 1), maxDelayMs);
|
|
114
|
+
const jitter = 0.8 + Math.random() * 0.4;
|
|
115
|
+
const actualDelayMs = Math.floor(delayMs * jitter);
|
|
116
|
+
logger.log('warn', `SmartAcme DNS-01 provider startup failed: ${(err as Error).message}; retrying in ${actualDelayMs}ms (attempt ${this.retryAttempt}/20)`);
|
|
117
|
+
this.scheduleStart(generation, actualDelayMs);
|
|
118
|
+
} finally {
|
|
119
|
+
if (this.startPromise === startPromise) {
|
|
120
|
+
this.startPromise = undefined;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private retriggerCertificateProvisioning(): void {
|
|
126
|
+
// During startup, certProvisionFunction returns 'http01' while SmartAcme is not ready,
|
|
127
|
+
// but Rust ACME is disabled when certProvisionFunction is set. Re-applying routes
|
|
128
|
+
// retries provisioning now that DNS-01 is available.
|
|
129
|
+
if (this.dcRouterRef.routeConfigManager) {
|
|
130
|
+
logger.log('info', 'Re-triggering certificate provisioning via RouteConfigManager');
|
|
131
|
+
this.dcRouterRef.routeConfigManager.applyRoutes().catch((err: any) => {
|
|
132
|
+
logger.log('warn', `Failed to re-trigger cert provisioning: ${err?.message || err}`);
|
|
133
|
+
});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (this.dcRouterRef.smartProxy) {
|
|
138
|
+
if (this.dcRouterRef.certProvisionScheduler) {
|
|
139
|
+
this.dcRouterRef.certProvisionScheduler.clear();
|
|
140
|
+
}
|
|
141
|
+
const currentRoutes = this.dcRouterRef.smartProxy.routeManager.getRoutes();
|
|
142
|
+
logger.log('info', `Re-triggering certificate provisioning for ${currentRoutes.length} routes`);
|
|
143
|
+
this.dcRouterRef.smartProxy.updateRoutes(currentRoutes).catch((err: any) => {
|
|
144
|
+
logger.log('warn', `Failed to re-trigger cert provisioning: ${err?.message || err}`);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private clearRetryTimer(): void {
|
|
150
|
+
if (this.retryTimer) {
|
|
151
|
+
clearTimeout(this.retryTimer);
|
|
152
|
+
this.retryTimer = undefined;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
package/ts/acme/index.ts
CHANGED