@profullstack/threatcrush 0.12.5 → 0.12.6

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
@@ -10420,11 +10420,15 @@ function isRoot() {
10420
10420
  return process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
10421
10421
  }
10422
10422
  function resolveClientSocket() {
10423
- if ((0, import_node_fs2.existsSync)(PATHS.socket)) return PATHS.socket;
10424
- const other = PATHS.mode === "system" ? USER_PATHS.socket : SYSTEM_PATHS.socket;
10425
- if ((0, import_node_fs2.existsSync)(other)) return other;
10423
+ const override = process.env.THREATCRUSH_SOCKET;
10424
+ if (override) return override;
10425
+ if ((0, import_node_fs2.existsSync)(SYSTEM_PATHS.socket)) return SYSTEM_PATHS.socket;
10426
+ if ((0, import_node_fs2.existsSync)(USER_PATHS.socket)) return USER_PATHS.socket;
10426
10427
  return PATHS.socket;
10427
10428
  }
10429
+ function systemDaemonPresent() {
10430
+ return (0, import_node_fs2.existsSync)(SYSTEM_PATHS.socket) || (0, import_node_fs2.existsSync)(SYSTEM_PATHS.pidFile);
10431
+ }
10428
10432
  function ensureRuntimeDirs() {
10429
10433
  for (const dir of [PATHS.configDir, PATHS.confD, PATHS.moduleDir, PATHS.logDir, PATHS.stateDir, PATHS.runDir]) {
10430
10434
  try {
@@ -23159,8 +23163,8 @@ var IpcServer = class {
23159
23163
  nodeFs.chmodSync(PATHS.socket, 432);
23160
23164
  } catch {
23161
23165
  }
23162
- const isRoot3 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23163
- if (isRoot3) {
23166
+ const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23167
+ if (isRoot4) {
23164
23168
  try {
23165
23169
  const { gid } = nodeFs.statSync("/var/log/auth.log");
23166
23170
  nodeFs.chownSync(PATHS.socket, 0, gid);
@@ -23512,8 +23516,8 @@ var JournalWatcher = class _JournalWatcher {
23512
23516
  // would give us root's mostly-empty per-user journal. Otherwise we use
23513
23517
  // --user so the daemon can run unprivileged on a workstation.
23514
23518
  static scopeArgs() {
23515
- const isRoot3 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23516
- return isRoot3 ? [] : ["--user"];
23519
+ const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23520
+ return isRoot4 ? [] : ["--user"];
23517
23521
  }
23518
23522
  static isAvailable() {
23519
23523
  const probe = (0, import_node_child_process4.spawnSync)("journalctl", [...this.scopeArgs(), "-n", "0", "--no-pager"], {
@@ -25728,14 +25732,25 @@ var RemediationManager = class {
25728
25732
  }
25729
25733
  this.blocklist = live;
25730
25734
  this.saveState();
25731
- if (this.config.dry_run) return;
25732
- let applied = [];
25735
+ let applied = null;
25733
25736
  try {
25734
25737
  applied = await this.adapter.listBlocked();
25735
25738
  } catch {
25736
25739
  }
25740
+ if (applied) {
25741
+ const known = new Set(live.filter((b) => !b.dry_run).map((b) => b.ip));
25742
+ for (const ip of applied) {
25743
+ if (known.has(ip)) continue;
25744
+ this.logLine(`[firewall] reconcile: dropping stale rule for ${ip} (no record of why)`);
25745
+ try {
25746
+ await this.adapter.unblock(ip);
25747
+ } catch {
25748
+ }
25749
+ }
25750
+ }
25751
+ if (this.config.dry_run) return;
25737
25752
  for (const entry of live) {
25738
- if (applied.includes(entry.ip)) continue;
25753
+ if (applied?.includes(entry.ip)) continue;
25739
25754
  try {
25740
25755
  await this.adapter.block(entry.ip);
25741
25756
  } catch {
@@ -26004,6 +26019,10 @@ async function runDaemon() {
26004
26019
  // src/commands/daemon.ts
26005
26020
  init_paths();
26006
26021
  init_ipc_client();
26022
+ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
26023
+ function isRoot2() {
26024
+ return typeof process.getuid === "function" && process.getuid() === 0;
26025
+ }
26007
26026
  var DAEMON_ENTRY = (0, import_node_path20.join)(__dirname, "daemon.js");
26008
26027
  async function daemonForeground() {
26009
26028
  await runDaemon();
@@ -26014,6 +26033,16 @@ async function daemonStart() {
26014
26033
  console.log(source_default.yellow(` threatcrushd already running (pid ${pid}).`));
26015
26034
  return;
26016
26035
  }
26036
+ if (!isRoot2() && systemDaemonPresent()) {
26037
+ console.log(source_default.yellow(" A system threatcrushd is already installed on this host."));
26038
+ console.log(source_default.dim(" Starting a second, user-mode daemon would shadow it: the CLI would"));
26039
+ console.log(source_default.dim(" talk to yours while the root one keeps enforcing the firewall."));
26040
+ console.log();
26041
+ console.log(source_default.dim(" Manage that one instead: sudo systemctl restart threatcrushd"));
26042
+ console.log(source_default.dim(` Or address it directly: THREATCRUSH_SOCKET=${SYSTEM_SOCKET} threatcrush status`));
26043
+ console.log();
26044
+ return;
26045
+ }
26017
26046
  ensureRuntimeDirs();
26018
26047
  if (!(0, import_node_fs28.existsSync)(DAEMON_ENTRY)) {
26019
26048
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
@@ -26164,7 +26193,7 @@ function looksLikeNodeScript(path) {
26164
26193
  function execStartCommand(binPath, nodePath, isNodeScript) {
26165
26194
  return isNodeScript ? `${nodePath} ${binPath} daemon` : `${binPath} daemon`;
26166
26195
  }
26167
- function isRoot2() {
26196
+ function isRoot3() {
26168
26197
  return typeof process.getuid === "function" && process.getuid() === 0;
26169
26198
  }
26170
26199
  function reexecWithSudo(args) {
@@ -26223,7 +26252,7 @@ async function installServiceCommand() {
26223
26252
  console.log(source_default.yellow(" systemd install is only supported on Linux."));
26224
26253
  return;
26225
26254
  }
26226
- if (!isRoot2()) {
26255
+ if (!isRoot3()) {
26227
26256
  if (reexecWithSudo(["install-service"])) return;
26228
26257
  console.log(source_default.red(" Needs root and sudo is unavailable or was declined."));
26229
26258
  console.log(source_default.dim(" Run this as root: threatcrush install-service"));
@@ -26298,7 +26327,7 @@ async function uninstallServiceCommand() {
26298
26327
  console.log(source_default.yellow(" systemd uninstall is only supported on Linux."));
26299
26328
  return;
26300
26329
  }
26301
- if (!isRoot2()) {
26330
+ if (!isRoot3()) {
26302
26331
  if (reexecWithSudo(["uninstall-service"])) return;
26303
26332
  console.log(source_default.red(" Needs root and sudo is unavailable or was declined."));
26304
26333
  console.log(source_default.dim(" Run this as root: threatcrush uninstall-service"));