pmcf 1.81.1 → 1.82.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.81.1",
3
+ "version": "1.82.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns-utils.mjs CHANGED
@@ -5,7 +5,11 @@ export function dnsFullName(name) {
5
5
  }
6
6
 
7
7
  export function DNSRecord(key, type, ...values) {
8
- values = values.map(v => (typeof v === "number" ? String(v).padStart(3) : v));
8
+ const pad = type === "MX" ? " " : "";
9
+
10
+ values = values.map(v =>
11
+ typeof v === "number" ? String(v).padStart(3) + pad : v
12
+ );
9
13
 
10
14
  return {
11
15
  key,
@@ -23,7 +27,8 @@ export function dnsFormatParameters(parameters) {
23
27
  value !== undefined && [...asIterator(value)].length > 0
24
28
  ? `${name}="${[...asIterator(value)].join(",")}"`
25
29
  : name
26
- ).sort((a,b)=>a[0].localeCompare(b[0]))
30
+ )
31
+ .sort((a, b) => a[0].localeCompare(b[0]))
27
32
  .join(" ");
28
33
  }
29
34
 
package/src/dns.mjs CHANGED
@@ -184,63 +184,86 @@ export class DNSService extends Base {
184
184
  async function generateZoneDefs(dns, targetDir) {
185
185
  const ttl = dns.recordTTL;
186
186
  const updates = [Math.ceil(Date.now() / 1000), ...dns.soaUpdates].join(" ");
187
+ const nameService = dns.findService(DNS_SERVICE_FILTER);
188
+ const rname = dns.administratorEmail.replace(/@/, ".");
189
+
190
+ const SOARecord = DNSRecord(
191
+ "@",
192
+ "SOA",
193
+ dnsFullName(nameService.domainName),
194
+ dnsFullName(rname),
195
+ `(${updates})`
196
+ );
187
197
 
188
- for (const domain of dns.domains) {
189
- const isLocalDomain = dns.localDomains.has(domain);
190
-
191
- const ownerName = isLocalDomain ? dns.owner.name : "FOREIGN";
192
- const zones = [];
193
- const records = new Set();
194
-
195
- const nameService = dns.findService(DNS_SERVICE_FILTER);
196
- const rname = dns.administratorEmail.replace(/@/, ".");
198
+ const NSRecord = DNSRecord(
199
+ "@",
200
+ "NS",
201
+ dnsFullName(nameService.ipAddressOrDomainName)
202
+ );
197
203
 
198
- let maxKeyLength;
204
+ console.log(`${nameService}`, nameService.ipAddressOrDomainName);
205
+
206
+ const configs = [];
207
+
208
+ for (const host of dns.owner.hosts()) {
209
+ for (const domain of host.foreignDomainNames) {
210
+ const zone = {
211
+ id: domain,
212
+ file: `FOREIGN/${domain}.zone`,
213
+ records: new Set([SOARecord, NSRecord])
214
+ };
215
+ const config = {
216
+ name: `${domain}.zone.conf`,
217
+ zones: [zone]
218
+ };
219
+ configs.push(config);
220
+
221
+ for (const address of host.rawAddresses) {
222
+ zone.records.add(
223
+ DNSRecord(
224
+ "@",
225
+ isIPv6Address(address) ? "AAAA" : "A",
226
+ normalizeIPAddress(address)
227
+ )
228
+ );
229
+ }
230
+ }
231
+ }
199
232
 
200
- console.log(`${nameService} ${domain}`, nameService.ipAddressOrDomainName);
201
- //console.log(dns.owner.fullName, domain, nameService.domainName, rname);
233
+ for (const domain of dns.localDomains) {
234
+ const ownerName = dns.owner.name;
202
235
  const reverseZones = new Map();
203
236
 
204
- const SOARecord = DNSRecord(
205
- "@",
206
- "SOA",
207
- dnsFullName(nameService.domainName),
208
- dnsFullName(rname),
209
- `(${updates})`
210
- );
211
-
212
- const NSRecord = DNSRecord(
213
- "@",
214
- "NS",
215
- dnsFullName(nameService.ipAddressOrDomainName)
216
- );
237
+ const config = {
238
+ name: `${domain}.zone.conf`,
239
+ zones: []
240
+ };
241
+ configs.push(config);
217
242
 
218
243
  const zone = {
219
244
  id: domain,
220
- type: "plain",
221
245
  file: `${ownerName}/${domain}.zone`,
222
- records: new Set([SOARecord, NSRecord, ...records])
223
- };
224
- zones.push(zone);
225
-
226
- const catalogZone = {
227
- id: `catalog.${domain}`,
228
- type: "catalog",
229
- file: `${ownerName}/catalog.${domain}.zone`,
230
- records: new Set([
231
- SOARecord,
232
- NSRecord,
233
- DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
234
- ])
235
- };
236
-
237
- const configs = {
238
- plain: { name: `${domain}.zone.conf`, content: [] }
246
+ records: new Set([SOARecord, NSRecord])
239
247
  };
240
-
241
- if (isLocalDomain && dns.hasCatalog) {
242
- zones.push(catalogZone);
243
- configs.catalog = { name: `catalog.${domain}.zone.conf`, content: [] };
248
+ config.zones.push(zone);
249
+
250
+ if (dns.hasCatalog) {
251
+ const catalogConfig = {
252
+ name: `catalog.${domain}.zone.conf`,
253
+ zones: []
254
+ };
255
+ configs.push(catalogConfig);
256
+
257
+ zone.catalogZone = {
258
+ id: `catalog.${domain}`,
259
+ file: `${ownerName}/catalog.${domain}.zone`,
260
+ records: new Set([
261
+ SOARecord,
262
+ NSRecord,
263
+ DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
264
+ ])
265
+ };
266
+ catalogConfig.zones.push(zone.catalogZone);
244
267
  }
245
268
 
246
269
  const hosts = new Set();
@@ -279,7 +302,7 @@ async function generateZoneDefs(dns, targetDir) {
279
302
  file: `${ownerName}/${reverseArpa}.zone`,
280
303
  records: new Set([SOARecord, NSRecord])
281
304
  };
282
- zones.push(reverseZone);
305
+ config.zones.push(reverseZone);
283
306
  reverseZones.set(subnet.address, reverseZone);
284
307
  }
285
308
 
@@ -295,7 +318,7 @@ async function generateZoneDefs(dns, targetDir) {
295
318
  }
296
319
  }
297
320
 
298
- if (isLocalDomain && !hosts.has(host)) {
321
+ if (!hosts.has(host)) {
299
322
  hosts.add(host);
300
323
  for (const service of host.findServices()) {
301
324
  for (const record of service.dnsRecordsForDomainName(
@@ -308,15 +331,20 @@ async function generateZoneDefs(dns, targetDir) {
308
331
  }
309
332
  }
310
333
  }
334
+ }
311
335
 
312
- for (const zone of zones) {
313
- const content = configs[zone.type].content;
336
+ for (const config of configs) {
337
+ console.log(`config: ${config.name}`);
314
338
 
315
- if (zone.type !== "catalog") {
339
+ const content = [];
340
+ for (const zone of config.zones) {
341
+ console.log(` zone: ${zone.id}`);
342
+
343
+ if (zone.catalogZone) {
316
344
  const hash = createHmac("md5", zone.id).digest("hex");
317
- catalogZone.records.add(
345
+ zone.catalogZone.records.add(
318
346
  DNSRecord(
319
- `${hash}.zones.catalog.${domain}.`,
347
+ `${hash}.zones.catalog.${zone.id}.`,
320
348
  "PTR",
321
349
  dnsFullName(zone.id)
322
350
  )
@@ -336,7 +364,7 @@ async function generateZoneDefs(dns, targetDir) {
336
364
  content.push(`};`);
337
365
  content.push("");
338
366
 
339
- maxKeyLength = 0;
367
+ let maxKeyLength = 0;
340
368
  for (const r of zone.records) {
341
369
  if (r.key.length > maxKeyLength) {
342
370
  maxKeyLength = r.key.length;
@@ -350,13 +378,11 @@ async function generateZoneDefs(dns, targetDir) {
350
378
  );
351
379
  }
352
380
 
353
- for (const cfg of Object.values(configs)) {
354
- await writeLines(
355
- join(targetDir, "etc/named.d/zones"),
356
- cfg.name,
357
- cfg.content
358
- );
359
- }
381
+ await writeLines(
382
+ join(targetDir, "etc/named.d/zones"),
383
+ config.name,
384
+ content
385
+ );
360
386
  }
361
387
  }
362
388
 
package/src/host.mjs CHANGED
@@ -254,10 +254,18 @@ export class Host extends Base {
254
254
  return parts[parts.length - 1];
255
255
  }
256
256
 
257
- get domains() {
257
+ get foreignDomainNames() {
258
+ return [...this.aliases].filter(n => n.split(".").length > 1);
259
+ }
260
+
261
+ get foreignDomains() {
258
262
  return new Set(
259
263
  [...this.aliases].map(n => domainFromDominName(n, this.domain))
260
- ).union(this.localDomains);
264
+ );
265
+ }
266
+
267
+ get domains() {
268
+ return this.foreignDomains.union(this.localDomains);
261
269
  }
262
270
 
263
271
  get domainNames() {
package/types/host.d.mts CHANGED
@@ -185,6 +185,8 @@ export class Host extends Base {
185
185
  get distribution(): any;
186
186
  get modelName(): any;
187
187
  get hostName(): string;
188
+ get foreignDomainNames(): any[];
189
+ get foreignDomains(): Set<any>;
188
190
  get domains(): Set<any>;
189
191
  get domainNames(): any[];
190
192
  get domainName(): any;