pmcf 1.4.0 → 1.5.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/bin/pmcf-host-defs +5 -5
- package/bin/pmcf-info +3 -5
- package/bin/pmcf-location-defs +13 -7
- package/bin/pmcf-named-defs +15 -16
- package/bin/pmcf-network +10 -6
- package/package.json +1 -1
- package/src/cmd.mjs +26 -0
- package/types/cmd.d.mts +9 -0
package/bin/pmcf-host-defs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { writeFile, mkdir, copyFile, glob } from "node:fs/promises";
|
|
4
|
-
import { cwd, argv } from "node:process";
|
|
5
4
|
import { join } from "node:path";
|
|
6
|
-
import {
|
|
5
|
+
import { writeLines, sectionLines } from "../src/model.mjs";
|
|
6
|
+
import { prepare } from "../src/cmd.mjs";
|
|
7
7
|
|
|
8
|
-
const world
|
|
8
|
+
const { world, args } = prepare();
|
|
9
9
|
|
|
10
|
-
const hostName =
|
|
10
|
+
const hostName = args[0];
|
|
11
11
|
|
|
12
12
|
const host = await world.host(hostName);
|
|
13
13
|
|
|
14
|
-
const targetDir =
|
|
14
|
+
const targetDir = args[1] || `pkg/host-${host.hostName}`;
|
|
15
15
|
|
|
16
16
|
await generateNetworkDefs(host, targetDir);
|
|
17
17
|
await generateMachineInfo(host, targetDir);
|
package/bin/pmcf-info
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { prepare } from "../src/cmd.mjs";
|
|
3
|
+
const { world, args } = prepare();
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const objectName = argv[3];
|
|
5
|
+
const objectName = args[0];
|
|
8
6
|
|
|
9
7
|
if (objectName) {
|
|
10
8
|
const object = await world.named(objectName);
|
package/bin/pmcf-location-defs
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { cwd, argv } from "node:process";
|
|
4
3
|
import { mkdir, copyFile } from "node:fs/promises";
|
|
5
4
|
import { join } from "node:path";
|
|
6
|
-
import {
|
|
5
|
+
import { writeLines, sectionLines } from "../src/model.mjs";
|
|
6
|
+
import { prepare } from "../src/cmd.mjs";
|
|
7
7
|
|
|
8
|
-
const world
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
const { world, args } = prepare();
|
|
9
|
+
|
|
10
|
+
const location = await world.location(args[0] || "SW");
|
|
11
|
+
const targetDir = args[1];
|
|
11
12
|
|
|
12
13
|
await generateLocationDefs(location, targetDir);
|
|
13
14
|
|
|
14
|
-
console.log(
|
|
15
|
+
console.log(
|
|
16
|
+
"provides",
|
|
17
|
+
"location",
|
|
18
|
+
"mf-location",
|
|
19
|
+
`mf-location-${location.name}`
|
|
20
|
+
);
|
|
15
21
|
console.log("replaces", `mf-location-${location.name}`);
|
|
16
22
|
console.log("description", `location definitions for ${location.name}`);
|
|
17
23
|
|
|
@@ -57,7 +63,7 @@ async function generateLocationDefs(location, dir) {
|
|
|
57
63
|
await mkdir(locationDir, { recursive: true });
|
|
58
64
|
|
|
59
65
|
copyFile(
|
|
60
|
-
join(location.directory, "location.json"),
|
|
66
|
+
join(world.directory, location.directory, "location.json"),
|
|
61
67
|
join(locationDir, "location.json")
|
|
62
68
|
);
|
|
63
69
|
}
|
package/bin/pmcf-named-defs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { cwd, argv } from "node:process";
|
|
4
3
|
import { join } from "node:path";
|
|
5
4
|
import { createHmac } from "node:crypto";
|
|
5
|
+
import { writeLines } from "../src/model.mjs";
|
|
6
|
+
import { prepare } from "../src/cmd.mjs";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
const { world, args } = prepare();
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const targetDir = argv[4] || `pkg/mf-named-${location.name}`;
|
|
10
|
+
const location = await world.location(args[0] || "SW");
|
|
11
|
+
const targetDir = args[1] || `pkg/mf-named-${location.name}`;
|
|
12
12
|
const ttl = location.dnsRecordTTL;
|
|
13
13
|
const updates = [
|
|
14
14
|
Math.ceil(Date.now() / 1000),
|
|
@@ -38,7 +38,7 @@ async function generateNamedDefs(location, targetDir) {
|
|
|
38
38
|
const records = new Set();
|
|
39
39
|
|
|
40
40
|
const nameserver = (await location.service({ type: "dns" }))?.owner;
|
|
41
|
-
const rname = location.administratorEmail.replace(/@/,
|
|
41
|
+
const rname = location.administratorEmail.replace(/@/, ".");
|
|
42
42
|
|
|
43
43
|
for await (const mail of location.services({ type: "smtp" })) {
|
|
44
44
|
records.add(
|
|
@@ -48,12 +48,7 @@ async function generateNamedDefs(location, targetDir) {
|
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
console.log(
|
|
52
|
-
location.name,
|
|
53
|
-
location.domain,
|
|
54
|
-
nameserver?.hostName,
|
|
55
|
-
rname
|
|
56
|
-
);
|
|
51
|
+
console.log(location.name, location.domain, nameserver?.hostName, rname);
|
|
57
52
|
|
|
58
53
|
const catalogZone = {
|
|
59
54
|
id: `catalog.${domain}`,
|
|
@@ -63,7 +58,7 @@ async function generateNamedDefs(location, targetDir) {
|
|
|
63
58
|
nameserver.domainName
|
|
64
59
|
}. ${rname}. (${updates})`,
|
|
65
60
|
`${"@".padEnd(NAME_LEN, " ")} ${ttl} IN NS ${nameserver.ipAddress}.`,
|
|
66
|
-
`${("version."+domain+
|
|
61
|
+
`${("version." + domain + ".").padEnd(NAME_LEN, " ")} IN TXT "2"`
|
|
67
62
|
])
|
|
68
63
|
};
|
|
69
64
|
|
|
@@ -152,9 +147,11 @@ async function generateNamedDefs(location, targetDir) {
|
|
|
152
147
|
zones.push(catalogZone);
|
|
153
148
|
|
|
154
149
|
for (const zone of zones) {
|
|
155
|
-
if(zone !== catalogZone) {
|
|
150
|
+
if (zone !== catalogZone) {
|
|
156
151
|
const hash = createHmac("md5", zone.id).digest("hex");
|
|
157
|
-
catalogZone.records.add(
|
|
152
|
+
catalogZone.records.add(
|
|
153
|
+
`${hash}.zones.${domain}. IN PTR ${zone.id}.`
|
|
154
|
+
);
|
|
158
155
|
}
|
|
159
156
|
|
|
160
157
|
zoneConfig.push(`zone \"${zone.id}\" {`);
|
|
@@ -162,7 +159,9 @@ async function generateNamedDefs(location, targetDir) {
|
|
|
162
159
|
zoneConfig.push(` file \"${zone.file}\";`);
|
|
163
160
|
|
|
164
161
|
const u = location.dnsAllowedUpdates;
|
|
165
|
-
zoneConfig.push(
|
|
162
|
+
zoneConfig.push(
|
|
163
|
+
` allow-update { ${u.length ? u.join(";") : "none"}; };`
|
|
164
|
+
);
|
|
166
165
|
zoneConfig.push(` notify yes;`);
|
|
167
166
|
zoneConfig.push(`};`);
|
|
168
167
|
zoneConfig.push("");
|
package/bin/pmcf-network
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { World } from "../src/model.mjs";
|
|
3
|
+
import { prepare } from "../src/cmd.mjs";
|
|
5
4
|
|
|
6
|
-
const world
|
|
7
|
-
|
|
5
|
+
const { world, args } = prepare();
|
|
6
|
+
|
|
7
|
+
const location = await world.location(args[0] || "SW");
|
|
8
8
|
|
|
9
9
|
function q(str) {
|
|
10
10
|
return str.match(/^\w+$/) ? str : `"${str}"`;
|
|
11
11
|
}
|
|
12
12
|
function id(str) {
|
|
13
|
-
return str.replaceAll(/-/g,
|
|
13
|
+
return str.replaceAll(/-/g, "");
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
console.log("graph G {");
|
|
@@ -26,7 +26,11 @@ for await (const host of location.hosts()) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
for await (const network of location.networks()) {
|
|
29
|
-
console.log(
|
|
29
|
+
console.log(
|
|
30
|
+
` ${id(network.name)} [label="${network.name}\\n${
|
|
31
|
+
network.ipv4
|
|
32
|
+
}" shape=circle];`
|
|
33
|
+
);
|
|
30
34
|
|
|
31
35
|
for await (const host of network.hosts()) {
|
|
32
36
|
for (const [n, i] of Object.entries(host.networkInterfaces)) {
|
package/package.json
CHANGED
package/src/cmd.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { argv, cwd, env } from "node:process";
|
|
3
|
+
import { World } from "./model.mjs";
|
|
4
|
+
|
|
5
|
+
export function prepare() {
|
|
6
|
+
const { values, positionals } = parseArgs({
|
|
7
|
+
args: argv.slice(2),
|
|
8
|
+
options: {
|
|
9
|
+
world: {
|
|
10
|
+
type: "string",
|
|
11
|
+
short: "w",
|
|
12
|
+
default: env.PMCF_WORLD || cwd()
|
|
13
|
+
},
|
|
14
|
+
output: {
|
|
15
|
+
type: "string",
|
|
16
|
+
short: "o",
|
|
17
|
+
default: cwd()
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
allowPositionals: true
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const world = new World(values.world);
|
|
24
|
+
|
|
25
|
+
return { world, options: values, args: positionals };
|
|
26
|
+
}
|