pmcf 1.21.2 → 1.23.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 +21 -29
- package/package.json +4 -4
- package/src/model.mjs +59 -9
- package/types/model.d.mts +6 -0
package/bin/pmcf-host-defs
CHANGED
|
@@ -43,42 +43,34 @@ async function generateMachineInfo(host, dir) {
|
|
|
43
43
|
async function generateNetworkDefs(host, dir) {
|
|
44
44
|
const networkDir = join(dir, "etc/systemd/network");
|
|
45
45
|
|
|
46
|
-
for (const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
await writeLines(networkDir, `${name}.link`, [
|
|
51
|
-
sectionLines("Match", { MACAddress: network.hwaddr }),
|
|
46
|
+
for (const ni of Object.values(host.networkInterfaces)) {
|
|
47
|
+
if (ni.name !== "eth0" && ni.hwaddr) {
|
|
48
|
+
await writeLines(networkDir, `${ni.name}.link`, [
|
|
49
|
+
sectionLines("Match", { MACAddress: ni.hwaddr }),
|
|
52
50
|
"",
|
|
53
|
-
sectionLines("Link", { Name: name })
|
|
51
|
+
sectionLines("Link", { Name: ni.name })
|
|
54
52
|
]);
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
const networkSections = [
|
|
58
|
-
sectionLines("Match", { Name: name }),
|
|
59
|
-
"",
|
|
60
|
-
sectionLines("Address", {
|
|
61
|
-
Address: network.ipv4 + "/" + network.network.ipv4_netmask
|
|
62
|
-
})
|
|
63
|
-
];
|
|
55
|
+
const networkSections = [sectionLines("Match", { Name: ni.name })];
|
|
64
56
|
|
|
65
|
-
|
|
57
|
+
for (const Address of ni.ipAddressesWithNetmask) {
|
|
66
58
|
networkSections.push(
|
|
67
59
|
"",
|
|
68
60
|
sectionLines("Address", {
|
|
69
|
-
Address
|
|
61
|
+
Address
|
|
70
62
|
})
|
|
71
63
|
);
|
|
72
64
|
}
|
|
73
65
|
|
|
74
|
-
switch (
|
|
66
|
+
switch (ni.kind) {
|
|
75
67
|
case "ethernet":
|
|
76
68
|
case "wifi":
|
|
77
|
-
const routeSectionExtra =
|
|
78
|
-
? { Destination:
|
|
69
|
+
const routeSectionExtra = ni.destination
|
|
70
|
+
? { Destination: ni.destination }
|
|
79
71
|
: { Gateway: host.location.gateway_ipv4 };
|
|
80
72
|
|
|
81
|
-
const networkSectionExtra =
|
|
73
|
+
const networkSectionExtra = ni.arpbridge
|
|
82
74
|
? {
|
|
83
75
|
IPForward: "yes",
|
|
84
76
|
IPv4ProxyARP: "yes"
|
|
@@ -98,8 +90,8 @@ async function generateNetworkDefs(host, dir) {
|
|
|
98
90
|
"",
|
|
99
91
|
sectionLines("Route", {
|
|
100
92
|
...routeSectionExtra,
|
|
101
|
-
Scope:
|
|
102
|
-
Metric:
|
|
93
|
+
Scope: ni.scope,
|
|
94
|
+
Metric: ni.metric,
|
|
103
95
|
InitialCongestionWindow: 20,
|
|
104
96
|
InitialAdvertisedReceiveWindow: 20
|
|
105
97
|
}),
|
|
@@ -112,7 +104,7 @@ async function generateNetworkDefs(host, dir) {
|
|
|
112
104
|
})
|
|
113
105
|
);
|
|
114
106
|
|
|
115
|
-
if (
|
|
107
|
+
if (ni.arpbridge) {
|
|
116
108
|
networkSections.push(
|
|
117
109
|
"",
|
|
118
110
|
sectionLines("Link", { Promiscuous: "yes" })
|
|
@@ -120,9 +112,9 @@ async function generateNetworkDefs(host, dir) {
|
|
|
120
112
|
}
|
|
121
113
|
}
|
|
122
114
|
|
|
123
|
-
await writeLines(networkDir, `${name}.network`, networkSections);
|
|
115
|
+
await writeLines(networkDir, `${ni.name}.network`, networkSections);
|
|
124
116
|
|
|
125
|
-
switch (
|
|
117
|
+
switch (ni?.kind) {
|
|
126
118
|
case "wireguard":
|
|
127
119
|
{
|
|
128
120
|
}
|
|
@@ -131,21 +123,21 @@ async function generateNetworkDefs(host, dir) {
|
|
|
131
123
|
const d = join(dir, "etc/wpa_supplicant");
|
|
132
124
|
await mkdir(d, { recursive: true });
|
|
133
125
|
writeFile(
|
|
134
|
-
join(d, `wpa_supplicant-${name}.conf`),
|
|
126
|
+
join(d, `wpa_supplicant-${ni.name}.conf`),
|
|
135
127
|
`country=${host.location.country}
|
|
136
128
|
ctrl_interface=DIR=/run/wpa_supplicant GROUP=netdev
|
|
137
129
|
update_config=1
|
|
138
130
|
p2p_disabled=1
|
|
139
131
|
network={
|
|
140
|
-
ssid="${
|
|
141
|
-
psk=${
|
|
132
|
+
ssid="${ni.ssid}"
|
|
133
|
+
psk=${ni.psk}
|
|
142
134
|
scan_ssid=1
|
|
143
135
|
}`,
|
|
144
136
|
"utf8"
|
|
145
137
|
);
|
|
146
138
|
|
|
147
139
|
host.postinstall.push(
|
|
148
|
-
`systemctl enable wpa_supplicant@${name}.service`
|
|
140
|
+
`systemctl enable wpa_supplicant@${ni.name}.service`
|
|
149
141
|
);
|
|
150
142
|
}
|
|
151
143
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmcf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,6 +39,9 @@
|
|
|
39
39
|
"lint:docs": "documentation lint ./src**/*.mjs",
|
|
40
40
|
"lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
41
41
|
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"pacc": "^3.1.9"
|
|
44
|
+
},
|
|
42
45
|
"devDependencies": {
|
|
43
46
|
"@types/node": "^22.10.10",
|
|
44
47
|
"ava": "^6.2.0",
|
|
@@ -64,8 +67,5 @@
|
|
|
64
67
|
"arlac77/template-node-app",
|
|
65
68
|
"arlac77/template-typescript"
|
|
66
69
|
]
|
|
67
|
-
},
|
|
68
|
-
"dependencies": {
|
|
69
|
-
"pacc": "^3.1.9"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/src/model.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { readFile, glob } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
asArray,
|
|
5
|
+
bridgeToJSON,
|
|
6
|
+
isIPv4Address,
|
|
7
|
+
isIPv6Address
|
|
8
|
+
} from "./utils.mjs";
|
|
4
9
|
import { Base } from "./base.mjs";
|
|
5
10
|
import { DNSService } from "./dns.mjs";
|
|
6
11
|
|
|
@@ -639,10 +644,8 @@ export class Host extends Base {
|
|
|
639
644
|
|
|
640
645
|
*networkAddresses() {
|
|
641
646
|
for (const networkInterface of Object.values(this.networkInterfaces)) {
|
|
642
|
-
for (const
|
|
643
|
-
|
|
644
|
-
yield { address: networkInterface[attribute], networkInterface };
|
|
645
|
-
}
|
|
647
|
+
for (const address of networkInterface.ipAddresses) {
|
|
648
|
+
yield { address, networkInterface };
|
|
646
649
|
}
|
|
647
650
|
}
|
|
648
651
|
}
|
|
@@ -692,17 +695,34 @@ export class NetworkInterface extends Base {
|
|
|
692
695
|
return "network_interface";
|
|
693
696
|
}
|
|
694
697
|
|
|
698
|
+
#ipAddresses = [];
|
|
695
699
|
#scope;
|
|
696
700
|
#metric;
|
|
697
701
|
#ssid;
|
|
698
702
|
#psk;
|
|
699
703
|
#network;
|
|
704
|
+
#kind;
|
|
700
705
|
arpbridge;
|
|
701
706
|
hwaddr;
|
|
702
707
|
|
|
703
708
|
constructor(owner, data) {
|
|
704
709
|
super(owner, data);
|
|
705
710
|
|
|
711
|
+
if (data.ipv4) {
|
|
712
|
+
this.#ipAddresses.push(...asArray(data.ipv4));
|
|
713
|
+
delete data.ipv4;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (data.ipv6) {
|
|
717
|
+
this.#ipAddresses.push(...asArray(data.ipv6));
|
|
718
|
+
delete data.ipv6;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
if (data.ipAddresses) {
|
|
722
|
+
this.#ipAddresses.push(...asArray(data.ipAddresses));
|
|
723
|
+
delete data.ipAddresses;
|
|
724
|
+
}
|
|
725
|
+
|
|
706
726
|
if (data.ssid) {
|
|
707
727
|
this.#ssid = data.ssid;
|
|
708
728
|
delete data.ssid;
|
|
@@ -717,7 +737,11 @@ export class NetworkInterface extends Base {
|
|
|
717
737
|
}
|
|
718
738
|
if (data.metric) {
|
|
719
739
|
this.#metric = data.metric;
|
|
720
|
-
delete data.
|
|
740
|
+
delete data.metric;
|
|
741
|
+
}
|
|
742
|
+
if (data.kind) {
|
|
743
|
+
this.#kind = data.kind;
|
|
744
|
+
delete data.kind;
|
|
721
745
|
}
|
|
722
746
|
|
|
723
747
|
if (data.network) {
|
|
@@ -742,6 +766,24 @@ export class NetworkInterface extends Base {
|
|
|
742
766
|
//this.arpbridge = owner.addARPBridge(this, data.arpbridge);
|
|
743
767
|
}
|
|
744
768
|
|
|
769
|
+
get ipAddresses() {
|
|
770
|
+
return this.#ipAddresses;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
get ipAddressesWithNetmask() {
|
|
774
|
+
return this.#ipAddresses.map(a =>
|
|
775
|
+
isIPv4Address(a) ? `${a}/${this.network.ipv4_netmask}` : a
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
get ipv4Addresses() {
|
|
780
|
+
return this.#ipAddresses.filter(a => isIPv4Address(a));
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
get ipv6Addresses() {
|
|
784
|
+
return this.#ipAddresses.filter(a => isIPv6Address(a));
|
|
785
|
+
}
|
|
786
|
+
|
|
745
787
|
get network() {
|
|
746
788
|
return this.#network;
|
|
747
789
|
}
|
|
@@ -781,6 +823,10 @@ export class NetworkInterface extends Base {
|
|
|
781
823
|
return this.#psk || this.network?.psk;
|
|
782
824
|
}
|
|
783
825
|
|
|
826
|
+
get kind() {
|
|
827
|
+
return this.#kind || this.network?.kind;
|
|
828
|
+
}
|
|
829
|
+
|
|
784
830
|
get propertyNames() {
|
|
785
831
|
return [
|
|
786
832
|
...super.propertyNames,
|
|
@@ -790,7 +836,9 @@ export class NetworkInterface extends Base {
|
|
|
790
836
|
"ssid",
|
|
791
837
|
"psk",
|
|
792
838
|
"scope",
|
|
793
|
-
"metric"
|
|
839
|
+
"metric",
|
|
840
|
+
"ipAddresses",
|
|
841
|
+
"kind"
|
|
794
842
|
];
|
|
795
843
|
}
|
|
796
844
|
}
|
|
@@ -865,8 +913,6 @@ export class Service extends Base {
|
|
|
865
913
|
|
|
866
914
|
Object.assign(this, data);
|
|
867
915
|
|
|
868
|
-
// this.owner = owner;
|
|
869
|
-
|
|
870
916
|
owner.addService(this);
|
|
871
917
|
}
|
|
872
918
|
|
|
@@ -909,6 +955,10 @@ export class Service extends Base {
|
|
|
909
955
|
return this.#ipAddresses || this.owner.ipAddresses;
|
|
910
956
|
}
|
|
911
957
|
|
|
958
|
+
get addresses() {
|
|
959
|
+
return this.ipAddresses.map(a => `${a}:${this.port}`);
|
|
960
|
+
}
|
|
961
|
+
|
|
912
962
|
get port() {
|
|
913
963
|
return this.#port || ServiceTypes[this.type]?.port;
|
|
914
964
|
}
|
package/types/model.d.mts
CHANGED
|
@@ -100,10 +100,15 @@ export class NetworkInterface extends Base {
|
|
|
100
100
|
hwaddr: any;
|
|
101
101
|
set network(networkOrName: any);
|
|
102
102
|
get network(): any;
|
|
103
|
+
get ipAddresses(): any[];
|
|
104
|
+
get ipAddressesWithNetmask(): any[];
|
|
105
|
+
get ipv4Addresses(): any[];
|
|
106
|
+
get ipv6Addresses(): any[];
|
|
103
107
|
get scope(): any;
|
|
104
108
|
get metric(): any;
|
|
105
109
|
get ssid(): any;
|
|
106
110
|
get psk(): any;
|
|
111
|
+
get kind(): any;
|
|
107
112
|
#private;
|
|
108
113
|
}
|
|
109
114
|
export class Subnet extends Base {
|
|
@@ -115,6 +120,7 @@ export class Service extends Base {
|
|
|
115
120
|
get protocol(): any;
|
|
116
121
|
get srvPrefix(): string;
|
|
117
122
|
get ipAddresses(): any;
|
|
123
|
+
get addresses(): any;
|
|
118
124
|
get port(): any;
|
|
119
125
|
get priority(): any;
|
|
120
126
|
get weight(): any;
|