@parhelia/capture 0.0.0-stage → 0.4.12893
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/README.md +83 -2
- package/dist/browserHost.d.ts +19 -0
- package/dist/browserHost.d.ts.map +1 -0
- package/dist/browserHost.js +247 -0
- package/dist/browserHostLink.d.ts +50 -0
- package/dist/browserHostLink.d.ts.map +1 -0
- package/dist/browserHostLink.js +193 -0
- package/dist/browserHostProtocol.d.ts +61 -0
- package/dist/browserHostProtocol.d.ts.map +1 -0
- package/dist/browserHostProtocol.js +29 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +239 -0
- package/dist/cmsJob.d.ts +38 -0
- package/dist/cmsJob.d.ts.map +1 -0
- package/dist/cmsJob.js +218 -0
- package/dist/egressProxy.d.ts +59 -0
- package/dist/egressProxy.d.ts.map +1 -0
- package/dist/egressProxy.js +205 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/install/doctor.d.ts +31 -0
- package/dist/install/doctor.d.ts.map +1 -0
- package/dist/install/doctor.js +189 -0
- package/dist/install/install.d.ts +72 -0
- package/dist/install/install.d.ts.map +1 -0
- package/dist/install/install.js +267 -0
- package/dist/install/layout.d.ts +81 -0
- package/dist/install/layout.d.ts.map +1 -0
- package/dist/install/layout.js +77 -0
- package/dist/install/services.d.ts +16 -0
- package/dist/install/services.d.ts.map +1 -0
- package/dist/install/services.js +94 -0
- package/dist/install/sys.d.ts +91 -0
- package/dist/install/sys.d.ts.map +1 -0
- package/dist/install/sys.js +260 -0
- package/dist/install/units.d.ts +57 -0
- package/dist/install/units.d.ts.map +1 -0
- package/dist/install/units.js +244 -0
- package/dist/install/updater.d.ts +66 -0
- package/dist/install/updater.d.ts.map +1 -0
- package/dist/install/updater.js +111 -0
- package/dist/install/versions.d.ts +61 -0
- package/dist/install/versions.d.ts.map +1 -0
- package/dist/install/versions.js +204 -0
- package/dist/isolation.d.ts +76 -0
- package/dist/isolation.d.ts.map +1 -0
- package/dist/isolation.js +163 -0
- package/dist/parheliaClient.d.ts +97 -0
- package/dist/parheliaClient.d.ts.map +1 -0
- package/dist/parheliaClient.js +111 -0
- package/dist/version.d.ts +13 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +36 -0
- package/dist/webIsolation.d.ts +24 -0
- package/dist/webIsolation.d.ts.map +1 -0
- package/dist/webIsolation.js +112 -0
- package/dist/webJob.d.ts +56 -0
- package/dist/webJob.d.ts.map +1 -0
- package/dist/webJob.js +177 -0
- package/dist/worker.d.ts +53 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +213 -0
- package/package.json +28 -4
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Capture sidecar CS6 (plan §5): `install` and `uninstall`. One command sets the machine up from a pairing code:
|
|
3
|
+
*
|
|
4
|
+
* Linux (root, systemd): the ipc group and two service users (the worker, and the browser user whose only group is the ipc
|
|
5
|
+
* group); /opt/parhelia-capture root-owned and read-only to both; the key (0600, the worker's); the version the host names,
|
|
6
|
+
* installed with every hash checked (a source build: the running package); Chromium's libraries and emoji fonts on apt systems;
|
|
7
|
+
* the socket scan (A7); the worker, browser host and updater units and the timer; then it waits for the worker's first poll.
|
|
8
|
+
* Windows (Administrator): the code under Program Files, the data directory and key with inheritance off (the service account,
|
|
9
|
+
* Administrators, SYSTEM), the browser's outbound firewall rule installed and verified before it runs, and three scheduled tasks.
|
|
10
|
+
* On a Windows machine that runs Parhelia itself, public-web is refused by name (plan §8) and CMS captures still install.
|
|
11
|
+
*/
|
|
12
|
+
import { webPreconditionRefusal } from "../isolation.js";
|
|
13
|
+
import { BROWSER_USER, IPC_GROUP, TASK, UNIT, WORKER_USER, } from "./layout.js";
|
|
14
|
+
import { services } from "./services.js";
|
|
15
|
+
import { dataDirAclArgs, keyFileAclArgs, keyFileAclHolds, launcherScript, linuxUnits, windowsTasks } from "./units.js";
|
|
16
|
+
import { readJson } from "./updater.js";
|
|
17
|
+
import { browserOf, currentVersion, installDev, installRelease, readRecord, switchCurrent } from "./versions.js";
|
|
18
|
+
export const MIN_NODE_MAJOR = 22;
|
|
19
|
+
export class CaptureInstallError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
constructor(code, message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.name = "CaptureInstallError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function must(result, what) {
|
|
28
|
+
if (result.status !== 0)
|
|
29
|
+
throw new CaptureInstallError("capture-install-step", `${what} failed: ${(result.stderr || result.stdout).trim().split("\n").slice(-3).join(" ")}`);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
/** Node ≥ 22, the rights, and the service manager, each refused by name (plan §5 "doctor names the failure"). */
|
|
33
|
+
export function preflight(sys, layout) {
|
|
34
|
+
const major = Number(sys.nodeVersion.split(".")[0]);
|
|
35
|
+
if (!(major >= MIN_NODE_MAJOR))
|
|
36
|
+
throw new CaptureInstallError("capture-install-node", `Node ${MIN_NODE_MAJOR} or later is required (this is ${sys.nodeVersion}). Install it from your OS packages or nodejs.org, then run the command again.`);
|
|
37
|
+
if (!sys.isPrivileged())
|
|
38
|
+
throw new CaptureInstallError("capture-install-rights", layout.platform === "win32"
|
|
39
|
+
? "Run the install from an Administrator PowerShell." : "Run the install as root (sudo npx @parhelia/capture install …).");
|
|
40
|
+
if (layout.platform === "linux" && sys.exec("systemctl", ["--version"]).status !== 0)
|
|
41
|
+
throw new CaptureInstallError("capture-install-systemd", "The capture service installs as systemd units; this machine has no systemd.");
|
|
42
|
+
}
|
|
43
|
+
export async function install(input) {
|
|
44
|
+
const { sys, layout } = input;
|
|
45
|
+
const log = input.log ?? (() => undefined);
|
|
46
|
+
const warnings = [];
|
|
47
|
+
preflight(sys, layout);
|
|
48
|
+
// 1. Accounts and directories (Linux), protected directories (Windows).
|
|
49
|
+
if (layout.platform === "linux") {
|
|
50
|
+
log("Creating the service users");
|
|
51
|
+
if (sys.exec("getent", ["group", IPC_GROUP]).status !== 0)
|
|
52
|
+
must(sys.exec("groupadd", ["--system", IPC_GROUP]), `Creating group ${IPC_GROUP}`);
|
|
53
|
+
if (sys.exec("id", ["-u", WORKER_USER]).status !== 0)
|
|
54
|
+
must(sys.exec("useradd", ["--system", "--gid", IPC_GROUP, "--home-dir", layout.stateDir, "--no-create-home", "--shell", "/usr/sbin/nologin", WORKER_USER]), `Creating user ${WORKER_USER}`);
|
|
55
|
+
if (sys.exec("id", ["-u", BROWSER_USER]).status !== 0)
|
|
56
|
+
must(sys.exec("useradd", ["--system", "--gid", IPC_GROUP, "--home-dir", "/nonexistent", "--no-create-home", "--shell", "/usr/sbin/nologin", BROWSER_USER]), `Creating user ${BROWSER_USER}`);
|
|
57
|
+
// The browser user has no supplementary group: a group-permissioned socket it can still see refuses it (plan §8).
|
|
58
|
+
must(sys.exec("usermod", ["-G", "", BROWSER_USER]), `Clearing ${BROWSER_USER}'s supplementary groups`);
|
|
59
|
+
for (const dir of [layout.prefix, layout.versionsDir, layout.configDir]) {
|
|
60
|
+
sys.mkdir(dir, { mode: 0o755 });
|
|
61
|
+
sys.chown(dir, "root", "root");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
for (const dir of [layout.prefix, layout.versionsDir, layout.configDir, layout.stateDir])
|
|
66
|
+
sys.mkdir(dir);
|
|
67
|
+
must(sys.exec("icacls", dataDirAclArgs(layout.configDir)), "Protecting the data directory");
|
|
68
|
+
}
|
|
69
|
+
// 2. The key: generated here and paired by its hash, or the provisioned one. It never appears in the UI, the shell or ps.
|
|
70
|
+
let key;
|
|
71
|
+
let allowed;
|
|
72
|
+
let workerId;
|
|
73
|
+
if (input.pairCode) {
|
|
74
|
+
key = input.newKey();
|
|
75
|
+
log("Pairing with Parhelia");
|
|
76
|
+
const paired = await input.pair(input.origin, input.pairCode, key, input.name).catch((error) => {
|
|
77
|
+
throw new CaptureInstallError("capture-install-pairing", `Pairing failed: ${error instanceof Error ? error.message : String(error)} (a code works once, for ten minutes: create a new one under Settings › Capture service).`);
|
|
78
|
+
});
|
|
79
|
+
allowed = paired.capabilities;
|
|
80
|
+
workerId = paired.workerId;
|
|
81
|
+
}
|
|
82
|
+
else if (input.keyFile) {
|
|
83
|
+
key = sys.readFile(input.keyFile).trim();
|
|
84
|
+
}
|
|
85
|
+
else if (sys.exists(layout.keyFile)) {
|
|
86
|
+
key = sys.readFile(layout.keyFile).trim();
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new CaptureInstallError("capture-install-key", "Pass the pairing code from Settings › Capture service (--pair XXXXX-XXXXX-XXXXX-XXXXX), or --key-file.");
|
|
90
|
+
}
|
|
91
|
+
sys.writeFile(layout.keyFile, key + "\n", { mode: 0o600 });
|
|
92
|
+
if (layout.platform === "linux")
|
|
93
|
+
sys.chown(layout.keyFile, WORKER_USER, IPC_GROUP);
|
|
94
|
+
else {
|
|
95
|
+
must(sys.exec("icacls", keyFileAclArgs(layout.keyFile)), "Protecting the key file");
|
|
96
|
+
const acl = keyFileAclHolds(must(sys.exec("icacls", [layout.keyFile]), "Reading the key file's ACL").stdout, layout.keyFile);
|
|
97
|
+
if (!acl.ok)
|
|
98
|
+
throw new CaptureInstallError("capture-install-key-acl", acl.detail);
|
|
99
|
+
}
|
|
100
|
+
// 3. What runs here: public-web only when the host allows it (the pairing's answer, or for a provisioned key the manifest's)
|
|
101
|
+
// and the isolation can be set up.
|
|
102
|
+
const answer = await input.fetchManifest(key).catch((error) => {
|
|
103
|
+
throw new CaptureInstallError("capture-install-unreachable", `Parhelia at ${new URL(input.origin).origin} did not answer with this key: ${error instanceof Error ? error.message : String(error)}`);
|
|
104
|
+
});
|
|
105
|
+
allowed ??= answer.capabilities;
|
|
106
|
+
let web = input.web ?? allowed?.includes("public-web") ?? false;
|
|
107
|
+
let webNote;
|
|
108
|
+
if (web && allowed && !allowed.includes("public-web")) {
|
|
109
|
+
web = false;
|
|
110
|
+
webNote = "The pairing does not allow screenshots of public websites.";
|
|
111
|
+
}
|
|
112
|
+
if (web && layout.platform === "win32") {
|
|
113
|
+
const refusal = webPreconditionRefusal({ platform: "win32", colocated: await input.colocated(), probeUrl: input.probeUrl });
|
|
114
|
+
if (refusal) {
|
|
115
|
+
web = false;
|
|
116
|
+
webNote = `${refusal.code}: ${refusal.message}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// 4. Chromium's libraries and fonts (apt systems; elsewhere named as a warning).
|
|
120
|
+
if (layout.platform === "linux") {
|
|
121
|
+
if (sys.exec("sh", ["-c", "command -v apt-get"]).status === 0) {
|
|
122
|
+
log("Installing Chromium's libraries and fonts");
|
|
123
|
+
// A fresh image has no package lists yet.
|
|
124
|
+
must(sys.exec("apt-get", ["update", "-q"], { env: { DEBIAN_FRONTEND: "noninteractive" } }), "Updating the package lists");
|
|
125
|
+
must(sys.exec("apt-get", ["install", "-y", "--no-install-recommends", "unzip", "fonts-noto-color-emoji", "fonts-liberation"], { env: { DEBIAN_FRONTEND: "noninteractive" } }), "Installing unzip and fonts");
|
|
126
|
+
must(sys.exec(sys.nodePath, [layout.join(input.self.playwrightDir, "cli.js"), "install-deps", "chromium-headless-shell"], { env: { DEBIAN_FRONTEND: "noninteractive" } }), "Installing Chromium's libraries");
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
warnings.push("This is not an apt-based system: install Chromium's libraries (see 'npx playwright-core install-deps --dry-run chromium-headless-shell'), unzip and an emoji font yourself.");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// 5. The code: the version the host names (hash-checked), or this running package for a source build.
|
|
133
|
+
const config = {
|
|
134
|
+
origin: new URL(input.origin).origin, keyFile: layout.keyFile, web, probeUrl: input.probeUrl, publicUrl: input.publicUrl,
|
|
135
|
+
socketDir: layout.socketDir, installDir: layout.currentLink, versionsDir: layout.versionsDir, statusFile: layout.statusFile,
|
|
136
|
+
updaterStatusFile: layout.updaterStatusFile, socketGroupAccess: layout.platform === "linux", registry: input.registry,
|
|
137
|
+
browserMirror: input.browserMirror, browserPath: input.browserPath,
|
|
138
|
+
inaccessiblePaths: layout.platform === "linux" ? input.scanSockets() : undefined,
|
|
139
|
+
};
|
|
140
|
+
let versionDir;
|
|
141
|
+
if (answer.release) {
|
|
142
|
+
log(`Installing version ${answer.manifest.version} (named by Parhelia)`);
|
|
143
|
+
versionDir = await installRelease(sys, layout, config, answer.manifest, { fromTarball: input.fromTarball, log });
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
log("Parhelia names no release (a source build): installing this package as it is, unchecked");
|
|
147
|
+
versionDir = installDev(sys, layout, { ...input.self, browserPath: input.browserPath });
|
|
148
|
+
warnings.push("Installed from a source build: no host-named hash checked this code or its browser.");
|
|
149
|
+
}
|
|
150
|
+
const record = readRecord(sys, versionDir);
|
|
151
|
+
// 6. Windows: the browser's rule, installed and verified before it ever runs (plan §8).
|
|
152
|
+
if (web && layout.platform === "win32") {
|
|
153
|
+
const executable = browserOf(sys, layout, versionDir);
|
|
154
|
+
const held = executable && input.firewall ? (input.firewall.install(record.version, executable), input.firewall.verify(record.version, executable)) : undefined;
|
|
155
|
+
if (!held?.ok) {
|
|
156
|
+
web = false;
|
|
157
|
+
config.web = false;
|
|
158
|
+
webNote = `capture-web-firewall: the browser's outbound rule could not be installed and verified${held ? ` (${held.detail})` : ""}; screenshots of public websites stay off.`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
switchCurrent(sys, layout, record.version);
|
|
162
|
+
sys.writeFile(layout.configFile, JSON.stringify(config, null, 2) + "\n", { mode: 0o644 });
|
|
163
|
+
if (layout.platform === "linux")
|
|
164
|
+
sys.chown(layout.configFile, "root", "root");
|
|
165
|
+
// The command administrators run afterwards (status, doctor, update) runs the installed version, not this bootstrap copy.
|
|
166
|
+
sys.writeFile(layout.launcher, launcherScript(layout, sys.nodePath), { mode: 0o755 });
|
|
167
|
+
if (layout.platform === "linux")
|
|
168
|
+
sys.chown(layout.launcher, "root", "root");
|
|
169
|
+
// 7. The services.
|
|
170
|
+
const unitInput = { layout, nodePath: sys.nodePath, inaccessiblePaths: config.inaccessiblePaths ?? [], web };
|
|
171
|
+
if (layout.platform === "linux") {
|
|
172
|
+
for (const [name, text] of Object.entries(linuxUnits(unitInput)))
|
|
173
|
+
sys.writeFile(layout.join(layout.unitDir, name), text, { mode: 0o644 });
|
|
174
|
+
if (!web)
|
|
175
|
+
sys.remove(layout.join(layout.unitDir, UNIT.browserHost));
|
|
176
|
+
must(sys.exec("systemctl", ["daemon-reload"]), "Reloading systemd");
|
|
177
|
+
must(sys.exec("systemctl", ["enable", UNIT.worker, ...(web ? [UNIT.browserHost] : []), UNIT.updaterTimer]), "Enabling the units");
|
|
178
|
+
sys.exec("systemctl", ["stop", UNIT.worker]);
|
|
179
|
+
must(sys.exec("systemctl", ["start", UNIT.updaterTimer]), "Starting the update timer");
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
sys.mkdir(layout.unitDir);
|
|
183
|
+
for (const [name, text] of Object.entries(windowsTasks(unitInput))) {
|
|
184
|
+
const file = layout.join(layout.unitDir, `${name}.xml`);
|
|
185
|
+
sys.writeFile(file, text);
|
|
186
|
+
must(sys.exec("schtasks", ["/Create", "/TN", TASK.folder + name, "/XML", file, "/F"]), `Registering the task ${name}`);
|
|
187
|
+
}
|
|
188
|
+
if (!web)
|
|
189
|
+
sys.exec("schtasks", ["/Delete", "/TN", TASK.folder + TASK.browserHost, "/F"]);
|
|
190
|
+
}
|
|
191
|
+
services(sys, layout, web).start();
|
|
192
|
+
// 8. The first good poll proves origin, key and code.
|
|
193
|
+
const since = sys.now();
|
|
194
|
+
let polled = false;
|
|
195
|
+
for (const until = sys.now() + (input.waitMs ?? 60_000); sys.now() < until;) {
|
|
196
|
+
const status = readJson(sys, layout.statusFile);
|
|
197
|
+
if (status?.lastPollOk && status.version === record.version && Date.parse(status.lastPollUtc ?? "") >= since) {
|
|
198
|
+
polled = true;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
await sys.sleep(1_000);
|
|
202
|
+
}
|
|
203
|
+
if (!polled && (input.waitMs ?? 60_000) > 0)
|
|
204
|
+
warnings.push(`The worker has not polled Parhelia yet: run 'parhelia-capture doctor' for the reason${layout.platform === "linux" ? ` (journalctl -u ${UNIT.worker})` : ""}.`);
|
|
205
|
+
return { version: record.version, source: record.source, web, webNote, workerId, polled, warnings };
|
|
206
|
+
}
|
|
207
|
+
/** Removes the services, the code, the state and (unless kept) the key; on Linux the users and the group. */
|
|
208
|
+
export function uninstall(input) {
|
|
209
|
+
const { sys, layout } = input;
|
|
210
|
+
preflight(sys, layout);
|
|
211
|
+
if (layout.platform === "linux") {
|
|
212
|
+
sys.exec("systemctl", ["disable", "--now", UNIT.updaterTimer, UNIT.browserHost, UNIT.worker]);
|
|
213
|
+
for (const unit of Object.values(UNIT))
|
|
214
|
+
sys.remove(layout.join(layout.unitDir, unit));
|
|
215
|
+
sys.exec("systemctl", ["daemon-reload"]);
|
|
216
|
+
sys.remove(layout.prefix);
|
|
217
|
+
sys.remove(layout.launcher);
|
|
218
|
+
sys.remove(layout.stateDir);
|
|
219
|
+
sys.remove(layout.browserStateDir);
|
|
220
|
+
if (input.keepKey)
|
|
221
|
+
sys.remove(layout.configFile);
|
|
222
|
+
else
|
|
223
|
+
sys.remove(layout.configDir);
|
|
224
|
+
sys.exec("userdel", [BROWSER_USER]);
|
|
225
|
+
sys.exec("userdel", [WORKER_USER]);
|
|
226
|
+
sys.exec("groupdel", [IPC_GROUP]);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
for (const task of [TASK.worker, TASK.browserHost, TASK.updater]) {
|
|
230
|
+
sys.exec("schtasks", ["/End", "/TN", TASK.folder + task]);
|
|
231
|
+
sys.exec("schtasks", ["/Delete", "/TN", TASK.folder + task, "/F"]);
|
|
232
|
+
}
|
|
233
|
+
sys.exec("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "Remove-NetFirewallRule -Group 'Parhelia capture' -ErrorAction SilentlyContinue"]);
|
|
234
|
+
sys.remove(layout.prefix);
|
|
235
|
+
if (input.keepKey) {
|
|
236
|
+
sys.remove(layout.stateDir);
|
|
237
|
+
sys.remove(layout.unitDir);
|
|
238
|
+
sys.remove(layout.configFile);
|
|
239
|
+
}
|
|
240
|
+
else
|
|
241
|
+
sys.remove(layout.configDir);
|
|
242
|
+
}
|
|
243
|
+
/** What `status` prints: versions, services, the last poll, the web profile, and the updater's last run. */
|
|
244
|
+
export function statusLines(sys, layout) {
|
|
245
|
+
const lines = [];
|
|
246
|
+
const config = readJson(sys, layout.configFile);
|
|
247
|
+
if (!config)
|
|
248
|
+
return ["The capture service is not installed here."];
|
|
249
|
+
const current = currentVersion(sys, layout);
|
|
250
|
+
const record = current ? readRecord(sys, layout.join(layout.versionsDir, current)) : undefined;
|
|
251
|
+
lines.push(`Parhelia: ${config.origin}`);
|
|
252
|
+
lines.push(`Version: ${current ?? "none"}${record ? ` (${record.source === "release" ? "checked against Parhelia's hashes" : "source build, unchecked"}; browser ${record.browserRevision ?? "?"})` : ""}`);
|
|
253
|
+
if (layout.platform === "linux") {
|
|
254
|
+
for (const unit of [UNIT.worker, ...(config.web ? [UNIT.browserHost] : []), UNIT.updaterTimer])
|
|
255
|
+
lines.push(`${unit}: ${sys.exec("systemctl", ["is-active", unit]).stdout.trim() || "unknown"}`);
|
|
256
|
+
}
|
|
257
|
+
const status = readJson(sys, layout.statusFile);
|
|
258
|
+
lines.push(status ? `Last poll: ${status.lastPollUtc ?? "never"} (${status.lastPollOk ? "ok" : status.lastPollError ?? "failed"})` : "Last poll: none yet");
|
|
259
|
+
lines.push(`Screenshots of public websites: ${!config.web ? "not installed" : status?.web?.ok ? "on" : `off (${status?.web?.reason ?? "not verified yet"})`}`);
|
|
260
|
+
const updater = readJson(sys, layout.updaterStatusFile);
|
|
261
|
+
if (updater) {
|
|
262
|
+
lines.push(`Updater: ${updater.result} at ${updater.checkedUtc}${updater.wanted ? `, Parhelia names ${updater.wanted}` : ""}`);
|
|
263
|
+
for (const problem of updater.problems)
|
|
264
|
+
lines.push(` Problem: ${problem}`);
|
|
265
|
+
}
|
|
266
|
+
return lines;
|
|
267
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export declare const WORKER_USER = "parhelia-capture";
|
|
2
|
+
export declare const BROWSER_USER = "parhelia-capture-browser";
|
|
3
|
+
/** The worker's primary group and the browser user's only group: it reaches the job and egress sockets, nothing else. */
|
|
4
|
+
export declare const IPC_GROUP = "parhelia-capture-ipc";
|
|
5
|
+
/** Windows: the built-in account the worker and browser host tasks run as (no password, no interactive logon). */
|
|
6
|
+
export declare const WINDOWS_SERVICE_ACCOUNT = "NT AUTHORITY\\LOCAL SERVICE";
|
|
7
|
+
export declare const UNIT: {
|
|
8
|
+
readonly worker: "parhelia-capture-worker.service";
|
|
9
|
+
readonly browserHost: "parhelia-capture-browser-host.service";
|
|
10
|
+
readonly updater: "parhelia-capture-updater.service";
|
|
11
|
+
readonly updaterTimer: "parhelia-capture-updater.timer";
|
|
12
|
+
};
|
|
13
|
+
export declare const TASK: {
|
|
14
|
+
readonly folder: "\\Parhelia Capture\\";
|
|
15
|
+
readonly worker: "Worker";
|
|
16
|
+
readonly browserHost: "Browser host";
|
|
17
|
+
readonly updater: "Updater";
|
|
18
|
+
};
|
|
19
|
+
export type Layout = {
|
|
20
|
+
platform: "linux" | "win32";
|
|
21
|
+
prefix: string;
|
|
22
|
+
versionsDir: string;
|
|
23
|
+
currentLink: string;
|
|
24
|
+
configDir: string;
|
|
25
|
+
configFile: string;
|
|
26
|
+
keyFile: string;
|
|
27
|
+
stateDir: string;
|
|
28
|
+
/** The worker's own status (version, last poll, web profile), read by `status` and by the updater's health check. */
|
|
29
|
+
statusFile: string;
|
|
30
|
+
/** The updater's last run (wanted version, outcome, problems), read by the worker into its poll report. */
|
|
31
|
+
updaterStatusFile: string;
|
|
32
|
+
browserStateDir: string;
|
|
33
|
+
socketDir: string;
|
|
34
|
+
unitDir: string;
|
|
35
|
+
/** The `parhelia-capture` command an administrator runs (status, doctor, update): always the installed current version. */
|
|
36
|
+
launcher: string;
|
|
37
|
+
join: (...parts: string[]) => string;
|
|
38
|
+
};
|
|
39
|
+
export declare function linuxLayout(): Layout;
|
|
40
|
+
export declare function windowsLayout(env?: Record<string, string | undefined>): Layout;
|
|
41
|
+
export declare function layoutFor(platform: NodeJS.Platform, env?: Record<string, string | undefined>): Layout;
|
|
42
|
+
/** The installed configuration (no secret: the key is its own file). */
|
|
43
|
+
export type InstalledConfig = {
|
|
44
|
+
origin: string;
|
|
45
|
+
keyFile: string;
|
|
46
|
+
/** Screenshots of public websites (the pairing allowed it, and isolation could be set up). */
|
|
47
|
+
web: boolean;
|
|
48
|
+
probeUrl?: string;
|
|
49
|
+
publicUrl?: string;
|
|
50
|
+
socketDir: string;
|
|
51
|
+
/** The `current` link: each process reads its browser from `<installDir>/install.json`. */
|
|
52
|
+
installDir: string;
|
|
53
|
+
versionsDir: string;
|
|
54
|
+
statusFile: string;
|
|
55
|
+
updaterStatusFile: string;
|
|
56
|
+
/** Sockets shared with the browser user through the ipc group (0660/0750) instead of owner-only. */
|
|
57
|
+
socketGroupAccess: boolean;
|
|
58
|
+
/** An npm registry other than the default (the integrity still decides). */
|
|
59
|
+
registry?: string;
|
|
60
|
+
/** Replaces the origin of the browser archive's URL (a mirror; the SHA-256 still decides). */
|
|
61
|
+
browserMirror?: string;
|
|
62
|
+
/** An explicit browser (air-gapped `--browser-path`); updates then leave the browser alone. */
|
|
63
|
+
browserPath?: string;
|
|
64
|
+
/** Linux: directories holding a Unix socket outside the hidden trees, made inaccessible in the browser host unit (A7). */
|
|
65
|
+
inaccessiblePaths?: string[];
|
|
66
|
+
};
|
|
67
|
+
/** What one installed version records about itself (`<version>/install.json`). */
|
|
68
|
+
export type InstallRecord = {
|
|
69
|
+
version: string;
|
|
70
|
+
/** Where the code came from: `release` (hash-checked against the host), `dev` (a source build, unchecked). */
|
|
71
|
+
source: "release" | "dev";
|
|
72
|
+
browserRevision?: string;
|
|
73
|
+
browserReleasedUtc?: string;
|
|
74
|
+
/** The browser executable, relative to the version directory (or absolute for an explicit `--browser-path`). */
|
|
75
|
+
browserExecutable?: string;
|
|
76
|
+
installedUtc: string;
|
|
77
|
+
/** The package entry, relative to the version directory. */
|
|
78
|
+
entry: string;
|
|
79
|
+
};
|
|
80
|
+
export declare const PACKAGE_ENTRY: string;
|
|
81
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/install/layout.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,WAAW,qBAAqB,CAAC;AAC9C,eAAO,MAAM,YAAY,6BAA6B,CAAC;AACvD,yHAAyH;AACzH,eAAO,MAAM,SAAS,yBAAyB,CAAC;AAChD,kHAAkH;AAClH,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AAErE,eAAO,MAAM,IAAI;aACf,MAAM,EAAE,iCAAiC;aACzC,WAAW,EAAE,uCAAuC;aACpD,OAAO,EAAE,kCAAkC;aAC3C,YAAY,EAAE,gCAAgC;CACtC,CAAC;AAEX,eAAO,MAAM,IAAI;aAAK,MAAM,EAAE,sBAAsB;aAAE,MAAM,EAAE,QAAQ;aAAE,WAAW,EAAE,cAAc;aAAE,OAAO,EAAE,SAAS;CAAW,CAAC;AAEnI,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,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H,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,CAAC;AAEF,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,8GAA8G;IAC9G,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gHAAgH;IAChH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,aAAa,QAA4E,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Capture sidecar CS6 (plan §5): where an installed sidecar lives, and its configuration file.
|
|
3
|
+
*
|
|
4
|
+
* Linux: the code under /opt/parhelia-capture/versions/<x.y.z> with the `current` link beside them, all root-owned and read-only
|
|
5
|
+
* to the service users, so a compromised worker cannot rewrite its own code or persist across restarts; the configuration and
|
|
6
|
+
* the key under /etc/parhelia-capture (the key 0600, owned by the worker user); the worker's state under /var/lib; the job and
|
|
7
|
+
* egress sockets under /run/parhelia-capture/browser-host (0750, group parhelia-capture-ipc: the browser user's only group).
|
|
8
|
+
* Windows: the code under %ProgramFiles%\Parhelia Capture (Administrators and SYSTEM write, everyone else reads), the
|
|
9
|
+
* configuration, key and state under %ProgramData%\Parhelia Capture (the key with inheritance off: the service account,
|
|
10
|
+
* Administrators, SYSTEM), the sockets as named pipes.
|
|
11
|
+
*/
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
export const WORKER_USER = "parhelia-capture";
|
|
14
|
+
export const BROWSER_USER = "parhelia-capture-browser";
|
|
15
|
+
/** The worker's primary group and the browser user's only group: it reaches the job and egress sockets, nothing else. */
|
|
16
|
+
export const IPC_GROUP = "parhelia-capture-ipc";
|
|
17
|
+
/** Windows: the built-in account the worker and browser host tasks run as (no password, no interactive logon). */
|
|
18
|
+
export const WINDOWS_SERVICE_ACCOUNT = "NT AUTHORITY\\LOCAL SERVICE";
|
|
19
|
+
export const UNIT = {
|
|
20
|
+
worker: "parhelia-capture-worker.service",
|
|
21
|
+
browserHost: "parhelia-capture-browser-host.service",
|
|
22
|
+
updater: "parhelia-capture-updater.service",
|
|
23
|
+
updaterTimer: "parhelia-capture-updater.timer",
|
|
24
|
+
};
|
|
25
|
+
export const TASK = { folder: "\\Parhelia Capture\\", worker: "Worker", browserHost: "Browser host", updater: "Updater" };
|
|
26
|
+
export function linuxLayout() {
|
|
27
|
+
const join = path.posix.join;
|
|
28
|
+
return {
|
|
29
|
+
platform: "linux",
|
|
30
|
+
prefix: "/opt/parhelia-capture",
|
|
31
|
+
versionsDir: "/opt/parhelia-capture/versions",
|
|
32
|
+
currentLink: "/opt/parhelia-capture/versions/current",
|
|
33
|
+
configDir: "/etc/parhelia-capture",
|
|
34
|
+
configFile: "/etc/parhelia-capture/config.json",
|
|
35
|
+
keyFile: "/etc/parhelia-capture/worker.key",
|
|
36
|
+
stateDir: "/var/lib/parhelia-capture",
|
|
37
|
+
statusFile: "/var/lib/parhelia-capture/status.json",
|
|
38
|
+
updaterStatusFile: "/var/lib/parhelia-capture/updater.json",
|
|
39
|
+
browserStateDir: "/var/lib/parhelia-capture-browser",
|
|
40
|
+
socketDir: "/run/parhelia-capture/browser-host",
|
|
41
|
+
unitDir: "/etc/systemd/system",
|
|
42
|
+
launcher: "/usr/local/sbin/parhelia-capture",
|
|
43
|
+
join,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function windowsLayout(env = process.env) {
|
|
47
|
+
const join = path.win32.join;
|
|
48
|
+
const programFiles = env.ProgramFiles ?? "C:\\Program Files";
|
|
49
|
+
const programData = env.ProgramData ?? "C:\\ProgramData";
|
|
50
|
+
const prefix = join(programFiles, "Parhelia Capture");
|
|
51
|
+
const data = join(programData, "Parhelia Capture");
|
|
52
|
+
return {
|
|
53
|
+
platform: "win32",
|
|
54
|
+
prefix,
|
|
55
|
+
versionsDir: join(prefix, "versions"),
|
|
56
|
+
currentLink: join(prefix, "versions", "current"),
|
|
57
|
+
configDir: data,
|
|
58
|
+
configFile: join(data, "config.json"),
|
|
59
|
+
keyFile: join(data, "worker.key"),
|
|
60
|
+
stateDir: join(data, "state"),
|
|
61
|
+
statusFile: join(data, "state", "status.json"),
|
|
62
|
+
updaterStatusFile: join(data, "state", "updater.json"),
|
|
63
|
+
browserStateDir: join(data, "browser"),
|
|
64
|
+
socketDir: "\\\\.\\pipe\\parhelia-capture",
|
|
65
|
+
unitDir: join(data, "tasks"),
|
|
66
|
+
launcher: join(prefix, "parhelia-capture.cmd"),
|
|
67
|
+
join,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function layoutFor(platform, env) {
|
|
71
|
+
if (platform === "linux")
|
|
72
|
+
return linuxLayout();
|
|
73
|
+
if (platform === "win32")
|
|
74
|
+
return windowsLayout(env);
|
|
75
|
+
throw new Error(`The capture service installs on Linux (systemd) and Windows only; this is ${platform}.`);
|
|
76
|
+
}
|
|
77
|
+
export const PACKAGE_ENTRY = path.posix.join("node_modules", "@parhelia", "capture", "dist", "cli.js");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type InstalledConfig, type Layout } from "./layout.js";
|
|
2
|
+
import type { Sys } from "./sys.js";
|
|
3
|
+
import type { Firewall } from "./updater.js";
|
|
4
|
+
export declare const TRIAL_UNIT = "parhelia-capture-trial-browser-host";
|
|
5
|
+
export declare function entryOf(layout: Layout, versionDir: string): string;
|
|
6
|
+
export declare function services(sys: Sys, layout: Layout, web: boolean): {
|
|
7
|
+
stop(): void;
|
|
8
|
+
start(): void;
|
|
9
|
+
};
|
|
10
|
+
export declare function windowsFirewall(sys: Sys): Firewall;
|
|
11
|
+
/** The staged version's self-test (plan CS-D14): run as the worker would, against a trial browser host when public-web is on. */
|
|
12
|
+
export declare function selfTest(sys: Sys, layout: Layout, config: InstalledConfig): (versionDir: string, _version: string) => Promise<{
|
|
13
|
+
ok: boolean;
|
|
14
|
+
detail: string;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=services.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/install/services.ts"],"names":[],"mappings":"AAQA,OAAO,EAAmE,KAAK,eAAe,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACjI,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,eAAO,MAAM,UAAU,wCAAwC,CAAC;AAEhE,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAElE;AAOD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG;IAAE,IAAI,IAAI,IAAI,CAAC;IAAC,KAAK,IAAI,IAAI,CAAA;CAAE,CAahG;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAUlD;AAED,iIAAiI;AACjI,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,gBAC9C,MAAM,YAAY,MAAM,KAAG,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA0C9F"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Capture sidecar CS6: the platform's half of install and update — the services (systemd units, scheduled tasks), the Windows
|
|
3
|
+
* firewall rule, and the self-test a staged version runs before the switch: a test capture as the worker user, and with
|
|
4
|
+
* public-web on, the §8 enforcement checks against a trial browser host started from the staged version in the same isolation
|
|
5
|
+
* as the real one (Linux: a transient unit with the browser host unit's properties).
|
|
6
|
+
*/
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { browserHostUnitProperties } from "../isolation.js";
|
|
9
|
+
import { BROWSER_USER, IPC_GROUP, PACKAGE_ENTRY, TASK, UNIT, WORKER_USER } from "./layout.js";
|
|
10
|
+
import { firewallRemoveScript, firewallRuleHolds, firewallRuleScript, firewallVerifyScript, nodeReadOnlyPaths } from "./units.js";
|
|
11
|
+
export const TRIAL_UNIT = "parhelia-capture-trial-browser-host";
|
|
12
|
+
export function entryOf(layout, versionDir) {
|
|
13
|
+
return layout.join(versionDir, ...PACKAGE_ENTRY.split("/"));
|
|
14
|
+
}
|
|
15
|
+
function check(result, what) {
|
|
16
|
+
if (result.status !== 0)
|
|
17
|
+
throw new Error(`${what} failed: ${(result.stderr || result.stdout).trim().split("\n").slice(-3).join(" ")}`);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
export function services(sys, layout, web) {
|
|
21
|
+
if (layout.platform === "linux") {
|
|
22
|
+
const units = [UNIT.worker, ...(web ? [UNIT.browserHost] : [])];
|
|
23
|
+
return {
|
|
24
|
+
stop: () => void check(sys.exec("systemctl", ["stop", ...units.slice().reverse()]), "Stopping the capture service"),
|
|
25
|
+
start: () => void check(sys.exec("systemctl", ["start", ...units]), "Starting the capture service"),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const tasks = [TASK.worker, ...(web ? [TASK.browserHost] : [])].map((name) => TASK.folder + name);
|
|
29
|
+
return {
|
|
30
|
+
stop: () => tasks.forEach((task) => sys.exec("schtasks", ["/End", "/TN", task])),
|
|
31
|
+
start: () => tasks.forEach((task) => check(sys.exec("schtasks", ["/Run", "/TN", task]), `Starting ${task}`)),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function windowsFirewall(sys) {
|
|
35
|
+
const powershell = (script) => sys.exec("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script]);
|
|
36
|
+
return {
|
|
37
|
+
install: (version, executable) => void check(powershell(firewallRuleScript(version, executable)), "Installing the browser's firewall rule"),
|
|
38
|
+
verify: (version, executable) => {
|
|
39
|
+
const answer = powershell(firewallVerifyScript(version));
|
|
40
|
+
return answer.status === 0 ? firewallRuleHolds(answer.stdout.trim(), executable) : { ok: false, detail: answer.stderr.trim() || "no such rule" };
|
|
41
|
+
},
|
|
42
|
+
remove: (version) => void powershell(firewallRemoveScript(version)),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The staged version's self-test (plan CS-D14): run as the worker would, against a trial browser host when public-web is on. */
|
|
46
|
+
export function selfTest(sys, layout, config) {
|
|
47
|
+
return async (versionDir, _version) => {
|
|
48
|
+
const entry = entryOf(layout, versionDir);
|
|
49
|
+
const asWorker = (args) => layout.platform === "linux"
|
|
50
|
+
? sys.exec("runuser", ["-u", WORKER_USER, "-g", IPC_GROUP, "--", sys.nodePath, entry, ...args], { timeoutMs: 180_000 })
|
|
51
|
+
: sys.exec(sys.nodePath, [entry, ...args], { timeoutMs: 180_000 });
|
|
52
|
+
const quick = asWorker(["doctor", "--quick", "--install-dir", versionDir]);
|
|
53
|
+
if (quick.status !== 0)
|
|
54
|
+
return { ok: false, detail: `the test capture failed: ${lastLines(quick)}` };
|
|
55
|
+
if (!config.web)
|
|
56
|
+
return { ok: true, detail: "test capture ok" };
|
|
57
|
+
if (layout.platform === "linux") {
|
|
58
|
+
const trialDir = path.posix.join(path.posix.dirname(layout.socketDir), "trial");
|
|
59
|
+
sys.remove(trialDir);
|
|
60
|
+
sys.mkdir(trialDir, { mode: 0o750 });
|
|
61
|
+
sys.chown(trialDir, WORKER_USER, IPC_GROUP);
|
|
62
|
+
const properties = browserHostUnitProperties({
|
|
63
|
+
socketDir: trialDir, readOnlyPaths: [layout.versionsDir, ...nodeReadOnlyPaths(sys.nodePath)],
|
|
64
|
+
inaccessiblePaths: config.inaccessiblePaths ?? [], user: BROWSER_USER, environment: { HOME: "/tmp" },
|
|
65
|
+
});
|
|
66
|
+
sys.exec("systemctl", ["stop", TRIAL_UNIT]);
|
|
67
|
+
const started = sys.exec("systemd-run", [`--unit=${TRIAL_UNIT}`, "--collect", "--quiet", "-p", "Type=exec", "-p", `Group=${IPC_GROUP}`,
|
|
68
|
+
"-p", "UMask=0077", ...properties.flatMap((property) => ["-p", property]),
|
|
69
|
+
sys.nodePath, entry, "browser-host", "--socket-dir", trialDir, "--install-dir", versionDir]);
|
|
70
|
+
if (started.status !== 0)
|
|
71
|
+
return { ok: false, detail: `the trial browser host did not start: ${lastLines(started)}` };
|
|
72
|
+
try {
|
|
73
|
+
const web = asWorker(["doctor", "--profile", "public-web", "--config", layout.configFile, "--socket-dir", trialDir]);
|
|
74
|
+
return web.status === 0 ? { ok: true, detail: "test capture and isolation ok" } : { ok: false, detail: `the isolation self-test failed: ${lastLines(web)}` };
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
sys.exec("systemctl", ["stop", TRIAL_UNIT]);
|
|
78
|
+
sys.remove(trialDir);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const trialPipe = `${layout.socketDir}-trial`;
|
|
82
|
+
const host = sys.spawn(sys.nodePath, [entry, "browser-host", "--socket-dir", trialPipe, "--install-dir", versionDir]);
|
|
83
|
+
try {
|
|
84
|
+
const web = asWorker(["doctor", "--profile", "public-web", "--config", layout.configFile, "--socket-dir", trialPipe]);
|
|
85
|
+
return web.status === 0 ? { ok: true, detail: "test capture and isolation ok" } : { ok: false, detail: `the isolation self-test failed: ${lastLines(web)}` };
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
host.stop();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function lastLines(result) {
|
|
93
|
+
return (result.stdout + "\n" + result.stderr).trim().split("\n").filter(Boolean).slice(-4).join(" | ");
|
|
94
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export type ExecResult = {
|
|
2
|
+
status: number;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
};
|
|
6
|
+
export type ExecOptions = {
|
|
7
|
+
env?: Record<string, string>;
|
|
8
|
+
input?: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface Sys {
|
|
13
|
+
readonly platform: NodeJS.Platform;
|
|
14
|
+
/** Node's own absolute path (recorded in the units and tasks; plan §5). */
|
|
15
|
+
readonly nodePath: string;
|
|
16
|
+
readonly nodeVersion: string;
|
|
17
|
+
isPrivileged(): boolean;
|
|
18
|
+
exists(file: string): boolean;
|
|
19
|
+
isDirectory(file: string): boolean;
|
|
20
|
+
readFile(file: string): string;
|
|
21
|
+
readBytes(file: string): Buffer;
|
|
22
|
+
writeFile(file: string, data: string | Buffer, options?: {
|
|
23
|
+
mode?: number;
|
|
24
|
+
}): void;
|
|
25
|
+
mkdir(dir: string, options?: {
|
|
26
|
+
mode?: number;
|
|
27
|
+
}): void;
|
|
28
|
+
chmod(file: string, mode: number): void;
|
|
29
|
+
/** Linux: `user:group` by name. */
|
|
30
|
+
chown(file: string, user: string, group: string, options?: {
|
|
31
|
+
recursive?: boolean;
|
|
32
|
+
}): void;
|
|
33
|
+
/** A symbolic link on Linux, a directory junction on Windows. */
|
|
34
|
+
link(target: string, linkPath: string): void;
|
|
35
|
+
readLink(linkPath: string): string | undefined;
|
|
36
|
+
rename(from: string, to: string): void;
|
|
37
|
+
remove(file: string): void;
|
|
38
|
+
list(dir: string): string[];
|
|
39
|
+
exec(command: string, args: string[], options?: ExecOptions): ExecResult;
|
|
40
|
+
/** A long-running process (a trial browser host during an update's self-test); `stop` ends it. */
|
|
41
|
+
spawn(command: string, args: string[], options?: ExecOptions): {
|
|
42
|
+
stop(): void;
|
|
43
|
+
};
|
|
44
|
+
copyDir(from: string, to: string): void;
|
|
45
|
+
download(url: string, file: string): Promise<void>;
|
|
46
|
+
fetch: typeof fetch;
|
|
47
|
+
sha256(file: string): string;
|
|
48
|
+
/** The Subresource Integrity string of a file for npm's algorithm (`sha512-<base64>`). */
|
|
49
|
+
integrity(file: string, algorithm?: string): string;
|
|
50
|
+
tempDir(prefix: string): string;
|
|
51
|
+
now(): number;
|
|
52
|
+
sleep(ms: number): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export declare function realSys(): Sys;
|
|
55
|
+
export type FakeFile = {
|
|
56
|
+
data: Buffer;
|
|
57
|
+
mode: number;
|
|
58
|
+
owner?: string;
|
|
59
|
+
dir?: false;
|
|
60
|
+
};
|
|
61
|
+
export type FakeEntry = FakeFile | {
|
|
62
|
+
dir: true;
|
|
63
|
+
mode: number;
|
|
64
|
+
owner?: string;
|
|
65
|
+
} | {
|
|
66
|
+
link: string;
|
|
67
|
+
owner?: string;
|
|
68
|
+
};
|
|
69
|
+
export type Exec = {
|
|
70
|
+
command: string;
|
|
71
|
+
args: string[];
|
|
72
|
+
env?: Record<string, string>;
|
|
73
|
+
};
|
|
74
|
+
/** An in-memory machine. `onExec` answers commands (default: success with no output); `downloads` maps URLs to bytes. */
|
|
75
|
+
export declare function fakeSys(options?: {
|
|
76
|
+
platform?: NodeJS.Platform;
|
|
77
|
+
privileged?: boolean;
|
|
78
|
+
nodeVersion?: string;
|
|
79
|
+
onExec?: (exec: Exec) => Partial<ExecResult> | undefined;
|
|
80
|
+
downloads?: Record<string, Buffer | (() => Buffer)>;
|
|
81
|
+
fetch?: typeof fetch;
|
|
82
|
+
}): Sys & {
|
|
83
|
+
entries: Map<string, FakeEntry>;
|
|
84
|
+
execs: Exec[];
|
|
85
|
+
put(file: string, data: string | Buffer, mode?: number): void;
|
|
86
|
+
modeOf(file: string): number | undefined;
|
|
87
|
+
ownerOf(file: string): string | undefined;
|
|
88
|
+
advance(ms: number): void;
|
|
89
|
+
};
|
|
90
|
+
export type FakeSys = ReturnType<typeof fakeSys>;
|
|
91
|
+
//# sourceMappingURL=sys.d.ts.map
|
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