pmcf 1.76.2 → 1.77.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 +1 -1
- package/src/dns-utils.mjs +16 -0
- package/src/dns.mjs +21 -52
- package/src/service.mjs +23 -0
- package/types/dns-utils.d.mts +5 -0
- package/types/service.d.mts +4 -0
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function dnsFullName(name) {
|
|
2
|
+
return name.endsWith(".") ? name : name + ".";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function DNSRecord(key, type, ...values) {
|
|
6
|
+
values = values.map(v => (typeof v === "number" ? String(v).padStart(3) : v));
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
key,
|
|
10
|
+
toString: (maxKeyLength, ttl) =>
|
|
11
|
+
`${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
|
|
12
|
+
5,
|
|
13
|
+
" "
|
|
14
|
+
)} ${values.join(" ")}`
|
|
15
|
+
};
|
|
16
|
+
}
|
package/src/dns.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
normalizeIPAddress,
|
|
8
8
|
isLinkLocal
|
|
9
9
|
} from "./utils.mjs";
|
|
10
|
+
import { DNSRecord, dnsFullName } from "./dns-utils.mjs";
|
|
10
11
|
import { Base } from "./base.mjs";
|
|
11
12
|
import { addType } from "./types.mjs";
|
|
12
13
|
import { serviceAddresses } from "./service.mjs";
|
|
@@ -175,10 +176,6 @@ export class DNSService extends Base {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
178
|
-
function fullName(name) {
|
|
179
|
-
return name.endsWith(".") ? name : name + ".";
|
|
180
|
-
}
|
|
181
|
-
|
|
182
179
|
async function generateZoneDefs(dns, targetDir) {
|
|
183
180
|
const ttl = dns.recordTTL;
|
|
184
181
|
const updates = [Math.ceil(Date.now() / 1000), ...dns.soaUpdates].join(" ");
|
|
@@ -192,24 +189,9 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
192
189
|
|
|
193
190
|
let maxKeyLength;
|
|
194
191
|
|
|
195
|
-
const createRecord = (key, type, ...values) => {
|
|
196
|
-
values = values.map(v =>
|
|
197
|
-
typeof v === "number" ? String(v).padStart(3) : v
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
key,
|
|
202
|
-
toString: () =>
|
|
203
|
-
`${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(
|
|
204
|
-
5,
|
|
205
|
-
" "
|
|
206
|
-
)} ${values.join(" ")}`
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
|
|
210
192
|
for (const mail of dns.owner.findServices({ type: "smtp" })) {
|
|
211
193
|
records.add(
|
|
212
|
-
|
|
194
|
+
DNSRecord("@", "MX", mail.priority, dnsFullName(mail.domainName))
|
|
213
195
|
);
|
|
214
196
|
}
|
|
215
197
|
|
|
@@ -217,25 +199,27 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
217
199
|
//console.log(dns.owner.fullName, domain, nameService.domainName, rname);
|
|
218
200
|
const reverseZones = new Map();
|
|
219
201
|
|
|
220
|
-
const SOARecord =
|
|
202
|
+
const SOARecord = DNSRecord(
|
|
221
203
|
"@",
|
|
222
204
|
"SOA",
|
|
223
|
-
|
|
224
|
-
|
|
205
|
+
dnsFullName(nameService.domainName),
|
|
206
|
+
dnsFullName(rname),
|
|
225
207
|
`(${updates})`
|
|
226
208
|
);
|
|
227
209
|
|
|
228
|
-
const NSRecord =
|
|
210
|
+
const NSRecord = DNSRecord(
|
|
229
211
|
"@",
|
|
230
212
|
"NS",
|
|
231
|
-
|
|
213
|
+
dnsFullName(nameService.ipAddressOrDomainName)
|
|
232
214
|
);
|
|
233
215
|
|
|
216
|
+
const ALPNRecord = DNSRecord("@", "HTTPS", 1, ".", "alpn=h3");
|
|
217
|
+
|
|
234
218
|
const zone = {
|
|
235
219
|
id: domain,
|
|
236
220
|
type: "plain",
|
|
237
221
|
file: `${dns.owner.name}/${domain}.zone`,
|
|
238
|
-
records: new Set([SOARecord, NSRecord, ...records])
|
|
222
|
+
records: new Set([SOARecord, NSRecord, ALPNRecord, ...records])
|
|
239
223
|
};
|
|
240
224
|
zones.push(zone);
|
|
241
225
|
|
|
@@ -246,7 +230,7 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
246
230
|
records: new Set([
|
|
247
231
|
SOARecord,
|
|
248
232
|
NSRecord,
|
|
249
|
-
|
|
233
|
+
DNSRecord(dnsFullName(`version.catalog.${domain}`), "TXT", '"1"')
|
|
250
234
|
])
|
|
251
235
|
};
|
|
252
236
|
|
|
@@ -278,8 +262,8 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
278
262
|
addresses.add(address);
|
|
279
263
|
|
|
280
264
|
zone.records.add(
|
|
281
|
-
|
|
282
|
-
|
|
265
|
+
DNSRecord(
|
|
266
|
+
dnsFullName(domainName),
|
|
283
267
|
isIPv6Address(address) ? "AAAA" : "A",
|
|
284
268
|
normalizeIPAddress(address)
|
|
285
269
|
)
|
|
@@ -301,10 +285,10 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
301
285
|
|
|
302
286
|
for (const domainName of host.domainNames) {
|
|
303
287
|
reverseZone.records.add(
|
|
304
|
-
|
|
305
|
-
|
|
288
|
+
DNSRecord(
|
|
289
|
+
dnsFullName(reverseArpaAddress(address)),
|
|
306
290
|
"PTR",
|
|
307
|
-
|
|
291
|
+
dnsFullName(domainName)
|
|
308
292
|
)
|
|
309
293
|
);
|
|
310
294
|
}
|
|
@@ -314,23 +298,8 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
314
298
|
if (!hosts.has(host)) {
|
|
315
299
|
hosts.add(host);
|
|
316
300
|
for (const service of host.findServices()) {
|
|
317
|
-
|
|
318
|
-
zone.records.add(
|
|
319
|
-
createRecord(service.alias, "CNAME", fullName(domainName))
|
|
320
|
-
);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (dns.hasSVRRecords && service.srvPrefix) {
|
|
324
|
-
zone.records.add(
|
|
325
|
-
createRecord(
|
|
326
|
-
fullName(`${service.srvPrefix}.${domainName}`),
|
|
327
|
-
"SRV",
|
|
328
|
-
service.priority,
|
|
329
|
-
service.weight,
|
|
330
|
-
service.port,
|
|
331
|
-
fullName(host.domainName)
|
|
332
|
-
)
|
|
333
|
-
);
|
|
301
|
+
for (const record of service.dnsRecordsForDomainName(domainName, dns.hasSVRRecords)) {
|
|
302
|
+
zone.records.add(record);
|
|
334
303
|
}
|
|
335
304
|
}
|
|
336
305
|
}
|
|
@@ -343,10 +312,10 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
343
312
|
if (zone.type !== "catalog") {
|
|
344
313
|
const hash = createHmac("md5", zone.id).digest("hex");
|
|
345
314
|
catalogZone.records.add(
|
|
346
|
-
|
|
315
|
+
DNSRecord(
|
|
347
316
|
`${hash}.zones.catalog.${domain}.`,
|
|
348
317
|
"PTR",
|
|
349
|
-
|
|
318
|
+
dnsFullName(zone.id)
|
|
350
319
|
)
|
|
351
320
|
);
|
|
352
321
|
}
|
|
@@ -374,7 +343,7 @@ async function generateZoneDefs(dns, targetDir) {
|
|
|
374
343
|
await writeLines(
|
|
375
344
|
join(targetDir, "var/lib/named"),
|
|
376
345
|
zone.file,
|
|
377
|
-
zone.records
|
|
346
|
+
[...zone.records].map(r => r.toString(maxKeyLength, ttl))
|
|
378
347
|
);
|
|
379
348
|
}
|
|
380
349
|
|
package/src/service.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { Base } from "./base.mjs";
|
|
|
2
2
|
import { addType } from "./types.mjs";
|
|
3
3
|
import { asArray } from "./utils.mjs";
|
|
4
4
|
import { networkAddressProperties } from "./network-support.mjs";
|
|
5
|
+
import { DNSRecord, dnsFullName } from "./dns-utils.mjs";
|
|
5
6
|
|
|
6
7
|
const ServiceTypes = {
|
|
7
8
|
dns: { protocol: "udp", port: 53, tls: false },
|
|
@@ -176,6 +177,28 @@ export class Service extends Base {
|
|
|
176
177
|
return `_${this.type}._${st.protocol}`;
|
|
177
178
|
}
|
|
178
179
|
}
|
|
180
|
+
|
|
181
|
+
dnsRecordsForDomainName(domainName, hasSVRRecords) {
|
|
182
|
+
const records = [];
|
|
183
|
+
if (this.master && this.alias) {
|
|
184
|
+
records.push(DNSRecord(this.alias, "CNAME", dnsFullName(domainName)));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (hasSVRRecords && this.srvPrefix) {
|
|
188
|
+
records.push(
|
|
189
|
+
DNSRecord(
|
|
190
|
+
dnsFullName(`${this.srvPrefix}.${domainName}`),
|
|
191
|
+
"SRV",
|
|
192
|
+
this.priority,
|
|
193
|
+
this.weight,
|
|
194
|
+
this.port,
|
|
195
|
+
dnsFullName(this.domainName)
|
|
196
|
+
)
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return records;
|
|
201
|
+
}
|
|
179
202
|
}
|
|
180
203
|
|
|
181
204
|
export const sortByPriority = (a, b) => a.priority - b.priority;
|
package/types/service.d.mts
CHANGED
|
@@ -134,6 +134,10 @@ export class Service extends Base {
|
|
|
134
134
|
get protocol(): any;
|
|
135
135
|
get tls(): any;
|
|
136
136
|
get srvPrefix(): string;
|
|
137
|
+
dnsRecordsForDomainName(domainName: any, hasSVRRecords: any): {
|
|
138
|
+
key: any;
|
|
139
|
+
toString: (maxKeyLength: any, ttl: any) => string;
|
|
140
|
+
}[];
|
|
137
141
|
#private;
|
|
138
142
|
}
|
|
139
143
|
export function sortByPriority(a: any, b: any): number;
|