pmcf 1.23.4 → 1.24.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.
@@ -16,8 +16,6 @@ const updates = [
16
16
  60000
17
17
  ].join(" ");
18
18
 
19
- const NAME_LEN = 35;
20
-
21
19
  await generateNamedDefs(owner, options.output);
22
20
 
23
21
  console.log("depends", "mf-named");
@@ -35,13 +33,15 @@ async function generateNamedDefs(owner, targetDir) {
35
33
  const nameserver = (await owner.service({ type: "dns" }))?.owner;
36
34
  const rname = dns.administratorEmail.replace(/@/, ".");
37
35
 
36
+ let maxKeyLength;
37
+
38
38
  const createRecord = (key, type, value) => {
39
39
  return {
40
40
  key,
41
41
  type,
42
42
  value,
43
43
  toString: () =>
44
- `${key.padEnd(NAME_LEN, " ")} ${ttl} IN ${type} ${value}`
44
+ `${key.padEnd(maxKeyLength, " ")} ${ttl} IN ${type.padEnd(5, " ")} ${value}`
45
45
  };
46
46
  };
47
47
 
@@ -148,7 +148,7 @@ async function generateNamedDefs(owner, targetDir) {
148
148
  if (zone !== catalogZone) {
149
149
  const hash = createHmac("md5", zone.id).digest("hex");
150
150
  catalogZone.records.add(
151
- `${hash}.zones.${domain}. IN PTR ${zone.id}.`
151
+ createRecord(`${hash}.zones.${domain}.`, "PTR", `${zone.id}.`)
152
152
  );
153
153
  }
154
154
 
@@ -165,6 +165,13 @@ async function generateNamedDefs(owner, targetDir) {
165
165
  zoneConfig.push(`};`);
166
166
  zoneConfig.push("");
167
167
 
168
+ maxKeyLength = 0;
169
+ for (const r of zone.records) {
170
+ if (r.key.length > maxKeyLength) {
171
+ maxKeyLength = r.key.length;
172
+ }
173
+ }
174
+
168
175
  writeLines(join(targetDir, "var/lib/named"), zone.file, zone.records);
169
176
  }
170
177
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.23.4",
3
+ "version": "1.24.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  isIPv6Address
8
8
  } from "./utils.mjs";
9
9
  import { Base } from "./base.mjs";
10
+ import { Service } from "./service.mjs";
10
11
  import { DNSService } from "./dns.mjs";
11
12
 
12
13
  export class Owner extends Base {
@@ -386,10 +387,10 @@ export class Network extends Owner {
386
387
  this.bridge = owner.addBridge(this, bridge);
387
388
  }
388
389
 
389
- get ipv4_netmask() {
390
+ get netmask() {
390
391
  const m = this.ipv4?.match(/\/(\d+)$/);
391
392
  if (m) {
392
- return m[1];
393
+ return parseInt(m[1]);
393
394
  }
394
395
  }
395
396
 
@@ -406,6 +407,7 @@ export class Network extends Owner {
406
407
  ...super.propertyNames,
407
408
  "kind",
408
409
  "ipv4",
410
+ "netmask",
409
411
  "scope",
410
412
  "metric",
411
413
  "bridge"
@@ -764,7 +766,7 @@ export class NetworkInterface extends Base {
764
766
 
765
767
  get ipAddressesWithNetmask() {
766
768
  return this.#ipAddresses.map(a =>
767
- isIPv4Address(a) ? `${a}/${this.network.ipv4_netmask}` : a
769
+ isIPv4Address(a) ? `${a}/${this.network.netmask}` : a
768
770
  );
769
771
  }
770
772
 
@@ -855,137 +857,6 @@ export class Subnet extends Base {
855
857
  }
856
858
  }
857
859
 
858
- const ServiceTypes = {
859
- dns: { protocol: "udp", port: 53 },
860
- ldap: { protocol: "tcp", port: 389 },
861
- http: { protocol: "tcp", port: 80 },
862
- https: { protocol: "tcp", port: 443 },
863
- rtsp: { protocol: "tcp", port: 554 },
864
- smtp: { protocol: "tcp", port: 25 },
865
- ssh: { protocol: "tcp", port: 22 },
866
- imap: { protocol: "tcp", port: 143 },
867
- imaps: { protocol: "tcp", port: 993 },
868
- dhcp: {}
869
- };
870
-
871
- export class Service extends Base {
872
- alias;
873
- #weight;
874
- #priority;
875
- #type;
876
- #port;
877
- #ipAddresses;
878
-
879
- static get typeName() {
880
- return "service";
881
- }
882
-
883
- constructor(owner, data) {
884
- super(owner, data);
885
- if (data.weight !== undefined) {
886
- this.#weight = data.weight;
887
- delete data.weight;
888
- }
889
- if (data.priority !== undefined) {
890
- this.#priority = data.priority;
891
- delete data.priority;
892
- }
893
- if (data.type) {
894
- this.#type = data.type;
895
- delete data.type;
896
- }
897
- if (data.port !== undefined) {
898
- this.#port = data.port;
899
- delete data.port;
900
- }
901
- if (data.ipAddresses) {
902
- this.#ipAddresses = data.ipAddresses;
903
- delete data.ipAddresses;
904
- }
905
-
906
- Object.assign(this, data);
907
-
908
- owner.addService(this);
909
- }
910
-
911
- withOwner(owner) {
912
- if (this.owner !== owner) {
913
- const data = { name: this.name };
914
- if (this.alias) {
915
- data.alias = this.alias;
916
- }
917
- if (this.#type) {
918
- data.type = this.#type;
919
- }
920
- if (this.#weight) {
921
- data.weight = this.#weight;
922
- }
923
- if (this.#port) {
924
- data.port = this.#port;
925
- }
926
- if (this.#ipAddresses) {
927
- data.ipAddresses = this.#ipAddresses;
928
- }
929
- return new this.constructor(owner, data);
930
- }
931
-
932
- return this;
933
- }
934
-
935
- get protocol() {
936
- return ServiceTypes[this.type]?.protocol;
937
- }
938
-
939
- get srvPrefix() {
940
- const st = ServiceTypes[this.type];
941
- if (st) {
942
- return `_${this.type}._${st.protocol}`;
943
- }
944
- }
945
-
946
- get ipAddresses() {
947
- return this.#ipAddresses || this.owner.ipAddresses;
948
- }
949
-
950
- get addresses() {
951
- return this.ipAddresses.map(a => `${a}:${this.port}`);
952
- }
953
-
954
- get port() {
955
- return this.#port || ServiceTypes[this.type]?.port;
956
- }
957
-
958
- get priority() {
959
- return this.#priority || this.owner.priority || 99;
960
- }
961
-
962
- get weight() {
963
- return this.#weight || this.owner.weight || 0;
964
- }
965
-
966
- get master() {
967
- return this.owner.master;
968
- }
969
-
970
- get type() {
971
- return this.#type || this.name;
972
- }
973
-
974
- get propertyNames() {
975
- return [
976
- ...super.propertyNames,
977
- "ipAddresses",
978
- "addresses",
979
- "port",
980
- "protocol",
981
- "alias",
982
- "type",
983
- "master",
984
- "priority",
985
- "weight"
986
- ];
987
- }
988
- }
989
860
 
990
861
  const _types = [Location, Network, Subnet, Host, Service, DNSService];
991
862
  const _typesByName = Object.fromEntries(_types.map(t => [t.typeName, t]));
package/src/module.mjs CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./base.mjs";
2
+ export * from "./service.mjs";
2
3
  export * from "./dns.mjs";
3
4
  export * from "./model.mjs";
@@ -0,0 +1,133 @@
1
+ import { Base } from "./base.mjs";
2
+
3
+ const ServiceTypes = {
4
+ dns: { protocol: "udp", port: 53 },
5
+ ldap: { protocol: "tcp", port: 389 },
6
+ http: { protocol: "tcp", port: 80 },
7
+ https: { protocol: "tcp", port: 443 },
8
+ rtsp: { protocol: "tcp", port: 554 },
9
+ smtp: { protocol: "tcp", port: 25 },
10
+ ssh: { protocol: "tcp", port: 22 },
11
+ imap: { protocol: "tcp", port: 143 },
12
+ imaps: { protocol: "tcp", port: 993 },
13
+ dhcp: {}
14
+ };
15
+
16
+ export class Service extends Base {
17
+ alias;
18
+ #weight;
19
+ #priority;
20
+ #type;
21
+ #port;
22
+ #ipAddresses;
23
+
24
+ static get typeName() {
25
+ return "service";
26
+ }
27
+
28
+ constructor(owner, data) {
29
+ super(owner, data);
30
+ if (data.weight !== undefined) {
31
+ this.#weight = data.weight;
32
+ delete data.weight;
33
+ }
34
+ if (data.priority !== undefined) {
35
+ this.#priority = data.priority;
36
+ delete data.priority;
37
+ }
38
+ if (data.type) {
39
+ this.#type = data.type;
40
+ delete data.type;
41
+ }
42
+ if (data.port !== undefined) {
43
+ this.#port = data.port;
44
+ delete data.port;
45
+ }
46
+ if (data.ipAddresses) {
47
+ this.#ipAddresses = data.ipAddresses;
48
+ delete data.ipAddresses;
49
+ }
50
+
51
+ Object.assign(this, data);
52
+
53
+ owner.addService(this);
54
+ }
55
+
56
+ withOwner(owner) {
57
+ if (this.owner !== owner) {
58
+ const data = { name: this.name };
59
+ if (this.alias) {
60
+ data.alias = this.alias;
61
+ }
62
+ if (this.#type) {
63
+ data.type = this.#type;
64
+ }
65
+ if (this.#weight) {
66
+ data.weight = this.#weight;
67
+ }
68
+ if (this.#port) {
69
+ data.port = this.#port;
70
+ }
71
+ if (this.#ipAddresses) {
72
+ data.ipAddresses = this.#ipAddresses;
73
+ }
74
+ return new this.constructor(owner, data);
75
+ }
76
+
77
+ return this;
78
+ }
79
+
80
+ get protocol() {
81
+ return ServiceTypes[this.type]?.protocol;
82
+ }
83
+
84
+ get srvPrefix() {
85
+ const st = ServiceTypes[this.type];
86
+ if (st?.protocol) {
87
+ return `_${this.type}._${st.protocol}`;
88
+ }
89
+ }
90
+
91
+ get ipAddresses() {
92
+ return this.#ipAddresses || this.owner.ipAddresses;
93
+ }
94
+
95
+ get addresses() {
96
+ return this.ipAddresses.map(a => `${a}:${this.port}`);
97
+ }
98
+
99
+ get port() {
100
+ return this.#port || ServiceTypes[this.type]?.port;
101
+ }
102
+
103
+ get priority() {
104
+ return this.#priority || this.owner.priority || 99;
105
+ }
106
+
107
+ get weight() {
108
+ return this.#weight || this.owner.weight || 0;
109
+ }
110
+
111
+ get master() {
112
+ return this.owner.master;
113
+ }
114
+
115
+ get type() {
116
+ return this.#type || this.name;
117
+ }
118
+
119
+ get propertyNames() {
120
+ return [
121
+ ...super.propertyNames,
122
+ "ipAddresses",
123
+ "addresses",
124
+ "port",
125
+ "protocol",
126
+ "alias",
127
+ "type",
128
+ "master",
129
+ "priority",
130
+ "weight"
131
+ ];
132
+ }
133
+ }
package/types/model.d.mts CHANGED
@@ -28,7 +28,7 @@ export class Owner extends Base {
28
28
  }
29
29
  export class World extends Owner {
30
30
  static get types(): {
31
- [k: string]: typeof DNSService | typeof Network | typeof Host | typeof Location | typeof Subnet | typeof Service;
31
+ [k: string]: typeof Service | typeof DNSService | typeof Network | typeof Host | typeof Location | typeof Subnet;
32
32
  };
33
33
  constructor(directory: any);
34
34
  get fullName(): string;
@@ -51,7 +51,7 @@ export class Network extends Owner {
51
51
  ipv4: any;
52
52
  subnet: any;
53
53
  bridge: any;
54
- get ipv4_netmask(): any;
54
+ get netmask(): number;
55
55
  get subnetAddress(): any;
56
56
  }
57
57
  export class Host extends Base {
@@ -112,18 +112,6 @@ export class Subnet extends Base {
112
112
  networks: Set<any>;
113
113
  get address(): any;
114
114
  }
115
- export class Service extends Base {
116
- alias: any;
117
- get protocol(): any;
118
- get srvPrefix(): string;
119
- get ipAddresses(): any;
120
- get addresses(): any;
121
- get port(): any;
122
- get priority(): any;
123
- get weight(): any;
124
- get master(): any;
125
- get type(): any;
126
- #private;
127
- }
128
115
  import { Base } from "./base.mjs";
129
116
  import { DNSService } from "./dns.mjs";
117
+ import { Service } from "./service.mjs";
@@ -1,3 +1,4 @@
1
1
  export * from "./base.mjs";
2
+ export * from "./service.mjs";
2
3
  export * from "./dns.mjs";
3
4
  export * from "./model.mjs";
@@ -0,0 +1,14 @@
1
+ export class Service extends Base {
2
+ alias: any;
3
+ get protocol(): any;
4
+ get srvPrefix(): string;
5
+ get ipAddresses(): any;
6
+ get addresses(): any;
7
+ get port(): any;
8
+ get priority(): any;
9
+ get weight(): any;
10
+ get master(): any;
11
+ get type(): any;
12
+ #private;
13
+ }
14
+ import { Base } from "./base.mjs";