pmcf 1.25.0 → 1.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/bin/pmcf-location-defs +2 -25
- package/bin/pmcf-named-defs +11 -17
- package/package.json +1 -1
- package/src/dns.mjs +24 -0
- package/src/model.mjs +4 -5
- package/src/utils.mjs +13 -0
- package/types/dns.d.mts +8 -0
- package/types/utils.d.mts +1 -0
package/bin/pmcf-location-defs
CHANGED
|
@@ -22,33 +22,10 @@ console.log("replaces", `mf-location-${location.name}`);
|
|
|
22
22
|
console.log("description", `location definitions for ${location.name}`);
|
|
23
23
|
|
|
24
24
|
async function generateLocationDefs(location, dir) {
|
|
25
|
-
const dns = location.dns;
|
|
26
|
-
const dnsServices = (await Array.fromAsync(dns.services())).sort(
|
|
27
|
-
(a, b) => a.priority - b.priority
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
console.log(dnsServices);
|
|
31
|
-
|
|
32
|
-
const master = dnsServices
|
|
33
|
-
.filter(s => s.priority < 10)
|
|
34
|
-
.map(s => s.ipAddresses)
|
|
35
|
-
.flat();
|
|
36
|
-
const fallback = dnsServices
|
|
37
|
-
.filter(s => s.priority >= 10)
|
|
38
|
-
.map(s => s.ipAddresses)
|
|
39
|
-
.flat();
|
|
40
|
-
|
|
41
25
|
await writeLines(
|
|
42
26
|
join(dir, "etc/systemd/resolved.conf.d"),
|
|
43
27
|
`${location.name}.conf`,
|
|
44
|
-
sectionLines("Resolve",
|
|
45
|
-
DNS: master.join(" "),
|
|
46
|
-
FallbackDNS: fallback.join(" "),
|
|
47
|
-
Domains: dns.domains.join(" "),
|
|
48
|
-
DNSSEC: "no",
|
|
49
|
-
MulticastDNS: "yes",
|
|
50
|
-
LLMNR: "no"
|
|
51
|
-
})
|
|
28
|
+
sectionLines("Resolve", await location.dns.resolvedConfig())
|
|
52
29
|
);
|
|
53
30
|
|
|
54
31
|
await writeLines(
|
|
@@ -75,7 +52,7 @@ async function generateLocationDefs(location, dir) {
|
|
|
75
52
|
|
|
76
53
|
await mkdir(locationDir, { recursive: true });
|
|
77
54
|
|
|
78
|
-
copyFile(
|
|
55
|
+
await copyFile(
|
|
79
56
|
join(location.directory, "location.json"),
|
|
80
57
|
join(locationDir, "location.json")
|
|
81
58
|
);
|
package/bin/pmcf-named-defs
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { createHmac } from "node:crypto";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
writeLines,
|
|
7
|
+
isIPv4Address,
|
|
8
|
+
normalizeIPAddress
|
|
9
|
+
} from "../src/utils.mjs";
|
|
6
10
|
import { prepare } from "../src/cmd.mjs";
|
|
7
11
|
|
|
8
12
|
const { world, args, options } = prepare();
|
|
@@ -38,10 +42,13 @@ async function generateNamedDefs(owner, targetDir) {
|
|
|
38
42
|
const createRecord = (key, type, value) => {
|
|
39
43
|
return {
|
|
40
44
|
key,
|
|
41
|
-
|
|
42
|
-
value
|
|
45
|
+
/*type,
|
|
46
|
+
value,*/
|
|
43
47
|
toString: () =>
|
|
44
|
-
`${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
|
|
48
|
+
`${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
|
|
49
|
+
5,
|
|
50
|
+
" "
|
|
51
|
+
)} ${value}`
|
|
45
52
|
};
|
|
46
53
|
};
|
|
47
54
|
|
|
@@ -201,16 +208,3 @@ export function reverseArpaAddress(address) {
|
|
|
201
208
|
(isIPv4Address(address) ? ".in-addr.arpa" : ".ip6.arpa")
|
|
202
209
|
);
|
|
203
210
|
}
|
|
204
|
-
|
|
205
|
-
export function normalizeIPAddress(address) {
|
|
206
|
-
if (isIPv4Address(address)) {
|
|
207
|
-
return address;
|
|
208
|
-
}
|
|
209
|
-
address = address.replace(/\/\d+$/, "");
|
|
210
|
-
const parts = address.split(":");
|
|
211
|
-
const i = parts.indexOf("");
|
|
212
|
-
if (i >= 0) {
|
|
213
|
-
parts.splice(i, 1, ..."0".repeat(9 - parts.length));
|
|
214
|
-
}
|
|
215
|
-
return parts.map(s => s.padStart(4, "0")).join(":");
|
|
216
|
-
}
|
package/package.json
CHANGED
package/src/dns.mjs
CHANGED
|
@@ -33,4 +33,28 @@ export class DNSService extends Base {
|
|
|
33
33
|
get propertyNames() {
|
|
34
34
|
return ["recordTTL", "forwardsTo", "allowedUpdates"];
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
async resolvedConfig() {
|
|
38
|
+
const dnsServices = (await Array.fromAsync(this.services())).sort(
|
|
39
|
+
(a, b) => a.priority - b.priority
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const master = dnsServices
|
|
43
|
+
.filter(s => s.priority < 10)
|
|
44
|
+
.map(s => s.ipAddresses)
|
|
45
|
+
.flat();
|
|
46
|
+
const fallback = dnsServices
|
|
47
|
+
.filter(s => s.priority >= 10)
|
|
48
|
+
.map(s => s.ipAddresses)
|
|
49
|
+
.flat();
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
DNS: master.join(" "),
|
|
53
|
+
FallbackDNS: fallback.join(" "),
|
|
54
|
+
Domains: this.domains.join(" "),
|
|
55
|
+
DNSSEC: "no",
|
|
56
|
+
MulticastDNS: "yes",
|
|
57
|
+
LLMNR: "no"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
36
60
|
}
|
package/src/model.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import {
|
|
|
4
4
|
asArray,
|
|
5
5
|
bridgeToJSON,
|
|
6
6
|
isIPv4Address,
|
|
7
|
-
isIPv6Address
|
|
7
|
+
isIPv6Address,
|
|
8
|
+
normalizeIPAddress
|
|
8
9
|
} from "./utils.mjs";
|
|
9
10
|
import { Base } from "./base.mjs";
|
|
10
11
|
import { Service } from "./service.mjs";
|
|
@@ -659,13 +660,11 @@ export class Host extends Base {
|
|
|
659
660
|
}
|
|
660
661
|
|
|
661
662
|
get ipAddresses() {
|
|
662
|
-
return [...this.networkAddresses()].map(na => na.address);
|
|
663
|
+
return [...this.networkAddresses()].map(na => normalizeIPAddress(na.address));
|
|
663
664
|
}
|
|
664
665
|
|
|
665
666
|
get ipAddress() {
|
|
666
|
-
|
|
667
|
-
return a.address;
|
|
668
|
-
}
|
|
667
|
+
return this.ipAddresses[0];
|
|
669
668
|
}
|
|
670
669
|
|
|
671
670
|
async publicKey(type = "ed25519") {
|
package/src/utils.mjs
CHANGED
|
@@ -39,3 +39,16 @@ export function isIPv4Address(address) {
|
|
|
39
39
|
export function isIPv6Address(address) {
|
|
40
40
|
return address.indexOf(":") >= 0;
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
export function normalizeIPAddress(address) {
|
|
44
|
+
address = address.replace(/\/\d+$/, "");
|
|
45
|
+
if (isIPv4Address(address)) {
|
|
46
|
+
return address;
|
|
47
|
+
}
|
|
48
|
+
const parts = address.split(":");
|
|
49
|
+
const i = parts.indexOf("");
|
|
50
|
+
if (i >= 0) {
|
|
51
|
+
parts.splice(i, 1, ..."0".repeat(9 - parts.length));
|
|
52
|
+
}
|
|
53
|
+
return parts.map(s => s.padStart(4, "0")).join(":");
|
|
54
|
+
}
|
package/types/dns.d.mts
CHANGED
|
@@ -4,5 +4,13 @@ export class DNSService extends Base {
|
|
|
4
4
|
forwardsTo: any[];
|
|
5
5
|
services(): AsyncGenerator<any, void, any>;
|
|
6
6
|
get domains(): any[];
|
|
7
|
+
resolvedConfig(): Promise<{
|
|
8
|
+
DNS: string;
|
|
9
|
+
FallbackDNS: string;
|
|
10
|
+
Domains: string;
|
|
11
|
+
DNSSEC: string;
|
|
12
|
+
MulticastDNS: string;
|
|
13
|
+
LLMNR: string;
|
|
14
|
+
}>;
|
|
7
15
|
}
|
|
8
16
|
import { Base } from "./base.mjs";
|
package/types/utils.d.mts
CHANGED