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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.38.1",
3
+ "version": "2.39.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -59,7 +59,7 @@ export class SkeletonNetworkInterface extends ServiceOwner {
59
59
  }
60
60
 
61
61
  get network() {
62
- return this.extendedProperty("_network") ?? this.host.network;
62
+ return this.extendedProperty("_network") ?? this.host?.network;
63
63
  }
64
64
 
65
65
  set network(network) {
@@ -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(this, location, packageData);
284
+ await this.generateZoneDefs(location, packageData);
278
285
 
279
286
  yield packageData;
280
287
  }
281
- }
282
288
 
283
- async function generateZoneDefs(dns, location, packageData) {
284
- const ttl = dns.recordTTL;
285
- const nameService = dns.findService({ type: "dns", priority: "<10" });
286
- const rname = dns.administratorEmail.replace(/@/, ".");
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
- const SOARecord = DNSRecord(
289
- "@",
290
- "SOA",
291
- dnsFullName(nameService.domainName),
292
- dnsFullName(rname),
293
- `(${[...dns.soaUpdates].join(" ")})`
294
- );
302
+ const NSRecord = DNSRecord(
303
+ "@",
304
+ "NS",
305
+ dnsFullName(nameService.ipAddressOrDomainName)
306
+ );
295
307
 
296
- const NSRecord = DNSRecord(
297
- "@",
298
- "NS",
299
- dnsFullName(nameService.ipAddressOrDomainName)
300
- );
308
+ console.log(`${nameService}`, nameService.ipAddressOrDomainName);
301
309
 
302
- console.log(`${nameService}`, nameService.ipAddressOrDomainName);
310
+ const configs = [];
303
311
 
304
- const configs = [];
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
- for (const host of location.hosts()) {
307
- for (const domain of host.foreignDomainNames) {
308
- const zone = {
309
- id: domain,
310
- file: `FOREIGN/${domain}.zone`,
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
- zone.records.add(DNSRecord("location", "TXT", host.location.name));
326
+ if (this.hasLocationRecord) {
327
+ zone.records.add(DNSRecord("location", "TXT", host.location.name));
328
+ }
321
329
 
322
- for (const na of host.networkAddresses(
323
- na => na.networkInterface.kind != "loopback"
324
- )) {
325
- zone.records.add(
326
- DNSRecord("@", dnsRecordTypeForAddressFamily(na.family), na.address)
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
- const foreignZones = configs.map(c => c.zones).flat();
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
- if (foreignZones.length) {
335
- addHook(
336
- packageData.properties.hooks,
337
- "post_upgrade",
338
- `rm -f ${foreignZones.map(zone => `/var/lib/named/${zone.file}.jnl`)}\n` +
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
- console.log(
346
- "LOCAL DOMAINS",
347
- location.localDomains,
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
- for (const domain of location.localDomains) {
353
- const locationName = location.name;
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(catalogConfig);
377
-
378
- zone.catalogZone = {
379
- id: `catalog.${domain}`,
380
- file: `${locationName}/catalog.${domain}.zone`,
381
- records: new Set([
382
- SOARecord,
383
- NSRecord,
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
- catalogConfig.zones.push(zone.catalogZone);
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
- const hosts = new Set();
391
- const addresses = new Set();
392
-
393
- for await (const {
394
- address,
395
- subnet,
396
- networkInterface,
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
- !addresses.has(address) &&
407
- (dns.hasLinkLocalAdresses || !isLinkLocal(address))
411
+ !this.exclude.has(networkInterface.network) &&
412
+ !this.excludeInterfaceKinds.has(networkInterface.kind)
408
413
  ) {
409
- addresses.add(address);
410
-
411
- for (const domainName of domainNames) {
412
- zone.records.add(
413
- DNSRecord(
414
- dnsFullName(domainName),
415
- dnsRecordTypeForAddressFamily(family),
416
- address
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(reverseArpa(address)),
439
- "PTR",
440
- dnsFullName(domainName)
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
- if (!hosts.has(host)) {
448
- hosts.add(host);
457
+ if (!hosts.has(host)) {
458
+ hosts.add(host);
449
459
 
450
- for (const foreignDomainName of host.foreignDomainNames) {
451
- zone.records.add(
452
- DNSRecord("outfacing", "PTR", dnsFullName(foreignDomainName))
453
- );
454
- }
460
+ for (const foreignDomainName of host.foreignDomainNames) {
461
+ zone.records.add(
462
+ DNSRecord("outfacing", "PTR", dnsFullName(foreignDomainName))
463
+ );
464
+ }
455
465
 
456
- for (const service of host.findServices()) {
457
- for (const record of service.dnsRecordsForDomainName(
458
- host.domainName,
459
- dns.hasSVRRecords
460
- )) {
461
- zone.records.add(record);
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
- for (const config of configs) {
470
- console.log(`config: ${config.name}`);
471
-
472
- const content = [];
473
- for (const zone of config.zones) {
474
- console.log(` file: ${zone.file}`);
475
-
476
- if (zone.catalogZone) {
477
- const hash = createHmac("md5", zone.id).digest("hex");
478
- zone.catalogZone.records.add(
479
- DNSRecord(
480
- `${hash}.zones.catalog.${zone.id}.`,
481
- "PTR",
482
- dnsFullName(zone.id)
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
- content.push(`zone \"${zone.id}\" {`);
488
- content.push(` type master;`);
489
- content.push(` file \"${zone.file}\";`);
497
+ content.push(`zone \"${zone.id}\" {`);
498
+ content.push(` type master;`);
499
+ content.push(` file \"${zone.file}\";`);
490
500
 
491
- content.push(
492
- ` allow-update { ${
493
- dns.allowedUpdates.length ? dns.allowedUpdates.join(";") : "none"
494
- }; };`
495
- );
496
- content.push(` notify ${dns.notify ? "yes" : "no"};`);
497
- content.push(`};`);
498
- content.push("");
499
-
500
- let maxKeyLength = 0;
501
- for (const r of zone.records) {
502
- if (r.key.length > maxKeyLength) {
503
- maxKeyLength = r.key.length;
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, "var/lib/named"),
509
- zone.file,
510
- [...zone.records]
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
  }
@@ -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";