pmcf 1.76.3 → 1.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/dns-utils.mjs +16 -0
- package/src/dns.mjs +19 -52
- package/src/service.mjs +23 -0
- package/types/dns-utils.d.mts +5 -0
- package/types/service.d.mts +4 -0
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function dnsFullName(name) {
|
|
2
|
+
return name.endsWith(".") ? name : name + ".";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function DNSRecord(key, type, ...values) {
|
|
6
|
+
values = values.map(v => (typeof v === "number" ? String(v).padStart(3) : v));
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
key,
|
|
10
|
+
toString: (maxKeyLength, ttl) =>
|
|
11
|
+
`${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
|
|
12
|
+
5,
|
|
13
|
+
" "
|
|
14
|
+
)} ${values.join(" ")}`
|
|
15
|
+
};
|
|
16
|
+
}
|
package/src/dns.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
normalizeIPAddress,
|
|
8
8
|
isLinkLocal
|
|
9
9
|
} from "./utils.mjs";
|
|
10
|
+
import { DNSRecord, dnsFullName } from "./dns-utils.mjs";
|
|
10
11
|
import { Base } from "./base.mjs";
|
|
11
12
|
import { addType } from "./types.mjs";
|
|
12
13
|
import { serviceAddresses } from "./service.mjs";
|
|
@@ -175,10 +176,6 @@ export class DNSService extends Base {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
function fullName(name) {
|
|
179
|
-
return name.endsWith(".") ? name : name + ".";
|
|
180
|
-
}
|
|
181
|
-
|
|
182
179
|
async function generateZoneDefs(dns, targetDir) {
|
|
183
180
|
const ttl = dns.recordTTL;
|
|
184
181
|
const updates = [Math.ceil(Date.now() / 1000), ...dns.soaUpdates].join(" ");
|
|
@@ -192,24 +189,9 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
192
189
|
|
|
193
190
|
let maxKeyLength;
|
|
194
191
|
|
|
195
|
-
const createRecord = (key, type, ...values) => {
|
|
196
|
-
values = values.map(v =>
|
|
197
|
-
typeof v === "number" ? String(v).padStart(3) : v
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
key,
|
|
202
|
-
toString: () =>
|
|
203
|
-
`${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
|
|
204
|
-
5,
|
|
205
|
-
" "
|
|
206
|
-
)} ${values.join(" ")}`
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
|
|
210
192
|
for (const mail of dns.owner.findServices({ type: "smtp" })) {
|
|
211
193
|
records.add(
|
|
212
|
-
|
|
194
|
+
DNSRecord("@", "MX", mail.priority, dnsFullName(mail.domainName))
|
|
213
195
|
);
|
|
214
196
|
}
|
|
215
197
|
|
|
@@ -217,21 +199,21 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
217
199
|
//console.log(dns.owner.fullName, domain, nameService.domainName, rname);
|
|
218
200
|
const reverseZones = new Map();
|
|
219
201
|
|
|
220
|
-
const SOARecord =
|
|
202
|
+
const SOARecord = DNSRecord(
|
|
221
203
|
"@",
|
|
222
204
|
"SOA",
|
|
223
|
-
|
|
224
|
-
|
|
205
|
+
dnsFullName(nameService.domainName),
|
|
206
|
+
dnsFullName(rname),
|
|
225
207
|
`(${updates})`
|
|
226
208
|
);
|
|
227
209
|
|
|
228
|
-
const NSRecord =
|
|
210
|
+
const NSRecord = DNSRecord(
|
|
229
211
|
"@",
|
|
230
212
|
"NS",
|
|
231
|
-
|
|
213
|
+
dnsFullName(nameService.ipAddressOrDomainName)
|
|
232
214
|
);
|
|
233
215
|
|
|
234
|
-
const ALPNRecord =
|
|
216
|
+
const ALPNRecord = DNSRecord("@", "HTTPS", 1, ".", "alpn=h3");
|
|
235
217
|
|
|
236
218
|
const zone = {
|
|
237
219
|
id: domain,
|
|
@@ -248,7 +230,7 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
248
230
|
records: new Set([
|
|
249
231
|
SOARecord,
|
|
250
232
|
NSRecord,
|
|
251
|
-
|
|
233
|
+
DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
|
|
252
234
|
])
|
|
253
235
|
};
|
|
254
236
|
|
|
@@ -280,8 +262,8 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
280
262
|
addresses.add(address);
|
|
281
263
|
|
|
282
264
|
zone.records.add(
|
|
283
|
-
|
|
284
|
-
|
|
265
|
+
DNSRecord(
|
|
266
|
+
dnsFullName(domainName),
|
|
285
267
|
isIPv6Address(address) ? "AAAA" : "A",
|
|
286
268
|
normalizeIPAddress(address)
|
|
287
269
|
)
|
|
@@ -303,10 +285,10 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
303
285
|
|
|
304
286
|
for (const domainName of host.domainNames) {
|
|
305
287
|
reverseZone.records.add(
|
|
306
|
-
|
|
307
|
-
|
|
288
|
+
DNSRecord(
|
|
289
|
+
dnsFullName(reverseArpaAddress(address)),
|
|
308
290
|
"PTR",
|
|
309
|
-
|
|
291
|
+
dnsFullName(domainName)
|
|
310
292
|
)
|
|
311
293
|
);
|
|
312
294
|
}
|
|
@@ -316,23 +298,8 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
316
298
|
if (!hosts.has(host)) {
|
|
317
299
|
hosts.add(host);
|
|
318
300
|
for (const service of host.findServices()) {
|
|
319
|
-
|
|
320
|
-
zone.records.add(
|
|
321
|
-
createRecord(service.alias, "CNAME", fullName(domainName))
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (dns.hasSVRRecords && service.srvPrefix) {
|
|
326
|
-
zone.records.add(
|
|
327
|
-
createRecord(
|
|
328
|
-
fullName(`${service.srvPrefix}.${domainName}`),
|
|
329
|
-
"SRV",
|
|
330
|
-
service.priority,
|
|
331
|
-
service.weight,
|
|
332
|
-
service.port,
|
|
333
|
-
fullName(host.domainName)
|
|
334
|
-
)
|
|
335
|
-
);
|
|
301
|
+
for (const record of service.dnsRecordsForDomainName(domainName, dns.hasSVRRecords)) {
|
|
302
|
+
zone.records.add(record);
|
|
336
303
|
}
|
|
337
304
|
}
|
|
338
305
|
}
|
|
@@ -345,10 +312,10 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
345
312
|
if (zone.type !== "catalog") {
|
|
346
313
|
const hash = createHmac("md5", zone.id).digest("hex");
|
|
347
314
|
catalogZone.records.add(
|
|
348
|
-
|
|
315
|
+
DNSRecord(
|
|
349
316
|
`${hash}.zones.catalog.${domain}.`,
|
|
350
317
|
"PTR",
|
|
351
|
-
|
|
318
|
+
dnsFullName(zone.id)
|
|
352
319
|
)
|
|
353
320
|
);
|
|
354
321
|
}
|
|
@@ -376,7 +343,7 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
376
343
|
await writeLines(
|
|
377
344
|
join(targetDir, "var/lib/named"),
|
|
378
345
|
zone.file,
|
|
379
|
-
zone.records
|
|
346
|
+
[...zone.records].map(r => r.toString(maxKeyLength, ttl))
|
|
380
347
|
);
|
|
381
348
|
}
|
|
382
349
|
|
package/src/service.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { Base } from "./base.mjs";
|
|
|
2
2
|
import { addType } from "./types.mjs";
|
|
3
3
|
import { asArray } from "./utils.mjs";
|
|
4
4
|
import { networkAddressProperties } from "./network-support.mjs";
|
|
5
|
+
import { DNSRecord, dnsFullName } from "./dns-utils.mjs";
|
|
5
6
|
|
|
6
7
|
const ServiceTypes = {
|
|
7
8
|
dns: { protocol: "udp", port: 53, tls: false },
|
|
@@ -176,6 +177,28 @@ export class Service extends Base {
|
|
|
176
177
|
return `_${this.type}._${st.protocol}`;
|
|
177
178
|
}
|
|
178
179
|
}
|
|
180
|
+
|
|
181
|
+
dnsRecordsForDomainName(domainName, hasSVRRecords) {
|
|
182
|
+
const records = [];
|
|
183
|
+
if (this.master && this.alias) {
|
|
184
|
+
records.push(DNSRecord(this.alias, "CNAME", dnsFullName(domainName)));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (hasSVRRecords && this.srvPrefix) {
|
|
188
|
+
records.push(
|
|
189
|
+
DNSRecord(
|
|
190
|
+
dnsFullName(`${this.srvPrefix}.${domainName}`),
|
|
191
|
+
"SRV",
|
|
192
|
+
this.priority,
|
|
193
|
+
this.weight,
|
|
194
|
+
this.port,
|
|
195
|
+
dnsFullName(this.domainName)
|
|
196
|
+
)
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return records;
|
|
201
|
+
}
|
|
179
202
|
}
|
|
180
203
|
|
|
181
204
|
export const sortByPriority = (a, b) => a.priority - b.priority;
|
package/types/service.d.mts
CHANGED
|
@@ -134,6 +134,10 @@ export class Service extends Base {
|
|
|
134
134
|
get protocol(): any;
|
|
135
135
|
get tls(): any;
|
|
136
136
|
get srvPrefix(): string;
|
|
137
|
+
dnsRecordsForDomainName(domainName: any, hasSVRRecords: any): {
|
|
138
|
+
key: any;
|
|
139
|
+
toString: (maxKeyLength: any, ttl: any) => string;
|
|
140
|
+
}[];
|
|
137
141
|
#private;
|
|
138
142
|
}
|
|
139
143
|
export function sortByPriority(a: any, b: any): number;
|