@profullstack/threatcrush 0.13.17 → 0.13.19
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/dist/daemon.js +21 -1
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +62 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30496,8 +30496,41 @@ async function serversCommand(options) {
|
|
|
30496
30496
|
console.log(source_default.dim(" Use the web dashboard to add servers: https://threatcrush.com/dashboard\n"));
|
|
30497
30497
|
return;
|
|
30498
30498
|
}
|
|
30499
|
+
if (action === "restart-all") {
|
|
30500
|
+
await restartAllCommand({ org });
|
|
30501
|
+
return;
|
|
30502
|
+
}
|
|
30499
30503
|
console.log(source_default.red(` Unknown action: ${action}`));
|
|
30500
|
-
console.log(source_default.dim(" Available: list, link, unlink\n"));
|
|
30504
|
+
console.log(source_default.dim(" Available: list, link, unlink, restart-all\n"));
|
|
30505
|
+
}
|
|
30506
|
+
async function restartAllCommand(opts) {
|
|
30507
|
+
let orgs;
|
|
30508
|
+
try {
|
|
30509
|
+
orgs = await fetchOrgs();
|
|
30510
|
+
} catch {
|
|
30511
|
+
console.log(source_default.red(" Not logged in. Run `threatcrush login`.\n"));
|
|
30512
|
+
process.exitCode = 1;
|
|
30513
|
+
return;
|
|
30514
|
+
}
|
|
30515
|
+
let org;
|
|
30516
|
+
try {
|
|
30517
|
+
org = await chooseOrg(orgs, opts.org, askChoice);
|
|
30518
|
+
} catch (err) {
|
|
30519
|
+
console.log(source_default.red(` \u2717 ${err.message}
|
|
30520
|
+
`));
|
|
30521
|
+
process.exitCode = 1;
|
|
30522
|
+
return;
|
|
30523
|
+
}
|
|
30524
|
+
const res = await cloudFetch(`/api/orgs/${org.id}/restart-all`, { method: "POST", body: "{}" });
|
|
30525
|
+
const data = await res.json().catch(() => ({}));
|
|
30526
|
+
if (!res.ok) {
|
|
30527
|
+
console.log(source_default.red(` \u2717 ${data.error || `Restart failed (${res.status})`}
|
|
30528
|
+
`));
|
|
30529
|
+
process.exitCode = 1;
|
|
30530
|
+
return;
|
|
30531
|
+
}
|
|
30532
|
+
console.log(source_default.green(` \u2713 Restart queued for ${data.queued ?? 0} server(s) in /${org.slug}. They reconnect within a minute.
|
|
30533
|
+
`));
|
|
30501
30534
|
}
|
|
30502
30535
|
async function fetchOrgs() {
|
|
30503
30536
|
const res = await cloudFetch("/api/orgs");
|
|
@@ -33366,6 +33399,18 @@ var RemediationConsumer = class {
|
|
|
33366
33399
|
}
|
|
33367
33400
|
this.manager.removeFromAllowlist(target);
|
|
33368
33401
|
return { status: "executed", executed_at };
|
|
33402
|
+
case "restart": {
|
|
33403
|
+
if (!this.opts.restartDaemon) return failed("restart not supported by this daemon");
|
|
33404
|
+
setTimeout(() => {
|
|
33405
|
+
try {
|
|
33406
|
+
this.opts.log("[cloud] dashboard requested a restart \u2014 restarting now");
|
|
33407
|
+
this.opts.restartDaemon?.();
|
|
33408
|
+
} catch (err) {
|
|
33409
|
+
this.opts.log(`[cloud] restart failed: ${err.message}`);
|
|
33410
|
+
}
|
|
33411
|
+
}, 3e3).unref?.();
|
|
33412
|
+
return { status: "executed", executed_at };
|
|
33413
|
+
}
|
|
33369
33414
|
default:
|
|
33370
33415
|
return failed(`unsupported action_type: ${action.action_type}`);
|
|
33371
33416
|
}
|
|
@@ -34760,6 +34805,14 @@ async function runDaemon() {
|
|
|
34760
34805
|
});
|
|
34761
34806
|
const version = readVersion2();
|
|
34762
34807
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
34808
|
+
const restartDaemon = () => {
|
|
34809
|
+
if (PATHS.mode === "system") {
|
|
34810
|
+
(0, import_node_child_process10.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
34811
|
+
} else {
|
|
34812
|
+
(0, import_node_child_process10.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
34813
|
+
setTimeout(() => process.exit(0), 500).unref();
|
|
34814
|
+
}
|
|
34815
|
+
};
|
|
34763
34816
|
const nodeProblem = daemonNodeProblem(process.versions.node);
|
|
34764
34817
|
if (nodeProblem) {
|
|
34765
34818
|
logLine(`[daemon] ${nodeProblem}`);
|
|
@@ -34844,7 +34897,7 @@ async function runDaemon() {
|
|
|
34844
34897
|
runHardening: runHardeningChecks
|
|
34845
34898
|
});
|
|
34846
34899
|
cloudSync.start();
|
|
34847
|
-
remediationConsumer = new RemediationConsumer(remediation, { log: logLine });
|
|
34900
|
+
remediationConsumer = new RemediationConsumer(remediation, { log: logLine, restartDaemon });
|
|
34848
34901
|
remediationConsumer.start();
|
|
34849
34902
|
allowlistSync = new AllowlistSync(remediation, { log: logLine });
|
|
34850
34903
|
allowlistSync.start();
|
|
@@ -35088,6 +35141,9 @@ function looksLikeNodeScript(path) {
|
|
|
35088
35141
|
function execStartCommand(binPath, nodePath, isNodeScript) {
|
|
35089
35142
|
return isNodeScript ? `${nodePath} ${binPath} daemon` : `${binPath} daemon`;
|
|
35090
35143
|
}
|
|
35144
|
+
function renderUnit(template, opts) {
|
|
35145
|
+
return template.replaceAll("{{BIN_PATH}} daemon", opts.exec).replaceAll("{{BIN_PATH}}", opts.binPath).replaceAll("{{CONFIG_DIR}}", opts.configDir);
|
|
35146
|
+
}
|
|
35091
35147
|
function nodeVersionDir(path) {
|
|
35092
35148
|
const m = path.match(
|
|
35093
35149
|
/^(.*?\/(?:installs\/node(?:js)?|\.nvm\/versions\/node|node-versions|tools\/image\/node|n\/versions\/node)\/[^/]+)\//
|
|
@@ -35197,7 +35253,7 @@ async function installServiceCommand() {
|
|
|
35197
35253
|
}
|
|
35198
35254
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
35199
35255
|
const configDir = (0, import_node_path22.join)((0, import_node_os10.homedir)(), ".threatcrush");
|
|
35200
|
-
const unit = resolveTemplate()
|
|
35256
|
+
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
35201
35257
|
(0, import_node_fs32.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
35202
35258
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
35203
35259
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
@@ -37274,6 +37330,9 @@ serversCmd.command("link").option("--org <id|slug>", "Organization to link into
|
|
|
37274
37330
|
serversCmd.command("unlink").description("Stop this machine reporting to the dashboard").action(async () => {
|
|
37275
37331
|
await serversCommand({ action: "unlink" });
|
|
37276
37332
|
});
|
|
37333
|
+
serversCmd.command("restart-all").option("--org <id|slug>", "Organization (default: current org, or your only org)").description("Queue a daemon restart for every server you administer").action(async (opts) => {
|
|
37334
|
+
await serversCommand({ action: "restart-all", org: opts.org });
|
|
37335
|
+
});
|
|
37277
37336
|
var propsCmd = program2.command("properties").alias("props").alias("targets").description("Manage scan/pentest targets (properties) in the current org").action(async () => {
|
|
37278
37337
|
await propertiesListCommand({});
|
|
37279
37338
|
});
|