lula2 0.0.7 → 0.0.9
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/README.md +45 -28
- package/dist/_app/immutable/assets/0.C97xfQzG.css +1 -0
- package/dist/_app/immutable/chunks/BJF-sFqz.js +2 -0
- package/dist/_app/immutable/chunks/{7x_q-1ab.js → BYKwBiub.js} +1 -1
- package/dist/_app/immutable/chunks/{CMWPLh7h.js → Bg93OsgA.js} +1 -1
- package/dist/_app/immutable/chunks/Bh_lsY1c.js +3 -0
- package/dist/_app/immutable/chunks/{BR-0Dorr.js → BqNBD7oY.js} +1 -1
- package/dist/_app/immutable/chunks/{D3aNP_lg.js → Bty54Wy4.js} +1 -1
- package/dist/_app/immutable/chunks/{B19gt6-g.js → CBYXl-8c.js} +1 -1
- package/dist/_app/immutable/chunks/{D4Q_ObIy.js → DUz6FRLu.js} +1 -1
- package/dist/_app/immutable/chunks/{B8y4N5iB.js → Ds9w7fzN.js} +1 -1
- package/dist/_app/immutable/entry/{app.gXI-RXWG.js → app.BycSt6Ly.js} +2 -2
- package/dist/_app/immutable/entry/start.CStyDRI8.js +1 -0
- package/dist/_app/immutable/nodes/{0.CSH0JcZp.js → 0.liUzuc-A.js} +1 -1
- package/dist/_app/immutable/nodes/{1.B2ee3OXU.js → 1.t1GUCrrv.js} +1 -1
- package/dist/_app/immutable/nodes/{2.D-sdW8nU.js → 2.CTVpMB9b.js} +1 -1
- package/dist/_app/immutable/nodes/{3.DpuBpKOB.js → 3.DnzjoQZ0.js} +1 -1
- package/dist/_app/immutable/nodes/{4.OaCXaSqf.js → 4.Dvs__DIQ.js} +1 -1
- package/dist/_app/version.json +1 -1
- package/dist/cli/commands/ui.js +2421 -4
- package/dist/cli/commands/version.js +4 -1
- package/dist/cli/server/index.js +2421 -4
- package/dist/cli/server/server.js +2421 -4
- package/dist/index.html +10 -10
- package/dist/index.js +2427 -7
- package/package.json +12 -11
- package/dist/_app/immutable/assets/0.DtiRW3lO.css +0 -1
- package/dist/_app/immutable/chunks/B_3ksxz5.js +0 -2
- package/dist/_app/immutable/chunks/DQAUO7J_.js +0 -3
- package/dist/_app/immutable/entry/start.B_FNOkXN.js +0 -1
package/dist/cli/commands/ui.js
CHANGED
|
@@ -1,12 +1,1565 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
7
|
var __esm = (fn, res) => function __init() {
|
|
4
8
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
9
|
};
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
6
13
|
var __export = (target, all) => {
|
|
7
14
|
for (var name in all)
|
|
8
15
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
16
|
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/common.js
|
|
35
|
+
var require_common = __commonJS({
|
|
36
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/common.js"(exports) {
|
|
37
|
+
"use strict";
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.isInSubnet = isInSubnet;
|
|
40
|
+
exports.isCorrect = isCorrect;
|
|
41
|
+
exports.numberToPaddedHex = numberToPaddedHex;
|
|
42
|
+
exports.stringToPaddedHex = stringToPaddedHex;
|
|
43
|
+
exports.testBit = testBit;
|
|
44
|
+
function isInSubnet(address) {
|
|
45
|
+
if (this.subnetMask < address.subnetMask) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (this.mask(address.subnetMask) === address.mask()) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
function isCorrect(defaultBits) {
|
|
54
|
+
return function() {
|
|
55
|
+
if (this.addressMinusSuffix !== this.correctForm()) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (this.subnetMask === defaultBits && !this.parsedSubnet) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return this.parsedSubnet === String(this.subnetMask);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function numberToPaddedHex(number) {
|
|
65
|
+
return number.toString(16).padStart(2, "0");
|
|
66
|
+
}
|
|
67
|
+
function stringToPaddedHex(numberString) {
|
|
68
|
+
return numberToPaddedHex(parseInt(numberString, 10));
|
|
69
|
+
}
|
|
70
|
+
function testBit(binaryValue, position) {
|
|
71
|
+
const { length } = binaryValue;
|
|
72
|
+
if (position > length) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
const positionInString = length - position;
|
|
76
|
+
return binaryValue.substring(positionInString, positionInString + 1) === "1";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v4/constants.js
|
|
82
|
+
var require_constants = __commonJS({
|
|
83
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v4/constants.js"(exports) {
|
|
84
|
+
"use strict";
|
|
85
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
+
exports.RE_SUBNET_STRING = exports.RE_ADDRESS = exports.GROUPS = exports.BITS = void 0;
|
|
87
|
+
exports.BITS = 32;
|
|
88
|
+
exports.GROUPS = 4;
|
|
89
|
+
exports.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g;
|
|
90
|
+
exports.RE_SUBNET_STRING = /\/\d{1,2}$/;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/address-error.js
|
|
95
|
+
var require_address_error = __commonJS({
|
|
96
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/address-error.js"(exports) {
|
|
97
|
+
"use strict";
|
|
98
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
99
|
+
exports.AddressError = void 0;
|
|
100
|
+
var AddressError = class extends Error {
|
|
101
|
+
constructor(message, parseMessage) {
|
|
102
|
+
super(message);
|
|
103
|
+
this.name = "AddressError";
|
|
104
|
+
this.parseMessage = parseMessage;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.AddressError = AddressError;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/ipv4.js
|
|
112
|
+
var require_ipv4 = __commonJS({
|
|
113
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/ipv4.js"(exports) {
|
|
114
|
+
"use strict";
|
|
115
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
116
|
+
if (k2 === void 0) k2 = k;
|
|
117
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
118
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
119
|
+
desc = { enumerable: true, get: function() {
|
|
120
|
+
return m[k];
|
|
121
|
+
} };
|
|
122
|
+
}
|
|
123
|
+
Object.defineProperty(o, k2, desc);
|
|
124
|
+
}) : (function(o, m, k, k2) {
|
|
125
|
+
if (k2 === void 0) k2 = k;
|
|
126
|
+
o[k2] = m[k];
|
|
127
|
+
}));
|
|
128
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
129
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
130
|
+
}) : function(o, v) {
|
|
131
|
+
o["default"] = v;
|
|
132
|
+
});
|
|
133
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
134
|
+
if (mod && mod.__esModule) return mod;
|
|
135
|
+
var result = {};
|
|
136
|
+
if (mod != null) {
|
|
137
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
138
|
+
}
|
|
139
|
+
__setModuleDefault(result, mod);
|
|
140
|
+
return result;
|
|
141
|
+
};
|
|
142
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
143
|
+
exports.Address4 = void 0;
|
|
144
|
+
var common = __importStar(require_common());
|
|
145
|
+
var constants = __importStar(require_constants());
|
|
146
|
+
var address_error_1 = require_address_error();
|
|
147
|
+
var Address4 = class _Address4 {
|
|
148
|
+
constructor(address) {
|
|
149
|
+
this.groups = constants.GROUPS;
|
|
150
|
+
this.parsedAddress = [];
|
|
151
|
+
this.parsedSubnet = "";
|
|
152
|
+
this.subnet = "/32";
|
|
153
|
+
this.subnetMask = 32;
|
|
154
|
+
this.v4 = true;
|
|
155
|
+
this.isCorrect = common.isCorrect(constants.BITS);
|
|
156
|
+
this.isInSubnet = common.isInSubnet;
|
|
157
|
+
this.address = address;
|
|
158
|
+
const subnet = constants.RE_SUBNET_STRING.exec(address);
|
|
159
|
+
if (subnet) {
|
|
160
|
+
this.parsedSubnet = subnet[0].replace("/", "");
|
|
161
|
+
this.subnetMask = parseInt(this.parsedSubnet, 10);
|
|
162
|
+
this.subnet = `/${this.subnetMask}`;
|
|
163
|
+
if (this.subnetMask < 0 || this.subnetMask > constants.BITS) {
|
|
164
|
+
throw new address_error_1.AddressError("Invalid subnet mask.");
|
|
165
|
+
}
|
|
166
|
+
address = address.replace(constants.RE_SUBNET_STRING, "");
|
|
167
|
+
}
|
|
168
|
+
this.addressMinusSuffix = address;
|
|
169
|
+
this.parsedAddress = this.parse(address);
|
|
170
|
+
}
|
|
171
|
+
static isValid(address) {
|
|
172
|
+
try {
|
|
173
|
+
new _Address4(address);
|
|
174
|
+
return true;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/*
|
|
180
|
+
* Parses a v4 address
|
|
181
|
+
*/
|
|
182
|
+
parse(address) {
|
|
183
|
+
const groups = address.split(".");
|
|
184
|
+
if (!address.match(constants.RE_ADDRESS)) {
|
|
185
|
+
throw new address_error_1.AddressError("Invalid IPv4 address.");
|
|
186
|
+
}
|
|
187
|
+
return groups;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Returns the correct form of an address
|
|
191
|
+
* @memberof Address4
|
|
192
|
+
* @instance
|
|
193
|
+
* @returns {String}
|
|
194
|
+
*/
|
|
195
|
+
correctForm() {
|
|
196
|
+
return this.parsedAddress.map((part) => parseInt(part, 10)).join(".");
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Converts a hex string to an IPv4 address object
|
|
200
|
+
* @memberof Address4
|
|
201
|
+
* @static
|
|
202
|
+
* @param {string} hex - a hex string to convert
|
|
203
|
+
* @returns {Address4}
|
|
204
|
+
*/
|
|
205
|
+
static fromHex(hex) {
|
|
206
|
+
const padded = hex.replace(/:/g, "").padStart(8, "0");
|
|
207
|
+
const groups = [];
|
|
208
|
+
let i;
|
|
209
|
+
for (i = 0; i < 8; i += 2) {
|
|
210
|
+
const h = padded.slice(i, i + 2);
|
|
211
|
+
groups.push(parseInt(h, 16));
|
|
212
|
+
}
|
|
213
|
+
return new _Address4(groups.join("."));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Converts an integer into a IPv4 address object
|
|
217
|
+
* @memberof Address4
|
|
218
|
+
* @static
|
|
219
|
+
* @param {integer} integer - a number to convert
|
|
220
|
+
* @returns {Address4}
|
|
221
|
+
*/
|
|
222
|
+
static fromInteger(integer) {
|
|
223
|
+
return _Address4.fromHex(integer.toString(16));
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Return an address from in-addr.arpa form
|
|
227
|
+
* @memberof Address4
|
|
228
|
+
* @static
|
|
229
|
+
* @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address
|
|
230
|
+
* @returns {Adress4}
|
|
231
|
+
* @example
|
|
232
|
+
* var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.)
|
|
233
|
+
* address.correctForm(); // '192.0.2.42'
|
|
234
|
+
*/
|
|
235
|
+
static fromArpa(arpaFormAddress) {
|
|
236
|
+
const leader = arpaFormAddress.replace(/(\.in-addr\.arpa)?\.$/, "");
|
|
237
|
+
const address = leader.split(".").reverse().join(".");
|
|
238
|
+
return new _Address4(address);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Converts an IPv4 address object to a hex string
|
|
242
|
+
* @memberof Address4
|
|
243
|
+
* @instance
|
|
244
|
+
* @returns {String}
|
|
245
|
+
*/
|
|
246
|
+
toHex() {
|
|
247
|
+
return this.parsedAddress.map((part) => common.stringToPaddedHex(part)).join(":");
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Converts an IPv4 address object to an array of bytes
|
|
251
|
+
* @memberof Address4
|
|
252
|
+
* @instance
|
|
253
|
+
* @returns {Array}
|
|
254
|
+
*/
|
|
255
|
+
toArray() {
|
|
256
|
+
return this.parsedAddress.map((part) => parseInt(part, 10));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Converts an IPv4 address object to an IPv6 address group
|
|
260
|
+
* @memberof Address4
|
|
261
|
+
* @instance
|
|
262
|
+
* @returns {String}
|
|
263
|
+
*/
|
|
264
|
+
toGroup6() {
|
|
265
|
+
const output = [];
|
|
266
|
+
let i;
|
|
267
|
+
for (i = 0; i < constants.GROUPS; i += 2) {
|
|
268
|
+
output.push(`${common.stringToPaddedHex(this.parsedAddress[i])}${common.stringToPaddedHex(this.parsedAddress[i + 1])}`);
|
|
269
|
+
}
|
|
270
|
+
return output.join(":");
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns the address as a `bigint`
|
|
274
|
+
* @memberof Address4
|
|
275
|
+
* @instance
|
|
276
|
+
* @returns {bigint}
|
|
277
|
+
*/
|
|
278
|
+
bigInt() {
|
|
279
|
+
return BigInt(`0x${this.parsedAddress.map((n) => common.stringToPaddedHex(n)).join("")}`);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Helper function getting start address.
|
|
283
|
+
* @memberof Address4
|
|
284
|
+
* @instance
|
|
285
|
+
* @returns {bigint}
|
|
286
|
+
*/
|
|
287
|
+
_startAddress() {
|
|
288
|
+
return BigInt(`0b${this.mask() + "0".repeat(constants.BITS - this.subnetMask)}`);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The first address in the range given by this address' subnet.
|
|
292
|
+
* Often referred to as the Network Address.
|
|
293
|
+
* @memberof Address4
|
|
294
|
+
* @instance
|
|
295
|
+
* @returns {Address4}
|
|
296
|
+
*/
|
|
297
|
+
startAddress() {
|
|
298
|
+
return _Address4.fromBigInt(this._startAddress());
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* The first host address in the range given by this address's subnet ie
|
|
302
|
+
* the first address after the Network Address
|
|
303
|
+
* @memberof Address4
|
|
304
|
+
* @instance
|
|
305
|
+
* @returns {Address4}
|
|
306
|
+
*/
|
|
307
|
+
startAddressExclusive() {
|
|
308
|
+
const adjust = BigInt("1");
|
|
309
|
+
return _Address4.fromBigInt(this._startAddress() + adjust);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Helper function getting end address.
|
|
313
|
+
* @memberof Address4
|
|
314
|
+
* @instance
|
|
315
|
+
* @returns {bigint}
|
|
316
|
+
*/
|
|
317
|
+
_endAddress() {
|
|
318
|
+
return BigInt(`0b${this.mask() + "1".repeat(constants.BITS - this.subnetMask)}`);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* The last address in the range given by this address' subnet
|
|
322
|
+
* Often referred to as the Broadcast
|
|
323
|
+
* @memberof Address4
|
|
324
|
+
* @instance
|
|
325
|
+
* @returns {Address4}
|
|
326
|
+
*/
|
|
327
|
+
endAddress() {
|
|
328
|
+
return _Address4.fromBigInt(this._endAddress());
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The last host address in the range given by this address's subnet ie
|
|
332
|
+
* the last address prior to the Broadcast Address
|
|
333
|
+
* @memberof Address4
|
|
334
|
+
* @instance
|
|
335
|
+
* @returns {Address4}
|
|
336
|
+
*/
|
|
337
|
+
endAddressExclusive() {
|
|
338
|
+
const adjust = BigInt("1");
|
|
339
|
+
return _Address4.fromBigInt(this._endAddress() - adjust);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Converts a BigInt to a v4 address object
|
|
343
|
+
* @memberof Address4
|
|
344
|
+
* @static
|
|
345
|
+
* @param {bigint} bigInt - a BigInt to convert
|
|
346
|
+
* @returns {Address4}
|
|
347
|
+
*/
|
|
348
|
+
static fromBigInt(bigInt) {
|
|
349
|
+
return _Address4.fromHex(bigInt.toString(16));
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Returns the first n bits of the address, defaulting to the
|
|
353
|
+
* subnet mask
|
|
354
|
+
* @memberof Address4
|
|
355
|
+
* @instance
|
|
356
|
+
* @returns {String}
|
|
357
|
+
*/
|
|
358
|
+
mask(mask) {
|
|
359
|
+
if (mask === void 0) {
|
|
360
|
+
mask = this.subnetMask;
|
|
361
|
+
}
|
|
362
|
+
return this.getBitsBase2(0, mask);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Returns the bits in the given range as a base-2 string
|
|
366
|
+
* @memberof Address4
|
|
367
|
+
* @instance
|
|
368
|
+
* @returns {string}
|
|
369
|
+
*/
|
|
370
|
+
getBitsBase2(start, end) {
|
|
371
|
+
return this.binaryZeroPad().slice(start, end);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Return the reversed ip6.arpa form of the address
|
|
375
|
+
* @memberof Address4
|
|
376
|
+
* @param {Object} options
|
|
377
|
+
* @param {boolean} options.omitSuffix - omit the "in-addr.arpa" suffix
|
|
378
|
+
* @instance
|
|
379
|
+
* @returns {String}
|
|
380
|
+
*/
|
|
381
|
+
reverseForm(options) {
|
|
382
|
+
if (!options) {
|
|
383
|
+
options = {};
|
|
384
|
+
}
|
|
385
|
+
const reversed = this.correctForm().split(".").reverse().join(".");
|
|
386
|
+
if (options.omitSuffix) {
|
|
387
|
+
return reversed;
|
|
388
|
+
}
|
|
389
|
+
return `${reversed}.in-addr.arpa.`;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Returns true if the given address is a multicast address
|
|
393
|
+
* @memberof Address4
|
|
394
|
+
* @instance
|
|
395
|
+
* @returns {boolean}
|
|
396
|
+
*/
|
|
397
|
+
isMulticast() {
|
|
398
|
+
return this.isInSubnet(new _Address4("224.0.0.0/4"));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Returns a zero-padded base-2 string representation of the address
|
|
402
|
+
* @memberof Address4
|
|
403
|
+
* @instance
|
|
404
|
+
* @returns {string}
|
|
405
|
+
*/
|
|
406
|
+
binaryZeroPad() {
|
|
407
|
+
return this.bigInt().toString(2).padStart(constants.BITS, "0");
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Groups an IPv4 address for inclusion at the end of an IPv6 address
|
|
411
|
+
* @returns {String}
|
|
412
|
+
*/
|
|
413
|
+
groupForV6() {
|
|
414
|
+
const segments = this.parsedAddress;
|
|
415
|
+
return this.address.replace(constants.RE_ADDRESS, `<span class="hover-group group-v4 group-6">${segments.slice(0, 2).join(".")}</span>.<span class="hover-group group-v4 group-7">${segments.slice(2, 4).join(".")}</span>`);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
exports.Address4 = Address4;
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v6/constants.js
|
|
423
|
+
var require_constants2 = __commonJS({
|
|
424
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v6/constants.js"(exports) {
|
|
425
|
+
"use strict";
|
|
426
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
427
|
+
exports.RE_URL_WITH_PORT = exports.RE_URL = exports.RE_ZONE_STRING = exports.RE_SUBNET_STRING = exports.RE_BAD_ADDRESS = exports.RE_BAD_CHARACTERS = exports.TYPES = exports.SCOPES = exports.GROUPS = exports.BITS = void 0;
|
|
428
|
+
exports.BITS = 128;
|
|
429
|
+
exports.GROUPS = 8;
|
|
430
|
+
exports.SCOPES = {
|
|
431
|
+
0: "Reserved",
|
|
432
|
+
1: "Interface local",
|
|
433
|
+
2: "Link local",
|
|
434
|
+
4: "Admin local",
|
|
435
|
+
5: "Site local",
|
|
436
|
+
8: "Organization local",
|
|
437
|
+
14: "Global",
|
|
438
|
+
15: "Reserved"
|
|
439
|
+
};
|
|
440
|
+
exports.TYPES = {
|
|
441
|
+
"ff01::1/128": "Multicast (All nodes on this interface)",
|
|
442
|
+
"ff01::2/128": "Multicast (All routers on this interface)",
|
|
443
|
+
"ff02::1/128": "Multicast (All nodes on this link)",
|
|
444
|
+
"ff02::2/128": "Multicast (All routers on this link)",
|
|
445
|
+
"ff05::2/128": "Multicast (All routers in this site)",
|
|
446
|
+
"ff02::5/128": "Multicast (OSPFv3 AllSPF routers)",
|
|
447
|
+
"ff02::6/128": "Multicast (OSPFv3 AllDR routers)",
|
|
448
|
+
"ff02::9/128": "Multicast (RIP routers)",
|
|
449
|
+
"ff02::a/128": "Multicast (EIGRP routers)",
|
|
450
|
+
"ff02::d/128": "Multicast (PIM routers)",
|
|
451
|
+
"ff02::16/128": "Multicast (MLDv2 reports)",
|
|
452
|
+
"ff01::fb/128": "Multicast (mDNSv6)",
|
|
453
|
+
"ff02::fb/128": "Multicast (mDNSv6)",
|
|
454
|
+
"ff05::fb/128": "Multicast (mDNSv6)",
|
|
455
|
+
"ff02::1:2/128": "Multicast (All DHCP servers and relay agents on this link)",
|
|
456
|
+
"ff05::1:2/128": "Multicast (All DHCP servers and relay agents in this site)",
|
|
457
|
+
"ff02::1:3/128": "Multicast (All DHCP servers on this link)",
|
|
458
|
+
"ff05::1:3/128": "Multicast (All DHCP servers in this site)",
|
|
459
|
+
"::/128": "Unspecified",
|
|
460
|
+
"::1/128": "Loopback",
|
|
461
|
+
"ff00::/8": "Multicast",
|
|
462
|
+
"fe80::/10": "Link-local unicast"
|
|
463
|
+
};
|
|
464
|
+
exports.RE_BAD_CHARACTERS = /([^0-9a-f:/%])/gi;
|
|
465
|
+
exports.RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/gi;
|
|
466
|
+
exports.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/;
|
|
467
|
+
exports.RE_ZONE_STRING = /%.*$/;
|
|
468
|
+
exports.RE_URL = /^\[{0,1}([0-9a-f:]+)\]{0,1}/;
|
|
469
|
+
exports.RE_URL_WITH_PORT = /\[([0-9a-f:]+)\]:([0-9]{1,5})/;
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v6/helpers.js
|
|
474
|
+
var require_helpers = __commonJS({
|
|
475
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v6/helpers.js"(exports) {
|
|
476
|
+
"use strict";
|
|
477
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
478
|
+
exports.spanAllZeroes = spanAllZeroes;
|
|
479
|
+
exports.spanAll = spanAll;
|
|
480
|
+
exports.spanLeadingZeroes = spanLeadingZeroes;
|
|
481
|
+
exports.simpleGroup = simpleGroup;
|
|
482
|
+
function spanAllZeroes(s) {
|
|
483
|
+
return s.replace(/(0+)/g, '<span class="zero">$1</span>');
|
|
484
|
+
}
|
|
485
|
+
function spanAll(s, offset = 0) {
|
|
486
|
+
const letters = s.split("");
|
|
487
|
+
return letters.map((n, i) => `<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`).join("");
|
|
488
|
+
}
|
|
489
|
+
function spanLeadingZeroesSimple(group) {
|
|
490
|
+
return group.replace(/^(0+)/, '<span class="zero">$1</span>');
|
|
491
|
+
}
|
|
492
|
+
function spanLeadingZeroes(address) {
|
|
493
|
+
const groups = address.split(":");
|
|
494
|
+
return groups.map((g) => spanLeadingZeroesSimple(g)).join(":");
|
|
495
|
+
}
|
|
496
|
+
function simpleGroup(addressString, offset = 0) {
|
|
497
|
+
const groups = addressString.split(":");
|
|
498
|
+
return groups.map((g, i) => {
|
|
499
|
+
if (/group-v4/.test(g)) {
|
|
500
|
+
return g;
|
|
501
|
+
}
|
|
502
|
+
return `<span class="hover-group group-${i + offset}">${spanLeadingZeroesSimple(g)}</span>`;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v6/regular-expressions.js
|
|
509
|
+
var require_regular_expressions = __commonJS({
|
|
510
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/v6/regular-expressions.js"(exports) {
|
|
511
|
+
"use strict";
|
|
512
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
513
|
+
if (k2 === void 0) k2 = k;
|
|
514
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
515
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
516
|
+
desc = { enumerable: true, get: function() {
|
|
517
|
+
return m[k];
|
|
518
|
+
} };
|
|
519
|
+
}
|
|
520
|
+
Object.defineProperty(o, k2, desc);
|
|
521
|
+
}) : (function(o, m, k, k2) {
|
|
522
|
+
if (k2 === void 0) k2 = k;
|
|
523
|
+
o[k2] = m[k];
|
|
524
|
+
}));
|
|
525
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
526
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
527
|
+
}) : function(o, v) {
|
|
528
|
+
o["default"] = v;
|
|
529
|
+
});
|
|
530
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
531
|
+
if (mod && mod.__esModule) return mod;
|
|
532
|
+
var result = {};
|
|
533
|
+
if (mod != null) {
|
|
534
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
535
|
+
}
|
|
536
|
+
__setModuleDefault(result, mod);
|
|
537
|
+
return result;
|
|
538
|
+
};
|
|
539
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
540
|
+
exports.ADDRESS_BOUNDARY = void 0;
|
|
541
|
+
exports.groupPossibilities = groupPossibilities;
|
|
542
|
+
exports.padGroup = padGroup;
|
|
543
|
+
exports.simpleRegularExpression = simpleRegularExpression;
|
|
544
|
+
exports.possibleElisions = possibleElisions;
|
|
545
|
+
var v6 = __importStar(require_constants2());
|
|
546
|
+
function groupPossibilities(possibilities) {
|
|
547
|
+
return `(${possibilities.join("|")})`;
|
|
548
|
+
}
|
|
549
|
+
function padGroup(group) {
|
|
550
|
+
if (group.length < 4) {
|
|
551
|
+
return `0{0,${4 - group.length}}${group}`;
|
|
552
|
+
}
|
|
553
|
+
return group;
|
|
554
|
+
}
|
|
555
|
+
exports.ADDRESS_BOUNDARY = "[^A-Fa-f0-9:]";
|
|
556
|
+
function simpleRegularExpression(groups) {
|
|
557
|
+
const zeroIndexes = [];
|
|
558
|
+
groups.forEach((group, i) => {
|
|
559
|
+
const groupInteger = parseInt(group, 16);
|
|
560
|
+
if (groupInteger === 0) {
|
|
561
|
+
zeroIndexes.push(i);
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
const possibilities = zeroIndexes.map((zeroIndex) => groups.map((group, i) => {
|
|
565
|
+
if (i === zeroIndex) {
|
|
566
|
+
const elision = i === 0 || i === v6.GROUPS - 1 ? ":" : "";
|
|
567
|
+
return groupPossibilities([padGroup(group), elision]);
|
|
568
|
+
}
|
|
569
|
+
return padGroup(group);
|
|
570
|
+
}).join(":"));
|
|
571
|
+
possibilities.push(groups.map(padGroup).join(":"));
|
|
572
|
+
return groupPossibilities(possibilities);
|
|
573
|
+
}
|
|
574
|
+
function possibleElisions(elidedGroups, moreLeft, moreRight) {
|
|
575
|
+
const left = moreLeft ? "" : ":";
|
|
576
|
+
const right = moreRight ? "" : ":";
|
|
577
|
+
const possibilities = [];
|
|
578
|
+
if (!moreLeft && !moreRight) {
|
|
579
|
+
possibilities.push("::");
|
|
580
|
+
}
|
|
581
|
+
if (moreLeft && moreRight) {
|
|
582
|
+
possibilities.push("");
|
|
583
|
+
}
|
|
584
|
+
if (moreRight && !moreLeft || !moreRight && moreLeft) {
|
|
585
|
+
possibilities.push(":");
|
|
586
|
+
}
|
|
587
|
+
possibilities.push(`${left}(:0{1,4}){1,${elidedGroups - 1}}`);
|
|
588
|
+
possibilities.push(`(0{1,4}:){1,${elidedGroups - 1}}${right}`);
|
|
589
|
+
possibilities.push(`(0{1,4}:){${elidedGroups - 1}}0{1,4}`);
|
|
590
|
+
for (let groups = 1; groups < elidedGroups - 1; groups++) {
|
|
591
|
+
for (let position = 1; position < elidedGroups - groups; position++) {
|
|
592
|
+
possibilities.push(`(0{1,4}:){${position}}:(0{1,4}:){${elidedGroups - position - groups - 1}}0{1,4}`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return groupPossibilities(possibilities);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/ipv6.js
|
|
601
|
+
var require_ipv6 = __commonJS({
|
|
602
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/ipv6.js"(exports) {
|
|
603
|
+
"use strict";
|
|
604
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
605
|
+
if (k2 === void 0) k2 = k;
|
|
606
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
607
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
608
|
+
desc = { enumerable: true, get: function() {
|
|
609
|
+
return m[k];
|
|
610
|
+
} };
|
|
611
|
+
}
|
|
612
|
+
Object.defineProperty(o, k2, desc);
|
|
613
|
+
}) : (function(o, m, k, k2) {
|
|
614
|
+
if (k2 === void 0) k2 = k;
|
|
615
|
+
o[k2] = m[k];
|
|
616
|
+
}));
|
|
617
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
618
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
619
|
+
}) : function(o, v) {
|
|
620
|
+
o["default"] = v;
|
|
621
|
+
});
|
|
622
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
623
|
+
if (mod && mod.__esModule) return mod;
|
|
624
|
+
var result = {};
|
|
625
|
+
if (mod != null) {
|
|
626
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
627
|
+
}
|
|
628
|
+
__setModuleDefault(result, mod);
|
|
629
|
+
return result;
|
|
630
|
+
};
|
|
631
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
632
|
+
exports.Address6 = void 0;
|
|
633
|
+
var common = __importStar(require_common());
|
|
634
|
+
var constants4 = __importStar(require_constants());
|
|
635
|
+
var constants6 = __importStar(require_constants2());
|
|
636
|
+
var helpers = __importStar(require_helpers());
|
|
637
|
+
var ipv4_1 = require_ipv4();
|
|
638
|
+
var regular_expressions_1 = require_regular_expressions();
|
|
639
|
+
var address_error_1 = require_address_error();
|
|
640
|
+
var common_1 = require_common();
|
|
641
|
+
function assert(condition) {
|
|
642
|
+
if (!condition) {
|
|
643
|
+
throw new Error("Assertion failed.");
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function addCommas(number) {
|
|
647
|
+
const r = /(\d+)(\d{3})/;
|
|
648
|
+
while (r.test(number)) {
|
|
649
|
+
number = number.replace(r, "$1,$2");
|
|
650
|
+
}
|
|
651
|
+
return number;
|
|
652
|
+
}
|
|
653
|
+
function spanLeadingZeroes4(n) {
|
|
654
|
+
n = n.replace(/^(0{1,})([1-9]+)$/, '<span class="parse-error">$1</span>$2');
|
|
655
|
+
n = n.replace(/^(0{1,})(0)$/, '<span class="parse-error">$1</span>$2');
|
|
656
|
+
return n;
|
|
657
|
+
}
|
|
658
|
+
function compact(address, slice) {
|
|
659
|
+
const s1 = [];
|
|
660
|
+
const s2 = [];
|
|
661
|
+
let i;
|
|
662
|
+
for (i = 0; i < address.length; i++) {
|
|
663
|
+
if (i < slice[0]) {
|
|
664
|
+
s1.push(address[i]);
|
|
665
|
+
} else if (i > slice[1]) {
|
|
666
|
+
s2.push(address[i]);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return s1.concat(["compact"]).concat(s2);
|
|
670
|
+
}
|
|
671
|
+
function paddedHex(octet) {
|
|
672
|
+
return parseInt(octet, 16).toString(16).padStart(4, "0");
|
|
673
|
+
}
|
|
674
|
+
function unsignByte(b) {
|
|
675
|
+
return b & 255;
|
|
676
|
+
}
|
|
677
|
+
var Address62 = class _Address6 {
|
|
678
|
+
constructor(address, optionalGroups) {
|
|
679
|
+
this.addressMinusSuffix = "";
|
|
680
|
+
this.parsedSubnet = "";
|
|
681
|
+
this.subnet = "/128";
|
|
682
|
+
this.subnetMask = 128;
|
|
683
|
+
this.v4 = false;
|
|
684
|
+
this.zone = "";
|
|
685
|
+
this.isInSubnet = common.isInSubnet;
|
|
686
|
+
this.isCorrect = common.isCorrect(constants6.BITS);
|
|
687
|
+
if (optionalGroups === void 0) {
|
|
688
|
+
this.groups = constants6.GROUPS;
|
|
689
|
+
} else {
|
|
690
|
+
this.groups = optionalGroups;
|
|
691
|
+
}
|
|
692
|
+
this.address = address;
|
|
693
|
+
const subnet = constants6.RE_SUBNET_STRING.exec(address);
|
|
694
|
+
if (subnet) {
|
|
695
|
+
this.parsedSubnet = subnet[0].replace("/", "");
|
|
696
|
+
this.subnetMask = parseInt(this.parsedSubnet, 10);
|
|
697
|
+
this.subnet = `/${this.subnetMask}`;
|
|
698
|
+
if (Number.isNaN(this.subnetMask) || this.subnetMask < 0 || this.subnetMask > constants6.BITS) {
|
|
699
|
+
throw new address_error_1.AddressError("Invalid subnet mask.");
|
|
700
|
+
}
|
|
701
|
+
address = address.replace(constants6.RE_SUBNET_STRING, "");
|
|
702
|
+
} else if (/\//.test(address)) {
|
|
703
|
+
throw new address_error_1.AddressError("Invalid subnet mask.");
|
|
704
|
+
}
|
|
705
|
+
const zone = constants6.RE_ZONE_STRING.exec(address);
|
|
706
|
+
if (zone) {
|
|
707
|
+
this.zone = zone[0];
|
|
708
|
+
address = address.replace(constants6.RE_ZONE_STRING, "");
|
|
709
|
+
}
|
|
710
|
+
this.addressMinusSuffix = address;
|
|
711
|
+
this.parsedAddress = this.parse(this.addressMinusSuffix);
|
|
712
|
+
}
|
|
713
|
+
static isValid(address) {
|
|
714
|
+
try {
|
|
715
|
+
new _Address6(address);
|
|
716
|
+
return true;
|
|
717
|
+
} catch (e) {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Convert a BigInt to a v6 address object
|
|
723
|
+
* @memberof Address6
|
|
724
|
+
* @static
|
|
725
|
+
* @param {bigint} bigInt - a BigInt to convert
|
|
726
|
+
* @returns {Address6}
|
|
727
|
+
* @example
|
|
728
|
+
* var bigInt = BigInt('1000000000000');
|
|
729
|
+
* var address = Address6.fromBigInt(bigInt);
|
|
730
|
+
* address.correctForm(); // '::e8:d4a5:1000'
|
|
731
|
+
*/
|
|
732
|
+
static fromBigInt(bigInt) {
|
|
733
|
+
const hex = bigInt.toString(16).padStart(32, "0");
|
|
734
|
+
const groups = [];
|
|
735
|
+
let i;
|
|
736
|
+
for (i = 0; i < constants6.GROUPS; i++) {
|
|
737
|
+
groups.push(hex.slice(i * 4, (i + 1) * 4));
|
|
738
|
+
}
|
|
739
|
+
return new _Address6(groups.join(":"));
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Convert a URL (with optional port number) to an address object
|
|
743
|
+
* @memberof Address6
|
|
744
|
+
* @static
|
|
745
|
+
* @param {string} url - a URL with optional port number
|
|
746
|
+
* @example
|
|
747
|
+
* var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
|
|
748
|
+
* addressAndPort.address.correctForm(); // 'ffff::'
|
|
749
|
+
* addressAndPort.port; // 8080
|
|
750
|
+
*/
|
|
751
|
+
static fromURL(url) {
|
|
752
|
+
let host;
|
|
753
|
+
let port = null;
|
|
754
|
+
let result;
|
|
755
|
+
if (url.indexOf("[") !== -1 && url.indexOf("]:") !== -1) {
|
|
756
|
+
result = constants6.RE_URL_WITH_PORT.exec(url);
|
|
757
|
+
if (result === null) {
|
|
758
|
+
return {
|
|
759
|
+
error: "failed to parse address with port",
|
|
760
|
+
address: null,
|
|
761
|
+
port: null
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
host = result[1];
|
|
765
|
+
port = result[2];
|
|
766
|
+
} else if (url.indexOf("/") !== -1) {
|
|
767
|
+
url = url.replace(/^[a-z0-9]+:\/\//, "");
|
|
768
|
+
result = constants6.RE_URL.exec(url);
|
|
769
|
+
if (result === null) {
|
|
770
|
+
return {
|
|
771
|
+
error: "failed to parse address from URL",
|
|
772
|
+
address: null,
|
|
773
|
+
port: null
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
host = result[1];
|
|
777
|
+
} else {
|
|
778
|
+
host = url;
|
|
779
|
+
}
|
|
780
|
+
if (port) {
|
|
781
|
+
port = parseInt(port, 10);
|
|
782
|
+
if (port < 0 || port > 65536) {
|
|
783
|
+
port = null;
|
|
784
|
+
}
|
|
785
|
+
} else {
|
|
786
|
+
port = null;
|
|
787
|
+
}
|
|
788
|
+
return {
|
|
789
|
+
address: new _Address6(host),
|
|
790
|
+
port
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Create an IPv6-mapped address given an IPv4 address
|
|
795
|
+
* @memberof Address6
|
|
796
|
+
* @static
|
|
797
|
+
* @param {string} address - An IPv4 address string
|
|
798
|
+
* @returns {Address6}
|
|
799
|
+
* @example
|
|
800
|
+
* var address = Address6.fromAddress4('192.168.0.1');
|
|
801
|
+
* address.correctForm(); // '::ffff:c0a8:1'
|
|
802
|
+
* address.to4in6(); // '::ffff:192.168.0.1'
|
|
803
|
+
*/
|
|
804
|
+
static fromAddress4(address) {
|
|
805
|
+
const address4 = new ipv4_1.Address4(address);
|
|
806
|
+
const mask6 = constants6.BITS - (constants4.BITS - address4.subnetMask);
|
|
807
|
+
return new _Address6(`::ffff:${address4.correctForm()}/${mask6}`);
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Return an address from ip6.arpa form
|
|
811
|
+
* @memberof Address6
|
|
812
|
+
* @static
|
|
813
|
+
* @param {string} arpaFormAddress - an 'ip6.arpa' form address
|
|
814
|
+
* @returns {Adress6}
|
|
815
|
+
* @example
|
|
816
|
+
* var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
|
|
817
|
+
* address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
|
|
818
|
+
*/
|
|
819
|
+
static fromArpa(arpaFormAddress) {
|
|
820
|
+
let address = arpaFormAddress.replace(/(\.ip6\.arpa)?\.$/, "");
|
|
821
|
+
const semicolonAmount = 7;
|
|
822
|
+
if (address.length !== 63) {
|
|
823
|
+
throw new address_error_1.AddressError("Invalid 'ip6.arpa' form.");
|
|
824
|
+
}
|
|
825
|
+
const parts = address.split(".").reverse();
|
|
826
|
+
for (let i = semicolonAmount; i > 0; i--) {
|
|
827
|
+
const insertIndex = i * 4;
|
|
828
|
+
parts.splice(insertIndex, 0, ":");
|
|
829
|
+
}
|
|
830
|
+
address = parts.join("");
|
|
831
|
+
return new _Address6(address);
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Return the Microsoft UNC transcription of the address
|
|
835
|
+
* @memberof Address6
|
|
836
|
+
* @instance
|
|
837
|
+
* @returns {String} the Microsoft UNC transcription of the address
|
|
838
|
+
*/
|
|
839
|
+
microsoftTranscription() {
|
|
840
|
+
return `${this.correctForm().replace(/:/g, "-")}.ipv6-literal.net`;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Return the first n bits of the address, defaulting to the subnet mask
|
|
844
|
+
* @memberof Address6
|
|
845
|
+
* @instance
|
|
846
|
+
* @param {number} [mask=subnet] - the number of bits to mask
|
|
847
|
+
* @returns {String} the first n bits of the address as a string
|
|
848
|
+
*/
|
|
849
|
+
mask(mask = this.subnetMask) {
|
|
850
|
+
return this.getBitsBase2(0, mask);
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Return the number of possible subnets of a given size in the address
|
|
854
|
+
* @memberof Address6
|
|
855
|
+
* @instance
|
|
856
|
+
* @param {number} [subnetSize=128] - the subnet size
|
|
857
|
+
* @returns {String}
|
|
858
|
+
*/
|
|
859
|
+
// TODO: probably useful to have a numeric version of this too
|
|
860
|
+
possibleSubnets(subnetSize = 128) {
|
|
861
|
+
const availableBits = constants6.BITS - this.subnetMask;
|
|
862
|
+
const subnetBits = Math.abs(subnetSize - constants6.BITS);
|
|
863
|
+
const subnetPowers = availableBits - subnetBits;
|
|
864
|
+
if (subnetPowers < 0) {
|
|
865
|
+
return "0";
|
|
866
|
+
}
|
|
867
|
+
return addCommas((BigInt("2") ** BigInt(subnetPowers)).toString(10));
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Helper function getting start address.
|
|
871
|
+
* @memberof Address6
|
|
872
|
+
* @instance
|
|
873
|
+
* @returns {bigint}
|
|
874
|
+
*/
|
|
875
|
+
_startAddress() {
|
|
876
|
+
return BigInt(`0b${this.mask() + "0".repeat(constants6.BITS - this.subnetMask)}`);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* The first address in the range given by this address' subnet
|
|
880
|
+
* Often referred to as the Network Address.
|
|
881
|
+
* @memberof Address6
|
|
882
|
+
* @instance
|
|
883
|
+
* @returns {Address6}
|
|
884
|
+
*/
|
|
885
|
+
startAddress() {
|
|
886
|
+
return _Address6.fromBigInt(this._startAddress());
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* The first host address in the range given by this address's subnet ie
|
|
890
|
+
* the first address after the Network Address
|
|
891
|
+
* @memberof Address6
|
|
892
|
+
* @instance
|
|
893
|
+
* @returns {Address6}
|
|
894
|
+
*/
|
|
895
|
+
startAddressExclusive() {
|
|
896
|
+
const adjust = BigInt("1");
|
|
897
|
+
return _Address6.fromBigInt(this._startAddress() + adjust);
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Helper function getting end address.
|
|
901
|
+
* @memberof Address6
|
|
902
|
+
* @instance
|
|
903
|
+
* @returns {bigint}
|
|
904
|
+
*/
|
|
905
|
+
_endAddress() {
|
|
906
|
+
return BigInt(`0b${this.mask() + "1".repeat(constants6.BITS - this.subnetMask)}`);
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* The last address in the range given by this address' subnet
|
|
910
|
+
* Often referred to as the Broadcast
|
|
911
|
+
* @memberof Address6
|
|
912
|
+
* @instance
|
|
913
|
+
* @returns {Address6}
|
|
914
|
+
*/
|
|
915
|
+
endAddress() {
|
|
916
|
+
return _Address6.fromBigInt(this._endAddress());
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* The last host address in the range given by this address's subnet ie
|
|
920
|
+
* the last address prior to the Broadcast Address
|
|
921
|
+
* @memberof Address6
|
|
922
|
+
* @instance
|
|
923
|
+
* @returns {Address6}
|
|
924
|
+
*/
|
|
925
|
+
endAddressExclusive() {
|
|
926
|
+
const adjust = BigInt("1");
|
|
927
|
+
return _Address6.fromBigInt(this._endAddress() - adjust);
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Return the scope of the address
|
|
931
|
+
* @memberof Address6
|
|
932
|
+
* @instance
|
|
933
|
+
* @returns {String}
|
|
934
|
+
*/
|
|
935
|
+
getScope() {
|
|
936
|
+
let scope = constants6.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)];
|
|
937
|
+
if (this.getType() === "Global unicast" && scope !== "Link local") {
|
|
938
|
+
scope = "Global";
|
|
939
|
+
}
|
|
940
|
+
return scope || "Unknown";
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Return the type of the address
|
|
944
|
+
* @memberof Address6
|
|
945
|
+
* @instance
|
|
946
|
+
* @returns {String}
|
|
947
|
+
*/
|
|
948
|
+
getType() {
|
|
949
|
+
for (const subnet of Object.keys(constants6.TYPES)) {
|
|
950
|
+
if (this.isInSubnet(new _Address6(subnet))) {
|
|
951
|
+
return constants6.TYPES[subnet];
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return "Global unicast";
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Return the bits in the given range as a BigInt
|
|
958
|
+
* @memberof Address6
|
|
959
|
+
* @instance
|
|
960
|
+
* @returns {bigint}
|
|
961
|
+
*/
|
|
962
|
+
getBits(start, end) {
|
|
963
|
+
return BigInt(`0b${this.getBitsBase2(start, end)}`);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Return the bits in the given range as a base-2 string
|
|
967
|
+
* @memberof Address6
|
|
968
|
+
* @instance
|
|
969
|
+
* @returns {String}
|
|
970
|
+
*/
|
|
971
|
+
getBitsBase2(start, end) {
|
|
972
|
+
return this.binaryZeroPad().slice(start, end);
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Return the bits in the given range as a base-16 string
|
|
976
|
+
* @memberof Address6
|
|
977
|
+
* @instance
|
|
978
|
+
* @returns {String}
|
|
979
|
+
*/
|
|
980
|
+
getBitsBase16(start, end) {
|
|
981
|
+
const length = end - start;
|
|
982
|
+
if (length % 4 !== 0) {
|
|
983
|
+
throw new Error("Length of bits to retrieve must be divisible by four");
|
|
984
|
+
}
|
|
985
|
+
return this.getBits(start, end).toString(16).padStart(length / 4, "0");
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Return the bits that are set past the subnet mask length
|
|
989
|
+
* @memberof Address6
|
|
990
|
+
* @instance
|
|
991
|
+
* @returns {String}
|
|
992
|
+
*/
|
|
993
|
+
getBitsPastSubnet() {
|
|
994
|
+
return this.getBitsBase2(this.subnetMask, constants6.BITS);
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Return the reversed ip6.arpa form of the address
|
|
998
|
+
* @memberof Address6
|
|
999
|
+
* @param {Object} options
|
|
1000
|
+
* @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
|
|
1001
|
+
* @instance
|
|
1002
|
+
* @returns {String}
|
|
1003
|
+
*/
|
|
1004
|
+
reverseForm(options) {
|
|
1005
|
+
if (!options) {
|
|
1006
|
+
options = {};
|
|
1007
|
+
}
|
|
1008
|
+
const characters = Math.floor(this.subnetMask / 4);
|
|
1009
|
+
const reversed = this.canonicalForm().replace(/:/g, "").split("").slice(0, characters).reverse().join(".");
|
|
1010
|
+
if (characters > 0) {
|
|
1011
|
+
if (options.omitSuffix) {
|
|
1012
|
+
return reversed;
|
|
1013
|
+
}
|
|
1014
|
+
return `${reversed}.ip6.arpa.`;
|
|
1015
|
+
}
|
|
1016
|
+
if (options.omitSuffix) {
|
|
1017
|
+
return "";
|
|
1018
|
+
}
|
|
1019
|
+
return "ip6.arpa.";
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Return the correct form of the address
|
|
1023
|
+
* @memberof Address6
|
|
1024
|
+
* @instance
|
|
1025
|
+
* @returns {String}
|
|
1026
|
+
*/
|
|
1027
|
+
correctForm() {
|
|
1028
|
+
let i;
|
|
1029
|
+
let groups = [];
|
|
1030
|
+
let zeroCounter = 0;
|
|
1031
|
+
const zeroes = [];
|
|
1032
|
+
for (i = 0; i < this.parsedAddress.length; i++) {
|
|
1033
|
+
const value = parseInt(this.parsedAddress[i], 16);
|
|
1034
|
+
if (value === 0) {
|
|
1035
|
+
zeroCounter++;
|
|
1036
|
+
}
|
|
1037
|
+
if (value !== 0 && zeroCounter > 0) {
|
|
1038
|
+
if (zeroCounter > 1) {
|
|
1039
|
+
zeroes.push([i - zeroCounter, i - 1]);
|
|
1040
|
+
}
|
|
1041
|
+
zeroCounter = 0;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
if (zeroCounter > 1) {
|
|
1045
|
+
zeroes.push([this.parsedAddress.length - zeroCounter, this.parsedAddress.length - 1]);
|
|
1046
|
+
}
|
|
1047
|
+
const zeroLengths = zeroes.map((n) => n[1] - n[0] + 1);
|
|
1048
|
+
if (zeroes.length > 0) {
|
|
1049
|
+
const index = zeroLengths.indexOf(Math.max(...zeroLengths));
|
|
1050
|
+
groups = compact(this.parsedAddress, zeroes[index]);
|
|
1051
|
+
} else {
|
|
1052
|
+
groups = this.parsedAddress;
|
|
1053
|
+
}
|
|
1054
|
+
for (i = 0; i < groups.length; i++) {
|
|
1055
|
+
if (groups[i] !== "compact") {
|
|
1056
|
+
groups[i] = parseInt(groups[i], 16).toString(16);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
let correct = groups.join(":");
|
|
1060
|
+
correct = correct.replace(/^compact$/, "::");
|
|
1061
|
+
correct = correct.replace(/(^compact)|(compact$)/, ":");
|
|
1062
|
+
correct = correct.replace(/compact/, "");
|
|
1063
|
+
return correct;
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Return a zero-padded base-2 string representation of the address
|
|
1067
|
+
* @memberof Address6
|
|
1068
|
+
* @instance
|
|
1069
|
+
* @returns {String}
|
|
1070
|
+
* @example
|
|
1071
|
+
* var address = new Address6('2001:4860:4001:803::1011');
|
|
1072
|
+
* address.binaryZeroPad();
|
|
1073
|
+
* // '0010000000000001010010000110000001000000000000010000100000000011
|
|
1074
|
+
* // 0000000000000000000000000000000000000000000000000001000000010001'
|
|
1075
|
+
*/
|
|
1076
|
+
binaryZeroPad() {
|
|
1077
|
+
return this.bigInt().toString(2).padStart(constants6.BITS, "0");
|
|
1078
|
+
}
|
|
1079
|
+
// TODO: Improve the semantics of this helper function
|
|
1080
|
+
parse4in6(address) {
|
|
1081
|
+
const groups = address.split(":");
|
|
1082
|
+
const lastGroup = groups.slice(-1)[0];
|
|
1083
|
+
const address4 = lastGroup.match(constants4.RE_ADDRESS);
|
|
1084
|
+
if (address4) {
|
|
1085
|
+
this.parsedAddress4 = address4[0];
|
|
1086
|
+
this.address4 = new ipv4_1.Address4(this.parsedAddress4);
|
|
1087
|
+
for (let i = 0; i < this.address4.groups; i++) {
|
|
1088
|
+
if (/^0[0-9]+/.test(this.address4.parsedAddress[i])) {
|
|
1089
|
+
throw new address_error_1.AddressError("IPv4 addresses can't have leading zeroes.", address.replace(constants4.RE_ADDRESS, this.address4.parsedAddress.map(spanLeadingZeroes4).join(".")));
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
this.v4 = true;
|
|
1093
|
+
groups[groups.length - 1] = this.address4.toGroup6();
|
|
1094
|
+
address = groups.join(":");
|
|
1095
|
+
}
|
|
1096
|
+
return address;
|
|
1097
|
+
}
|
|
1098
|
+
// TODO: Make private?
|
|
1099
|
+
parse(address) {
|
|
1100
|
+
address = this.parse4in6(address);
|
|
1101
|
+
const badCharacters = address.match(constants6.RE_BAD_CHARACTERS);
|
|
1102
|
+
if (badCharacters) {
|
|
1103
|
+
throw new address_error_1.AddressError(`Bad character${badCharacters.length > 1 ? "s" : ""} detected in address: ${badCharacters.join("")}`, address.replace(constants6.RE_BAD_CHARACTERS, '<span class="parse-error">$1</span>'));
|
|
1104
|
+
}
|
|
1105
|
+
const badAddress = address.match(constants6.RE_BAD_ADDRESS);
|
|
1106
|
+
if (badAddress) {
|
|
1107
|
+
throw new address_error_1.AddressError(`Address failed regex: ${badAddress.join("")}`, address.replace(constants6.RE_BAD_ADDRESS, '<span class="parse-error">$1</span>'));
|
|
1108
|
+
}
|
|
1109
|
+
let groups = [];
|
|
1110
|
+
const halves = address.split("::");
|
|
1111
|
+
if (halves.length === 2) {
|
|
1112
|
+
let first = halves[0].split(":");
|
|
1113
|
+
let last = halves[1].split(":");
|
|
1114
|
+
if (first.length === 1 && first[0] === "") {
|
|
1115
|
+
first = [];
|
|
1116
|
+
}
|
|
1117
|
+
if (last.length === 1 && last[0] === "") {
|
|
1118
|
+
last = [];
|
|
1119
|
+
}
|
|
1120
|
+
const remaining = this.groups - (first.length + last.length);
|
|
1121
|
+
if (!remaining) {
|
|
1122
|
+
throw new address_error_1.AddressError("Error parsing groups");
|
|
1123
|
+
}
|
|
1124
|
+
this.elidedGroups = remaining;
|
|
1125
|
+
this.elisionBegin = first.length;
|
|
1126
|
+
this.elisionEnd = first.length + this.elidedGroups;
|
|
1127
|
+
groups = groups.concat(first);
|
|
1128
|
+
for (let i = 0; i < remaining; i++) {
|
|
1129
|
+
groups.push("0");
|
|
1130
|
+
}
|
|
1131
|
+
groups = groups.concat(last);
|
|
1132
|
+
} else if (halves.length === 1) {
|
|
1133
|
+
groups = address.split(":");
|
|
1134
|
+
this.elidedGroups = 0;
|
|
1135
|
+
} else {
|
|
1136
|
+
throw new address_error_1.AddressError("Too many :: groups found");
|
|
1137
|
+
}
|
|
1138
|
+
groups = groups.map((group) => parseInt(group, 16).toString(16));
|
|
1139
|
+
if (groups.length !== this.groups) {
|
|
1140
|
+
throw new address_error_1.AddressError("Incorrect number of groups found");
|
|
1141
|
+
}
|
|
1142
|
+
return groups;
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Return the canonical form of the address
|
|
1146
|
+
* @memberof Address6
|
|
1147
|
+
* @instance
|
|
1148
|
+
* @returns {String}
|
|
1149
|
+
*/
|
|
1150
|
+
canonicalForm() {
|
|
1151
|
+
return this.parsedAddress.map(paddedHex).join(":");
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Return the decimal form of the address
|
|
1155
|
+
* @memberof Address6
|
|
1156
|
+
* @instance
|
|
1157
|
+
* @returns {String}
|
|
1158
|
+
*/
|
|
1159
|
+
decimal() {
|
|
1160
|
+
return this.parsedAddress.map((n) => parseInt(n, 16).toString(10).padStart(5, "0")).join(":");
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Return the address as a BigInt
|
|
1164
|
+
* @memberof Address6
|
|
1165
|
+
* @instance
|
|
1166
|
+
* @returns {bigint}
|
|
1167
|
+
*/
|
|
1168
|
+
bigInt() {
|
|
1169
|
+
return BigInt(`0x${this.parsedAddress.map(paddedHex).join("")}`);
|
|
1170
|
+
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Return the last two groups of this address as an IPv4 address string
|
|
1173
|
+
* @memberof Address6
|
|
1174
|
+
* @instance
|
|
1175
|
+
* @returns {Address4}
|
|
1176
|
+
* @example
|
|
1177
|
+
* var address = new Address6('2001:4860:4001::1825:bf11');
|
|
1178
|
+
* address.to4().correctForm(); // '24.37.191.17'
|
|
1179
|
+
*/
|
|
1180
|
+
to4() {
|
|
1181
|
+
const binary = this.binaryZeroPad().split("");
|
|
1182
|
+
return ipv4_1.Address4.fromHex(BigInt(`0b${binary.slice(96, 128).join("")}`).toString(16));
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Return the v4-in-v6 form of the address
|
|
1186
|
+
* @memberof Address6
|
|
1187
|
+
* @instance
|
|
1188
|
+
* @returns {String}
|
|
1189
|
+
*/
|
|
1190
|
+
to4in6() {
|
|
1191
|
+
const address4 = this.to4();
|
|
1192
|
+
const address6 = new _Address6(this.parsedAddress.slice(0, 6).join(":"), 6);
|
|
1193
|
+
const correct = address6.correctForm();
|
|
1194
|
+
let infix = "";
|
|
1195
|
+
if (!/:$/.test(correct)) {
|
|
1196
|
+
infix = ":";
|
|
1197
|
+
}
|
|
1198
|
+
return correct + infix + address4.address;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Return an object containing the Teredo properties of the address
|
|
1202
|
+
* @memberof Address6
|
|
1203
|
+
* @instance
|
|
1204
|
+
* @returns {Object}
|
|
1205
|
+
*/
|
|
1206
|
+
inspectTeredo() {
|
|
1207
|
+
const prefix = this.getBitsBase16(0, 32);
|
|
1208
|
+
const bitsForUdpPort = this.getBits(80, 96);
|
|
1209
|
+
const udpPort = (bitsForUdpPort ^ BigInt("0xffff")).toString();
|
|
1210
|
+
const server4 = ipv4_1.Address4.fromHex(this.getBitsBase16(32, 64));
|
|
1211
|
+
const bitsForClient4 = this.getBits(96, 128);
|
|
1212
|
+
const client4 = ipv4_1.Address4.fromHex((bitsForClient4 ^ BigInt("0xffffffff")).toString(16));
|
|
1213
|
+
const flagsBase2 = this.getBitsBase2(64, 80);
|
|
1214
|
+
const coneNat = (0, common_1.testBit)(flagsBase2, 15);
|
|
1215
|
+
const reserved = (0, common_1.testBit)(flagsBase2, 14);
|
|
1216
|
+
const groupIndividual = (0, common_1.testBit)(flagsBase2, 8);
|
|
1217
|
+
const universalLocal = (0, common_1.testBit)(flagsBase2, 9);
|
|
1218
|
+
const nonce = BigInt(`0b${flagsBase2.slice(2, 6) + flagsBase2.slice(8, 16)}`).toString(10);
|
|
1219
|
+
return {
|
|
1220
|
+
prefix: `${prefix.slice(0, 4)}:${prefix.slice(4, 8)}`,
|
|
1221
|
+
server4: server4.address,
|
|
1222
|
+
client4: client4.address,
|
|
1223
|
+
flags: flagsBase2,
|
|
1224
|
+
coneNat,
|
|
1225
|
+
microsoft: {
|
|
1226
|
+
reserved,
|
|
1227
|
+
universalLocal,
|
|
1228
|
+
groupIndividual,
|
|
1229
|
+
nonce
|
|
1230
|
+
},
|
|
1231
|
+
udpPort
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Return an object containing the 6to4 properties of the address
|
|
1236
|
+
* @memberof Address6
|
|
1237
|
+
* @instance
|
|
1238
|
+
* @returns {Object}
|
|
1239
|
+
*/
|
|
1240
|
+
inspect6to4() {
|
|
1241
|
+
const prefix = this.getBitsBase16(0, 16);
|
|
1242
|
+
const gateway = ipv4_1.Address4.fromHex(this.getBitsBase16(16, 48));
|
|
1243
|
+
return {
|
|
1244
|
+
prefix: prefix.slice(0, 4),
|
|
1245
|
+
gateway: gateway.address
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Return a v6 6to4 address from a v6 v4inv6 address
|
|
1250
|
+
* @memberof Address6
|
|
1251
|
+
* @instance
|
|
1252
|
+
* @returns {Address6}
|
|
1253
|
+
*/
|
|
1254
|
+
to6to4() {
|
|
1255
|
+
if (!this.is4()) {
|
|
1256
|
+
return null;
|
|
1257
|
+
}
|
|
1258
|
+
const addr6to4 = [
|
|
1259
|
+
"2002",
|
|
1260
|
+
this.getBitsBase16(96, 112),
|
|
1261
|
+
this.getBitsBase16(112, 128),
|
|
1262
|
+
"",
|
|
1263
|
+
"/16"
|
|
1264
|
+
].join(":");
|
|
1265
|
+
return new _Address6(addr6to4);
|
|
1266
|
+
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Return a byte array
|
|
1269
|
+
* @memberof Address6
|
|
1270
|
+
* @instance
|
|
1271
|
+
* @returns {Array}
|
|
1272
|
+
*/
|
|
1273
|
+
toByteArray() {
|
|
1274
|
+
const valueWithoutPadding = this.bigInt().toString(16);
|
|
1275
|
+
const leadingPad = "0".repeat(valueWithoutPadding.length % 2);
|
|
1276
|
+
const value = `${leadingPad}${valueWithoutPadding}`;
|
|
1277
|
+
const bytes = [];
|
|
1278
|
+
for (let i = 0, length = value.length; i < length; i += 2) {
|
|
1279
|
+
bytes.push(parseInt(value.substring(i, i + 2), 16));
|
|
1280
|
+
}
|
|
1281
|
+
return bytes;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Return an unsigned byte array
|
|
1285
|
+
* @memberof Address6
|
|
1286
|
+
* @instance
|
|
1287
|
+
* @returns {Array}
|
|
1288
|
+
*/
|
|
1289
|
+
toUnsignedByteArray() {
|
|
1290
|
+
return this.toByteArray().map(unsignByte);
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Convert a byte array to an Address6 object
|
|
1294
|
+
* @memberof Address6
|
|
1295
|
+
* @static
|
|
1296
|
+
* @returns {Address6}
|
|
1297
|
+
*/
|
|
1298
|
+
static fromByteArray(bytes) {
|
|
1299
|
+
return this.fromUnsignedByteArray(bytes.map(unsignByte));
|
|
1300
|
+
}
|
|
1301
|
+
/**
|
|
1302
|
+
* Convert an unsigned byte array to an Address6 object
|
|
1303
|
+
* @memberof Address6
|
|
1304
|
+
* @static
|
|
1305
|
+
* @returns {Address6}
|
|
1306
|
+
*/
|
|
1307
|
+
static fromUnsignedByteArray(bytes) {
|
|
1308
|
+
const BYTE_MAX = BigInt("256");
|
|
1309
|
+
let result = BigInt("0");
|
|
1310
|
+
let multiplier = BigInt("1");
|
|
1311
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
1312
|
+
result += multiplier * BigInt(bytes[i].toString(10));
|
|
1313
|
+
multiplier *= BYTE_MAX;
|
|
1314
|
+
}
|
|
1315
|
+
return _Address6.fromBigInt(result);
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Returns true if the address is in the canonical form, false otherwise
|
|
1319
|
+
* @memberof Address6
|
|
1320
|
+
* @instance
|
|
1321
|
+
* @returns {boolean}
|
|
1322
|
+
*/
|
|
1323
|
+
isCanonical() {
|
|
1324
|
+
return this.addressMinusSuffix === this.canonicalForm();
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Returns true if the address is a link local address, false otherwise
|
|
1328
|
+
* @memberof Address6
|
|
1329
|
+
* @instance
|
|
1330
|
+
* @returns {boolean}
|
|
1331
|
+
*/
|
|
1332
|
+
isLinkLocal() {
|
|
1333
|
+
if (this.getBitsBase2(0, 64) === "1111111010000000000000000000000000000000000000000000000000000000") {
|
|
1334
|
+
return true;
|
|
1335
|
+
}
|
|
1336
|
+
return false;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Returns true if the address is a multicast address, false otherwise
|
|
1340
|
+
* @memberof Address6
|
|
1341
|
+
* @instance
|
|
1342
|
+
* @returns {boolean}
|
|
1343
|
+
*/
|
|
1344
|
+
isMulticast() {
|
|
1345
|
+
return this.getType() === "Multicast";
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Returns true if the address is a v4-in-v6 address, false otherwise
|
|
1349
|
+
* @memberof Address6
|
|
1350
|
+
* @instance
|
|
1351
|
+
* @returns {boolean}
|
|
1352
|
+
*/
|
|
1353
|
+
is4() {
|
|
1354
|
+
return this.v4;
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Returns true if the address is a Teredo address, false otherwise
|
|
1358
|
+
* @memberof Address6
|
|
1359
|
+
* @instance
|
|
1360
|
+
* @returns {boolean}
|
|
1361
|
+
*/
|
|
1362
|
+
isTeredo() {
|
|
1363
|
+
return this.isInSubnet(new _Address6("2001::/32"));
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Returns true if the address is a 6to4 address, false otherwise
|
|
1367
|
+
* @memberof Address6
|
|
1368
|
+
* @instance
|
|
1369
|
+
* @returns {boolean}
|
|
1370
|
+
*/
|
|
1371
|
+
is6to4() {
|
|
1372
|
+
return this.isInSubnet(new _Address6("2002::/16"));
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Returns true if the address is a loopback address, false otherwise
|
|
1376
|
+
* @memberof Address6
|
|
1377
|
+
* @instance
|
|
1378
|
+
* @returns {boolean}
|
|
1379
|
+
*/
|
|
1380
|
+
isLoopback() {
|
|
1381
|
+
return this.getType() === "Loopback";
|
|
1382
|
+
}
|
|
1383
|
+
// #endregion
|
|
1384
|
+
// #region HTML
|
|
1385
|
+
/**
|
|
1386
|
+
* @returns {String} the address in link form with a default port of 80
|
|
1387
|
+
*/
|
|
1388
|
+
href(optionalPort) {
|
|
1389
|
+
if (optionalPort === void 0) {
|
|
1390
|
+
optionalPort = "";
|
|
1391
|
+
} else {
|
|
1392
|
+
optionalPort = `:${optionalPort}`;
|
|
1393
|
+
}
|
|
1394
|
+
return `http://[${this.correctForm()}]${optionalPort}/`;
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* @returns {String} a link suitable for conveying the address via a URL hash
|
|
1398
|
+
*/
|
|
1399
|
+
link(options) {
|
|
1400
|
+
if (!options) {
|
|
1401
|
+
options = {};
|
|
1402
|
+
}
|
|
1403
|
+
if (options.className === void 0) {
|
|
1404
|
+
options.className = "";
|
|
1405
|
+
}
|
|
1406
|
+
if (options.prefix === void 0) {
|
|
1407
|
+
options.prefix = "/#address=";
|
|
1408
|
+
}
|
|
1409
|
+
if (options.v4 === void 0) {
|
|
1410
|
+
options.v4 = false;
|
|
1411
|
+
}
|
|
1412
|
+
let formFunction = this.correctForm;
|
|
1413
|
+
if (options.v4) {
|
|
1414
|
+
formFunction = this.to4in6;
|
|
1415
|
+
}
|
|
1416
|
+
const form = formFunction.call(this);
|
|
1417
|
+
if (options.className) {
|
|
1418
|
+
return `<a href="${options.prefix}${form}" class="${options.className}">${form}</a>`;
|
|
1419
|
+
}
|
|
1420
|
+
return `<a href="${options.prefix}${form}">${form}</a>`;
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Groups an address
|
|
1424
|
+
* @returns {String}
|
|
1425
|
+
*/
|
|
1426
|
+
group() {
|
|
1427
|
+
if (this.elidedGroups === 0) {
|
|
1428
|
+
return helpers.simpleGroup(this.address).join(":");
|
|
1429
|
+
}
|
|
1430
|
+
assert(typeof this.elidedGroups === "number");
|
|
1431
|
+
assert(typeof this.elisionBegin === "number");
|
|
1432
|
+
const output = [];
|
|
1433
|
+
const [left, right] = this.address.split("::");
|
|
1434
|
+
if (left.length) {
|
|
1435
|
+
output.push(...helpers.simpleGroup(left));
|
|
1436
|
+
} else {
|
|
1437
|
+
output.push("");
|
|
1438
|
+
}
|
|
1439
|
+
const classes = ["hover-group"];
|
|
1440
|
+
for (let i = this.elisionBegin; i < this.elisionBegin + this.elidedGroups; i++) {
|
|
1441
|
+
classes.push(`group-${i}`);
|
|
1442
|
+
}
|
|
1443
|
+
output.push(`<span class="${classes.join(" ")}"></span>`);
|
|
1444
|
+
if (right.length) {
|
|
1445
|
+
output.push(...helpers.simpleGroup(right, this.elisionEnd));
|
|
1446
|
+
} else {
|
|
1447
|
+
output.push("");
|
|
1448
|
+
}
|
|
1449
|
+
if (this.is4()) {
|
|
1450
|
+
assert(this.address4 instanceof ipv4_1.Address4);
|
|
1451
|
+
output.pop();
|
|
1452
|
+
output.push(this.address4.groupForV6());
|
|
1453
|
+
}
|
|
1454
|
+
return output.join(":");
|
|
1455
|
+
}
|
|
1456
|
+
// #endregion
|
|
1457
|
+
// #region Regular expressions
|
|
1458
|
+
/**
|
|
1459
|
+
* Generate a regular expression string that can be used to find or validate
|
|
1460
|
+
* all variations of this address
|
|
1461
|
+
* @memberof Address6
|
|
1462
|
+
* @instance
|
|
1463
|
+
* @param {boolean} substringSearch
|
|
1464
|
+
* @returns {string}
|
|
1465
|
+
*/
|
|
1466
|
+
regularExpressionString(substringSearch = false) {
|
|
1467
|
+
let output = [];
|
|
1468
|
+
const address6 = new _Address6(this.correctForm());
|
|
1469
|
+
if (address6.elidedGroups === 0) {
|
|
1470
|
+
output.push((0, regular_expressions_1.simpleRegularExpression)(address6.parsedAddress));
|
|
1471
|
+
} else if (address6.elidedGroups === constants6.GROUPS) {
|
|
1472
|
+
output.push((0, regular_expressions_1.possibleElisions)(constants6.GROUPS));
|
|
1473
|
+
} else {
|
|
1474
|
+
const halves = address6.address.split("::");
|
|
1475
|
+
if (halves[0].length) {
|
|
1476
|
+
output.push((0, regular_expressions_1.simpleRegularExpression)(halves[0].split(":")));
|
|
1477
|
+
}
|
|
1478
|
+
assert(typeof address6.elidedGroups === "number");
|
|
1479
|
+
output.push((0, regular_expressions_1.possibleElisions)(address6.elidedGroups, halves[0].length !== 0, halves[1].length !== 0));
|
|
1480
|
+
if (halves[1].length) {
|
|
1481
|
+
output.push((0, regular_expressions_1.simpleRegularExpression)(halves[1].split(":")));
|
|
1482
|
+
}
|
|
1483
|
+
output = [output.join(":")];
|
|
1484
|
+
}
|
|
1485
|
+
if (!substringSearch) {
|
|
1486
|
+
output = [
|
|
1487
|
+
"(?=^|",
|
|
1488
|
+
regular_expressions_1.ADDRESS_BOUNDARY,
|
|
1489
|
+
"|[^\\w\\:])(",
|
|
1490
|
+
...output,
|
|
1491
|
+
")(?=[^\\w\\:]|",
|
|
1492
|
+
regular_expressions_1.ADDRESS_BOUNDARY,
|
|
1493
|
+
"|$)"
|
|
1494
|
+
];
|
|
1495
|
+
}
|
|
1496
|
+
return output.join("");
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Generate a regular expression that can be used to find or validate all
|
|
1500
|
+
* variations of this address.
|
|
1501
|
+
* @memberof Address6
|
|
1502
|
+
* @instance
|
|
1503
|
+
* @param {boolean} substringSearch
|
|
1504
|
+
* @returns {RegExp}
|
|
1505
|
+
*/
|
|
1506
|
+
regularExpression(substringSearch = false) {
|
|
1507
|
+
return new RegExp(this.regularExpressionString(substringSearch), "i");
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
exports.Address6 = Address62;
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
|
|
1514
|
+
// node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/ip-address.js
|
|
1515
|
+
var require_ip_address = __commonJS({
|
|
1516
|
+
"node_modules/.pnpm/ip-address@10.0.1/node_modules/ip-address/dist/ip-address.js"(exports) {
|
|
1517
|
+
"use strict";
|
|
1518
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1519
|
+
if (k2 === void 0) k2 = k;
|
|
1520
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1521
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1522
|
+
desc = { enumerable: true, get: function() {
|
|
1523
|
+
return m[k];
|
|
1524
|
+
} };
|
|
1525
|
+
}
|
|
1526
|
+
Object.defineProperty(o, k2, desc);
|
|
1527
|
+
}) : (function(o, m, k, k2) {
|
|
1528
|
+
if (k2 === void 0) k2 = k;
|
|
1529
|
+
o[k2] = m[k];
|
|
1530
|
+
}));
|
|
1531
|
+
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1532
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
1533
|
+
}) : function(o, v) {
|
|
1534
|
+
o["default"] = v;
|
|
1535
|
+
});
|
|
1536
|
+
var __importStar = exports && exports.__importStar || function(mod) {
|
|
1537
|
+
if (mod && mod.__esModule) return mod;
|
|
1538
|
+
var result = {};
|
|
1539
|
+
if (mod != null) {
|
|
1540
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
1541
|
+
}
|
|
1542
|
+
__setModuleDefault(result, mod);
|
|
1543
|
+
return result;
|
|
1544
|
+
};
|
|
1545
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1546
|
+
exports.v6 = exports.AddressError = exports.Address6 = exports.Address4 = void 0;
|
|
1547
|
+
var ipv4_1 = require_ipv4();
|
|
1548
|
+
Object.defineProperty(exports, "Address4", { enumerable: true, get: function() {
|
|
1549
|
+
return ipv4_1.Address4;
|
|
1550
|
+
} });
|
|
1551
|
+
var ipv6_1 = require_ipv6();
|
|
1552
|
+
Object.defineProperty(exports, "Address6", { enumerable: true, get: function() {
|
|
1553
|
+
return ipv6_1.Address6;
|
|
1554
|
+
} });
|
|
1555
|
+
var address_error_1 = require_address_error();
|
|
1556
|
+
Object.defineProperty(exports, "AddressError", { enumerable: true, get: function() {
|
|
1557
|
+
return address_error_1.AddressError;
|
|
1558
|
+
} });
|
|
1559
|
+
var helpers = __importStar(require_helpers());
|
|
1560
|
+
exports.v6 = { helpers };
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
10
1563
|
|
|
11
1564
|
// cli/utils/debug.ts
|
|
12
1565
|
var debug_exports = {};
|
|
@@ -2042,10 +3595,867 @@ import open from "open";
|
|
|
2042
3595
|
import { join as join7 } from "path";
|
|
2043
3596
|
|
|
2044
3597
|
// cli/server/server.ts
|
|
2045
|
-
init_serverState();
|
|
2046
|
-
init_spreadsheetRoutes();
|
|
2047
3598
|
import cors from "cors";
|
|
2048
3599
|
import express2 from "express";
|
|
3600
|
+
|
|
3601
|
+
// node_modules/.pnpm/express-rate-limit@8.1.0_express@5.1.0/node_modules/express-rate-limit/dist/index.mjs
|
|
3602
|
+
var import_ip_address = __toESM(require_ip_address(), 1);
|
|
3603
|
+
import { isIPv6 } from "node:net";
|
|
3604
|
+
import { isIPv6 as isIPv62 } from "node:net";
|
|
3605
|
+
import { Buffer as Buffer2 } from "node:buffer";
|
|
3606
|
+
import { createHash } from "node:crypto";
|
|
3607
|
+
import { isIP } from "node:net";
|
|
3608
|
+
function ipKeyGenerator(ip, ipv6Subnet = 56) {
|
|
3609
|
+
if (ipv6Subnet && isIPv6(ip)) {
|
|
3610
|
+
return `${new import_ip_address.Address6(`${ip}/${ipv6Subnet}`).startAddress().correctForm()}/${ipv6Subnet}`;
|
|
3611
|
+
}
|
|
3612
|
+
return ip;
|
|
3613
|
+
}
|
|
3614
|
+
var MemoryStore = class {
|
|
3615
|
+
constructor(validations2) {
|
|
3616
|
+
this.validations = validations2;
|
|
3617
|
+
this.previous = /* @__PURE__ */ new Map();
|
|
3618
|
+
this.current = /* @__PURE__ */ new Map();
|
|
3619
|
+
this.localKeys = true;
|
|
3620
|
+
}
|
|
3621
|
+
/**
|
|
3622
|
+
* Method that initializes the store.
|
|
3623
|
+
*
|
|
3624
|
+
* @param options {Options} - The options used to setup the middleware.
|
|
3625
|
+
*/
|
|
3626
|
+
init(options) {
|
|
3627
|
+
this.windowMs = options.windowMs;
|
|
3628
|
+
this.validations?.windowMs(this.windowMs);
|
|
3629
|
+
if (this.interval) clearInterval(this.interval);
|
|
3630
|
+
this.interval = setInterval(() => {
|
|
3631
|
+
this.clearExpired();
|
|
3632
|
+
}, this.windowMs);
|
|
3633
|
+
this.interval.unref?.();
|
|
3634
|
+
}
|
|
3635
|
+
/**
|
|
3636
|
+
* Method to fetch a client's hit count and reset time.
|
|
3637
|
+
*
|
|
3638
|
+
* @param key {string} - The identifier for a client.
|
|
3639
|
+
*
|
|
3640
|
+
* @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client.
|
|
3641
|
+
*
|
|
3642
|
+
* @public
|
|
3643
|
+
*/
|
|
3644
|
+
async get(key) {
|
|
3645
|
+
return this.current.get(key) ?? this.previous.get(key);
|
|
3646
|
+
}
|
|
3647
|
+
/**
|
|
3648
|
+
* Method to increment a client's hit counter.
|
|
3649
|
+
*
|
|
3650
|
+
* @param key {string} - The identifier for a client.
|
|
3651
|
+
*
|
|
3652
|
+
* @returns {ClientRateLimitInfo} - The number of hits and reset time for that client.
|
|
3653
|
+
*
|
|
3654
|
+
* @public
|
|
3655
|
+
*/
|
|
3656
|
+
async increment(key) {
|
|
3657
|
+
const client = this.getClient(key);
|
|
3658
|
+
const now = Date.now();
|
|
3659
|
+
if (client.resetTime.getTime() <= now) {
|
|
3660
|
+
this.resetClient(client, now);
|
|
3661
|
+
}
|
|
3662
|
+
client.totalHits++;
|
|
3663
|
+
return client;
|
|
3664
|
+
}
|
|
3665
|
+
/**
|
|
3666
|
+
* Method to decrement a client's hit counter.
|
|
3667
|
+
*
|
|
3668
|
+
* @param key {string} - The identifier for a client.
|
|
3669
|
+
*
|
|
3670
|
+
* @public
|
|
3671
|
+
*/
|
|
3672
|
+
async decrement(key) {
|
|
3673
|
+
const client = this.getClient(key);
|
|
3674
|
+
if (client.totalHits > 0) client.totalHits--;
|
|
3675
|
+
}
|
|
3676
|
+
/**
|
|
3677
|
+
* Method to reset a client's hit counter.
|
|
3678
|
+
*
|
|
3679
|
+
* @param key {string} - The identifier for a client.
|
|
3680
|
+
*
|
|
3681
|
+
* @public
|
|
3682
|
+
*/
|
|
3683
|
+
async resetKey(key) {
|
|
3684
|
+
this.current.delete(key);
|
|
3685
|
+
this.previous.delete(key);
|
|
3686
|
+
}
|
|
3687
|
+
/**
|
|
3688
|
+
* Method to reset everyone's hit counter.
|
|
3689
|
+
*
|
|
3690
|
+
* @public
|
|
3691
|
+
*/
|
|
3692
|
+
async resetAll() {
|
|
3693
|
+
this.current.clear();
|
|
3694
|
+
this.previous.clear();
|
|
3695
|
+
}
|
|
3696
|
+
/**
|
|
3697
|
+
* Method to stop the timer (if currently running) and prevent any memory
|
|
3698
|
+
* leaks.
|
|
3699
|
+
*
|
|
3700
|
+
* @public
|
|
3701
|
+
*/
|
|
3702
|
+
shutdown() {
|
|
3703
|
+
clearInterval(this.interval);
|
|
3704
|
+
void this.resetAll();
|
|
3705
|
+
}
|
|
3706
|
+
/**
|
|
3707
|
+
* Recycles a client by setting its hit count to zero, and reset time to
|
|
3708
|
+
* `windowMs` milliseconds from now.
|
|
3709
|
+
*
|
|
3710
|
+
* NOT to be confused with `#resetKey()`, which removes a client from both the
|
|
3711
|
+
* `current` and `previous` maps.
|
|
3712
|
+
*
|
|
3713
|
+
* @param client {Client} - The client to recycle.
|
|
3714
|
+
* @param now {number} - The current time, to which the `windowMs` is added to get the `resetTime` for the client.
|
|
3715
|
+
*
|
|
3716
|
+
* @return {Client} - The modified client that was passed in, to allow for chaining.
|
|
3717
|
+
*/
|
|
3718
|
+
resetClient(client, now = Date.now()) {
|
|
3719
|
+
client.totalHits = 0;
|
|
3720
|
+
client.resetTime.setTime(now + this.windowMs);
|
|
3721
|
+
return client;
|
|
3722
|
+
}
|
|
3723
|
+
/**
|
|
3724
|
+
* Retrieves or creates a client, given a key. Also ensures that the client being
|
|
3725
|
+
* returned is in the `current` map.
|
|
3726
|
+
*
|
|
3727
|
+
* @param key {string} - The key under which the client is (or is to be) stored.
|
|
3728
|
+
*
|
|
3729
|
+
* @returns {Client} - The requested client.
|
|
3730
|
+
*/
|
|
3731
|
+
getClient(key) {
|
|
3732
|
+
if (this.current.has(key)) return this.current.get(key);
|
|
3733
|
+
let client;
|
|
3734
|
+
if (this.previous.has(key)) {
|
|
3735
|
+
client = this.previous.get(key);
|
|
3736
|
+
this.previous.delete(key);
|
|
3737
|
+
} else {
|
|
3738
|
+
client = { totalHits: 0, resetTime: /* @__PURE__ */ new Date() };
|
|
3739
|
+
this.resetClient(client);
|
|
3740
|
+
}
|
|
3741
|
+
this.current.set(key, client);
|
|
3742
|
+
return client;
|
|
3743
|
+
}
|
|
3744
|
+
/**
|
|
3745
|
+
* Move current clients to previous, create a new map for current.
|
|
3746
|
+
*
|
|
3747
|
+
* This function is called every `windowMs`.
|
|
3748
|
+
*/
|
|
3749
|
+
clearExpired() {
|
|
3750
|
+
this.previous = this.current;
|
|
3751
|
+
this.current = /* @__PURE__ */ new Map();
|
|
3752
|
+
}
|
|
3753
|
+
};
|
|
3754
|
+
var SUPPORTED_DRAFT_VERSIONS = [
|
|
3755
|
+
"draft-6",
|
|
3756
|
+
"draft-7",
|
|
3757
|
+
"draft-8"
|
|
3758
|
+
];
|
|
3759
|
+
var getResetSeconds = (windowMs, resetTime) => {
|
|
3760
|
+
let resetSeconds;
|
|
3761
|
+
if (resetTime) {
|
|
3762
|
+
const deltaSeconds = Math.ceil((resetTime.getTime() - Date.now()) / 1e3);
|
|
3763
|
+
resetSeconds = Math.max(0, deltaSeconds);
|
|
3764
|
+
} else {
|
|
3765
|
+
resetSeconds = Math.ceil(windowMs / 1e3);
|
|
3766
|
+
}
|
|
3767
|
+
return resetSeconds;
|
|
3768
|
+
};
|
|
3769
|
+
var getPartitionKey = (key) => {
|
|
3770
|
+
const hash = createHash("sha256");
|
|
3771
|
+
hash.update(key);
|
|
3772
|
+
const partitionKey = hash.digest("hex").slice(0, 12);
|
|
3773
|
+
return Buffer2.from(partitionKey).toString("base64");
|
|
3774
|
+
};
|
|
3775
|
+
var setLegacyHeaders = (response, info) => {
|
|
3776
|
+
if (response.headersSent) return;
|
|
3777
|
+
response.setHeader("X-RateLimit-Limit", info.limit.toString());
|
|
3778
|
+
response.setHeader("X-RateLimit-Remaining", info.remaining.toString());
|
|
3779
|
+
if (info.resetTime instanceof Date) {
|
|
3780
|
+
response.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString());
|
|
3781
|
+
response.setHeader(
|
|
3782
|
+
"X-RateLimit-Reset",
|
|
3783
|
+
Math.ceil(info.resetTime.getTime() / 1e3).toString()
|
|
3784
|
+
);
|
|
3785
|
+
}
|
|
3786
|
+
};
|
|
3787
|
+
var setDraft6Headers = (response, info, windowMs) => {
|
|
3788
|
+
if (response.headersSent) return;
|
|
3789
|
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
|
3790
|
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
|
3791
|
+
response.setHeader("RateLimit-Policy", `${info.limit};w=${windowSeconds}`);
|
|
3792
|
+
response.setHeader("RateLimit-Limit", info.limit.toString());
|
|
3793
|
+
response.setHeader("RateLimit-Remaining", info.remaining.toString());
|
|
3794
|
+
if (typeof resetSeconds === "number")
|
|
3795
|
+
response.setHeader("RateLimit-Reset", resetSeconds.toString());
|
|
3796
|
+
};
|
|
3797
|
+
var setDraft7Headers = (response, info, windowMs) => {
|
|
3798
|
+
if (response.headersSent) return;
|
|
3799
|
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
|
3800
|
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
|
3801
|
+
response.setHeader("RateLimit-Policy", `${info.limit};w=${windowSeconds}`);
|
|
3802
|
+
response.setHeader(
|
|
3803
|
+
"RateLimit",
|
|
3804
|
+
`limit=${info.limit}, remaining=${info.remaining}, reset=${resetSeconds}`
|
|
3805
|
+
);
|
|
3806
|
+
};
|
|
3807
|
+
var setDraft8Headers = (response, info, windowMs, name, key) => {
|
|
3808
|
+
if (response.headersSent) return;
|
|
3809
|
+
const windowSeconds = Math.ceil(windowMs / 1e3);
|
|
3810
|
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
|
3811
|
+
const partitionKey = getPartitionKey(key);
|
|
3812
|
+
const header = `r=${info.remaining}; t=${resetSeconds}`;
|
|
3813
|
+
const policy = `q=${info.limit}; w=${windowSeconds}; pk=:${partitionKey}:`;
|
|
3814
|
+
response.append("RateLimit", `"${name}"; ${header}`);
|
|
3815
|
+
response.append("RateLimit-Policy", `"${name}"; ${policy}`);
|
|
3816
|
+
};
|
|
3817
|
+
var setRetryAfterHeader = (response, info, windowMs) => {
|
|
3818
|
+
if (response.headersSent) return;
|
|
3819
|
+
const resetSeconds = getResetSeconds(windowMs, info.resetTime);
|
|
3820
|
+
response.setHeader("Retry-After", resetSeconds.toString());
|
|
3821
|
+
};
|
|
3822
|
+
var omitUndefinedProperties = (passedOptions) => {
|
|
3823
|
+
const omittedOptions = {};
|
|
3824
|
+
for (const k of Object.keys(passedOptions)) {
|
|
3825
|
+
const key = k;
|
|
3826
|
+
if (passedOptions[key] !== void 0) {
|
|
3827
|
+
omittedOptions[key] = passedOptions[key];
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
return omittedOptions;
|
|
3831
|
+
};
|
|
3832
|
+
var ValidationError = class extends Error {
|
|
3833
|
+
/**
|
|
3834
|
+
* The code must be a string, in snake case and all capital, that starts with
|
|
3835
|
+
* the substring `ERR_ERL_`.
|
|
3836
|
+
*
|
|
3837
|
+
* The message must be a string, starting with an uppercase character,
|
|
3838
|
+
* describing the issue in detail.
|
|
3839
|
+
*/
|
|
3840
|
+
constructor(code, message) {
|
|
3841
|
+
const url = `https://express-rate-limit.github.io/${code}/`;
|
|
3842
|
+
super(`${message} See ${url} for more information.`);
|
|
3843
|
+
this.name = this.constructor.name;
|
|
3844
|
+
this.code = code;
|
|
3845
|
+
this.help = url;
|
|
3846
|
+
}
|
|
3847
|
+
};
|
|
3848
|
+
var ChangeWarning = class extends ValidationError {
|
|
3849
|
+
};
|
|
3850
|
+
var usedStores = /* @__PURE__ */ new Set();
|
|
3851
|
+
var singleCountKeys = /* @__PURE__ */ new WeakMap();
|
|
3852
|
+
var validations = {
|
|
3853
|
+
enabled: {
|
|
3854
|
+
default: true
|
|
3855
|
+
},
|
|
3856
|
+
// Should be EnabledValidations type, but that's a circular reference
|
|
3857
|
+
disable() {
|
|
3858
|
+
for (const k of Object.keys(this.enabled)) this.enabled[k] = false;
|
|
3859
|
+
},
|
|
3860
|
+
/**
|
|
3861
|
+
* Checks whether the IP address is valid, and that it does not have a port
|
|
3862
|
+
* number in it.
|
|
3863
|
+
*
|
|
3864
|
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_invalid_ip_address.
|
|
3865
|
+
*
|
|
3866
|
+
* @param ip {string | undefined} - The IP address provided by Express as request.ip.
|
|
3867
|
+
*
|
|
3868
|
+
* @returns {void}
|
|
3869
|
+
*/
|
|
3870
|
+
ip(ip) {
|
|
3871
|
+
if (ip === void 0) {
|
|
3872
|
+
throw new ValidationError(
|
|
3873
|
+
"ERR_ERL_UNDEFINED_IP_ADDRESS",
|
|
3874
|
+
`An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely.`
|
|
3875
|
+
);
|
|
3876
|
+
}
|
|
3877
|
+
if (!isIP(ip)) {
|
|
3878
|
+
throw new ValidationError(
|
|
3879
|
+
"ERR_ERL_INVALID_IP_ADDRESS",
|
|
3880
|
+
`An invalid 'request.ip' (${ip}) was detected. Consider passing a custom 'keyGenerator' function to the rate limiter.`
|
|
3881
|
+
);
|
|
3882
|
+
}
|
|
3883
|
+
},
|
|
3884
|
+
/**
|
|
3885
|
+
* Makes sure the trust proxy setting is not set to `true`.
|
|
3886
|
+
*
|
|
3887
|
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_permissive_trust_proxy.
|
|
3888
|
+
*
|
|
3889
|
+
* @param request {Request} - The Express request object.
|
|
3890
|
+
*
|
|
3891
|
+
* @returns {void}
|
|
3892
|
+
*/
|
|
3893
|
+
trustProxy(request) {
|
|
3894
|
+
if (request.app.get("trust proxy") === true) {
|
|
3895
|
+
throw new ValidationError(
|
|
3896
|
+
"ERR_ERL_PERMISSIVE_TRUST_PROXY",
|
|
3897
|
+
`The Express 'trust proxy' setting is true, which allows anyone to trivially bypass IP-based rate limiting.`
|
|
3898
|
+
);
|
|
3899
|
+
}
|
|
3900
|
+
},
|
|
3901
|
+
/**
|
|
3902
|
+
* Makes sure the trust proxy setting is set in case the `X-Forwarded-For`
|
|
3903
|
+
* header is present.
|
|
3904
|
+
*
|
|
3905
|
+
* See https://github.com/express-rate-limit/express-rate-limit/wiki/Error-Codes#err_erl_unset_trust_proxy.
|
|
3906
|
+
*
|
|
3907
|
+
* @param request {Request} - The Express request object.
|
|
3908
|
+
*
|
|
3909
|
+
* @returns {void}
|
|
3910
|
+
*/
|
|
3911
|
+
xForwardedForHeader(request) {
|
|
3912
|
+
if (request.headers["x-forwarded-for"] && request.app.get("trust proxy") === false) {
|
|
3913
|
+
throw new ValidationError(
|
|
3914
|
+
"ERR_ERL_UNEXPECTED_X_FORWARDED_FOR",
|
|
3915
|
+
`The 'X-Forwarded-For' header is set but the Express 'trust proxy' setting is false (default). This could indicate a misconfiguration which would prevent express-rate-limit from accurately identifying users.`
|
|
3916
|
+
);
|
|
3917
|
+
}
|
|
3918
|
+
},
|
|
3919
|
+
/**
|
|
3920
|
+
* Alert the user if the Forwarded header is set (standardized version of X-Forwarded-For - not supported by express as of version 5.1.0)
|
|
3921
|
+
*
|
|
3922
|
+
* @param request {Request} - The Express request object.
|
|
3923
|
+
*
|
|
3924
|
+
* @returns {void}
|
|
3925
|
+
*/
|
|
3926
|
+
forwardedHeader(request) {
|
|
3927
|
+
if (request.headers.forwarded && request.ip === request.socket?.remoteAddress) {
|
|
3928
|
+
throw new ValidationError(
|
|
3929
|
+
"ERR_ERL_FORWARDED_HEADER",
|
|
3930
|
+
`The 'Forwarded' header (standardized X-Forwarded-For) is set but currently being ignored. Add a custom keyGenerator to use a value from this header.`
|
|
3931
|
+
);
|
|
3932
|
+
}
|
|
3933
|
+
},
|
|
3934
|
+
/**
|
|
3935
|
+
* Ensures totalHits value from store is a positive integer.
|
|
3936
|
+
*
|
|
3937
|
+
* @param hits {any} - The `totalHits` returned by the store.
|
|
3938
|
+
*/
|
|
3939
|
+
positiveHits(hits) {
|
|
3940
|
+
if (typeof hits !== "number" || hits < 1 || hits !== Math.round(hits)) {
|
|
3941
|
+
throw new ValidationError(
|
|
3942
|
+
"ERR_ERL_INVALID_HITS",
|
|
3943
|
+
`The totalHits value returned from the store must be a positive integer, got ${hits}`
|
|
3944
|
+
);
|
|
3945
|
+
}
|
|
3946
|
+
},
|
|
3947
|
+
/**
|
|
3948
|
+
* Ensures a single store instance is not used with multiple express-rate-limit instances
|
|
3949
|
+
*/
|
|
3950
|
+
unsharedStore(store) {
|
|
3951
|
+
if (usedStores.has(store)) {
|
|
3952
|
+
const maybeUniquePrefix = store?.localKeys ? "" : " (with a unique prefix)";
|
|
3953
|
+
throw new ValidationError(
|
|
3954
|
+
"ERR_ERL_STORE_REUSE",
|
|
3955
|
+
`A Store instance must not be shared across multiple rate limiters. Create a new instance of ${store.constructor.name}${maybeUniquePrefix} for each limiter instead.`
|
|
3956
|
+
);
|
|
3957
|
+
}
|
|
3958
|
+
usedStores.add(store);
|
|
3959
|
+
},
|
|
3960
|
+
/**
|
|
3961
|
+
* Ensures a given key is incremented only once per request.
|
|
3962
|
+
*
|
|
3963
|
+
* @param request {Request} - The Express request object.
|
|
3964
|
+
* @param store {Store} - The store class.
|
|
3965
|
+
* @param key {string} - The key used to store the client's hit count.
|
|
3966
|
+
*
|
|
3967
|
+
* @returns {void}
|
|
3968
|
+
*/
|
|
3969
|
+
singleCount(request, store, key) {
|
|
3970
|
+
let storeKeys = singleCountKeys.get(request);
|
|
3971
|
+
if (!storeKeys) {
|
|
3972
|
+
storeKeys = /* @__PURE__ */ new Map();
|
|
3973
|
+
singleCountKeys.set(request, storeKeys);
|
|
3974
|
+
}
|
|
3975
|
+
const storeKey = store.localKeys ? store : store.constructor.name;
|
|
3976
|
+
let keys = storeKeys.get(storeKey);
|
|
3977
|
+
if (!keys) {
|
|
3978
|
+
keys = [];
|
|
3979
|
+
storeKeys.set(storeKey, keys);
|
|
3980
|
+
}
|
|
3981
|
+
const prefixedKey = `${store.prefix ?? ""}${key}`;
|
|
3982
|
+
if (keys.includes(prefixedKey)) {
|
|
3983
|
+
throw new ValidationError(
|
|
3984
|
+
"ERR_ERL_DOUBLE_COUNT",
|
|
3985
|
+
`The hit count for ${key} was incremented more than once for a single request.`
|
|
3986
|
+
);
|
|
3987
|
+
}
|
|
3988
|
+
keys.push(prefixedKey);
|
|
3989
|
+
},
|
|
3990
|
+
/**
|
|
3991
|
+
* Warns the user that the behaviour for `max: 0` / `limit: 0` is
|
|
3992
|
+
* changing in the next major release.
|
|
3993
|
+
*
|
|
3994
|
+
* @param limit {number} - The maximum number of hits per client.
|
|
3995
|
+
*
|
|
3996
|
+
* @returns {void}
|
|
3997
|
+
*/
|
|
3998
|
+
limit(limit) {
|
|
3999
|
+
if (limit === 0) {
|
|
4000
|
+
throw new ChangeWarning(
|
|
4001
|
+
"WRN_ERL_MAX_ZERO",
|
|
4002
|
+
"Setting limit or max to 0 disables rate limiting in express-rate-limit v6 and older, but will cause all requests to be blocked in v7"
|
|
4003
|
+
);
|
|
4004
|
+
}
|
|
4005
|
+
},
|
|
4006
|
+
/**
|
|
4007
|
+
* Warns the user that the `draft_polli_ratelimit_headers` option is deprecated
|
|
4008
|
+
* and will be removed in the next major release.
|
|
4009
|
+
*
|
|
4010
|
+
* @param draft_polli_ratelimit_headers {any | undefined} - The now-deprecated setting that was used to enable standard headers.
|
|
4011
|
+
*
|
|
4012
|
+
* @returns {void}
|
|
4013
|
+
*/
|
|
4014
|
+
draftPolliHeaders(draft_polli_ratelimit_headers) {
|
|
4015
|
+
if (draft_polli_ratelimit_headers) {
|
|
4016
|
+
throw new ChangeWarning(
|
|
4017
|
+
"WRN_ERL_DEPRECATED_DRAFT_POLLI_HEADERS",
|
|
4018
|
+
`The draft_polli_ratelimit_headers configuration option is deprecated and has been removed in express-rate-limit v7, please set standardHeaders: 'draft-6' instead.`
|
|
4019
|
+
);
|
|
4020
|
+
}
|
|
4021
|
+
},
|
|
4022
|
+
/**
|
|
4023
|
+
* Warns the user that the `onLimitReached` option is deprecated and
|
|
4024
|
+
* will be removed in the next major release.
|
|
4025
|
+
*
|
|
4026
|
+
* @param onLimitReached {any | undefined} - The maximum number of hits per client.
|
|
4027
|
+
*
|
|
4028
|
+
* @returns {void}
|
|
4029
|
+
*/
|
|
4030
|
+
onLimitReached(onLimitReached) {
|
|
4031
|
+
if (onLimitReached) {
|
|
4032
|
+
throw new ChangeWarning(
|
|
4033
|
+
"WRN_ERL_DEPRECATED_ON_LIMIT_REACHED",
|
|
4034
|
+
"The onLimitReached configuration option is deprecated and has been removed in express-rate-limit v7."
|
|
4035
|
+
);
|
|
4036
|
+
}
|
|
4037
|
+
},
|
|
4038
|
+
/**
|
|
4039
|
+
* Warns the user when an invalid/unsupported version of the draft spec is passed.
|
|
4040
|
+
*
|
|
4041
|
+
* @param version {any | undefined} - The version passed by the user.
|
|
4042
|
+
*
|
|
4043
|
+
* @returns {void}
|
|
4044
|
+
*/
|
|
4045
|
+
headersDraftVersion(version) {
|
|
4046
|
+
if (typeof version !== "string" || // @ts-expect-error This is fine. If version is not in the array, it will just return false.
|
|
4047
|
+
!SUPPORTED_DRAFT_VERSIONS.includes(version)) {
|
|
4048
|
+
const versionString = SUPPORTED_DRAFT_VERSIONS.join(", ");
|
|
4049
|
+
throw new ValidationError(
|
|
4050
|
+
"ERR_ERL_HEADERS_UNSUPPORTED_DRAFT_VERSION",
|
|
4051
|
+
`standardHeaders: only the following versions of the IETF draft specification are supported: ${versionString}.`
|
|
4052
|
+
);
|
|
4053
|
+
}
|
|
4054
|
+
},
|
|
4055
|
+
/**
|
|
4056
|
+
* Warns the user when the selected headers option requires a reset time but
|
|
4057
|
+
* the store does not provide one.
|
|
4058
|
+
*
|
|
4059
|
+
* @param resetTime {Date | undefined} - The timestamp when the client's hit count will be reset.
|
|
4060
|
+
*
|
|
4061
|
+
* @returns {void}
|
|
4062
|
+
*/
|
|
4063
|
+
headersResetTime(resetTime) {
|
|
4064
|
+
if (!resetTime) {
|
|
4065
|
+
throw new ValidationError(
|
|
4066
|
+
"ERR_ERL_HEADERS_NO_RESET",
|
|
4067
|
+
`standardHeaders: 'draft-7' requires a 'resetTime', but the store did not provide one. The 'windowMs' value will be used instead, which may cause clients to wait longer than necessary.`
|
|
4068
|
+
);
|
|
4069
|
+
}
|
|
4070
|
+
},
|
|
4071
|
+
/**
|
|
4072
|
+
* Checks the options.validate setting to ensure that only recognized
|
|
4073
|
+
* validations are enabled or disabled.
|
|
4074
|
+
*
|
|
4075
|
+
* If any unrecognized values are found, an error is logged that
|
|
4076
|
+
* includes the list of supported vaidations.
|
|
4077
|
+
*/
|
|
4078
|
+
validationsConfig() {
|
|
4079
|
+
const supportedValidations = Object.keys(this).filter(
|
|
4080
|
+
(k) => !["enabled", "disable"].includes(k)
|
|
4081
|
+
);
|
|
4082
|
+
supportedValidations.push("default");
|
|
4083
|
+
for (const key of Object.keys(this.enabled)) {
|
|
4084
|
+
if (!supportedValidations.includes(key)) {
|
|
4085
|
+
throw new ValidationError(
|
|
4086
|
+
"ERR_ERL_UNKNOWN_VALIDATION",
|
|
4087
|
+
`options.validate.${key} is not recognized. Supported validate options are: ${supportedValidations.join(
|
|
4088
|
+
", "
|
|
4089
|
+
)}.`
|
|
4090
|
+
);
|
|
4091
|
+
}
|
|
4092
|
+
}
|
|
4093
|
+
},
|
|
4094
|
+
/**
|
|
4095
|
+
* Checks to see if the instance was created inside of a request handler,
|
|
4096
|
+
* which would prevent it from working correctly, with the default memory
|
|
4097
|
+
* store (or any other store with localKeys.)
|
|
4098
|
+
*/
|
|
4099
|
+
creationStack(store) {
|
|
4100
|
+
const { stack } = new Error(
|
|
4101
|
+
"express-rate-limit validation check (set options.validate.creationStack=false to disable)"
|
|
4102
|
+
);
|
|
4103
|
+
if (stack?.includes("Layer.handle [as handle_request]") || // express v4
|
|
4104
|
+
stack?.includes("Layer.handleRequest")) {
|
|
4105
|
+
if (!store.localKeys) {
|
|
4106
|
+
throw new ValidationError(
|
|
4107
|
+
"ERR_ERL_CREATED_IN_REQUEST_HANDLER",
|
|
4108
|
+
"express-rate-limit instance should *usually* be created at app initialization, not when responding to a request."
|
|
4109
|
+
);
|
|
4110
|
+
}
|
|
4111
|
+
throw new ValidationError(
|
|
4112
|
+
"ERR_ERL_CREATED_IN_REQUEST_HANDLER",
|
|
4113
|
+
"express-rate-limit instance should be created at app initialization, not when responding to a request."
|
|
4114
|
+
);
|
|
4115
|
+
}
|
|
4116
|
+
},
|
|
4117
|
+
ipv6Subnet(ipv6Subnet) {
|
|
4118
|
+
if (ipv6Subnet === false) {
|
|
4119
|
+
return;
|
|
4120
|
+
}
|
|
4121
|
+
if (!Number.isInteger(ipv6Subnet) || ipv6Subnet < 32 || ipv6Subnet > 64) {
|
|
4122
|
+
throw new ValidationError(
|
|
4123
|
+
"ERR_ERL_IPV6_SUBNET",
|
|
4124
|
+
`Unexpected ipv6Subnet value: ${ipv6Subnet}. Expected an integer between 32 and 64 (usually 48-64).`
|
|
4125
|
+
);
|
|
4126
|
+
}
|
|
4127
|
+
},
|
|
4128
|
+
ipv6SubnetOrKeyGenerator(options) {
|
|
4129
|
+
if (options.ipv6Subnet !== void 0 && options.keyGenerator) {
|
|
4130
|
+
throw new ValidationError(
|
|
4131
|
+
"ERR_ERL_IPV6SUBNET_OR_KEYGENERATOR",
|
|
4132
|
+
`Incompatible options: the 'ipv6Subnet' option is ignored when a custom 'keyGenerator' function is also set.`
|
|
4133
|
+
);
|
|
4134
|
+
}
|
|
4135
|
+
},
|
|
4136
|
+
keyGeneratorIpFallback(keyGenerator) {
|
|
4137
|
+
if (!keyGenerator) {
|
|
4138
|
+
return;
|
|
4139
|
+
}
|
|
4140
|
+
const src = keyGenerator.toString();
|
|
4141
|
+
if ((src.includes("req.ip") || src.includes("request.ip")) && !src.includes("ipKeyGenerator")) {
|
|
4142
|
+
throw new ValidationError(
|
|
4143
|
+
"ERR_ERL_KEY_GEN_IPV6",
|
|
4144
|
+
"Custom keyGenerator appears to use request IP without calling the ipKeyGenerator helper function for IPv6 addresses. This could allow IPv6 users to bypass limits."
|
|
4145
|
+
);
|
|
4146
|
+
}
|
|
4147
|
+
},
|
|
4148
|
+
/**
|
|
4149
|
+
* Checks to see if the window duration is greater than 2^32 - 1. This is only
|
|
4150
|
+
* called by the default MemoryStore, since it uses Node's setInterval method.
|
|
4151
|
+
*
|
|
4152
|
+
* See https://nodejs.org/api/timers.html#setintervalcallback-delay-args.
|
|
4153
|
+
*/
|
|
4154
|
+
windowMs(windowMs) {
|
|
4155
|
+
const SET_TIMEOUT_MAX = 2 ** 31 - 1;
|
|
4156
|
+
if (typeof windowMs !== "number" || Number.isNaN(windowMs) || windowMs < 1 || windowMs > SET_TIMEOUT_MAX) {
|
|
4157
|
+
throw new ValidationError(
|
|
4158
|
+
"ERR_ERL_WINDOW_MS",
|
|
4159
|
+
`Invalid windowMs value: ${windowMs}${typeof windowMs !== "number" ? ` (${typeof windowMs})` : ""}, must be a number between 1 and ${SET_TIMEOUT_MAX} when using the default MemoryStore`
|
|
4160
|
+
);
|
|
4161
|
+
}
|
|
4162
|
+
}
|
|
4163
|
+
};
|
|
4164
|
+
var getValidations = (_enabled) => {
|
|
4165
|
+
let enabled;
|
|
4166
|
+
if (typeof _enabled === "boolean") {
|
|
4167
|
+
enabled = {
|
|
4168
|
+
default: _enabled
|
|
4169
|
+
};
|
|
4170
|
+
} else {
|
|
4171
|
+
enabled = {
|
|
4172
|
+
default: true,
|
|
4173
|
+
..._enabled
|
|
4174
|
+
};
|
|
4175
|
+
}
|
|
4176
|
+
const wrappedValidations = { enabled };
|
|
4177
|
+
for (const [name, validation] of Object.entries(validations)) {
|
|
4178
|
+
if (typeof validation === "function")
|
|
4179
|
+
wrappedValidations[name] = (...args) => {
|
|
4180
|
+
if (!(enabled[name] ?? enabled.default)) {
|
|
4181
|
+
return;
|
|
4182
|
+
}
|
|
4183
|
+
try {
|
|
4184
|
+
;
|
|
4185
|
+
validation.apply(
|
|
4186
|
+
wrappedValidations,
|
|
4187
|
+
args
|
|
4188
|
+
);
|
|
4189
|
+
} catch (error) {
|
|
4190
|
+
if (error instanceof ChangeWarning) console.warn(error);
|
|
4191
|
+
else console.error(error);
|
|
4192
|
+
}
|
|
4193
|
+
};
|
|
4194
|
+
}
|
|
4195
|
+
return wrappedValidations;
|
|
4196
|
+
};
|
|
4197
|
+
var isLegacyStore = (store) => (
|
|
4198
|
+
// Check that `incr` exists but `increment` does not - store authors might want
|
|
4199
|
+
// to keep both around for backwards compatibility.
|
|
4200
|
+
typeof store.incr === "function" && typeof store.increment !== "function"
|
|
4201
|
+
);
|
|
4202
|
+
var promisifyStore = (passedStore) => {
|
|
4203
|
+
if (!isLegacyStore(passedStore)) {
|
|
4204
|
+
return passedStore;
|
|
4205
|
+
}
|
|
4206
|
+
const legacyStore = passedStore;
|
|
4207
|
+
class PromisifiedStore {
|
|
4208
|
+
async increment(key) {
|
|
4209
|
+
return new Promise((resolve, reject) => {
|
|
4210
|
+
legacyStore.incr(
|
|
4211
|
+
key,
|
|
4212
|
+
(error, totalHits, resetTime) => {
|
|
4213
|
+
if (error) reject(error);
|
|
4214
|
+
resolve({ totalHits, resetTime });
|
|
4215
|
+
}
|
|
4216
|
+
);
|
|
4217
|
+
});
|
|
4218
|
+
}
|
|
4219
|
+
async decrement(key) {
|
|
4220
|
+
return legacyStore.decrement(key);
|
|
4221
|
+
}
|
|
4222
|
+
async resetKey(key) {
|
|
4223
|
+
return legacyStore.resetKey(key);
|
|
4224
|
+
}
|
|
4225
|
+
/* istanbul ignore next */
|
|
4226
|
+
async resetAll() {
|
|
4227
|
+
if (typeof legacyStore.resetAll === "function")
|
|
4228
|
+
return legacyStore.resetAll();
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
return new PromisifiedStore();
|
|
4232
|
+
};
|
|
4233
|
+
var getOptionsFromConfig = (config) => {
|
|
4234
|
+
const { validations: validations2, ...directlyPassableEntries } = config;
|
|
4235
|
+
return {
|
|
4236
|
+
...directlyPassableEntries,
|
|
4237
|
+
validate: validations2.enabled
|
|
4238
|
+
};
|
|
4239
|
+
};
|
|
4240
|
+
var parseOptions = (passedOptions) => {
|
|
4241
|
+
const notUndefinedOptions = omitUndefinedProperties(passedOptions);
|
|
4242
|
+
const validations2 = getValidations(notUndefinedOptions?.validate ?? true);
|
|
4243
|
+
validations2.validationsConfig();
|
|
4244
|
+
validations2.draftPolliHeaders(
|
|
4245
|
+
// @ts-expect-error see the note above.
|
|
4246
|
+
notUndefinedOptions.draft_polli_ratelimit_headers
|
|
4247
|
+
);
|
|
4248
|
+
validations2.onLimitReached(notUndefinedOptions.onLimitReached);
|
|
4249
|
+
if (notUndefinedOptions.ipv6Subnet !== void 0 && typeof notUndefinedOptions.ipv6Subnet !== "function") {
|
|
4250
|
+
validations2.ipv6Subnet(notUndefinedOptions.ipv6Subnet);
|
|
4251
|
+
}
|
|
4252
|
+
validations2.keyGeneratorIpFallback(notUndefinedOptions.keyGenerator);
|
|
4253
|
+
validations2.ipv6SubnetOrKeyGenerator(notUndefinedOptions);
|
|
4254
|
+
let standardHeaders = notUndefinedOptions.standardHeaders ?? false;
|
|
4255
|
+
if (standardHeaders === true) standardHeaders = "draft-6";
|
|
4256
|
+
const config = {
|
|
4257
|
+
windowMs: 60 * 1e3,
|
|
4258
|
+
limit: passedOptions.max ?? 5,
|
|
4259
|
+
// `max` is deprecated, but support it anyways.
|
|
4260
|
+
message: "Too many requests, please try again later.",
|
|
4261
|
+
statusCode: 429,
|
|
4262
|
+
legacyHeaders: passedOptions.headers ?? true,
|
|
4263
|
+
identifier(request, _response) {
|
|
4264
|
+
let duration = "";
|
|
4265
|
+
const property = config.requestPropertyName;
|
|
4266
|
+
const { limit } = request[property];
|
|
4267
|
+
const seconds = config.windowMs / 1e3;
|
|
4268
|
+
const minutes = config.windowMs / (1e3 * 60);
|
|
4269
|
+
const hours = config.windowMs / (1e3 * 60 * 60);
|
|
4270
|
+
const days = config.windowMs / (1e3 * 60 * 60 * 24);
|
|
4271
|
+
if (seconds < 60) duration = `${seconds}sec`;
|
|
4272
|
+
else if (minutes < 60) duration = `${minutes}min`;
|
|
4273
|
+
else if (hours < 24) duration = `${hours}hr${hours > 1 ? "s" : ""}`;
|
|
4274
|
+
else duration = `${days}day${days > 1 ? "s" : ""}`;
|
|
4275
|
+
return `${limit}-in-${duration}`;
|
|
4276
|
+
},
|
|
4277
|
+
requestPropertyName: "rateLimit",
|
|
4278
|
+
skipFailedRequests: false,
|
|
4279
|
+
skipSuccessfulRequests: false,
|
|
4280
|
+
requestWasSuccessful: (_request, response) => response.statusCode < 400,
|
|
4281
|
+
skip: (_request, _response) => false,
|
|
4282
|
+
async keyGenerator(request, response) {
|
|
4283
|
+
validations2.ip(request.ip);
|
|
4284
|
+
validations2.trustProxy(request);
|
|
4285
|
+
validations2.xForwardedForHeader(request);
|
|
4286
|
+
validations2.forwardedHeader(request);
|
|
4287
|
+
const ip = request.ip;
|
|
4288
|
+
let subnet = 56;
|
|
4289
|
+
if (isIPv62(ip)) {
|
|
4290
|
+
subnet = typeof config.ipv6Subnet === "function" ? await config.ipv6Subnet(request, response) : config.ipv6Subnet;
|
|
4291
|
+
if (typeof config.ipv6Subnet === "function")
|
|
4292
|
+
validations2.ipv6Subnet(subnet);
|
|
4293
|
+
}
|
|
4294
|
+
return ipKeyGenerator(ip, subnet);
|
|
4295
|
+
},
|
|
4296
|
+
ipv6Subnet: 56,
|
|
4297
|
+
async handler(request, response, _next, _optionsUsed) {
|
|
4298
|
+
response.status(config.statusCode);
|
|
4299
|
+
const message = typeof config.message === "function" ? await config.message(
|
|
4300
|
+
request,
|
|
4301
|
+
response
|
|
4302
|
+
) : config.message;
|
|
4303
|
+
if (!response.writableEnded) response.send(message);
|
|
4304
|
+
},
|
|
4305
|
+
passOnStoreError: false,
|
|
4306
|
+
// Allow the default options to be overridden by the passed options.
|
|
4307
|
+
...notUndefinedOptions,
|
|
4308
|
+
// `standardHeaders` is resolved into a draft version above, use that.
|
|
4309
|
+
standardHeaders,
|
|
4310
|
+
// Note that this field is declared after the user's options are spread in,
|
|
4311
|
+
// so that this field doesn't get overridden with an un-promisified store!
|
|
4312
|
+
store: promisifyStore(
|
|
4313
|
+
notUndefinedOptions.store ?? new MemoryStore(validations2)
|
|
4314
|
+
),
|
|
4315
|
+
// Print an error to the console if a few known misconfigurations are detected.
|
|
4316
|
+
validations: validations2
|
|
4317
|
+
};
|
|
4318
|
+
if (typeof config.store.increment !== "function" || typeof config.store.decrement !== "function" || typeof config.store.resetKey !== "function" || config.store.resetAll !== void 0 && typeof config.store.resetAll !== "function" || config.store.init !== void 0 && typeof config.store.init !== "function") {
|
|
4319
|
+
throw new TypeError(
|
|
4320
|
+
"An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface."
|
|
4321
|
+
);
|
|
4322
|
+
}
|
|
4323
|
+
return config;
|
|
4324
|
+
};
|
|
4325
|
+
var handleAsyncErrors = (fn) => async (request, response, next) => {
|
|
4326
|
+
try {
|
|
4327
|
+
await Promise.resolve(fn(request, response, next)).catch(next);
|
|
4328
|
+
} catch (error) {
|
|
4329
|
+
next(error);
|
|
4330
|
+
}
|
|
4331
|
+
};
|
|
4332
|
+
var rateLimit = (passedOptions) => {
|
|
4333
|
+
const config = parseOptions(passedOptions ?? {});
|
|
4334
|
+
const options = getOptionsFromConfig(config);
|
|
4335
|
+
config.validations.creationStack(config.store);
|
|
4336
|
+
config.validations.unsharedStore(config.store);
|
|
4337
|
+
if (typeof config.store.init === "function") config.store.init(options);
|
|
4338
|
+
const middleware = handleAsyncErrors(
|
|
4339
|
+
async (request, response, next) => {
|
|
4340
|
+
const skip = await config.skip(request, response);
|
|
4341
|
+
if (skip) {
|
|
4342
|
+
next();
|
|
4343
|
+
return;
|
|
4344
|
+
}
|
|
4345
|
+
const augmentedRequest = request;
|
|
4346
|
+
const key = await config.keyGenerator(request, response);
|
|
4347
|
+
let totalHits = 0;
|
|
4348
|
+
let resetTime;
|
|
4349
|
+
try {
|
|
4350
|
+
const incrementResult = await config.store.increment(key);
|
|
4351
|
+
totalHits = incrementResult.totalHits;
|
|
4352
|
+
resetTime = incrementResult.resetTime;
|
|
4353
|
+
} catch (error) {
|
|
4354
|
+
if (config.passOnStoreError) {
|
|
4355
|
+
console.error(
|
|
4356
|
+
"express-rate-limit: error from store, allowing request without rate-limiting.",
|
|
4357
|
+
error
|
|
4358
|
+
);
|
|
4359
|
+
next();
|
|
4360
|
+
return;
|
|
4361
|
+
}
|
|
4362
|
+
throw error;
|
|
4363
|
+
}
|
|
4364
|
+
config.validations.positiveHits(totalHits);
|
|
4365
|
+
config.validations.singleCount(request, config.store, key);
|
|
4366
|
+
const retrieveLimit = typeof config.limit === "function" ? config.limit(request, response) : config.limit;
|
|
4367
|
+
const limit = await retrieveLimit;
|
|
4368
|
+
config.validations.limit(limit);
|
|
4369
|
+
const info = {
|
|
4370
|
+
limit,
|
|
4371
|
+
used: totalHits,
|
|
4372
|
+
remaining: Math.max(limit - totalHits, 0),
|
|
4373
|
+
resetTime,
|
|
4374
|
+
key
|
|
4375
|
+
};
|
|
4376
|
+
Object.defineProperty(info, "current", {
|
|
4377
|
+
configurable: false,
|
|
4378
|
+
enumerable: false,
|
|
4379
|
+
value: totalHits
|
|
4380
|
+
});
|
|
4381
|
+
augmentedRequest[config.requestPropertyName] = info;
|
|
4382
|
+
if (config.legacyHeaders && !response.headersSent) {
|
|
4383
|
+
setLegacyHeaders(response, info);
|
|
4384
|
+
}
|
|
4385
|
+
if (config.standardHeaders && !response.headersSent) {
|
|
4386
|
+
switch (config.standardHeaders) {
|
|
4387
|
+
case "draft-6": {
|
|
4388
|
+
setDraft6Headers(response, info, config.windowMs);
|
|
4389
|
+
break;
|
|
4390
|
+
}
|
|
4391
|
+
case "draft-7": {
|
|
4392
|
+
config.validations.headersResetTime(info.resetTime);
|
|
4393
|
+
setDraft7Headers(response, info, config.windowMs);
|
|
4394
|
+
break;
|
|
4395
|
+
}
|
|
4396
|
+
case "draft-8": {
|
|
4397
|
+
const retrieveName = typeof config.identifier === "function" ? config.identifier(request, response) : config.identifier;
|
|
4398
|
+
const name = await retrieveName;
|
|
4399
|
+
config.validations.headersResetTime(info.resetTime);
|
|
4400
|
+
setDraft8Headers(response, info, config.windowMs, name, key);
|
|
4401
|
+
break;
|
|
4402
|
+
}
|
|
4403
|
+
default: {
|
|
4404
|
+
config.validations.headersDraftVersion(config.standardHeaders);
|
|
4405
|
+
break;
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
}
|
|
4409
|
+
if (config.skipFailedRequests || config.skipSuccessfulRequests) {
|
|
4410
|
+
let decremented = false;
|
|
4411
|
+
const decrementKey = async () => {
|
|
4412
|
+
if (!decremented) {
|
|
4413
|
+
await config.store.decrement(key);
|
|
4414
|
+
decremented = true;
|
|
4415
|
+
}
|
|
4416
|
+
};
|
|
4417
|
+
if (config.skipFailedRequests) {
|
|
4418
|
+
response.on("finish", async () => {
|
|
4419
|
+
if (!await config.requestWasSuccessful(request, response))
|
|
4420
|
+
await decrementKey();
|
|
4421
|
+
});
|
|
4422
|
+
response.on("close", async () => {
|
|
4423
|
+
if (!response.writableEnded) await decrementKey();
|
|
4424
|
+
});
|
|
4425
|
+
response.on("error", async () => {
|
|
4426
|
+
await decrementKey();
|
|
4427
|
+
});
|
|
4428
|
+
}
|
|
4429
|
+
if (config.skipSuccessfulRequests) {
|
|
4430
|
+
response.on("finish", async () => {
|
|
4431
|
+
if (await config.requestWasSuccessful(request, response))
|
|
4432
|
+
await decrementKey();
|
|
4433
|
+
});
|
|
4434
|
+
}
|
|
4435
|
+
}
|
|
4436
|
+
config.validations.disable();
|
|
4437
|
+
if (totalHits > limit) {
|
|
4438
|
+
if (config.legacyHeaders || config.standardHeaders) {
|
|
4439
|
+
setRetryAfterHeader(response, info, config.windowMs);
|
|
4440
|
+
}
|
|
4441
|
+
config.handler(request, response, next, options);
|
|
4442
|
+
return;
|
|
4443
|
+
}
|
|
4444
|
+
next();
|
|
4445
|
+
}
|
|
4446
|
+
);
|
|
4447
|
+
const getThrowFn = () => {
|
|
4448
|
+
throw new Error("The current store does not support the get/getKey method");
|
|
4449
|
+
};
|
|
4450
|
+
middleware.resetKey = config.store.resetKey.bind(config.store);
|
|
4451
|
+
middleware.getKey = typeof config.store.get === "function" ? config.store.get.bind(config.store) : getThrowFn;
|
|
4452
|
+
return middleware;
|
|
4453
|
+
};
|
|
4454
|
+
var rate_limit_default = rateLimit;
|
|
4455
|
+
|
|
4456
|
+
// cli/server/server.ts
|
|
4457
|
+
init_serverState();
|
|
4458
|
+
init_spreadsheetRoutes();
|
|
2049
4459
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3 } from "fs";
|
|
2050
4460
|
import { createServer as createHttpServer } from "http";
|
|
2051
4461
|
import { dirname as dirname2, join as join6 } from "path";
|
|
@@ -2662,16 +5072,23 @@ async function createServer(options) {
|
|
|
2662
5072
|
if (!existsSync4(controlSetDir)) {
|
|
2663
5073
|
mkdirSync3(controlSetDir, { recursive: true });
|
|
2664
5074
|
}
|
|
5075
|
+
const limiter = rate_limit_default({
|
|
5076
|
+
windowMs: 15 * 60 * 1e3,
|
|
5077
|
+
// 15 minutes
|
|
5078
|
+
max: 200
|
|
5079
|
+
// max requests per windowMs
|
|
5080
|
+
});
|
|
2665
5081
|
initializeServerState(controlSetDir);
|
|
2666
5082
|
await loadAllData();
|
|
2667
5083
|
const app = express2();
|
|
2668
5084
|
app.use(cors());
|
|
2669
5085
|
app.use(express2.json({ limit: "50mb" }));
|
|
5086
|
+
app.use(limiter);
|
|
2670
5087
|
const distPath = join6(__dirname, "../dist");
|
|
2671
5088
|
app.use(express2.static(distPath));
|
|
2672
5089
|
app.use("/api", spreadsheetRoutes_default);
|
|
2673
|
-
app.get("
|
|
2674
|
-
res.sendFile(
|
|
5090
|
+
app.get("/*splat", (req, res) => {
|
|
5091
|
+
res.sendFile("index.html", { root: distPath });
|
|
2675
5092
|
});
|
|
2676
5093
|
const httpServer = createHttpServer(app);
|
|
2677
5094
|
wsManager.initialize(httpServer);
|