@push.rocks/smartproxy 4.2.4 → 4.3.0
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/classes.networkproxy.d.ts +6 -6
- package/dist_ts/classes.networkproxy.js +56 -39
- package/dist_ts/classes.port80handler.d.ts +109 -13
- package/dist_ts/classes.port80handler.js +399 -118
- package/package.json +1 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.networkproxy.ts +59 -38
- package/ts/classes.port80handler.ts +497 -125
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartproxy",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartproxy',
|
|
6
|
-
version: '4.
|
|
6
|
+
version: '4.3.0',
|
|
7
7
|
description: 'A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, dynamic routing with authentication options, and automatic ACME certificate management.'
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
2
|
import { ProxyRouter } from './classes.router.js';
|
|
3
|
-
import {
|
|
3
|
+
import { Port80Handler, Port80HandlerEvents, type IDomainOptions } from './classes.port80handler.js';
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { fileURLToPath } from 'url';
|
|
@@ -72,8 +72,8 @@ export class NetworkProxy {
|
|
|
72
72
|
private defaultCertificates: { key: string; cert: string };
|
|
73
73
|
private certificateCache: Map<string, { key: string; cert: string; expires?: Date }> = new Map();
|
|
74
74
|
|
|
75
|
-
//
|
|
76
|
-
private
|
|
75
|
+
// Port80Handler for certificate management
|
|
76
|
+
private port80Handler: Port80Handler | null = null;
|
|
77
77
|
private certificateStoreDir: string;
|
|
78
78
|
|
|
79
79
|
// New connection pool for backend connections
|
|
@@ -375,16 +375,16 @@ export class NetworkProxy {
|
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
/**
|
|
378
|
-
* Initializes the
|
|
378
|
+
* Initializes the Port80Handler for ACME certificate management
|
|
379
379
|
* @private
|
|
380
380
|
*/
|
|
381
|
-
private async
|
|
381
|
+
private async initializePort80Handler(): Promise<void> {
|
|
382
382
|
if (!this.options.acme.enabled) {
|
|
383
383
|
return;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
// Create certificate manager
|
|
387
|
-
this.
|
|
387
|
+
this.port80Handler = new Port80Handler({
|
|
388
388
|
port: this.options.acme.port,
|
|
389
389
|
contactEmail: this.options.acme.contactEmail,
|
|
390
390
|
useProduction: this.options.acme.useProduction,
|
|
@@ -394,32 +394,32 @@ export class NetworkProxy {
|
|
|
394
394
|
});
|
|
395
395
|
|
|
396
396
|
// Register event handlers
|
|
397
|
-
this.
|
|
398
|
-
this.
|
|
399
|
-
this.
|
|
400
|
-
this.
|
|
397
|
+
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_ISSUED, this.handleCertificateIssued.bind(this));
|
|
398
|
+
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_RENEWED, this.handleCertificateIssued.bind(this));
|
|
399
|
+
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_FAILED, this.handleCertificateFailed.bind(this));
|
|
400
|
+
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_EXPIRING, (data) => {
|
|
401
401
|
this.log('info', `Certificate for ${data.domain} expires in ${data.daysRemaining} days`);
|
|
402
402
|
});
|
|
403
403
|
|
|
404
|
-
// Start the
|
|
404
|
+
// Start the handler
|
|
405
405
|
try {
|
|
406
|
-
await this.
|
|
407
|
-
this.log('info', `
|
|
406
|
+
await this.port80Handler.start();
|
|
407
|
+
this.log('info', `Port80Handler started on port ${this.options.acme.port}`);
|
|
408
408
|
|
|
409
409
|
// Add domains from proxy configs
|
|
410
|
-
this.
|
|
410
|
+
this.registerDomainsWithPort80Handler();
|
|
411
411
|
} catch (error) {
|
|
412
|
-
this.log('error', `Failed to start
|
|
413
|
-
this.
|
|
412
|
+
this.log('error', `Failed to start Port80Handler: ${error}`);
|
|
413
|
+
this.port80Handler = null;
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
/**
|
|
418
|
-
* Registers domains from proxy configs with the
|
|
418
|
+
* Registers domains from proxy configs with the Port80Handler
|
|
419
419
|
* @private
|
|
420
420
|
*/
|
|
421
|
-
private
|
|
422
|
-
if (!this.
|
|
421
|
+
private registerDomainsWithPort80Handler(): void {
|
|
422
|
+
if (!this.port80Handler) return;
|
|
423
423
|
|
|
424
424
|
// Get all hostnames from proxy configs
|
|
425
425
|
this.proxyConfigs.forEach(config => {
|
|
@@ -461,26 +461,32 @@ export class NetworkProxy {
|
|
|
461
461
|
this.log('warn', `Failed to extract expiry date from certificate for ${hostname}`);
|
|
462
462
|
}
|
|
463
463
|
|
|
464
|
-
// Update the certificate in the
|
|
465
|
-
this.
|
|
464
|
+
// Update the certificate in the handler
|
|
465
|
+
this.port80Handler.setCertificate(hostname, cert, key, expiryDate);
|
|
466
466
|
|
|
467
467
|
// Also update our own certificate cache
|
|
468
468
|
this.updateCertificateCache(hostname, cert, key, expiryDate);
|
|
469
469
|
|
|
470
470
|
this.log('info', `Loaded existing certificate for ${hostname}`);
|
|
471
471
|
} else {
|
|
472
|
-
// Register the domain for certificate issuance
|
|
473
|
-
|
|
472
|
+
// Register the domain for certificate issuance with new domain options format
|
|
473
|
+
const domainOptions: IDomainOptions = {
|
|
474
|
+
domainName: hostname,
|
|
475
|
+
sslRedirect: true,
|
|
476
|
+
acmeMaintenance: true
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
this.port80Handler.addDomain(domainOptions);
|
|
474
480
|
this.log('info', `Registered domain for ACME certificate issuance: ${hostname}`);
|
|
475
481
|
}
|
|
476
482
|
} catch (error) {
|
|
477
|
-
this.log('error', `Error registering domain ${hostname} with
|
|
483
|
+
this.log('error', `Error registering domain ${hostname} with Port80Handler: ${error}`);
|
|
478
484
|
}
|
|
479
485
|
});
|
|
480
486
|
}
|
|
481
487
|
|
|
482
488
|
/**
|
|
483
|
-
* Handles newly issued or renewed certificates from
|
|
489
|
+
* Handles newly issued or renewed certificates from Port80Handler
|
|
484
490
|
* @private
|
|
485
491
|
*/
|
|
486
492
|
private handleCertificateIssued(data: { domain: string; certificate: string; privateKey: string; expiryDate: Date }): void {
|
|
@@ -556,13 +562,21 @@ export class NetworkProxy {
|
|
|
556
562
|
}
|
|
557
563
|
|
|
558
564
|
// Check if we should trigger certificate issuance
|
|
559
|
-
if (this.options.acme?.enabled && this.
|
|
565
|
+
if (this.options.acme?.enabled && this.port80Handler && !domain.includes('*')) {
|
|
560
566
|
// Check if this domain is already registered
|
|
561
|
-
const certData = this.
|
|
567
|
+
const certData = this.port80Handler.getCertificate(domain);
|
|
562
568
|
|
|
563
569
|
if (!certData) {
|
|
564
570
|
this.log('info', `No certificate found for ${domain}, registering for issuance`);
|
|
565
|
-
|
|
571
|
+
|
|
572
|
+
// Register with new domain options format
|
|
573
|
+
const domainOptions: IDomainOptions = {
|
|
574
|
+
domainName: domain,
|
|
575
|
+
sslRedirect: true,
|
|
576
|
+
acmeMaintenance: true
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
this.port80Handler.addDomain(domainOptions);
|
|
566
580
|
}
|
|
567
581
|
}
|
|
568
582
|
|
|
@@ -587,9 +601,9 @@ export class NetworkProxy {
|
|
|
587
601
|
public async start(): Promise<void> {
|
|
588
602
|
this.startTime = Date.now();
|
|
589
603
|
|
|
590
|
-
// Initialize
|
|
604
|
+
// Initialize Port80Handler if enabled
|
|
591
605
|
if (this.options.acme.enabled) {
|
|
592
|
-
await this.
|
|
606
|
+
await this.initializePort80Handler();
|
|
593
607
|
}
|
|
594
608
|
|
|
595
609
|
// Create the HTTPS server
|
|
@@ -1588,13 +1602,13 @@ export class NetworkProxy {
|
|
|
1588
1602
|
}
|
|
1589
1603
|
this.connectionPool.clear();
|
|
1590
1604
|
|
|
1591
|
-
// Stop
|
|
1592
|
-
if (this.
|
|
1605
|
+
// Stop Port80Handler if it's running
|
|
1606
|
+
if (this.port80Handler) {
|
|
1593
1607
|
try {
|
|
1594
|
-
await this.
|
|
1595
|
-
this.log('info', '
|
|
1608
|
+
await this.port80Handler.stop();
|
|
1609
|
+
this.log('info', 'Port80Handler stopped');
|
|
1596
1610
|
} catch (error) {
|
|
1597
|
-
this.log('error', 'Error stopping
|
|
1611
|
+
this.log('error', 'Error stopping Port80Handler', error);
|
|
1598
1612
|
}
|
|
1599
1613
|
}
|
|
1600
1614
|
|
|
@@ -1619,8 +1633,8 @@ export class NetworkProxy {
|
|
|
1619
1633
|
return false;
|
|
1620
1634
|
}
|
|
1621
1635
|
|
|
1622
|
-
if (!this.
|
|
1623
|
-
this.log('error', '
|
|
1636
|
+
if (!this.port80Handler) {
|
|
1637
|
+
this.log('error', 'Port80Handler is not initialized');
|
|
1624
1638
|
return false;
|
|
1625
1639
|
}
|
|
1626
1640
|
|
|
@@ -1631,7 +1645,14 @@ export class NetworkProxy {
|
|
|
1631
1645
|
}
|
|
1632
1646
|
|
|
1633
1647
|
try {
|
|
1634
|
-
|
|
1648
|
+
// Use the new domain options format
|
|
1649
|
+
const domainOptions: IDomainOptions = {
|
|
1650
|
+
domainName: domain,
|
|
1651
|
+
sslRedirect: true,
|
|
1652
|
+
acmeMaintenance: true
|
|
1653
|
+
};
|
|
1654
|
+
|
|
1655
|
+
this.port80Handler.addDomain(domainOptions);
|
|
1635
1656
|
this.log('info', `Certificate request submitted for domain: ${domain}`);
|
|
1636
1657
|
return true;
|
|
1637
1658
|
} catch (error) {
|