@profullstack/threatcrush 0.13.31 → 0.13.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/daemon.js +313 -63
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +402 -150
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24745,9 +24745,9 @@ var source_default = chalk;
|
|
|
24745
24745
|
|
|
24746
24746
|
// src/index.ts
|
|
24747
24747
|
var import_readline = __toESM(require("readline"));
|
|
24748
|
-
var
|
|
24749
|
-
var
|
|
24750
|
-
var
|
|
24748
|
+
var import_node_child_process17 = require("child_process");
|
|
24749
|
+
var import_node_fs42 = require("fs");
|
|
24750
|
+
var import_node_path30 = require("path");
|
|
24751
24751
|
var import_node_os13 = require("os");
|
|
24752
24752
|
|
|
24753
24753
|
// src/commands/monitor.ts
|
|
@@ -31639,6 +31639,7 @@ function loadConfig(configPath) {
|
|
|
31639
31639
|
detection: parsed.detection,
|
|
31640
31640
|
cloud: parsed.cloud,
|
|
31641
31641
|
watchdog: parsed.watchdog,
|
|
31642
|
+
update: parsed.update,
|
|
31642
31643
|
storage: parsed.storage,
|
|
31643
31644
|
license: parsed.license
|
|
31644
31645
|
};
|
|
@@ -31672,7 +31673,8 @@ function generateDefaultConfig(detectedServices) {
|
|
|
31672
31673
|
modules: DEFAULT_CONFIG.modules,
|
|
31673
31674
|
// Written out so the opt-out is discoverable; these are also the defaults
|
|
31674
31675
|
// when the section is absent.
|
|
31675
|
-
cloud: { enabled: true, min_severity: "medium" }
|
|
31676
|
+
cloud: { enabled: true, min_severity: "medium" },
|
|
31677
|
+
update: { auto: true, interval: "6h", min_age: "2h" }
|
|
31676
31678
|
};
|
|
31677
31679
|
return import_toml.default.stringify(config);
|
|
31678
31680
|
}
|
|
@@ -39777,16 +39779,16 @@ async function sshConnect(options) {
|
|
|
39777
39779
|
}
|
|
39778
39780
|
|
|
39779
39781
|
// src/commands/daemon.ts
|
|
39780
|
-
var
|
|
39781
|
-
var import_node_fs35 = require("fs");
|
|
39782
|
-
var import_node_path26 = require("path");
|
|
39782
|
+
var import_node_child_process13 = require("child_process");
|
|
39783
39783
|
var import_node_fs36 = require("fs");
|
|
39784
|
+
var import_node_path27 = require("path");
|
|
39785
|
+
var import_node_fs37 = require("fs");
|
|
39784
39786
|
|
|
39785
39787
|
// src/daemon/index.ts
|
|
39786
|
-
var
|
|
39787
|
-
var
|
|
39788
|
+
var import_node_fs35 = require("fs");
|
|
39789
|
+
var import_node_child_process12 = require("child_process");
|
|
39788
39790
|
var import_node_os11 = require("os");
|
|
39789
|
-
var
|
|
39791
|
+
var import_node_path26 = require("path");
|
|
39790
39792
|
var import_node_util = require("util");
|
|
39791
39793
|
init_paths();
|
|
39792
39794
|
|
|
@@ -42341,6 +42343,242 @@ var RemediationConsumer = class {
|
|
|
42341
42343
|
}
|
|
42342
42344
|
};
|
|
42343
42345
|
|
|
42346
|
+
// src/daemon/workers/auto-update.ts
|
|
42347
|
+
var import_node_child_process9 = require("child_process");
|
|
42348
|
+
var import_node_fs30 = require("fs");
|
|
42349
|
+
var import_node_path22 = require("path");
|
|
42350
|
+
init_backoff();
|
|
42351
|
+
var PKG_NAME = "@profullstack/threatcrush";
|
|
42352
|
+
var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
|
|
42353
|
+
var DEFAULT_INTERVAL_MS = 6 * 36e5;
|
|
42354
|
+
var DEFAULT_MIN_AGE_MS = 2 * 36e5;
|
|
42355
|
+
var RETRY_AFTER_MS = 24 * 36e5;
|
|
42356
|
+
function isNewer(a, b) {
|
|
42357
|
+
const parse2 = (v) => {
|
|
42358
|
+
const [core, pre] = v.replace(/^v/, "").split("-", 2);
|
|
42359
|
+
return { nums: core.split(".").map((n) => Number.parseInt(n, 10) || 0), pre: pre ?? null };
|
|
42360
|
+
};
|
|
42361
|
+
const x = parse2(a);
|
|
42362
|
+
const y = parse2(b);
|
|
42363
|
+
for (let i = 0; i < 3; i++) {
|
|
42364
|
+
if ((x.nums[i] ?? 0) !== (y.nums[i] ?? 0)) return (x.nums[i] ?? 0) > (y.nums[i] ?? 0);
|
|
42365
|
+
}
|
|
42366
|
+
if (x.pre === y.pre) return false;
|
|
42367
|
+
if (x.pre === null) return true;
|
|
42368
|
+
if (y.pre === null) return false;
|
|
42369
|
+
return x.pre > y.pre;
|
|
42370
|
+
}
|
|
42371
|
+
function pickUpdate(doc, current, opts) {
|
|
42372
|
+
const latest = doc["dist-tags"]?.latest;
|
|
42373
|
+
if (!latest) return { version: null, reason: "registry has no latest tag" };
|
|
42374
|
+
if (!isNewer(latest, current)) return { version: null, reason: `up to date (${current})` };
|
|
42375
|
+
const major = (v) => Number.parseInt(v.replace(/^v/, ""), 10);
|
|
42376
|
+
if (!opts.allowMajor && major(latest) !== major(current)) {
|
|
42377
|
+
return { version: null, reason: `${latest} is a new major; set [update] allow_major = true to take it` };
|
|
42378
|
+
}
|
|
42379
|
+
const published = Date.parse(doc.time?.[latest] ?? "");
|
|
42380
|
+
if (!Number.isFinite(published)) return { version: null, reason: `no publish time for ${latest}` };
|
|
42381
|
+
if (opts.now - published < opts.minAgeMs) {
|
|
42382
|
+
return { version: null, reason: `${latest} is younger than min_age; waiting` };
|
|
42383
|
+
}
|
|
42384
|
+
return { version: latest };
|
|
42385
|
+
}
|
|
42386
|
+
function installPlan(opts) {
|
|
42387
|
+
const expected = `${import_node_path22.sep}lib${import_node_path22.sep}node_modules${import_node_path22.sep}@profullstack${import_node_path22.sep}threatcrush`;
|
|
42388
|
+
if (!opts.pkgRoot.endsWith(expected)) {
|
|
42389
|
+
return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
|
|
42390
|
+
}
|
|
42391
|
+
const nodeBin = (0, import_node_path22.dirname)(opts.execPath);
|
|
42392
|
+
const npm = (0, import_node_path22.join)(nodeBin, "npm");
|
|
42393
|
+
if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
|
|
42394
|
+
if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
|
|
42395
|
+
const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
|
|
42396
|
+
const path = `${nodeBin}:/usr/local/bin:/usr/bin:/bin`;
|
|
42397
|
+
if (opts.underSystemd && opts.uid === 0) {
|
|
42398
|
+
return {
|
|
42399
|
+
kind: "run",
|
|
42400
|
+
argv: [
|
|
42401
|
+
"systemd-run",
|
|
42402
|
+
"--wait",
|
|
42403
|
+
"--collect",
|
|
42404
|
+
"--quiet",
|
|
42405
|
+
`--unit=threatcrush-autoupdate-${opts.version.replace(/[^0-9A-Za-z]/g, "-")}`,
|
|
42406
|
+
`--uid=${opts.owner.uid}`,
|
|
42407
|
+
`--gid=${opts.owner.gid}`,
|
|
42408
|
+
`--setenv=HOME=${opts.owner.home}`,
|
|
42409
|
+
`--setenv=PATH=${path}`,
|
|
42410
|
+
...npmArgs
|
|
42411
|
+
]
|
|
42412
|
+
};
|
|
42413
|
+
}
|
|
42414
|
+
if (opts.uid === opts.owner.uid) {
|
|
42415
|
+
return { kind: "run", argv: npmArgs, env: { PATH: path } };
|
|
42416
|
+
}
|
|
42417
|
+
return {
|
|
42418
|
+
kind: "unsupported",
|
|
42419
|
+
reason: `install is owned by uid ${opts.owner.uid}, daemon runs as ${opts.uid}; run \`threatcrush update\` as that user`
|
|
42420
|
+
};
|
|
42421
|
+
}
|
|
42422
|
+
function ownerOf(path, passwd = "/etc/passwd") {
|
|
42423
|
+
try {
|
|
42424
|
+
const st = (0, import_node_fs30.statSync)(path);
|
|
42425
|
+
let home = st.uid === 0 ? "/root" : "";
|
|
42426
|
+
try {
|
|
42427
|
+
for (const line2 of (0, import_node_fs30.readFileSync)(passwd, "utf8").split("\n")) {
|
|
42428
|
+
const f = line2.split(":");
|
|
42429
|
+
if (Number(f[2]) === st.uid && f[5]) home = f[5];
|
|
42430
|
+
}
|
|
42431
|
+
} catch {
|
|
42432
|
+
}
|
|
42433
|
+
return home ? { uid: st.uid, gid: st.gid, home } : null;
|
|
42434
|
+
} catch {
|
|
42435
|
+
return null;
|
|
42436
|
+
}
|
|
42437
|
+
}
|
|
42438
|
+
function updateSettings(section, env2 = process.env) {
|
|
42439
|
+
const interval = parseDuration(section?.interval);
|
|
42440
|
+
const minAge = parseDuration(section?.min_age);
|
|
42441
|
+
return {
|
|
42442
|
+
enabled: section?.auto !== false && env2.THREATCRUSH_AUTO_UPDATE !== "0",
|
|
42443
|
+
intervalMs: interval ? Math.max(15 * 60, interval) * 1e3 : DEFAULT_INTERVAL_MS,
|
|
42444
|
+
minAgeMs: minAge !== null ? minAge * 1e3 : DEFAULT_MIN_AGE_MS,
|
|
42445
|
+
allowMajor: section?.allow_major === true
|
|
42446
|
+
};
|
|
42447
|
+
}
|
|
42448
|
+
function defaultRun(argv, env2) {
|
|
42449
|
+
return new Promise((resolve6) => {
|
|
42450
|
+
const child = (0, import_node_child_process9.spawn)(argv[0], argv.slice(1), {
|
|
42451
|
+
env: { ...process.env, ...env2 },
|
|
42452
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
42453
|
+
});
|
|
42454
|
+
let output = "";
|
|
42455
|
+
const keep = (b) => {
|
|
42456
|
+
output = (output + b.toString()).slice(-4e3);
|
|
42457
|
+
};
|
|
42458
|
+
child.stdout?.on("data", keep);
|
|
42459
|
+
child.stderr?.on("data", keep);
|
|
42460
|
+
child.on("error", (err) => resolve6({ code: -1, output: err.message }));
|
|
42461
|
+
child.on("close", (code) => resolve6({ code: code ?? -1, output }));
|
|
42462
|
+
});
|
|
42463
|
+
}
|
|
42464
|
+
var AutoUpdate = class {
|
|
42465
|
+
constructor(opts) {
|
|
42466
|
+
this.opts = opts;
|
|
42467
|
+
this.fetchImpl = opts.fetchImpl ?? fetch;
|
|
42468
|
+
this.run = opts.run ?? defaultRun;
|
|
42469
|
+
this.now = opts.now ?? Date.now;
|
|
42470
|
+
this.random = opts.random ?? Math.random;
|
|
42471
|
+
}
|
|
42472
|
+
opts;
|
|
42473
|
+
timer = null;
|
|
42474
|
+
busy = false;
|
|
42475
|
+
fetchImpl;
|
|
42476
|
+
run;
|
|
42477
|
+
now;
|
|
42478
|
+
random;
|
|
42479
|
+
start() {
|
|
42480
|
+
if (!this.opts.settings.enabled) {
|
|
42481
|
+
this.opts.log("[update] auto-update off ([update] auto = false or THREATCRUSH_AUTO_UPDATE=0)");
|
|
42482
|
+
return;
|
|
42483
|
+
}
|
|
42484
|
+
this.schedule(10 * 6e4 + this.random() * 30 * 6e4);
|
|
42485
|
+
}
|
|
42486
|
+
stop() {
|
|
42487
|
+
if (this.timer) clearTimeout(this.timer);
|
|
42488
|
+
this.timer = null;
|
|
42489
|
+
}
|
|
42490
|
+
schedule(ms) {
|
|
42491
|
+
this.timer = setTimeout(() => {
|
|
42492
|
+
void this.check().finally(() => {
|
|
42493
|
+
if (this.timer !== null) this.schedule(this.opts.settings.intervalMs + this.random() * 36e5);
|
|
42494
|
+
});
|
|
42495
|
+
}, ms);
|
|
42496
|
+
this.timer.unref?.();
|
|
42497
|
+
}
|
|
42498
|
+
/** One check; returns what it did, for logs and tests. */
|
|
42499
|
+
async check() {
|
|
42500
|
+
if (this.busy) return "busy";
|
|
42501
|
+
this.busy = true;
|
|
42502
|
+
try {
|
|
42503
|
+
let doc;
|
|
42504
|
+
try {
|
|
42505
|
+
const res = await this.fetchImpl(REGISTRY, {
|
|
42506
|
+
headers: { accept: "application/json" },
|
|
42507
|
+
signal: AbortSignal.timeout(2e4)
|
|
42508
|
+
});
|
|
42509
|
+
if (!res.ok) return this.note(`registry answered ${res.status}`);
|
|
42510
|
+
doc = await res.json();
|
|
42511
|
+
} catch (err) {
|
|
42512
|
+
return this.note(`registry unreachable: ${err.message}`);
|
|
42513
|
+
}
|
|
42514
|
+
const pick = pickUpdate(doc, this.opts.version, {
|
|
42515
|
+
allowMajor: this.opts.settings.allowMajor,
|
|
42516
|
+
minAgeMs: this.opts.settings.minAgeMs,
|
|
42517
|
+
now: this.now()
|
|
42518
|
+
});
|
|
42519
|
+
if (pick.version === null) return this.note(pick.reason, false);
|
|
42520
|
+
const target = pick.version;
|
|
42521
|
+
const last = this.lastAttempt();
|
|
42522
|
+
if (last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
|
|
42523
|
+
return this.note(`${target} was tried at ${new Date(last.at).toISOString()} and did not take; retrying after a day`);
|
|
42524
|
+
}
|
|
42525
|
+
const plan = installPlan({
|
|
42526
|
+
version: target,
|
|
42527
|
+
pkgRoot: this.opts.pkgRoot,
|
|
42528
|
+
execPath: process.execPath,
|
|
42529
|
+
uid: process.getuid?.() ?? -1,
|
|
42530
|
+
owner: ownerOf(this.opts.pkgRoot),
|
|
42531
|
+
underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
|
|
42532
|
+
npmExists: import_node_fs30.existsSync
|
|
42533
|
+
});
|
|
42534
|
+
if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
|
|
42535
|
+
this.recordAttempt(target);
|
|
42536
|
+
this.event(`updating ThreatCrush ${this.opts.version} \u2192 ${target}`, { from: this.opts.version, to: target });
|
|
42537
|
+
this.opts.log(`[update] installing ${target}: ${plan.argv.join(" ")}`);
|
|
42538
|
+
const { code, output } = await this.run(plan.argv, plan.env);
|
|
42539
|
+
if (code !== 0) {
|
|
42540
|
+
const tail = output.trim().split("\n").slice(-3).join(" | ");
|
|
42541
|
+
this.event(`auto-update to ${target} failed (exit ${code})`, { to: target, code, output: tail });
|
|
42542
|
+
return this.note(`install of ${target} failed (exit ${code}): ${tail}`);
|
|
42543
|
+
}
|
|
42544
|
+
this.opts.log(`[update] ${target} installed; restarting onto it`);
|
|
42545
|
+
this.opts.restartDaemon();
|
|
42546
|
+
return `updated to ${target}`;
|
|
42547
|
+
} finally {
|
|
42548
|
+
this.busy = false;
|
|
42549
|
+
}
|
|
42550
|
+
}
|
|
42551
|
+
note(line2, log = true) {
|
|
42552
|
+
if (log) this.opts.log(`[update] ${line2}`);
|
|
42553
|
+
return line2;
|
|
42554
|
+
}
|
|
42555
|
+
event(message, details) {
|
|
42556
|
+
this.opts.bus.publish({
|
|
42557
|
+
timestamp: new Date(this.now()),
|
|
42558
|
+
module: "auto-update",
|
|
42559
|
+
category: "system",
|
|
42560
|
+
severity: "info",
|
|
42561
|
+
message,
|
|
42562
|
+
details
|
|
42563
|
+
});
|
|
42564
|
+
}
|
|
42565
|
+
lastAttempt() {
|
|
42566
|
+
try {
|
|
42567
|
+
const v = JSON.parse((0, import_node_fs30.readFileSync)(this.opts.statePath, "utf8"));
|
|
42568
|
+
return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
|
|
42569
|
+
} catch {
|
|
42570
|
+
return null;
|
|
42571
|
+
}
|
|
42572
|
+
}
|
|
42573
|
+
recordAttempt(version) {
|
|
42574
|
+
try {
|
|
42575
|
+
(0, import_node_fs30.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
|
|
42576
|
+
} catch (err) {
|
|
42577
|
+
this.opts.log(`[update] could not record attempt: ${err.message}`);
|
|
42578
|
+
}
|
|
42579
|
+
}
|
|
42580
|
+
};
|
|
42581
|
+
|
|
42344
42582
|
// src/daemon/rules/engine.ts
|
|
42345
42583
|
var MAX_WINDOW_ENTRIES = 1e3;
|
|
42346
42584
|
function live(window) {
|
|
@@ -42502,8 +42740,8 @@ var RuleEngine = class {
|
|
|
42502
42740
|
};
|
|
42503
42741
|
|
|
42504
42742
|
// src/daemon/rules/loader.ts
|
|
42505
|
-
var
|
|
42506
|
-
var
|
|
42743
|
+
var import_node_fs31 = require("fs");
|
|
42744
|
+
var import_node_path23 = require("path");
|
|
42507
42745
|
|
|
42508
42746
|
// src/daemon/rules/default-rules.ts
|
|
42509
42747
|
var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
|
|
@@ -42904,11 +43142,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
|
|
|
42904
43142
|
function loadAllRules(customDir) {
|
|
42905
43143
|
const rules = [...DEFAULT_RULES];
|
|
42906
43144
|
const dir = customDir || RULES_DIR;
|
|
42907
|
-
if ((0,
|
|
42908
|
-
const files = (0,
|
|
43145
|
+
if ((0, import_node_fs31.existsSync)(dir)) {
|
|
43146
|
+
const files = (0, import_node_fs31.readdirSync)(dir).filter((f) => f.endsWith(".json"));
|
|
42909
43147
|
for (const file of files) {
|
|
42910
43148
|
try {
|
|
42911
|
-
const raw = (0,
|
|
43149
|
+
const raw = (0, import_node_fs31.readFileSync)((0, import_node_path23.join)(dir, file), "utf-8");
|
|
42912
43150
|
const parsed = JSON.parse(raw);
|
|
42913
43151
|
const customRules = Array.isArray(parsed) ? parsed : [parsed];
|
|
42914
43152
|
for (const rule of customRules) {
|
|
@@ -42939,9 +43177,9 @@ function loadAllRules(customDir) {
|
|
|
42939
43177
|
}
|
|
42940
43178
|
|
|
42941
43179
|
// src/daemon/firewall/adapters.ts
|
|
42942
|
-
var
|
|
42943
|
-
var
|
|
42944
|
-
var
|
|
43180
|
+
var import_node_child_process10 = require("child_process");
|
|
43181
|
+
var import_node_fs32 = require("fs");
|
|
43182
|
+
var import_node_path24 = require("path");
|
|
42945
43183
|
var import_node_net8 = require("net");
|
|
42946
43184
|
function assertValidFirewallIp(ip) {
|
|
42947
43185
|
if ((0, import_node_net8.isIP)(ip) !== 4) {
|
|
@@ -42954,9 +43192,9 @@ function assertBannableIp(ip) {
|
|
|
42954
43192
|
}
|
|
42955
43193
|
}
|
|
42956
43194
|
function writeIfAbsent(path, contents) {
|
|
42957
|
-
(0,
|
|
43195
|
+
(0, import_node_fs32.mkdirSync)((0, import_node_path24.dirname)(path), { recursive: true });
|
|
42958
43196
|
try {
|
|
42959
|
-
(0,
|
|
43197
|
+
(0, import_node_fs32.writeFileSync)(path, contents, { flag: "wx" });
|
|
42960
43198
|
} catch (err) {
|
|
42961
43199
|
if (err.code !== "EEXIST") throw err;
|
|
42962
43200
|
}
|
|
@@ -42975,11 +43213,11 @@ var Fail2banAdapter = class {
|
|
|
42975
43213
|
enforces = true;
|
|
42976
43214
|
jailReady = false;
|
|
42977
43215
|
isAvailable() {
|
|
42978
|
-
const result = (0,
|
|
43216
|
+
const result = (0, import_node_child_process10.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
|
|
42979
43217
|
return result.status === 0;
|
|
42980
43218
|
}
|
|
42981
43219
|
client(args) {
|
|
42982
|
-
return (0,
|
|
43220
|
+
return (0, import_node_child_process10.execFileSync)("fail2ban-client", args, {
|
|
42983
43221
|
encoding: "utf-8",
|
|
42984
43222
|
stdio: ["ignore", "pipe", "pipe"]
|
|
42985
43223
|
});
|
|
@@ -43075,35 +43313,35 @@ var NftablesAdapter = class {
|
|
|
43075
43313
|
table = "threatcrush";
|
|
43076
43314
|
set = "blocklist";
|
|
43077
43315
|
isAvailable() {
|
|
43078
|
-
const result = (0,
|
|
43316
|
+
const result = (0, import_node_child_process10.spawnSync)("nft", ["--version"], { stdio: "pipe" });
|
|
43079
43317
|
return result.status === 0;
|
|
43080
43318
|
}
|
|
43081
43319
|
ensureSetup() {
|
|
43082
43320
|
try {
|
|
43083
|
-
(0,
|
|
43321
|
+
(0, import_node_child_process10.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
|
|
43084
43322
|
} catch {
|
|
43085
|
-
(0,
|
|
43086
|
-
(0,
|
|
43087
|
-
(0,
|
|
43088
|
-
(0,
|
|
43323
|
+
(0, import_node_child_process10.execSync)(`nft add table inet ${this.table}`);
|
|
43324
|
+
(0, import_node_child_process10.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
|
|
43325
|
+
(0, import_node_child_process10.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
|
|
43326
|
+
(0, import_node_child_process10.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
|
|
43089
43327
|
}
|
|
43090
43328
|
}
|
|
43091
43329
|
async block(ip) {
|
|
43092
43330
|
assertValidFirewallIp(ip);
|
|
43093
43331
|
this.ensureSetup();
|
|
43094
|
-
(0,
|
|
43332
|
+
(0, import_node_child_process10.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
43095
43333
|
}
|
|
43096
43334
|
async unblock(ip) {
|
|
43097
43335
|
assertValidFirewallIp(ip);
|
|
43098
43336
|
try {
|
|
43099
|
-
(0,
|
|
43337
|
+
(0, import_node_child_process10.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
|
|
43100
43338
|
} catch {
|
|
43101
43339
|
}
|
|
43102
43340
|
}
|
|
43103
43341
|
async isBlocked(ip) {
|
|
43104
43342
|
assertValidFirewallIp(ip);
|
|
43105
43343
|
try {
|
|
43106
|
-
const output = (0,
|
|
43344
|
+
const output = (0, import_node_child_process10.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
43107
43345
|
return output.includes(ip);
|
|
43108
43346
|
} catch {
|
|
43109
43347
|
return false;
|
|
@@ -43111,7 +43349,7 @@ var NftablesAdapter = class {
|
|
|
43111
43349
|
}
|
|
43112
43350
|
async listBlocked() {
|
|
43113
43351
|
try {
|
|
43114
|
-
const output = (0,
|
|
43352
|
+
const output = (0, import_node_child_process10.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
|
|
43115
43353
|
const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
|
|
43116
43354
|
if (!match) return [];
|
|
43117
43355
|
return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
|
|
@@ -43124,34 +43362,34 @@ var IptablesAdapter = class {
|
|
|
43124
43362
|
name = "iptables";
|
|
43125
43363
|
chain = "THREATCRUSH";
|
|
43126
43364
|
isAvailable() {
|
|
43127
|
-
const result = (0,
|
|
43365
|
+
const result = (0, import_node_child_process10.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
|
|
43128
43366
|
return result.status === 0;
|
|
43129
43367
|
}
|
|
43130
43368
|
ensureChain() {
|
|
43131
43369
|
try {
|
|
43132
|
-
(0,
|
|
43370
|
+
(0, import_node_child_process10.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
|
|
43133
43371
|
} catch {
|
|
43134
|
-
(0,
|
|
43135
|
-
(0,
|
|
43372
|
+
(0, import_node_child_process10.execSync)(`iptables -N ${this.chain}`);
|
|
43373
|
+
(0, import_node_child_process10.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
|
|
43136
43374
|
}
|
|
43137
43375
|
}
|
|
43138
43376
|
async block(ip) {
|
|
43139
43377
|
assertValidFirewallIp(ip);
|
|
43140
43378
|
this.ensureChain();
|
|
43141
43379
|
if (await this.isBlocked(ip)) return;
|
|
43142
|
-
(0,
|
|
43380
|
+
(0, import_node_child_process10.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
|
|
43143
43381
|
}
|
|
43144
43382
|
async unblock(ip) {
|
|
43145
43383
|
assertValidFirewallIp(ip);
|
|
43146
43384
|
try {
|
|
43147
|
-
(0,
|
|
43385
|
+
(0, import_node_child_process10.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
|
|
43148
43386
|
} catch {
|
|
43149
43387
|
}
|
|
43150
43388
|
}
|
|
43151
43389
|
async isBlocked(ip) {
|
|
43152
43390
|
assertValidFirewallIp(ip);
|
|
43153
43391
|
try {
|
|
43154
|
-
const output = (0,
|
|
43392
|
+
const output = (0, import_node_child_process10.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
43155
43393
|
return output.includes(ip);
|
|
43156
43394
|
} catch {
|
|
43157
43395
|
return false;
|
|
@@ -43159,7 +43397,7 @@ var IptablesAdapter = class {
|
|
|
43159
43397
|
}
|
|
43160
43398
|
async listBlocked() {
|
|
43161
43399
|
try {
|
|
43162
|
-
const output = (0,
|
|
43400
|
+
const output = (0, import_node_child_process10.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
|
|
43163
43401
|
const ips = [];
|
|
43164
43402
|
for (const line2 of output.split("\n")) {
|
|
43165
43403
|
const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
|
|
@@ -43215,7 +43453,7 @@ function detectFirewallAdapter(backend = "auto") {
|
|
|
43215
43453
|
}
|
|
43216
43454
|
|
|
43217
43455
|
// src/daemon/firewall/remediation.ts
|
|
43218
|
-
var
|
|
43456
|
+
var import_node_fs33 = require("fs");
|
|
43219
43457
|
var import_node_net9 = require("net");
|
|
43220
43458
|
init_paths();
|
|
43221
43459
|
init_backoff();
|
|
@@ -43629,7 +43867,7 @@ var RemediationManager = class {
|
|
|
43629
43867
|
}
|
|
43630
43868
|
logLine(line2) {
|
|
43631
43869
|
try {
|
|
43632
|
-
(0,
|
|
43870
|
+
(0, import_node_fs33.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
43633
43871
|
`);
|
|
43634
43872
|
} catch {
|
|
43635
43873
|
}
|
|
@@ -43667,19 +43905,19 @@ function remediationSettings(section) {
|
|
|
43667
43905
|
init_backoff();
|
|
43668
43906
|
|
|
43669
43907
|
// src/daemon/watchdog-service.ts
|
|
43670
|
-
var
|
|
43671
|
-
var
|
|
43908
|
+
var import_node_fs34 = require("fs");
|
|
43909
|
+
var import_node_path25 = require("path");
|
|
43672
43910
|
function defaultShareGid() {
|
|
43673
43911
|
const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
|
|
43674
43912
|
if (!isRoot4) return void 0;
|
|
43675
43913
|
try {
|
|
43676
|
-
return (0,
|
|
43914
|
+
return (0, import_node_fs34.statSync)("/var/log/auth.log").gid;
|
|
43677
43915
|
} catch {
|
|
43678
43916
|
return void 0;
|
|
43679
43917
|
}
|
|
43680
43918
|
}
|
|
43681
43919
|
function startWatchdog(opts) {
|
|
43682
|
-
const dir = opts.config?.dir ?? (0,
|
|
43920
|
+
const dir = opts.config?.dir ?? (0, import_node_path25.join)(opts.stateDir, WATCHDOG_DIRNAME);
|
|
43683
43921
|
const base = { dir, logged: 0, answered: 0, errored: 0 };
|
|
43684
43922
|
if (opts.config?.enabled === false) {
|
|
43685
43923
|
opts.log("[watchdog] off ([watchdog] enabled = false)");
|
|
@@ -43773,7 +44011,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
|
|
|
43773
44011
|
}
|
|
43774
44012
|
|
|
43775
44013
|
// src/core/node-runtime.ts
|
|
43776
|
-
var
|
|
44014
|
+
var import_node_child_process11 = require("child_process");
|
|
43777
44015
|
var MIN_DAEMON_NODE_MAJOR = 22;
|
|
43778
44016
|
function nodeMajor(version) {
|
|
43779
44017
|
const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
|
|
@@ -43787,23 +44025,23 @@ function daemonNodeProblem(version) {
|
|
|
43787
44025
|
}
|
|
43788
44026
|
function versionOfNode(path) {
|
|
43789
44027
|
if (path === process.execPath) return process.versions.node;
|
|
43790
|
-
const res = (0,
|
|
44028
|
+
const res = (0, import_node_child_process11.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
|
|
43791
44029
|
return res.status === 0 ? res.stdout.trim() : null;
|
|
43792
44030
|
}
|
|
43793
44031
|
|
|
43794
44032
|
// src/daemon/index.ts
|
|
43795
44033
|
function readVersion2() {
|
|
43796
44034
|
try {
|
|
43797
|
-
const pkg = JSON.parse((0,
|
|
44035
|
+
const pkg = JSON.parse((0, import_node_fs35.readFileSync)((0, import_node_path26.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
43798
44036
|
return pkg.version || "0.0.0";
|
|
43799
44037
|
} catch {
|
|
43800
44038
|
return "0.0.0";
|
|
43801
44039
|
}
|
|
43802
44040
|
}
|
|
43803
44041
|
async function runHardeningChecks() {
|
|
43804
|
-
const { stdout } = await (0, import_node_util.promisify)(
|
|
44042
|
+
const { stdout } = await (0, import_node_util.promisify)(import_node_child_process12.execFile)(
|
|
43805
44043
|
process.execPath,
|
|
43806
|
-
[(0,
|
|
44044
|
+
[(0, import_node_path26.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
|
|
43807
44045
|
{ timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
|
|
43808
44046
|
);
|
|
43809
44047
|
const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
|
|
@@ -43811,7 +44049,7 @@ async function runHardeningChecks() {
|
|
|
43811
44049
|
}
|
|
43812
44050
|
function logLine(line2) {
|
|
43813
44051
|
try {
|
|
43814
|
-
(0,
|
|
44052
|
+
(0, import_node_fs35.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
|
|
43815
44053
|
`);
|
|
43816
44054
|
} catch {
|
|
43817
44055
|
}
|
|
@@ -43836,9 +44074,9 @@ async function runDaemon() {
|
|
|
43836
44074
|
logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
|
|
43837
44075
|
const restartDaemon = () => {
|
|
43838
44076
|
if (PATHS.mode === "system") {
|
|
43839
|
-
(0,
|
|
44077
|
+
(0, import_node_child_process12.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
|
|
43840
44078
|
} else {
|
|
43841
|
-
(0,
|
|
44079
|
+
(0, import_node_child_process12.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
|
|
43842
44080
|
setTimeout(() => process.exit(0), 500).unref();
|
|
43843
44081
|
}
|
|
43844
44082
|
};
|
|
@@ -43853,7 +44091,7 @@ async function runDaemon() {
|
|
|
43853
44091
|
} catch (err) {
|
|
43854
44092
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
43855
44093
|
}
|
|
43856
|
-
const config = loadConfig((0,
|
|
44094
|
+
const config = loadConfig((0, import_node_fs35.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
|
|
43857
44095
|
configureAttackDetection(config.detection);
|
|
43858
44096
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
43859
44097
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -43932,7 +44170,7 @@ async function runDaemon() {
|
|
|
43932
44170
|
version,
|
|
43933
44171
|
hostname: (0, import_node_os11.hostname)(),
|
|
43934
44172
|
minSeverity,
|
|
43935
|
-
spoolPath: (0,
|
|
44173
|
+
spoolPath: (0, import_node_path26.join)(PATHS.stateDir, "cloud-spool.jsonl"),
|
|
43936
44174
|
log: logLine,
|
|
43937
44175
|
ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
|
|
43938
44176
|
runHardening: runHardeningChecks
|
|
@@ -43946,6 +44184,16 @@ async function runDaemon() {
|
|
|
43946
44184
|
logLine(link ? `[cloud] reporting as server ${link.serverId} (org ${link.orgId}), detections >= ${minSeverity}` : "[cloud] not linked; run `threatcrush login` and `threatcrush servers link` to report to the dashboard");
|
|
43947
44185
|
}
|
|
43948
44186
|
const watchdog = startWatchdog({ bus, config: config.watchdog, stateDir: PATHS.stateDir, log: logLine });
|
|
44187
|
+
const autoUpdate = new AutoUpdate({
|
|
44188
|
+
version,
|
|
44189
|
+
settings: updateSettings(config.update),
|
|
44190
|
+
pkgRoot: (0, import_node_path26.join)(__dirname, ".."),
|
|
44191
|
+
statePath: (0, import_node_path26.join)(PATHS.stateDir, "auto-update.json"),
|
|
44192
|
+
bus,
|
|
44193
|
+
log: logLine,
|
|
44194
|
+
restartDaemon
|
|
44195
|
+
});
|
|
44196
|
+
autoUpdate.start();
|
|
43949
44197
|
const ipc = new IpcServer(version, moduleHost, remediation, () => watchdog.status());
|
|
43950
44198
|
await ipc.start();
|
|
43951
44199
|
logLine(`[daemon] ipc listening on ${PATHS.socket}`);
|
|
@@ -43979,6 +44227,10 @@ async function runDaemon() {
|
|
|
43979
44227
|
watchdog.stop();
|
|
43980
44228
|
} catch {
|
|
43981
44229
|
}
|
|
44230
|
+
try {
|
|
44231
|
+
autoUpdate.stop();
|
|
44232
|
+
} catch {
|
|
44233
|
+
}
|
|
43982
44234
|
try {
|
|
43983
44235
|
await ipc.stop();
|
|
43984
44236
|
} catch {
|
|
@@ -44014,7 +44266,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
|
|
|
44014
44266
|
function isRoot2() {
|
|
44015
44267
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
44016
44268
|
}
|
|
44017
|
-
var DAEMON_ENTRY = (0,
|
|
44269
|
+
var DAEMON_ENTRY = (0, import_node_path27.join)(__dirname, "daemon.js");
|
|
44018
44270
|
async function daemonForeground() {
|
|
44019
44271
|
await runDaemon();
|
|
44020
44272
|
}
|
|
@@ -44035,7 +44287,7 @@ async function daemonStart() {
|
|
|
44035
44287
|
return;
|
|
44036
44288
|
}
|
|
44037
44289
|
ensureRuntimeDirs();
|
|
44038
|
-
if (!(0,
|
|
44290
|
+
if (!(0, import_node_fs36.existsSync)(DAEMON_ENTRY)) {
|
|
44039
44291
|
console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
|
|
44040
44292
|
console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
|
|
44041
44293
|
return;
|
|
@@ -44043,8 +44295,8 @@ async function daemonStart() {
|
|
|
44043
44295
|
let out;
|
|
44044
44296
|
let err;
|
|
44045
44297
|
try {
|
|
44046
|
-
out = (0,
|
|
44047
|
-
err = (0,
|
|
44298
|
+
out = (0, import_node_fs37.openSync)(PATHS.logFile, "a");
|
|
44299
|
+
err = (0, import_node_fs37.openSync)(PATHS.logFile, "a");
|
|
44048
44300
|
} catch (e) {
|
|
44049
44301
|
const code = e.code;
|
|
44050
44302
|
console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
|
|
@@ -44057,7 +44309,7 @@ async function daemonStart() {
|
|
|
44057
44309
|
}
|
|
44058
44310
|
return;
|
|
44059
44311
|
}
|
|
44060
|
-
const child = (0,
|
|
44312
|
+
const child = (0, import_node_child_process13.spawn)(process.execPath, [DAEMON_ENTRY], {
|
|
44061
44313
|
detached: true,
|
|
44062
44314
|
stdio: ["ignore", out, err],
|
|
44063
44315
|
env: { ...process.env, THREATCRUSH_DAEMON: "1" }
|
|
@@ -44132,41 +44384,41 @@ async function waitForExit(pid, timeoutMs) {
|
|
|
44132
44384
|
}
|
|
44133
44385
|
async function releaseStaleSocket() {
|
|
44134
44386
|
const deadline = Date.now() + 2e3;
|
|
44135
|
-
while ((0,
|
|
44387
|
+
while ((0, import_node_fs36.existsSync)(PATHS.socket) && Date.now() < deadline) {
|
|
44136
44388
|
await new Promise((r) => setTimeout(r, 50));
|
|
44137
44389
|
}
|
|
44138
|
-
if ((0,
|
|
44390
|
+
if ((0, import_node_fs36.existsSync)(PATHS.socket)) {
|
|
44139
44391
|
try {
|
|
44140
|
-
(0,
|
|
44392
|
+
(0, import_node_fs36.unlinkSync)(PATHS.socket);
|
|
44141
44393
|
} catch {
|
|
44142
44394
|
}
|
|
44143
44395
|
}
|
|
44144
44396
|
}
|
|
44145
44397
|
|
|
44146
44398
|
// src/commands/service.ts
|
|
44147
|
-
var
|
|
44148
|
-
var
|
|
44149
|
-
var
|
|
44399
|
+
var import_node_child_process14 = require("child_process");
|
|
44400
|
+
var import_node_fs38 = require("fs");
|
|
44401
|
+
var import_node_path28 = require("path");
|
|
44150
44402
|
var import_node_os12 = require("os");
|
|
44151
44403
|
var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
|
|
44152
44404
|
var DAEMON_UNIT_NAME = "threatcrushd.service";
|
|
44153
44405
|
function resolveTemplate() {
|
|
44154
|
-
const templatePath = (0,
|
|
44155
|
-
if (!(0,
|
|
44406
|
+
const templatePath = (0, import_node_path28.join)(__dirname, "systemd", "threatcrushd.service");
|
|
44407
|
+
if (!(0, import_node_fs38.existsSync)(templatePath)) {
|
|
44156
44408
|
throw new Error(`systemd unit template not found at ${templatePath}`);
|
|
44157
44409
|
}
|
|
44158
|
-
return (0,
|
|
44410
|
+
return (0, import_node_fs38.readFileSync)(templatePath, "utf-8");
|
|
44159
44411
|
}
|
|
44160
44412
|
function stableBinPath(binPath) {
|
|
44161
44413
|
const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
|
|
44162
44414
|
if (stable === binPath) return binPath;
|
|
44163
|
-
return (0,
|
|
44415
|
+
return (0, import_node_fs38.existsSync)(stable) ? stable : binPath;
|
|
44164
44416
|
}
|
|
44165
44417
|
function resolveBinPath() {
|
|
44166
44418
|
const arg = process.argv[1];
|
|
44167
|
-
if (arg && (0,
|
|
44419
|
+
if (arg && (0, import_node_fs38.existsSync)(arg)) return stableBinPath(arg);
|
|
44168
44420
|
try {
|
|
44169
|
-
return (0,
|
|
44421
|
+
return (0, import_node_child_process14.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
|
|
44170
44422
|
} catch {
|
|
44171
44423
|
return "threatcrush";
|
|
44172
44424
|
}
|
|
@@ -44174,11 +44426,11 @@ function resolveBinPath() {
|
|
|
44174
44426
|
function stableNodePath(execPath) {
|
|
44175
44427
|
const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
|
|
44176
44428
|
if (stable === execPath) return execPath;
|
|
44177
|
-
return (0,
|
|
44429
|
+
return (0, import_node_fs38.existsSync)(stable) ? stable : execPath;
|
|
44178
44430
|
}
|
|
44179
44431
|
function looksLikeNodeScript(path) {
|
|
44180
44432
|
try {
|
|
44181
|
-
const head = (0,
|
|
44433
|
+
const head = (0, import_node_fs38.readFileSync)(path, "utf-8").slice(0, 120);
|
|
44182
44434
|
return /^#!.*\bnode\b/.test(head);
|
|
44183
44435
|
} catch {
|
|
44184
44436
|
return false;
|
|
@@ -44205,20 +44457,20 @@ function isRoot3() {
|
|
|
44205
44457
|
return typeof process.getuid === "function" && process.getuid() === 0;
|
|
44206
44458
|
}
|
|
44207
44459
|
function reexecWithSudo(args) {
|
|
44208
|
-
if ((0,
|
|
44460
|
+
if ((0, import_node_child_process14.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
44209
44461
|
console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
|
|
44210
44462
|
const bin = resolveBinPath();
|
|
44211
44463
|
const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
|
|
44212
|
-
const result = (0,
|
|
44464
|
+
const result = (0, import_node_child_process14.spawnSync)("sudo", argv, { stdio: "inherit" });
|
|
44213
44465
|
return result.status === 0;
|
|
44214
44466
|
}
|
|
44215
44467
|
function callerHome() {
|
|
44216
44468
|
const user = process.env.SUDO_USER;
|
|
44217
44469
|
if (!user) return null;
|
|
44218
44470
|
try {
|
|
44219
|
-
const line2 = (0,
|
|
44471
|
+
const line2 = (0, import_node_child_process14.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
|
|
44220
44472
|
const home = line2.split(":")[5];
|
|
44221
|
-
return home && (0,
|
|
44473
|
+
return home && (0, import_node_fs38.existsSync)(home) ? home : null;
|
|
44222
44474
|
} catch {
|
|
44223
44475
|
return null;
|
|
44224
44476
|
}
|
|
@@ -44226,13 +44478,13 @@ function callerHome() {
|
|
|
44226
44478
|
function stopUserModeDaemon() {
|
|
44227
44479
|
const home = callerHome();
|
|
44228
44480
|
if (!home) return;
|
|
44229
|
-
const runDir = (0,
|
|
44230
|
-
const pidFile = (0,
|
|
44231
|
-
const socket = (0,
|
|
44232
|
-
if (!(0,
|
|
44481
|
+
const runDir = (0, import_node_path28.join)(home, ".threatcrush", "run");
|
|
44482
|
+
const pidFile = (0, import_node_path28.join)(runDir, "threatcrushd.pid");
|
|
44483
|
+
const socket = (0, import_node_path28.join)(runDir, "threatcrushd.sock");
|
|
44484
|
+
if (!(0, import_node_fs38.existsSync)(pidFile) && !(0, import_node_fs38.existsSync)(socket)) return;
|
|
44233
44485
|
let pid = null;
|
|
44234
44486
|
try {
|
|
44235
|
-
pid = Number.parseInt((0,
|
|
44487
|
+
pid = Number.parseInt((0, import_node_fs38.readFileSync)(pidFile, "utf-8").trim(), 10);
|
|
44236
44488
|
} catch {
|
|
44237
44489
|
pid = null;
|
|
44238
44490
|
}
|
|
@@ -44245,13 +44497,13 @@ function stopUserModeDaemon() {
|
|
|
44245
44497
|
}
|
|
44246
44498
|
for (const path of [socket, pidFile]) {
|
|
44247
44499
|
try {
|
|
44248
|
-
if ((0,
|
|
44500
|
+
if ((0, import_node_fs38.existsSync)(path)) (0, import_node_fs38.rmSync)(path);
|
|
44249
44501
|
} catch {
|
|
44250
44502
|
}
|
|
44251
44503
|
}
|
|
44252
44504
|
}
|
|
44253
44505
|
function unitIsActive() {
|
|
44254
|
-
const result = (0,
|
|
44506
|
+
const result = (0, import_node_child_process14.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
|
|
44255
44507
|
return result.status === 0;
|
|
44256
44508
|
}
|
|
44257
44509
|
async function installServiceCommand() {
|
|
@@ -44262,8 +44514,8 @@ async function installServiceCommand() {
|
|
|
44262
44514
|
return;
|
|
44263
44515
|
}
|
|
44264
44516
|
const noSystemd = systemdUnavailableReason({
|
|
44265
|
-
hasSystemctl: (0,
|
|
44266
|
-
booted: (0,
|
|
44517
|
+
hasSystemctl: (0, import_node_child_process14.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
|
|
44518
|
+
booted: (0, import_node_fs38.existsSync)("/run/systemd/system")
|
|
44267
44519
|
});
|
|
44268
44520
|
if (noSystemd) {
|
|
44269
44521
|
console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
|
|
@@ -44285,7 +44537,7 @@ async function installServiceCommand() {
|
|
|
44285
44537
|
const isNodeScript = looksLikeNodeScript(binPath);
|
|
44286
44538
|
let nodePath = stableNodePath(process.execPath);
|
|
44287
44539
|
if (isNodeScript && nodeVersionDir(binPath)) {
|
|
44288
|
-
binPath = (0,
|
|
44540
|
+
binPath = (0, import_node_fs38.realpathSync)(binPath);
|
|
44289
44541
|
nodePath = process.execPath;
|
|
44290
44542
|
}
|
|
44291
44543
|
if (isNodeScript) {
|
|
@@ -44298,9 +44550,9 @@ async function installServiceCommand() {
|
|
|
44298
44550
|
}
|
|
44299
44551
|
}
|
|
44300
44552
|
const exec = execStartCommand(binPath, nodePath, isNodeScript);
|
|
44301
|
-
const configDir = (0,
|
|
44553
|
+
const configDir = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush");
|
|
44302
44554
|
const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
|
|
44303
|
-
(0,
|
|
44555
|
+
(0, import_node_fs38.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
|
|
44304
44556
|
console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
|
|
44305
44557
|
console.log(source_default.dim(` ExecStart=${exec}`));
|
|
44306
44558
|
const nodeDir = nodeVersionDir(nodePath);
|
|
@@ -44315,8 +44567,8 @@ async function installServiceCommand() {
|
|
|
44315
44567
|
installLogrotate();
|
|
44316
44568
|
stopUserModeDaemon();
|
|
44317
44569
|
try {
|
|
44318
|
-
(0,
|
|
44319
|
-
(0,
|
|
44570
|
+
(0, import_node_child_process14.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
44571
|
+
(0, import_node_child_process14.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
|
|
44320
44572
|
} catch (err) {
|
|
44321
44573
|
console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
|
|
44322
44574
|
console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
|
|
@@ -44353,9 +44605,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
|
|
|
44353
44605
|
].join("\n");
|
|
44354
44606
|
}
|
|
44355
44607
|
function installLogrotate() {
|
|
44356
|
-
if (!(0,
|
|
44608
|
+
if (!(0, import_node_fs38.existsSync)((0, import_node_path28.dirname)(LOGROTATE_PATH))) return;
|
|
44357
44609
|
try {
|
|
44358
|
-
(0,
|
|
44610
|
+
(0, import_node_fs38.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
|
|
44359
44611
|
console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
|
|
44360
44612
|
} catch (err) {
|
|
44361
44613
|
console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
|
|
@@ -44377,20 +44629,20 @@ function ensureSystemDirs(configDir) {
|
|
|
44377
44629
|
];
|
|
44378
44630
|
let admGid2 = null;
|
|
44379
44631
|
try {
|
|
44380
|
-
admGid2 = (0,
|
|
44632
|
+
admGid2 = (0, import_node_fs38.statSync)("/var/log/auth.log").gid;
|
|
44381
44633
|
} catch {
|
|
44382
44634
|
}
|
|
44383
44635
|
for (const { path, groupWritable, sticky } of dirs) {
|
|
44384
44636
|
try {
|
|
44385
|
-
(0,
|
|
44637
|
+
(0, import_node_fs38.mkdirSync)(path, { recursive: true });
|
|
44386
44638
|
} catch {
|
|
44387
44639
|
}
|
|
44388
44640
|
try {
|
|
44389
44641
|
if (groupWritable && admGid2 !== null) {
|
|
44390
|
-
(0,
|
|
44391
|
-
(0,
|
|
44642
|
+
(0, import_node_fs38.chmodSync)(path, sticky ? 1533 : 509);
|
|
44643
|
+
(0, import_node_child_process14.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
|
|
44392
44644
|
} else {
|
|
44393
|
-
(0,
|
|
44645
|
+
(0, import_node_fs38.chmodSync)(path, 493);
|
|
44394
44646
|
}
|
|
44395
44647
|
} catch {
|
|
44396
44648
|
}
|
|
@@ -44410,29 +44662,29 @@ async function uninstallServiceCommand() {
|
|
|
44410
44662
|
return;
|
|
44411
44663
|
}
|
|
44412
44664
|
try {
|
|
44413
|
-
(0,
|
|
44665
|
+
(0, import_node_child_process14.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
|
|
44414
44666
|
} catch {
|
|
44415
44667
|
}
|
|
44416
44668
|
try {
|
|
44417
|
-
(0,
|
|
44669
|
+
(0, import_node_child_process14.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
|
|
44418
44670
|
} catch {
|
|
44419
44671
|
}
|
|
44420
44672
|
try {
|
|
44421
|
-
if ((0,
|
|
44422
|
-
(0,
|
|
44673
|
+
if ((0, import_node_fs38.existsSync)(UNIT_PATH)) {
|
|
44674
|
+
(0, import_node_child_process14.execSync)(`rm -f ${UNIT_PATH}`);
|
|
44423
44675
|
console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
|
|
44424
44676
|
}
|
|
44425
44677
|
} catch {
|
|
44426
44678
|
}
|
|
44427
44679
|
try {
|
|
44428
|
-
(0,
|
|
44680
|
+
(0, import_node_child_process14.execSync)("systemctl daemon-reload", { stdio: "inherit" });
|
|
44429
44681
|
} catch {
|
|
44430
44682
|
}
|
|
44431
44683
|
console.log(source_default.green(" \u2713 threatcrushd service removed."));
|
|
44432
44684
|
}
|
|
44433
44685
|
|
|
44434
44686
|
// src/commands/save.ts
|
|
44435
|
-
var
|
|
44687
|
+
var import_node_fs39 = require("fs");
|
|
44436
44688
|
var import_toml5 = __toESM(require_toml());
|
|
44437
44689
|
init_cli_config();
|
|
44438
44690
|
init_paths();
|
|
@@ -44471,9 +44723,9 @@ async function saveCommand(opts = {}) {
|
|
|
44471
44723
|
}
|
|
44472
44724
|
const path = opts.config ?? PATHS.configFile;
|
|
44473
44725
|
let config = {};
|
|
44474
|
-
if ((0,
|
|
44726
|
+
if ((0, import_node_fs39.existsSync)(path)) {
|
|
44475
44727
|
try {
|
|
44476
|
-
config = import_toml5.default.parse((0,
|
|
44728
|
+
config = import_toml5.default.parse((0, import_node_fs39.readFileSync)(path, "utf-8"));
|
|
44477
44729
|
} catch (err) {
|
|
44478
44730
|
console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
|
|
44479
44731
|
`));
|
|
@@ -44586,8 +44838,8 @@ function welcomeCommand() {
|
|
|
44586
44838
|
}
|
|
44587
44839
|
|
|
44588
44840
|
// src/commands/properties.ts
|
|
44589
|
-
var
|
|
44590
|
-
var
|
|
44841
|
+
var import_node_fs40 = require("fs");
|
|
44842
|
+
var import_node_path29 = require("path");
|
|
44591
44843
|
var import_node_readline4 = __toESM(require("readline"));
|
|
44592
44844
|
init_cli_config();
|
|
44593
44845
|
var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
@@ -44917,8 +45169,8 @@ async function propertiesRunsCommand(opts) {
|
|
|
44917
45169
|
}
|
|
44918
45170
|
}
|
|
44919
45171
|
function parseImportFile(path) {
|
|
44920
|
-
const ext = (0,
|
|
44921
|
-
const raw = (0,
|
|
45172
|
+
const ext = (0, import_node_path29.extname)(path).toLowerCase();
|
|
45173
|
+
const raw = (0, import_node_fs40.readFileSync)(path, "utf-8");
|
|
44922
45174
|
if (ext === ".json") {
|
|
44923
45175
|
const parsed = JSON.parse(raw);
|
|
44924
45176
|
if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
|
|
@@ -45113,19 +45365,19 @@ async function rulesCommand(opts) {
|
|
|
45113
45365
|
}
|
|
45114
45366
|
|
|
45115
45367
|
// src/commands/harden.ts
|
|
45116
|
-
var
|
|
45117
|
-
var
|
|
45368
|
+
var import_node_fs41 = require("fs");
|
|
45369
|
+
var import_node_child_process15 = require("child_process");
|
|
45118
45370
|
init_cli_config();
|
|
45119
45371
|
function tryExec(cmd) {
|
|
45120
45372
|
try {
|
|
45121
|
-
return (0,
|
|
45373
|
+
return (0, import_node_child_process15.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
45122
45374
|
} catch {
|
|
45123
45375
|
return null;
|
|
45124
45376
|
}
|
|
45125
45377
|
}
|
|
45126
45378
|
function tryRead(path) {
|
|
45127
45379
|
try {
|
|
45128
|
-
return (0,
|
|
45380
|
+
return (0, import_node_fs41.readFileSync)(path, "utf-8");
|
|
45129
45381
|
} catch {
|
|
45130
45382
|
return null;
|
|
45131
45383
|
}
|
|
@@ -45229,8 +45481,8 @@ function checkSshWeakConfig() {
|
|
|
45229
45481
|
};
|
|
45230
45482
|
}
|
|
45231
45483
|
function checkAutoUpdates() {
|
|
45232
|
-
const unattended = (0,
|
|
45233
|
-
const dnfAuto = (0,
|
|
45484
|
+
const unattended = (0, import_node_fs41.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs41.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
|
|
45485
|
+
const dnfAuto = (0, import_node_fs41.existsSync)("/etc/dnf/automatic.conf");
|
|
45234
45486
|
if (unattended || dnfAuto) {
|
|
45235
45487
|
return {
|
|
45236
45488
|
key: "auto-updates",
|
|
@@ -45356,7 +45608,7 @@ function checkFail2ban() {
|
|
|
45356
45608
|
explanation: "fail2ban is installed and running."
|
|
45357
45609
|
};
|
|
45358
45610
|
}
|
|
45359
|
-
if ((0,
|
|
45611
|
+
if ((0, import_node_fs41.existsSync)("/etc/fail2ban/fail2ban.conf")) {
|
|
45360
45612
|
return {
|
|
45361
45613
|
key: checkKey,
|
|
45362
45614
|
status: "warn",
|
|
@@ -45685,11 +45937,11 @@ async function allowlistCommand(opts) {
|
|
|
45685
45937
|
init_paths();
|
|
45686
45938
|
|
|
45687
45939
|
// src/upgrade.ts
|
|
45688
|
-
var
|
|
45940
|
+
var import_node_child_process16 = require("child_process");
|
|
45689
45941
|
var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
|
|
45690
45942
|
var defaultRunner = (cmd) => {
|
|
45691
45943
|
try {
|
|
45692
|
-
return (0,
|
|
45944
|
+
return (0, import_node_child_process16.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
45693
45945
|
} catch {
|
|
45694
45946
|
return null;
|
|
45695
45947
|
}
|
|
@@ -45802,27 +46054,27 @@ ${source_default.green(" \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u25
|
|
|
45802
46054
|
${source_default.dim(" C R U S H")}
|
|
45803
46055
|
`;
|
|
45804
46056
|
var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
|
|
45805
|
-
var
|
|
46057
|
+
var PKG_NAME2 = "@profullstack/threatcrush";
|
|
45806
46058
|
var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
|
|
45807
|
-
var INSTALL_CONFIG_PATH = (0,
|
|
46059
|
+
var INSTALL_CONFIG_PATH = (0, import_node_path30.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
|
|
45808
46060
|
function detectPackageManager() {
|
|
45809
46061
|
try {
|
|
45810
|
-
const npmGlobal = (0,
|
|
45811
|
-
if (npmGlobal.includes(
|
|
46062
|
+
const npmGlobal = (0, import_node_child_process17.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
|
|
46063
|
+
if (npmGlobal.includes(PKG_NAME2)) return "npm";
|
|
45812
46064
|
} catch {
|
|
45813
46065
|
}
|
|
45814
46066
|
try {
|
|
45815
|
-
(0,
|
|
46067
|
+
(0, import_node_child_process17.execSync)("pnpm --version", { stdio: "pipe" });
|
|
45816
46068
|
return "pnpm";
|
|
45817
46069
|
} catch {
|
|
45818
46070
|
}
|
|
45819
46071
|
try {
|
|
45820
|
-
(0,
|
|
46072
|
+
(0, import_node_child_process17.execSync)("yarn --version", { stdio: "pipe" });
|
|
45821
46073
|
return "yarn";
|
|
45822
46074
|
} catch {
|
|
45823
46075
|
}
|
|
45824
46076
|
try {
|
|
45825
|
-
(0,
|
|
46077
|
+
(0, import_node_child_process17.execSync)("bun --version", { stdio: "pipe" });
|
|
45826
46078
|
return "bun";
|
|
45827
46079
|
} catch {
|
|
45828
46080
|
}
|
|
@@ -45830,14 +46082,14 @@ function detectPackageManager() {
|
|
|
45830
46082
|
}
|
|
45831
46083
|
function readInstallConfig() {
|
|
45832
46084
|
try {
|
|
45833
|
-
return JSON.parse((0,
|
|
46085
|
+
return JSON.parse((0, import_node_fs42.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
|
|
45834
46086
|
} catch {
|
|
45835
46087
|
return {};
|
|
45836
46088
|
}
|
|
45837
46089
|
}
|
|
45838
46090
|
function packageLooksInstalled(pm, pkgName) {
|
|
45839
46091
|
try {
|
|
45840
|
-
const output = (0,
|
|
46092
|
+
const output = (0, import_node_child_process17.execSync)(globalListCommand(pm, pkgName), {
|
|
45841
46093
|
encoding: "utf-8",
|
|
45842
46094
|
stdio: ["pipe", "pipe", "pipe"]
|
|
45843
46095
|
});
|
|
@@ -45853,7 +46105,7 @@ function upgradeCommands(pkgName) {
|
|
|
45853
46105
|
}
|
|
45854
46106
|
async function reportIfStillStale() {
|
|
45855
46107
|
const warning = shadowedUpdateWarning(
|
|
45856
|
-
await latestPublishedVersion(
|
|
46108
|
+
await latestPublishedVersion(PKG_NAME2),
|
|
45857
46109
|
activeCliVersion(),
|
|
45858
46110
|
activeCliPath()
|
|
45859
46111
|
);
|
|
@@ -45940,14 +46192,14 @@ async function promoteUnprivilegedDaemon() {
|
|
|
45940
46192
|
function restartSystemdDaemon() {
|
|
45941
46193
|
const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
45942
46194
|
const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
|
|
45943
|
-
if (!asRoot && (0,
|
|
46195
|
+
if (!asRoot && (0, import_node_child_process17.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
|
|
45944
46196
|
const [cmd, ...args] = argv;
|
|
45945
|
-
if ((0,
|
|
45946
|
-
return (0,
|
|
46197
|
+
if ((0, import_node_child_process17.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
|
|
46198
|
+
return (0, import_node_child_process17.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
|
|
45947
46199
|
}
|
|
45948
46200
|
function execQuiet(cmd) {
|
|
45949
46201
|
try {
|
|
45950
|
-
return (0,
|
|
46202
|
+
return (0, import_node_child_process17.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
|
|
45951
46203
|
} catch {
|
|
45952
46204
|
return null;
|
|
45953
46205
|
}
|
|
@@ -46133,7 +46385,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
|
|
|
46133
46385
|
program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
46134
46386
|
console.log(LOGO2);
|
|
46135
46387
|
const logPath = PATHS.logFile;
|
|
46136
|
-
if (!(0,
|
|
46388
|
+
if (!(0, import_node_fs42.existsSync)(logPath)) {
|
|
46137
46389
|
console.log(source_default.yellow(` No log file found at ${logPath}`));
|
|
46138
46390
|
console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
|
|
46139
46391
|
return;
|
|
@@ -46141,19 +46393,19 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
|
|
|
46141
46393
|
console.log(source_default.green(` Tailing ${logPath}...
|
|
46142
46394
|
`));
|
|
46143
46395
|
console.log(source_default.gray(" Press Ctrl+C to stop\n"));
|
|
46144
|
-
(0,
|
|
46396
|
+
(0, import_node_child_process17.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
|
|
46145
46397
|
});
|
|
46146
46398
|
program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
|
|
46147
46399
|
console.log(LOGO2);
|
|
46148
46400
|
if (opts.modules) {
|
|
46149
46401
|
console.log(LOGO2);
|
|
46150
46402
|
console.log(source_default.yellow(" Updating modules...\n"));
|
|
46151
|
-
const commands2 = upgradeCommands(
|
|
46403
|
+
const commands2 = upgradeCommands(PKG_NAME2);
|
|
46152
46404
|
try {
|
|
46153
46405
|
for (const cmd of commands2) {
|
|
46154
46406
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
46155
46407
|
`));
|
|
46156
|
-
(0,
|
|
46408
|
+
(0, import_node_child_process17.execSync)(cmd, { stdio: "inherit" });
|
|
46157
46409
|
}
|
|
46158
46410
|
console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
|
|
46159
46411
|
await reportIfStillStale();
|
|
@@ -46166,19 +46418,19 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
|
|
|
46166
46418
|
}
|
|
46167
46419
|
return;
|
|
46168
46420
|
}
|
|
46169
|
-
const holders = globalHolders(
|
|
46421
|
+
const holders = globalHolders(PKG_NAME2);
|
|
46170
46422
|
const installConfig = readInstallConfig();
|
|
46171
46423
|
const installMode = opts.cli ? "server" : opts.desktop ? "desktop" : installConfig.installMode || "server";
|
|
46172
46424
|
console.log(source_default.dim(` Detected package manager: ${holders.join(", ") || detectPackageManager()}`));
|
|
46173
46425
|
console.log(source_default.dim(` Install mode: ${installMode}`));
|
|
46174
46426
|
console.log(source_default.dim(` Current version: ${PKG_VERSION}
|
|
46175
46427
|
`));
|
|
46176
|
-
const commands = upgradeCommands(
|
|
46428
|
+
const commands = upgradeCommands(PKG_NAME2);
|
|
46177
46429
|
try {
|
|
46178
46430
|
for (const cmd of commands) {
|
|
46179
46431
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
46180
46432
|
`));
|
|
46181
|
-
(0,
|
|
46433
|
+
(0, import_node_child_process17.execSync)(cmd, { stdio: "inherit" });
|
|
46182
46434
|
}
|
|
46183
46435
|
console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
|
|
46184
46436
|
if (installMode === "desktop") {
|
|
@@ -46213,9 +46465,9 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
46213
46465
|
}
|
|
46214
46466
|
const installConfig = readInstallConfig();
|
|
46215
46467
|
const installMode = installConfig.installMode || "server";
|
|
46216
|
-
const holders = globalHolders(
|
|
46468
|
+
const holders = globalHolders(PKG_NAME2);
|
|
46217
46469
|
const pms = holders.length > 0 ? holders : [detectPackageManager()];
|
|
46218
|
-
const commands = pms.map((pm) => globalInstallCommand(pm,
|
|
46470
|
+
const commands = pms.map((pm) => globalInstallCommand(pm, PKG_NAME2, "remove"));
|
|
46219
46471
|
for (const pm of pms) {
|
|
46220
46472
|
if (installMode === "desktop" && packageLooksInstalled(pm, DESKTOP_PKG_NAME)) {
|
|
46221
46473
|
commands.push(globalInstallCommand(pm, DESKTOP_PKG_NAME, "remove"));
|
|
@@ -46229,7 +46481,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
|
|
|
46229
46481
|
for (const cmd of commands) {
|
|
46230
46482
|
console.log(source_default.green(` \u2192 ${cmd}
|
|
46231
46483
|
`));
|
|
46232
|
-
(0,
|
|
46484
|
+
(0, import_node_child_process17.execSync)(cmd, { stdio: "inherit" });
|
|
46233
46485
|
}
|
|
46234
46486
|
console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
|
|
46235
46487
|
console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
|
|
@@ -46306,10 +46558,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
|
|
|
46306
46558
|
});
|
|
46307
46559
|
storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
|
|
46308
46560
|
console.log(LOGO2);
|
|
46309
|
-
const configPath = (0,
|
|
46561
|
+
const configPath = (0, import_node_path30.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
|
|
46310
46562
|
let email = "";
|
|
46311
46563
|
try {
|
|
46312
|
-
const config = JSON.parse((0,
|
|
46564
|
+
const config = JSON.parse((0, import_node_fs42.readFileSync)(configPath, "utf-8"));
|
|
46313
46565
|
email = config.email || "";
|
|
46314
46566
|
} catch {
|
|
46315
46567
|
}
|
|
@@ -46326,9 +46578,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
|
|
|
46326
46578
|
return;
|
|
46327
46579
|
}
|
|
46328
46580
|
try {
|
|
46329
|
-
const dir = (0,
|
|
46330
|
-
if (!(0,
|
|
46331
|
-
(0,
|
|
46581
|
+
const dir = (0, import_node_path30.join)((0, import_node_os13.homedir)(), ".threatcrush");
|
|
46582
|
+
if (!(0, import_node_fs42.existsSync)(dir)) (0, import_node_fs42.mkdirSync)(dir, { recursive: true });
|
|
46583
|
+
(0, import_node_fs42.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
|
|
46332
46584
|
console.log(source_default.dim(` Saved email to ${configPath}`));
|
|
46333
46585
|
} catch {
|
|
46334
46586
|
}
|