@profullstack/threatcrush 0.13.18 → 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/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();
@@ -37277,6 +37330,9 @@ serversCmd.command("link").option("--org <id|slug>", "Organization to link into
37277
37330
  serversCmd.command("unlink").description("Stop this machine reporting to the dashboard").action(async () => {
37278
37331
  await serversCommand({ action: "unlink" });
37279
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
+ });
37280
37336
  var propsCmd = program2.command("properties").alias("props").alias("targets").description("Manage scan/pentest targets (properties) in the current org").action(async () => {
37281
37337
  await propertiesListCommand({});
37282
37338
  });