pmcf 2.38.1 → 2.39.1
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/network-interfaces/skeleton.mjs +1 -1
- package/src/services/dns.mjs +209 -198
- package/types/services/dns.d.mts +8 -0
package/package.json
CHANGED
package/src/services/dns.mjs
CHANGED
|
@@ -54,6 +54,12 @@ const DNSServiceTypeDefinition = {
|
|
|
54
54
|
writeable: true,
|
|
55
55
|
default: false
|
|
56
56
|
},
|
|
57
|
+
hasLocationRecord: {
|
|
58
|
+
type: "boolean",
|
|
59
|
+
collection: false,
|
|
60
|
+
writeable: true,
|
|
61
|
+
default: true
|
|
62
|
+
},
|
|
57
63
|
excludeInterfaceKinds: {
|
|
58
64
|
type: "string",
|
|
59
65
|
collection: true,
|
|
@@ -107,6 +113,7 @@ export class DNSService extends ExtraSourceService {
|
|
|
107
113
|
hasSVRRecords = true;
|
|
108
114
|
hasCatalog = true;
|
|
109
115
|
hasLinkLocalAdresses = true;
|
|
116
|
+
hasLocationRecord = true;
|
|
110
117
|
notify = true;
|
|
111
118
|
_trusted = [];
|
|
112
119
|
_protected = [];
|
|
@@ -274,249 +281,253 @@ export class DNSService extends ExtraSourceService {
|
|
|
274
281
|
)
|
|
275
282
|
];
|
|
276
283
|
|
|
277
|
-
await generateZoneDefs(
|
|
284
|
+
await this.generateZoneDefs(location, packageData);
|
|
278
285
|
|
|
279
286
|
yield packageData;
|
|
280
287
|
}
|
|
281
|
-
}
|
|
282
288
|
|
|
283
|
-
async
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
289
|
+
async generateZoneDefs(location, packageData) {
|
|
290
|
+
const ttl = this.recordTTL;
|
|
291
|
+
const nameService = this.findService({ type: "dns", priority: "<10" });
|
|
292
|
+
const rname = this.administratorEmail.replace(/@/, ".");
|
|
293
|
+
|
|
294
|
+
const SOARecord = DNSRecord(
|
|
295
|
+
"@",
|
|
296
|
+
"SOA",
|
|
297
|
+
dnsFullName(nameService.domainName),
|
|
298
|
+
dnsFullName(rname),
|
|
299
|
+
`(${[...this.soaUpdates].join(" ")})`
|
|
300
|
+
);
|
|
287
301
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
`(${[...dns.soaUpdates].join(" ")})`
|
|
294
|
-
);
|
|
302
|
+
const NSRecord = DNSRecord(
|
|
303
|
+
"@",
|
|
304
|
+
"NS",
|
|
305
|
+
dnsFullName(nameService.ipAddressOrDomainName)
|
|
306
|
+
);
|
|
295
307
|
|
|
296
|
-
|
|
297
|
-
"@",
|
|
298
|
-
"NS",
|
|
299
|
-
dnsFullName(nameService.ipAddressOrDomainName)
|
|
300
|
-
);
|
|
308
|
+
console.log(`${nameService}`, nameService.ipAddressOrDomainName);
|
|
301
309
|
|
|
302
|
-
|
|
310
|
+
const configs = [];
|
|
303
311
|
|
|
304
|
-
|
|
312
|
+
for (const host of location.hosts()) {
|
|
313
|
+
for (const domain of host.foreignDomainNames) {
|
|
314
|
+
const zone = {
|
|
315
|
+
id: domain,
|
|
316
|
+
file: `FOREIGN/${domain}.zone`,
|
|
317
|
+
records: new Set([SOARecord, NSRecord])
|
|
318
|
+
};
|
|
305
319
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
records: new Set([SOARecord, NSRecord])
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
const config = {
|
|
315
|
-
name: `${domain}.zone.conf`,
|
|
316
|
-
zones: [zone]
|
|
317
|
-
};
|
|
318
|
-
configs.push(config);
|
|
320
|
+
const config = {
|
|
321
|
+
name: `${domain}.zone.conf`,
|
|
322
|
+
zones: [zone]
|
|
323
|
+
};
|
|
324
|
+
configs.push(config);
|
|
319
325
|
|
|
320
|
-
|
|
326
|
+
if (this.hasLocationRecord) {
|
|
327
|
+
zone.records.add(DNSRecord("location", "TXT", host.location.name));
|
|
328
|
+
}
|
|
321
329
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
330
|
+
for (const na of host.networkAddresses(
|
|
331
|
+
na => na.networkInterface.kind != "loopback"
|
|
332
|
+
)) {
|
|
333
|
+
zone.records.add(
|
|
334
|
+
DNSRecord("@", dnsRecordTypeForAddressFamily(na.family), na.address)
|
|
335
|
+
);
|
|
336
|
+
}
|
|
328
337
|
}
|
|
329
338
|
}
|
|
330
|
-
}
|
|
331
339
|
|
|
332
|
-
|
|
340
|
+
const foreignZones = configs.map(c => c.zones).flat();
|
|
341
|
+
|
|
342
|
+
if (foreignZones.length) {
|
|
343
|
+
addHook(
|
|
344
|
+
packageData.properties.hooks,
|
|
345
|
+
"post_upgrade",
|
|
346
|
+
`rm -f ${foreignZones.map(
|
|
347
|
+
zone => `/var/lib/named/${zone.file}.jnl`
|
|
348
|
+
)}\n` +
|
|
349
|
+
`/usr/bin/named-hostname-info ${foreignZones
|
|
350
|
+
.map(zone => zone.id)
|
|
351
|
+
.join(" ")}|/usr/bin/named-hostname-update`
|
|
352
|
+
);
|
|
353
|
+
}
|
|
333
354
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
`/usr/bin/named-hostname-info ${foreignZones
|
|
340
|
-
.map(zone => zone.id)
|
|
341
|
-
.join(" ")}|/usr/bin/named-hostname-update`
|
|
355
|
+
console.log(
|
|
356
|
+
"LOCAL DOMAINS",
|
|
357
|
+
location.localDomains,
|
|
358
|
+
location.domain,
|
|
359
|
+
location.toString()
|
|
342
360
|
);
|
|
343
|
-
}
|
|
344
361
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
location.domain,
|
|
349
|
-
location.toString()
|
|
350
|
-
);
|
|
362
|
+
for (const domain of location.localDomains) {
|
|
363
|
+
const locationName = location.name;
|
|
364
|
+
const reverseZones = new Map();
|
|
351
365
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const reverseZones = new Map();
|
|
355
|
-
|
|
356
|
-
const config = {
|
|
357
|
-
name: `${domain}.zone.conf`,
|
|
358
|
-
zones: []
|
|
359
|
-
};
|
|
360
|
-
configs.push(config);
|
|
361
|
-
|
|
362
|
-
const locationRecord = DNSRecord("location", "TXT", locationName);
|
|
363
|
-
|
|
364
|
-
const zone = {
|
|
365
|
-
id: domain,
|
|
366
|
-
file: `${locationName}/${domain}.zone`,
|
|
367
|
-
records: new Set([SOARecord, NSRecord, locationRecord])
|
|
368
|
-
};
|
|
369
|
-
config.zones.push(zone);
|
|
370
|
-
|
|
371
|
-
if (dns.hasCatalog) {
|
|
372
|
-
const catalogConfig = {
|
|
373
|
-
name: `catalog.${domain}.zone.conf`,
|
|
366
|
+
const config = {
|
|
367
|
+
name: `${domain}.zone.conf`,
|
|
374
368
|
zones: []
|
|
375
369
|
};
|
|
376
|
-
configs.push(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
|
|
385
|
-
])
|
|
370
|
+
configs.push(config);
|
|
371
|
+
|
|
372
|
+
const locationRecord = DNSRecord("location", "TXT", locationName);
|
|
373
|
+
|
|
374
|
+
const zone = {
|
|
375
|
+
id: domain,
|
|
376
|
+
file: `${locationName}/${domain}.zone`,
|
|
377
|
+
records: new Set([SOARecord, NSRecord, locationRecord])
|
|
386
378
|
};
|
|
387
|
-
|
|
388
|
-
|
|
379
|
+
config.zones.push(zone);
|
|
380
|
+
|
|
381
|
+
if (this.hasCatalog) {
|
|
382
|
+
const catalogConfig = {
|
|
383
|
+
name: `catalog.${domain}.zone.conf`,
|
|
384
|
+
zones: []
|
|
385
|
+
};
|
|
386
|
+
configs.push(catalogConfig);
|
|
387
|
+
|
|
388
|
+
zone.catalogZone = {
|
|
389
|
+
id: `catalog.${domain}`,
|
|
390
|
+
file: `${locationName}/catalog.${domain}.zone`,
|
|
391
|
+
records: new Set([
|
|
392
|
+
SOARecord,
|
|
393
|
+
NSRecord,
|
|
394
|
+
DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
|
|
395
|
+
])
|
|
396
|
+
};
|
|
397
|
+
catalogConfig.zones.push(zone.catalogZone);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const hosts = new Set();
|
|
401
|
+
const addresses = new Set();
|
|
389
402
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
domainNames,
|
|
398
|
-
family
|
|
399
|
-
} of location.networkAddresses()) {
|
|
400
|
-
if (
|
|
401
|
-
!dns.exclude.has(networkInterface.network) &&
|
|
402
|
-
!dns.excludeInterfaceKinds.has(networkInterface.kind)
|
|
403
|
-
) {
|
|
404
|
-
const host = networkInterface.host;
|
|
403
|
+
for await (const {
|
|
404
|
+
address,
|
|
405
|
+
subnet,
|
|
406
|
+
networkInterface,
|
|
407
|
+
domainNames,
|
|
408
|
+
family
|
|
409
|
+
} of location.networkAddresses()) {
|
|
405
410
|
if (
|
|
406
|
-
!
|
|
407
|
-
(
|
|
411
|
+
!this.exclude.has(networkInterface.network) &&
|
|
412
|
+
!this.excludeInterfaceKinds.has(networkInterface.kind)
|
|
408
413
|
) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
if (subnet && host.domain === domain) {
|
|
421
|
-
let reverseZone = reverseZones.get(subnet.address);
|
|
422
|
-
|
|
423
|
-
if (!reverseZone) {
|
|
424
|
-
const id = reverseArpa(subnet.prefix);
|
|
425
|
-
reverseZone = {
|
|
426
|
-
id,
|
|
427
|
-
type: "plain",
|
|
428
|
-
file: `${locationName}/${id}.zone`,
|
|
429
|
-
records: new Set([SOARecord, NSRecord])
|
|
430
|
-
};
|
|
431
|
-
config.zones.push(reverseZone);
|
|
432
|
-
reverseZones.set(subnet.address, reverseZone);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
for (const domainName of host.domainNames) {
|
|
436
|
-
reverseZone.records.add(
|
|
414
|
+
const host = networkInterface.host;
|
|
415
|
+
if (
|
|
416
|
+
!addresses.has(address) &&
|
|
417
|
+
(this.hasLinkLocalAdresses || !isLinkLocal(address))
|
|
418
|
+
) {
|
|
419
|
+
addresses.add(address);
|
|
420
|
+
|
|
421
|
+
for (const domainName of domainNames) {
|
|
422
|
+
zone.records.add(
|
|
437
423
|
DNSRecord(
|
|
438
|
-
dnsFullName(
|
|
439
|
-
|
|
440
|
-
|
|
424
|
+
dnsFullName(domainName),
|
|
425
|
+
dnsRecordTypeForAddressFamily(family),
|
|
426
|
+
address
|
|
441
427
|
)
|
|
442
428
|
);
|
|
443
429
|
}
|
|
430
|
+
if (subnet && host.domain === domain) {
|
|
431
|
+
let reverseZone = reverseZones.get(subnet.address);
|
|
432
|
+
|
|
433
|
+
if (!reverseZone) {
|
|
434
|
+
const id = reverseArpa(subnet.prefix);
|
|
435
|
+
reverseZone = {
|
|
436
|
+
id,
|
|
437
|
+
type: "plain",
|
|
438
|
+
file: `${locationName}/${id}.zone`,
|
|
439
|
+
records: new Set([SOARecord, NSRecord])
|
|
440
|
+
};
|
|
441
|
+
config.zones.push(reverseZone);
|
|
442
|
+
reverseZones.set(subnet.address, reverseZone);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
for (const domainName of host.domainNames) {
|
|
446
|
+
reverseZone.records.add(
|
|
447
|
+
DNSRecord(
|
|
448
|
+
dnsFullName(reverseArpa(address)),
|
|
449
|
+
"PTR",
|
|
450
|
+
dnsFullName(domainName)
|
|
451
|
+
)
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
444
455
|
}
|
|
445
|
-
}
|
|
446
456
|
|
|
447
|
-
|
|
448
|
-
|
|
457
|
+
if (!hosts.has(host)) {
|
|
458
|
+
hosts.add(host);
|
|
449
459
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
460
|
+
for (const foreignDomainName of host.foreignDomainNames) {
|
|
461
|
+
zone.records.add(
|
|
462
|
+
DNSRecord("outfacing", "PTR", dnsFullName(foreignDomainName))
|
|
463
|
+
);
|
|
464
|
+
}
|
|
455
465
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
466
|
+
for (const service of host.findServices()) {
|
|
467
|
+
for (const record of service.dnsRecordsForDomainName(
|
|
468
|
+
host.domainName,
|
|
469
|
+
this.hasSVRRecords
|
|
470
|
+
)) {
|
|
471
|
+
zone.records.add(record);
|
|
472
|
+
}
|
|
462
473
|
}
|
|
463
474
|
}
|
|
464
475
|
}
|
|
465
476
|
}
|
|
466
477
|
}
|
|
467
|
-
}
|
|
468
478
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
479
|
+
for (const config of configs) {
|
|
480
|
+
console.log(`config: ${config.name}`);
|
|
481
|
+
|
|
482
|
+
const content = [];
|
|
483
|
+
for (const zone of config.zones) {
|
|
484
|
+
console.log(` file: ${zone.file}`);
|
|
485
|
+
|
|
486
|
+
if (zone.catalogZone) {
|
|
487
|
+
const hash = createHmac("md5", zone.id).digest("hex");
|
|
488
|
+
zone.catalogZone.records.add(
|
|
489
|
+
DNSRecord(
|
|
490
|
+
`${hash}.zones.catalog.${zone.id}.`,
|
|
491
|
+
"PTR",
|
|
492
|
+
dnsFullName(zone.id)
|
|
493
|
+
)
|
|
494
|
+
);
|
|
495
|
+
}
|
|
486
496
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
497
|
+
content.push(`zone \"${zone.id}\" {`);
|
|
498
|
+
content.push(` type master;`);
|
|
499
|
+
content.push(` file \"${zone.file}\";`);
|
|
490
500
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
501
|
+
content.push(
|
|
502
|
+
` allow-update { ${
|
|
503
|
+
this.allowedUpdates.length ? this.allowedUpdates.join(";") : "none"
|
|
504
|
+
}; };`
|
|
505
|
+
);
|
|
506
|
+
content.push(` notify ${this.notify ? "yes" : "no"};`);
|
|
507
|
+
content.push(`};`);
|
|
508
|
+
content.push("");
|
|
509
|
+
|
|
510
|
+
let maxKeyLength = 0;
|
|
511
|
+
for (const r of zone.records) {
|
|
512
|
+
if (r.key.length > maxKeyLength) {
|
|
513
|
+
maxKeyLength = r.key.length;
|
|
514
|
+
}
|
|
504
515
|
}
|
|
516
|
+
|
|
517
|
+
await writeLines(
|
|
518
|
+
join(packageData.dir, "var/lib/named"),
|
|
519
|
+
zone.file,
|
|
520
|
+
[...zone.records]
|
|
521
|
+
.sort(sortZoneRecords)
|
|
522
|
+
.map(r => r.toString(maxKeyLength, ttl))
|
|
523
|
+
);
|
|
505
524
|
}
|
|
506
525
|
|
|
507
526
|
await writeLines(
|
|
508
|
-
join(packageData.dir, "
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
.sort(sortZoneRecords)
|
|
512
|
-
.map(r => r.toString(maxKeyLength, ttl))
|
|
527
|
+
join(packageData.dir, "etc/named/zones"),
|
|
528
|
+
config.name,
|
|
529
|
+
content
|
|
513
530
|
);
|
|
514
531
|
}
|
|
515
|
-
|
|
516
|
-
await writeLines(
|
|
517
|
-
join(packageData.dir, "etc/named/zones"),
|
|
518
|
-
config.name,
|
|
519
|
-
content
|
|
520
|
-
);
|
|
521
532
|
}
|
|
522
533
|
}
|
package/types/services/dns.d.mts
CHANGED
|
@@ -287,6 +287,12 @@ export class DNSService extends ExtraSourceService {
|
|
|
287
287
|
writeable: boolean;
|
|
288
288
|
default: boolean;
|
|
289
289
|
};
|
|
290
|
+
hasLocationRecord: {
|
|
291
|
+
type: string;
|
|
292
|
+
collection: boolean;
|
|
293
|
+
writeable: boolean;
|
|
294
|
+
default: boolean;
|
|
295
|
+
};
|
|
290
296
|
excludeInterfaceKinds: {
|
|
291
297
|
type: string;
|
|
292
298
|
collection: boolean;
|
|
@@ -345,6 +351,7 @@ export class DNSService extends ExtraSourceService {
|
|
|
345
351
|
hasSVRRecords: boolean;
|
|
346
352
|
hasCatalog: boolean;
|
|
347
353
|
hasLinkLocalAdresses: boolean;
|
|
354
|
+
hasLocationRecord: boolean;
|
|
348
355
|
notify: boolean;
|
|
349
356
|
_trusted: any[];
|
|
350
357
|
_protected: any[];
|
|
@@ -377,6 +384,7 @@ export class DNSService extends ExtraSourceService {
|
|
|
377
384
|
access: string;
|
|
378
385
|
};
|
|
379
386
|
}, void, unknown>;
|
|
387
|
+
generateZoneDefs(location: any, packageData: any): Promise<void>;
|
|
380
388
|
}
|
|
381
389
|
import { ExtraSourceService } from "pmcf";
|
|
382
390
|
import { FileContentProvider } from "npm-pkgbuild";
|