@profullstack/threatcrush 0.13.51 → 0.13.52

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
@@ -23426,9 +23426,9 @@ var source_default = chalk;
23426
23426
  // src/index.ts
23427
23427
  var import_readline = __toESM(require("readline"));
23428
23428
  var import_node_child_process23 = require("child_process");
23429
- var import_node_fs53 = require("fs");
23430
- var import_node_path39 = require("path");
23431
- var import_node_os15 = require("os");
23429
+ var import_node_fs54 = require("fs");
23430
+ var import_node_path40 = require("path");
23431
+ var import_node_os16 = require("os");
23432
23432
 
23433
23433
  // src/commands/monitor.ts
23434
23434
  var import_node_fs11 = require("fs");
@@ -40760,9 +40760,85 @@ async function useOrganization(slug) {
40760
40760
  }
40761
40761
  }
40762
40762
 
40763
+ // src/commands/credits.ts
40764
+ var import_node_os10 = require("os");
40765
+ var import_node_fs24 = require("fs");
40766
+ var import_node_path20 = require("path");
40767
+ var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
40768
+ var CONFIG_PATH2 = (0, import_node_path20.join)((0, import_node_os10.homedir)(), ".threatcrush", "config.json");
40769
+ function sessionToken() {
40770
+ try {
40771
+ const cfg = JSON.parse((0, import_node_fs24.readFileSync)(CONFIG_PATH2, "utf-8"));
40772
+ return cfg.token ?? null;
40773
+ } catch {
40774
+ return null;
40775
+ }
40776
+ }
40777
+ async function api(path2, init = {}, f = fetch) {
40778
+ const token = sessionToken();
40779
+ if (!token) {
40780
+ console.error(source_default.red(" Not signed in. Run `threatcrush login` first."));
40781
+ process.exitCode = 1;
40782
+ return { ok: false, status: 401, body: {} };
40783
+ }
40784
+ const res = await f(`${API_URL4}${path2}`, {
40785
+ ...init,
40786
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, ...init.headers ?? {} }
40787
+ });
40788
+ const body = await res.json().catch(() => ({}));
40789
+ if (res.status === 401) console.error(source_default.red(" Session expired. Run `threatcrush login` again."));
40790
+ return { ok: res.ok, status: res.status, body };
40791
+ }
40792
+ function fail(body, fallback) {
40793
+ console.error(source_default.red(` ${String(body.error ?? fallback)}`));
40794
+ process.exitCode = 1;
40795
+ }
40796
+ async function redeemCommand(code, f = fetch) {
40797
+ const r = await api("/api/credits/redeem", { method: "POST", body: JSON.stringify({ code }) }, f);
40798
+ if (r.status === 401 && !r.body.error) return;
40799
+ if (!r.ok) return fail(r.body, "Could not redeem the code.");
40800
+ console.log(source_default.green(` ${String(r.body.message)}`));
40801
+ if (typeof r.body.balance_usd === "number") console.log(` Credit balance: $${r.body.balance_usd.toFixed(2)}`);
40802
+ }
40803
+ async function invitesCommand(action = "list", arg, f = fetch) {
40804
+ if (action === "create") {
40805
+ const r2 = await api("/api/credits/invites", { method: "POST", body: JSON.stringify({ note: arg ?? "" }) }, f);
40806
+ if (!r2.ok) return fail(r2.body, "Could not create an invite.");
40807
+ console.log(source_default.green(" Invite created. Send this link (it is shown once):"));
40808
+ console.log(` ${source_default.bold(String(r2.body.url))}`);
40809
+ return;
40810
+ }
40811
+ if (action === "accept") {
40812
+ if (!arg) return fail({}, "Usage: threatcrush invites accept <code>");
40813
+ const r2 = await api("/api/credits/invites/accept", { method: "POST", body: JSON.stringify({ code: arg }) }, f);
40814
+ if (!r2.ok) return fail(r2.body, "Could not accept the invite.");
40815
+ console.log(source_default.green(` ${String(r2.body.message)}`));
40816
+ return;
40817
+ }
40818
+ if (action === "revoke") {
40819
+ if (!arg) return fail({}, "Usage: threatcrush invites revoke <id>");
40820
+ const r2 = await api(`/api/credits/invites/${encodeURIComponent(arg)}`, { method: "DELETE" }, f);
40821
+ if (!r2.ok) return fail(r2.body, "Could not withdraw the invite.");
40822
+ console.log(source_default.green(" Invite withdrawn."));
40823
+ return;
40824
+ }
40825
+ const r = await api("/api/credits/invites", {}, f);
40826
+ if (!r.ok) return fail(r.body, "Could not load invites.");
40827
+ const q = r.body.quota;
40828
+ console.log(` Invites left: ${source_default.bold(`${q.left} / ${q.total}`)} (bonus: ${String(r.body.bonusCredits)} credits each)`);
40829
+ if (!r.body.canInvite) {
40830
+ console.log(source_default.yellow(r.body.unlocksAt ? ` Invites unlock on ${String(r.body.unlocksAt).slice(0, 10)}.` : ` Cannot invite: ${String(r.body.blockedReason)}`));
40831
+ }
40832
+ for (const i of r.body.invites ?? []) {
40833
+ const who = i.usedByEmail ? ` ${i.usedByEmail}` : "";
40834
+ const bonus = i.status === "used" ? ` (credits ${i.bonus})` : "";
40835
+ console.log(` ${source_default.dim(i.id)} ${new Date(i.createdAt).toISOString().slice(0, 10)} ${i.status}${who}${bonus} ${i.note}`);
40836
+ }
40837
+ }
40838
+
40763
40839
  // src/commands/servers.ts
40764
40840
  var import_node_readline2 = __toESM(require("readline"));
40765
- var import_node_os10 = require("os");
40841
+ var import_node_os11 = require("os");
40766
40842
  init_cli_config();
40767
40843
  function connectionStatus(server, now = Date.now()) {
40768
40844
  const seen = server.last_seen ? Date.parse(server.last_seen) : NaN;
@@ -40861,7 +40937,7 @@ async function chooseOrg(orgs, flag, ask2) {
40861
40937
  async function linkServer(opts = {}, ask2 = askChoice) {
40862
40938
  if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
40863
40939
  const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
40864
- const host = opts.hostname ?? (0, import_node_os10.hostname)();
40940
+ const host = opts.hostname ?? (0, import_node_os11.hostname)();
40865
40941
  const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
40866
40942
  if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
40867
40943
  const { servers = [] } = await listRes.json();
@@ -40978,15 +41054,15 @@ function timeAgo(dateStr) {
40978
41054
  }
40979
41055
 
40980
41056
  // src/commands/connect.ts
40981
- var import_node_os11 = require("os");
40982
- var import_node_fs24 = require("fs");
40983
- var import_node_path20 = require("path");
41057
+ var import_node_os12 = require("os");
41058
+ var import_node_fs25 = require("fs");
41059
+ var import_node_path21 = require("path");
40984
41060
  var import_node_child_process5 = require("child_process");
40985
- var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
40986
- var CONFIG_PATH2 = (0, import_node_path20.join)((0, import_node_os11.homedir)(), ".threatcrush", "config.json");
41061
+ var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
41062
+ var CONFIG_PATH3 = (0, import_node_path21.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
40987
41063
  function readConfig2() {
40988
41064
  try {
40989
- return JSON.parse((0, import_node_fs24.readFileSync)(CONFIG_PATH2, "utf-8"));
41065
+ return JSON.parse((0, import_node_fs25.readFileSync)(CONFIG_PATH3, "utf-8"));
40990
41066
  } catch {
40991
41067
  return {};
40992
41068
  }
@@ -41028,7 +41104,7 @@ async function connectCommand(options) {
41028
41104
  async function interactiveConnect(orgSlug) {
41029
41105
  const config = readConfig2();
41030
41106
  try {
41031
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41107
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
41032
41108
  if (!orgsRes.ok) {
41033
41109
  console.log(source_default.red(" Failed to fetch organizations. Are you logged in?\n"));
41034
41110
  return;
@@ -41050,7 +41126,7 @@ async function interactiveConnect(orgSlug) {
41050
41126
  if (!orgId) {
41051
41127
  orgId = orgs[0].id;
41052
41128
  }
41053
- const serversRes = await fetch(`${API_URL4}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41129
+ const serversRes = await fetch(`${API_URL5}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41054
41130
  if (!serversRes.ok) {
41055
41131
  console.log(source_default.red(" Failed to fetch servers.\n"));
41056
41132
  return;
@@ -41083,7 +41159,7 @@ async function resolveServer(nameOrSlug, orgSlug) {
41083
41159
  try {
41084
41160
  let orgId = config.current_org_id;
41085
41161
  if (orgSlug) {
41086
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41162
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
41087
41163
  if (!orgsRes.ok) return null;
41088
41164
  const orgsData = await orgsRes.json();
41089
41165
  const org = (orgsData.organizations || []).find((o) => o.slug === orgSlug);
@@ -41091,13 +41167,13 @@ async function resolveServer(nameOrSlug, orgSlug) {
41091
41167
  orgId = org.id;
41092
41168
  }
41093
41169
  if (!orgId) {
41094
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41170
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
41095
41171
  if (!orgsRes.ok) return null;
41096
41172
  const orgsData = await orgsRes.json();
41097
41173
  orgId = (orgsData.organizations || [])[0]?.id;
41098
41174
  if (!orgId) return null;
41099
41175
  }
41100
- const serversRes = await fetch(`${API_URL4}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41176
+ const serversRes = await fetch(`${API_URL5}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41101
41177
  if (!serversRes.ok) return null;
41102
41178
  const serversData = await serversRes.json();
41103
41179
  const servers = serversData.servers || [];
@@ -41141,21 +41217,21 @@ async function sshConnect(options) {
41141
41217
 
41142
41218
  // src/commands/daemon.ts
41143
41219
  var import_node_child_process17 = require("child_process");
41144
- var import_node_fs42 = require("fs");
41145
- var import_node_path32 = require("path");
41146
41220
  var import_node_fs43 = require("fs");
41221
+ var import_node_path33 = require("path");
41222
+ var import_node_fs44 = require("fs");
41147
41223
 
41148
41224
  // src/daemon/index.ts
41149
- var import_node_fs41 = require("fs");
41225
+ var import_node_fs42 = require("fs");
41150
41226
  var import_node_child_process16 = require("child_process");
41151
- var import_node_os12 = require("os");
41152
- var import_node_path31 = require("path");
41227
+ var import_node_os13 = require("os");
41228
+ var import_node_path32 = require("path");
41153
41229
  var import_node_util4 = require("util");
41154
41230
  init_paths();
41155
41231
 
41156
41232
  // src/daemon/ipc-server.ts
41157
41233
  var import_node_net3 = require("net");
41158
- var import_node_fs25 = require("fs");
41234
+ var import_node_fs26 = require("fs");
41159
41235
  init_paths();
41160
41236
  init_control_token();
41161
41237
 
@@ -41209,9 +41285,9 @@ var IpcServer = class {
41209
41285
  controlToken = "";
41210
41286
  async start() {
41211
41287
  this.controlToken = issueControlToken();
41212
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) {
41288
+ if ((0, import_node_fs26.existsSync)(PATHS.socket)) {
41213
41289
  try {
41214
- (0, import_node_fs25.unlinkSync)(PATHS.socket);
41290
+ (0, import_node_fs26.unlinkSync)(PATHS.socket);
41215
41291
  } catch {
41216
41292
  }
41217
41293
  }
@@ -41249,14 +41325,14 @@ var IpcServer = class {
41249
41325
  return new Promise((resolve6) => {
41250
41326
  if (!this.server) {
41251
41327
  try {
41252
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) (0, import_node_fs25.unlinkSync)(PATHS.socket);
41328
+ if ((0, import_node_fs26.existsSync)(PATHS.socket)) (0, import_node_fs26.unlinkSync)(PATHS.socket);
41253
41329
  } catch {
41254
41330
  }
41255
41331
  return resolve6();
41256
41332
  }
41257
41333
  this.server.close(() => {
41258
41334
  try {
41259
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) (0, import_node_fs25.unlinkSync)(PATHS.socket);
41335
+ if ((0, import_node_fs26.existsSync)(PATHS.socket)) (0, import_node_fs26.unlinkSync)(PATHS.socket);
41260
41336
  } catch {
41261
41337
  }
41262
41338
  resolve6();
@@ -41436,7 +41512,7 @@ var IpcServer = class {
41436
41512
  }
41437
41513
  }
41438
41514
  };
41439
- function admGid(readGroup = () => (0, import_node_fs25.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs25.statSync)("/var/log/auth.log")) {
41515
+ function admGid(readGroup = () => (0, import_node_fs26.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs26.statSync)("/var/log/auth.log")) {
41440
41516
  try {
41441
41517
  for (const line2 of readGroup().split("\n")) {
41442
41518
  const [name, , gid] = line2.split(":");
@@ -41452,14 +41528,14 @@ function admGid(readGroup = () => (0, import_node_fs25.readFileSync)("/etc/group
41452
41528
  }
41453
41529
 
41454
41530
  // src/daemon/module-host.ts
41455
- var import_node_fs31 = require("fs");
41456
- var import_node_path22 = require("path");
41531
+ var import_node_fs32 = require("fs");
41532
+ var import_node_path23 = require("path");
41457
41533
  var import_node_url = require("url");
41458
41534
  var import_toml4 = __toESM(require_toml());
41459
41535
  init_paths();
41460
41536
 
41461
41537
  // src/daemon/watchers/log-watcher.ts
41462
- var import_node_fs26 = require("fs");
41538
+ var import_node_fs27 = require("fs");
41463
41539
  var DEFAULT_SOURCES = [
41464
41540
  { path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
41465
41541
  { path: "/var/log/secure", module: "ssh-guard", category: "auth" },
@@ -41479,9 +41555,9 @@ var LogWatcher = class {
41479
41555
  start() {
41480
41556
  const started = [];
41481
41557
  for (const src of this.sources) {
41482
- if (!(0, import_node_fs26.existsSync)(src.path)) continue;
41558
+ if (!(0, import_node_fs27.existsSync)(src.path)) continue;
41483
41559
  try {
41484
- (0, import_node_fs26.accessSync)(src.path, import_node_fs26.constants.R_OK);
41560
+ (0, import_node_fs27.accessSync)(src.path, import_node_fs27.constants.R_OK);
41485
41561
  } catch {
41486
41562
  continue;
41487
41563
  }
@@ -41778,7 +41854,7 @@ function realtimeToDate(rt) {
41778
41854
 
41779
41855
  // src/modules/network-monitor/index.ts
41780
41856
  var import_node_child_process7 = require("child_process");
41781
- var import_node_fs27 = require("fs");
41857
+ var import_node_fs28 = require("fs");
41782
41858
  var NetworkMonitor = class {
41783
41859
  constructor(bus2) {
41784
41860
  this.bus = bus2;
@@ -41842,7 +41918,7 @@ var NetworkMonitor = class {
41842
41918
  hasConntrackOrSs() {
41843
41919
  const ss = (0, import_node_child_process7.spawnSync)("ss", ["--version"], { stdio: "pipe" });
41844
41920
  if (ss.status === 0) return true;
41845
- return (0, import_node_fs27.existsSync)("/proc/net/tcp");
41921
+ return (0, import_node_fs28.existsSync)("/proc/net/tcp");
41846
41922
  }
41847
41923
  /**
41848
41924
  * The TCP ports this host actually listens on.
@@ -42029,18 +42105,18 @@ var NetworkMonitor = class {
42029
42105
  };
42030
42106
 
42031
42107
  // src/modules/dns-monitor/index.ts
42032
- var import_node_fs30 = require("fs");
42108
+ var import_node_fs31 = require("fs");
42033
42109
  var import_node_child_process9 = require("child_process");
42034
42110
  var import_node_readline3 = require("readline");
42035
42111
 
42036
42112
  // src/core/threat-feeds/index.ts
42037
- var import_node_fs29 = require("fs");
42038
- var import_node_path21 = require("path");
42113
+ var import_node_fs30 = require("fs");
42114
+ var import_node_path22 = require("path");
42039
42115
  var import_node_net5 = require("net");
42040
42116
 
42041
42117
  // src/daemon/firewall/protected.ts
42042
42118
  var import_node_child_process8 = require("child_process");
42043
- var import_node_fs28 = require("fs");
42119
+ var import_node_fs29 = require("fs");
42044
42120
  var import_node_net4 = require("net");
42045
42121
  var DEFAULT_PROTECTED = [
42046
42122
  "127.0.0.0/8",
@@ -42196,14 +42272,14 @@ function moshClients(procDir = "/proc") {
42196
42272
  const found = /* @__PURE__ */ new Set();
42197
42273
  let pids = [];
42198
42274
  try {
42199
- pids = (0, import_node_fs28.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
42275
+ pids = (0, import_node_fs29.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
42200
42276
  } catch {
42201
42277
  return [];
42202
42278
  }
42203
42279
  for (const pid of pids) {
42204
42280
  try {
42205
- if ((0, import_node_fs28.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
42206
- const ip = sshClientFromEnviron((0, import_node_fs28.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
42281
+ if ((0, import_node_fs29.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
42282
+ const ip = sshClientFromEnviron((0, import_node_fs29.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
42207
42283
  if (ip) found.add(ip);
42208
42284
  } catch {
42209
42285
  }
@@ -42409,17 +42485,17 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
42409
42485
  }
42410
42486
  function readFeedCache(path2) {
42411
42487
  try {
42412
- const set = JSON.parse((0, import_node_fs29.readFileSync)(path2, "utf-8"));
42488
+ const set = JSON.parse((0, import_node_fs30.readFileSync)(path2, "utf-8"));
42413
42489
  return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
42414
42490
  } catch {
42415
42491
  return null;
42416
42492
  }
42417
42493
  }
42418
42494
  function writeFeedCache(path2, set) {
42419
- (0, import_node_fs29.mkdirSync)((0, import_node_path21.dirname)(path2), { recursive: true });
42495
+ (0, import_node_fs30.mkdirSync)((0, import_node_path22.dirname)(path2), { recursive: true });
42420
42496
  const tmp = `${path2}.tmp`;
42421
- (0, import_node_fs29.writeFileSync)(tmp, JSON.stringify(set));
42422
- (0, import_node_fs29.renameSync)(tmp, path2);
42497
+ (0, import_node_fs30.writeFileSync)(tmp, JSON.stringify(set));
42498
+ (0, import_node_fs30.renameSync)(tmp, path2);
42423
42499
  }
42424
42500
  var RESOLVER_FILES = {
42425
42501
  hosts: "blocked-domains.hosts",
@@ -42544,9 +42620,9 @@ var DnsMonitor = class {
42544
42620
  }
42545
42621
  start() {
42546
42622
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
42547
- if (!(0, import_node_fs30.existsSync)(p)) return false;
42623
+ if (!(0, import_node_fs31.existsSync)(p)) return false;
42548
42624
  try {
42549
- (0, import_node_fs30.accessSync)(p, import_node_fs30.constants.R_OK);
42625
+ (0, import_node_fs31.accessSync)(p, import_node_fs31.constants.R_OK);
42550
42626
  return true;
42551
42627
  } catch {
42552
42628
  return false;
@@ -42903,15 +42979,15 @@ var ModuleHost = class {
42903
42979
  }
42904
42980
  }
42905
42981
  async discoverAndStartInstalled() {
42906
- if (!(0, import_node_fs31.existsSync)(PATHS.moduleDir)) return;
42982
+ if (!(0, import_node_fs32.existsSync)(PATHS.moduleDir)) return;
42907
42983
  const configs = loadModuleConfigs(PATHS.confD);
42908
- const entries = (0, import_node_fs31.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
42984
+ const entries = (0, import_node_fs32.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
42909
42985
  for (const entry of entries) {
42910
42986
  if (!entry.isDirectory()) continue;
42911
- const manifestPath = (0, import_node_path22.join)(PATHS.moduleDir, entry.name, "mod.toml");
42912
- if (!(0, import_node_fs31.existsSync)(manifestPath)) continue;
42987
+ const manifestPath = (0, import_node_path23.join)(PATHS.moduleDir, entry.name, "mod.toml");
42988
+ if (!(0, import_node_fs32.existsSync)(manifestPath)) continue;
42913
42989
  try {
42914
- const manifest = import_toml4.default.parse((0, import_node_fs31.readFileSync)(manifestPath, "utf-8"));
42990
+ const manifest = import_toml4.default.parse((0, import_node_fs32.readFileSync)(manifestPath, "utf-8"));
42915
42991
  const name = manifest.module?.name || entry.name;
42916
42992
  const defaults = manifest.module?.config?.defaults || {};
42917
42993
  const config = {
@@ -42925,7 +43001,7 @@ var ModuleHost = class {
42925
43001
  source: "installed",
42926
43002
  status: config.enabled === false ? "disabled" : "loaded",
42927
43003
  events: 0,
42928
- path: (0, import_node_path22.join)(PATHS.moduleDir, entry.name),
43004
+ path: (0, import_node_path23.join)(PATHS.moduleDir, entry.name),
42929
43005
  config
42930
43006
  };
42931
43007
  this.modules.set(name, hosted);
@@ -42940,7 +43016,7 @@ var ModuleHost = class {
42940
43016
  status: "error",
42941
43017
  events: 0,
42942
43018
  detail: `manifest load failed: ${String(err.message || err)}`,
42943
- path: (0, import_node_path22.join)(PATHS.moduleDir, entry.name)
43019
+ path: (0, import_node_path23.join)(PATHS.moduleDir, entry.name)
42944
43020
  });
42945
43021
  }
42946
43022
  }
@@ -42979,17 +43055,17 @@ var ModuleHost = class {
42979
43055
  }
42980
43056
  }
42981
43057
  installedEntrypoint(modulePath) {
42982
- const packageJson = (0, import_node_path22.join)(modulePath, "package.json");
43058
+ const packageJson = (0, import_node_path23.join)(modulePath, "package.json");
42983
43059
  const candidates = [];
42984
- if ((0, import_node_fs31.existsSync)(packageJson)) {
43060
+ if ((0, import_node_fs32.existsSync)(packageJson)) {
42985
43061
  try {
42986
- const pkg = JSON.parse((0, import_node_fs31.readFileSync)(packageJson, "utf-8"));
42987
- if (pkg.main) candidates.push((0, import_node_path22.join)(modulePath, pkg.main));
43062
+ const pkg = JSON.parse((0, import_node_fs32.readFileSync)(packageJson, "utf-8"));
43063
+ if (pkg.main) candidates.push((0, import_node_path23.join)(modulePath, pkg.main));
42988
43064
  } catch {
42989
43065
  }
42990
43066
  }
42991
- candidates.push((0, import_node_path22.join)(modulePath, "dist", "index.js"), (0, import_node_path22.join)(modulePath, "index.js"));
42992
- return candidates.find((candidate) => (0, import_node_fs31.existsSync)(candidate)) || null;
43067
+ candidates.push((0, import_node_path23.join)(modulePath, "dist", "index.js"), (0, import_node_path23.join)(modulePath, "index.js"));
43068
+ return candidates.find((candidate) => (0, import_node_fs32.existsSync)(candidate)) || null;
42993
43069
  }
42994
43070
  isThreatCrushModule(value) {
42995
43071
  return Boolean(
@@ -43498,16 +43574,16 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
43498
43574
  }
43499
43575
 
43500
43576
  // src/daemon/workers/cloud-spool.ts
43501
- var import_node_fs32 = require("fs");
43577
+ var import_node_fs33 = require("fs");
43502
43578
  var import_promises = require("fs/promises");
43503
- var import_node_path23 = require("path");
43579
+ var import_node_path24 = require("path");
43504
43580
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
43505
43581
  var CloudSpool = class {
43506
43582
  constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
43507
43583
  this.path = path2;
43508
43584
  this.limits = limits;
43509
43585
  try {
43510
- (0, import_node_fs32.mkdirSync)((0, import_node_path23.dirname)(path2), { recursive: true });
43586
+ (0, import_node_fs33.mkdirSync)((0, import_node_path24.dirname)(path2), { recursive: true });
43511
43587
  } catch {
43512
43588
  }
43513
43589
  this.load();
@@ -43576,7 +43652,7 @@ var CloudSpool = class {
43576
43652
  load() {
43577
43653
  let raw;
43578
43654
  try {
43579
- raw = (0, import_node_fs32.readFileSync)(this.path, "utf-8");
43655
+ raw = (0, import_node_fs33.readFileSync)(this.path, "utf-8");
43580
43656
  } catch {
43581
43657
  return;
43582
43658
  }
@@ -44043,32 +44119,32 @@ function resolveConfig(section) {
44043
44119
  }
44044
44120
 
44045
44121
  // src/core/abuse-report-log.ts
44046
- var import_node_fs33 = require("fs");
44047
- var import_node_path24 = require("path");
44122
+ var import_node_fs34 = require("fs");
44123
+ var import_node_path25 = require("path");
44048
44124
  init_paths();
44049
44125
  var ABUSE_DIRNAME = "abuse-reports";
44050
44126
  var LOG_FILE2 = "reports.jsonl";
44051
44127
  function resolveAbuseDir(dir) {
44052
44128
  if (dir) return dir;
44053
44129
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
44054
- const system = (0, import_node_path24.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44055
- if ((0, import_node_fs33.existsSync)(system)) return system;
44056
- return (0, import_node_path24.join)(PATHS.stateDir, ABUSE_DIRNAME);
44130
+ const system = (0, import_node_path25.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44131
+ if ((0, import_node_fs34.existsSync)(system)) return system;
44132
+ return (0, import_node_path25.join)(PATHS.stateDir, ABUSE_DIRNAME);
44057
44133
  }
44058
44134
  function logPath(dir) {
44059
- return (0, import_node_path24.join)(resolveAbuseDir(dir), LOG_FILE2);
44135
+ return (0, import_node_path25.join)(resolveAbuseDir(dir), LOG_FILE2);
44060
44136
  }
44061
44137
  function appendReport(record, dir) {
44062
44138
  const path2 = logPath(dir);
44063
- (0, import_node_fs33.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44064
- (0, import_node_fs33.appendFileSync)(path2, `${JSON.stringify(record)}
44139
+ (0, import_node_fs34.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44140
+ (0, import_node_fs34.appendFileSync)(path2, `${JSON.stringify(record)}
44065
44141
  `, { mode: 420 });
44066
44142
  }
44067
44143
  function readReports(dir) {
44068
44144
  const path2 = logPath(dir);
44069
44145
  let raw;
44070
44146
  try {
44071
- raw = (0, import_node_fs33.readFileSync)(path2, "utf-8");
44147
+ raw = (0, import_node_fs34.readFileSync)(path2, "utf-8");
44072
44148
  } catch {
44073
44149
  return [];
44074
44150
  }
@@ -44465,8 +44541,8 @@ var RemediationConsumer = class {
44465
44541
 
44466
44542
  // src/daemon/workers/auto-update.ts
44467
44543
  var import_node_child_process10 = require("child_process");
44468
- var import_node_fs34 = require("fs");
44469
- var import_node_path25 = require("path");
44544
+ var import_node_fs35 = require("fs");
44545
+ var import_node_path26 = require("path");
44470
44546
  init_backoff();
44471
44547
  var PKG_NAME = "@profullstack/threatcrush";
44472
44548
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
@@ -44510,12 +44586,12 @@ function pickUpdate(doc, current, opts) {
44510
44586
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
44511
44587
  }
44512
44588
  function installPlan(opts) {
44513
- const expected = `${import_node_path25.sep}lib${import_node_path25.sep}node_modules${import_node_path25.sep}@profullstack${import_node_path25.sep}threatcrush`;
44589
+ const expected = `${import_node_path26.sep}lib${import_node_path26.sep}node_modules${import_node_path26.sep}@profullstack${import_node_path26.sep}threatcrush`;
44514
44590
  if (!opts.pkgRoot.endsWith(expected)) {
44515
44591
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
44516
44592
  }
44517
- const nodeBin = (0, import_node_path25.dirname)(opts.execPath);
44518
- const npm = (0, import_node_path25.join)(nodeBin, "npm");
44593
+ const nodeBin = (0, import_node_path26.dirname)(opts.execPath);
44594
+ const npm = (0, import_node_path26.join)(nodeBin, "npm");
44519
44595
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
44520
44596
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
44521
44597
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -44547,10 +44623,10 @@ function installPlan(opts) {
44547
44623
  }
44548
44624
  function ownerOf(path2, passwd = "/etc/passwd") {
44549
44625
  try {
44550
- const st = (0, import_node_fs34.statSync)(path2);
44626
+ const st = (0, import_node_fs35.statSync)(path2);
44551
44627
  let home = st.uid === 0 ? "/root" : "";
44552
44628
  try {
44553
- for (const line2 of (0, import_node_fs34.readFileSync)(passwd, "utf8").split("\n")) {
44629
+ for (const line2 of (0, import_node_fs35.readFileSync)(passwd, "utf8").split("\n")) {
44554
44630
  const f = line2.split(":");
44555
44631
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
44556
44632
  }
@@ -44655,7 +44731,7 @@ var AutoUpdate = class {
44655
44731
  uid: process.getuid?.() ?? -1,
44656
44732
  owner: ownerOf(this.opts.pkgRoot),
44657
44733
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
44658
- npmExists: import_node_fs34.existsSync
44734
+ npmExists: import_node_fs35.existsSync
44659
44735
  });
44660
44736
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
44661
44737
  this.recordAttempt(target);
@@ -44690,7 +44766,7 @@ var AutoUpdate = class {
44690
44766
  }
44691
44767
  lastAttempt() {
44692
44768
  try {
44693
- const v = JSON.parse((0, import_node_fs34.readFileSync)(this.opts.statePath, "utf8"));
44769
+ const v = JSON.parse((0, import_node_fs35.readFileSync)(this.opts.statePath, "utf8"));
44694
44770
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
44695
44771
  } catch {
44696
44772
  return null;
@@ -44698,7 +44774,7 @@ var AutoUpdate = class {
44698
44774
  }
44699
44775
  recordAttempt(version) {
44700
44776
  try {
44701
- (0, import_node_fs34.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44777
+ (0, import_node_fs35.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44702
44778
  } catch (err) {
44703
44779
  this.opts.log(`[update] could not record attempt: ${err.message}`);
44704
44780
  }
@@ -44707,8 +44783,8 @@ var AutoUpdate = class {
44707
44783
 
44708
44784
  // src/daemon/workers/threat-feeds.ts
44709
44785
  var import_node_child_process11 = require("child_process");
44710
- var import_node_fs35 = require("fs");
44711
- var import_node_path26 = require("path");
44786
+ var import_node_fs36 = require("fs");
44787
+ var import_node_path27 = require("path");
44712
44788
  var import_node_net10 = require("net");
44713
44789
  init_backoff();
44714
44790
  var EGRESS_TABLE = "threatcrush_egress";
@@ -44880,14 +44956,14 @@ var ThreatFeeds = class {
44880
44956
  */
44881
44957
  writeResolverFiles(set) {
44882
44958
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
44883
- const dir = this.opts.resolverDir ?? (0, import_node_path26.dirname)(this.opts.cachePath);
44959
+ const dir = this.opts.resolverDir ?? (0, import_node_path27.dirname)(this.opts.cachePath);
44884
44960
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
44885
44961
  const write = (name, content) => {
44886
- const path2 = (0, import_node_path26.join)(dir, name);
44962
+ const path2 = (0, import_node_path27.join)(dir, name);
44887
44963
  if (this.resolverWritten.get(name) === content) return false;
44888
44964
  try {
44889
- (0, import_node_fs35.writeFileSync)(`${path2}.tmp`, content);
44890
- (0, import_node_fs35.renameSync)(`${path2}.tmp`, path2);
44965
+ (0, import_node_fs36.writeFileSync)(`${path2}.tmp`, content);
44966
+ (0, import_node_fs36.renameSync)(`${path2}.tmp`, path2);
44891
44967
  this.resolverWritten.set(name, content);
44892
44968
  return true;
44893
44969
  } catch (err) {
@@ -44898,11 +44974,11 @@ var ThreatFeeds = class {
44898
44974
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
44899
44975
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
44900
44976
  const via = [];
44901
- if ((0, import_node_fs35.existsSync)(hooks.dnsmasq)) {
44977
+ if ((0, import_node_fs36.existsSync)(hooks.dnsmasq)) {
44902
44978
  via.push("dnsmasq");
44903
44979
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
44904
44980
  }
44905
- if ((0, import_node_fs35.existsSync)(hooks.unbound)) {
44981
+ if ((0, import_node_fs36.existsSync)(hooks.unbound)) {
44906
44982
  via.push("unbound");
44907
44983
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
44908
44984
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -44963,8 +45039,8 @@ var ThreatFeeds = class {
44963
45039
  };
44964
45040
 
44965
45041
  // src/daemon/workers/privilege-watch.ts
44966
- var import_node_fs36 = require("fs");
44967
- var import_node_path27 = require("path");
45042
+ var import_node_fs37 = require("fs");
45043
+ var import_node_path28 = require("path");
44968
45044
  var import_node_child_process12 = require("child_process");
44969
45045
 
44970
45046
  // src/core/privileges/index.ts
@@ -45155,31 +45231,31 @@ function countryName(code) {
45155
45231
  var fsIO = {
45156
45232
  readFile: (p) => {
45157
45233
  try {
45158
- return (0, import_node_fs36.readFileSync)(p, "utf-8");
45234
+ return (0, import_node_fs37.readFileSync)(p, "utf-8");
45159
45235
  } catch {
45160
45236
  return null;
45161
45237
  }
45162
45238
  },
45163
45239
  readDir: (p) => {
45164
45240
  try {
45165
- return (0, import_node_fs36.readdirSync)(p);
45241
+ return (0, import_node_fs37.readdirSync)(p);
45166
45242
  } catch {
45167
45243
  return null;
45168
45244
  }
45169
45245
  },
45170
- exists: (p) => (0, import_node_fs36.existsSync)(p)
45246
+ exists: (p) => (0, import_node_fs37.existsSync)(p)
45171
45247
  };
45172
45248
  function readJson(path2) {
45173
45249
  try {
45174
- return JSON.parse((0, import_node_fs36.readFileSync)(path2, "utf-8"));
45250
+ return JSON.parse((0, import_node_fs37.readFileSync)(path2, "utf-8"));
45175
45251
  } catch {
45176
45252
  return null;
45177
45253
  }
45178
45254
  }
45179
45255
  function writeJson(path2, value) {
45180
- (0, import_node_fs36.mkdirSync)((0, import_node_path27.dirname)(path2), { recursive: true });
45181
- (0, import_node_fs36.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45182
- (0, import_node_fs36.renameSync)(`${path2}.tmp`, path2);
45256
+ (0, import_node_fs37.mkdirSync)((0, import_node_path28.dirname)(path2), { recursive: true });
45257
+ (0, import_node_fs37.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45258
+ (0, import_node_fs37.renameSync)(`${path2}.tmp`, path2);
45183
45259
  }
45184
45260
  function defaultRun3(cmd, args) {
45185
45261
  const res = (0, import_node_child_process12.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -45335,7 +45411,7 @@ var PrivilegeWatch = class {
45335
45411
  * raised a "new country" alert on its first run; on dev2 it did, at once.
45336
45412
  */
45337
45413
  async backfillLogins() {
45338
- if ((0, import_node_fs36.existsSync)(this.opts.loginsPath)) return;
45414
+ if ((0, import_node_fs37.existsSync)(this.opts.loginsPath)) return;
45339
45415
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
45340
45416
  const byUser = parseAcceptedLogins(out ?? "");
45341
45417
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -45348,7 +45424,7 @@ var PrivilegeWatch = class {
45348
45424
  return;
45349
45425
  }
45350
45426
  }
45351
- if ((0, import_node_fs36.existsSync)(this.opts.loginsPath)) return;
45427
+ if ((0, import_node_fs37.existsSync)(this.opts.loginsPath)) return;
45352
45428
  const at = this.now().toISOString();
45353
45429
  const history = {};
45354
45430
  for (const [user, userIps] of byUser) {
@@ -45560,8 +45636,8 @@ var RuleEngine = class {
45560
45636
  };
45561
45637
 
45562
45638
  // src/daemon/rules/loader.ts
45563
- var import_node_fs37 = require("fs");
45564
- var import_node_path28 = require("path");
45639
+ var import_node_fs38 = require("fs");
45640
+ var import_node_path29 = require("path");
45565
45641
 
45566
45642
  // src/daemon/rules/default-rules.ts
45567
45643
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -46031,11 +46107,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
46031
46107
  function loadAllRules(customDir) {
46032
46108
  const rules = [...DEFAULT_RULES];
46033
46109
  const dir = customDir || RULES_DIR;
46034
- if ((0, import_node_fs37.existsSync)(dir)) {
46035
- const files = (0, import_node_fs37.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46110
+ if ((0, import_node_fs38.existsSync)(dir)) {
46111
+ const files = (0, import_node_fs38.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46036
46112
  for (const file of files) {
46037
46113
  try {
46038
- const raw = (0, import_node_fs37.readFileSync)((0, import_node_path28.join)(dir, file), "utf-8");
46114
+ const raw = (0, import_node_fs38.readFileSync)((0, import_node_path29.join)(dir, file), "utf-8");
46039
46115
  const parsed = JSON.parse(raw);
46040
46116
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
46041
46117
  for (const rule of customRules) {
@@ -46067,8 +46143,8 @@ function loadAllRules(customDir) {
46067
46143
 
46068
46144
  // src/daemon/firewall/adapters.ts
46069
46145
  var import_node_child_process13 = require("child_process");
46070
- var import_node_fs38 = require("fs");
46071
- var import_node_path29 = require("path");
46146
+ var import_node_fs39 = require("fs");
46147
+ var import_node_path30 = require("path");
46072
46148
  var import_node_net11 = require("net");
46073
46149
  function assertValidFirewallIp(ip) {
46074
46150
  if ((0, import_node_net11.isIP)(ip) !== 4) {
@@ -46081,9 +46157,9 @@ function assertBannableIp(ip) {
46081
46157
  }
46082
46158
  }
46083
46159
  function writeIfAbsent(path2, contents) {
46084
- (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
46160
+ (0, import_node_fs39.mkdirSync)((0, import_node_path30.dirname)(path2), { recursive: true });
46085
46161
  try {
46086
- (0, import_node_fs38.writeFileSync)(path2, contents, { flag: "wx" });
46162
+ (0, import_node_fs39.writeFileSync)(path2, contents, { flag: "wx" });
46087
46163
  } catch (err) {
46088
46164
  if (err.code !== "EEXIST") throw err;
46089
46165
  }
@@ -46342,7 +46418,7 @@ function detectFirewallAdapter(backend = "auto") {
46342
46418
  }
46343
46419
 
46344
46420
  // src/daemon/firewall/remediation.ts
46345
- var import_node_fs39 = require("fs");
46421
+ var import_node_fs40 = require("fs");
46346
46422
  var import_node_child_process14 = require("child_process");
46347
46423
  var import_node_net12 = require("net");
46348
46424
  init_paths();
@@ -46413,19 +46489,19 @@ var defaultDiscovery = {
46413
46489
  const snapshot = takeSnapshot({
46414
46490
  readFile: (p) => {
46415
46491
  try {
46416
- return (0, import_node_fs39.readFileSync)(p, "utf-8");
46492
+ return (0, import_node_fs40.readFileSync)(p, "utf-8");
46417
46493
  } catch {
46418
46494
  return null;
46419
46495
  }
46420
46496
  },
46421
46497
  readDir: (p) => {
46422
46498
  try {
46423
- return (0, import_node_fs39.readdirSync)(p);
46499
+ return (0, import_node_fs40.readdirSync)(p);
46424
46500
  } catch {
46425
46501
  return null;
46426
46502
  }
46427
46503
  },
46428
- exists: (p) => (0, import_node_fs39.existsSync)(p)
46504
+ exists: (p) => (0, import_node_fs40.existsSync)(p)
46429
46505
  });
46430
46506
  const out = /* @__PURE__ */ new Set();
46431
46507
  for (const keys of Object.values(snapshot.keys)) {
@@ -46866,7 +46942,7 @@ var RemediationManager = class {
46866
46942
  }
46867
46943
  logLine(line2) {
46868
46944
  try {
46869
- (0, import_node_fs39.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
46945
+ (0, import_node_fs40.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
46870
46946
  `);
46871
46947
  } catch {
46872
46948
  }
@@ -46909,19 +46985,19 @@ function remediationSettings(section) {
46909
46985
  init_backoff();
46910
46986
 
46911
46987
  // src/daemon/watchdog-service.ts
46912
- var import_node_fs40 = require("fs");
46913
- var import_node_path30 = require("path");
46988
+ var import_node_fs41 = require("fs");
46989
+ var import_node_path31 = require("path");
46914
46990
  function defaultShareGid() {
46915
46991
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
46916
46992
  if (!isRoot4) return void 0;
46917
46993
  try {
46918
- return (0, import_node_fs40.statSync)("/var/log/auth.log").gid;
46994
+ return (0, import_node_fs41.statSync)("/var/log/auth.log").gid;
46919
46995
  } catch {
46920
46996
  return void 0;
46921
46997
  }
46922
46998
  }
46923
46999
  function startWatchdog(opts) {
46924
- const dir = opts.config?.dir ?? (0, import_node_path30.join)(opts.stateDir, WATCHDOG_DIRNAME);
47000
+ const dir = opts.config?.dir ?? (0, import_node_path31.join)(opts.stateDir, WATCHDOG_DIRNAME);
46925
47001
  const base = { dir, logged: 0, answered: 0, errored: 0 };
46926
47002
  if (opts.config?.enabled === false) {
46927
47003
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -47036,7 +47112,7 @@ function versionOfNode(path2) {
47036
47112
  // src/daemon/index.ts
47037
47113
  function readVersion2() {
47038
47114
  try {
47039
- const pkg = JSON.parse((0, import_node_fs41.readFileSync)((0, import_node_path31.join)(__dirname, "..", "package.json"), "utf-8"));
47115
+ const pkg = JSON.parse((0, import_node_fs42.readFileSync)((0, import_node_path32.join)(__dirname, "..", "package.json"), "utf-8"));
47040
47116
  return pkg.version || "0.0.0";
47041
47117
  } catch {
47042
47118
  return "0.0.0";
@@ -47045,7 +47121,7 @@ function readVersion2() {
47045
47121
  async function runHardeningChecks() {
47046
47122
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47047
47123
  process.execPath,
47048
- [(0, import_node_path31.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47124
+ [(0, import_node_path32.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47049
47125
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
47050
47126
  );
47051
47127
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47059,7 +47135,7 @@ async function runHardeningChecks() {
47059
47135
  async function runPatchCheck() {
47060
47136
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47061
47137
  process.execPath,
47062
- [(0, import_node_path31.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47138
+ [(0, import_node_path32.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47063
47139
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
47064
47140
  );
47065
47141
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47067,7 +47143,7 @@ async function runPatchCheck() {
47067
47143
  }
47068
47144
  function logLine(line2) {
47069
47145
  try {
47070
- (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47146
+ (0, import_node_fs42.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47071
47147
  `);
47072
47148
  } catch {
47073
47149
  }
@@ -47109,7 +47185,7 @@ async function runDaemon() {
47109
47185
  } catch (err) {
47110
47186
  logLine(`[daemon] state db unavailable: ${err.message}`);
47111
47187
  }
47112
- const config = loadConfig((0, import_node_fs41.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47188
+ const config = loadConfig((0, import_node_fs42.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47113
47189
  configureAttackDetection(config.detection);
47114
47190
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
47115
47191
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -47173,7 +47249,7 @@ async function runDaemon() {
47173
47249
  const threatFeeds = new ThreatFeeds({
47174
47250
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
47175
47251
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
47176
- cachePath: (0, import_node_path31.join)(PATHS.stateDir, "threat-feeds.json"),
47252
+ cachePath: (0, import_node_path32.join)(PATHS.stateDir, "threat-feeds.json"),
47177
47253
  bus,
47178
47254
  log: logLine
47179
47255
  });
@@ -47181,9 +47257,9 @@ async function runDaemon() {
47181
47257
  const privilegeWatch = new PrivilegeWatch({
47182
47258
  settings: privilegeSettings(config.privileged),
47183
47259
  bus,
47184
- snapshotPath: (0, import_node_path31.join)(PATHS.stateDir, "privileges.json"),
47185
- loginsPath: (0, import_node_path31.join)(PATHS.stateDir, "login-countries.json"),
47186
- cursorPath: (0, import_node_path31.join)(PATHS.stateDir, "sudo-cursor.json"),
47260
+ snapshotPath: (0, import_node_path32.join)(PATHS.stateDir, "privileges.json"),
47261
+ loginsPath: (0, import_node_path32.join)(PATHS.stateDir, "login-countries.json"),
47262
+ cursorPath: (0, import_node_path32.join)(PATHS.stateDir, "sudo-cursor.json"),
47187
47263
  log: logLine
47188
47264
  });
47189
47265
  privilegeWatch.start();
@@ -47204,9 +47280,9 @@ async function runDaemon() {
47204
47280
  cloudSync = new CloudSync({
47205
47281
  bus,
47206
47282
  version,
47207
- hostname: (0, import_node_os12.hostname)(),
47283
+ hostname: (0, import_node_os13.hostname)(),
47208
47284
  minSeverity,
47209
- spoolPath: (0, import_node_path31.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47285
+ spoolPath: (0, import_node_path32.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47210
47286
  log: logLine,
47211
47287
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
47212
47288
  runHardening: runHardeningChecks
@@ -47225,8 +47301,8 @@ async function runDaemon() {
47225
47301
  const autoUpdate = new AutoUpdate({
47226
47302
  version,
47227
47303
  settings: updateSettings(config.update),
47228
- pkgRoot: (0, import_node_path31.join)(__dirname, ".."),
47229
- statePath: (0, import_node_path31.join)(PATHS.stateDir, "auto-update.json"),
47304
+ pkgRoot: (0, import_node_path32.join)(__dirname, ".."),
47305
+ statePath: (0, import_node_path32.join)(PATHS.stateDir, "auto-update.json"),
47230
47306
  bus,
47231
47307
  log: logLine,
47232
47308
  restartDaemon
@@ -47316,7 +47392,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
47316
47392
  function isRoot2() {
47317
47393
  return typeof process.getuid === "function" && process.getuid() === 0;
47318
47394
  }
47319
- var DAEMON_ENTRY = (0, import_node_path32.join)(__dirname, "daemon.js");
47395
+ var DAEMON_ENTRY = (0, import_node_path33.join)(__dirname, "daemon.js");
47320
47396
  async function daemonForeground() {
47321
47397
  await runDaemon();
47322
47398
  }
@@ -47337,7 +47413,7 @@ async function daemonStart() {
47337
47413
  return;
47338
47414
  }
47339
47415
  ensureRuntimeDirs();
47340
- if (!(0, import_node_fs42.existsSync)(DAEMON_ENTRY)) {
47416
+ if (!(0, import_node_fs43.existsSync)(DAEMON_ENTRY)) {
47341
47417
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
47342
47418
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
47343
47419
  return;
@@ -47345,8 +47421,8 @@ async function daemonStart() {
47345
47421
  let out;
47346
47422
  let err;
47347
47423
  try {
47348
- out = (0, import_node_fs43.openSync)(PATHS.logFile, "a");
47349
- err = (0, import_node_fs43.openSync)(PATHS.logFile, "a");
47424
+ out = (0, import_node_fs44.openSync)(PATHS.logFile, "a");
47425
+ err = (0, import_node_fs44.openSync)(PATHS.logFile, "a");
47350
47426
  } catch (e) {
47351
47427
  const code = e.code;
47352
47428
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -47434,12 +47510,12 @@ async function waitForExit(pid, timeoutMs) {
47434
47510
  }
47435
47511
  async function releaseStaleSocket() {
47436
47512
  const deadline = Date.now() + 2e3;
47437
- while ((0, import_node_fs42.existsSync)(PATHS.socket) && Date.now() < deadline) {
47513
+ while ((0, import_node_fs43.existsSync)(PATHS.socket) && Date.now() < deadline) {
47438
47514
  await new Promise((r) => setTimeout(r, 50));
47439
47515
  }
47440
- if ((0, import_node_fs42.existsSync)(PATHS.socket)) {
47516
+ if ((0, import_node_fs43.existsSync)(PATHS.socket)) {
47441
47517
  try {
47442
- (0, import_node_fs42.unlinkSync)(PATHS.socket);
47518
+ (0, import_node_fs43.unlinkSync)(PATHS.socket);
47443
47519
  } catch {
47444
47520
  }
47445
47521
  }
@@ -47447,26 +47523,26 @@ async function releaseStaleSocket() {
47447
47523
 
47448
47524
  // src/commands/service.ts
47449
47525
  var import_node_child_process18 = require("child_process");
47450
- var import_node_fs44 = require("fs");
47451
- var import_node_path33 = require("path");
47452
- var import_node_os13 = require("os");
47526
+ var import_node_fs45 = require("fs");
47527
+ var import_node_path34 = require("path");
47528
+ var import_node_os14 = require("os");
47453
47529
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
47454
47530
  var DAEMON_UNIT_NAME = "threatcrushd.service";
47455
47531
  function resolveTemplate() {
47456
- const templatePath = (0, import_node_path33.join)(__dirname, "systemd", "threatcrushd.service");
47457
- if (!(0, import_node_fs44.existsSync)(templatePath)) {
47532
+ const templatePath = (0, import_node_path34.join)(__dirname, "systemd", "threatcrushd.service");
47533
+ if (!(0, import_node_fs45.existsSync)(templatePath)) {
47458
47534
  throw new Error(`systemd unit template not found at ${templatePath}`);
47459
47535
  }
47460
- return (0, import_node_fs44.readFileSync)(templatePath, "utf-8");
47536
+ return (0, import_node_fs45.readFileSync)(templatePath, "utf-8");
47461
47537
  }
47462
47538
  function stableBinPath(binPath) {
47463
47539
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
47464
47540
  if (stable === binPath) return binPath;
47465
- return (0, import_node_fs44.existsSync)(stable) ? stable : binPath;
47541
+ return (0, import_node_fs45.existsSync)(stable) ? stable : binPath;
47466
47542
  }
47467
47543
  function resolveBinPath() {
47468
47544
  const arg = process.argv[1];
47469
- if (arg && (0, import_node_fs44.existsSync)(arg)) return stableBinPath(arg);
47545
+ if (arg && (0, import_node_fs45.existsSync)(arg)) return stableBinPath(arg);
47470
47546
  try {
47471
47547
  return (0, import_node_child_process18.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
47472
47548
  } catch {
@@ -47476,11 +47552,11 @@ function resolveBinPath() {
47476
47552
  function stableNodePath(execPath) {
47477
47553
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
47478
47554
  if (stable === execPath) return execPath;
47479
- return (0, import_node_fs44.existsSync)(stable) ? stable : execPath;
47555
+ return (0, import_node_fs45.existsSync)(stable) ? stable : execPath;
47480
47556
  }
47481
47557
  function looksLikeNodeScript(path2) {
47482
47558
  try {
47483
- const head = (0, import_node_fs44.readFileSync)(path2, "utf-8").slice(0, 120);
47559
+ const head = (0, import_node_fs45.readFileSync)(path2, "utf-8").slice(0, 120);
47484
47560
  return /^#!.*\bnode\b/.test(head);
47485
47561
  } catch {
47486
47562
  return false;
@@ -47520,7 +47596,7 @@ function callerHome() {
47520
47596
  try {
47521
47597
  const line2 = (0, import_node_child_process18.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
47522
47598
  const home = line2.split(":")[5];
47523
- return home && (0, import_node_fs44.existsSync)(home) ? home : null;
47599
+ return home && (0, import_node_fs45.existsSync)(home) ? home : null;
47524
47600
  } catch {
47525
47601
  return null;
47526
47602
  }
@@ -47528,13 +47604,13 @@ function callerHome() {
47528
47604
  function stopUserModeDaemon() {
47529
47605
  const home = callerHome();
47530
47606
  if (!home) return;
47531
- const runDir = (0, import_node_path33.join)(home, ".threatcrush", "run");
47532
- const pidFile = (0, import_node_path33.join)(runDir, "threatcrushd.pid");
47533
- const socket = (0, import_node_path33.join)(runDir, "threatcrushd.sock");
47534
- if (!(0, import_node_fs44.existsSync)(pidFile) && !(0, import_node_fs44.existsSync)(socket)) return;
47607
+ const runDir = (0, import_node_path34.join)(home, ".threatcrush", "run");
47608
+ const pidFile = (0, import_node_path34.join)(runDir, "threatcrushd.pid");
47609
+ const socket = (0, import_node_path34.join)(runDir, "threatcrushd.sock");
47610
+ if (!(0, import_node_fs45.existsSync)(pidFile) && !(0, import_node_fs45.existsSync)(socket)) return;
47535
47611
  let pid = null;
47536
47612
  try {
47537
- pid = Number.parseInt((0, import_node_fs44.readFileSync)(pidFile, "utf-8").trim(), 10);
47613
+ pid = Number.parseInt((0, import_node_fs45.readFileSync)(pidFile, "utf-8").trim(), 10);
47538
47614
  } catch {
47539
47615
  pid = null;
47540
47616
  }
@@ -47547,7 +47623,7 @@ function stopUserModeDaemon() {
47547
47623
  }
47548
47624
  for (const path2 of [socket, pidFile]) {
47549
47625
  try {
47550
- if ((0, import_node_fs44.existsSync)(path2)) (0, import_node_fs44.rmSync)(path2);
47626
+ if ((0, import_node_fs45.existsSync)(path2)) (0, import_node_fs45.rmSync)(path2);
47551
47627
  } catch {
47552
47628
  }
47553
47629
  }
@@ -47565,7 +47641,7 @@ async function installServiceCommand() {
47565
47641
  }
47566
47642
  const noSystemd = systemdUnavailableReason({
47567
47643
  hasSystemctl: (0, import_node_child_process18.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
47568
- booted: (0, import_node_fs44.existsSync)("/run/systemd/system")
47644
+ booted: (0, import_node_fs45.existsSync)("/run/systemd/system")
47569
47645
  });
47570
47646
  if (noSystemd) {
47571
47647
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -47587,7 +47663,7 @@ async function installServiceCommand() {
47587
47663
  const isNodeScript = looksLikeNodeScript(binPath);
47588
47664
  let nodePath = stableNodePath(process.execPath);
47589
47665
  if (isNodeScript && nodeVersionDir(binPath)) {
47590
- binPath = (0, import_node_fs44.realpathSync)(binPath);
47666
+ binPath = (0, import_node_fs45.realpathSync)(binPath);
47591
47667
  nodePath = process.execPath;
47592
47668
  }
47593
47669
  if (isNodeScript) {
@@ -47600,9 +47676,9 @@ async function installServiceCommand() {
47600
47676
  }
47601
47677
  }
47602
47678
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
47603
- const configDir = (0, import_node_path33.join)((0, import_node_os13.homedir)(), ".threatcrush");
47679
+ const configDir = (0, import_node_path34.join)((0, import_node_os14.homedir)(), ".threatcrush");
47604
47680
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
47605
- (0, import_node_fs44.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47681
+ (0, import_node_fs45.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47606
47682
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
47607
47683
  console.log(source_default.dim(` ExecStart=${exec}`));
47608
47684
  const nodeDir = nodeVersionDir(nodePath);
@@ -47655,9 +47731,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
47655
47731
  ].join("\n");
47656
47732
  }
47657
47733
  function installLogrotate() {
47658
- if (!(0, import_node_fs44.existsSync)((0, import_node_path33.dirname)(LOGROTATE_PATH))) return;
47734
+ if (!(0, import_node_fs45.existsSync)((0, import_node_path34.dirname)(LOGROTATE_PATH))) return;
47659
47735
  try {
47660
- (0, import_node_fs44.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47736
+ (0, import_node_fs45.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47661
47737
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
47662
47738
  } catch (err) {
47663
47739
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -47679,20 +47755,20 @@ function ensureSystemDirs(configDir) {
47679
47755
  ];
47680
47756
  let admGid2 = null;
47681
47757
  try {
47682
- admGid2 = (0, import_node_fs44.statSync)("/var/log/auth.log").gid;
47758
+ admGid2 = (0, import_node_fs45.statSync)("/var/log/auth.log").gid;
47683
47759
  } catch {
47684
47760
  }
47685
47761
  for (const { path: path2, groupWritable, sticky } of dirs) {
47686
47762
  try {
47687
- (0, import_node_fs44.mkdirSync)(path2, { recursive: true });
47763
+ (0, import_node_fs45.mkdirSync)(path2, { recursive: true });
47688
47764
  } catch {
47689
47765
  }
47690
47766
  try {
47691
47767
  if (groupWritable && admGid2 !== null) {
47692
- (0, import_node_fs44.chmodSync)(path2, sticky ? 1533 : 509);
47768
+ (0, import_node_fs45.chmodSync)(path2, sticky ? 1533 : 509);
47693
47769
  (0, import_node_child_process18.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
47694
47770
  } else {
47695
- (0, import_node_fs44.chmodSync)(path2, 493);
47771
+ (0, import_node_fs45.chmodSync)(path2, 493);
47696
47772
  }
47697
47773
  } catch {
47698
47774
  }
@@ -47720,7 +47796,7 @@ async function uninstallServiceCommand() {
47720
47796
  } catch {
47721
47797
  }
47722
47798
  try {
47723
- if ((0, import_node_fs44.existsSync)(UNIT_PATH)) {
47799
+ if ((0, import_node_fs45.existsSync)(UNIT_PATH)) {
47724
47800
  (0, import_node_child_process18.execSync)(`rm -f ${UNIT_PATH}`);
47725
47801
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
47726
47802
  }
@@ -47734,7 +47810,7 @@ async function uninstallServiceCommand() {
47734
47810
  }
47735
47811
 
47736
47812
  // src/commands/save.ts
47737
- var import_node_fs45 = require("fs");
47813
+ var import_node_fs46 = require("fs");
47738
47814
  var import_toml5 = __toESM(require_toml());
47739
47815
  init_cli_config();
47740
47816
  init_paths();
@@ -47773,9 +47849,9 @@ async function saveCommand(opts = {}) {
47773
47849
  }
47774
47850
  const path2 = opts.config ?? PATHS.configFile;
47775
47851
  let config = {};
47776
- if ((0, import_node_fs45.existsSync)(path2)) {
47852
+ if ((0, import_node_fs46.existsSync)(path2)) {
47777
47853
  try {
47778
- config = import_toml5.default.parse((0, import_node_fs45.readFileSync)(path2, "utf-8"));
47854
+ config = import_toml5.default.parse((0, import_node_fs46.readFileSync)(path2, "utf-8"));
47779
47855
  } catch (err) {
47780
47856
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
47781
47857
  `));
@@ -47888,11 +47964,11 @@ function welcomeCommand() {
47888
47964
  }
47889
47965
 
47890
47966
  // src/commands/properties.ts
47891
- var import_node_fs46 = require("fs");
47892
- var import_node_path34 = require("path");
47967
+ var import_node_fs47 = require("fs");
47968
+ var import_node_path35 = require("path");
47893
47969
  var import_node_readline4 = __toESM(require("readline"));
47894
47970
  init_cli_config();
47895
- var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
47971
+ var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
47896
47972
  var KINDS = ["url", "api", "domain", "ip", "repo"];
47897
47973
  function prompt(question) {
47898
47974
  const rl = import_node_readline4.default.createInterface({ input: process.stdin, output: process.stdout });
@@ -47915,7 +47991,7 @@ async function resolveOrgId(orgFlag) {
47915
47991
  }
47916
47992
  let orgs = [];
47917
47993
  try {
47918
- const res = await fetch(`${API_URL5}/api/orgs`, { headers: authHeaders() });
47994
+ const res = await fetch(`${API_URL6}/api/orgs`, { headers: authHeaders() });
47919
47995
  if (!res.ok) {
47920
47996
  console.log(source_default.red(` Failed to list organizations (${res.status})
47921
47997
  `));
@@ -47945,7 +48021,7 @@ async function resolveOrgId(orgFlag) {
47945
48021
  }
47946
48022
  async function fetchProperties(orgId, kind) {
47947
48023
  const qs = kind ? `?kind=${kind}` : "";
47948
- const res = await fetch(`${API_URL5}/api/orgs/${orgId}/properties${qs}`, { headers: authHeaders() });
48024
+ const res = await fetch(`${API_URL6}/api/orgs/${orgId}/properties${qs}`, { headers: authHeaders() });
47949
48025
  if (!res.ok) {
47950
48026
  const body = await res.json().catch(() => ({ error: res.statusText }));
47951
48027
  console.log(source_default.red(` ${body.error || "Failed to load properties"}
@@ -48026,7 +48102,7 @@ async function propertiesAddCommand(name, target, opts) {
48026
48102
  };
48027
48103
  const spinner = ora({ text: `Creating property ${source_default.white(name)}...`, color: "green" }).start();
48028
48104
  try {
48029
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties`, {
48105
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties`, {
48030
48106
  method: "POST",
48031
48107
  headers: authHeaders(),
48032
48108
  body: JSON.stringify(body)
@@ -48062,7 +48138,7 @@ async function propertiesRemoveCommand(nameOrId, opts) {
48062
48138
  return;
48063
48139
  }
48064
48140
  }
48065
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties/${match.id}`, {
48141
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties/${match.id}`, {
48066
48142
  method: "DELETE",
48067
48143
  headers: authHeaders()
48068
48144
  });
@@ -48077,7 +48153,7 @@ async function propertiesRemoveCommand(nameOrId, opts) {
48077
48153
  }
48078
48154
  async function enqueueRun(orgId, propertyId, type, trigger = "cli") {
48079
48155
  try {
48080
- const res = await fetch(`${API_URL5}/api/orgs/${orgId}/properties/${propertyId}/runs`, {
48156
+ const res = await fetch(`${API_URL6}/api/orgs/${orgId}/properties/${propertyId}/runs`, {
48081
48157
  method: "POST",
48082
48158
  headers: authHeaders(),
48083
48159
  body: JSON.stringify({ type, trigger })
@@ -48090,7 +48166,7 @@ async function enqueueRun(orgId, propertyId, type, trigger = "cli") {
48090
48166
  }
48091
48167
  async function finalizeRun(orgId, propertyId, runId, result) {
48092
48168
  try {
48093
- await fetch(`${API_URL5}/api/orgs/${orgId}/properties/${propertyId}/runs/${runId}`, {
48169
+ await fetch(`${API_URL6}/api/orgs/${orgId}/properties/${propertyId}/runs/${runId}`, {
48094
48170
  method: "PATCH",
48095
48171
  headers: authHeaders(),
48096
48172
  body: JSON.stringify({
@@ -48194,7 +48270,7 @@ async function propertiesRunsCommand(opts) {
48194
48270
  let total = 0;
48195
48271
  for (const prop of propsToShow) {
48196
48272
  const res = await fetch(
48197
- `${API_URL5}/api/orgs/${resolved.org.id}/properties/${prop.id}/runs?limit=${limit}`,
48273
+ `${API_URL6}/api/orgs/${resolved.org.id}/properties/${prop.id}/runs?limit=${limit}`,
48198
48274
  { headers: authHeaders() }
48199
48275
  );
48200
48276
  if (!res.ok) continue;
@@ -48219,8 +48295,8 @@ async function propertiesRunsCommand(opts) {
48219
48295
  }
48220
48296
  }
48221
48297
  function parseImportFile(path2) {
48222
- const ext = (0, import_node_path34.extname)(path2).toLowerCase();
48223
- const raw = (0, import_node_fs46.readFileSync)(path2, "utf-8");
48298
+ const ext = (0, import_node_path35.extname)(path2).toLowerCase();
48299
+ const raw = (0, import_node_fs47.readFileSync)(path2, "utf-8");
48224
48300
  if (ext === ".json") {
48225
48301
  const parsed = JSON.parse(raw);
48226
48302
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -48298,7 +48374,7 @@ async function propertiesImportCommand(filePath, opts) {
48298
48374
  continue;
48299
48375
  }
48300
48376
  try {
48301
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties`, {
48377
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties`, {
48302
48378
  method: "POST",
48303
48379
  headers: authHeaders(),
48304
48380
  body: JSON.stringify({
@@ -48415,7 +48491,7 @@ async function rulesCommand(opts) {
48415
48491
  }
48416
48492
 
48417
48493
  // src/commands/harden.ts
48418
- var import_node_fs47 = require("fs");
48494
+ var import_node_fs48 = require("fs");
48419
48495
  var import_node_child_process19 = require("child_process");
48420
48496
  init_cli_config();
48421
48497
  function tryExec(cmd) {
@@ -48427,7 +48503,7 @@ function tryExec(cmd) {
48427
48503
  }
48428
48504
  function tryRead(path2) {
48429
48505
  try {
48430
- return (0, import_node_fs47.readFileSync)(path2, "utf-8");
48506
+ return (0, import_node_fs48.readFileSync)(path2, "utf-8");
48431
48507
  } catch {
48432
48508
  return null;
48433
48509
  }
@@ -48531,8 +48607,8 @@ function checkSshWeakConfig() {
48531
48607
  };
48532
48608
  }
48533
48609
  function checkAutoUpdates() {
48534
- const unattended = (0, import_node_fs47.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs47.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48535
- const dnfAuto = (0, import_node_fs47.existsSync)("/etc/dnf/automatic.conf");
48610
+ const unattended = (0, import_node_fs48.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs48.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48611
+ const dnfAuto = (0, import_node_fs48.existsSync)("/etc/dnf/automatic.conf");
48536
48612
  if (unattended || dnfAuto) {
48537
48613
  return {
48538
48614
  key: "auto-updates",
@@ -48658,7 +48734,7 @@ function checkFail2ban() {
48658
48734
  explanation: "fail2ban is installed and running."
48659
48735
  };
48660
48736
  }
48661
- if ((0, import_node_fs47.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48737
+ if ((0, import_node_fs48.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48662
48738
  return {
48663
48739
  key: checkKey,
48664
48740
  status: "warn",
@@ -48844,8 +48920,8 @@ async function hardenCommand(opts) {
48844
48920
  }
48845
48921
 
48846
48922
  // src/core/patches/index.ts
48847
- var import_node_fs48 = require("fs");
48848
- var import_node_path35 = require("path");
48923
+ var import_node_fs49 = require("fs");
48924
+ var import_node_path36 = require("path");
48849
48925
  var import_node_child_process20 = require("child_process");
48850
48926
  var import_node_util5 = require("util");
48851
48927
 
@@ -49005,9 +49081,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
49005
49081
  function newestReleaseMtime(dir) {
49006
49082
  try {
49007
49083
  let newest = 0;
49008
- for (const name of (0, import_node_fs48.readdirSync)(dir)) {
49084
+ for (const name of (0, import_node_fs49.readdirSync)(dir)) {
49009
49085
  if (!/Release$/.test(name)) continue;
49010
- newest = Math.max(newest, (0, import_node_fs48.statSync)((0, import_node_path35.join)(dir, name)).mtimeMs);
49086
+ newest = Math.max(newest, (0, import_node_fs49.statSync)((0, import_node_path36.join)(dir, name)).mtimeMs);
49011
49087
  }
49012
49088
  return newest > 0 ? new Date(newest) : null;
49013
49089
  } catch {
@@ -49024,7 +49100,7 @@ async function checkPatches(opts = {}) {
49024
49100
  let osText = opts.osRelease;
49025
49101
  if (osText === void 0) {
49026
49102
  try {
49027
- osText = (0, import_node_fs48.readFileSync)("/etc/os-release", "utf-8");
49103
+ osText = (0, import_node_fs49.readFileSync)("/etc/os-release", "utf-8");
49028
49104
  } catch {
49029
49105
  osText = "";
49030
49106
  }
@@ -49251,24 +49327,24 @@ async function patchesCommand(opts) {
49251
49327
 
49252
49328
  // src/commands/feeds.ts
49253
49329
  var import_node_net13 = require("net");
49254
- var import_node_path37 = require("path");
49330
+ var import_node_path38 = require("path");
49255
49331
  init_paths();
49256
49332
 
49257
49333
  // src/commands/feeds-resolver.ts
49258
49334
  var import_node_child_process21 = require("child_process");
49259
- var import_node_fs49 = require("fs");
49260
- var import_node_path36 = require("path");
49335
+ var import_node_fs50 = require("fs");
49336
+ var import_node_path37 = require("path");
49261
49337
  var realIO = {
49262
- exists: (p) => (0, import_node_fs49.existsSync)(p),
49338
+ exists: (p) => (0, import_node_fs50.existsSync)(p),
49263
49339
  read: (p) => {
49264
49340
  try {
49265
- return (0, import_node_fs49.readFileSync)(p, "utf-8");
49341
+ return (0, import_node_fs50.readFileSync)(p, "utf-8");
49266
49342
  } catch {
49267
49343
  return null;
49268
49344
  }
49269
49345
  },
49270
- write: (p, c) => (0, import_node_fs49.writeFileSync)(p, c),
49271
- remove: (p) => (0, import_node_fs49.rmSync)(p, { force: true }),
49346
+ write: (p, c) => (0, import_node_fs50.writeFileSync)(p, c),
49347
+ remove: (p) => (0, import_node_fs50.rmSync)(p, { force: true }),
49272
49348
  run: (cmd, args) => {
49273
49349
  const r = (0, import_node_child_process21.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
49274
49350
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -49278,17 +49354,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
49278
49354
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
49279
49355
  function hookContent(resolver, stateDir) {
49280
49356
  const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
49281
- return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.hosts)}
49282
- ` : `${head}include: "${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound)}"
49357
+ return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path37.join)(stateDir, RESOLVER_FILES.hosts)}
49358
+ ` : `${head}include: "${(0, import_node_path37.join)(stateDir, RESOLVER_FILES.unbound)}"
49283
49359
  `;
49284
49360
  }
49285
49361
  function apparmorRule(stateDir) {
49286
- return ` ${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49362
+ return ` ${(0, import_node_path37.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49287
49363
  }
49288
49364
  function detectResolvers(io = realIO) {
49289
49365
  const found = [];
49290
- if (io.exists((0, import_node_path36.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49291
- if (io.exists((0, import_node_path36.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49366
+ if (io.exists((0, import_node_path37.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49367
+ if (io.exists((0, import_node_path37.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49292
49368
  return found;
49293
49369
  }
49294
49370
  function check(resolver, io) {
@@ -49301,7 +49377,7 @@ function restartIfActive(resolver, io) {
49301
49377
  }
49302
49378
  function installHook(resolver, stateDir, io = realIO) {
49303
49379
  const hook = RESOLVER_HOOKS[resolver];
49304
- const file = (0, import_node_path36.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49380
+ const file = (0, import_node_path37.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49305
49381
  if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
49306
49382
  io.write(hook, hookContent(resolver, stateDir));
49307
49383
  if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
@@ -49362,8 +49438,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
49362
49438
  }
49363
49439
  return failed ? 1 : 0;
49364
49440
  }
49365
- const hosts = io.read((0, import_node_path36.join)(stateDir, RESOLVER_FILES.hosts));
49366
- const unbound = io.read((0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound));
49441
+ const hosts = io.read((0, import_node_path37.join)(stateDir, RESOLVER_FILES.hosts));
49442
+ const unbound = io.read((0, import_node_path37.join)(stateDir, RESOLVER_FILES.unbound));
49367
49443
  console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
49368
49444
  for (const r of ["dnsmasq", "unbound"]) {
49369
49445
  console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
@@ -49375,11 +49451,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
49375
49451
  // src/commands/feeds.ts
49376
49452
  async function loadSet() {
49377
49453
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
49378
- const path2 = (0, import_node_path37.join)(dir, "threat-feeds.json");
49454
+ const path2 = (0, import_node_path38.join)(dir, "threat-feeds.json");
49379
49455
  const set = readFeedCache(path2);
49380
49456
  if (set) return { set, from: path2 };
49381
49457
  }
49382
- const settings = threatFeedSettings(loadConfig((0, import_node_path37.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49458
+ const settings = threatFeedSettings(loadConfig((0, import_node_path38.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49383
49459
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
49384
49460
  }
49385
49461
  async function feedsCommand(action, value, opts) {
@@ -49423,14 +49499,14 @@ async function feedsCommand(action, value, opts) {
49423
49499
  }
49424
49500
 
49425
49501
  // src/commands/reputation.ts
49426
- var import_node_os14 = require("os");
49427
- var import_node_fs50 = require("fs");
49428
- var import_node_path38 = require("path");
49429
- var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49430
- var CONFIG_PATH3 = (0, import_node_path38.join)((0, import_node_os14.homedir)(), ".threatcrush", "config.json");
49502
+ var import_node_os15 = require("os");
49503
+ var import_node_fs51 = require("fs");
49504
+ var import_node_path39 = require("path");
49505
+ var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49506
+ var CONFIG_PATH4 = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49431
49507
  function readConfig3() {
49432
49508
  try {
49433
- return JSON.parse((0, import_node_fs50.readFileSync)(CONFIG_PATH3, "utf-8"));
49509
+ return JSON.parse((0, import_node_fs51.readFileSync)(CONFIG_PATH4, "utf-8"));
49434
49510
  } catch {
49435
49511
  return {};
49436
49512
  }
@@ -49486,7 +49562,7 @@ async function reputationLookupCommand(indicators, opts) {
49486
49562
  const org = opts.org ?? auth.orgId;
49487
49563
  let reports;
49488
49564
  if (indicators.length === 1) {
49489
- const url = `${API_URL6}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
49565
+ const url = `${API_URL7}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
49490
49566
  const res = await fetch(url, { headers: auth.headers });
49491
49567
  const body = await res.json().catch(() => ({}));
49492
49568
  if (!res.ok) {
@@ -49497,7 +49573,7 @@ async function reputationLookupCommand(indicators, opts) {
49497
49573
  }
49498
49574
  reports = [body];
49499
49575
  } else {
49500
- const res = await fetch(`${API_URL6}/api/v1/reputation/bulk`, {
49576
+ const res = await fetch(`${API_URL7}/api/v1/reputation/bulk`, {
49501
49577
  method: "POST",
49502
49578
  headers: { ...auth.headers, "Content-Type": "application/json" },
49503
49579
  body: JSON.stringify({ indicators, org: org ?? void 0 })
@@ -49539,7 +49615,7 @@ async function reputationWatchCommand(action, indicator, opts) {
49539
49615
  process.exitCode = 2;
49540
49616
  return;
49541
49617
  }
49542
- res = await fetch(`${API_URL6}/api/v1/reputation/watches`, {
49618
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches`, {
49543
49619
  method: "POST",
49544
49620
  headers: { ...auth.headers, "Content-Type": "application/json" },
49545
49621
  body: JSON.stringify({ indicator, note: opts.note, destination_id: opts.destination, org: org ?? void 0 })
@@ -49550,12 +49626,12 @@ async function reputationWatchCommand(action, indicator, opts) {
49550
49626
  process.exitCode = 2;
49551
49627
  return;
49552
49628
  }
49553
- res = await fetch(`${API_URL6}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
49629
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
49554
49630
  method: "DELETE",
49555
49631
  headers: auth.headers
49556
49632
  });
49557
49633
  } else {
49558
- res = await fetch(`${API_URL6}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
49634
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
49559
49635
  }
49560
49636
  const body = await res.json().catch(() => ({}));
49561
49637
  if (!res.ok) {
@@ -49589,7 +49665,7 @@ async function reputationSubscribeCommand(opts) {
49589
49665
  process.exitCode = 2;
49590
49666
  return;
49591
49667
  }
49592
- const res = await fetch(`${API_URL6}/api/v1/reputation/subscribe`, {
49668
+ const res = await fetch(`${API_URL7}/api/v1/reputation/subscribe`, {
49593
49669
  method: "POST",
49594
49670
  headers: { ...auth.headers, "Content-Type": "application/json" },
49595
49671
  body: JSON.stringify({
@@ -49618,7 +49694,7 @@ async function reputationSubscribeCommand(opts) {
49618
49694
  }
49619
49695
 
49620
49696
  // src/commands/privileged.ts
49621
- var import_node_fs51 = require("fs");
49697
+ var import_node_fs52 = require("fs");
49622
49698
  init_paths();
49623
49699
  var SEV2 = {
49624
49700
  critical: source_default.red.bold,
@@ -49631,19 +49707,19 @@ async function privilegedCommand(opts) {
49631
49707
  const snapshot = takeSnapshot({
49632
49708
  readFile: (p) => {
49633
49709
  try {
49634
- return (0, import_node_fs51.readFileSync)(p, "utf-8");
49710
+ return (0, import_node_fs52.readFileSync)(p, "utf-8");
49635
49711
  } catch {
49636
49712
  return null;
49637
49713
  }
49638
49714
  },
49639
49715
  readDir: (p) => {
49640
49716
  try {
49641
- return (0, import_node_fs51.readdirSync)(p);
49717
+ return (0, import_node_fs52.readdirSync)(p);
49642
49718
  } catch {
49643
49719
  return null;
49644
49720
  }
49645
49721
  },
49646
- exists: (p) => (0, import_node_fs51.existsSync)(p)
49722
+ exists: (p) => (0, import_node_fs52.existsSync)(p)
49647
49723
  });
49648
49724
  let events = [];
49649
49725
  let ledgerNote = "";
@@ -49825,7 +49901,7 @@ async function allowlistCommand(opts) {
49825
49901
  }
49826
49902
 
49827
49903
  // src/commands/abuse.ts
49828
- var import_node_fs52 = require("fs");
49904
+ var import_node_fs53 = require("fs");
49829
49905
  init_paths();
49830
49906
  function rows(records) {
49831
49907
  if (records.length === 0) {
@@ -49885,7 +49961,7 @@ function abuseRetractCommand(id, opts = {}) {
49885
49961
  );
49886
49962
  }
49887
49963
  function abuseStatusCommand(opts = {}) {
49888
- const config = loadConfig((0, import_node_fs52.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
49964
+ const config = loadConfig((0, import_node_fs53.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
49889
49965
  const cfg = resolveConfig(config.abuse_reporter);
49890
49966
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
49891
49967
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -50015,6 +50091,45 @@ function shadowedUpdateWarning(latest, active2, activePath) {
50015
50091
 
50016
50092
  // src/index.ts
50017
50093
  init_ipc_client();
50094
+
50095
+ // src/core/user-agent.ts
50096
+ init_cli_config();
50097
+ var USER_AGENT = `threatcrush/${PKG_VERSION} (node ${process.version}; ${process.platform})`;
50098
+ function isOurHost(url, api2 = apiUrl()) {
50099
+ let host;
50100
+ try {
50101
+ host = new URL(url).hostname.toLowerCase();
50102
+ } catch {
50103
+ return false;
50104
+ }
50105
+ let apiHost = "";
50106
+ try {
50107
+ apiHost = new URL(api2).hostname.toLowerCase();
50108
+ } catch {
50109
+ }
50110
+ return host === apiHost || host === "threatcrush.com" || host.endsWith(".threatcrush.com");
50111
+ }
50112
+ function urlOf(input) {
50113
+ if (typeof input === "string") return input;
50114
+ if (input instanceof URL) return input.href;
50115
+ return input.url;
50116
+ }
50117
+ function installUserAgent(target = globalThis) {
50118
+ const base = target.fetch;
50119
+ if (!base || base.__threatcrushUA) return;
50120
+ const wrapped = ((input, init) => {
50121
+ if (!isOurHost(urlOf(input))) return base(input, init);
50122
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
50123
+ if (headers.has("user-agent")) return base(input, init);
50124
+ headers.set("user-agent", USER_AGENT);
50125
+ return base(input, { ...init, headers });
50126
+ });
50127
+ wrapped.__threatcrushUA = true;
50128
+ target.fetch = wrapped;
50129
+ }
50130
+
50131
+ // src/index.ts
50132
+ installUserAgent();
50018
50133
  var LOGO2 = `
50019
50134
  ${source_default.green(" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557")}
50020
50135
  ${source_default.green(" \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D")}
@@ -50024,10 +50139,10 @@ ${source_default.green(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u25
50024
50139
  ${source_default.green(" \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D")}
50025
50140
  ${source_default.dim(" C R U S H")}
50026
50141
  `;
50027
- var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50142
+ var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50028
50143
  var PKG_NAME2 = "@profullstack/threatcrush";
50029
50144
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
50030
- var INSTALL_CONFIG_PATH = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "install.json");
50145
+ var INSTALL_CONFIG_PATH = (0, import_node_path40.join)((0, import_node_os16.homedir)(), ".threatcrush", "install.json");
50031
50146
  function detectPackageManager() {
50032
50147
  try {
50033
50148
  const npmGlobal = (0, import_node_child_process23.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -50053,7 +50168,7 @@ function detectPackageManager() {
50053
50168
  }
50054
50169
  function readInstallConfig() {
50055
50170
  try {
50056
- return JSON.parse((0, import_node_fs53.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50171
+ return JSON.parse((0, import_node_fs54.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50057
50172
  } catch {
50058
50173
  return {};
50059
50174
  }
@@ -50393,7 +50508,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
50393
50508
  program2.command("logs").description("Tail daemon logs").action(async () => {
50394
50509
  console.log(LOGO2);
50395
50510
  const logPath2 = PATHS.logFile;
50396
- if (!(0, import_node_fs53.existsSync)(logPath2)) {
50511
+ if (!(0, import_node_fs54.existsSync)(logPath2)) {
50397
50512
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
50398
50513
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
50399
50514
  return;
@@ -50514,7 +50629,7 @@ var storeCmd = program2.command("store").description("Browse the module marketpl
50514
50629
  console.log(source_default.green(" Module Marketplace\n"));
50515
50630
  console.log(source_default.dim(" Loading available modules..."));
50516
50631
  try {
50517
- const res = await fetch(`${API_URL7}/api/modules`);
50632
+ const res = await fetch(`${API_URL8}/api/modules`);
50518
50633
  if (!res.ok) {
50519
50634
  console.log(source_default.red(` \u2717 Failed to load modules: ${res.statusText}
50520
50635
  `));
@@ -50541,7 +50656,7 @@ storeCmd.command("search <query>").description("Search for modules in the store"
50541
50656
  console.log(source_default.green(` Searching for "${query}"...
50542
50657
  `));
50543
50658
  try {
50544
- const res = await fetch(`${API_URL7}/api/modules?q=${encodeURIComponent(query)}`);
50659
+ const res = await fetch(`${API_URL8}/api/modules?q=${encodeURIComponent(query)}`);
50545
50660
  if (!res.ok) {
50546
50661
  console.log(source_default.red(` \u2717 Search failed: ${res.statusText}
50547
50662
  `));
@@ -50566,10 +50681,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
50566
50681
  });
50567
50682
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
50568
50683
  console.log(LOGO2);
50569
- const configPath = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
50684
+ const configPath = (0, import_node_path40.join)((0, import_node_os16.homedir)(), ".threatcrush", "config.json");
50570
50685
  let email = "";
50571
50686
  try {
50572
- const config = JSON.parse((0, import_node_fs53.readFileSync)(configPath, "utf-8"));
50687
+ const config = JSON.parse((0, import_node_fs54.readFileSync)(configPath, "utf-8"));
50573
50688
  email = config.email || "";
50574
50689
  } catch {
50575
50690
  }
@@ -50586,9 +50701,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50586
50701
  return;
50587
50702
  }
50588
50703
  try {
50589
- const dir = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush");
50590
- if (!(0, import_node_fs53.existsSync)(dir)) (0, import_node_fs53.mkdirSync)(dir, { recursive: true });
50591
- (0, import_node_fs53.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
50704
+ const dir = (0, import_node_path40.join)((0, import_node_os16.homedir)(), ".threatcrush");
50705
+ if (!(0, import_node_fs54.existsSync)(dir)) (0, import_node_fs54.mkdirSync)(dir, { recursive: true });
50706
+ (0, import_node_fs54.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
50592
50707
  console.log(source_default.dim(` Saved email to ${configPath}`));
50593
50708
  } catch {
50594
50709
  }
@@ -50598,7 +50713,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50598
50713
  `));
50599
50714
  let meta;
50600
50715
  try {
50601
- const res = await fetch(`${API_URL7}/api/modules/fetch-meta`, {
50716
+ const res = await fetch(`${API_URL8}/api/modules/fetch-meta`, {
50602
50717
  method: "POST",
50603
50718
  headers: { "Content-Type": "application/json" },
50604
50719
  body: JSON.stringify({ url, git_url: url })
@@ -50644,7 +50759,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50644
50759
  }
50645
50760
  console.log(source_default.dim("\n Publishing..."));
50646
50761
  try {
50647
- const res = await fetch(`${API_URL7}/api/modules`, {
50762
+ const res = await fetch(`${API_URL8}/api/modules`, {
50648
50763
  method: "POST",
50649
50764
  headers: { "Content-Type": "application/json" },
50650
50765
  body: JSON.stringify({
@@ -50665,7 +50780,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50665
50780
  const slug = mod?.slug || meta.name;
50666
50781
  console.log(source_default.green(`
50667
50782
  \u2713 Module submitted for review. It appears in the store once approved.`));
50668
- console.log(source_default.dim(` ${API_URL7}/store/${slug}
50783
+ console.log(source_default.dim(` ${API_URL8}/store/${slug}
50669
50784
  `));
50670
50785
  } catch (err) {
50671
50786
  console.log(source_default.red(`
@@ -50736,6 +50851,12 @@ propsCmd.command("runs").alias("history").description("Show recent scan/pentest
50736
50851
  propsCmd.command("import <file>").description("Bulk-import properties from a .json, .csv, or .tsv file").option("--org <slug>", "Organization slug").option("-n, --dry-run", "Preview without writing").action(async (file, opts) => {
50737
50852
  await propertiesImportCommand(file, { org: opts.org, dryRun: opts.dryRun });
50738
50853
  });
50854
+ program2.command("redeem").description("Redeem a ThreatCrush credit code into your credit balance (needs `threatcrush login`)").argument("<code>", "Credit code, e.g. CR-XXXX-XXXX-XXXX-XXXX").action(async (code) => {
50855
+ await redeemCommand(code);
50856
+ });
50857
+ program2.command("invites").description("Your invites (3 per account): list, create [note], accept <code>, revoke <id>").argument("[action]", "list | create | accept | revoke", "list").argument("[arg]", "note for create, code for accept, id for revoke").action(async (action, arg) => {
50858
+ await invitesCommand(action, arg);
50859
+ });
50739
50860
  program2.command("connect").description("Connect to a ThreatCrush server via SSH").argument("[target]", "Server name, user@hostname, or hostname").option("--org <slug>", "Organization slug").option("-u, --user <user>", "SSH username").option("-p, --port <port>", "SSH port", "22").option("-i, --identity <path>", "SSH identity file").action(async (target, opts) => {
50740
50861
  await connectCommand({
50741
50862
  target,