@profullstack/threatcrush 0.13.58 → 0.13.60

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
@@ -1655,20 +1655,20 @@ var require_parse_async = __commonJS({
1655
1655
  const index = 0;
1656
1656
  const blocksize = opts.blocksize || 40960;
1657
1657
  const parser = new TOMLParser();
1658
- return new Promise((resolve7, reject) => {
1659
- setImmediate(parseAsyncNext, index, blocksize, resolve7, reject);
1658
+ return new Promise((resolve8, reject) => {
1659
+ setImmediate(parseAsyncNext, index, blocksize, resolve8, reject);
1660
1660
  });
1661
- function parseAsyncNext(index2, blocksize2, resolve7, reject) {
1661
+ function parseAsyncNext(index2, blocksize2, resolve8, reject) {
1662
1662
  if (index2 >= str3.length) {
1663
1663
  try {
1664
- return resolve7(parser.finish());
1664
+ return resolve8(parser.finish());
1665
1665
  } catch (err) {
1666
1666
  return reject(prettyError(err, str3));
1667
1667
  }
1668
1668
  }
1669
1669
  try {
1670
1670
  parser.parse(str3.slice(index2, index2 + blocksize2));
1671
- setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve7, reject);
1671
+ setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve8, reject);
1672
1672
  } catch (err) {
1673
1673
  reject(prettyError(err, str3));
1674
1674
  }
@@ -1694,7 +1694,7 @@ var require_parse_stream = __commonJS({
1694
1694
  function parseReadable(stm) {
1695
1695
  const parser = new TOMLParser();
1696
1696
  stm.setEncoding("utf8");
1697
- return new Promise((resolve7, reject) => {
1697
+ return new Promise((resolve8, reject) => {
1698
1698
  let readable;
1699
1699
  let ended = false;
1700
1700
  let errored = false;
@@ -1702,7 +1702,7 @@ var require_parse_stream = __commonJS({
1702
1702
  ended = true;
1703
1703
  if (readable) return;
1704
1704
  try {
1705
- resolve7(parser.finish());
1705
+ resolve8(parser.finish());
1706
1706
  } catch (err) {
1707
1707
  reject(err);
1708
1708
  }
@@ -16764,8 +16764,8 @@ var init_app = __esm({
16764
16764
  this.frame();
16765
16765
  }, interval);
16766
16766
  this.timer.unref?.();
16767
- await new Promise((resolve7) => {
16768
- this.exitResolve = resolve7;
16767
+ await new Promise((resolve8) => {
16768
+ this.exitResolve = resolve8;
16769
16769
  });
16770
16770
  }
16771
16771
  targetFps() {
@@ -17238,7 +17238,7 @@ var init_ipc_client = __esm({
17238
17238
  if (!(0, import_node_fs8.existsSync)(this.socketPath)) {
17239
17239
  throw new Error(`threatcrushd socket not found at ${this.socketPath}`);
17240
17240
  }
17241
- return new Promise((resolve7, reject) => {
17241
+ return new Promise((resolve8, reject) => {
17242
17242
  const sock = (0, import_node_net.createConnection)(this.socketPath);
17243
17243
  const timer = setTimeout(() => {
17244
17244
  sock.destroy();
@@ -17251,7 +17251,7 @@ var init_ipc_client = __esm({
17251
17251
  sock.on("data", (chunk2) => this.onData(chunk2.toString()));
17252
17252
  sock.on("close", () => this.onClose());
17253
17253
  sock.on("error", () => this.onClose());
17254
- resolve7();
17254
+ resolve8();
17255
17255
  });
17256
17256
  sock.once("error", (err) => {
17257
17257
  clearTimeout(timer);
@@ -17267,14 +17267,14 @@ var init_ipc_client = __esm({
17267
17267
  if (!this.socket) throw new Error("not connected");
17268
17268
  const id = this.nextId++;
17269
17269
  const frame = params ? { id, method, params } : { id, method };
17270
- return new Promise((resolve7, reject) => {
17270
+ return new Promise((resolve8, reject) => {
17271
17271
  const timer = setTimeout(() => {
17272
17272
  this.pending.delete(id);
17273
17273
  reject(new Error(
17274
17274
  `threatcrushd did not answer "${method}" within ${REQUEST_TIMEOUT_MS / 1e3}s; if it is older than this CLI, update it`
17275
17275
  ));
17276
17276
  }, REQUEST_TIMEOUT_MS);
17277
- this.pending.set(id, { resolve: resolve7, reject, timer });
17277
+ this.pending.set(id, { resolve: resolve8, reject, timer });
17278
17278
  this.socket.write(JSON.stringify(frame) + "\n", (err) => {
17279
17279
  if (err && this.pending.delete(id)) {
17280
17280
  clearTimeout(timer);
@@ -23426,8 +23426,8 @@ var source_default = chalk;
23426
23426
  // src/index.ts
23427
23427
  var import_readline = __toESM(require("readline"));
23428
23428
  var import_node_child_process24 = require("child_process");
23429
- var import_node_fs55 = require("fs");
23430
- var import_node_path42 = require("path");
23429
+ var import_node_fs56 = require("fs");
23430
+ var import_node_path43 = require("path");
23431
23431
  var import_node_os17 = require("os");
23432
23432
 
23433
23433
  // src/commands/monitor.ts
@@ -38664,8 +38664,8 @@ function askPiped(question, mask) {
38664
38664
  if (reader.lines.length > 0) return Promise.resolve(settle2(reader.lines.shift()));
38665
38665
  if (reader.ended) return Promise.resolve(settle2(null));
38666
38666
  reader.rl.resume();
38667
- return new Promise((resolve7) => {
38668
- reader.waiting = (line2) => resolve7(settle2(line2));
38667
+ return new Promise((resolve8) => {
38668
+ reader.waiting = (line2) => resolve8(settle2(line2));
38669
38669
  });
38670
38670
  }
38671
38671
  function askTerminal(question, mask) {
@@ -38673,20 +38673,20 @@ function askTerminal(question, mask) {
38673
38673
  cb();
38674
38674
  } }) : process.stdout;
38675
38675
  const rl = import_node_readline.default.createInterface({ input: process.stdin, output, terminal: true });
38676
- return new Promise((resolve7) => {
38676
+ return new Promise((resolve8) => {
38677
38677
  let settled = false;
38678
38678
  rl.on("close", () => {
38679
38679
  if (settled) return;
38680
38680
  settled = true;
38681
38681
  process.stdout.write("\n");
38682
- resolve7(null);
38682
+ resolve8(null);
38683
38683
  });
38684
38684
  if (mask) process.stdout.write(question);
38685
38685
  rl.question(mask ? "" : question, (answer) => {
38686
38686
  settled = true;
38687
38687
  rl.close();
38688
38688
  if (mask) process.stdout.write("\n");
38689
- resolve7(answer);
38689
+ resolve8(answer);
38690
38690
  });
38691
38691
  });
38692
38692
  }
@@ -38724,7 +38724,7 @@ async function startLinkLogin(pkce, deviceName = (0, import_node_os8.hostname)()
38724
38724
  }
38725
38725
  return data;
38726
38726
  }
38727
- var sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
38727
+ var sleep = (ms) => new Promise((resolve8) => setTimeout(resolve8, ms));
38728
38728
  async function waitForApproval(request, pkce, opts = {}) {
38729
38729
  const wait = opts.sleepMs ?? sleep;
38730
38730
  const now = opts.now ?? Date.now;
@@ -41084,9 +41084,9 @@ async function fetchOrgs() {
41084
41084
  }
41085
41085
  function askChoice(question) {
41086
41086
  const rl = import_node_readline2.default.createInterface({ input: process.stdin, output: process.stdout });
41087
- return new Promise((resolve7) => rl.question(question, (answer) => {
41087
+ return new Promise((resolve8) => rl.question(question, (answer) => {
41088
41088
  rl.close();
41089
- resolve7(answer.trim());
41089
+ resolve8(answer.trim());
41090
41090
  }));
41091
41091
  }
41092
41092
  async function chooseOrg(orgs, flag, ask2) {
@@ -41232,6 +41232,7 @@ var import_node_os12 = require("os");
41232
41232
  var import_node_fs26 = require("fs");
41233
41233
  var import_node_path22 = require("path");
41234
41234
  var import_node_child_process5 = require("child_process");
41235
+ var import_node_net3 = require("net");
41235
41236
  var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
41236
41237
  var CONFIG_PATH3 = (0, import_node_path22.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
41237
41238
  function readConfig2() {
@@ -41257,7 +41258,7 @@ async function connectCommand(options) {
41257
41258
  if (server) {
41258
41259
  await sshConnect({
41259
41260
  hostname: server.hostname || server.ip_address,
41260
- port: server.port,
41261
+ port: server.port || 22,
41261
41262
  username: user || server.ssh_username || null,
41262
41263
  identity
41263
41264
  });
@@ -41357,6 +41358,20 @@ async function resolveServer(nameOrSlug, orgSlug) {
41357
41358
  return null;
41358
41359
  }
41359
41360
  }
41361
+ var SSH_USER = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/;
41362
+ var SSH_HOST = /^(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]{0,62}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,62}[A-Za-z0-9])?)*\.?$/;
41363
+ function sshTargetError(options) {
41364
+ if (!SSH_HOST.test(options.hostname) && (0, import_node_net3.isIP)(options.hostname) === 0) return `refusing unsafe hostname ${JSON.stringify(options.hostname)}`;
41365
+ if (!SSH_USER.test(options.username)) return `refusing unsafe ssh user ${JSON.stringify(options.username)}`;
41366
+ if (!Number.isInteger(options.port) || options.port < 1 || options.port > 65535) return `refusing port ${JSON.stringify(options.port)}`;
41367
+ return null;
41368
+ }
41369
+ function sshArgv(options) {
41370
+ const args = ["-p", String(options.port)];
41371
+ if (options.identity) args.push("-i", options.identity);
41372
+ args.push("--", `${options.username}@${options.hostname}`);
41373
+ return args;
41374
+ }
41360
41375
  async function sshConnect(options) {
41361
41376
  const { hostname: hostname5, port, username, identity } = options;
41362
41377
  if (!hostname5) {
@@ -41364,14 +41379,17 @@ async function sshConnect(options) {
41364
41379
  return;
41365
41380
  }
41366
41381
  const user = username || "root";
41382
+ const problem = sshTargetError({ hostname: hostname5, username: user, port });
41383
+ if (problem) {
41384
+ console.log(source_default.red(` ${problem}
41385
+ `));
41386
+ process.exitCode = 1;
41387
+ return;
41388
+ }
41367
41389
  console.log(source_default.green(` Connecting to ${user}@${hostname5}:${port}...
41368
41390
  `));
41369
41391
  console.log(source_default.dim(" (Spawning SSH session \u2014 exit with Ctrl+D or type 'exit')\n"));
41370
- const sshArgs = ["-p", String(port)];
41371
- if (identity) {
41372
- sshArgs.push("-i", identity);
41373
- }
41374
- sshArgs.push(`${user}@${hostname5}`);
41392
+ const sshArgs = sshArgv({ hostname: hostname5, username: user, port, identity });
41375
41393
  const ssh = (0, import_node_child_process5.spawn)("ssh", sshArgs, { stdio: "inherit" });
41376
41394
  ssh.on("error", (err) => {
41377
41395
  console.log(source_default.red(`
@@ -41391,20 +41409,20 @@ async function sshConnect(options) {
41391
41409
 
41392
41410
  // src/commands/daemon.ts
41393
41411
  var import_node_child_process17 = require("child_process");
41394
- var import_node_fs44 = require("fs");
41395
- var import_node_path34 = require("path");
41396
41412
  var import_node_fs45 = require("fs");
41413
+ var import_node_path35 = require("path");
41414
+ var import_node_fs46 = require("fs");
41397
41415
 
41398
41416
  // src/daemon/index.ts
41399
- var import_node_fs43 = require("fs");
41417
+ var import_node_fs44 = require("fs");
41400
41418
  var import_node_child_process16 = require("child_process");
41401
41419
  var import_node_os13 = require("os");
41402
- var import_node_path33 = require("path");
41420
+ var import_node_path34 = require("path");
41403
41421
  var import_node_util4 = require("util");
41404
41422
  init_paths();
41405
41423
 
41406
41424
  // src/daemon/ipc-server.ts
41407
- var import_node_net3 = require("net");
41425
+ var import_node_net4 = require("net");
41408
41426
  var import_node_fs27 = require("fs");
41409
41427
  init_paths();
41410
41428
  init_control_token();
@@ -41465,8 +41483,8 @@ var IpcServer = class {
41465
41483
  } catch {
41466
41484
  }
41467
41485
  }
41468
- return new Promise((resolve7, reject) => {
41469
- this.server = (0, import_node_net3.createServer)((sock) => this.handleClient(sock));
41486
+ return new Promise((resolve8, reject) => {
41487
+ this.server = (0, import_node_net4.createServer)((sock) => this.handleClient(sock));
41470
41488
  this.server.on("error", reject);
41471
41489
  this.server.listen(PATHS.socket, () => {
41472
41490
  const nodeFs = require("fs");
@@ -41484,7 +41502,7 @@ var IpcServer = class {
41484
41502
  }
41485
41503
  }
41486
41504
  }
41487
- resolve7();
41505
+ resolve8();
41488
41506
  });
41489
41507
  });
41490
41508
  }
@@ -41496,20 +41514,20 @@ var IpcServer = class {
41496
41514
  }
41497
41515
  }
41498
41516
  this.clients.clear();
41499
- return new Promise((resolve7) => {
41517
+ return new Promise((resolve8) => {
41500
41518
  if (!this.server) {
41501
41519
  try {
41502
41520
  if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
41503
41521
  } catch {
41504
41522
  }
41505
- return resolve7();
41523
+ return resolve8();
41506
41524
  }
41507
41525
  this.server.close(() => {
41508
41526
  try {
41509
41527
  if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
41510
41528
  } catch {
41511
41529
  }
41512
- resolve7();
41530
+ resolve8();
41513
41531
  });
41514
41532
  });
41515
41533
  }
@@ -42286,12 +42304,12 @@ var import_node_readline3 = require("readline");
42286
42304
  // src/core/threat-feeds/index.ts
42287
42305
  var import_node_fs31 = require("fs");
42288
42306
  var import_node_path23 = require("path");
42289
- var import_node_net5 = require("net");
42307
+ var import_node_net6 = require("net");
42290
42308
 
42291
42309
  // src/daemon/firewall/protected.ts
42292
42310
  var import_node_child_process8 = require("child_process");
42293
42311
  var import_node_fs30 = require("fs");
42294
- var import_node_net4 = require("net");
42312
+ var import_node_net5 = require("net");
42295
42313
  var DEFAULT_PROTECTED = [
42296
42314
  "127.0.0.0/8",
42297
42315
  "::1/128",
@@ -42335,7 +42353,7 @@ var SHARED_INFRASTRUCTURE = [
42335
42353
  "208.67.220.220/32"
42336
42354
  ];
42337
42355
  function ipToBytes(ip) {
42338
- const version = (0, import_node_net4.isIP)(ip);
42356
+ const version = (0, import_node_net5.isIP)(ip);
42339
42357
  if (version === 4) return v4ToBytes(ip);
42340
42358
  if (version === 6) return v6ToBytes(ip);
42341
42359
  return null;
@@ -42413,7 +42431,7 @@ function currentSshClient(env3 = process.env) {
42413
42431
  const source = env3.SSH_CLIENT || env3.SSH_CONNECTION;
42414
42432
  if (!source) return null;
42415
42433
  const ip = source.trim().split(/\s+/)[0];
42416
- return ip && (0, import_node_net4.isIP)(ip) ? ip : null;
42434
+ return ip && (0, import_node_net5.isIP)(ip) ? ip : null;
42417
42435
  }
42418
42436
  function establishedSshPeers() {
42419
42437
  const peers = /* @__PURE__ */ new Set();
@@ -42429,7 +42447,7 @@ function establishedSshPeers() {
42429
42447
  const peer = parts[4];
42430
42448
  if (!peer) continue;
42431
42449
  const ip = peer.slice(0, peer.lastIndexOf(":")).replace(/^\[|\]$/g, "");
42432
- if (ip && (0, import_node_net4.isIP)(ip)) peers.add(ip);
42450
+ if (ip && (0, import_node_net5.isIP)(ip)) peers.add(ip);
42433
42451
  }
42434
42452
  } catch {
42435
42453
  }
@@ -42438,7 +42456,7 @@ function establishedSshPeers() {
42438
42456
  function sshClientFromEnviron(environ) {
42439
42457
  for (const entry of environ.split("\0")) {
42440
42458
  const m = /^SSH_(?:CONNECTION|CLIENT)=(\S+)/.exec(entry);
42441
- if (m && (0, import_node_net4.isIP)(m[1])) return m[1];
42459
+ if (m && (0, import_node_net5.isIP)(m[1])) return m[1];
42442
42460
  }
42443
42461
  return null;
42444
42462
  }
@@ -42464,7 +42482,7 @@ function parseKeyLogins(text, skip = () => false) {
42464
42482
  const out = /* @__PURE__ */ new Map();
42465
42483
  for (const line2 of text.split("\n")) {
42466
42484
  const m = /^(\d+(?:\.\d+)?)\s.*Accepted publickey for \S+ from (\S+) port \d+ [^\s:]+(?:: \S+ (SHA256:\S+))?/.exec(line2);
42467
- if (!m || !(0, import_node_net4.isIP)(m[2])) continue;
42485
+ if (!m || !(0, import_node_net5.isIP)(m[2])) continue;
42468
42486
  if (m[3] && skip(m[3])) continue;
42469
42487
  const at = Math.round(Number(m[1]) * 1e3);
42470
42488
  if (at > (out.get(m[2]) ?? 0)) out.set(m[2], at);
@@ -42481,7 +42499,7 @@ function defaultGateways() {
42481
42499
  const out = (0, import_node_child_process8.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
42482
42500
  for (const line2 of out.split("\n")) {
42483
42501
  const match = line2.match(/\bvia\s+(\S+)/);
42484
- if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
42502
+ if (match && (0, import_node_net5.isIP)(match[1])) found.add(match[1]);
42485
42503
  }
42486
42504
  } catch {
42487
42505
  }
@@ -42594,26 +42612,26 @@ function parseIpList(text, feed) {
42594
42612
  const out = /* @__PURE__ */ new Map();
42595
42613
  for (const line2 of text.split("\n")) {
42596
42614
  const ip = line2.trim();
42597
- if (ip && !ip.startsWith("#") && (0, import_node_net5.isIP)(ip)) out.set(ip, { malware: "unknown", threat: "botnet_cc", feed });
42615
+ if (ip && !ip.startsWith("#") && (0, import_node_net6.isIP)(ip)) out.set(ip, { malware: "unknown", threat: "botnet_cc", feed });
42598
42616
  }
42599
42617
  return out;
42600
42618
  }
42601
42619
  function stripPort(value) {
42602
42620
  const v6 = /^\[([^\]]+)\]:\d+$/.exec(value);
42603
42621
  const ip = v6 ? v6[1] : value.replace(/:\d+$/, "");
42604
- return (0, import_node_net5.isIP)(ip) ? ip : null;
42622
+ return (0, import_node_net6.isIP)(ip) ? ip : null;
42605
42623
  }
42606
42624
  function normalizeDomain(value) {
42607
42625
  const d = value.trim().toLowerCase().replace(/\.$/, "");
42608
- if (!d || d === "localhost" || (0, import_node_net5.isIP)(d) || !/^[a-z0-9_.-]+\.[a-z0-9-]{2,}$/.test(d)) return null;
42626
+ if (!d || d === "localhost" || (0, import_node_net6.isIP)(d) || !/^[a-z0-9_.-]+\.[a-z0-9-]{2,}$/.test(d)) return null;
42609
42627
  return d;
42610
42628
  }
42611
42629
  function allowedDomain(domain, allow) {
42612
42630
  return allow.some((a) => domain === a || domain.endsWith(`.${a}`));
42613
42631
  }
42614
42632
  function buildFeedSet(parts, allow, sources, now = /* @__PURE__ */ new Date()) {
42615
- const neverIps = [...DEFAULT_PROTECTED, ...SHARED_RANGES, ...allow.filter((a) => (0, import_node_net5.isIP)(a.split("/")[0]))];
42616
- const allowDomains = allow.filter((a) => !(0, import_node_net5.isIP)(a.split("/")[0])).map((a) => a.toLowerCase());
42633
+ const neverIps = [...DEFAULT_PROTECTED, ...SHARED_RANGES, ...allow.filter((a) => (0, import_node_net6.isIP)(a.split("/")[0]))];
42634
+ const allowDomains = allow.filter((a) => !(0, import_node_net6.isIP)(a.split("/")[0])).map((a) => a.toLowerCase());
42617
42635
  const ips = {};
42618
42636
  const domains = {};
42619
42637
  let skipped = 0;
@@ -43511,19 +43529,187 @@ function slackChannel(webhookUrl) {
43511
43529
  }
43512
43530
 
43513
43531
  // src/daemon/workers/runs-worker.ts
43532
+ var import_promises2 = require("dns/promises");
43533
+ var import_node_fs34 = require("fs");
43534
+ var import_node_net8 = require("net");
43535
+ var import_node_path25 = require("path");
43514
43536
  init_cli_config();
43537
+
43538
+ // src/core/cloud-events.ts
43539
+ var import_node_crypto7 = require("crypto");
43540
+ var import_node_net7 = require("net");
43541
+ init_cli_config();
43542
+ function currentLink() {
43543
+ if (!hasSession()) return null;
43544
+ const cfg = readCliConfig();
43545
+ if (!cfg.server_id || !cfg.server_org_id) return null;
43546
+ return { serverId: cfg.server_id, orgId: cfg.server_org_id };
43547
+ }
43548
+ var SEVERITY_RANK6 = {
43549
+ info: 0,
43550
+ low: 1,
43551
+ medium: 2,
43552
+ high: 3,
43553
+ critical: 4
43554
+ };
43555
+ var MAX_TITLE_CHARS = 300;
43556
+ var MAX_METADATA_BYTES = 16 * 1024;
43557
+ var MAX_STRING_CHARS = 1024;
43558
+ function jsonBytes(value) {
43559
+ try {
43560
+ return Buffer.byteLength(JSON.stringify(value) ?? "");
43561
+ } catch {
43562
+ return Infinity;
43563
+ }
43564
+ }
43565
+ function trimMetadata(meta) {
43566
+ const entries = [];
43567
+ for (const [key, value] of Object.entries(meta)) {
43568
+ if (value === void 0 || typeof value === "function") continue;
43569
+ const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
43570
+ if (jsonBytes(cut) === Infinity) continue;
43571
+ entries.push([key, cut]);
43572
+ }
43573
+ let out = Object.fromEntries(entries);
43574
+ let truncated = entries.length !== Object.keys(meta).length;
43575
+ if (jsonBytes(out) > MAX_METADATA_BYTES) {
43576
+ truncated = true;
43577
+ const bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
43578
+ while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
43579
+ bySize.pop();
43580
+ }
43581
+ out = Object.fromEntries(bySize);
43582
+ }
43583
+ return truncated ? { ...out, _truncated: true } : out;
43584
+ }
43585
+ function str2(value) {
43586
+ return typeof value === "string" && value ? value : void 0;
43587
+ }
43588
+ function detectionEvent(serverId, event) {
43589
+ const { rule_id, username, user, description, ...rest } = event.details ?? {};
43590
+ const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
43591
+ return {
43592
+ type: "detection",
43593
+ server_id: serverId,
43594
+ severity: event.severity,
43595
+ title: title.slice(0, MAX_TITLE_CHARS) || event.module,
43596
+ rule_id: str2(rule_id) ?? event.module,
43597
+ description: str2(description),
43598
+ source_ip: event.source_ip && (0, import_node_net7.isIP)(event.source_ip) ? event.source_ip : void 0,
43599
+ username: str2(username) ?? str2(user),
43600
+ raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
43601
+ detected_at: event.timestamp.toISOString()
43602
+ };
43603
+ }
43604
+ function remediationEvent(serverId, event) {
43605
+ const d = event.details ?? {};
43606
+ if (d.action !== "block" && d.action !== "unblock") return null;
43607
+ if (d.origin === "cloud" || !event.source_ip) return null;
43608
+ const at = event.timestamp;
43609
+ const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
43610
+ return {
43611
+ type: "remediation",
43612
+ server_id: serverId,
43613
+ event_id: (0, import_node_crypto7.randomUUID)(),
43614
+ action_type: d.action,
43615
+ target_value: event.source_ip,
43616
+ status: d.failed === true ? "failed" : "executed",
43617
+ rule_id: str2(d.rule_id),
43618
+ reason: str2(d.reason),
43619
+ error: str2(d.error),
43620
+ dry_run: d.dry_run === true,
43621
+ executed_at: at.toISOString(),
43622
+ expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
43623
+ };
43624
+ }
43625
+ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
43626
+ return results.map((r) => ({
43627
+ type: "hardening_finding",
43628
+ server_id: serverId,
43629
+ finding_key: r.key,
43630
+ status: r.status,
43631
+ severity: r.severity,
43632
+ title: r.title.slice(0, MAX_TITLE_CHARS),
43633
+ recommendation: r.recommendation,
43634
+ observed_at: observedAt.toISOString(),
43635
+ ...r.details ? { details: trimMetadata(r.details) } : {}
43636
+ }));
43637
+ }
43638
+
43639
+ // src/daemon/workers/runs-worker.ts
43515
43640
  var POLL_INTERVAL_MS = 3e4;
43516
43641
  var SCHEDULE_INTERVAL_MS = 12e4;
43642
+ var NOT_PUBLIC = [
43643
+ ...DEFAULT_PROTECTED,
43644
+ "0.0.0.0/8",
43645
+ "100.64.0.0/10",
43646
+ "192.0.0.0/24",
43647
+ "198.18.0.0/15",
43648
+ "224.0.0.0/3",
43649
+ "::/128",
43650
+ "::ffff:0:0/96",
43651
+ "64:ff9b::/96",
43652
+ "ff00::/8"
43653
+ ];
43654
+ function isPublicTarget(ip) {
43655
+ return (0, import_node_net8.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
43656
+ }
43657
+ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises2.lookup)(h, { all: true })).map((a) => a.address)) {
43658
+ let url;
43659
+ try {
43660
+ url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
43661
+ } catch {
43662
+ return `not a URL: ${rawUrl}`;
43663
+ }
43664
+ if (url.protocol !== "http:" && url.protocol !== "https:") return `not an http(s) URL: ${rawUrl}`;
43665
+ const host = url.hostname.replace(/^\[|\]$/g, "");
43666
+ let addresses;
43667
+ try {
43668
+ addresses = (0, import_node_net8.isIP)(host) ? [host] : await resolveHost(host);
43669
+ } catch (err) {
43670
+ return `cannot resolve ${host}: ${err.message}`;
43671
+ }
43672
+ if (addresses.length === 0) return `cannot resolve ${host}`;
43673
+ const inside = addresses.find((a) => !isPublicTarget(a));
43674
+ return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
43675
+ }
43676
+ function scanTargetError(target, roots, real = import_node_fs34.realpathSync) {
43677
+ if (roots.length === 0) {
43678
+ return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
43679
+ }
43680
+ let path2;
43681
+ try {
43682
+ path2 = real((0, import_node_path25.resolve)(target));
43683
+ } catch {
43684
+ return `no such path: ${target}`;
43685
+ }
43686
+ for (const root of roots) {
43687
+ let base;
43688
+ try {
43689
+ base = real((0, import_node_path25.resolve)(root));
43690
+ } catch {
43691
+ continue;
43692
+ }
43693
+ if (path2 === base || path2.startsWith(base.endsWith(import_node_path25.sep) ? base : base + import_node_path25.sep)) return null;
43694
+ }
43695
+ return `${target} is outside [cloud] run_scan_paths`;
43696
+ }
43517
43697
  var RunsWorker = class {
43518
- constructor(bus2) {
43698
+ constructor(bus2, opts = { enabled: false, scanRoots: [] }) {
43519
43699
  this.bus = bus2;
43700
+ this.opts = opts;
43520
43701
  }
43521
43702
  bus;
43703
+ opts;
43522
43704
  pollTimer = null;
43523
43705
  scheduleTimer = null;
43524
43706
  running = false;
43525
43707
  orgIds = [];
43526
43708
  async start() {
43709
+ if (!this.opts.enabled) {
43710
+ this.opts.log?.("[runs] dashboard property runs off (set [cloud] runs = true to run them on this machine)");
43711
+ return;
43712
+ }
43527
43713
  if (!hasSession()) return;
43528
43714
  try {
43529
43715
  await this.refreshOrgs();
@@ -43545,7 +43731,7 @@ var RunsWorker = class {
43545
43731
  async scheduleTick() {
43546
43732
  if (!hasSession()) return;
43547
43733
  try {
43548
- if (this.orgIds.length === 0) await this.refreshOrgs();
43734
+ await this.refreshOrgs();
43549
43735
  for (const orgId of this.orgIds) {
43550
43736
  try {
43551
43737
  await cloudFetch(`/api/orgs/${orgId}/schedules/tick`, { method: "POST" });
@@ -43560,7 +43746,7 @@ var RunsWorker = class {
43560
43746
  if (!hasSession()) return;
43561
43747
  this.running = true;
43562
43748
  try {
43563
- if (this.orgIds.length === 0) await this.refreshOrgs();
43749
+ await this.refreshOrgs();
43564
43750
  for (const orgId of this.orgIds) {
43565
43751
  const claimed = await this.claimOne(orgId);
43566
43752
  if (!claimed) continue;
@@ -43572,11 +43758,10 @@ var RunsWorker = class {
43572
43758
  this.running = false;
43573
43759
  }
43574
43760
  }
43761
+ /** Only the org this server is linked to: never every org its user is in. */
43575
43762
  async refreshOrgs() {
43576
- const res = await cloudFetch("/api/orgs");
43577
- if (!res.ok) return;
43578
- const data = await res.json();
43579
- this.orgIds = (data.organizations || []).map((o) => o.id);
43763
+ const link = currentLink();
43764
+ this.orgIds = link ? [link.orgId] : [];
43580
43765
  }
43581
43766
  async claimOne(orgId) {
43582
43767
  try {
@@ -43603,6 +43788,18 @@ var RunsWorker = class {
43603
43788
  error: "property target missing"
43604
43789
  };
43605
43790
  }
43791
+ const refused = run.type === "scan" ? scanTargetError(target, this.opts.scanRoots) : await pentestTargetError(target);
43792
+ if (refused) {
43793
+ this.opts.log?.(`[runs] refused ${run.type} ${target}: ${refused}`);
43794
+ return {
43795
+ type: run.type,
43796
+ target,
43797
+ findings: [],
43798
+ severity_summary: { critical: 0, high: 0, medium: 0, low: 0, info: 0 },
43799
+ summary: `refused: ${refused}`,
43800
+ error: refused
43801
+ };
43802
+ }
43606
43803
  this.bus.announceModule("runs-worker", "running", `${run.type} ${run.property?.name || target}`);
43607
43804
  try {
43608
43805
  if (run.type === "scan") return await runScan(target);
@@ -43646,118 +43843,17 @@ var RunsWorker = class {
43646
43843
  // src/daemon/workers/cloud-sync.ts
43647
43844
  init_cli_config();
43648
43845
 
43649
- // src/core/cloud-events.ts
43650
- var import_node_crypto7 = require("crypto");
43651
- var import_node_net6 = require("net");
43652
- init_cli_config();
43653
- function currentLink() {
43654
- if (!hasSession()) return null;
43655
- const cfg = readCliConfig();
43656
- if (!cfg.server_id || !cfg.server_org_id) return null;
43657
- return { serverId: cfg.server_id, orgId: cfg.server_org_id };
43658
- }
43659
- var SEVERITY_RANK6 = {
43660
- info: 0,
43661
- low: 1,
43662
- medium: 2,
43663
- high: 3,
43664
- critical: 4
43665
- };
43666
- var MAX_TITLE_CHARS = 300;
43667
- var MAX_METADATA_BYTES = 16 * 1024;
43668
- var MAX_STRING_CHARS = 1024;
43669
- function jsonBytes(value) {
43670
- try {
43671
- return Buffer.byteLength(JSON.stringify(value) ?? "");
43672
- } catch {
43673
- return Infinity;
43674
- }
43675
- }
43676
- function trimMetadata(meta) {
43677
- const entries = [];
43678
- for (const [key, value] of Object.entries(meta)) {
43679
- if (value === void 0 || typeof value === "function") continue;
43680
- const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
43681
- if (jsonBytes(cut) === Infinity) continue;
43682
- entries.push([key, cut]);
43683
- }
43684
- let out = Object.fromEntries(entries);
43685
- let truncated = entries.length !== Object.keys(meta).length;
43686
- if (jsonBytes(out) > MAX_METADATA_BYTES) {
43687
- truncated = true;
43688
- const bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
43689
- while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
43690
- bySize.pop();
43691
- }
43692
- out = Object.fromEntries(bySize);
43693
- }
43694
- return truncated ? { ...out, _truncated: true } : out;
43695
- }
43696
- function str2(value) {
43697
- return typeof value === "string" && value ? value : void 0;
43698
- }
43699
- function detectionEvent(serverId, event) {
43700
- const { rule_id, username, user, description, ...rest } = event.details ?? {};
43701
- const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
43702
- return {
43703
- type: "detection",
43704
- server_id: serverId,
43705
- severity: event.severity,
43706
- title: title.slice(0, MAX_TITLE_CHARS) || event.module,
43707
- rule_id: str2(rule_id) ?? event.module,
43708
- description: str2(description),
43709
- source_ip: event.source_ip && (0, import_node_net6.isIP)(event.source_ip) ? event.source_ip : void 0,
43710
- username: str2(username) ?? str2(user),
43711
- raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
43712
- detected_at: event.timestamp.toISOString()
43713
- };
43714
- }
43715
- function remediationEvent(serverId, event) {
43716
- const d = event.details ?? {};
43717
- if (d.action !== "block" && d.action !== "unblock") return null;
43718
- if (d.origin === "cloud" || !event.source_ip) return null;
43719
- const at = event.timestamp;
43720
- const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
43721
- return {
43722
- type: "remediation",
43723
- server_id: serverId,
43724
- event_id: (0, import_node_crypto7.randomUUID)(),
43725
- action_type: d.action,
43726
- target_value: event.source_ip,
43727
- status: d.failed === true ? "failed" : "executed",
43728
- rule_id: str2(d.rule_id),
43729
- reason: str2(d.reason),
43730
- error: str2(d.error),
43731
- dry_run: d.dry_run === true,
43732
- executed_at: at.toISOString(),
43733
- expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
43734
- };
43735
- }
43736
- function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
43737
- return results.map((r) => ({
43738
- type: "hardening_finding",
43739
- server_id: serverId,
43740
- finding_key: r.key,
43741
- status: r.status,
43742
- severity: r.severity,
43743
- title: r.title.slice(0, MAX_TITLE_CHARS),
43744
- recommendation: r.recommendation,
43745
- observed_at: observedAt.toISOString(),
43746
- ...r.details ? { details: trimMetadata(r.details) } : {}
43747
- }));
43748
- }
43749
-
43750
43846
  // src/daemon/workers/cloud-spool.ts
43751
- var import_node_fs34 = require("fs");
43752
- var import_promises2 = require("fs/promises");
43753
- var import_node_path25 = require("path");
43847
+ var import_node_fs35 = require("fs");
43848
+ var import_promises3 = require("fs/promises");
43849
+ var import_node_path26 = require("path");
43754
43850
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
43755
43851
  var CloudSpool = class {
43756
43852
  constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
43757
43853
  this.path = path2;
43758
43854
  this.limits = limits;
43759
43855
  try {
43760
- (0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path2), { recursive: true });
43856
+ (0, import_node_fs35.mkdirSync)((0, import_node_path26.dirname)(path2), { recursive: true });
43761
43857
  } catch {
43762
43858
  }
43763
43859
  this.load();
@@ -43826,7 +43922,7 @@ var CloudSpool = class {
43826
43922
  load() {
43827
43923
  let raw;
43828
43924
  try {
43829
- raw = (0, import_node_fs34.readFileSync)(this.path, "utf-8");
43925
+ raw = (0, import_node_fs35.readFileSync)(this.path, "utf-8");
43830
43926
  } catch {
43831
43927
  return;
43832
43928
  }
@@ -43857,13 +43953,13 @@ var CloudSpool = class {
43857
43953
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
43858
43954
  ` : "";
43859
43955
  const tmp = `${this.path}.tmp`;
43860
- await (0, import_promises2.writeFile)(tmp, body, { mode: 384 });
43861
- await (0, import_promises2.rename)(tmp, this.path);
43956
+ await (0, import_promises3.writeFile)(tmp, body, { mode: 384 });
43957
+ await (0, import_promises3.rename)(tmp, this.path);
43862
43958
  } else if (this.pendingAppend.length > 0) {
43863
43959
  const chunk2 = `${this.pendingAppend.join("\n")}
43864
43960
  `;
43865
43961
  this.pendingAppend = [];
43866
- await (0, import_promises2.appendFile)(this.path, chunk2, { mode: 384 });
43962
+ await (0, import_promises3.appendFile)(this.path, chunk2, { mode: 384 });
43867
43963
  }
43868
43964
  }).catch(() => {
43869
43965
  this.needsRewrite = true;
@@ -44067,7 +44163,7 @@ var CloudSync = class {
44067
44163
  var import_node_crypto8 = require("crypto");
44068
44164
 
44069
44165
  // src/daemon/workers/abuse-evidence.ts
44070
- var import_node_net7 = require("net");
44166
+ var import_node_net9 = require("net");
44071
44167
  var NEVER_REPORT_RANGES = [
44072
44168
  ...DEFAULT_PROTECTED,
44073
44169
  "100.64.0.0/10",
@@ -44143,7 +44239,7 @@ function summarizeEvidence(events) {
44143
44239
  };
44144
44240
  }
44145
44241
  function isReportable(ip, evidence, config, now = Date.now()) {
44146
- if ((0, import_node_net7.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
44242
+ if ((0, import_node_net9.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
44147
44243
  if (isProtected(ip, config.neverReport)) {
44148
44244
  return { reportable: false, reason: "address is in a never-report range (private/CGNAT/reserved/allowlisted)" };
44149
44245
  }
@@ -44293,32 +44389,32 @@ function resolveConfig(section) {
44293
44389
  }
44294
44390
 
44295
44391
  // src/core/abuse-report-log.ts
44296
- var import_node_fs35 = require("fs");
44297
- var import_node_path26 = require("path");
44392
+ var import_node_fs36 = require("fs");
44393
+ var import_node_path27 = require("path");
44298
44394
  init_paths();
44299
44395
  var ABUSE_DIRNAME = "abuse-reports";
44300
44396
  var LOG_FILE2 = "reports.jsonl";
44301
44397
  function resolveAbuseDir(dir) {
44302
44398
  if (dir) return dir;
44303
44399
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
44304
- const system = (0, import_node_path26.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44305
- if ((0, import_node_fs35.existsSync)(system)) return system;
44306
- return (0, import_node_path26.join)(PATHS.stateDir, ABUSE_DIRNAME);
44400
+ const system = (0, import_node_path27.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44401
+ if ((0, import_node_fs36.existsSync)(system)) return system;
44402
+ return (0, import_node_path27.join)(PATHS.stateDir, ABUSE_DIRNAME);
44307
44403
  }
44308
44404
  function logPath(dir) {
44309
- return (0, import_node_path26.join)(resolveAbuseDir(dir), LOG_FILE2);
44405
+ return (0, import_node_path27.join)(resolveAbuseDir(dir), LOG_FILE2);
44310
44406
  }
44311
44407
  function appendReport(record, dir) {
44312
44408
  const path2 = logPath(dir);
44313
- (0, import_node_fs35.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44314
- (0, import_node_fs35.appendFileSync)(path2, `${JSON.stringify(record)}
44409
+ (0, import_node_fs36.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44410
+ (0, import_node_fs36.appendFileSync)(path2, `${JSON.stringify(record)}
44315
44411
  `, { mode: 420 });
44316
44412
  }
44317
44413
  function readReports(dir) {
44318
44414
  const path2 = logPath(dir);
44319
44415
  let raw;
44320
44416
  try {
44321
- raw = (0, import_node_fs35.readFileSync)(path2, "utf-8");
44417
+ raw = (0, import_node_fs36.readFileSync)(path2, "utf-8");
44322
44418
  } catch {
44323
44419
  return [];
44324
44420
  }
@@ -44494,20 +44590,27 @@ var AbuseReporter = class {
44494
44590
  };
44495
44591
 
44496
44592
  // src/daemon/workers/remediation-consumer.ts
44497
- var import_node_net9 = require("net");
44593
+ var import_node_net11 = require("net");
44498
44594
  init_cli_config();
44499
44595
 
44500
44596
  // src/daemon/workers/allowlist-sync.ts
44501
- var import_node_net8 = require("net");
44597
+ var import_node_net10 = require("net");
44502
44598
  init_cli_config();
44503
44599
  function isAddressOrCidr(value) {
44504
44600
  const [network, prefix, extra] = value.split("/");
44505
- const family = (0, import_node_net8.isIP)(network);
44601
+ const family = (0, import_node_net10.isIP)(network);
44506
44602
  if (family === 0 || extra !== void 0) return false;
44507
44603
  if (prefix === void 0) return true;
44508
44604
  if (!/^\d{1,3}$/.test(prefix)) return false;
44509
44605
  return Number(prefix) <= (family === 4 ? 32 : 128);
44510
44606
  }
44607
+ var CLOUD_MIN_PREFIX = { 4: 8, 6: 16 };
44608
+ function isCloudAllowEntry(value) {
44609
+ if (!isAddressOrCidr(value)) return false;
44610
+ const [network, prefix] = value.split("/");
44611
+ if (prefix === void 0) return true;
44612
+ return Number(prefix) >= CLOUD_MIN_PREFIX[(0, import_node_net10.isIP)(network)];
44613
+ }
44511
44614
  var AllowlistSync = class {
44512
44615
  constructor(manager, opts) {
44513
44616
  this.manager = manager;
@@ -44543,7 +44646,8 @@ var AllowlistSync = class {
44543
44646
  for (const entry of entries) {
44544
44647
  if (entry.type !== "ip" && entry.type !== "cidr") continue;
44545
44648
  const value = String(entry.value ?? "").trim();
44546
- if (isAddressOrCidr(value)) wanted.add(value);
44649
+ if (isCloudAllowEntry(value)) wanted.add(value);
44650
+ else if (isAddressOrCidr(value)) this.opts.log(`[cloud] org allowlist: ignoring ${value} (wider than /${CLOUD_MIN_PREFIX[(0, import_node_net10.isIP)(value.split("/")[0])]})`);
44547
44651
  }
44548
44652
  const added2 = [];
44549
44653
  const protectedNow = new Set(this.manager.getProtected());
@@ -44651,7 +44755,7 @@ var RemediationConsumer = class {
44651
44755
  try {
44652
44756
  switch (action.action_type) {
44653
44757
  case "block": {
44654
- if ((0, import_node_net9.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44758
+ if ((0, import_node_net11.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44655
44759
  let ttlSeconds = this.manager.status().max_ban_seconds;
44656
44760
  if (action.expires_at) {
44657
44761
  const until = Date.parse(action.expires_at);
@@ -44670,7 +44774,7 @@ var RemediationConsumer = class {
44670
44774
  return { status: "executed", dry_run: result.entry?.dry_run === true, executed_at };
44671
44775
  }
44672
44776
  case "unblock": {
44673
- if ((0, import_node_net9.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44777
+ if ((0, import_node_net11.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44674
44778
  const wasBanned = this.manager.getBlocklist().some((b) => b.ip === target);
44675
44779
  const result = await this.manager.unban(target, {
44676
44780
  forget: true,
@@ -44683,13 +44787,16 @@ var RemediationConsumer = class {
44683
44787
  return { status: "executed", dry_run: this.manager.status().dry_run, executed_at };
44684
44788
  }
44685
44789
  case "allowlist_add":
44686
- if (!isAddressOrCidr(target)) return failed(`not an IP address or CIDR: ${target}`);
44790
+ if (!isCloudAllowEntry(target)) return failed(`not an IP address or CIDR the dashboard may protect: ${target}`);
44687
44791
  this.manager.addToAllowlist(target);
44688
44792
  return { status: "executed", executed_at };
44689
44793
  case "allowlist_remove":
44690
44794
  if (DEFAULT_PROTECTED.includes(target)) {
44691
44795
  return failed(`${target} is a built-in protected range and cannot be removed`);
44692
44796
  }
44797
+ if (this.manager.isPinned(target)) {
44798
+ return failed(`${target} is protected by this server's own configuration and cannot be removed from the dashboard`);
44799
+ }
44693
44800
  this.manager.removeFromAllowlist(target);
44694
44801
  return { status: "executed", executed_at };
44695
44802
  case "restart": {
@@ -44704,6 +44811,13 @@ var RemediationConsumer = class {
44704
44811
  }, 3e3).unref?.();
44705
44812
  return { status: "executed", executed_at };
44706
44813
  }
44814
+ case "update": {
44815
+ if (!this.opts.updateNow) return failed("update not supported by this daemon");
44816
+ this.opts.log("[cloud] dashboard requested an update");
44817
+ const outcome = await this.opts.updateNow();
44818
+ if (outcome.startsWith("updated to") || outcome.startsWith("up to date")) return { status: "executed", executed_at };
44819
+ return failed(outcome);
44820
+ }
44707
44821
  default:
44708
44822
  return failed(`unsupported action_type: ${action.action_type}`);
44709
44823
  }
@@ -44715,8 +44829,8 @@ var RemediationConsumer = class {
44715
44829
 
44716
44830
  // src/daemon/workers/auto-update.ts
44717
44831
  var import_node_child_process10 = require("child_process");
44718
- var import_node_fs36 = require("fs");
44719
- var import_node_path27 = require("path");
44832
+ var import_node_fs37 = require("fs");
44833
+ var import_node_path28 = require("path");
44720
44834
  init_backoff();
44721
44835
  var PKG_NAME = "@profullstack/threatcrush";
44722
44836
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
@@ -44760,12 +44874,12 @@ function pickUpdate(doc, current, opts) {
44760
44874
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
44761
44875
  }
44762
44876
  function installPlan(opts) {
44763
- const expected = `${import_node_path27.sep}lib${import_node_path27.sep}node_modules${import_node_path27.sep}@profullstack${import_node_path27.sep}threatcrush`;
44877
+ const expected = `${import_node_path28.sep}lib${import_node_path28.sep}node_modules${import_node_path28.sep}@profullstack${import_node_path28.sep}threatcrush`;
44764
44878
  if (!opts.pkgRoot.endsWith(expected)) {
44765
44879
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
44766
44880
  }
44767
- const nodeBin = (0, import_node_path27.dirname)(opts.execPath);
44768
- const npm = (0, import_node_path27.join)(nodeBin, "npm");
44881
+ const nodeBin = (0, import_node_path28.dirname)(opts.execPath);
44882
+ const npm = (0, import_node_path28.join)(nodeBin, "npm");
44769
44883
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
44770
44884
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
44771
44885
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -44797,10 +44911,10 @@ function installPlan(opts) {
44797
44911
  }
44798
44912
  function ownerOf(path2, passwd = "/etc/passwd") {
44799
44913
  try {
44800
- const st = (0, import_node_fs36.statSync)(path2);
44914
+ const st = (0, import_node_fs37.statSync)(path2);
44801
44915
  let home = st.uid === 0 ? "/root" : "";
44802
44916
  try {
44803
- for (const line2 of (0, import_node_fs36.readFileSync)(passwd, "utf8").split("\n")) {
44917
+ for (const line2 of (0, import_node_fs37.readFileSync)(passwd, "utf8").split("\n")) {
44804
44918
  const f = line2.split(":");
44805
44919
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
44806
44920
  }
@@ -44822,7 +44936,7 @@ function updateSettings(section, env3 = process.env) {
44822
44936
  };
44823
44937
  }
44824
44938
  function defaultRun(argv, env3) {
44825
- return new Promise((resolve7) => {
44939
+ return new Promise((resolve8) => {
44826
44940
  const child = (0, import_node_child_process10.spawn)(argv[0], argv.slice(1), {
44827
44941
  env: { ...process.env, ...env3 },
44828
44942
  stdio: ["ignore", "pipe", "pipe"]
@@ -44833,8 +44947,8 @@ function defaultRun(argv, env3) {
44833
44947
  };
44834
44948
  child.stdout?.on("data", keep);
44835
44949
  child.stderr?.on("data", keep);
44836
- child.on("error", (err) => resolve7({ code: -1, output: err.message }));
44837
- child.on("close", (code) => resolve7({ code: code ?? -1, output }));
44950
+ child.on("error", (err) => resolve8({ code: -1, output: err.message }));
44951
+ child.on("close", (code) => resolve8({ code: code ?? -1, output }));
44838
44952
  });
44839
44953
  }
44840
44954
  var AutoUpdate = class {
@@ -44871,8 +44985,13 @@ var AutoUpdate = class {
44871
44985
  }, ms);
44872
44986
  this.timer.unref?.();
44873
44987
  }
44874
- /** One check; returns what it did, for logs and tests. */
44875
- async check() {
44988
+ /**
44989
+ * One check; returns what it did, for logs and tests.
44990
+ * `force` is the dashboard's "Update now": no min_age wait and no
44991
+ * retry-after-a-day for a version that failed before. `restartDelayMs`
44992
+ * restarts that much later, so the action's result is reported first.
44993
+ */
44994
+ async check(opts = {}) {
44876
44995
  if (this.busy) return "busy";
44877
44996
  this.busy = true;
44878
44997
  try {
@@ -44889,13 +45008,13 @@ var AutoUpdate = class {
44889
45008
  }
44890
45009
  const pick = pickUpdate(doc, this.opts.version, {
44891
45010
  allowMajor: this.opts.settings.allowMajor,
44892
- minAgeMs: this.opts.settings.minAgeMs,
45011
+ minAgeMs: opts.force ? 0 : this.opts.settings.minAgeMs,
44893
45012
  now: this.now()
44894
45013
  });
44895
45014
  if (pick.version === null) return this.note(pick.reason, !pick.reason.startsWith("up to date"));
44896
45015
  const target = pick.version;
44897
45016
  const last = this.lastAttempt();
44898
- if (last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
45017
+ if (!opts.force && last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
44899
45018
  return this.note(`${target} was tried at ${new Date(last.at).toISOString()} and did not take; retrying after a day`);
44900
45019
  }
44901
45020
  const plan = installPlan({
@@ -44905,7 +45024,7 @@ var AutoUpdate = class {
44905
45024
  uid: process.getuid?.() ?? -1,
44906
45025
  owner: ownerOf(this.opts.pkgRoot),
44907
45026
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
44908
- npmExists: import_node_fs36.existsSync
45027
+ npmExists: import_node_fs37.existsSync
44909
45028
  });
44910
45029
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
44911
45030
  this.recordAttempt(target);
@@ -44918,7 +45037,8 @@ var AutoUpdate = class {
44918
45037
  return this.note(`install of ${target} failed (exit ${code}): ${tail}`);
44919
45038
  }
44920
45039
  this.opts.log(`[update] ${target} installed; restarting onto it`);
44921
- this.opts.restartDaemon();
45040
+ if (opts.restartDelayMs) setTimeout(() => this.opts.restartDaemon(), opts.restartDelayMs).unref?.();
45041
+ else this.opts.restartDaemon();
44922
45042
  return `updated to ${target}`;
44923
45043
  } finally {
44924
45044
  this.busy = false;
@@ -44940,7 +45060,7 @@ var AutoUpdate = class {
44940
45060
  }
44941
45061
  lastAttempt() {
44942
45062
  try {
44943
- const v = JSON.parse((0, import_node_fs36.readFileSync)(this.opts.statePath, "utf8"));
45063
+ const v = JSON.parse((0, import_node_fs37.readFileSync)(this.opts.statePath, "utf8"));
44944
45064
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
44945
45065
  } catch {
44946
45066
  return null;
@@ -44948,7 +45068,7 @@ var AutoUpdate = class {
44948
45068
  }
44949
45069
  recordAttempt(version) {
44950
45070
  try {
44951
- (0, import_node_fs36.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
45071
+ (0, import_node_fs37.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44952
45072
  } catch (err) {
44953
45073
  this.opts.log(`[update] could not record attempt: ${err.message}`);
44954
45074
  }
@@ -44957,9 +45077,9 @@ var AutoUpdate = class {
44957
45077
 
44958
45078
  // src/daemon/workers/threat-feeds.ts
44959
45079
  var import_node_child_process11 = require("child_process");
44960
- var import_node_fs37 = require("fs");
44961
- var import_node_path28 = require("path");
44962
- var import_node_net10 = require("net");
45080
+ var import_node_fs38 = require("fs");
45081
+ var import_node_path29 = require("path");
45082
+ var import_node_net12 = require("net");
44963
45083
  init_backoff();
44964
45084
  var EGRESS_TABLE = "threatcrush_egress";
44965
45085
  var DEFAULT_REFRESH_MS = 36e5;
@@ -44978,8 +45098,8 @@ function threatFeedSettings(section) {
44978
45098
  };
44979
45099
  }
44980
45100
  function egressRuleset(ips) {
44981
- const v4 = ips.filter((ip) => (0, import_node_net10.isIP)(ip) === 4);
44982
- const v6 = ips.filter((ip) => (0, import_node_net10.isIP)(ip) === 6);
45101
+ const v4 = ips.filter((ip) => (0, import_node_net12.isIP)(ip) === 4);
45102
+ const v6 = ips.filter((ip) => (0, import_node_net12.isIP)(ip) === 6);
44983
45103
  const set = (name, type, items) => ` set ${name} { type ${type};${items.length ? ` elements = { ${items.join(", ")} }` : ""} }`;
44984
45104
  const chain = (name, hook) => [
44985
45105
  ` chain ${name} {`,
@@ -45004,7 +45124,7 @@ function splitAddr(addr) {
45004
45124
  const m = /^\[?(.+?)\]?:(\d+|\*)$/.exec(addr);
45005
45125
  if (!m) return null;
45006
45126
  const ip = m[1].replace(/%.*$/, "").replace(/^::ffff:/i, "");
45007
- return (0, import_node_net10.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
45127
+ return (0, import_node_net12.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
45008
45128
  }
45009
45129
  function parseSs(text) {
45010
45130
  const out = [];
@@ -45130,14 +45250,14 @@ var ThreatFeeds = class {
45130
45250
  */
45131
45251
  writeResolverFiles(set) {
45132
45252
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
45133
- const dir = this.opts.resolverDir ?? (0, import_node_path28.dirname)(this.opts.cachePath);
45253
+ const dir = this.opts.resolverDir ?? (0, import_node_path29.dirname)(this.opts.cachePath);
45134
45254
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
45135
45255
  const write = (name, content) => {
45136
- const path2 = (0, import_node_path28.join)(dir, name);
45256
+ const path2 = (0, import_node_path29.join)(dir, name);
45137
45257
  if (this.resolverWritten.get(name) === content) return false;
45138
45258
  try {
45139
- (0, import_node_fs37.writeFileSync)(`${path2}.tmp`, content);
45140
- (0, import_node_fs37.renameSync)(`${path2}.tmp`, path2);
45259
+ (0, import_node_fs38.writeFileSync)(`${path2}.tmp`, content);
45260
+ (0, import_node_fs38.renameSync)(`${path2}.tmp`, path2);
45141
45261
  this.resolverWritten.set(name, content);
45142
45262
  return true;
45143
45263
  } catch (err) {
@@ -45148,11 +45268,11 @@ var ThreatFeeds = class {
45148
45268
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
45149
45269
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
45150
45270
  const via = [];
45151
- if ((0, import_node_fs37.existsSync)(hooks.dnsmasq)) {
45271
+ if ((0, import_node_fs38.existsSync)(hooks.dnsmasq)) {
45152
45272
  via.push("dnsmasq");
45153
45273
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
45154
45274
  }
45155
- if ((0, import_node_fs37.existsSync)(hooks.unbound)) {
45275
+ if ((0, import_node_fs38.existsSync)(hooks.unbound)) {
45156
45276
  via.push("unbound");
45157
45277
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
45158
45278
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -45213,8 +45333,8 @@ var ThreatFeeds = class {
45213
45333
  };
45214
45334
 
45215
45335
  // src/daemon/workers/privilege-watch.ts
45216
- var import_node_fs38 = require("fs");
45217
- var import_node_path29 = require("path");
45336
+ var import_node_fs39 = require("fs");
45337
+ var import_node_path30 = require("path");
45218
45338
  var import_node_child_process12 = require("child_process");
45219
45339
 
45220
45340
  // src/core/privileges/index.ts
@@ -45405,31 +45525,31 @@ function countryName(code) {
45405
45525
  var fsIO = {
45406
45526
  readFile: (p) => {
45407
45527
  try {
45408
- return (0, import_node_fs38.readFileSync)(p, "utf-8");
45528
+ return (0, import_node_fs39.readFileSync)(p, "utf-8");
45409
45529
  } catch {
45410
45530
  return null;
45411
45531
  }
45412
45532
  },
45413
45533
  readDir: (p) => {
45414
45534
  try {
45415
- return (0, import_node_fs38.readdirSync)(p);
45535
+ return (0, import_node_fs39.readdirSync)(p);
45416
45536
  } catch {
45417
45537
  return null;
45418
45538
  }
45419
45539
  },
45420
- exists: (p) => (0, import_node_fs38.existsSync)(p)
45540
+ exists: (p) => (0, import_node_fs39.existsSync)(p)
45421
45541
  };
45422
45542
  function readJson(path2) {
45423
45543
  try {
45424
- return JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
45544
+ return JSON.parse((0, import_node_fs39.readFileSync)(path2, "utf-8"));
45425
45545
  } catch {
45426
45546
  return null;
45427
45547
  }
45428
45548
  }
45429
45549
  function writeJson(path2, value) {
45430
- (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
45431
- (0, import_node_fs38.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45432
- (0, import_node_fs38.renameSync)(`${path2}.tmp`, path2);
45550
+ (0, import_node_fs39.mkdirSync)((0, import_node_path30.dirname)(path2), { recursive: true });
45551
+ (0, import_node_fs39.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45552
+ (0, import_node_fs39.renameSync)(`${path2}.tmp`, path2);
45433
45553
  }
45434
45554
  function defaultRun3(cmd, args) {
45435
45555
  const res = (0, import_node_child_process12.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -45585,7 +45705,7 @@ var PrivilegeWatch = class {
45585
45705
  * raised a "new country" alert on its first run; on dev2 it did, at once.
45586
45706
  */
45587
45707
  async backfillLogins() {
45588
- if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45708
+ if ((0, import_node_fs39.existsSync)(this.opts.loginsPath)) return;
45589
45709
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
45590
45710
  const byUser = parseAcceptedLogins(out ?? "");
45591
45711
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -45598,7 +45718,7 @@ var PrivilegeWatch = class {
45598
45718
  return;
45599
45719
  }
45600
45720
  }
45601
- if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45721
+ if ((0, import_node_fs39.existsSync)(this.opts.loginsPath)) return;
45602
45722
  const at = this.now().toISOString();
45603
45723
  const history = {};
45604
45724
  for (const [user, userIps] of byUser) {
@@ -45810,8 +45930,8 @@ var RuleEngine = class {
45810
45930
  };
45811
45931
 
45812
45932
  // src/daemon/rules/loader.ts
45813
- var import_node_fs39 = require("fs");
45814
- var import_node_path30 = require("path");
45933
+ var import_node_fs40 = require("fs");
45934
+ var import_node_path31 = require("path");
45815
45935
 
45816
45936
  // src/daemon/rules/default-rules.ts
45817
45937
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -46281,11 +46401,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
46281
46401
  function loadAllRules(customDir) {
46282
46402
  const rules = [...DEFAULT_RULES];
46283
46403
  const dir = customDir || RULES_DIR;
46284
- if ((0, import_node_fs39.existsSync)(dir)) {
46285
- const files = (0, import_node_fs39.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46404
+ if ((0, import_node_fs40.existsSync)(dir)) {
46405
+ const files = (0, import_node_fs40.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46286
46406
  for (const file of files) {
46287
46407
  try {
46288
- const raw = (0, import_node_fs39.readFileSync)((0, import_node_path30.join)(dir, file), "utf-8");
46408
+ const raw = (0, import_node_fs40.readFileSync)((0, import_node_path31.join)(dir, file), "utf-8");
46289
46409
  const parsed = JSON.parse(raw);
46290
46410
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
46291
46411
  for (const rule of customRules) {
@@ -46317,23 +46437,23 @@ function loadAllRules(customDir) {
46317
46437
 
46318
46438
  // src/daemon/firewall/adapters.ts
46319
46439
  var import_node_child_process13 = require("child_process");
46320
- var import_node_fs40 = require("fs");
46321
- var import_node_path31 = require("path");
46322
- var import_node_net11 = require("net");
46440
+ var import_node_fs41 = require("fs");
46441
+ var import_node_path32 = require("path");
46442
+ var import_node_net13 = require("net");
46323
46443
  function assertValidFirewallIp(ip) {
46324
- if ((0, import_node_net11.isIP)(ip) !== 4) {
46444
+ if ((0, import_node_net13.isIP)(ip) !== 4) {
46325
46445
  throw new Error(`Invalid IPv4 address: ${ip}`);
46326
46446
  }
46327
46447
  }
46328
46448
  function assertBannableIp(ip) {
46329
- if ((0, import_node_net11.isIP)(ip) === 0) {
46449
+ if ((0, import_node_net13.isIP)(ip) === 0) {
46330
46450
  throw new Error(`Invalid IP address: ${ip}`);
46331
46451
  }
46332
46452
  }
46333
46453
  function writeIfAbsent(path2, contents) {
46334
- (0, import_node_fs40.mkdirSync)((0, import_node_path31.dirname)(path2), { recursive: true });
46454
+ (0, import_node_fs41.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
46335
46455
  try {
46336
- (0, import_node_fs40.writeFileSync)(path2, contents, { flag: "wx" });
46456
+ (0, import_node_fs41.writeFileSync)(path2, contents, { flag: "wx" });
46337
46457
  } catch (err) {
46338
46458
  if (err.code !== "EEXIST") throw err;
46339
46459
  }
@@ -46432,7 +46552,7 @@ var Fail2banAdapter = class {
46432
46552
  const status = this.client(["status", this.jail]);
46433
46553
  const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
46434
46554
  if (!line2) return [];
46435
- return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net11.isIP)(s) !== 0);
46555
+ return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
46436
46556
  } catch {
46437
46557
  return [];
46438
46558
  }
@@ -46442,10 +46562,10 @@ var Fail2banAdapter = class {
46442
46562
  function parseBannedList(output) {
46443
46563
  const found = [];
46444
46564
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
46445
- if ((0, import_node_net11.isIP)(match[1]) !== 0) found.push(match[1]);
46565
+ if ((0, import_node_net13.isIP)(match[1]) !== 0) found.push(match[1]);
46446
46566
  }
46447
46567
  if (found.length > 0) return found;
46448
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net11.isIP)(s) !== 0);
46568
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
46449
46569
  }
46450
46570
  var NftablesAdapter = class {
46451
46571
  name = "nftables";
@@ -46592,9 +46712,9 @@ function detectFirewallAdapter(backend = "auto") {
46592
46712
  }
46593
46713
 
46594
46714
  // src/daemon/firewall/remediation.ts
46595
- var import_node_fs41 = require("fs");
46715
+ var import_node_fs42 = require("fs");
46596
46716
  var import_node_child_process14 = require("child_process");
46597
- var import_node_net12 = require("net");
46717
+ var import_node_net14 = require("net");
46598
46718
  init_paths();
46599
46719
  init_backoff();
46600
46720
 
@@ -46663,19 +46783,19 @@ var defaultDiscovery = {
46663
46783
  const snapshot = takeSnapshot({
46664
46784
  readFile: (p) => {
46665
46785
  try {
46666
- return (0, import_node_fs41.readFileSync)(p, "utf-8");
46786
+ return (0, import_node_fs42.readFileSync)(p, "utf-8");
46667
46787
  } catch {
46668
46788
  return null;
46669
46789
  }
46670
46790
  },
46671
46791
  readDir: (p) => {
46672
46792
  try {
46673
- return (0, import_node_fs41.readdirSync)(p);
46793
+ return (0, import_node_fs42.readdirSync)(p);
46674
46794
  } catch {
46675
46795
  return null;
46676
46796
  }
46677
46797
  },
46678
- exists: (p) => (0, import_node_fs41.existsSync)(p)
46798
+ exists: (p) => (0, import_node_fs42.existsSync)(p)
46679
46799
  });
46680
46800
  const out = /* @__PURE__ */ new Set();
46681
46801
  for (const keys of Object.values(snapshot.keys)) {
@@ -46683,12 +46803,12 @@ var defaultDiscovery = {
46683
46803
  }
46684
46804
  return out;
46685
46805
  },
46686
- keyLoginJournal: (sinceSeconds) => new Promise((resolve7) => {
46806
+ keyLoginJournal: (sinceSeconds) => new Promise((resolve8) => {
46687
46807
  (0, import_node_child_process14.execFile)(
46688
46808
  "journalctl",
46689
46809
  ["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
46690
46810
  { maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
46691
- (_err, stdout) => resolve7(stdout ?? "")
46811
+ (_err, stdout) => resolve8(stdout ?? "")
46692
46812
  );
46693
46813
  })
46694
46814
  };
@@ -46723,6 +46843,7 @@ var RemediationManager = class {
46723
46843
  this.config.allowlist = [...this.config.allowlist];
46724
46844
  this.protectedList = [...DEFAULT_PROTECTED, ...SHARED_INFRASTRUCTURE, ...this.config.allowlist];
46725
46845
  for (const gateway of defaultGateways()) this.protectedList.push(gateway);
46846
+ this.pinned = new Set(this.protectedList);
46726
46847
  if (this.adapter.enforces === false) this.config.dry_run = true;
46727
46848
  this.loadState();
46728
46849
  this.refreshSshProtection();
@@ -46738,6 +46859,12 @@ var RemediationManager = class {
46738
46859
  blocklist = [];
46739
46860
  strikes = {};
46740
46861
  protectedList = [];
46862
+ /**
46863
+ * What was protected at start: built-ins, shared infrastructure, the
46864
+ * operator's `[remediation] allowlist`, default gateways. The dashboard may
46865
+ * add to the protected set but never take these out of it.
46866
+ */
46867
+ pinned = /* @__PURE__ */ new Set();
46741
46868
  /** Operator address → last time seen (ms), persisted. */
46742
46869
  operators = {};
46743
46870
  expiryTimer = null;
@@ -46810,7 +46937,7 @@ var RemediationManager = class {
46810
46937
  if (remediation?.action !== "block") return;
46811
46938
  }
46812
46939
  const ip = event.source_ip;
46813
- if (!ip || (0, import_node_net12.isIP)(ip) === 0) return;
46940
+ if (!ip || (0, import_node_net14.isIP)(ip) === 0) return;
46814
46941
  if (this.isAllowlisted(ip)) return;
46815
46942
  if (this.blocklist.some((b) => b.ip === ip)) return;
46816
46943
  if (this.config.spare_verified_crawlers) {
@@ -46829,7 +46956,7 @@ var RemediationManager = class {
46829
46956
  * 4th offence and so on, clamped to `max_ban_seconds`.
46830
46957
  */
46831
46958
  async ban(ip, reason, opts = {}) {
46832
- if ((0, import_node_net12.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
46959
+ if ((0, import_node_net14.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
46833
46960
  if (this.isAllowlisted(ip)) {
46834
46961
  return { ok: false, error: `${ip} is protected and can never be blocked` };
46835
46962
  }
@@ -46986,6 +47113,10 @@ var RemediationManager = class {
46986
47113
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
46987
47114
  if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);
46988
47115
  }
47116
+ /** Protected since start (built-in, shared infrastructure, operator config, gateway): not removable from the cloud. */
47117
+ isPinned(ip) {
47118
+ return this.pinned.has(ip);
47119
+ }
46989
47120
  removeFromAllowlist(ip) {
46990
47121
  if (DEFAULT_PROTECTED.includes(ip)) return;
46991
47122
  this.protectedList = this.protectedList.filter((a) => a !== ip);
@@ -47092,7 +47223,7 @@ var RemediationManager = class {
47092
47223
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
47093
47224
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
47094
47225
  for (const [ip, at] of Object.entries(saved)) {
47095
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net12.isIP)(ip)) continue;
47226
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net14.isIP)(ip)) continue;
47096
47227
  this.operators[ip] = at;
47097
47228
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
47098
47229
  }
@@ -47116,7 +47247,7 @@ var RemediationManager = class {
47116
47247
  }
47117
47248
  logLine(line2) {
47118
47249
  try {
47119
- (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47250
+ (0, import_node_fs42.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47120
47251
  `);
47121
47252
  } catch {
47122
47253
  }
@@ -47159,19 +47290,19 @@ function remediationSettings(section) {
47159
47290
  init_backoff();
47160
47291
 
47161
47292
  // src/daemon/watchdog-service.ts
47162
- var import_node_fs42 = require("fs");
47163
- var import_node_path32 = require("path");
47293
+ var import_node_fs43 = require("fs");
47294
+ var import_node_path33 = require("path");
47164
47295
  function defaultShareGid() {
47165
47296
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
47166
47297
  if (!isRoot4) return void 0;
47167
47298
  try {
47168
- return (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
47299
+ return (0, import_node_fs43.statSync)("/var/log/auth.log").gid;
47169
47300
  } catch {
47170
47301
  return void 0;
47171
47302
  }
47172
47303
  }
47173
47304
  function startWatchdog(opts) {
47174
- const dir = opts.config?.dir ?? (0, import_node_path32.join)(opts.stateDir, WATCHDOG_DIRNAME);
47305
+ const dir = opts.config?.dir ?? (0, import_node_path33.join)(opts.stateDir, WATCHDOG_DIRNAME);
47175
47306
  const base = { dir, logged: 0, answered: 0, errored: 0 };
47176
47307
  if (opts.config?.enabled === false) {
47177
47308
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -47286,7 +47417,7 @@ function versionOfNode(path2) {
47286
47417
  // src/daemon/index.ts
47287
47418
  function readVersion2() {
47288
47419
  try {
47289
- const pkg = JSON.parse((0, import_node_fs43.readFileSync)((0, import_node_path33.join)(__dirname, "..", "package.json"), "utf-8"));
47420
+ const pkg = JSON.parse((0, import_node_fs44.readFileSync)((0, import_node_path34.join)(__dirname, "..", "package.json"), "utf-8"));
47290
47421
  return pkg.version || "0.0.0";
47291
47422
  } catch {
47292
47423
  return "0.0.0";
@@ -47295,7 +47426,7 @@ function readVersion2() {
47295
47426
  async function runHardeningChecks() {
47296
47427
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47297
47428
  process.execPath,
47298
- [(0, import_node_path33.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47429
+ [(0, import_node_path34.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47299
47430
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
47300
47431
  );
47301
47432
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47309,7 +47440,7 @@ async function runHardeningChecks() {
47309
47440
  async function runPatchCheck() {
47310
47441
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47311
47442
  process.execPath,
47312
- [(0, import_node_path33.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47443
+ [(0, import_node_path34.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47313
47444
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
47314
47445
  );
47315
47446
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47317,7 +47448,7 @@ async function runPatchCheck() {
47317
47448
  }
47318
47449
  function logLine(line2) {
47319
47450
  try {
47320
- (0, import_node_fs43.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47451
+ (0, import_node_fs44.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47321
47452
  `);
47322
47453
  } catch {
47323
47454
  }
@@ -47359,7 +47490,7 @@ async function runDaemon() {
47359
47490
  } catch (err) {
47360
47491
  logLine(`[daemon] state db unavailable: ${err.message}`);
47361
47492
  }
47362
- const config = loadConfig((0, import_node_fs43.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47493
+ const config = loadConfig((0, import_node_fs44.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47363
47494
  configureAttackDetection(config.detection);
47364
47495
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
47365
47496
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -47423,7 +47554,7 @@ async function runDaemon() {
47423
47554
  const threatFeeds = new ThreatFeeds({
47424
47555
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
47425
47556
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
47426
- cachePath: (0, import_node_path33.join)(PATHS.stateDir, "threat-feeds.json"),
47557
+ cachePath: (0, import_node_path34.join)(PATHS.stateDir, "threat-feeds.json"),
47427
47558
  bus,
47428
47559
  log: logLine
47429
47560
  });
@@ -47431,14 +47562,18 @@ async function runDaemon() {
47431
47562
  const privilegeWatch = new PrivilegeWatch({
47432
47563
  settings: privilegeSettings(config.privileged),
47433
47564
  bus,
47434
- snapshotPath: (0, import_node_path33.join)(PATHS.stateDir, "privileges.json"),
47435
- loginsPath: (0, import_node_path33.join)(PATHS.stateDir, "login-countries.json"),
47436
- cursorPath: (0, import_node_path33.join)(PATHS.stateDir, "sudo-cursor.json"),
47565
+ snapshotPath: (0, import_node_path34.join)(PATHS.stateDir, "privileges.json"),
47566
+ loginsPath: (0, import_node_path34.join)(PATHS.stateDir, "login-countries.json"),
47567
+ cursorPath: (0, import_node_path34.join)(PATHS.stateDir, "sudo-cursor.json"),
47437
47568
  log: logLine
47438
47569
  });
47439
47570
  privilegeWatch.start();
47440
47571
  new AlertDispatcher(bus, config);
47441
- const runsWorker = new RunsWorker(bus);
47572
+ const runsWorker = new RunsWorker(bus, {
47573
+ enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
47574
+ scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
47575
+ log: logLine
47576
+ });
47442
47577
  try {
47443
47578
  await runsWorker.start();
47444
47579
  } catch (err) {
@@ -47446,6 +47581,7 @@ async function runDaemon() {
47446
47581
  }
47447
47582
  let cloudSync = null;
47448
47583
  let remediationConsumer = null;
47584
+ let autoUpdateRef = null;
47449
47585
  let allowlistSync = null;
47450
47586
  if (config.cloud?.enabled === false) {
47451
47587
  logLine("[cloud] disabled by [cloud] enabled = false");
@@ -47456,13 +47592,18 @@ async function runDaemon() {
47456
47592
  version,
47457
47593
  hostname: (0, import_node_os13.hostname)(),
47458
47594
  minSeverity,
47459
- spoolPath: (0, import_node_path33.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47595
+ spoolPath: (0, import_node_path34.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47460
47596
  log: logLine,
47461
47597
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
47462
47598
  runHardening: runHardeningChecks
47463
47599
  });
47464
47600
  cloudSync.start();
47465
- remediationConsumer = new RemediationConsumer(remediation, { log: logLine, restartDaemon });
47601
+ remediationConsumer = new RemediationConsumer(remediation, {
47602
+ log: logLine,
47603
+ restartDaemon,
47604
+ // autoUpdate is created below; the action only runs once polling starts.
47605
+ updateNow: () => autoUpdateRef ? autoUpdateRef.check({ force: true, restartDelayMs: 3e3 }) : Promise.resolve("updater not started")
47606
+ });
47466
47607
  remediationConsumer.start();
47467
47608
  allowlistSync = new AllowlistSync(remediation, { log: logLine });
47468
47609
  allowlistSync.start();
@@ -47472,11 +47613,11 @@ async function runDaemon() {
47472
47613
  const abuseReporter = new AbuseReporter({ bus, section: config.abuse_reporter, log: logLine });
47473
47614
  abuseReporter.start();
47474
47615
  const watchdog = startWatchdog({ bus, config: config.watchdog, stateDir: PATHS.stateDir, log: logLine });
47475
- const autoUpdate = new AutoUpdate({
47616
+ const autoUpdate = autoUpdateRef = new AutoUpdate({
47476
47617
  version,
47477
47618
  settings: updateSettings(config.update),
47478
- pkgRoot: (0, import_node_path33.join)(__dirname, ".."),
47479
- statePath: (0, import_node_path33.join)(PATHS.stateDir, "auto-update.json"),
47619
+ pkgRoot: (0, import_node_path34.join)(__dirname, ".."),
47620
+ statePath: (0, import_node_path34.join)(PATHS.stateDir, "auto-update.json"),
47480
47621
  bus,
47481
47622
  log: logLine,
47482
47623
  restartDaemon
@@ -47566,7 +47707,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
47566
47707
  function isRoot2() {
47567
47708
  return typeof process.getuid === "function" && process.getuid() === 0;
47568
47709
  }
47569
- var DAEMON_ENTRY = (0, import_node_path34.join)(__dirname, "daemon.js");
47710
+ var DAEMON_ENTRY = (0, import_node_path35.join)(__dirname, "daemon.js");
47570
47711
  async function daemonForeground() {
47571
47712
  await runDaemon();
47572
47713
  }
@@ -47587,7 +47728,7 @@ async function daemonStart() {
47587
47728
  return;
47588
47729
  }
47589
47730
  ensureRuntimeDirs();
47590
- if (!(0, import_node_fs44.existsSync)(DAEMON_ENTRY)) {
47731
+ if (!(0, import_node_fs45.existsSync)(DAEMON_ENTRY)) {
47591
47732
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
47592
47733
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
47593
47734
  return;
@@ -47595,8 +47736,8 @@ async function daemonStart() {
47595
47736
  let out;
47596
47737
  let err;
47597
47738
  try {
47598
- out = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47599
- err = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47739
+ out = (0, import_node_fs46.openSync)(PATHS.logFile, "a");
47740
+ err = (0, import_node_fs46.openSync)(PATHS.logFile, "a");
47600
47741
  } catch (e) {
47601
47742
  const code = e.code;
47602
47743
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -47684,12 +47825,12 @@ async function waitForExit(pid, timeoutMs) {
47684
47825
  }
47685
47826
  async function releaseStaleSocket() {
47686
47827
  const deadline = Date.now() + 2e3;
47687
- while ((0, import_node_fs44.existsSync)(PATHS.socket) && Date.now() < deadline) {
47828
+ while ((0, import_node_fs45.existsSync)(PATHS.socket) && Date.now() < deadline) {
47688
47829
  await new Promise((r) => setTimeout(r, 50));
47689
47830
  }
47690
- if ((0, import_node_fs44.existsSync)(PATHS.socket)) {
47831
+ if ((0, import_node_fs45.existsSync)(PATHS.socket)) {
47691
47832
  try {
47692
- (0, import_node_fs44.unlinkSync)(PATHS.socket);
47833
+ (0, import_node_fs45.unlinkSync)(PATHS.socket);
47693
47834
  } catch {
47694
47835
  }
47695
47836
  }
@@ -47697,26 +47838,26 @@ async function releaseStaleSocket() {
47697
47838
 
47698
47839
  // src/commands/service.ts
47699
47840
  var import_node_child_process18 = require("child_process");
47700
- var import_node_fs46 = require("fs");
47701
- var import_node_path35 = require("path");
47841
+ var import_node_fs47 = require("fs");
47842
+ var import_node_path36 = require("path");
47702
47843
  var import_node_os14 = require("os");
47703
47844
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
47704
47845
  var DAEMON_UNIT_NAME = "threatcrushd.service";
47705
47846
  function resolveTemplate() {
47706
- const templatePath = (0, import_node_path35.join)(__dirname, "systemd", "threatcrushd.service");
47707
- if (!(0, import_node_fs46.existsSync)(templatePath)) {
47847
+ const templatePath = (0, import_node_path36.join)(__dirname, "systemd", "threatcrushd.service");
47848
+ if (!(0, import_node_fs47.existsSync)(templatePath)) {
47708
47849
  throw new Error(`systemd unit template not found at ${templatePath}`);
47709
47850
  }
47710
- return (0, import_node_fs46.readFileSync)(templatePath, "utf-8");
47851
+ return (0, import_node_fs47.readFileSync)(templatePath, "utf-8");
47711
47852
  }
47712
47853
  function stableBinPath(binPath) {
47713
47854
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
47714
47855
  if (stable === binPath) return binPath;
47715
- return (0, import_node_fs46.existsSync)(stable) ? stable : binPath;
47856
+ return (0, import_node_fs47.existsSync)(stable) ? stable : binPath;
47716
47857
  }
47717
47858
  function resolveBinPath() {
47718
47859
  const arg = process.argv[1];
47719
- if (arg && (0, import_node_fs46.existsSync)(arg)) return stableBinPath(arg);
47860
+ if (arg && (0, import_node_fs47.existsSync)(arg)) return stableBinPath(arg);
47720
47861
  try {
47721
47862
  return (0, import_node_child_process18.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
47722
47863
  } catch {
@@ -47726,11 +47867,11 @@ function resolveBinPath() {
47726
47867
  function stableNodePath(execPath) {
47727
47868
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
47728
47869
  if (stable === execPath) return execPath;
47729
- return (0, import_node_fs46.existsSync)(stable) ? stable : execPath;
47870
+ return (0, import_node_fs47.existsSync)(stable) ? stable : execPath;
47730
47871
  }
47731
47872
  function looksLikeNodeScript(path2) {
47732
47873
  try {
47733
- const head = (0, import_node_fs46.readFileSync)(path2, "utf-8").slice(0, 120);
47874
+ const head = (0, import_node_fs47.readFileSync)(path2, "utf-8").slice(0, 120);
47734
47875
  return /^#!.*\bnode\b/.test(head);
47735
47876
  } catch {
47736
47877
  return false;
@@ -47770,7 +47911,7 @@ function callerHome() {
47770
47911
  try {
47771
47912
  const line2 = (0, import_node_child_process18.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
47772
47913
  const home = line2.split(":")[5];
47773
- return home && (0, import_node_fs46.existsSync)(home) ? home : null;
47914
+ return home && (0, import_node_fs47.existsSync)(home) ? home : null;
47774
47915
  } catch {
47775
47916
  return null;
47776
47917
  }
@@ -47778,13 +47919,13 @@ function callerHome() {
47778
47919
  function stopUserModeDaemon() {
47779
47920
  const home = callerHome();
47780
47921
  if (!home) return;
47781
- const runDir = (0, import_node_path35.join)(home, ".threatcrush", "run");
47782
- const pidFile = (0, import_node_path35.join)(runDir, "threatcrushd.pid");
47783
- const socket = (0, import_node_path35.join)(runDir, "threatcrushd.sock");
47784
- if (!(0, import_node_fs46.existsSync)(pidFile) && !(0, import_node_fs46.existsSync)(socket)) return;
47922
+ const runDir = (0, import_node_path36.join)(home, ".threatcrush", "run");
47923
+ const pidFile = (0, import_node_path36.join)(runDir, "threatcrushd.pid");
47924
+ const socket = (0, import_node_path36.join)(runDir, "threatcrushd.sock");
47925
+ if (!(0, import_node_fs47.existsSync)(pidFile) && !(0, import_node_fs47.existsSync)(socket)) return;
47785
47926
  let pid = null;
47786
47927
  try {
47787
- pid = Number.parseInt((0, import_node_fs46.readFileSync)(pidFile, "utf-8").trim(), 10);
47928
+ pid = Number.parseInt((0, import_node_fs47.readFileSync)(pidFile, "utf-8").trim(), 10);
47788
47929
  } catch {
47789
47930
  pid = null;
47790
47931
  }
@@ -47797,7 +47938,7 @@ function stopUserModeDaemon() {
47797
47938
  }
47798
47939
  for (const path2 of [socket, pidFile]) {
47799
47940
  try {
47800
- if ((0, import_node_fs46.existsSync)(path2)) (0, import_node_fs46.rmSync)(path2);
47941
+ if ((0, import_node_fs47.existsSync)(path2)) (0, import_node_fs47.rmSync)(path2);
47801
47942
  } catch {
47802
47943
  }
47803
47944
  }
@@ -47815,7 +47956,7 @@ async function installServiceCommand() {
47815
47956
  }
47816
47957
  const noSystemd = systemdUnavailableReason({
47817
47958
  hasSystemctl: (0, import_node_child_process18.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
47818
- booted: (0, import_node_fs46.existsSync)("/run/systemd/system")
47959
+ booted: (0, import_node_fs47.existsSync)("/run/systemd/system")
47819
47960
  });
47820
47961
  if (noSystemd) {
47821
47962
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -47837,7 +47978,7 @@ async function installServiceCommand() {
47837
47978
  const isNodeScript = looksLikeNodeScript(binPath);
47838
47979
  let nodePath = stableNodePath(process.execPath);
47839
47980
  if (isNodeScript && nodeVersionDir(binPath)) {
47840
- binPath = (0, import_node_fs46.realpathSync)(binPath);
47981
+ binPath = (0, import_node_fs47.realpathSync)(binPath);
47841
47982
  nodePath = process.execPath;
47842
47983
  }
47843
47984
  if (isNodeScript) {
@@ -47850,9 +47991,9 @@ async function installServiceCommand() {
47850
47991
  }
47851
47992
  }
47852
47993
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
47853
- const configDir = (0, import_node_path35.join)((0, import_node_os14.homedir)(), ".threatcrush");
47994
+ const configDir = (0, import_node_path36.join)((0, import_node_os14.homedir)(), ".threatcrush");
47854
47995
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
47855
- (0, import_node_fs46.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47996
+ (0, import_node_fs47.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47856
47997
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
47857
47998
  console.log(source_default.dim(` ExecStart=${exec}`));
47858
47999
  const nodeDir = nodeVersionDir(nodePath);
@@ -47905,9 +48046,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
47905
48046
  ].join("\n");
47906
48047
  }
47907
48048
  function installLogrotate() {
47908
- if (!(0, import_node_fs46.existsSync)((0, import_node_path35.dirname)(LOGROTATE_PATH))) return;
48049
+ if (!(0, import_node_fs47.existsSync)((0, import_node_path36.dirname)(LOGROTATE_PATH))) return;
47909
48050
  try {
47910
- (0, import_node_fs46.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
48051
+ (0, import_node_fs47.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47911
48052
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
47912
48053
  } catch (err) {
47913
48054
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -47929,20 +48070,20 @@ function ensureSystemDirs(configDir) {
47929
48070
  ];
47930
48071
  let admGid2 = null;
47931
48072
  try {
47932
- admGid2 = (0, import_node_fs46.statSync)("/var/log/auth.log").gid;
48073
+ admGid2 = (0, import_node_fs47.statSync)("/var/log/auth.log").gid;
47933
48074
  } catch {
47934
48075
  }
47935
48076
  for (const { path: path2, groupWritable, sticky } of dirs) {
47936
48077
  try {
47937
- (0, import_node_fs46.mkdirSync)(path2, { recursive: true });
48078
+ (0, import_node_fs47.mkdirSync)(path2, { recursive: true });
47938
48079
  } catch {
47939
48080
  }
47940
48081
  try {
47941
48082
  if (groupWritable && admGid2 !== null) {
47942
- (0, import_node_fs46.chmodSync)(path2, sticky ? 1533 : 509);
48083
+ (0, import_node_fs47.chmodSync)(path2, sticky ? 1533 : 509);
47943
48084
  (0, import_node_child_process18.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
47944
48085
  } else {
47945
- (0, import_node_fs46.chmodSync)(path2, 493);
48086
+ (0, import_node_fs47.chmodSync)(path2, 493);
47946
48087
  }
47947
48088
  } catch {
47948
48089
  }
@@ -47970,7 +48111,7 @@ async function uninstallServiceCommand() {
47970
48111
  } catch {
47971
48112
  }
47972
48113
  try {
47973
- if ((0, import_node_fs46.existsSync)(UNIT_PATH)) {
48114
+ if ((0, import_node_fs47.existsSync)(UNIT_PATH)) {
47974
48115
  (0, import_node_child_process18.execSync)(`rm -f ${UNIT_PATH}`);
47975
48116
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
47976
48117
  }
@@ -47984,7 +48125,7 @@ async function uninstallServiceCommand() {
47984
48125
  }
47985
48126
 
47986
48127
  // src/commands/save.ts
47987
- var import_node_fs47 = require("fs");
48128
+ var import_node_fs48 = require("fs");
47988
48129
  var import_toml5 = __toESM(require_toml());
47989
48130
  init_cli_config();
47990
48131
  init_paths();
@@ -48023,9 +48164,9 @@ async function saveCommand(opts = {}) {
48023
48164
  }
48024
48165
  const path2 = opts.config ?? PATHS.configFile;
48025
48166
  let config = {};
48026
- if ((0, import_node_fs47.existsSync)(path2)) {
48167
+ if ((0, import_node_fs48.existsSync)(path2)) {
48027
48168
  try {
48028
- config = import_toml5.default.parse((0, import_node_fs47.readFileSync)(path2, "utf-8"));
48169
+ config = import_toml5.default.parse((0, import_node_fs48.readFileSync)(path2, "utf-8"));
48029
48170
  } catch (err) {
48030
48171
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
48031
48172
  `));
@@ -48138,17 +48279,17 @@ function welcomeCommand() {
48138
48279
  }
48139
48280
 
48140
48281
  // src/commands/properties.ts
48141
- var import_node_fs48 = require("fs");
48142
- var import_node_path36 = require("path");
48282
+ var import_node_fs49 = require("fs");
48283
+ var import_node_path37 = require("path");
48143
48284
  var import_node_readline4 = __toESM(require("readline"));
48144
48285
  init_cli_config();
48145
48286
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
48146
48287
  var KINDS = ["url", "api", "domain", "ip", "repo"];
48147
48288
  function prompt(question) {
48148
48289
  const rl = import_node_readline4.default.createInterface({ input: process.stdin, output: process.stdout });
48149
- return new Promise((resolve7) => rl.question(question, (answer) => {
48290
+ return new Promise((resolve8) => rl.question(question, (answer) => {
48150
48291
  rl.close();
48151
- resolve7(answer.trim());
48292
+ resolve8(answer.trim());
48152
48293
  }));
48153
48294
  }
48154
48295
  async function requireAuth() {
@@ -48469,8 +48610,8 @@ async function propertiesRunsCommand(opts) {
48469
48610
  }
48470
48611
  }
48471
48612
  function parseImportFile(path2) {
48472
- const ext = (0, import_node_path36.extname)(path2).toLowerCase();
48473
- const raw = (0, import_node_fs48.readFileSync)(path2, "utf-8");
48613
+ const ext = (0, import_node_path37.extname)(path2).toLowerCase();
48614
+ const raw = (0, import_node_fs49.readFileSync)(path2, "utf-8");
48474
48615
  if (ext === ".json") {
48475
48616
  const parsed = JSON.parse(raw);
48476
48617
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -48665,7 +48806,7 @@ async function rulesCommand(opts) {
48665
48806
  }
48666
48807
 
48667
48808
  // src/commands/harden.ts
48668
- var import_node_fs49 = require("fs");
48809
+ var import_node_fs50 = require("fs");
48669
48810
  var import_node_child_process19 = require("child_process");
48670
48811
  init_cli_config();
48671
48812
  function tryExec(cmd) {
@@ -48677,7 +48818,7 @@ function tryExec(cmd) {
48677
48818
  }
48678
48819
  function tryRead(path2) {
48679
48820
  try {
48680
- return (0, import_node_fs49.readFileSync)(path2, "utf-8");
48821
+ return (0, import_node_fs50.readFileSync)(path2, "utf-8");
48681
48822
  } catch {
48682
48823
  return null;
48683
48824
  }
@@ -48781,8 +48922,8 @@ function checkSshWeakConfig() {
48781
48922
  };
48782
48923
  }
48783
48924
  function checkAutoUpdates() {
48784
- const unattended = (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48785
- const dnfAuto = (0, import_node_fs49.existsSync)("/etc/dnf/automatic.conf");
48925
+ const unattended = (0, import_node_fs50.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs50.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48926
+ const dnfAuto = (0, import_node_fs50.existsSync)("/etc/dnf/automatic.conf");
48786
48927
  if (unattended || dnfAuto) {
48787
48928
  return {
48788
48929
  key: "auto-updates",
@@ -48908,7 +49049,7 @@ function checkFail2ban() {
48908
49049
  explanation: "fail2ban is installed and running."
48909
49050
  };
48910
49051
  }
48911
- if ((0, import_node_fs49.existsSync)("/etc/fail2ban/fail2ban.conf")) {
49052
+ if ((0, import_node_fs50.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48912
49053
  return {
48913
49054
  key: checkKey,
48914
49055
  status: "warn",
@@ -49094,8 +49235,8 @@ async function hardenCommand(opts) {
49094
49235
  }
49095
49236
 
49096
49237
  // src/core/patches/index.ts
49097
- var import_node_fs50 = require("fs");
49098
- var import_node_path37 = require("path");
49238
+ var import_node_fs51 = require("fs");
49239
+ var import_node_path38 = require("path");
49099
49240
  var import_node_child_process20 = require("child_process");
49100
49241
  var import_node_util5 = require("util");
49101
49242
 
@@ -49255,9 +49396,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
49255
49396
  function newestReleaseMtime(dir) {
49256
49397
  try {
49257
49398
  let newest = 0;
49258
- for (const name of (0, import_node_fs50.readdirSync)(dir)) {
49399
+ for (const name of (0, import_node_fs51.readdirSync)(dir)) {
49259
49400
  if (!/Release$/.test(name)) continue;
49260
- newest = Math.max(newest, (0, import_node_fs50.statSync)((0, import_node_path37.join)(dir, name)).mtimeMs);
49401
+ newest = Math.max(newest, (0, import_node_fs51.statSync)((0, import_node_path38.join)(dir, name)).mtimeMs);
49261
49402
  }
49262
49403
  return newest > 0 ? new Date(newest) : null;
49263
49404
  } catch {
@@ -49274,7 +49415,7 @@ async function checkPatches(opts = {}) {
49274
49415
  let osText = opts.osRelease;
49275
49416
  if (osText === void 0) {
49276
49417
  try {
49277
- osText = (0, import_node_fs50.readFileSync)("/etc/os-release", "utf-8");
49418
+ osText = (0, import_node_fs51.readFileSync)("/etc/os-release", "utf-8");
49278
49419
  } catch {
49279
49420
  osText = "";
49280
49421
  }
@@ -49500,25 +49641,25 @@ async function patchesCommand(opts) {
49500
49641
  }
49501
49642
 
49502
49643
  // src/commands/feeds.ts
49503
- var import_node_net13 = require("net");
49504
- var import_node_path39 = require("path");
49644
+ var import_node_net15 = require("net");
49645
+ var import_node_path40 = require("path");
49505
49646
  init_paths();
49506
49647
 
49507
49648
  // src/commands/feeds-resolver.ts
49508
49649
  var import_node_child_process21 = require("child_process");
49509
- var import_node_fs51 = require("fs");
49510
- var import_node_path38 = require("path");
49650
+ var import_node_fs52 = require("fs");
49651
+ var import_node_path39 = require("path");
49511
49652
  var realIO = {
49512
- exists: (p) => (0, import_node_fs51.existsSync)(p),
49653
+ exists: (p) => (0, import_node_fs52.existsSync)(p),
49513
49654
  read: (p) => {
49514
49655
  try {
49515
- return (0, import_node_fs51.readFileSync)(p, "utf-8");
49656
+ return (0, import_node_fs52.readFileSync)(p, "utf-8");
49516
49657
  } catch {
49517
49658
  return null;
49518
49659
  }
49519
49660
  },
49520
- write: (p, c) => (0, import_node_fs51.writeFileSync)(p, c),
49521
- remove: (p) => (0, import_node_fs51.rmSync)(p, { force: true }),
49661
+ write: (p, c) => (0, import_node_fs52.writeFileSync)(p, c),
49662
+ remove: (p) => (0, import_node_fs52.rmSync)(p, { force: true }),
49522
49663
  run: (cmd, args) => {
49523
49664
  const r = (0, import_node_child_process21.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
49524
49665
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -49528,17 +49669,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
49528
49669
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
49529
49670
  function hookContent(resolver, stateDir) {
49530
49671
  const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
49531
- return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts)}
49532
- ` : `${head}include: "${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)}"
49672
+ return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.hosts)}
49673
+ ` : `${head}include: "${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound)}"
49533
49674
  `;
49534
49675
  }
49535
49676
  function apparmorRule(stateDir) {
49536
- return ` ${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49677
+ return ` ${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49537
49678
  }
49538
49679
  function detectResolvers(io = realIO) {
49539
49680
  const found = [];
49540
- if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49541
- if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49681
+ if (io.exists((0, import_node_path39.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49682
+ if (io.exists((0, import_node_path39.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49542
49683
  return found;
49543
49684
  }
49544
49685
  function check(resolver, io) {
@@ -49551,7 +49692,7 @@ function restartIfActive(resolver, io) {
49551
49692
  }
49552
49693
  function installHook(resolver, stateDir, io = realIO) {
49553
49694
  const hook = RESOLVER_HOOKS[resolver];
49554
- const file = (0, import_node_path38.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49695
+ const file = (0, import_node_path39.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49555
49696
  if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
49556
49697
  io.write(hook, hookContent(resolver, stateDir));
49557
49698
  if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
@@ -49612,8 +49753,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
49612
49753
  }
49613
49754
  return failed ? 1 : 0;
49614
49755
  }
49615
- const hosts = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts));
49616
- const unbound = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound));
49756
+ const hosts = io.read((0, import_node_path39.join)(stateDir, RESOLVER_FILES.hosts));
49757
+ const unbound = io.read((0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound));
49617
49758
  console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
49618
49759
  for (const r of ["dnsmasq", "unbound"]) {
49619
49760
  console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
@@ -49625,11 +49766,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
49625
49766
  // src/commands/feeds.ts
49626
49767
  async function loadSet() {
49627
49768
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
49628
- const path2 = (0, import_node_path39.join)(dir, "threat-feeds.json");
49769
+ const path2 = (0, import_node_path40.join)(dir, "threat-feeds.json");
49629
49770
  const set = readFeedCache(path2);
49630
49771
  if (set) return { set, from: path2 };
49631
49772
  }
49632
- const settings = threatFeedSettings(loadConfig((0, import_node_path39.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49773
+ const settings = threatFeedSettings(loadConfig((0, import_node_path40.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49633
49774
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
49634
49775
  }
49635
49776
  async function feedsCommand(action, value, opts) {
@@ -49644,8 +49785,8 @@ async function feedsCommand(action, value, opts) {
49644
49785
  process.exitCode = 2;
49645
49786
  return;
49646
49787
  }
49647
- const ipHit = (0, import_node_net13.isIP)(value) ? matchIp(value, set) : null;
49648
- const domainHit = (0, import_node_net13.isIP)(value) ? null : matchDomain(value, set);
49788
+ const ipHit = (0, import_node_net15.isIP)(value) ? matchIp(value, set) : null;
49789
+ const domainHit = (0, import_node_net15.isIP)(value) ? null : matchDomain(value, set);
49649
49790
  const listed = ipHit ?? domainHit?.indicator ?? null;
49650
49791
  if (opts.json) {
49651
49792
  console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
@@ -49674,13 +49815,13 @@ async function feedsCommand(action, value, opts) {
49674
49815
 
49675
49816
  // src/commands/reputation.ts
49676
49817
  var import_node_os15 = require("os");
49677
- var import_node_fs52 = require("fs");
49678
- var import_node_path40 = require("path");
49818
+ var import_node_fs53 = require("fs");
49819
+ var import_node_path41 = require("path");
49679
49820
  var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49680
- var CONFIG_PATH4 = (0, import_node_path40.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49821
+ var CONFIG_PATH4 = (0, import_node_path41.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49681
49822
  function readConfig3() {
49682
49823
  try {
49683
- return JSON.parse((0, import_node_fs52.readFileSync)(CONFIG_PATH4, "utf-8"));
49824
+ return JSON.parse((0, import_node_fs53.readFileSync)(CONFIG_PATH4, "utf-8"));
49684
49825
  } catch {
49685
49826
  return {};
49686
49827
  }
@@ -49868,7 +50009,7 @@ async function reputationSubscribeCommand(opts) {
49868
50009
  }
49869
50010
 
49870
50011
  // src/commands/privileged.ts
49871
- var import_node_fs53 = require("fs");
50012
+ var import_node_fs54 = require("fs");
49872
50013
  init_paths();
49873
50014
  var SEV2 = {
49874
50015
  critical: source_default.red.bold,
@@ -49881,19 +50022,19 @@ async function privilegedCommand(opts) {
49881
50022
  const snapshot = takeSnapshot({
49882
50023
  readFile: (p) => {
49883
50024
  try {
49884
- return (0, import_node_fs53.readFileSync)(p, "utf-8");
50025
+ return (0, import_node_fs54.readFileSync)(p, "utf-8");
49885
50026
  } catch {
49886
50027
  return null;
49887
50028
  }
49888
50029
  },
49889
50030
  readDir: (p) => {
49890
50031
  try {
49891
- return (0, import_node_fs53.readdirSync)(p);
50032
+ return (0, import_node_fs54.readdirSync)(p);
49892
50033
  } catch {
49893
50034
  return null;
49894
50035
  }
49895
50036
  },
49896
- exists: (p) => (0, import_node_fs53.existsSync)(p)
50037
+ exists: (p) => (0, import_node_fs54.existsSync)(p)
49897
50038
  });
49898
50039
  let events = [];
49899
50040
  let ledgerNote = "";
@@ -50075,7 +50216,7 @@ async function allowlistCommand(opts) {
50075
50216
  }
50076
50217
 
50077
50218
  // src/commands/abuse.ts
50078
- var import_node_fs54 = require("fs");
50219
+ var import_node_fs55 = require("fs");
50079
50220
  init_paths();
50080
50221
  function rows(records) {
50081
50222
  if (records.length === 0) {
@@ -50135,7 +50276,7 @@ function abuseRetractCommand(id, opts = {}) {
50135
50276
  );
50136
50277
  }
50137
50278
  function abuseStatusCommand(opts = {}) {
50138
- const config = loadConfig((0, import_node_fs54.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
50279
+ const config = loadConfig((0, import_node_fs55.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
50139
50280
  const cfg = resolveConfig(config.abuse_reporter);
50140
50281
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
50141
50282
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -50305,7 +50446,7 @@ function installUserAgent(target = globalThis) {
50305
50446
  // src/core/cloud-upload.ts
50306
50447
  var import_node_child_process23 = require("child_process");
50307
50448
  var import_node_os16 = require("os");
50308
- var import_node_path41 = require("path");
50449
+ var import_node_path42 = require("path");
50309
50450
  init_cli_config();
50310
50451
  function uploadDisabled(upload, env3 = process.env) {
50311
50452
  if (upload === false) return true;
@@ -50324,8 +50465,8 @@ function cleanUrl(raw) {
50324
50465
  return raw.split(/[?#]/)[0];
50325
50466
  }
50326
50467
  }
50327
- function repoTarget(path2, run = (args) => (0, import_node_child_process23.execFileSync)("git", args, { cwd: (0, import_node_path41.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
50328
- const abs = (0, import_node_path41.resolve)(path2);
50468
+ function repoTarget(path2, run = (args) => (0, import_node_child_process23.execFileSync)("git", args, { cwd: (0, import_node_path42.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
50469
+ const abs = (0, import_node_path42.resolve)(path2);
50329
50470
  try {
50330
50471
  const root = run(["rev-parse", "--show-toplevel"]);
50331
50472
  const sub = abs === root ? "." : abs.slice(root.length + 1);
@@ -50697,7 +50838,7 @@ ${source_default.dim(" C R U S H")}
50697
50838
  var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50698
50839
  var PKG_NAME2 = "@profullstack/threatcrush";
50699
50840
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
50700
- var INSTALL_CONFIG_PATH = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush", "install.json");
50841
+ var INSTALL_CONFIG_PATH = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush", "install.json");
50701
50842
  function detectPackageManager() {
50702
50843
  try {
50703
50844
  const npmGlobal = (0, import_node_child_process24.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -50723,7 +50864,7 @@ function detectPackageManager() {
50723
50864
  }
50724
50865
  function readInstallConfig() {
50725
50866
  try {
50726
- return JSON.parse((0, import_node_fs55.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50867
+ return JSON.parse((0, import_node_fs56.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50727
50868
  } catch {
50728
50869
  return {};
50729
50870
  }
@@ -51133,7 +51274,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
51133
51274
  program2.command("logs").description("Tail daemon logs").action(async () => {
51134
51275
  console.log(LOGO2);
51135
51276
  const logPath2 = PATHS.logFile;
51136
- if (!(0, import_node_fs55.existsSync)(logPath2)) {
51277
+ if (!(0, import_node_fs56.existsSync)(logPath2)) {
51137
51278
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
51138
51279
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
51139
51280
  return;
@@ -51201,10 +51342,10 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
51201
51342
  program2.command("remove").description("Uninstall ThreatCrush and the installed bundle").alias("uninstall").action(async () => {
51202
51343
  console.log(LOGO2);
51203
51344
  const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51204
- const confirm = await new Promise((resolve7) => {
51345
+ const confirm = await new Promise((resolve8) => {
51205
51346
  rl.question(source_default.yellow(" Are you sure you want to uninstall ThreatCrush? (y/N): "), (answer) => {
51206
51347
  rl.close();
51207
- resolve7(answer.trim().toLowerCase());
51348
+ resolve8(answer.trim().toLowerCase());
51208
51349
  });
51209
51350
  });
51210
51351
  if (confirm !== "y" && confirm !== "yes") {
@@ -51306,19 +51447,19 @@ storeCmd.command("search <query>").description("Search for modules in the store"
51306
51447
  });
51307
51448
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
51308
51449
  console.log(LOGO2);
51309
- const configPath = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
51450
+ const configPath = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
51310
51451
  let email = "";
51311
51452
  try {
51312
- const config = JSON.parse((0, import_node_fs55.readFileSync)(configPath, "utf-8"));
51453
+ const config = JSON.parse((0, import_node_fs56.readFileSync)(configPath, "utf-8"));
51313
51454
  email = config.email || "";
51314
51455
  } catch {
51315
51456
  }
51316
51457
  if (!email) {
51317
51458
  const rl2 = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51318
- email = await new Promise((resolve7) => {
51459
+ email = await new Promise((resolve8) => {
51319
51460
  rl2.question(source_default.green(" Enter your email: "), (answer) => {
51320
51461
  rl2.close();
51321
- resolve7(answer.trim());
51462
+ resolve8(answer.trim());
51322
51463
  });
51323
51464
  });
51324
51465
  if (!email || !email.includes("@")) {
@@ -51326,9 +51467,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
51326
51467
  return;
51327
51468
  }
51328
51469
  try {
51329
- const dir = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush");
51330
- if (!(0, import_node_fs55.existsSync)(dir)) (0, import_node_fs55.mkdirSync)(dir, { recursive: true });
51331
- (0, import_node_fs55.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
51470
+ const dir = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush");
51471
+ if (!(0, import_node_fs56.existsSync)(dir)) (0, import_node_fs56.mkdirSync)(dir, { recursive: true });
51472
+ (0, import_node_fs56.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
51332
51473
  console.log(source_default.dim(` Saved email to ${configPath}`));
51333
51474
  } catch {
51334
51475
  }
@@ -51372,10 +51513,10 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
51372
51513
  }
51373
51514
  console.log();
51374
51515
  const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51375
- const confirm = await new Promise((resolve7) => {
51516
+ const confirm = await new Promise((resolve8) => {
51376
51517
  rl.question(source_default.yellow(" Publish this module? (y/N): "), (answer) => {
51377
51518
  rl.close();
51378
- resolve7(answer.trim().toLowerCase());
51519
+ resolve8(answer.trim().toLowerCase());
51379
51520
  });
51380
51521
  });
51381
51522
  if (confirm !== "y" && confirm !== "yes") {