pmcf 2.9.2 → 2.10.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/package.json +1 -1
- package/src/host-utils.mjs +5 -2
- package/src/service.mjs +4 -0
- package/src/services/dhcp.mjs +18 -23
- package/src/subnet.mjs +38 -3
- package/types/service.d.mts +1 -0
- package/types/subnet.d.mts +5 -0
package/package.json
CHANGED
package/src/host-utils.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeFile, mkdir, copyFile, glob, chmod } from "node:fs/promises";
|
|
1
|
+
import { writeFile, mkdir, copyFile, glob, chmod, stat } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { writeLines, sectionLines } from "../src/utils.mjs";
|
|
4
4
|
import { addHook } from "./hooks.mjs";
|
|
@@ -142,8 +142,11 @@ export async function copySshKeys(host, packageData) {
|
|
|
142
142
|
await copyFile(join(host.directory, file), destinationFileName);
|
|
143
143
|
await chmod(
|
|
144
144
|
destinationFileName,
|
|
145
|
-
destinationFileName.endsWith(".pub") ?
|
|
145
|
+
destinationFileName.endsWith(".pub") ? 0o644 : 0o600
|
|
146
146
|
);
|
|
147
|
+
|
|
148
|
+
const s = await stat(destinationFileName);
|
|
149
|
+
console.log(destinationFileName,s.mode)
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
|
package/src/service.mjs
CHANGED
|
@@ -152,6 +152,10 @@ export class Service extends Base {
|
|
|
152
152
|
return this.rawAddresses.map(a => `${a}:${this.port}`);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
get networks() {
|
|
156
|
+
return this.server.networks;
|
|
157
|
+
}
|
|
158
|
+
|
|
155
159
|
get endpoints() {
|
|
156
160
|
if (!ServiceTypes[this.type]) {
|
|
157
161
|
return [{ address: this.rawAddress, port: this._port, tls: false }];
|
package/src/services/dhcp.mjs
CHANGED
|
@@ -147,17 +147,14 @@ export class DHCPService extends Service {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
-
// console.log(this.owner.name,this.owner.networks());
|
|
151
|
-
/*
|
|
152
150
|
const subnets = new Set();
|
|
153
151
|
|
|
154
|
-
for (const network of this.
|
|
152
|
+
for (const network of this.networks) {
|
|
155
153
|
for (const subnet of network.subnets()) {
|
|
156
154
|
subnets.add(subnet);
|
|
157
155
|
}
|
|
158
156
|
}
|
|
159
|
-
console.log([...subnets].map(s => s.address));
|
|
160
|
-
*/
|
|
157
|
+
//console.log([...subnets].filter(s => s.isIPv4).map(s => s.address));
|
|
161
158
|
|
|
162
159
|
const hwmap = new Map();
|
|
163
160
|
const hostNames = new Set();
|
|
@@ -199,24 +196,22 @@ export class DHCPService extends Service {
|
|
|
199
196
|
data: [...this.domains].join(",")
|
|
200
197
|
}
|
|
201
198
|
],
|
|
202
|
-
subnet4: [
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
],
|
|
199
|
+
subnet4: [...subnets]
|
|
200
|
+
.filter(s => s.isIPv4)
|
|
201
|
+
.map((subnet, index) => {
|
|
202
|
+
return {
|
|
203
|
+
id: index + 1,
|
|
204
|
+
subnet: subnet.longAddress,
|
|
205
|
+
pools: [{ pool: subnet.addressRange.join(" - ") }],
|
|
206
|
+
"option-data": [
|
|
207
|
+
{
|
|
208
|
+
name: "routers",
|
|
209
|
+
data: network.gateway.rawAddress
|
|
210
|
+
}
|
|
211
|
+
],
|
|
212
|
+
reservations
|
|
213
|
+
};
|
|
214
|
+
}),
|
|
220
215
|
loggers
|
|
221
216
|
}
|
|
222
217
|
};
|
package/src/subnet.mjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
normalizeCIDR,
|
|
3
|
+
isLinkLocal,
|
|
4
|
+
isIPv4Address,
|
|
5
|
+
isIPv6Address
|
|
6
|
+
} from "./utils.mjs";
|
|
2
7
|
import { Base } from "./base.mjs";
|
|
3
8
|
import { addType } from "./types.mjs";
|
|
4
9
|
|
|
@@ -48,6 +53,34 @@ export class Subnet extends Base {
|
|
|
48
53
|
return isLinkLocal(this.address);
|
|
49
54
|
}
|
|
50
55
|
|
|
56
|
+
get isIPv4() {
|
|
57
|
+
return isIPv4Address(this.address);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get isIPv6() {
|
|
61
|
+
return isIPv6Address(this.address);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get addressRange() {
|
|
65
|
+
const l = this.prefixLength;
|
|
66
|
+
return l === 24
|
|
67
|
+
? [this.prefix + ".0", this.prefix + ".255"]
|
|
68
|
+
: [this.prefix + ".0.0", this.prefix + ".255.255"];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get longPrefix() {
|
|
72
|
+
const prefix = this.prefix;
|
|
73
|
+
|
|
74
|
+
switch (this.prefixLength) {
|
|
75
|
+
case 24:
|
|
76
|
+
return prefix + ".0";
|
|
77
|
+
case 16:
|
|
78
|
+
return prefix + ".0.0";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return prefix;
|
|
82
|
+
}
|
|
83
|
+
|
|
51
84
|
get prefix() {
|
|
52
85
|
const [prefix] = this.name.split("/");
|
|
53
86
|
return prefix;
|
|
@@ -64,6 +97,10 @@ export class Subnet extends Base {
|
|
|
64
97
|
return this.name;
|
|
65
98
|
}
|
|
66
99
|
|
|
100
|
+
get longAddress() {
|
|
101
|
+
return `${this.longPrefix}/${this.prefixLength}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
67
104
|
_traverse(...args) {
|
|
68
105
|
if (super._traverse(...args)) {
|
|
69
106
|
for (const network of this.networks) {
|
|
@@ -76,7 +113,6 @@ export class Subnet extends Base {
|
|
|
76
113
|
}
|
|
77
114
|
}
|
|
78
115
|
|
|
79
|
-
|
|
80
116
|
export function subnets(sources) {
|
|
81
117
|
const all = new Set();
|
|
82
118
|
|
|
@@ -88,4 +124,3 @@ export function subnets(sources) {
|
|
|
88
124
|
|
|
89
125
|
return all;
|
|
90
126
|
}
|
|
91
|
-
|
package/types/service.d.mts
CHANGED
package/types/subnet.d.mts
CHANGED
|
@@ -28,9 +28,14 @@ export class Subnet extends Base {
|
|
|
28
28
|
get fullName(): string;
|
|
29
29
|
matchesAddress(address: any): any;
|
|
30
30
|
get isLinkLocal(): boolean;
|
|
31
|
+
get isIPv4(): boolean;
|
|
32
|
+
get isIPv6(): boolean;
|
|
33
|
+
get addressRange(): string[];
|
|
34
|
+
get longPrefix(): string;
|
|
31
35
|
get prefix(): string;
|
|
32
36
|
get prefixLength(): number;
|
|
33
37
|
get address(): string;
|
|
38
|
+
get longAddress(): string;
|
|
34
39
|
_traverse(...args: any[]): boolean;
|
|
35
40
|
}
|
|
36
41
|
import { Base } from "./base.mjs";
|