pmcf 1.23.2 → 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.
@@ -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 location = await world.load(args[0], { type: Location });
10
+ const owner = await world.load(args[0]);
12
11
  const updates = [
13
12
  Math.ceil(Date.now() / 1000),
14
13
  36000,
@@ -19,78 +18,74 @@ const updates = [
19
18
 
20
19
  const NAME_LEN = 35;
21
20
 
22
- await generateNamedDefs(location, options.output);
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 ${location.name}`);
25
+ console.log("description", `named defintions for ${owner.name}`);
27
26
 
28
- /*for await (const location of world.locations()) {
29
- await generateNamedDefs(location, targetDir);
30
- }*/
31
-
32
- async function generateNamedDefs(location, targetDir) {
33
- const dns = location.dns;
34
- const domain = location.domain;
27
+ async function generateNamedDefs(owner, targetDir) {
28
+ const dns = owner.dns;
35
29
  const ttl = dns.recordTTL;
36
30
 
37
- if (domain) {
31
+ for (const domain of dns.domains) {
38
32
  const zones = [];
39
33
  const records = new Set();
40
34
 
41
- const nameserver = (await location.service({ type: "dns" }))?.owner;
42
- const rname = location.administratorEmail.replace(/@/, ".");
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
+ };
43
47
 
44
- for await (const mail of location.services({ type: "smtp" })) {
48
+ for await (const mail of owner.services({ type: "smtp" })) {
45
49
  records.add(
46
- `${"@".padEnd(NAME_LEN, " ")} ${ttl} IN MX ${mail.priority} ${
47
- mail.owner.domainName
48
- }.`
50
+ createRecord("@", "MX", `${mail.priority} ${mail.owner.domainName}.`)
49
51
  );
50
52
  }
51
53
 
52
- console.log(location.name, location.domain, nameserver?.hostName, rname);
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}.`);
53
63
 
54
64
  const catalogZone = {
55
65
  id: `catalog.${domain}`,
56
66
  file: `catalog.${domain}.zone`,
57
67
  records: new Set([
58
- `${"@".padEnd(NAME_LEN, " ")} ${ttl} IN SOA ${
59
- nameserver.domainName
60
- }. ${rname}. (${updates})`,
61
- `${"@".padEnd(NAME_LEN, " ")} ${ttl} IN NS ${nameserver.ipAddress}.`,
62
- `${("version." + domain + ".").padEnd(NAME_LEN, " ")} IN TXT "2"`
68
+ SOARecord,
69
+ NSRecord,
70
+ createRecord(`version.${domain}.`, "TXT", '"2"')
63
71
  ])
64
72
  };
65
73
 
66
74
  const zone = {
67
75
  id: domain,
68
76
  file: `${domain}.zone`,
69
- records: new Set([
70
- `${"@".padEnd(NAME_LEN, " ")} ${ttl} IN SOA ${
71
- nameserver.domainName
72
- }. ${rname}. (${updates})`,
73
- `${"@".padEnd(NAME_LEN, " ")} ${ttl} IN NS ${nameserver.ipAddress}.`,
74
- ...records
75
- ])
77
+ records: new Set([SOARecord, NSRecord, ...records])
76
78
  };
77
79
  zones.push(zone);
78
80
 
79
- for (const subnet of location.subnets()) {
81
+ for (const subnet of owner.subnets()) {
80
82
  if (subnet.address) {
81
83
  const reverse = reverseAddress(subnet.address);
82
84
  const reverseArpa = reverseArpaAddress(subnet.address);
83
85
  const zone = {
84
86
  id: reverseArpa,
85
87
  file: `${reverse}.zone`,
86
- records: new Set([
87
- `${"@".padEnd(NAME_LEN, " ")} ${ttl} IN SOA ${
88
- nameserver.domainName
89
- }. ${rname}. (${updates})`,
90
- `${(reverseArpa + ".").padEnd(NAME_LEN, " ")} ${ttl} IN NS ${
91
- nameserver.domainName
92
- }.`
93
- ])
88
+ records: new Set([SOARecord, NSRecord])
94
89
  };
95
90
  zones.push(zone);
96
91
  subnet.reverseZone = zone;
@@ -100,33 +95,34 @@ async function generateNamedDefs(location, targetDir) {
100
95
  for await (const {
101
96
  address,
102
97
  networkInterface
103
- } of location.networkAddresses()) {
98
+ } of owner.networkAddresses()) {
104
99
  const host = networkInterface.host;
105
100
  zone.records.add(
106
- `${host.hostName.padEnd(NAME_LEN, " ")} ${ttl} IN ${
107
- isIPv4Address(address) ? "A " : "AAAA"
108
- } ${normalizeIPAddress(address)}`
101
+ createRecord(
102
+ host.hostName,
103
+ isIPv4Address(address) ? "A " : "AAAA",
104
+ normalizeIPAddress(address)
105
+ )
109
106
  );
110
107
 
111
108
  for (const service of host.services()) {
112
109
  if (service.master && service.alias) {
113
110
  zone.records.add(
114
- `${service.alias.padEnd(NAME_LEN, " ")} ${ttl} IN CNAME ${
115
- host.domainName
116
- }.`
111
+ createRecord(service.alias, "CNAME", `${host.domainName}.`)
117
112
  );
118
113
  }
119
114
 
120
115
  if (service.srvPrefix) {
121
116
  zone.records.add(
122
- `${`${service.srvPrefix}.${host.domainName}.`.padEnd(
123
- NAME_LEN,
124
- " "
125
- )} ${ttl} IN SRV ${String(service.priority).padStart(4)} ${String(
126
- service.weight
127
- ).padStart(3)} ${String(service.port).padStart(5)} ${
128
- host.domainName
129
- }.`
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
+ )
130
126
  );
131
127
  }
132
128
  }
@@ -135,10 +131,11 @@ async function generateNamedDefs(location, targetDir) {
135
131
 
136
132
  if (reverseZone && isIPv4Address(address)) {
137
133
  reverseZone.records.add(
138
- `${(reverseArpaAddress(address) + ".").padEnd(
139
- NAME_LEN,
140
- " "
141
- )} ${ttl} IN PTR ${networkInterface.host.domainName}.`
134
+ createRecord(
135
+ reverseArpaAddress(address) + ".",
136
+ "PTR",
137
+ `${networkInterface.host.domainName}.`
138
+ )
142
139
  );
143
140
  }
144
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.23.2",
3
+ "version": "1.23.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/base.mjs CHANGED
@@ -69,6 +69,10 @@ export class Base {
69
69
  return this.owner?.network;
70
70
  }
71
71
 
72
+ get administratorEmail() {
73
+ return this.owner?.administratorEmail;
74
+ }
75
+
72
76
  #directory;
73
77
  set directory(directory) {
74
78
  this.#directory = directory;
package/src/model.mjs CHANGED
@@ -153,7 +153,7 @@ export class Owner extends Base {
153
153
  bridge.delete(network);
154
154
  bridge.add(other);
155
155
  other.bridge = bridge;
156
- this.info("RESOLVE", network, other, bridgeToJSON(bridge));
156
+ //this.info("RESOLVE", network, other, bridgeToJSON(bridge));
157
157
  } else {
158
158
  this.error(`Unresolvabale bridge network`, network);
159
159
  }
@@ -975,6 +975,7 @@ export class Service extends Base {
975
975
  return [
976
976
  ...super.propertyNames,
977
977
  "ipAddresses",
978
+ "addresses",
978
979
  "port",
979
980
  "protocol",
980
981
  "alias",
package/types/base.d.mts CHANGED
@@ -15,6 +15,7 @@ export class Base {
15
15
  get location(): any;
16
16
  get host(): any;
17
17
  get network(): any;
18
+ get administratorEmail(): any;
18
19
  set directory(directory: any);
19
20
  get directory(): any;
20
21
  get fullName(): any;
package/types/model.d.mts CHANGED
@@ -18,7 +18,6 @@ export class Owner extends Base {
18
18
  addSubnet(subnet: any): void;
19
19
  subnet(name: any): any;
20
20
  subnets(): MapIterator<any>;
21
- get administratorEmail(): any;
22
21
  toJSON(): {
23
22
  networks: any[];
24
23
  subnets: any[];