@push.rocks/smartproxy 15.0.2 → 16.0.2
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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/certificate/index.d.ts +10 -4
- package/dist_ts/certificate/index.js +5 -7
- package/dist_ts/certificate/models/certificate-types.d.ts +35 -15
- package/dist_ts/certificate/providers/cert-provisioner.d.ts +41 -15
- package/dist_ts/certificate/providers/cert-provisioner.js +201 -41
- package/dist_ts/forwarding/config/forwarding-types.d.ts +40 -76
- package/dist_ts/forwarding/config/forwarding-types.js +19 -18
- package/dist_ts/forwarding/config/index.d.ts +4 -2
- package/dist_ts/forwarding/config/index.js +5 -3
- package/dist_ts/forwarding/handlers/base-handler.js +3 -1
- package/dist_ts/forwarding/index.d.ts +5 -6
- package/dist_ts/forwarding/index.js +3 -3
- package/dist_ts/http/models/http-types.js +1 -1
- package/dist_ts/http/port80/acme-interfaces.d.ts +30 -0
- package/dist_ts/http/port80/acme-interfaces.js +46 -1
- package/dist_ts/http/port80/port80-handler.d.ts +17 -2
- package/dist_ts/http/port80/port80-handler.js +49 -11
- package/dist_ts/proxies/smart-proxy/models/interfaces.d.ts +2 -61
- package/dist_ts/proxies/smart-proxy/models/interfaces.js +5 -4
- package/dist_ts/proxies/smart-proxy/models/route-types.d.ts +118 -4
- package/dist_ts/proxies/smart-proxy/network-proxy-bridge.d.ts +70 -4
- package/dist_ts/proxies/smart-proxy/network-proxy-bridge.js +193 -43
- package/dist_ts/proxies/smart-proxy/route-connection-handler.d.ts +2 -5
- package/dist_ts/proxies/smart-proxy/route-connection-handler.js +25 -146
- package/dist_ts/proxies/smart-proxy/route-helpers/index.d.ts +7 -0
- package/dist_ts/proxies/smart-proxy/route-helpers/index.js +9 -0
- package/dist_ts/proxies/smart-proxy/route-helpers.d.ts +54 -1
- package/dist_ts/proxies/smart-proxy/route-helpers.js +102 -1
- package/dist_ts/proxies/smart-proxy/route-manager.d.ts +3 -9
- package/dist_ts/proxies/smart-proxy/route-manager.js +3 -115
- package/dist_ts/proxies/smart-proxy/smart-proxy.d.ts +72 -10
- package/dist_ts/proxies/smart-proxy/smart-proxy.js +135 -268
- package/dist_ts/proxies/smart-proxy/timeout-manager.js +3 -3
- package/dist_ts/proxies/smart-proxy/utils/index.d.ts +12 -0
- package/dist_ts/proxies/smart-proxy/utils/index.js +19 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.d.ts +174 -0
- package/dist_ts/proxies/smart-proxy/utils/route-helpers.js +332 -0
- package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.d.ts +51 -0
- package/dist_ts/proxies/smart-proxy/utils/route-migration-utils.js +124 -0
- package/dist_ts/proxies/smart-proxy/utils/route-patterns.d.ts +131 -0
- package/dist_ts/proxies/smart-proxy/utils/route-patterns.js +217 -0
- package/dist_ts/proxies/smart-proxy/utils/route-utils.d.ts +79 -0
- package/dist_ts/proxies/smart-proxy/utils/route-utils.js +266 -0
- package/dist_ts/proxies/smart-proxy/utils/route-validators.d.ts +73 -0
- package/dist_ts/proxies/smart-proxy/utils/route-validators.js +242 -0
- package/package.json +1 -1
- package/readme.md +139 -111
- package/readme.plan.md +164 -312
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/certificate/index.ts +17 -9
- package/ts/certificate/models/certificate-types.ts +37 -16
- package/ts/certificate/providers/cert-provisioner.ts +247 -54
- package/ts/forwarding/config/forwarding-types.ts +79 -107
- package/ts/forwarding/config/index.ts +4 -2
- package/ts/forwarding/handlers/base-handler.ts +4 -2
- package/ts/forwarding/index.ts +3 -2
- package/ts/http/models/http-types.ts +0 -1
- package/ts/http/port80/acme-interfaces.ts +84 -0
- package/ts/http/port80/port80-handler.ts +61 -15
- package/ts/proxies/smart-proxy/models/interfaces.ts +7 -64
- package/ts/proxies/smart-proxy/models/route-types.ts +152 -22
- package/ts/proxies/smart-proxy/network-proxy-bridge.ts +226 -55
- package/ts/proxies/smart-proxy/route-connection-handler.ts +36 -205
- package/ts/proxies/smart-proxy/route-helpers/index.ts +9 -0
- package/ts/proxies/smart-proxy/route-helpers.ts +165 -11
- package/ts/proxies/smart-proxy/route-manager.ts +3 -130
- package/ts/proxies/smart-proxy/smart-proxy.ts +157 -329
- package/ts/proxies/smart-proxy/timeout-manager.ts +2 -2
- package/ts/proxies/smart-proxy/utils/index.ts +40 -0
- package/ts/proxies/smart-proxy/utils/route-helpers.ts +455 -0
- package/ts/proxies/smart-proxy/utils/route-migration-utils.ts +165 -0
- package/ts/proxies/smart-proxy/utils/route-patterns.ts +309 -0
- package/ts/proxies/smart-proxy/utils/route-utils.ts +330 -0
- package/ts/proxies/smart-proxy/utils/route-validators.ts +269 -0
- package/ts/forwarding/config/domain-config.ts +0 -28
- package/ts/forwarding/config/domain-manager.ts +0 -283
- package/ts/proxies/smart-proxy/connection-handler.ts +0 -1240
- package/ts/proxies/smart-proxy/port-range-manager.ts +0 -211
- /package/ts/proxies/smart-proxy/{domain-config-manager.ts → domain-config-manager.ts.bak} +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type * as plugins from '../../plugins.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
+
* @deprecated The legacy forwarding types are being replaced by the route-based configuration system.
|
|
5
|
+
* See /ts/proxies/smart-proxy/models/route-types.ts for the new route-based configuration.
|
|
6
|
+
*
|
|
4
7
|
* The primary forwarding types supported by SmartProxy
|
|
5
8
|
*/
|
|
6
9
|
export type TForwardingType =
|
|
@@ -9,88 +12,6 @@ export type TForwardingType =
|
|
|
9
12
|
| 'https-terminate-to-http' // Terminate TLS and forward to HTTP backend
|
|
10
13
|
| 'https-terminate-to-https'; // Terminate TLS and forward to HTTPS backend
|
|
11
14
|
|
|
12
|
-
/**
|
|
13
|
-
* Target configuration for forwarding
|
|
14
|
-
*/
|
|
15
|
-
export interface ITargetConfig {
|
|
16
|
-
host: string | string[]; // Support single host or round-robin
|
|
17
|
-
port: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* HTTP-specific options for forwarding
|
|
22
|
-
*/
|
|
23
|
-
export interface IHttpOptions {
|
|
24
|
-
enabled?: boolean; // Whether HTTP is enabled
|
|
25
|
-
redirectToHttps?: boolean; // Redirect HTTP to HTTPS
|
|
26
|
-
headers?: Record<string, string>; // Custom headers for HTTP responses
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* HTTPS-specific options for forwarding
|
|
31
|
-
*/
|
|
32
|
-
export interface IHttpsOptions {
|
|
33
|
-
customCert?: { // Use custom cert instead of auto-provisioned
|
|
34
|
-
key: string;
|
|
35
|
-
cert: string;
|
|
36
|
-
};
|
|
37
|
-
forwardSni?: boolean; // Forward SNI info in passthrough mode
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* ACME certificate handling options
|
|
42
|
-
*/
|
|
43
|
-
export interface IAcmeForwardingOptions {
|
|
44
|
-
enabled?: boolean; // Enable ACME certificate provisioning
|
|
45
|
-
maintenance?: boolean; // Auto-renew certificates
|
|
46
|
-
production?: boolean; // Use production ACME servers
|
|
47
|
-
forwardChallenges?: { // Forward ACME challenges
|
|
48
|
-
host: string;
|
|
49
|
-
port: number;
|
|
50
|
-
useTls?: boolean;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Security options for forwarding
|
|
56
|
-
*/
|
|
57
|
-
export interface ISecurityOptions {
|
|
58
|
-
allowedIps?: string[]; // IPs allowed to connect
|
|
59
|
-
blockedIps?: string[]; // IPs blocked from connecting
|
|
60
|
-
maxConnections?: number; // Max simultaneous connections
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Advanced options for forwarding
|
|
65
|
-
*/
|
|
66
|
-
export interface IAdvancedOptions {
|
|
67
|
-
portRanges?: Array<{ from: number; to: number }>; // Allowed port ranges
|
|
68
|
-
networkProxyPort?: number; // Custom NetworkProxy port if using terminate mode
|
|
69
|
-
keepAlive?: boolean; // Enable TCP keepalive
|
|
70
|
-
timeout?: number; // Connection timeout in ms
|
|
71
|
-
headers?: Record<string, string>; // Custom headers with support for variables like {sni}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Unified forwarding configuration interface
|
|
76
|
-
*/
|
|
77
|
-
export interface IForwardConfig {
|
|
78
|
-
// Define the primary forwarding type - use-case driven approach
|
|
79
|
-
type: TForwardingType;
|
|
80
|
-
|
|
81
|
-
// Target configuration
|
|
82
|
-
target: ITargetConfig;
|
|
83
|
-
|
|
84
|
-
// Protocol options
|
|
85
|
-
http?: IHttpOptions;
|
|
86
|
-
https?: IHttpsOptions;
|
|
87
|
-
acme?: IAcmeForwardingOptions;
|
|
88
|
-
|
|
89
|
-
// Security and advanced options
|
|
90
|
-
security?: ISecurityOptions;
|
|
91
|
-
advanced?: IAdvancedOptions;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
15
|
/**
|
|
95
16
|
* Event types emitted by forwarding handlers
|
|
96
17
|
*/
|
|
@@ -114,49 +35,100 @@ export interface IForwardingHandler extends plugins.EventEmitter {
|
|
|
114
35
|
handleHttpRequest(req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse): void;
|
|
115
36
|
}
|
|
116
37
|
|
|
38
|
+
// Import and re-export the route-based helpers for seamless transition
|
|
39
|
+
import {
|
|
40
|
+
createHttpRoute,
|
|
41
|
+
createHttpsTerminateRoute,
|
|
42
|
+
createHttpsPassthroughRoute,
|
|
43
|
+
createHttpToHttpsRedirect,
|
|
44
|
+
createCompleteHttpsServer,
|
|
45
|
+
createLoadBalancerRoute
|
|
46
|
+
} from '../../proxies/smart-proxy/utils/route-helpers.js';
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
createHttpRoute,
|
|
50
|
+
createHttpsTerminateRoute,
|
|
51
|
+
createHttpsPassthroughRoute,
|
|
52
|
+
createHttpToHttpsRedirect,
|
|
53
|
+
createCompleteHttpsServer,
|
|
54
|
+
createLoadBalancerRoute
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated These helper functions are maintained for backward compatibility.
|
|
59
|
+
* Please use the route-based helpers instead:
|
|
60
|
+
* - createHttpRoute
|
|
61
|
+
* - createHttpsTerminateRoute
|
|
62
|
+
* - createHttpsPassthroughRoute
|
|
63
|
+
* - createHttpToHttpsRedirect
|
|
64
|
+
*/
|
|
65
|
+
import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js';
|
|
66
|
+
import { domainConfigToRouteConfig } from '../../proxies/smart-proxy/utils/route-migration-utils.js';
|
|
67
|
+
|
|
68
|
+
// For backward compatibility
|
|
69
|
+
export interface IForwardConfig {
|
|
70
|
+
type: TForwardingType;
|
|
71
|
+
target: {
|
|
72
|
+
host: string | string[];
|
|
73
|
+
port: number;
|
|
74
|
+
};
|
|
75
|
+
http?: any;
|
|
76
|
+
https?: any;
|
|
77
|
+
acme?: any;
|
|
78
|
+
security?: any;
|
|
79
|
+
advanced?: any;
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface IDeprecatedForwardConfig {
|
|
84
|
+
type: TForwardingType;
|
|
85
|
+
target: {
|
|
86
|
+
host: string | string[];
|
|
87
|
+
port: number;
|
|
88
|
+
};
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
}
|
|
91
|
+
|
|
117
92
|
/**
|
|
118
|
-
*
|
|
93
|
+
* @deprecated Use createHttpRoute instead
|
|
119
94
|
*/
|
|
120
95
|
export const httpOnly = (
|
|
121
|
-
partialConfig: Partial<
|
|
122
|
-
):
|
|
96
|
+
partialConfig: Partial<IDeprecatedForwardConfig> & Pick<IDeprecatedForwardConfig, 'target'>
|
|
97
|
+
): IDeprecatedForwardConfig => ({
|
|
123
98
|
type: 'http-only',
|
|
124
99
|
target: partialConfig.target,
|
|
125
|
-
|
|
126
|
-
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
127
|
-
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
100
|
+
...(partialConfig)
|
|
128
101
|
});
|
|
129
102
|
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Use createHttpsTerminateRoute instead
|
|
105
|
+
*/
|
|
130
106
|
export const tlsTerminateToHttp = (
|
|
131
|
-
partialConfig: Partial<
|
|
132
|
-
):
|
|
107
|
+
partialConfig: Partial<IDeprecatedForwardConfig> & Pick<IDeprecatedForwardConfig, 'target'>
|
|
108
|
+
): IDeprecatedForwardConfig => ({
|
|
133
109
|
type: 'https-terminate-to-http',
|
|
134
110
|
target: partialConfig.target,
|
|
135
|
-
|
|
136
|
-
acme: { enabled: true, maintenance: true, ...(partialConfig.acme || {}) },
|
|
137
|
-
http: { enabled: true, redirectToHttps: true, ...(partialConfig.http || {}) },
|
|
138
|
-
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
139
|
-
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
111
|
+
...(partialConfig)
|
|
140
112
|
});
|
|
141
113
|
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated Use createHttpsTerminateRoute with reencrypt option instead
|
|
116
|
+
*/
|
|
142
117
|
export const tlsTerminateToHttps = (
|
|
143
|
-
partialConfig: Partial<
|
|
144
|
-
):
|
|
118
|
+
partialConfig: Partial<IDeprecatedForwardConfig> & Pick<IDeprecatedForwardConfig, 'target'>
|
|
119
|
+
): IDeprecatedForwardConfig => ({
|
|
145
120
|
type: 'https-terminate-to-https',
|
|
146
121
|
target: partialConfig.target,
|
|
147
|
-
|
|
148
|
-
acme: { enabled: true, maintenance: true, ...(partialConfig.acme || {}) },
|
|
149
|
-
http: { enabled: true, redirectToHttps: true, ...(partialConfig.http || {}) },
|
|
150
|
-
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
151
|
-
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
122
|
+
...(partialConfig)
|
|
152
123
|
});
|
|
153
124
|
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated Use createHttpsPassthroughRoute instead
|
|
127
|
+
*/
|
|
154
128
|
export const httpsPassthrough = (
|
|
155
|
-
partialConfig: Partial<
|
|
156
|
-
):
|
|
129
|
+
partialConfig: Partial<IDeprecatedForwardConfig> & Pick<IDeprecatedForwardConfig, 'target'>
|
|
130
|
+
): IDeprecatedForwardConfig => ({
|
|
157
131
|
type: 'https-passthrough',
|
|
158
132
|
target: partialConfig.target,
|
|
159
|
-
|
|
160
|
-
...(partialConfig.security ? { security: partialConfig.security } : {}),
|
|
161
|
-
...(partialConfig.advanced ? { advanced: partialConfig.advanced } : {})
|
|
133
|
+
...(partialConfig)
|
|
162
134
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Forwarding configuration exports
|
|
3
|
+
*
|
|
4
|
+
* Note: The legacy domain-based configuration has been replaced by route-based configuration.
|
|
5
|
+
* See /ts/proxies/smart-proxy/models/route-types.ts for the new route-based configuration.
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
export * from './forwarding-types.js';
|
|
6
|
-
export * from '
|
|
7
|
-
export * from './domain-manager.js';
|
|
9
|
+
export * from '../../proxies/smart-proxy/utils/route-helpers.js';
|
|
@@ -104,13 +104,15 @@ export abstract class ForwardingHandler extends plugins.EventEmitter implements
|
|
|
104
104
|
|
|
105
105
|
// Apply custom headers with variable substitution
|
|
106
106
|
for (const [key, value] of Object.entries(customHeaders)) {
|
|
107
|
+
if (typeof value !== 'string') continue;
|
|
108
|
+
|
|
107
109
|
let processedValue = value;
|
|
108
|
-
|
|
110
|
+
|
|
109
111
|
// Replace variables in the header value
|
|
110
112
|
for (const [varName, varValue] of Object.entries(variables)) {
|
|
111
113
|
processedValue = processedValue.replace(`{${varName}}`, varValue);
|
|
112
114
|
}
|
|
113
|
-
|
|
115
|
+
|
|
114
116
|
result[key] = processedValue;
|
|
115
117
|
}
|
|
116
118
|
|
package/ts/forwarding/index.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
// Export types and configuration
|
|
7
7
|
export * from './config/forwarding-types.js';
|
|
8
|
-
export * from './config/domain-config.js';
|
|
9
|
-
export * from './config/domain-manager.js';
|
|
10
8
|
|
|
11
9
|
// Export handlers
|
|
12
10
|
export { ForwardingHandler } from './handlers/base-handler.js';
|
|
@@ -26,6 +24,9 @@ import {
|
|
|
26
24
|
httpsPassthrough
|
|
27
25
|
} from './config/forwarding-types.js';
|
|
28
26
|
|
|
27
|
+
// Export route-based helpers from smart-proxy
|
|
28
|
+
export * from '../proxies/smart-proxy/utils/route-helpers.js';
|
|
29
|
+
|
|
29
30
|
export const helpers = {
|
|
30
31
|
httpOnly,
|
|
31
32
|
tlsTerminateToHttp,
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type definitions for SmartAcme interfaces used by ChallengeResponder
|
|
3
3
|
* These reflect the actual SmartAcme API based on the documentation
|
|
4
|
+
*
|
|
5
|
+
* Also includes route-based interfaces for Port80Handler to extract domains
|
|
6
|
+
* that need certificate management from route configurations.
|
|
4
7
|
*/
|
|
5
8
|
import * as plugins from '../../plugins.js';
|
|
9
|
+
import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js';
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* Structure for SmartAcme certificate result
|
|
@@ -82,4 +86,84 @@ export interface ISmartAcme {
|
|
|
82
86
|
getCertificateForDomain(domain: string): Promise<ISmartAcmeCert>;
|
|
83
87
|
on?(event: string, listener: (data: any) => void): void;
|
|
84
88
|
eventEmitter?: plugins.EventEmitter;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Port80Handler route options
|
|
93
|
+
*/
|
|
94
|
+
export interface IPort80RouteOptions {
|
|
95
|
+
// The domain for the certificate
|
|
96
|
+
domain: string;
|
|
97
|
+
|
|
98
|
+
// Whether to redirect HTTP to HTTPS
|
|
99
|
+
sslRedirect: boolean;
|
|
100
|
+
|
|
101
|
+
// Whether to enable ACME certificate management
|
|
102
|
+
acmeMaintenance: boolean;
|
|
103
|
+
|
|
104
|
+
// Optional target for forwarding HTTP requests
|
|
105
|
+
forward?: {
|
|
106
|
+
ip: string;
|
|
107
|
+
port: number;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Optional target for forwarding ACME challenge requests
|
|
111
|
+
acmeForward?: {
|
|
112
|
+
ip: string;
|
|
113
|
+
port: number;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Reference to the route that requested this certificate
|
|
117
|
+
routeReference?: {
|
|
118
|
+
routeId?: string;
|
|
119
|
+
routeName?: string;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Extract domains that need certificate management from routes
|
|
125
|
+
* @param routes Route configurations to extract domains from
|
|
126
|
+
* @returns Array of Port80RouteOptions for each domain
|
|
127
|
+
*/
|
|
128
|
+
export function extractPort80RoutesFromRoutes(routes: IRouteConfig[]): IPort80RouteOptions[] {
|
|
129
|
+
const result: IPort80RouteOptions[] = [];
|
|
130
|
+
|
|
131
|
+
for (const route of routes) {
|
|
132
|
+
// Skip routes that don't have domains or TLS configuration
|
|
133
|
+
if (!route.match.domains || !route.action.tls) continue;
|
|
134
|
+
|
|
135
|
+
// Skip routes that don't terminate TLS
|
|
136
|
+
if (route.action.tls.mode !== 'terminate' && route.action.tls.mode !== 'terminate-and-reencrypt') continue;
|
|
137
|
+
|
|
138
|
+
// Only routes with automatic certificates need ACME
|
|
139
|
+
if (route.action.tls.certificate !== 'auto') continue;
|
|
140
|
+
|
|
141
|
+
// Get domains from route
|
|
142
|
+
const domains = Array.isArray(route.match.domains)
|
|
143
|
+
? route.match.domains
|
|
144
|
+
: [route.match.domains];
|
|
145
|
+
|
|
146
|
+
// Create Port80RouteOptions for each domain
|
|
147
|
+
for (const domain of domains) {
|
|
148
|
+
// Skip wildcards (we can't get certificates for them)
|
|
149
|
+
if (domain.includes('*')) continue;
|
|
150
|
+
|
|
151
|
+
// Create Port80RouteOptions
|
|
152
|
+
const options: IPort80RouteOptions = {
|
|
153
|
+
domain,
|
|
154
|
+
sslRedirect: true, // Default to true for HTTPS routes
|
|
155
|
+
acmeMaintenance: true, // Default to true for auto certificates
|
|
156
|
+
|
|
157
|
+
// Add route reference
|
|
158
|
+
routeReference: {
|
|
159
|
+
routeName: route.name
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Add domain to result
|
|
164
|
+
result.push(options);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return result;
|
|
85
169
|
}
|
|
@@ -2,12 +2,12 @@ import * as plugins from '../../plugins.js';
|
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
3
|
import { CertificateEvents } from '../../certificate/events/certificate-events.js';
|
|
4
4
|
import type {
|
|
5
|
-
|
|
6
|
-
IDomainOptions,
|
|
5
|
+
IDomainOptions, // Kept for backward compatibility
|
|
7
6
|
ICertificateData,
|
|
8
7
|
ICertificateFailure,
|
|
9
8
|
ICertificateExpiring,
|
|
10
|
-
IAcmeOptions
|
|
9
|
+
IAcmeOptions,
|
|
10
|
+
IRouteForwardConfig
|
|
11
11
|
} from '../../certificate/models/certificate-types.js';
|
|
12
12
|
import {
|
|
13
13
|
HttpEvents,
|
|
@@ -18,6 +18,9 @@ import {
|
|
|
18
18
|
} from '../models/http-types.js';
|
|
19
19
|
import type { IDomainCertificate } from '../models/http-types.js';
|
|
20
20
|
import { ChallengeResponder } from './challenge-responder.js';
|
|
21
|
+
import { extractPort80RoutesFromRoutes } from './acme-interfaces.js';
|
|
22
|
+
import type { IPort80RouteOptions } from './acme-interfaces.js';
|
|
23
|
+
import type { IRouteConfig } from '../../proxies/smart-proxy/models/route-types.js';
|
|
21
24
|
|
|
22
25
|
// Re-export for backward compatibility
|
|
23
26
|
export {
|
|
@@ -68,7 +71,7 @@ export class Port80Handler extends plugins.EventEmitter {
|
|
|
68
71
|
renewThresholdDays: options.renewThresholdDays ?? 30,
|
|
69
72
|
renewCheckIntervalHours: options.renewCheckIntervalHours ?? 24,
|
|
70
73
|
autoRenew: options.autoRenew ?? true,
|
|
71
|
-
|
|
74
|
+
routeForwards: options.routeForwards ?? []
|
|
72
75
|
};
|
|
73
76
|
|
|
74
77
|
// Initialize challenge responder
|
|
@@ -198,29 +201,33 @@ export class Port80Handler extends plugins.EventEmitter {
|
|
|
198
201
|
* Adds a domain with configuration options
|
|
199
202
|
* @param options Domain configuration options
|
|
200
203
|
*/
|
|
201
|
-
public addDomain(options: IDomainOptions): void {
|
|
202
|
-
|
|
204
|
+
public addDomain(options: IDomainOptions | IPort80RouteOptions): void {
|
|
205
|
+
// Normalize options format (handle both IDomainOptions and IPort80RouteOptions)
|
|
206
|
+
const normalizedOptions: IDomainOptions = this.normalizeOptions(options);
|
|
207
|
+
|
|
208
|
+
if (!normalizedOptions.domainName || typeof normalizedOptions.domainName !== 'string') {
|
|
203
209
|
throw new HttpError('Invalid domain name');
|
|
204
210
|
}
|
|
205
211
|
|
|
206
|
-
const domainName =
|
|
212
|
+
const domainName = normalizedOptions.domainName;
|
|
207
213
|
|
|
208
214
|
if (!this.domainCertificates.has(domainName)) {
|
|
209
215
|
this.domainCertificates.set(domainName, {
|
|
210
|
-
options,
|
|
216
|
+
options: normalizedOptions,
|
|
211
217
|
certObtained: false,
|
|
212
218
|
obtainingInProgress: false
|
|
213
219
|
});
|
|
214
220
|
|
|
215
221
|
console.log(`Domain added: ${domainName} with configuration:`, {
|
|
216
|
-
sslRedirect:
|
|
217
|
-
acmeMaintenance:
|
|
218
|
-
hasForward: !!
|
|
219
|
-
hasAcmeForward: !!
|
|
222
|
+
sslRedirect: normalizedOptions.sslRedirect,
|
|
223
|
+
acmeMaintenance: normalizedOptions.acmeMaintenance,
|
|
224
|
+
hasForward: !!normalizedOptions.forward,
|
|
225
|
+
hasAcmeForward: !!normalizedOptions.acmeForward,
|
|
226
|
+
routeReference: normalizedOptions.routeReference
|
|
220
227
|
});
|
|
221
228
|
|
|
222
229
|
// If acmeMaintenance is enabled and not a glob pattern, start certificate process immediately
|
|
223
|
-
if (
|
|
230
|
+
if (normalizedOptions.acmeMaintenance && this.server && !this.isGlobPattern(domainName)) {
|
|
224
231
|
this.obtainCertificate(domainName).catch(err => {
|
|
225
232
|
console.error(`Error obtaining initial certificate for ${domainName}:`, err);
|
|
226
233
|
});
|
|
@@ -228,11 +235,50 @@ export class Port80Handler extends plugins.EventEmitter {
|
|
|
228
235
|
} else {
|
|
229
236
|
// Update existing domain with new options
|
|
230
237
|
const existing = this.domainCertificates.get(domainName)!;
|
|
231
|
-
existing.options =
|
|
238
|
+
existing.options = normalizedOptions;
|
|
232
239
|
console.log(`Domain ${domainName} configuration updated`);
|
|
233
240
|
}
|
|
234
241
|
}
|
|
235
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Add domains from route configurations
|
|
245
|
+
* @param routes Array of route configurations
|
|
246
|
+
*/
|
|
247
|
+
public addDomainsFromRoutes(routes: IRouteConfig[]): void {
|
|
248
|
+
// Extract Port80RouteOptions from routes
|
|
249
|
+
const routeOptions = extractPort80RoutesFromRoutes(routes);
|
|
250
|
+
|
|
251
|
+
// Add each domain
|
|
252
|
+
for (const options of routeOptions) {
|
|
253
|
+
this.addDomain(options);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
console.log(`Added ${routeOptions.length} domains from routes for certificate management`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Normalize options from either IDomainOptions or IPort80RouteOptions
|
|
261
|
+
* @param options Options to normalize
|
|
262
|
+
* @returns Normalized IDomainOptions
|
|
263
|
+
* @private
|
|
264
|
+
*/
|
|
265
|
+
private normalizeOptions(options: IDomainOptions | IPort80RouteOptions): IDomainOptions {
|
|
266
|
+
// Handle IPort80RouteOptions format
|
|
267
|
+
if ('domain' in options) {
|
|
268
|
+
return {
|
|
269
|
+
domainName: options.domain,
|
|
270
|
+
sslRedirect: options.sslRedirect,
|
|
271
|
+
acmeMaintenance: options.acmeMaintenance,
|
|
272
|
+
forward: options.forward,
|
|
273
|
+
acmeForward: options.acmeForward,
|
|
274
|
+
routeReference: options.routeReference
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Already in IDomainOptions format
|
|
279
|
+
return options;
|
|
280
|
+
}
|
|
281
|
+
|
|
236
282
|
/**
|
|
237
283
|
* Removes a domain from management
|
|
238
284
|
* @param domain The domain to remove
|
|
@@ -459,7 +505,7 @@ export class Port80Handler extends plugins.EventEmitter {
|
|
|
459
505
|
private forwardRequest(
|
|
460
506
|
req: plugins.http.IncomingMessage,
|
|
461
507
|
res: plugins.http.ServerResponse,
|
|
462
|
-
target:
|
|
508
|
+
target: { ip: string; port: number },
|
|
463
509
|
requestType: string
|
|
464
510
|
): void {
|
|
465
511
|
const options = {
|
|
@@ -13,64 +13,17 @@ export type TSmartProxyCertProvisionObject = plugins.tsclass.network.ICert | 'ht
|
|
|
13
13
|
*/
|
|
14
14
|
export type IRoutedSmartProxyOptions = ISmartProxyOptions;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Legacy domain configuration interface for backward compatibility
|
|
18
|
-
*/
|
|
19
|
-
export interface IDomainConfig {
|
|
20
|
-
domains: string[];
|
|
21
|
-
forwarding: {
|
|
22
|
-
type: TForwardingType;
|
|
23
|
-
target: {
|
|
24
|
-
host: string | string[];
|
|
25
|
-
port: number;
|
|
26
|
-
};
|
|
27
|
-
acme?: {
|
|
28
|
-
enabled?: boolean;
|
|
29
|
-
maintenance?: boolean;
|
|
30
|
-
production?: boolean;
|
|
31
|
-
forwardChallenges?: {
|
|
32
|
-
host: string;
|
|
33
|
-
port: number;
|
|
34
|
-
useTls?: boolean;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
http?: {
|
|
38
|
-
enabled?: boolean;
|
|
39
|
-
redirectToHttps?: boolean;
|
|
40
|
-
headers?: Record<string, string>;
|
|
41
|
-
};
|
|
42
|
-
https?: {
|
|
43
|
-
customCert?: {
|
|
44
|
-
key: string;
|
|
45
|
-
cert: string;
|
|
46
|
-
};
|
|
47
|
-
forwardSni?: boolean;
|
|
48
|
-
};
|
|
49
|
-
security?: {
|
|
50
|
-
allowedIps?: string[];
|
|
51
|
-
blockedIps?: string[];
|
|
52
|
-
maxConnections?: number;
|
|
53
|
-
};
|
|
54
|
-
advanced?: {
|
|
55
|
-
portRanges?: Array<{ from: number; to: number }>;
|
|
56
|
-
networkProxyPort?: number;
|
|
57
|
-
keepAlive?: boolean;
|
|
58
|
-
timeout?: number;
|
|
59
|
-
headers?: Record<string, string>;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
16
|
/**
|
|
65
17
|
* Helper functions for type checking configuration types
|
|
66
18
|
*/
|
|
67
19
|
export function isLegacyOptions(options: any): boolean {
|
|
68
|
-
|
|
69
|
-
|
|
20
|
+
// Legacy options are no longer supported
|
|
21
|
+
return false;
|
|
70
22
|
}
|
|
71
23
|
|
|
72
24
|
export function isRoutedOptions(options: any): boolean {
|
|
73
|
-
|
|
25
|
+
// All configurations are now route-based
|
|
26
|
+
return true;
|
|
74
27
|
}
|
|
75
28
|
|
|
76
29
|
/**
|
|
@@ -80,14 +33,7 @@ export interface ISmartProxyOptions {
|
|
|
80
33
|
// The unified configuration array (required)
|
|
81
34
|
routes: IRouteConfig[];
|
|
82
35
|
|
|
83
|
-
//
|
|
84
|
-
fromPort?: number;
|
|
85
|
-
toPort?: number;
|
|
86
|
-
sniEnabled?: boolean;
|
|
87
|
-
domainConfigs?: IDomainConfig[];
|
|
88
|
-
targetIP?: string;
|
|
89
|
-
defaultAllowedIPs?: string[];
|
|
90
|
-
defaultBlockedIPs?: string[];
|
|
36
|
+
// Port range configuration
|
|
91
37
|
globalPortRanges?: Array<{ from: number; to: number }>;
|
|
92
38
|
forwardAllGlobalRanges?: boolean;
|
|
93
39
|
preserveSourceIP?: boolean;
|
|
@@ -99,8 +45,8 @@ export interface ISmartProxyOptions {
|
|
|
99
45
|
port: number; // Default port to use when not specified in routes
|
|
100
46
|
};
|
|
101
47
|
security?: {
|
|
102
|
-
|
|
103
|
-
|
|
48
|
+
allowedIps?: string[]; // Default allowed IPs
|
|
49
|
+
blockedIps?: string[]; // Default blocked IPs
|
|
104
50
|
maxConnections?: number; // Default max connections
|
|
105
51
|
};
|
|
106
52
|
preserveSourceIP?: boolean; // Default source IP preservation
|
|
@@ -184,9 +130,6 @@ export interface IConnectionRecord {
|
|
|
184
130
|
pendingData: Buffer[]; // Buffer to hold data during connection setup
|
|
185
131
|
pendingDataSize: number; // Track total size of pending data
|
|
186
132
|
|
|
187
|
-
// Legacy property for backward compatibility
|
|
188
|
-
domainConfig?: IDomainConfig;
|
|
189
|
-
|
|
190
133
|
// Enhanced tracking fields
|
|
191
134
|
bytesReceived: number; // Total bytes received
|
|
192
135
|
bytesSent: number; // Total bytes sent
|