pmcf 2.24.3 → 2.26.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/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  ## Poor mans configuration management
16
16
 
17
+
17
18
  # API
18
19
 
19
20
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.24.3",
3
+ "version": "2.26.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dns-utils.mjs CHANGED
@@ -1,14 +1,51 @@
1
1
  import { decodeIPv4, decodeIPv6 } from "ip-utilties";
2
2
  import { asIterator } from "./utils.mjs";
3
3
 
4
+ const typeOrder = {
5
+ SOA: 0,
6
+ NS: 1,
7
+ MX: 2,
8
+ A: 3,
9
+ AAAA: 3,
10
+ CNAME: 4,
11
+ PTR: 5,
12
+ HTTPS: 6,
13
+ SRV: 7,
14
+ TXT: 8
15
+ };
16
+
17
+ export function sortZoneRecords(a, b) {
18
+ let order = typeOrder[a.type] - typeOrder[b.type];
19
+ if (order) {
20
+ return order;
21
+ }
22
+
23
+ if (a.type === "PTR") {
24
+ const toNum = a => {
25
+ const s = a.split(".");
26
+ s.pop();s.pop();s.pop();
27
+ return s.reverse().reduce((a, c) => BigInt(parseInt(c,16)) + 256n * 256n * a, 0n);
28
+ };
29
+ return Number(toNum(a.key) - toNum(b.key));
30
+ }
31
+ order = a.key.localeCompare(b.key);
32
+ if(order) {
33
+ return order;
34
+ }
35
+
36
+ return a.values[0] - b.values[0];
37
+ }
38
+
4
39
  export function dnsFullName(name) {
5
40
  return name.endsWith(".") ? name : name + ".";
6
41
  }
7
42
 
8
43
  export function dnsRecordTypeForAddressFamily(family) {
9
- switch(family) {
10
- case 'IPv4': return "A";
11
- case 'IPv6': return "AAAA";
44
+ switch (family) {
45
+ case "IPv4":
46
+ return "A";
47
+ case "IPv6":
48
+ return "AAAA";
12
49
  }
13
50
  }
14
51
 
@@ -33,7 +70,9 @@ export function DNSRecord(key, type, ...values) {
33
70
  );
34
71
 
35
72
  return {
73
+ type,
36
74
  key,
75
+ values,
37
76
  toString: (maxKeyLength = 0, ttl = "1W") =>
38
77
  `${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
39
78
  5,
package/src/endpoint.mjs CHANGED
@@ -1,9 +1,7 @@
1
- import { familyIP } from "ip-utilties";
2
-
3
1
  export class Endpoint {
4
- constructor(service, networkInterface, data) {
2
+ constructor(service, networkAddress, data) {
5
3
  this.service = service;
6
- this.networkInterface = networkInterface;
4
+ this.networkAddress = networkAddress;
7
5
  Object.assign(this, data);
8
6
  }
9
7
 
@@ -16,13 +14,13 @@ export class Endpoint {
16
14
  }
17
15
 
18
16
  get hostName() {
19
- return this.networkInterface.hostName;
17
+ return this.networkAddress.networkInterface.hostName;
20
18
  }
21
19
 
22
20
  #address;
23
21
 
24
22
  get address() {
25
- return this.#address ?? this.networkInterface.address;
23
+ return this.#address ?? this.networkAddress.address;
26
24
  }
27
25
 
28
26
  set address(value) {
@@ -30,6 +28,10 @@ export class Endpoint {
30
28
  }
31
29
 
32
30
  get family() {
33
- return familyIP(this.address);
31
+ return this.networkAddress.family;
32
+ }
33
+
34
+ get networkInterface() {
35
+ return this.networkAddress.networkInterface;
34
36
  }
35
37
  }
package/src/service.mjs CHANGED
@@ -189,12 +189,11 @@ export class Service extends Base {
189
189
  ];
190
190
 
191
191
  const result = [...this.server.networkAddresses()]
192
- .map(sa =>
192
+ .map(na =>
193
193
  data.map(
194
194
  d =>
195
- new Endpoint(this, sa.networkInterface, {
195
+ new Endpoint(this, na, {
196
196
  ...d,
197
- address: sa.address,
198
197
  ...local
199
198
  })
200
199
  )
@@ -19,7 +19,6 @@ const DHCPServiceTypeDefinition = {
19
19
  };
20
20
 
21
21
  const controlAgentEndpoint = {
22
- // extends: ["http"],
23
22
  type: "kea-control-agent",
24
23
  port: 8000,
25
24
  protocol: "tcp",
@@ -52,17 +51,16 @@ export class DHCPService extends Service {
52
51
  }
53
52
 
54
53
  endpoints(filter) {
55
- const l0 = this.server.findNetworkInterface({ scope: "host" });
54
+ const endpoints = super.endpoints(filter);
56
55
 
57
- if (l0) {
58
- return [
59
- ...super.endpoints(filter),
60
- new Endpoint(this, l0, controlAgentEndpoint),
61
- new Endpoint(this, l0, ddnsEndpoint)
62
- ];
56
+ for (const na of this.server.networkAddresses(
57
+ na => na.networkInterface.kind === "localhost"
58
+ )) {
59
+ endpoints.push(new Endpoint(this, na, controlAgentEndpoint));
60
+ endpoints.push(new Endpoint(this, na, ddnsEndpoint));
63
61
  }
64
62
 
65
- return super.endpoints(filter);
63
+ return endpoints;
66
64
  }
67
65
 
68
66
  async *preparePackages(dir) {
@@ -256,7 +254,7 @@ export class DHCPService extends Service {
256
254
  }
257
255
  ],
258
256
  subnet4: [...subnets]
259
- .filter(s => s.family==='IPv4')
257
+ .filter(s => s.family === "IPv4")
260
258
  .map((subnet, index) => {
261
259
  return {
262
260
  id: index + 1,
@@ -295,30 +293,29 @@ export class DHCPService extends Service {
295
293
  .join(",")
296
294
  }
297
295
  ],
298
- subnet6: [
299
- {
300
- id: 1,
301
- subnet: "2001:db8:1::/64",
302
- pools: [
303
- {
304
- pool: "2001:db8:1::/80"
305
- }
306
- ],
307
- "pd-pools": [
308
- {
309
- prefix: "2001:db8:8::",
310
- "prefix-len": 56,
311
- "delegated-len": 64
312
- }
313
- ],
314
- reservations: [
315
- {
316
- duid: "01:02:03:04:05:0A:0B:0C:0D:0E",
317
- "ip-addresses": ["2001:db8:1::100"]
318
- }
319
- ]
320
- }
321
- ],
296
+ subnet6: [...subnets]
297
+ .filter(s => s.family === "IPv6")
298
+ .map((subnet, index) => {
299
+ return {
300
+ id: index + 1,
301
+ subnet: subnet.longAddress,
302
+ pools: [{ pool: subnet.addressRange.join(" - ") }],
303
+
304
+ "pd-pools": [
305
+ {
306
+ prefix: "2001:db8:8::",
307
+ "prefix-len": 56,
308
+ "delegated-len": 64
309
+ }
310
+ ],
311
+ reservations: [
312
+ {
313
+ duid: "01:02:03:04:05:0A:0B:0C:0D:0E",
314
+ "ip-addresses": ["2001:db8:1::100"]
315
+ }
316
+ ]
317
+ };
318
+ }),
322
319
  "dhcp-ddns": dhcpServerDdns,
323
320
  loggers
324
321
  }
@@ -6,7 +6,8 @@ import { writeLines } from "../utils.mjs";
6
6
  import {
7
7
  DNSRecord,
8
8
  dnsFullName,
9
- dnsRecordTypeForAddressFamily
9
+ dnsRecordTypeForAddressFamily,
10
+ sortZoneRecords
10
11
  } from "../dns-utils.mjs";
11
12
  import { addType } from "../types.mjs";
12
13
  import { ServiceTypeDefinition, serviceAddresses } from "../service.mjs";
@@ -481,7 +482,9 @@ async function generateZoneDefs(dns, location, packageData) {
481
482
  await writeLines(
482
483
  join(packageData.dir, "var/lib/named"),
483
484
  zone.file,
484
- [...zone.records].map(r => r.toString(maxKeyLength, ttl))
485
+ [...zone.records]
486
+ .sort(sortZoneRecords)
487
+ .map(r => r.toString(maxKeyLength, ttl))
485
488
  );
486
489
  }
487
490
 
@@ -85,10 +85,14 @@ export class NTPService extends ExtraSourceService {
85
85
  };
86
86
 
87
87
  const lines = [
88
- ...serviceEndpoints(this, {
89
- ...NTP_SERVICE_FILTER,
90
- priority: ">=10"
91
- }).map(
88
+ ...serviceEndpoints(
89
+ this,
90
+ {
91
+ ...NTP_SERVICE_FILTER,
92
+ priority: ">=10"
93
+ },
94
+ e => e.family === 'IPv4' && e.networkInterface.kind !== "loopback"
95
+ ).map(
92
96
  endpoint =>
93
97
  `${endpoint.service.isPool ? "pool" : "server"} ${
94
98
  endpoint.address
@@ -1,7 +1,10 @@
1
+ export function sortZoneRecords(a: any, b: any): number;
1
2
  export function dnsFullName(name: any): any;
2
3
  export function dnsRecordTypeForAddressFamily(family: any): "A" | "AAAA";
3
4
  export function DNSRecord(key: any, type: any, ...values: any[]): {
5
+ type: any;
4
6
  key: any;
7
+ values: any[];
5
8
  toString: (maxKeyLength?: number, ttl?: string) => string;
6
9
  };
7
10
  export function dnsFormatParameters(parameters: any): string;
@@ -1,12 +1,13 @@
1
1
  export class Endpoint {
2
- constructor(service: any, networkInterface: any, data: any);
2
+ constructor(service: any, networkAddress: any, data: any);
3
3
  service: any;
4
- networkInterface: any;
4
+ networkAddress: any;
5
5
  toString(): string;
6
6
  get socketAddress(): string;
7
7
  get hostName(): any;
8
8
  set address(value: any);
9
9
  get address(): any;
10
10
  get family(): any;
11
+ get networkInterface(): any;
11
12
  #private;
12
13
  }
@@ -325,7 +325,9 @@ export class Service extends Base {
325
325
  get type(): any;
326
326
  get systemdServices(): any;
327
327
  dnsRecordsForDomainName(domainName: any, hasSVRRecords: any): {
328
+ type: any;
328
329
  key: any;
330
+ values: any[];
329
331
  toString: (maxKeyLength?: number, ttl?: string) => string;
330
332
  }[];
331
333
  }