pmcf 1.23.5 → 1.24.1
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-host-defs +4 -2
- package/package.json +1 -1
- package/src/model.mjs +5 -134
- package/src/module.mjs +1 -0
- package/src/service.mjs +133 -0
- package/types/model.d.mts +3 -15
- package/types/module.d.mts +1 -0
- package/types/service.d.mts +14 -0
package/bin/pmcf-host-defs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { writeFile, mkdir, copyFile, glob } from "node:fs/promises";
|
|
3
|
+
import { writeFile, mkdir, copyFile, glob, chmod } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { Host } from "pmcf";
|
|
6
6
|
import { writeLines, sectionLines } from "../src/utils.mjs";
|
|
@@ -151,7 +151,9 @@ async function copySshKeys(host, dir) {
|
|
|
151
151
|
await mkdir(sshDir, { recursive: true });
|
|
152
152
|
|
|
153
153
|
for await (const file of glob("ssh_host_*", { cwd: host.directory })) {
|
|
154
|
-
|
|
154
|
+
const destinationFileName = join(sshDir, file);
|
|
155
|
+
await copyFile(join(host.directory, file), destinationFileName);
|
|
156
|
+
await chmod(destinationFileName, destinationFileName.endsWith('.pub') ? 0o0644 : 0o0600);
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
|
package/package.json
CHANGED
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
|
|
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.
|
|
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?.protocol) {
|
|
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
package/src/service.mjs
ADDED
|
@@ -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
|
|
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
|
|
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";
|
package/types/module.d.mts
CHANGED
|
@@ -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";
|