pmcf 1.23.3 → 1.23.4
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-named-defs +55 -57
- package/package.json +1 -1
- package/src/base.mjs +4 -0
- package/types/base.d.mts +1 -0
- package/types/model.d.mts +0 -1
package/bin/pmcf-named-defs
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { createHmac } from "node:crypto";
|
|
5
|
-
import { Location } from "pmcf";
|
|
6
5
|
import { writeLines, isIPv4Address } from "../src/utils.mjs";
|
|
7
6
|
import { prepare } from "../src/cmd.mjs";
|
|
8
7
|
|
|
9
8
|
const { world, args, options } = prepare();
|
|
10
9
|
|
|
11
|
-
const
|
|
10
|
+
const owner = await world.load(args[0]);
|
|
12
11
|
const updates = [
|
|
13
12
|
Math.ceil(Date.now() / 1000),
|
|
14
13
|
36000,
|
|
@@ -19,77 +18,74 @@ const updates = [
|
|
|
19
18
|
|
|
20
19
|
const NAME_LEN = 35;
|
|
21
20
|
|
|
22
|
-
await generateNamedDefs(
|
|
21
|
+
await generateNamedDefs(owner, options.output);
|
|
23
22
|
|
|
24
23
|
console.log("depends", "mf-named");
|
|
25
24
|
console.log("replaces", "mf-named-zones");
|
|
26
|
-
console.log("description", `named defintions for ${
|
|
25
|
+
console.log("description", `named defintions for ${owner.name}`);
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}*/
|
|
31
|
-
|
|
32
|
-
async function generateNamedDefs(location, targetDir) {
|
|
33
|
-
const dns = location.dns;
|
|
27
|
+
async function generateNamedDefs(owner, targetDir) {
|
|
28
|
+
const dns = owner.dns;
|
|
34
29
|
const ttl = dns.recordTTL;
|
|
35
30
|
|
|
36
31
|
for (const domain of dns.domains) {
|
|
37
32
|
const zones = [];
|
|
38
33
|
const records = new Set();
|
|
39
34
|
|
|
40
|
-
const nameserver = (await
|
|
41
|
-
const rname =
|
|
35
|
+
const nameserver = (await owner.service({ type: "dns" }))?.owner;
|
|
36
|
+
const rname = dns.administratorEmail.replace(/@/, ".");
|
|
37
|
+
|
|
38
|
+
const createRecord = (key, type, value) => {
|
|
39
|
+
return {
|
|
40
|
+
key,
|
|
41
|
+
type,
|
|
42
|
+
value,
|
|
43
|
+
toString: () =>
|
|
44
|
+
`${key.padEnd(NAME_LEN, " ")} ${ttl} IN ${type} ${value}`
|
|
45
|
+
};
|
|
46
|
+
};
|
|
42
47
|
|
|
43
|
-
for await (const mail of
|
|
48
|
+
for await (const mail of owner.services({ type: "smtp" })) {
|
|
44
49
|
records.add(
|
|
45
|
-
|
|
46
|
-
mail.owner.domainName
|
|
47
|
-
}.`
|
|
50
|
+
createRecord("@", "MX", `${mail.priority} ${mail.owner.domainName}.`)
|
|
48
51
|
);
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
console.log(
|
|
54
|
+
console.log(owner.name, domain, nameserver?.hostName, rname);
|
|
55
|
+
|
|
56
|
+
const SOARecord = createRecord(
|
|
57
|
+
"@",
|
|
58
|
+
"SOA",
|
|
59
|
+
`${nameserver?.domainName}. ${rname}. (${updates})`
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const NSRecord = createRecord("@", "NS", `${nameserver?.ipAddress}.`);
|
|
52
63
|
|
|
53
64
|
const catalogZone = {
|
|
54
65
|
id: `catalog.${domain}`,
|
|
55
66
|
file: `catalog.${domain}.zone`,
|
|
56
67
|
records: new Set([
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
`${"@".padEnd(NAME_LEN, " ")} ${ttl} IN NS ${nameserver.ipAddress}.`,
|
|
61
|
-
`${("version." + domain + ".").padEnd(NAME_LEN, " ")} IN TXT "2"`
|
|
68
|
+
SOARecord,
|
|
69
|
+
NSRecord,
|
|
70
|
+
createRecord(`version.${domain}.`, "TXT", '"2"')
|
|
62
71
|
])
|
|
63
72
|
};
|
|
64
73
|
|
|
65
74
|
const zone = {
|
|
66
75
|
id: domain,
|
|
67
76
|
file: `${domain}.zone`,
|
|
68
|
-
records: new Set([
|
|
69
|
-
`${"@".padEnd(NAME_LEN, " ")} ${ttl} IN SOA ${
|
|
70
|
-
nameserver.domainName
|
|
71
|
-
}. ${rname}. (${updates})`,
|
|
72
|
-
`${"@".padEnd(NAME_LEN, " ")} ${ttl} IN NS ${nameserver.ipAddress}.`,
|
|
73
|
-
...records
|
|
74
|
-
])
|
|
77
|
+
records: new Set([SOARecord, NSRecord, ...records])
|
|
75
78
|
};
|
|
76
79
|
zones.push(zone);
|
|
77
80
|
|
|
78
|
-
for (const subnet of
|
|
81
|
+
for (const subnet of owner.subnets()) {
|
|
79
82
|
if (subnet.address) {
|
|
80
83
|
const reverse = reverseAddress(subnet.address);
|
|
81
84
|
const reverseArpa = reverseArpaAddress(subnet.address);
|
|
82
85
|
const zone = {
|
|
83
86
|
id: reverseArpa,
|
|
84
87
|
file: `${reverse}.zone`,
|
|
85
|
-
records: new Set([
|
|
86
|
-
`${"@".padEnd(NAME_LEN, " ")} ${ttl} IN SOA ${
|
|
87
|
-
nameserver.domainName
|
|
88
|
-
}. ${rname}. (${updates})`,
|
|
89
|
-
`${(reverseArpa + ".").padEnd(NAME_LEN, " ")} ${ttl} IN NS ${
|
|
90
|
-
nameserver.domainName
|
|
91
|
-
}.`
|
|
92
|
-
])
|
|
88
|
+
records: new Set([SOARecord, NSRecord])
|
|
93
89
|
};
|
|
94
90
|
zones.push(zone);
|
|
95
91
|
subnet.reverseZone = zone;
|
|
@@ -99,33 +95,34 @@ async function generateNamedDefs(location, targetDir) {
|
|
|
99
95
|
for await (const {
|
|
100
96
|
address,
|
|
101
97
|
networkInterface
|
|
102
|
-
} of
|
|
98
|
+
} of owner.networkAddresses()) {
|
|
103
99
|
const host = networkInterface.host;
|
|
104
100
|
zone.records.add(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
createRecord(
|
|
102
|
+
host.hostName,
|
|
103
|
+
isIPv4Address(address) ? "A " : "AAAA",
|
|
104
|
+
normalizeIPAddress(address)
|
|
105
|
+
)
|
|
108
106
|
);
|
|
109
107
|
|
|
110
108
|
for (const service of host.services()) {
|
|
111
109
|
if (service.master && service.alias) {
|
|
112
110
|
zone.records.add(
|
|
113
|
-
|
|
114
|
-
host.domainName
|
|
115
|
-
}.`
|
|
111
|
+
createRecord(service.alias, "CNAME", `${host.domainName}.`)
|
|
116
112
|
);
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
if (service.srvPrefix) {
|
|
120
116
|
zone.records.add(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
createRecord(
|
|
118
|
+
`${service.srvPrefix}.${host.domainName}.`,
|
|
119
|
+
"SRV",
|
|
120
|
+
`${String(service.priority).padStart(4)} ${String(
|
|
121
|
+
service.weight
|
|
122
|
+
).padStart(3)} ${String(service.port).padStart(5)} ${
|
|
123
|
+
host.domainName
|
|
124
|
+
}.`
|
|
125
|
+
)
|
|
129
126
|
);
|
|
130
127
|
}
|
|
131
128
|
}
|
|
@@ -134,10 +131,11 @@ async function generateNamedDefs(location, targetDir) {
|
|
|
134
131
|
|
|
135
132
|
if (reverseZone && isIPv4Address(address)) {
|
|
136
133
|
reverseZone.records.add(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
"
|
|
140
|
-
|
|
134
|
+
createRecord(
|
|
135
|
+
reverseArpaAddress(address) + ".",
|
|
136
|
+
"PTR",
|
|
137
|
+
`${networkInterface.host.domainName}.`
|
|
138
|
+
)
|
|
141
139
|
);
|
|
142
140
|
}
|
|
143
141
|
}
|
package/package.json
CHANGED
package/src/base.mjs
CHANGED
package/types/base.d.mts
CHANGED