pinggy 0.4.4 → 0.4.5
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/index.cjs +19 -14
- package/dist/index.js +1 -1
- package/dist/{main-PFPDXIRG.js → main-2RDHMQT7.js} +19 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3154,6 +3154,17 @@ var init_extendedOptions = __esm({
|
|
|
3154
3154
|
});
|
|
3155
3155
|
|
|
3156
3156
|
// src/cli/buildConfig.ts
|
|
3157
|
+
function removeIPv6Brackets(ip) {
|
|
3158
|
+
if (ip.startsWith("[") && ip.endsWith("]")) {
|
|
3159
|
+
return ip.slice(1, -1);
|
|
3160
|
+
}
|
|
3161
|
+
return ip;
|
|
3162
|
+
}
|
|
3163
|
+
function isValidServerAddress(host) {
|
|
3164
|
+
const normalized = removeIPv6Brackets(host.trim());
|
|
3165
|
+
if (!normalized) return false;
|
|
3166
|
+
return domainRegex.test(normalized) || (0, import_net2.isIP)(normalized) !== 0;
|
|
3167
|
+
}
|
|
3157
3168
|
function isKeyword(str) {
|
|
3158
3169
|
return KEYWORDS.has(str.toLowerCase());
|
|
3159
3170
|
}
|
|
@@ -3166,7 +3177,7 @@ function parseUserAndDomain(str) {
|
|
|
3166
3177
|
if (!str) return { token, type, server, qrCode, forceFlag };
|
|
3167
3178
|
if (str.includes("@")) {
|
|
3168
3179
|
const [user, domain] = str.split("@", 2);
|
|
3169
|
-
if (
|
|
3180
|
+
if (isValidServerAddress(domain)) {
|
|
3170
3181
|
let processKeyword2 = function(keyword) {
|
|
3171
3182
|
if ([import_pinggy4.TunnelType.Http, import_pinggy4.TunnelType.Tcp, import_pinggy4.TunnelType.Tls, import_pinggy4.TunnelType.Udp, import_pinggy4.TunnelType.TlsTcp].includes(keyword)) {
|
|
3172
3183
|
type = keyword;
|
|
@@ -3202,7 +3213,7 @@ function parseUserAndDomain(str) {
|
|
|
3202
3213
|
}
|
|
3203
3214
|
}
|
|
3204
3215
|
}
|
|
3205
|
-
} else if (
|
|
3216
|
+
} else if (isValidServerAddress(str)) {
|
|
3206
3217
|
server = str;
|
|
3207
3218
|
}
|
|
3208
3219
|
return { token, type, server, qrCode, forceFlag };
|
|
@@ -3273,12 +3284,6 @@ function parseLocalPort(finalConfig, values) {
|
|
|
3273
3284
|
}
|
|
3274
3285
|
return null;
|
|
3275
3286
|
}
|
|
3276
|
-
function removeIPv6Brackets(ip) {
|
|
3277
|
-
if (ip.startsWith("[") && ip.endsWith("]")) {
|
|
3278
|
-
return ip.slice(1, -1);
|
|
3279
|
-
}
|
|
3280
|
-
return ip;
|
|
3281
|
-
}
|
|
3282
3287
|
function isValidHostAddress(host) {
|
|
3283
3288
|
const normalized = removeIPv6Brackets(host.trim());
|
|
3284
3289
|
if (normalized.length === 0) return false;
|
|
@@ -3336,7 +3341,7 @@ function parseAdditionalForwarding(forwarding) {
|
|
|
3336
3341
|
}
|
|
3337
3342
|
const firstPart = parsed[0];
|
|
3338
3343
|
const [hostPart] = firstPart.split("@");
|
|
3339
|
-
let protocol =
|
|
3344
|
+
let protocol = import_pinggy4.TunnelType.Http;
|
|
3340
3345
|
let remoteDomainRaw;
|
|
3341
3346
|
let remotePort = 0;
|
|
3342
3347
|
if (hostPart.includes("//")) {
|
|
@@ -3350,7 +3355,7 @@ function parseAdditionalForwarding(forwarding) {
|
|
|
3350
3355
|
return new Error("invalid forwarding address format");
|
|
3351
3356
|
}
|
|
3352
3357
|
remoteDomainRaw = domainAndPort[0];
|
|
3353
|
-
if (!remoteDomainRaw || !
|
|
3358
|
+
if (!remoteDomainRaw || !isValidServerAddress(remoteDomainRaw)) {
|
|
3354
3359
|
return new Error("invalid remote domain");
|
|
3355
3360
|
}
|
|
3356
3361
|
const parsedRemotePort = toPort(domainAndPort[1]);
|
|
@@ -3366,10 +3371,10 @@ function parseAdditionalForwarding(forwarding) {
|
|
|
3366
3371
|
}
|
|
3367
3372
|
} else {
|
|
3368
3373
|
remoteDomainRaw = hostPart;
|
|
3369
|
-
if (!
|
|
3374
|
+
if (!isValidServerAddress(remoteDomainRaw)) {
|
|
3370
3375
|
return new Error("invalid remote domain");
|
|
3371
3376
|
}
|
|
3372
|
-
protocol =
|
|
3377
|
+
protocol = import_pinggy4.TunnelType.Http;
|
|
3373
3378
|
remotePort = 0;
|
|
3374
3379
|
}
|
|
3375
3380
|
const localDomain = removeIPv6Brackets(parsed[2] || "localhost");
|
|
@@ -3539,7 +3544,7 @@ async function buildFinalConfig(values, positionals) {
|
|
|
3539
3544
|
// Apply loaded config on top of defaults
|
|
3540
3545
|
configId: getRandomId(),
|
|
3541
3546
|
token: token || (configFromFile?.token || (typeof values.token === "string" ? values.token : "")),
|
|
3542
|
-
serverAddress: server
|
|
3547
|
+
serverAddress: server ? removeIPv6Brackets(server) : configFromFile?.serverAddress || defaultOptions.serverAddress,
|
|
3543
3548
|
isQRCode: qrCode || (configFromFile?.isQRCode || false),
|
|
3544
3549
|
autoReconnect: configFromFile?.autoReconnect ? configFromFile.autoReconnect : defaultOptions.autoReconnect,
|
|
3545
3550
|
optional: {
|
|
@@ -3589,7 +3594,7 @@ var init_buildConfig = __esm({
|
|
|
3589
3594
|
"force",
|
|
3590
3595
|
"qr"
|
|
3591
3596
|
]);
|
|
3592
|
-
VALID_PROTOCOLS = [
|
|
3597
|
+
VALID_PROTOCOLS = [import_pinggy4.TunnelType.Http, import_pinggy4.TunnelType.Tcp, import_pinggy4.TunnelType.Udp, import_pinggy4.TunnelType.Tls, import_pinggy4.TunnelType.TlsTcp];
|
|
3593
3598
|
}
|
|
3594
3599
|
});
|
|
3595
3600
|
|
package/dist/index.js
CHANGED
|
@@ -256,6 +256,17 @@ import fs from "fs";
|
|
|
256
256
|
import path from "path";
|
|
257
257
|
import { isIP as isIP2 } from "net";
|
|
258
258
|
var domainRegex = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
|
|
259
|
+
function removeIPv6Brackets(ip) {
|
|
260
|
+
if (ip.startsWith("[") && ip.endsWith("]")) {
|
|
261
|
+
return ip.slice(1, -1);
|
|
262
|
+
}
|
|
263
|
+
return ip;
|
|
264
|
+
}
|
|
265
|
+
function isValidServerAddress(host) {
|
|
266
|
+
const normalized = removeIPv6Brackets(host.trim());
|
|
267
|
+
if (!normalized) return false;
|
|
268
|
+
return domainRegex.test(normalized) || isIP2(normalized) !== 0;
|
|
269
|
+
}
|
|
259
270
|
var KEYWORDS = /* @__PURE__ */ new Set([
|
|
260
271
|
TunnelType.Http,
|
|
261
272
|
TunnelType.Tcp,
|
|
@@ -277,7 +288,7 @@ function parseUserAndDomain(str) {
|
|
|
277
288
|
if (!str) return { token, type, server, qrCode, forceFlag };
|
|
278
289
|
if (str.includes("@")) {
|
|
279
290
|
const [user, domain] = str.split("@", 2);
|
|
280
|
-
if (
|
|
291
|
+
if (isValidServerAddress(domain)) {
|
|
281
292
|
let processKeyword2 = function(keyword) {
|
|
282
293
|
if ([TunnelType.Http, TunnelType.Tcp, TunnelType.Tls, TunnelType.Udp, TunnelType.TlsTcp].includes(keyword)) {
|
|
283
294
|
type = keyword;
|
|
@@ -313,7 +324,7 @@ function parseUserAndDomain(str) {
|
|
|
313
324
|
}
|
|
314
325
|
}
|
|
315
326
|
}
|
|
316
|
-
} else if (
|
|
327
|
+
} else if (isValidServerAddress(str)) {
|
|
317
328
|
server = str;
|
|
318
329
|
}
|
|
319
330
|
return { token, type, server, qrCode, forceFlag };
|
|
@@ -384,12 +395,6 @@ function parseLocalPort(finalConfig, values) {
|
|
|
384
395
|
}
|
|
385
396
|
return null;
|
|
386
397
|
}
|
|
387
|
-
function removeIPv6Brackets(ip) {
|
|
388
|
-
if (ip.startsWith("[") && ip.endsWith("]")) {
|
|
389
|
-
return ip.slice(1, -1);
|
|
390
|
-
}
|
|
391
|
-
return ip;
|
|
392
|
-
}
|
|
393
398
|
function isValidHostAddress(host) {
|
|
394
399
|
const normalized = removeIPv6Brackets(host.trim());
|
|
395
400
|
if (normalized.length === 0) return false;
|
|
@@ -416,7 +421,7 @@ function ipv6SafeSplitColon(s) {
|
|
|
416
421
|
result.push(buf);
|
|
417
422
|
return result;
|
|
418
423
|
}
|
|
419
|
-
var VALID_PROTOCOLS = [
|
|
424
|
+
var VALID_PROTOCOLS = [TunnelType.Http, TunnelType.Tcp, TunnelType.Udp, TunnelType.Tls, TunnelType.TlsTcp];
|
|
420
425
|
function parseDefaultForwarding(forwarding) {
|
|
421
426
|
const parts = ipv6SafeSplitColon(forwarding);
|
|
422
427
|
if (parts.length === 3) {
|
|
@@ -448,7 +453,7 @@ function parseAdditionalForwarding(forwarding) {
|
|
|
448
453
|
}
|
|
449
454
|
const firstPart = parsed[0];
|
|
450
455
|
const [hostPart] = firstPart.split("@");
|
|
451
|
-
let protocol =
|
|
456
|
+
let protocol = TunnelType.Http;
|
|
452
457
|
let remoteDomainRaw;
|
|
453
458
|
let remotePort = 0;
|
|
454
459
|
if (hostPart.includes("//")) {
|
|
@@ -462,7 +467,7 @@ function parseAdditionalForwarding(forwarding) {
|
|
|
462
467
|
return new Error("invalid forwarding address format");
|
|
463
468
|
}
|
|
464
469
|
remoteDomainRaw = domainAndPort[0];
|
|
465
|
-
if (!remoteDomainRaw || !
|
|
470
|
+
if (!remoteDomainRaw || !isValidServerAddress(remoteDomainRaw)) {
|
|
466
471
|
return new Error("invalid remote domain");
|
|
467
472
|
}
|
|
468
473
|
const parsedRemotePort = toPort(domainAndPort[1]);
|
|
@@ -478,10 +483,10 @@ function parseAdditionalForwarding(forwarding) {
|
|
|
478
483
|
}
|
|
479
484
|
} else {
|
|
480
485
|
remoteDomainRaw = hostPart;
|
|
481
|
-
if (!
|
|
486
|
+
if (!isValidServerAddress(remoteDomainRaw)) {
|
|
482
487
|
return new Error("invalid remote domain");
|
|
483
488
|
}
|
|
484
|
-
protocol =
|
|
489
|
+
protocol = TunnelType.Http;
|
|
485
490
|
remotePort = 0;
|
|
486
491
|
}
|
|
487
492
|
const localDomain = removeIPv6Brackets(parsed[2] || "localhost");
|
|
@@ -651,7 +656,7 @@ async function buildFinalConfig(values, positionals) {
|
|
|
651
656
|
// Apply loaded config on top of defaults
|
|
652
657
|
configId: getRandomId(),
|
|
653
658
|
token: token || (configFromFile?.token || (typeof values.token === "string" ? values.token : "")),
|
|
654
|
-
serverAddress: server
|
|
659
|
+
serverAddress: server ? removeIPv6Brackets(server) : configFromFile?.serverAddress || defaultOptions.serverAddress,
|
|
655
660
|
isQRCode: qrCode || (configFromFile?.isQRCode || false),
|
|
656
661
|
autoReconnect: configFromFile?.autoReconnect ? configFromFile.autoReconnect : defaultOptions.autoReconnect,
|
|
657
662
|
optional: {
|