conbridge-agent 0.3.1 → 0.4.0
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 +1 -1
- package/conbridge-agent.cjs +1986 -1621
- package/package.json +1 -1
package/conbridge-agent.cjs
CHANGED
|
@@ -29,7 +29,7 @@ __export(cli_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(cli_exports);
|
|
30
30
|
|
|
31
31
|
// <define:__CONBRIDGE_BUILD__>
|
|
32
|
-
var define_CONBRIDGE_BUILD_default = { version: "0.
|
|
32
|
+
var define_CONBRIDGE_BUILD_default = { version: "0.4.0", commit: "a5d55893f404", built_at: "2026-10-31T00:01:24.018Z", keychain_helper_sha256: "359d0b3f3fedc26561d0e0b27a93df624fa55c1519c120e23fae46e9f2c2dc6a", distribution: "npm" };
|
|
33
33
|
|
|
34
34
|
// dist/cli.js
|
|
35
35
|
var import_node_child_process10 = require("node:child_process");
|
|
@@ -19838,6 +19838,7 @@ var INVENTORY_DEFAULTS = Object.freeze({ enabled: false, interval_s: 86400 });
|
|
|
19838
19838
|
var INVENTORY_MAX_COMPRESSED_BYTES = 15e5;
|
|
19839
19839
|
var INVENTORY_PART_CHARS = 48e3;
|
|
19840
19840
|
var INVENTORY_MAX_PARTS = Math.ceil(INVENTORY_MAX_COMPRESSED_BYTES * 4 / 3 / INVENTORY_PART_CHARS);
|
|
19841
|
+
var INVENTORY_MAX_SSH_HOSTS = 50;
|
|
19841
19842
|
var INVENTORY_LIMITS = Object.freeze({
|
|
19842
19843
|
packages: 2e4,
|
|
19843
19844
|
software: 128,
|
|
@@ -20122,7 +20123,8 @@ var metrics = base.extend({
|
|
|
20122
20123
|
var softwareInventoryConfig = base.extend({
|
|
20123
20124
|
kind: external_exports.literal("SOFTWARE_INVENTORY_CONFIG"),
|
|
20124
20125
|
enabled: external_exports.boolean(),
|
|
20125
|
-
interval_s: external_exports.literal([...INVENTORY_INTERVALS_S])
|
|
20126
|
+
interval_s: external_exports.literal([...INVENTORY_INTERVALS_S]),
|
|
20127
|
+
ssh_hosts: external_exports.array(uuid3).max(INVENTORY_MAX_SSH_HOSTS).optional()
|
|
20126
20128
|
});
|
|
20127
20129
|
var softwareInventoryRequest = base.extend({
|
|
20128
20130
|
kind: external_exports.literal("SOFTWARE_INVENTORY_REQUEST"),
|
|
@@ -20135,7 +20137,9 @@ var softwareInventoryPart = base.extend({
|
|
|
20135
20137
|
sequence: external_exports.number().int().min(0).max(INVENTORY_MAX_PARTS - 1),
|
|
20136
20138
|
total: external_exports.number().int().min(1).max(INVENTORY_MAX_PARTS),
|
|
20137
20139
|
sha256: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
20138
|
-
data: external_exports.string().min(1).max(INVENTORY_PART_CHARS).regex(/^[A-Za-z0-9+/]+={0,2}$/)
|
|
20140
|
+
data: external_exports.string().min(1).max(INVENTORY_PART_CHARS).regex(/^[A-Za-z0-9+/]+={0,2}$/),
|
|
20141
|
+
/** Set when the snapshot is of a pinned SSH host of this agent rather than the computer itself. */
|
|
20142
|
+
resource_id: uuid3.optional()
|
|
20139
20143
|
});
|
|
20140
20144
|
var envelopeSchema = external_exports.discriminatedUnion("kind", [
|
|
20141
20145
|
hello,
|
|
@@ -20252,7 +20256,12 @@ var AGENT_FEATURE_MIN_VERSION = Object.freeze({
|
|
|
20252
20256
|
/** MONITOR_CONFIG / METRICS (ADR DEVICE_MONITORING). */
|
|
20253
20257
|
monitoring: "0.2.0",
|
|
20254
20258
|
/** SOFTWARE_INVENTORY_* (ADR DEVICE_INVENTORY). */
|
|
20255
|
-
inventory: "0.3.0"
|
|
20259
|
+
inventory: "0.3.0",
|
|
20260
|
+
/**
|
|
20261
|
+
* `ssh_hosts` in SOFTWARE_INVENTORY_CONFIG (ADR SECURITY_INTELLIGENCE 11.6). Older agents drop the whole config frame
|
|
20262
|
+
* when it carries the field, so the relay sends it only to agents known to have this version.
|
|
20263
|
+
*/
|
|
20264
|
+
ssh_inventory: "0.4.0"
|
|
20256
20265
|
});
|
|
20257
20266
|
|
|
20258
20267
|
// ../../packages/protocol/dist/security/types.js
|
|
@@ -20370,6 +20379,52 @@ var IMAGE_PRODUCTS = Object.freeze({
|
|
|
20370
20379
|
alpine: "alpine"
|
|
20371
20380
|
});
|
|
20372
20381
|
|
|
20382
|
+
// ../../packages/protocol/dist/security/intel.js
|
|
20383
|
+
var CPE_PRODUCTS = Object.freeze({
|
|
20384
|
+
node: { cpe: "nodejs:node.js", scheme: "semver", name: "Node.js", releases: "node", packaged: /^nodejs$/ },
|
|
20385
|
+
php: { cpe: "php:php", scheme: "php", name: "PHP", releases: "php", packaged: /^php(\d+(\.\d+)?)?$/ },
|
|
20386
|
+
python: { cpe: "python:python", scheme: "dotted", name: "Python", packaged: /^python3(\.\d+)?$/ },
|
|
20387
|
+
openssl: { cpe: "openssl:openssl", scheme: "dotted", name: "OpenSSL", packaged: /^openssl(\d+(\.\d+)?)?$/ },
|
|
20388
|
+
nginx: { cpe: "f5:nginx", scheme: "dotted", name: "nginx", packaged: /^nginx$/ },
|
|
20389
|
+
apache: { cpe: "apache:http_server", scheme: "dotted", name: "Apache HTTP Server", packaged: /^(apache2|httpd)$/ },
|
|
20390
|
+
httpd: { cpe: "apache:http_server", scheme: "dotted", name: "Apache HTTP Server", packaged: /^(apache2|httpd)$/ },
|
|
20391
|
+
redis: { cpe: "redis:redis", scheme: "dotted", name: "Redis", packaged: /^redis$/ },
|
|
20392
|
+
mysql: { cpe: "oracle:mysql", scheme: "dotted", name: "MySQL", packaged: /^mysql-(server|community)?.*$|^mysql\d.*$/ },
|
|
20393
|
+
mariadb: { cpe: "mariadb:mariadb", scheme: "dotted", name: "MariaDB", packaged: /^mariadb(-\d+(\.\d+)?)?$/ },
|
|
20394
|
+
postgresql: { cpe: "postgresql:postgresql", scheme: "dotted", name: "PostgreSQL", packaged: /^postgresql(-\d+)?$/ },
|
|
20395
|
+
curl: { cpe: "haxx:curl", scheme: "dotted", name: "curl", packaged: /^curl$/ },
|
|
20396
|
+
git: { cpe: "git-scm:git", scheme: "dotted", name: "Git", packaged: /^git$/ },
|
|
20397
|
+
openssh: { cpe: "openbsd:openssh", scheme: "dotted", name: "OpenSSH", packaged: /^openssh(-server|-client)?$/ },
|
|
20398
|
+
sqlite: { cpe: "sqlite:sqlite", scheme: "dotted", name: "SQLite", packaged: /^sqlite3?$/ },
|
|
20399
|
+
ruby: { cpe: "ruby-lang:ruby", scheme: "dotted", name: "Ruby", packaged: /^ruby(\d+(\.\d+)?)?$/ },
|
|
20400
|
+
go: { cpe: "golang:go", scheme: "dotted", name: "Go", packaged: /^golang(-\d+(\.\d+)?)?$/ },
|
|
20401
|
+
composer: { cpe: "getcomposer:composer", scheme: "dotted", name: "Composer", packaged: /^composer$/ },
|
|
20402
|
+
bash: { cpe: "gnu:bash", scheme: "dotted", name: "Bash", packaged: /^bash$/ },
|
|
20403
|
+
caddy: { cpe: "caddyserver:caddy", scheme: "dotted", name: "Caddy", packaged: /^caddy$/ },
|
|
20404
|
+
haproxy: { cpe: "haproxy:haproxy", scheme: "dotted", name: "HAProxy", packaged: /^haproxy$/ },
|
|
20405
|
+
traefik: { cpe: "traefik:traefik", scheme: "dotted", name: "Traefik", packaged: /^traefik$/ },
|
|
20406
|
+
docker: { cpe: "docker:engine", scheme: "dotted", name: "Docker Engine", packaged: /^(docker\.io|docker-ce|moby-engine)$/ }
|
|
20407
|
+
});
|
|
20408
|
+
var EOL_SLUGS = Object.freeze({
|
|
20409
|
+
ubuntu: "ubuntu",
|
|
20410
|
+
debian: "debian",
|
|
20411
|
+
centos: "centos",
|
|
20412
|
+
alpine: "alpine-linux",
|
|
20413
|
+
"windows-server": "windows-server",
|
|
20414
|
+
node: "nodejs",
|
|
20415
|
+
php: "php",
|
|
20416
|
+
python: "python",
|
|
20417
|
+
mysql: "mysql",
|
|
20418
|
+
mariadb: "mariadb",
|
|
20419
|
+
postgresql: "postgresql",
|
|
20420
|
+
ruby: "ruby"
|
|
20421
|
+
});
|
|
20422
|
+
|
|
20423
|
+
// ../../packages/protocol/dist/security/risk.js
|
|
20424
|
+
var RATING_BASE = Object.freeze({ critical: 95, high: 80, medium: 55, low: 25, negligible: 10 });
|
|
20425
|
+
var CRITICALITY_FACTOR = Object.freeze({ low: 0.8, normal: 1, high: 1.1, critical: 1.2 });
|
|
20426
|
+
var CLASS_FACTOR = Object.freeze({ confirmed: 1, potential: 0.7, unknown: 0.5, not_affected: 0, fixed: 0 });
|
|
20427
|
+
|
|
20373
20428
|
// ../../packages/protocol/dist/http.js
|
|
20374
20429
|
var HTTP_API_VERSION = 1;
|
|
20375
20430
|
var requestIdSchema = external_exports.uuid();
|
|
@@ -21994,7 +22049,7 @@ var import_node_fs = require("node:fs");
|
|
|
21994
22049
|
var import_node_path2 = require("node:path");
|
|
21995
22050
|
var import_node_sea = require("node:sea");
|
|
21996
22051
|
var import_node_url = require("node:url");
|
|
21997
|
-
var SOURCE_VERSION = "0.
|
|
22052
|
+
var SOURCE_VERSION = "0.4.0";
|
|
21998
22053
|
var BUILD_INFO = typeof define_CONBRIDGE_BUILD_default === "object" && define_CONBRIDGE_BUILD_default !== null ? define_CONBRIDGE_BUILD_default : null;
|
|
21999
22054
|
var AGENT_VERSION = BUILD_INFO?.version ?? SOURCE_VERSION;
|
|
22000
22055
|
function runningAsSea() {
|
|
@@ -22800,6 +22855,7 @@ async function pairDevice(options) {
|
|
|
22800
22855
|
paired_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22801
22856
|
key_store: options.keyStore.descriptor
|
|
22802
22857
|
};
|
|
22858
|
+
await options.onApproved?.();
|
|
22803
22859
|
await saveIdentity(options.paths, identity);
|
|
22804
22860
|
succeeded = true;
|
|
22805
22861
|
return identity;
|
|
@@ -23452,6 +23508,38 @@ async function installRuntime(stateDir, from = {}) {
|
|
|
23452
23508
|
}
|
|
23453
23509
|
return { entry, changed };
|
|
23454
23510
|
}
|
|
23511
|
+
async function snapshotRuntime(stateDir) {
|
|
23512
|
+
const dir = runtimeDir(stateDir);
|
|
23513
|
+
const backup = `${dir}.previous`;
|
|
23514
|
+
await (0, import_promises7.rm)(backup, { recursive: true, force: true });
|
|
23515
|
+
await (0, import_promises7.mkdir)(backup, { recursive: true, mode: 448 });
|
|
23516
|
+
const saved = /* @__PURE__ */ new Map();
|
|
23517
|
+
for (const name3 of [RUNTIME_ENTRY, KEYCHAIN_HELPER_NAME]) {
|
|
23518
|
+
const info = await (0, import_promises7.stat)((0, import_node_path10.join)(dir, name3)).catch(() => null);
|
|
23519
|
+
if (!info?.isFile())
|
|
23520
|
+
continue;
|
|
23521
|
+
await (0, import_promises7.copyFile)((0, import_node_path10.join)(dir, name3), (0, import_node_path10.join)(backup, name3));
|
|
23522
|
+
saved.set(name3, info.mode & 511);
|
|
23523
|
+
}
|
|
23524
|
+
const discard = () => (0, import_promises7.rm)(backup, { recursive: true, force: true });
|
|
23525
|
+
return {
|
|
23526
|
+
async restore() {
|
|
23527
|
+
await (0, import_promises7.mkdir)(dir, { recursive: true, mode: 448 });
|
|
23528
|
+
for (const name3 of [RUNTIME_ENTRY, KEYCHAIN_HELPER_NAME]) {
|
|
23529
|
+
const mode = saved.get(name3);
|
|
23530
|
+
if (mode !== void 0)
|
|
23531
|
+
await copyAtomic((0, import_node_path10.join)(backup, name3), (0, import_node_path10.join)(dir, name3), mode);
|
|
23532
|
+
else
|
|
23533
|
+
await (0, import_promises7.unlink)((0, import_node_path10.join)(dir, name3)).catch((error63) => {
|
|
23534
|
+
if (errorCode2(error63) !== "ENOENT")
|
|
23535
|
+
throw error63;
|
|
23536
|
+
});
|
|
23537
|
+
}
|
|
23538
|
+
await discard();
|
|
23539
|
+
},
|
|
23540
|
+
discard
|
|
23541
|
+
};
|
|
23542
|
+
}
|
|
23455
23543
|
async function runningFromRuntime(stateDir, entry = currentEntry()) {
|
|
23456
23544
|
const [running, installed] = await Promise.all([realpathLenient(entry), realpathLenient(runtimeEntry(stateDir))]);
|
|
23457
23545
|
return running === installed;
|
|
@@ -24981,406 +25069,341 @@ var MonitorLoop = class {
|
|
|
24981
25069
|
};
|
|
24982
25070
|
|
|
24983
25071
|
// dist/inventory/loop.js
|
|
24984
|
-
var
|
|
25072
|
+
var import_node_crypto9 = require("node:crypto");
|
|
24985
25073
|
var import_node_zlib = require("node:zlib");
|
|
24986
|
-
function encodeSnapshot(snapshot, requestId, runId = (0, import_node_crypto8.randomUUID)()) {
|
|
24987
|
-
const gz = (0, import_node_zlib.gzipSync)(Buffer.from(JSON.stringify(snapshot), "utf8"), { level: 9 });
|
|
24988
|
-
if (gz.byteLength > INVENTORY_MAX_COMPRESSED_BYTES)
|
|
24989
|
-
return null;
|
|
24990
|
-
const sha2563 = (0, import_node_crypto8.createHash)("sha256").update(gz).digest("hex");
|
|
24991
|
-
const data = gz.toString("base64");
|
|
24992
|
-
const total = Math.max(1, Math.ceil(data.length / INVENTORY_PART_CHARS));
|
|
24993
|
-
return Array.from({ length: total }, (_, sequence) => ({
|
|
24994
|
-
run_id: runId,
|
|
24995
|
-
request_id: requestId,
|
|
24996
|
-
sequence,
|
|
24997
|
-
total,
|
|
24998
|
-
sha256: sha2563,
|
|
24999
|
-
data: data.slice(sequence * INVENTORY_PART_CHARS, (sequence + 1) * INVENTORY_PART_CHARS)
|
|
25000
|
-
}));
|
|
25001
|
-
}
|
|
25002
|
-
var InventoryLoop = class {
|
|
25003
|
-
#options;
|
|
25004
|
-
#logger;
|
|
25005
|
-
#intervalS = null;
|
|
25006
|
-
#timer = null;
|
|
25007
|
-
#running = false;
|
|
25008
|
-
#stopped = false;
|
|
25009
|
-
constructor(options) {
|
|
25010
|
-
this.#options = options;
|
|
25011
|
-
this.#logger = options.logger ?? silentLogger;
|
|
25012
|
-
}
|
|
25013
|
-
get enabled() {
|
|
25014
|
-
return this.#intervalS !== null;
|
|
25015
|
-
}
|
|
25016
|
-
apply(config2) {
|
|
25017
|
-
if (this.#stopped)
|
|
25018
|
-
return;
|
|
25019
|
-
if (!config2.enabled) {
|
|
25020
|
-
if (this.#intervalS !== null)
|
|
25021
|
-
this.#logger.info("software inventory stopped");
|
|
25022
|
-
this.#intervalS = null;
|
|
25023
|
-
this.#clear();
|
|
25024
|
-
return;
|
|
25025
|
-
}
|
|
25026
|
-
if (this.#intervalS === config2.interval_s && this.#timer)
|
|
25027
|
-
return;
|
|
25028
|
-
const first = this.#intervalS === null;
|
|
25029
|
-
this.#intervalS = config2.interval_s;
|
|
25030
|
-
this.#clear();
|
|
25031
|
-
const jitter = (this.#options.firstRunMs ?? (() => 5e3 + Math.floor(Math.random() * 25e3)))();
|
|
25032
|
-
const last = this.#options.lastSentAtMs?.() ?? null;
|
|
25033
|
-
const now = (this.#options.now ?? Date.now)();
|
|
25034
|
-
const due = last === null ? jitter : Math.max(jitter, last + config2.interval_s * 1e3 - now);
|
|
25035
|
-
this.#schedule(first ? due : config2.interval_s * 1e3);
|
|
25036
|
-
this.#logger.info("software inventory scheduled", { interval_s: config2.interval_s });
|
|
25037
|
-
}
|
|
25038
|
-
/** Console Refresh: one run now (ignored while off or while a run is in progress). */
|
|
25039
|
-
request(requestId) {
|
|
25040
|
-
if (this.#stopped || this.#intervalS === null || this.#running)
|
|
25041
|
-
return;
|
|
25042
|
-
void this.#run(requestId);
|
|
25043
|
-
}
|
|
25044
|
-
stop() {
|
|
25045
|
-
this.#stopped = true;
|
|
25046
|
-
this.#intervalS = null;
|
|
25047
|
-
this.#clear();
|
|
25048
|
-
}
|
|
25049
|
-
#clear() {
|
|
25050
|
-
if (this.#timer)
|
|
25051
|
-
clearTimeout(this.#timer);
|
|
25052
|
-
this.#timer = null;
|
|
25053
|
-
}
|
|
25054
|
-
#schedule(ms) {
|
|
25055
|
-
this.#timer = setTimeout(() => {
|
|
25056
|
-
this.#timer = null;
|
|
25057
|
-
void this.#run(null).finally(() => {
|
|
25058
|
-
if (!this.#stopped && this.#intervalS !== null && !this.#timer)
|
|
25059
|
-
this.#schedule(this.#intervalS * 1e3);
|
|
25060
|
-
});
|
|
25061
|
-
}, ms);
|
|
25062
|
-
this.#timer.unref?.();
|
|
25063
|
-
}
|
|
25064
|
-
async #run(requestId) {
|
|
25065
|
-
if (this.#running)
|
|
25066
|
-
return;
|
|
25067
|
-
if (!this.#options.allowed()) {
|
|
25068
|
-
this.#logger.info("software inventory is off on this computer (conbridge-agent config inventory on)");
|
|
25069
|
-
return;
|
|
25070
|
-
}
|
|
25071
|
-
this.#running = true;
|
|
25072
|
-
const started = Date.now();
|
|
25073
|
-
try {
|
|
25074
|
-
const snapshot = await this.#options.collect();
|
|
25075
|
-
if (this.#stopped || this.#intervalS === null)
|
|
25076
|
-
return;
|
|
25077
|
-
const parts = encodeSnapshot(snapshot, requestId);
|
|
25078
|
-
if (!parts) {
|
|
25079
|
-
this.#logger.warn("software inventory too large to send");
|
|
25080
|
-
return;
|
|
25081
|
-
}
|
|
25082
|
-
this.#options.send(parts);
|
|
25083
|
-
this.#options.onSent?.((this.#options.now ?? Date.now)());
|
|
25084
|
-
this.#logger.info("software inventory sent", { packages: snapshot.packages.length, containers: snapshot.containers.length, parts: parts.length, ms: Date.now() - started });
|
|
25085
|
-
} catch (error63) {
|
|
25086
|
-
this.#logger.warn("software inventory failed", { error: error63 instanceof Error ? error63.name : "unknown" });
|
|
25087
|
-
} finally {
|
|
25088
|
-
this.#running = false;
|
|
25089
|
-
}
|
|
25090
|
-
}
|
|
25091
|
-
};
|
|
25092
25074
|
|
|
25093
|
-
// dist/
|
|
25075
|
+
// dist/ssh/exec.js
|
|
25094
25076
|
var import_node_child_process6 = require("node:child_process");
|
|
25095
|
-
var
|
|
25096
|
-
var import_node_os4 = require("node:os");
|
|
25077
|
+
var import_node_path13 = require("node:path");
|
|
25097
25078
|
|
|
25098
|
-
// dist/
|
|
25099
|
-
var
|
|
25100
|
-
var
|
|
25101
|
-
var
|
|
25102
|
-
var
|
|
25103
|
-
var
|
|
25104
|
-
|
|
25105
|
-
|
|
25106
|
-
|
|
25107
|
-
|
|
25108
|
-
|
|
25109
|
-
return trimmed;
|
|
25110
|
-
return trimmed.slice(0, max).trimEnd();
|
|
25079
|
+
// dist/ssh/hosts.js
|
|
25080
|
+
var import_node_crypto8 = require("node:crypto");
|
|
25081
|
+
var import_promises11 = require("node:fs/promises");
|
|
25082
|
+
var import_node_path12 = require("node:path");
|
|
25083
|
+
var MAX_SSH_HOSTS = 64;
|
|
25084
|
+
var SSH_ALIAS = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
25085
|
+
var DNS_HOST = /^(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
|
|
25086
|
+
var IPV6_HOST = /^(?=.{2,45}$)[0-9A-Fa-f:.]*:[0-9A-Fa-f:.]*$/;
|
|
25087
|
+
var SSH_USER = /^[A-Za-z_][A-Za-z0-9_.-]{0,31}$/;
|
|
25088
|
+
function isValidSshHost(value) {
|
|
25089
|
+
return DNS_HOST.test(value) || IPV6_HOST.test(value);
|
|
25111
25090
|
}
|
|
25112
|
-
function
|
|
25113
|
-
return
|
|
25091
|
+
function isValidIdentityPath(value) {
|
|
25092
|
+
return (0, import_node_path12.isAbsolute)(value) && value.length <= 1024 && !/[\u0000-\u001f\u007f%"]/.test(value);
|
|
25114
25093
|
}
|
|
25115
|
-
|
|
25116
|
-
|
|
25094
|
+
var PINNABLE_KEY_TYPES = Object.freeze([
|
|
25095
|
+
"ssh-ed25519",
|
|
25096
|
+
"ecdsa-sha2-nistp256",
|
|
25097
|
+
"ecdsa-sha2-nistp384",
|
|
25098
|
+
"ecdsa-sha2-nistp521",
|
|
25099
|
+
"ssh-rsa"
|
|
25100
|
+
]);
|
|
25101
|
+
var base643 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
25102
|
+
var sshHostSchema = external_exports.strictObject({
|
|
25103
|
+
resource_id: external_exports.uuid(),
|
|
25104
|
+
alias: external_exports.string().regex(SSH_ALIAS),
|
|
25105
|
+
host: external_exports.string().refine(isValidSshHost, "Invalid host"),
|
|
25106
|
+
port: external_exports.number().int().min(1).max(65535),
|
|
25107
|
+
user: external_exports.string().regex(SSH_USER).optional(),
|
|
25108
|
+
identity: external_exports.string().refine(isValidIdentityPath, "Invalid identity path").optional(),
|
|
25109
|
+
production: external_exports.boolean(),
|
|
25110
|
+
key_type: external_exports.enum(PINNABLE_KEY_TYPES),
|
|
25111
|
+
public_key: external_exports.string().min(16).max(8192).regex(base643),
|
|
25112
|
+
fingerprint: external_exports.string().regex(/^SHA256:[A-Za-z0-9+/]{43}$/),
|
|
25113
|
+
pinned_at: external_exports.iso.datetime({ offset: true })
|
|
25114
|
+
});
|
|
25115
|
+
var hostsFileSchema = external_exports.strictObject({ version: external_exports.literal(1), hosts: external_exports.array(sshHostSchema).max(MAX_SSH_HOSTS) });
|
|
25116
|
+
function sshPaths(stateDir) {
|
|
25117
|
+
const dir = (0, import_node_path12.join)(stateDir, "ssh");
|
|
25118
|
+
return { dir, hosts: (0, import_node_path12.join)(dir, "hosts.json"), knownHostsDir: (0, import_node_path12.join)(dir, "known_hosts") };
|
|
25117
25119
|
}
|
|
25118
|
-
function
|
|
25119
|
-
return
|
|
25120
|
+
function knownHostsPath(paths, resourceId) {
|
|
25121
|
+
return (0, import_node_path12.join)(paths.knownHostsDir, external_exports.uuid().parse(resourceId));
|
|
25120
25122
|
}
|
|
25121
|
-
function
|
|
25122
|
-
|
|
25123
|
-
return [];
|
|
25124
|
-
return stdout.split(/\r?\n/).filter((line) => line.trim() !== "");
|
|
25123
|
+
function hostKeyAlias(host) {
|
|
25124
|
+
return "conbridge-" + host.resource_id;
|
|
25125
25125
|
}
|
|
25126
|
-
function
|
|
25127
|
-
|
|
25128
|
-
result2.push(item);
|
|
25126
|
+
function fingerprintOf(publicKey) {
|
|
25127
|
+
return "SHA256:" + (0, import_node_crypto8.createHash)("sha256").update(Buffer.from(publicKey, "base64")).digest("base64").replace(/=+$/, "");
|
|
25129
25128
|
}
|
|
25130
|
-
function
|
|
25131
|
-
const
|
|
25132
|
-
|
|
25133
|
-
return void 0;
|
|
25134
|
-
const number4 = Number(raw);
|
|
25135
|
-
return Number.isSafeInteger(number4) ? number4 : void 0;
|
|
25129
|
+
function normalizeFingerprint(value) {
|
|
25130
|
+
const trimmed = value.trim();
|
|
25131
|
+
return trimmed.startsWith("SHA256:") ? trimmed : "SHA256:" + trimmed;
|
|
25136
25132
|
}
|
|
25137
|
-
function
|
|
25138
|
-
const
|
|
25139
|
-
|
|
25140
|
-
|
|
25141
|
-
|
|
25142
|
-
|
|
25133
|
+
function parseKeyscan(output2) {
|
|
25134
|
+
const keys = [];
|
|
25135
|
+
for (const line of output2.split("\n")) {
|
|
25136
|
+
const trimmed = line.trim();
|
|
25137
|
+
if (trimmed === "" || trimmed.startsWith("#"))
|
|
25138
|
+
continue;
|
|
25139
|
+
const [, type, key] = trimmed.split(/\s+/);
|
|
25140
|
+
if (!type || !key || !PINNABLE_KEY_TYPES.includes(type) || !base643.test(key) || key.length > 8192)
|
|
25141
|
+
continue;
|
|
25142
|
+
keys.push({ key_type: type, public_key: key, fingerprint: fingerprintOf(key) });
|
|
25143
|
+
}
|
|
25144
|
+
return keys;
|
|
25143
25145
|
}
|
|
25144
|
-
function
|
|
25145
|
-
|
|
25146
|
-
|
|
25147
|
-
|
|
25148
|
-
|
|
25146
|
+
function preferredKey(keys) {
|
|
25147
|
+
for (const type of PINNABLE_KEY_TYPES) {
|
|
25148
|
+
const key = keys.find((candidate) => candidate.key_type === type);
|
|
25149
|
+
if (key)
|
|
25150
|
+
return key;
|
|
25151
|
+
}
|
|
25152
|
+
return null;
|
|
25149
25153
|
}
|
|
25150
|
-
function
|
|
25151
|
-
|
|
25154
|
+
async function loadSshHosts(paths) {
|
|
25155
|
+
let text4;
|
|
25156
|
+
try {
|
|
25157
|
+
text4 = await (0, import_promises11.readFile)(paths.hosts, "utf8");
|
|
25158
|
+
} catch (error63) {
|
|
25159
|
+
if (errorCode2(error63) === "ENOENT")
|
|
25160
|
+
return [];
|
|
25161
|
+
throw error63;
|
|
25162
|
+
}
|
|
25163
|
+
return hostsFileSchema.parse(JSON.parse(text4)).hosts;
|
|
25152
25164
|
}
|
|
25153
|
-
function
|
|
25154
|
-
|
|
25155
|
-
|
|
25156
|
-
|
|
25157
|
-
if (!/^\d{8}$/.test(raw))
|
|
25158
|
-
return void 0;
|
|
25159
|
-
const year = Number(raw.slice(0, 4));
|
|
25160
|
-
const month = Number(raw.slice(4, 6));
|
|
25161
|
-
const day = Number(raw.slice(6, 8));
|
|
25162
|
-
if (month < 1 || month > 12 || day < 1)
|
|
25163
|
-
return void 0;
|
|
25164
|
-
const leap = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
25165
|
-
const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
25166
|
-
const limit = days[month - 1];
|
|
25167
|
-
if (limit === void 0 || day > limit)
|
|
25168
|
-
return void 0;
|
|
25169
|
-
return `${raw.slice(0, 4)}-${raw.slice(4, 6)}-${raw.slice(6, 8)}`;
|
|
25170
|
-
}
|
|
25171
|
-
function parseJson(json2) {
|
|
25172
|
-
try {
|
|
25173
|
-
return JSON.parse(json2);
|
|
25174
|
-
} catch {
|
|
25175
|
-
return void 0;
|
|
25165
|
+
async function ensureSshDirs(paths) {
|
|
25166
|
+
for (const dir of [paths.dir, paths.knownHostsDir]) {
|
|
25167
|
+
await (0, import_promises11.mkdir)(dir, { recursive: true, mode: 448 });
|
|
25168
|
+
await (0, import_promises11.chmod)(dir, 448);
|
|
25176
25169
|
}
|
|
25177
25170
|
}
|
|
25178
|
-
function
|
|
25179
|
-
|
|
25180
|
-
|
|
25181
|
-
const parts = line.split(" ");
|
|
25182
|
-
if (parts.length < 5)
|
|
25183
|
-
continue;
|
|
25184
|
-
const status = text(parts[4], 16);
|
|
25185
|
-
if (!status.startsWith("ii") && !status.startsWith("hi"))
|
|
25186
|
-
continue;
|
|
25187
|
-
const name3 = nameOf(parts[0]);
|
|
25188
|
-
if (!name3)
|
|
25189
|
-
continue;
|
|
25190
|
-
const version6 = versionOf(parts[1]);
|
|
25191
|
-
const item = { name: name3, version: version6, manager: "dpkg" };
|
|
25192
|
-
const arch3 = text(parts[2], ARCH_MAX);
|
|
25193
|
-
if (arch3)
|
|
25194
|
-
item.arch = arch3;
|
|
25195
|
-
const size = sizeFromKiB(parts[3]);
|
|
25196
|
-
if (size !== void 0)
|
|
25197
|
-
item.size_bytes = size;
|
|
25198
|
-
const sourceName = nameOf(parts[5]);
|
|
25199
|
-
if (sourceName && sourceName !== name3)
|
|
25200
|
-
item.source_name = sourceName;
|
|
25201
|
-
const sourceVersion = versionOf(parts[6]);
|
|
25202
|
-
if (sourceVersion && sourceVersion !== version6)
|
|
25203
|
-
item.source_version = sourceVersion;
|
|
25204
|
-
push(result2, item);
|
|
25205
|
-
}
|
|
25206
|
-
return result2;
|
|
25171
|
+
async function saveSshHosts(paths, hosts) {
|
|
25172
|
+
await ensureSshDirs(paths);
|
|
25173
|
+
await writeFileAtomic(paths.hosts, JSON.stringify(hostsFileSchema.parse({ version: 1, hosts }), null, 2) + "\n", 384);
|
|
25207
25174
|
}
|
|
25208
|
-
function
|
|
25209
|
-
|
|
25210
|
-
|
|
25211
|
-
|
|
25212
|
-
if (parts.length < 6)
|
|
25213
|
-
continue;
|
|
25214
|
-
const name3 = nameOf(parts[0]);
|
|
25215
|
-
if (!name3 || name3 === "gpg-pubkey")
|
|
25216
|
-
continue;
|
|
25217
|
-
const version6 = versionOf(parts[2]);
|
|
25218
|
-
const release2 = versionOf(parts[3]);
|
|
25219
|
-
if (!version6 || !release2)
|
|
25220
|
-
continue;
|
|
25221
|
-
const epoch = text(parts[1], 32);
|
|
25222
|
-
const epochPrefix = /^\d+$/.test(epoch) ? `${epoch}:` : "";
|
|
25223
|
-
const item = { name: name3, version: versionOf(`${epochPrefix}${version6}-${release2}`), manager: "rpm" };
|
|
25224
|
-
const arch3 = text(parts[4], ARCH_MAX);
|
|
25225
|
-
if (arch3 && arch3 !== "(none)")
|
|
25226
|
-
item.arch = arch3;
|
|
25227
|
-
const size = integerText(parts[5]);
|
|
25228
|
-
if (size !== void 0)
|
|
25229
|
-
item.size_bytes = size;
|
|
25230
|
-
push(result2, item);
|
|
25231
|
-
}
|
|
25232
|
-
return result2;
|
|
25175
|
+
async function writeKnownHosts(paths, host) {
|
|
25176
|
+
await ensureSshDirs(paths);
|
|
25177
|
+
await writeFileAtomic(knownHostsPath(paths, host.resource_id), `${hostKeyAlias(host)} ${host.key_type} ${host.public_key}
|
|
25178
|
+
`, 384);
|
|
25233
25179
|
}
|
|
25234
|
-
function
|
|
25235
|
-
|
|
25236
|
-
|
|
25237
|
-
|
|
25238
|
-
|
|
25239
|
-
|
|
25240
|
-
|
|
25241
|
-
|
|
25242
|
-
|
|
25243
|
-
|
|
25244
|
-
|
|
25245
|
-
|
|
25246
|
-
const
|
|
25247
|
-
if (
|
|
25248
|
-
|
|
25249
|
-
push(result2, item);
|
|
25180
|
+
async function validateNewHost(input2) {
|
|
25181
|
+
if (!SSH_ALIAS.test(input2.alias))
|
|
25182
|
+
throw new Error('Alias must be 1-63 lowercase letters, digits, "-" or "_", starting with a letter or digit');
|
|
25183
|
+
if (!isValidSshHost(input2.host))
|
|
25184
|
+
throw new Error("Host must be a DNS name, IPv4 or IPv6 address");
|
|
25185
|
+
if (input2.port !== void 0 && (!Number.isInteger(input2.port) || input2.port < 1 || input2.port > 65535))
|
|
25186
|
+
throw new Error("Port must be 1-65535");
|
|
25187
|
+
if (input2.user !== void 0 && !SSH_USER.test(input2.user))
|
|
25188
|
+
throw new Error("User must be a plain login name");
|
|
25189
|
+
if (input2.identity !== void 0) {
|
|
25190
|
+
if (!isValidIdentityPath(input2.identity))
|
|
25191
|
+
throw new Error("Identity must be an absolute path without quotes, % or control characters");
|
|
25192
|
+
const info = await (0, import_promises11.stat)(input2.identity).catch(() => null);
|
|
25193
|
+
if (!info?.isFile())
|
|
25194
|
+
throw new Error("Identity file not found");
|
|
25250
25195
|
}
|
|
25251
|
-
return result2;
|
|
25252
25196
|
}
|
|
25253
|
-
function
|
|
25254
|
-
|
|
25255
|
-
|
|
25256
|
-
|
|
25257
|
-
|
|
25258
|
-
|
|
25259
|
-
|
|
25260
|
-
|
|
25261
|
-
|
|
25262
|
-
|
|
25263
|
-
|
|
25264
|
-
|
|
25197
|
+
async function addSshHost(paths, input2, key, now = /* @__PURE__ */ new Date()) {
|
|
25198
|
+
await validateNewHost(input2);
|
|
25199
|
+
const hosts = await loadSshHosts(paths);
|
|
25200
|
+
if (hosts.some((host2) => host2.alias === input2.alias))
|
|
25201
|
+
throw new Error(`An SSH host named ${input2.alias} already exists`);
|
|
25202
|
+
if (hosts.length >= MAX_SSH_HOSTS)
|
|
25203
|
+
throw new Error(`At most ${MAX_SSH_HOSTS} SSH hosts are supported`);
|
|
25204
|
+
const host = sshHostSchema.parse({
|
|
25205
|
+
resource_id: (0, import_node_crypto8.randomUUID)(),
|
|
25206
|
+
alias: input2.alias,
|
|
25207
|
+
host: input2.host,
|
|
25208
|
+
port: input2.port ?? 22,
|
|
25209
|
+
...input2.user !== void 0 ? { user: input2.user } : {},
|
|
25210
|
+
...input2.identity !== void 0 ? { identity: input2.identity } : {},
|
|
25211
|
+
production: input2.production === true,
|
|
25212
|
+
key_type: key.key_type,
|
|
25213
|
+
public_key: key.public_key,
|
|
25214
|
+
fingerprint: key.fingerprint,
|
|
25215
|
+
pinned_at: now.toISOString()
|
|
25216
|
+
});
|
|
25217
|
+
await writeKnownHosts(paths, host);
|
|
25218
|
+
await saveSshHosts(paths, [...hosts, host]);
|
|
25219
|
+
return host;
|
|
25265
25220
|
}
|
|
25266
|
-
function
|
|
25267
|
-
|
|
25268
|
-
for (const line of lines(stdout)) {
|
|
25269
|
-
const parts = line.trim().split(/\s+/);
|
|
25270
|
-
if (parts.length < 2)
|
|
25271
|
-
continue;
|
|
25272
|
-
if (parts[0] === "Name" && parts[1] === "Version")
|
|
25273
|
-
continue;
|
|
25274
|
-
const name3 = nameOf(parts[0]);
|
|
25275
|
-
if (!name3)
|
|
25276
|
-
continue;
|
|
25277
|
-
const item = { name: name3, version: versionOf(parts[1]), manager: "snap" };
|
|
25278
|
-
const publisher = text(parts[4], PUBLISHER_MAX).replace(/[✓*]+$/u, "").trim();
|
|
25279
|
-
if (publisher && publisher !== "-")
|
|
25280
|
-
item.publisher = publisher;
|
|
25281
|
-
push(result2, item);
|
|
25282
|
-
}
|
|
25283
|
-
return result2;
|
|
25221
|
+
async function findSshHost(paths, alias) {
|
|
25222
|
+
return (await loadSshHosts(paths)).find((host) => host.alias === alias) ?? null;
|
|
25284
25223
|
}
|
|
25285
|
-
function
|
|
25286
|
-
const
|
|
25287
|
-
|
|
25288
|
-
|
|
25289
|
-
|
|
25290
|
-
|
|
25291
|
-
|
|
25292
|
-
|
|
25293
|
-
|
|
25294
|
-
|
|
25295
|
-
|
|
25296
|
-
return
|
|
25224
|
+
async function updateHost(paths, alias, change) {
|
|
25225
|
+
const hosts = await loadSshHosts(paths);
|
|
25226
|
+
const index = hosts.findIndex((host) => host.alias === alias);
|
|
25227
|
+
if (index < 0)
|
|
25228
|
+
throw new Error(`No SSH host named ${alias}`);
|
|
25229
|
+
const updated = sshHostSchema.parse(change(hosts[index]));
|
|
25230
|
+
const next = [...hosts];
|
|
25231
|
+
next[index] = updated;
|
|
25232
|
+
if (updated.public_key !== hosts[index].public_key || updated.key_type !== hosts[index].key_type)
|
|
25233
|
+
await writeKnownHosts(paths, updated);
|
|
25234
|
+
await saveSshHosts(paths, next);
|
|
25235
|
+
return updated;
|
|
25297
25236
|
}
|
|
25298
|
-
function
|
|
25299
|
-
|
|
25300
|
-
const dependencies = asRecord(root?.dependencies);
|
|
25301
|
-
if (!dependencies)
|
|
25302
|
-
return [];
|
|
25303
|
-
const result2 = [];
|
|
25304
|
-
for (const [rawName, value] of Object.entries(dependencies)) {
|
|
25305
|
-
const info = asRecord(value);
|
|
25306
|
-
if (!info || typeof info.version !== "string")
|
|
25307
|
-
continue;
|
|
25308
|
-
const name3 = nameOf(rawName);
|
|
25309
|
-
if (!name3)
|
|
25310
|
-
continue;
|
|
25311
|
-
push(result2, { name: name3, version: versionOf(info.version), manager: "npm-global" });
|
|
25312
|
-
}
|
|
25313
|
-
return result2;
|
|
25237
|
+
async function repinSshHost(paths, alias, key, now = /* @__PURE__ */ new Date()) {
|
|
25238
|
+
return await updateHost(paths, alias, (host) => ({ ...host, key_type: key.key_type, public_key: key.public_key, fingerprint: key.fingerprint, pinned_at: now.toISOString() }));
|
|
25314
25239
|
}
|
|
25315
|
-
function
|
|
25316
|
-
|
|
25317
|
-
const items = root?.SPApplicationsDataType;
|
|
25318
|
-
if (!Array.isArray(items))
|
|
25319
|
-
return [];
|
|
25320
|
-
const result2 = [];
|
|
25321
|
-
const seen = /* @__PURE__ */ new Set();
|
|
25322
|
-
for (const value of items) {
|
|
25323
|
-
const info = asRecord(value);
|
|
25324
|
-
if (!info)
|
|
25325
|
-
continue;
|
|
25326
|
-
const name3 = nameOf(info._name);
|
|
25327
|
-
if (!name3)
|
|
25328
|
-
continue;
|
|
25329
|
-
const path = text(info.path, 4096);
|
|
25330
|
-
if (!isApplicationPath(path))
|
|
25331
|
-
continue;
|
|
25332
|
-
const version6 = versionOf(info.version);
|
|
25333
|
-
const key = `${name3}\0${version6}`;
|
|
25334
|
-
if (seen.has(key))
|
|
25335
|
-
continue;
|
|
25336
|
-
seen.add(key);
|
|
25337
|
-
const item = { name: name3, version: version6, manager: "macos-app" };
|
|
25338
|
-
const source = text(info.obtained_from, 60);
|
|
25339
|
-
if (source === "apple")
|
|
25340
|
-
item.publisher = "Apple";
|
|
25341
|
-
else if (source === "mac_app_store")
|
|
25342
|
-
item.publisher = "App Store";
|
|
25343
|
-
push(result2, item);
|
|
25344
|
-
}
|
|
25345
|
-
return result2;
|
|
25240
|
+
async function setSshHostProduction(paths, alias, production) {
|
|
25241
|
+
return await updateHost(paths, alias, (host) => ({ ...host, production }));
|
|
25346
25242
|
}
|
|
25347
|
-
function
|
|
25348
|
-
const
|
|
25349
|
-
const
|
|
25350
|
-
|
|
25351
|
-
|
|
25352
|
-
|
|
25353
|
-
|
|
25354
|
-
|
|
25355
|
-
|
|
25356
|
-
|
|
25357
|
-
|
|
25358
|
-
|
|
25359
|
-
|
|
25360
|
-
|
|
25361
|
-
|
|
25362
|
-
|
|
25363
|
-
|
|
25364
|
-
|
|
25365
|
-
|
|
25366
|
-
|
|
25367
|
-
|
|
25368
|
-
|
|
25369
|
-
|
|
25370
|
-
|
|
25371
|
-
|
|
25372
|
-
|
|
25373
|
-
|
|
25374
|
-
|
|
25243
|
+
async function removeSshHost(paths, alias) {
|
|
25244
|
+
const hosts = await loadSshHosts(paths);
|
|
25245
|
+
const host = hosts.find((entry) => entry.alias === alias);
|
|
25246
|
+
if (!host)
|
|
25247
|
+
return false;
|
|
25248
|
+
await saveSshHosts(paths, hosts.filter((entry) => entry !== host));
|
|
25249
|
+
await (0, import_promises11.unlink)(knownHostsPath(paths, host.resource_id)).catch(() => void 0);
|
|
25250
|
+
return true;
|
|
25251
|
+
}
|
|
25252
|
+
function hostAddress(host) {
|
|
25253
|
+
if (host.port === 22)
|
|
25254
|
+
return host.host;
|
|
25255
|
+
return host.host.includes(":") ? `[${host.host}]:${host.port}` : `${host.host}:${host.port}`;
|
|
25256
|
+
}
|
|
25257
|
+
function inventoryResource2(host) {
|
|
25258
|
+
return { resource_id: host.resource_id, kind: "ssh_host", label: host.alias, attrs: { production: host.production, address: hostAddress(host) } };
|
|
25259
|
+
}
|
|
25260
|
+
|
|
25261
|
+
// dist/ssh/exec.js
|
|
25262
|
+
var DEFAULT_SSH_BINARIES = Object.freeze({ ssh: "/usr/bin/ssh", keyscan: "/usr/bin/ssh-keyscan" });
|
|
25263
|
+
function sshBinariesFromEnv(env = process.env) {
|
|
25264
|
+
const pick2 = (value, fallback) => value && (0, import_node_path13.isAbsolute)(value) ? value : fallback;
|
|
25265
|
+
return { ssh: pick2(env.CONBRIDGE_SSH_BIN, DEFAULT_SSH_BINARIES.ssh), keyscan: pick2(env.CONBRIDGE_SSH_KEYSCAN_BIN, DEFAULT_SSH_BINARIES.keyscan) };
|
|
25266
|
+
}
|
|
25267
|
+
function sshChildEnv(env = process.env) {
|
|
25268
|
+
const child = {};
|
|
25269
|
+
for (const key of ["PATH", "HOME", "USER", "LOGNAME", "SSH_AUTH_SOCK", "LANG", "TMPDIR"]) {
|
|
25270
|
+
if (env[key] !== void 0)
|
|
25271
|
+
child[key] = env[key];
|
|
25375
25272
|
}
|
|
25376
|
-
return
|
|
25273
|
+
return child;
|
|
25274
|
+
}
|
|
25275
|
+
function runProcess(file2, args, options) {
|
|
25276
|
+
const started = Date.now();
|
|
25277
|
+
return new Promise((resolve8) => {
|
|
25278
|
+
const kept = { stdout: [], stderr: [] };
|
|
25279
|
+
const totals = { stdout: 0, stderr: 0 };
|
|
25280
|
+
let keptBytes = 0;
|
|
25281
|
+
let truncated = false;
|
|
25282
|
+
let timedOut = false;
|
|
25283
|
+
let settled = false;
|
|
25284
|
+
const child = (0, import_node_child_process6.spawn)(file2, [...args], { stdio: ["ignore", "pipe", "pipe"], env: options.env, shell: false });
|
|
25285
|
+
const collect = (stream) => (chunk2) => {
|
|
25286
|
+
totals[stream] += chunk2.length;
|
|
25287
|
+
const room = options.maxBytes - keptBytes;
|
|
25288
|
+
if (room <= 0) {
|
|
25289
|
+
truncated = true;
|
|
25290
|
+
return;
|
|
25291
|
+
}
|
|
25292
|
+
const piece = chunk2.length > room ? chunk2.subarray(0, room) : chunk2;
|
|
25293
|
+
if (piece.length < chunk2.length)
|
|
25294
|
+
truncated = true;
|
|
25295
|
+
kept[stream].push(piece);
|
|
25296
|
+
keptBytes += piece.length;
|
|
25297
|
+
};
|
|
25298
|
+
child.stdout.on("data", collect("stdout"));
|
|
25299
|
+
child.stderr.on("data", collect("stderr"));
|
|
25300
|
+
let killTimer;
|
|
25301
|
+
const timer = setTimeout(() => {
|
|
25302
|
+
timedOut = true;
|
|
25303
|
+
child.kill("SIGTERM");
|
|
25304
|
+
killTimer = setTimeout(() => child.kill("SIGKILL"), 2e3);
|
|
25305
|
+
}, options.timeoutMs);
|
|
25306
|
+
const finish = (exitCode, spawnError) => {
|
|
25307
|
+
if (settled)
|
|
25308
|
+
return;
|
|
25309
|
+
settled = true;
|
|
25310
|
+
clearTimeout(timer);
|
|
25311
|
+
if (killTimer)
|
|
25312
|
+
clearTimeout(killTimer);
|
|
25313
|
+
resolve8({
|
|
25314
|
+
exitCode,
|
|
25315
|
+
timedOut,
|
|
25316
|
+
truncated,
|
|
25317
|
+
durationMs: Date.now() - started,
|
|
25318
|
+
stdout: Buffer.concat(kept.stdout).toString("utf8"),
|
|
25319
|
+
stderr: Buffer.concat(kept.stderr).toString("utf8"),
|
|
25320
|
+
stdoutBytes: totals.stdout,
|
|
25321
|
+
stderrBytes: totals.stderr,
|
|
25322
|
+
...spawnError !== void 0 ? { spawnError } : {}
|
|
25323
|
+
});
|
|
25324
|
+
};
|
|
25325
|
+
child.on("error", (error63) => finish(null, error63.code ?? "SPAWN_FAILED"));
|
|
25326
|
+
child.on("close", (code) => finish(code));
|
|
25327
|
+
});
|
|
25328
|
+
}
|
|
25329
|
+
function keyscanType(type) {
|
|
25330
|
+
if (type === "ssh-ed25519")
|
|
25331
|
+
return "ed25519";
|
|
25332
|
+
if (type === "ssh-rsa")
|
|
25333
|
+
return "rsa";
|
|
25334
|
+
return "ecdsa";
|
|
25335
|
+
}
|
|
25336
|
+
function hostKeyAlgorithms(type) {
|
|
25337
|
+
return type === "ssh-rsa" ? "rsa-sha2-512,rsa-sha2-256" : type;
|
|
25338
|
+
}
|
|
25339
|
+
function sshConfigPath(path) {
|
|
25340
|
+
if (/["\n\r]/.test(path))
|
|
25341
|
+
throw new Error("Path cannot be used in an ssh option");
|
|
25342
|
+
const escaped = path.replace(/%/g, "%%");
|
|
25343
|
+
return /\s/.test(escaped) ? `"${escaped}"` : escaped;
|
|
25344
|
+
}
|
|
25345
|
+
var KEYSCAN_TIMEOUT_S = 10;
|
|
25346
|
+
async function scanHostKeys(binaries, target, options = {}) {
|
|
25347
|
+
const types = options.types ?? ["ssh-ed25519", "ecdsa-sha2-nistp256", "ssh-rsa"];
|
|
25348
|
+
const args = ["-T", String(KEYSCAN_TIMEOUT_S), "-p", String(target.port), "-t", [...new Set(types.map(keyscanType))].join(","), "--", target.host];
|
|
25349
|
+
const result2 = await runProcess(binaries.keyscan, args, { timeoutMs: (KEYSCAN_TIMEOUT_S + 5) * 1e3, maxBytes: 64 * 1024, env: sshChildEnv(options.env) });
|
|
25350
|
+
if (result2.spawnError)
|
|
25351
|
+
return { keys: [], error: "ssh-keyscan could not be started (" + result2.spawnError + ")" };
|
|
25352
|
+
const keys = parseKeyscan(result2.stdout);
|
|
25353
|
+
return { keys, error: keys.length === 0 ? result2.timedOut ? "Host did not answer in time" : "Host returned no usable host key" : null };
|
|
25354
|
+
}
|
|
25355
|
+
function buildSshArgs(paths, host, command2) {
|
|
25356
|
+
const options = [
|
|
25357
|
+
"BatchMode=yes",
|
|
25358
|
+
"StrictHostKeyChecking=yes",
|
|
25359
|
+
`UserKnownHostsFile=${sshConfigPath(knownHostsPath(paths, host.resource_id))}`,
|
|
25360
|
+
"GlobalKnownHostsFile=/dev/null",
|
|
25361
|
+
`HostKeyAlias=${hostKeyAlias(host)}`,
|
|
25362
|
+
`HostKeyAlgorithms=${hostKeyAlgorithms(host.key_type)}`,
|
|
25363
|
+
"UpdateHostKeys=no",
|
|
25364
|
+
"CheckHostIP=no",
|
|
25365
|
+
"PasswordAuthentication=no",
|
|
25366
|
+
"KbdInteractiveAuthentication=no",
|
|
25367
|
+
"ProxyCommand=none",
|
|
25368
|
+
"PermitLocalCommand=no",
|
|
25369
|
+
"ForwardAgent=no",
|
|
25370
|
+
"ForwardX11=no",
|
|
25371
|
+
"ClearAllForwardings=yes",
|
|
25372
|
+
"ControlMaster=no",
|
|
25373
|
+
"ControlPath=none",
|
|
25374
|
+
"RequestTTY=no",
|
|
25375
|
+
"ConnectTimeout=15",
|
|
25376
|
+
"ServerAliveInterval=15",
|
|
25377
|
+
"ServerAliveCountMax=3",
|
|
25378
|
+
"LogLevel=ERROR",
|
|
25379
|
+
...host.identity !== void 0 ? ["IdentitiesOnly=yes"] : []
|
|
25380
|
+
];
|
|
25381
|
+
return [
|
|
25382
|
+
"-F",
|
|
25383
|
+
"/dev/null",
|
|
25384
|
+
...options.flatMap((option) => ["-o", option]),
|
|
25385
|
+
...host.identity !== void 0 ? ["-i", host.identity] : [],
|
|
25386
|
+
"-p",
|
|
25387
|
+
String(host.port),
|
|
25388
|
+
...host.user !== void 0 ? ["-l", host.user] : [],
|
|
25389
|
+
"-n",
|
|
25390
|
+
"-T",
|
|
25391
|
+
"--",
|
|
25392
|
+
host.host,
|
|
25393
|
+
command2
|
|
25394
|
+
];
|
|
25395
|
+
}
|
|
25396
|
+
function isHostKeyFailure(result2) {
|
|
25397
|
+
return result2.exitCode === 255 && result2.stdoutBytes === 0 && /Host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED|No (?:ED25519|ECDSA|RSA) host key is known/i.test(result2.stderr);
|
|
25377
25398
|
}
|
|
25378
25399
|
|
|
25379
|
-
// dist/inventory/parsers/
|
|
25380
|
-
var
|
|
25381
|
-
var
|
|
25382
|
-
var
|
|
25383
|
-
|
|
25400
|
+
// dist/inventory/parsers/packages.js
|
|
25401
|
+
var NAME_MAX = 200;
|
|
25402
|
+
var VERSION_MAX = 128;
|
|
25403
|
+
var ARCH_MAX = 32;
|
|
25404
|
+
var PUBLISHER_MAX = 200;
|
|
25405
|
+
var MAX_PACKAGES = INVENTORY_LIMITS.packages;
|
|
25406
|
+
function text(value, max) {
|
|
25384
25407
|
if (typeof value !== "string")
|
|
25385
25408
|
return "";
|
|
25386
25409
|
const trimmed = value.trim();
|
|
@@ -25388,590 +25411,946 @@ function text2(value, max) {
|
|
|
25388
25411
|
return trimmed;
|
|
25389
25412
|
return trimmed.slice(0, max).trimEnd();
|
|
25390
25413
|
}
|
|
25391
|
-
function
|
|
25414
|
+
function nameOf(value) {
|
|
25415
|
+
return text(value, NAME_MAX);
|
|
25416
|
+
}
|
|
25417
|
+
function versionOf(value) {
|
|
25418
|
+
return text(value, VERSION_MAX);
|
|
25419
|
+
}
|
|
25420
|
+
function asRecord(value) {
|
|
25392
25421
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
25393
25422
|
}
|
|
25394
|
-
function
|
|
25423
|
+
function lines(stdout) {
|
|
25395
25424
|
if (typeof stdout !== "string")
|
|
25396
25425
|
return [];
|
|
25397
25426
|
return stdout.split(/\r?\n/).filter((line) => line.trim() !== "");
|
|
25398
25427
|
}
|
|
25399
|
-
function
|
|
25428
|
+
function push(result2, item) {
|
|
25429
|
+
if (result2.length < MAX_PACKAGES)
|
|
25430
|
+
result2.push(item);
|
|
25431
|
+
}
|
|
25432
|
+
function integerText(value) {
|
|
25433
|
+
const raw = text(value, 64);
|
|
25434
|
+
if (!/^\d+$/.test(raw))
|
|
25435
|
+
return void 0;
|
|
25436
|
+
const number4 = Number(raw);
|
|
25437
|
+
return Number.isSafeInteger(number4) ? number4 : void 0;
|
|
25438
|
+
}
|
|
25439
|
+
function sizeFromKiB(value) {
|
|
25440
|
+
const kib = integerText(value);
|
|
25441
|
+
if (kib === void 0)
|
|
25442
|
+
return void 0;
|
|
25443
|
+
const bytes3 = kib * 1024;
|
|
25444
|
+
return Number.isSafeInteger(bytes3) ? bytes3 : void 0;
|
|
25445
|
+
}
|
|
25446
|
+
function sizeFromKb(value) {
|
|
25447
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
25448
|
+
return void 0;
|
|
25449
|
+
const bytes3 = value * 1024;
|
|
25450
|
+
return Number.isSafeInteger(bytes3) && bytes3 > 0 ? bytes3 : void 0;
|
|
25451
|
+
}
|
|
25452
|
+
function isApplicationPath(path) {
|
|
25453
|
+
return path.startsWith("/Applications/") || /^\/Users\/[^/]+\/Applications\//.test(path);
|
|
25454
|
+
}
|
|
25455
|
+
function installDate(value) {
|
|
25400
25456
|
if (typeof value !== "string")
|
|
25401
25457
|
return void 0;
|
|
25458
|
+
const raw = value.trim();
|
|
25459
|
+
if (!/^\d{8}$/.test(raw))
|
|
25460
|
+
return void 0;
|
|
25461
|
+
const year = Number(raw.slice(0, 4));
|
|
25462
|
+
const month = Number(raw.slice(4, 6));
|
|
25463
|
+
const day = Number(raw.slice(6, 8));
|
|
25464
|
+
if (month < 1 || month > 12 || day < 1)
|
|
25465
|
+
return void 0;
|
|
25466
|
+
const leap = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
25467
|
+
const days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
25468
|
+
const limit = days[month - 1];
|
|
25469
|
+
if (limit === void 0 || day > limit)
|
|
25470
|
+
return void 0;
|
|
25471
|
+
return `${raw.slice(0, 4)}-${raw.slice(4, 6)}-${raw.slice(6, 8)}`;
|
|
25472
|
+
}
|
|
25473
|
+
function parseJson(json2) {
|
|
25402
25474
|
try {
|
|
25403
|
-
return JSON.parse(
|
|
25475
|
+
return JSON.parse(json2);
|
|
25404
25476
|
} catch {
|
|
25405
25477
|
return void 0;
|
|
25406
25478
|
}
|
|
25407
25479
|
}
|
|
25408
|
-
function
|
|
25409
|
-
result2
|
|
25410
|
-
|
|
25411
|
-
|
|
25412
|
-
|
|
25413
|
-
return unit.endsWith(".service") ? unit.slice(0, -".service".length) : unit;
|
|
25414
|
-
}
|
|
25415
|
-
function systemdState(active, sub) {
|
|
25416
|
-
if (active === "active")
|
|
25417
|
-
return sub === "running" ? "running" : "stopped";
|
|
25418
|
-
if (active === "failed")
|
|
25419
|
-
return "failed";
|
|
25420
|
-
if (active === "activating" || active === "reloading")
|
|
25421
|
-
return "starting";
|
|
25422
|
-
if (active === "deactivating")
|
|
25423
|
-
return "stopping";
|
|
25424
|
-
if (active === "inactive")
|
|
25425
|
-
return "stopped";
|
|
25426
|
-
return "unknown";
|
|
25427
|
-
}
|
|
25428
|
-
function unitFileEnablement(unitFiles) {
|
|
25429
|
-
const enablement = /* @__PURE__ */ new Map();
|
|
25430
|
-
for (const line of lines2(unitFiles)) {
|
|
25431
|
-
const parts = line.trim().split(/\s+/);
|
|
25432
|
-
const unit = parts[0];
|
|
25433
|
-
const state2 = parts[1];
|
|
25434
|
-
if (!unit || !state2)
|
|
25480
|
+
function parseDpkg(stdout) {
|
|
25481
|
+
const result2 = [];
|
|
25482
|
+
for (const line of lines(stdout)) {
|
|
25483
|
+
const parts = line.split(" ");
|
|
25484
|
+
if (parts.length < 5)
|
|
25435
25485
|
continue;
|
|
25436
|
-
|
|
25437
|
-
|
|
25438
|
-
|
|
25439
|
-
|
|
25440
|
-
|
|
25441
|
-
|
|
25486
|
+
const status = text(parts[4], 16);
|
|
25487
|
+
if (!status.startsWith("ii") && !status.startsWith("hi"))
|
|
25488
|
+
continue;
|
|
25489
|
+
const name3 = nameOf(parts[0]);
|
|
25490
|
+
if (!name3)
|
|
25491
|
+
continue;
|
|
25492
|
+
const version6 = versionOf(parts[1]);
|
|
25493
|
+
const item = { name: name3, version: version6, manager: "dpkg" };
|
|
25494
|
+
const arch3 = text(parts[2], ARCH_MAX);
|
|
25495
|
+
if (arch3)
|
|
25496
|
+
item.arch = arch3;
|
|
25497
|
+
const size = sizeFromKiB(parts[3]);
|
|
25498
|
+
if (size !== void 0)
|
|
25499
|
+
item.size_bytes = size;
|
|
25500
|
+
const sourceName = nameOf(parts[5]);
|
|
25501
|
+
if (sourceName && sourceName !== name3)
|
|
25502
|
+
item.source_name = sourceName;
|
|
25503
|
+
const sourceVersion = versionOf(parts[6]);
|
|
25504
|
+
if (sourceVersion && sourceVersion !== version6)
|
|
25505
|
+
item.source_version = sourceVersion;
|
|
25506
|
+
push(result2, item);
|
|
25442
25507
|
}
|
|
25443
|
-
return
|
|
25508
|
+
return result2;
|
|
25444
25509
|
}
|
|
25445
|
-
function
|
|
25446
|
-
const enablement = unitFileEnablement(unitFiles);
|
|
25510
|
+
function parseRpm(stdout) {
|
|
25447
25511
|
const result2 = [];
|
|
25448
|
-
for (const
|
|
25449
|
-
const
|
|
25450
|
-
|
|
25512
|
+
for (const line of lines(stdout)) {
|
|
25513
|
+
const parts = line.split(" ");
|
|
25514
|
+
if (parts.length < 6)
|
|
25515
|
+
continue;
|
|
25516
|
+
const name3 = nameOf(parts[0]);
|
|
25517
|
+
if (!name3 || name3 === "gpg-pubkey")
|
|
25518
|
+
continue;
|
|
25519
|
+
const version6 = versionOf(parts[2]);
|
|
25520
|
+
const release2 = versionOf(parts[3]);
|
|
25521
|
+
if (!version6 || !release2)
|
|
25522
|
+
continue;
|
|
25523
|
+
const epoch = text(parts[1], 32);
|
|
25524
|
+
const epochPrefix = /^\d+$/.test(epoch) ? `${epoch}:` : "";
|
|
25525
|
+
const item = { name: name3, version: versionOf(`${epochPrefix}${version6}-${release2}`), manager: "rpm" };
|
|
25526
|
+
const arch3 = text(parts[4], ARCH_MAX);
|
|
25527
|
+
if (arch3 && arch3 !== "(none)")
|
|
25528
|
+
item.arch = arch3;
|
|
25529
|
+
const size = integerText(parts[5]);
|
|
25530
|
+
if (size !== void 0)
|
|
25531
|
+
item.size_bytes = size;
|
|
25532
|
+
push(result2, item);
|
|
25533
|
+
}
|
|
25534
|
+
return result2;
|
|
25535
|
+
}
|
|
25536
|
+
function parseApk(stdout) {
|
|
25537
|
+
const result2 = [];
|
|
25538
|
+
for (const line of lines(stdout)) {
|
|
25539
|
+
const trimmed = line.trim();
|
|
25540
|
+
const match = /^(.+)-([0-9][^-\s]*-r\d+)\s/.exec(trimmed);
|
|
25451
25541
|
if (!match)
|
|
25452
25542
|
continue;
|
|
25453
|
-
const
|
|
25454
|
-
|
|
25455
|
-
const active = match[3];
|
|
25456
|
-
const sub = match[4];
|
|
25457
|
-
if (!unitToken || !load || !active || !sub)
|
|
25543
|
+
const name3 = nameOf(match[1]);
|
|
25544
|
+
if (!name3)
|
|
25458
25545
|
continue;
|
|
25459
|
-
|
|
25546
|
+
const item = { name: name3, version: versionOf(match[2]), manager: "apk" };
|
|
25547
|
+
const rest = trimmed.slice(match[0].length).trim().split(/\s+/);
|
|
25548
|
+
const arch3 = text(rest[0], ARCH_MAX);
|
|
25549
|
+
if (arch3)
|
|
25550
|
+
item.arch = arch3;
|
|
25551
|
+
push(result2, item);
|
|
25552
|
+
}
|
|
25553
|
+
return result2;
|
|
25554
|
+
}
|
|
25555
|
+
function parsePacman(stdout) {
|
|
25556
|
+
const result2 = [];
|
|
25557
|
+
for (const line of lines(stdout)) {
|
|
25558
|
+
const parts = line.trim().split(/\s+/);
|
|
25559
|
+
if (parts.length < 2)
|
|
25460
25560
|
continue;
|
|
25461
|
-
const name3 =
|
|
25561
|
+
const name3 = nameOf(parts[0]);
|
|
25462
25562
|
if (!name3)
|
|
25463
25563
|
continue;
|
|
25464
|
-
|
|
25465
|
-
name: name3,
|
|
25466
|
-
manager: "systemd",
|
|
25467
|
-
state: systemdState(active.toLowerCase(), sub.toLowerCase()),
|
|
25468
|
-
enabled: enablement.get(name3) ?? null
|
|
25469
|
-
};
|
|
25470
|
-
const description = text2(match[5] ?? "", DESCRIPTION_MAX);
|
|
25471
|
-
if (description)
|
|
25472
|
-
item.description = description;
|
|
25473
|
-
result2.push(item);
|
|
25564
|
+
push(result2, { name: name3, version: versionOf(parts[1]), manager: "pacman" });
|
|
25474
25565
|
}
|
|
25475
|
-
return
|
|
25566
|
+
return result2;
|
|
25476
25567
|
}
|
|
25477
|
-
function
|
|
25568
|
+
function parseSnap(stdout) {
|
|
25478
25569
|
const result2 = [];
|
|
25479
|
-
for (const line of
|
|
25480
|
-
const parts = line.split(
|
|
25481
|
-
if (parts.length <
|
|
25570
|
+
for (const line of lines(stdout)) {
|
|
25571
|
+
const parts = line.trim().split(/\s+/);
|
|
25572
|
+
if (parts.length < 2)
|
|
25482
25573
|
continue;
|
|
25483
|
-
|
|
25484
|
-
const statusText = (parts[1] ?? "").trim();
|
|
25485
|
-
const label = text2(parts[2], NAME_MAX2);
|
|
25486
|
-
if (!label)
|
|
25574
|
+
if (parts[0] === "Name" && parts[1] === "Version")
|
|
25487
25575
|
continue;
|
|
25488
|
-
|
|
25576
|
+
const name3 = nameOf(parts[0]);
|
|
25577
|
+
if (!name3)
|
|
25489
25578
|
continue;
|
|
25490
|
-
|
|
25491
|
-
|
|
25492
|
-
|
|
25493
|
-
|
|
25494
|
-
|
|
25495
|
-
|
|
25496
|
-
|
|
25497
|
-
|
|
25579
|
+
const item = { name: name3, version: versionOf(parts[1]), manager: "snap" };
|
|
25580
|
+
const publisher = text(parts[4], PUBLISHER_MAX).replace(/[✓*]+$/u, "").trim();
|
|
25581
|
+
if (publisher && publisher !== "-")
|
|
25582
|
+
item.publisher = publisher;
|
|
25583
|
+
push(result2, item);
|
|
25584
|
+
}
|
|
25585
|
+
return result2;
|
|
25586
|
+
}
|
|
25587
|
+
function parseBrewVersions(stdout, manager) {
|
|
25588
|
+
const result2 = [];
|
|
25589
|
+
for (const line of lines(stdout)) {
|
|
25590
|
+
const parts = line.trim().split(/\s+/);
|
|
25591
|
+
if (parts.length < 2)
|
|
25498
25592
|
continue;
|
|
25499
|
-
|
|
25500
|
-
|
|
25593
|
+
const name3 = nameOf(parts[0]);
|
|
25594
|
+
if (!name3)
|
|
25595
|
+
continue;
|
|
25596
|
+
push(result2, { name: name3, version: versionOf(parts[1]), manager });
|
|
25501
25597
|
}
|
|
25502
|
-
return
|
|
25598
|
+
return result2;
|
|
25503
25599
|
}
|
|
25504
|
-
function
|
|
25505
|
-
const
|
|
25506
|
-
|
|
25600
|
+
function parseNpmGlobal(json2) {
|
|
25601
|
+
const root = asRecord(parseJson(json2));
|
|
25602
|
+
const dependencies = asRecord(root?.dependencies);
|
|
25603
|
+
if (!dependencies)
|
|
25507
25604
|
return [];
|
|
25508
25605
|
const result2 = [];
|
|
25509
|
-
for (const value of
|
|
25510
|
-
const info =
|
|
25511
|
-
if (!info)
|
|
25606
|
+
for (const [rawName, value] of Object.entries(dependencies)) {
|
|
25607
|
+
const info = asRecord(value);
|
|
25608
|
+
if (!info || typeof info.version !== "string")
|
|
25512
25609
|
continue;
|
|
25513
|
-
const name3 =
|
|
25610
|
+
const name3 = nameOf(rawName);
|
|
25514
25611
|
if (!name3)
|
|
25515
25612
|
continue;
|
|
25516
|
-
|
|
25517
|
-
let state2;
|
|
25518
|
-
let enabled;
|
|
25519
|
-
switch (status) {
|
|
25520
|
-
case "started":
|
|
25521
|
-
state2 = "running";
|
|
25522
|
-
enabled = true;
|
|
25523
|
-
break;
|
|
25524
|
-
case "error":
|
|
25525
|
-
state2 = "failed";
|
|
25526
|
-
enabled = true;
|
|
25527
|
-
break;
|
|
25528
|
-
case "scheduled":
|
|
25529
|
-
state2 = "starting";
|
|
25530
|
-
enabled = true;
|
|
25531
|
-
break;
|
|
25532
|
-
case "none":
|
|
25533
|
-
case "stopped":
|
|
25534
|
-
state2 = "stopped";
|
|
25535
|
-
enabled = false;
|
|
25536
|
-
break;
|
|
25537
|
-
default:
|
|
25538
|
-
state2 = "unknown";
|
|
25539
|
-
enabled = null;
|
|
25540
|
-
}
|
|
25541
|
-
result2.push({ name: name3, manager: "brew", state: state2, enabled });
|
|
25613
|
+
push(result2, { name: name3, version: versionOf(info.version), manager: "npm-global" });
|
|
25542
25614
|
}
|
|
25543
|
-
return
|
|
25544
|
-
}
|
|
25545
|
-
var WINDOWS_STATES = {
|
|
25546
|
-
"4": "running",
|
|
25547
|
-
running: "running",
|
|
25548
|
-
"1": "stopped",
|
|
25549
|
-
stopped: "stopped",
|
|
25550
|
-
"2": "starting",
|
|
25551
|
-
startpending: "starting",
|
|
25552
|
-
"3": "stopping",
|
|
25553
|
-
stoppending: "stopping",
|
|
25554
|
-
"7": "stopped",
|
|
25555
|
-
paused: "stopped"
|
|
25556
|
-
};
|
|
25557
|
-
var WINDOWS_START_TYPES = {
|
|
25558
|
-
"2": true,
|
|
25559
|
-
automatic: true,
|
|
25560
|
-
"3": false,
|
|
25561
|
-
manual: false,
|
|
25562
|
-
"4": false,
|
|
25563
|
-
disabled: false
|
|
25564
|
-
};
|
|
25565
|
-
function windowsState(value) {
|
|
25566
|
-
if (typeof value === "number")
|
|
25567
|
-
return WINDOWS_STATES[String(value)] ?? "unknown";
|
|
25568
|
-
if (typeof value === "string")
|
|
25569
|
-
return WINDOWS_STATES[value.trim().toLowerCase()] ?? "unknown";
|
|
25570
|
-
return "unknown";
|
|
25571
|
-
}
|
|
25572
|
-
function windowsEnabled(value) {
|
|
25573
|
-
if (typeof value === "number")
|
|
25574
|
-
return WINDOWS_START_TYPES[String(value)] ?? null;
|
|
25575
|
-
if (typeof value === "string")
|
|
25576
|
-
return WINDOWS_START_TYPES[value.trim().toLowerCase()] ?? null;
|
|
25577
|
-
return null;
|
|
25615
|
+
return result2;
|
|
25578
25616
|
}
|
|
25579
|
-
function
|
|
25580
|
-
const
|
|
25581
|
-
|
|
25617
|
+
function parseMacApps(json2) {
|
|
25618
|
+
const root = asRecord(parseJson(json2));
|
|
25619
|
+
const items = root?.SPApplicationsDataType;
|
|
25620
|
+
if (!Array.isArray(items))
|
|
25582
25621
|
return [];
|
|
25583
|
-
const entries = Array.isArray(parsed) ? parsed : [parsed];
|
|
25584
25622
|
const result2 = [];
|
|
25585
|
-
|
|
25586
|
-
|
|
25623
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25624
|
+
for (const value of items) {
|
|
25625
|
+
const info = asRecord(value);
|
|
25587
25626
|
if (!info)
|
|
25588
25627
|
continue;
|
|
25589
|
-
const name3 =
|
|
25628
|
+
const name3 = nameOf(info._name);
|
|
25590
25629
|
if (!name3)
|
|
25591
25630
|
continue;
|
|
25592
|
-
const
|
|
25593
|
-
|
|
25594
|
-
|
|
25595
|
-
|
|
25596
|
-
|
|
25597
|
-
|
|
25598
|
-
|
|
25599
|
-
|
|
25600
|
-
|
|
25601
|
-
|
|
25631
|
+
const path = text(info.path, 4096);
|
|
25632
|
+
if (!isApplicationPath(path))
|
|
25633
|
+
continue;
|
|
25634
|
+
const version6 = versionOf(info.version);
|
|
25635
|
+
const key = `${name3}\0${version6}`;
|
|
25636
|
+
if (seen.has(key))
|
|
25637
|
+
continue;
|
|
25638
|
+
seen.add(key);
|
|
25639
|
+
const item = { name: name3, version: version6, manager: "macos-app" };
|
|
25640
|
+
const source = text(info.obtained_from, 60);
|
|
25641
|
+
if (source === "apple")
|
|
25642
|
+
item.publisher = "Apple";
|
|
25643
|
+
else if (source === "mac_app_store")
|
|
25644
|
+
item.publisher = "App Store";
|
|
25645
|
+
push(result2, item);
|
|
25602
25646
|
}
|
|
25603
|
-
return
|
|
25647
|
+
return result2;
|
|
25648
|
+
}
|
|
25649
|
+
function parseWindowsPrograms(json2) {
|
|
25650
|
+
const parsed = parseJson(json2);
|
|
25651
|
+
const entries = Array.isArray(parsed) ? parsed : [parsed];
|
|
25652
|
+
const result2 = [];
|
|
25653
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25654
|
+
for (const value of entries) {
|
|
25655
|
+
const info = asRecord(value);
|
|
25656
|
+
if (!info)
|
|
25657
|
+
continue;
|
|
25658
|
+
const name3 = nameOf(info.DisplayName);
|
|
25659
|
+
if (!name3)
|
|
25660
|
+
continue;
|
|
25661
|
+
const version6 = versionOf(info.DisplayVersion);
|
|
25662
|
+
const key = `${name3}\0${version6}`;
|
|
25663
|
+
if (seen.has(key))
|
|
25664
|
+
continue;
|
|
25665
|
+
seen.add(key);
|
|
25666
|
+
const item = { name: name3, version: version6, manager: "windows" };
|
|
25667
|
+
const publisher = text(info.Publisher, PUBLISHER_MAX);
|
|
25668
|
+
if (publisher)
|
|
25669
|
+
item.publisher = publisher;
|
|
25670
|
+
const size = sizeFromKb(info.EstimatedSize);
|
|
25671
|
+
if (size !== void 0)
|
|
25672
|
+
item.size_bytes = size;
|
|
25673
|
+
const installedOn = installDate(info.InstallDate);
|
|
25674
|
+
if (installedOn)
|
|
25675
|
+
item.installed_on = installedOn;
|
|
25676
|
+
push(result2, item);
|
|
25677
|
+
}
|
|
25678
|
+
return result2;
|
|
25604
25679
|
}
|
|
25605
25680
|
|
|
25606
|
-
// dist/inventory/parsers/
|
|
25607
|
-
var
|
|
25608
|
-
var
|
|
25609
|
-
|
|
25610
|
-
|
|
25611
|
-
|
|
25612
|
-
|
|
25613
|
-
|
|
25614
|
-
|
|
25615
|
-
|
|
25616
|
-
|
|
25617
|
-
|
|
25618
|
-
|
|
25619
|
-
|
|
25620
|
-
|
|
25621
|
-
|
|
25622
|
-
|
|
25623
|
-
|
|
25624
|
-
|
|
25625
|
-
|
|
25626
|
-
|
|
25627
|
-
|
|
25628
|
-
|
|
25629
|
-
|
|
25630
|
-
|
|
25631
|
-
|
|
25632
|
-
|
|
25633
|
-
|
|
25634
|
-
|
|
25681
|
+
// dist/inventory/parsers/sections.js
|
|
25682
|
+
var SECTION_MARKER = "@@conbridge-section";
|
|
25683
|
+
var MARKER_PATTERN = /^@@conbridge-section ([a-z0-9-]{1,32})$/;
|
|
25684
|
+
function splitSections(output2) {
|
|
25685
|
+
const sections = /* @__PURE__ */ new Map();
|
|
25686
|
+
if (typeof output2 !== "string")
|
|
25687
|
+
return { sections, complete: false };
|
|
25688
|
+
const lines4 = output2.split("\n").map((line) => line.endsWith("\r") ? line.slice(0, -1) : line);
|
|
25689
|
+
let current;
|
|
25690
|
+
let buffer = [];
|
|
25691
|
+
let complete = false;
|
|
25692
|
+
const flush = () => {
|
|
25693
|
+
if (current === void 0)
|
|
25694
|
+
return;
|
|
25695
|
+
let end = buffer.length;
|
|
25696
|
+
while (end > 0 && buffer[end - 1] === "")
|
|
25697
|
+
end -= 1;
|
|
25698
|
+
const content2 = buffer.slice(0, end).join("\n");
|
|
25699
|
+
if (!sections.has(current))
|
|
25700
|
+
sections.set(current, content2);
|
|
25701
|
+
current = void 0;
|
|
25702
|
+
buffer = [];
|
|
25703
|
+
};
|
|
25704
|
+
for (const line of lines4) {
|
|
25705
|
+
const match = MARKER_PATTERN.exec(line);
|
|
25706
|
+
if (!match) {
|
|
25707
|
+
if (current !== void 0)
|
|
25708
|
+
buffer.push(line);
|
|
25709
|
+
continue;
|
|
25710
|
+
}
|
|
25711
|
+
flush();
|
|
25712
|
+
const name3 = match[1] ?? "";
|
|
25713
|
+
if (name3 === "end") {
|
|
25714
|
+
complete = true;
|
|
25715
|
+
break;
|
|
25716
|
+
}
|
|
25717
|
+
current = name3;
|
|
25718
|
+
}
|
|
25719
|
+
if (!complete)
|
|
25720
|
+
flush();
|
|
25721
|
+
return { sections, complete };
|
|
25722
|
+
}
|
|
25723
|
+
|
|
25724
|
+
// dist/inventory/parsers/system.js
|
|
25725
|
+
var RELEASE_KEYS = {
|
|
25726
|
+
ID: "id",
|
|
25727
|
+
VERSION_ID: "versionId",
|
|
25728
|
+
VERSION_CODENAME: "codename",
|
|
25729
|
+
PRETTY_NAME: "prettyName",
|
|
25730
|
+
NAME: "name",
|
|
25731
|
+
VERSION: "version"
|
|
25635
25732
|
};
|
|
25636
|
-
function
|
|
25637
|
-
|
|
25638
|
-
|
|
25639
|
-
|
|
25640
|
-
|
|
25641
|
-
|
|
25642
|
-
|
|
25733
|
+
function unquote(raw) {
|
|
25734
|
+
const value = raw.trim();
|
|
25735
|
+
if (value.length >= 2 && value.startsWith('"')) {
|
|
25736
|
+
const end = value.lastIndexOf('"');
|
|
25737
|
+
if (end > 0)
|
|
25738
|
+
return value.slice(1, end).replace(/\\"/g, '"').trim();
|
|
25739
|
+
}
|
|
25740
|
+
if (value.length >= 2 && value.startsWith("'")) {
|
|
25741
|
+
const end = value.lastIndexOf("'");
|
|
25742
|
+
if (end > 0)
|
|
25743
|
+
return value.slice(1, end).trim();
|
|
25744
|
+
}
|
|
25745
|
+
return value;
|
|
25643
25746
|
}
|
|
25644
|
-
function
|
|
25645
|
-
|
|
25747
|
+
function parseOsRelease(text4) {
|
|
25748
|
+
const result2 = {};
|
|
25749
|
+
if (typeof text4 !== "string")
|
|
25750
|
+
return result2;
|
|
25751
|
+
for (const rawLine of text4.split(/\r?\n/)) {
|
|
25752
|
+
const line = rawLine.trim();
|
|
25753
|
+
if (!line || line.startsWith("#"))
|
|
25754
|
+
continue;
|
|
25755
|
+
const separator = line.indexOf("=");
|
|
25756
|
+
if (separator <= 0)
|
|
25757
|
+
continue;
|
|
25758
|
+
const key = line.slice(0, separator).trim();
|
|
25759
|
+
const field = RELEASE_KEYS[key];
|
|
25760
|
+
if (!field)
|
|
25761
|
+
continue;
|
|
25762
|
+
const value = unquote(line.slice(separator + 1));
|
|
25763
|
+
if (!value)
|
|
25764
|
+
continue;
|
|
25765
|
+
result2[field] = value;
|
|
25766
|
+
}
|
|
25767
|
+
return result2;
|
|
25646
25768
|
}
|
|
25647
|
-
function
|
|
25769
|
+
function parseSwVers(text4) {
|
|
25770
|
+
const result2 = {};
|
|
25771
|
+
if (typeof text4 !== "string")
|
|
25772
|
+
return result2;
|
|
25773
|
+
for (const rawLine of text4.split(/\r?\n/)) {
|
|
25774
|
+
const line = rawLine.trim();
|
|
25775
|
+
if (!line)
|
|
25776
|
+
continue;
|
|
25777
|
+
const separator = line.indexOf(":");
|
|
25778
|
+
if (separator <= 0)
|
|
25779
|
+
continue;
|
|
25780
|
+
const key = line.slice(0, separator).trim();
|
|
25781
|
+
const value = line.slice(separator + 1).trim();
|
|
25782
|
+
if (!value)
|
|
25783
|
+
continue;
|
|
25784
|
+
if (key === "ProductName")
|
|
25785
|
+
result2.productName = value;
|
|
25786
|
+
else if (key === "ProductVersion")
|
|
25787
|
+
result2.productVersion = value;
|
|
25788
|
+
else if (key === "BuildVersion")
|
|
25789
|
+
result2.buildVersion = value;
|
|
25790
|
+
}
|
|
25791
|
+
return result2;
|
|
25792
|
+
}
|
|
25793
|
+
function asRecord2(value) {
|
|
25648
25794
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
25649
25795
|
}
|
|
25650
|
-
function
|
|
25651
|
-
|
|
25652
|
-
return [];
|
|
25653
|
-
return stdout.split(/\r?\n/).filter((line) => line.trim() !== "");
|
|
25796
|
+
function stringField(value) {
|
|
25797
|
+
return typeof value === "string" ? value.trim() : "";
|
|
25654
25798
|
}
|
|
25655
|
-
function
|
|
25656
|
-
|
|
25657
|
-
|
|
25799
|
+
function windowsArch(value) {
|
|
25800
|
+
const arch3 = value.trim();
|
|
25801
|
+
switch (arch3.toLowerCase()) {
|
|
25802
|
+
case "64-bit":
|
|
25803
|
+
return "x64";
|
|
25804
|
+
case "arm 64-bit":
|
|
25805
|
+
case "arm64":
|
|
25806
|
+
return "arm64";
|
|
25807
|
+
case "32-bit":
|
|
25808
|
+
return "x86";
|
|
25809
|
+
default:
|
|
25810
|
+
return arch3;
|
|
25811
|
+
}
|
|
25812
|
+
}
|
|
25813
|
+
function parseWindowsOs(json2) {
|
|
25814
|
+
if (typeof json2 !== "string")
|
|
25815
|
+
return null;
|
|
25816
|
+
let parsed;
|
|
25658
25817
|
try {
|
|
25659
|
-
|
|
25818
|
+
parsed = JSON.parse(json2);
|
|
25660
25819
|
} catch {
|
|
25661
|
-
return
|
|
25820
|
+
return null;
|
|
25662
25821
|
}
|
|
25822
|
+
const info = asRecord2(parsed);
|
|
25823
|
+
if (!info)
|
|
25824
|
+
return null;
|
|
25825
|
+
const caption = stringField(info.Caption).replace(/^Microsoft\s+/i, "");
|
|
25826
|
+
const version6 = stringField(info.Version);
|
|
25827
|
+
if (!caption || !version6)
|
|
25828
|
+
return null;
|
|
25829
|
+
const buildNumber = stringField(info.BuildNumber);
|
|
25830
|
+
const ubr = info.UBR;
|
|
25831
|
+
const build = typeof ubr === "number" ? `${buildNumber}.${ubr}` : buildNumber;
|
|
25832
|
+
return { caption, version: version6, build, arch: windowsArch(stringField(info.OSArchitecture)) };
|
|
25663
25833
|
}
|
|
25664
|
-
|
|
25665
|
-
|
|
25666
|
-
|
|
25834
|
+
var MODEL_PLACEHOLDERS = /* @__PURE__ */ new Set(["to be filled by o.e.m.", "system product name", "default string"]);
|
|
25835
|
+
function cleanModel(text4) {
|
|
25836
|
+
if (typeof text4 !== "string")
|
|
25837
|
+
return null;
|
|
25838
|
+
const cleaned = text4.replace(/\0/g, "").trim().slice(0, 200);
|
|
25839
|
+
if (!cleaned)
|
|
25840
|
+
return null;
|
|
25841
|
+
if (MODEL_PLACEHOLDERS.has(cleaned.toLowerCase()))
|
|
25842
|
+
return null;
|
|
25843
|
+
return cleaned;
|
|
25667
25844
|
}
|
|
25668
|
-
function
|
|
25669
|
-
|
|
25670
|
-
|
|
25671
|
-
|
|
25672
|
-
|
|
25673
|
-
|
|
25674
|
-
|
|
25675
|
-
return void 0;
|
|
25676
|
-
return raw.slice(0, 12);
|
|
25845
|
+
function firstNonEmptyLine(output2) {
|
|
25846
|
+
for (const line of output2.split(/\r?\n/)) {
|
|
25847
|
+
const trimmed = line.trim();
|
|
25848
|
+
if (trimmed)
|
|
25849
|
+
return trimmed;
|
|
25850
|
+
}
|
|
25851
|
+
return "";
|
|
25677
25852
|
}
|
|
25678
|
-
function
|
|
25853
|
+
function group(match) {
|
|
25854
|
+
if (!match)
|
|
25855
|
+
return null;
|
|
25856
|
+
const value = match[1];
|
|
25679
25857
|
if (typeof value !== "string")
|
|
25680
|
-
return
|
|
25681
|
-
const
|
|
25682
|
-
return
|
|
25858
|
+
return null;
|
|
25859
|
+
const trimmed = value.trim();
|
|
25860
|
+
return trimmed ? trimmed : null;
|
|
25683
25861
|
}
|
|
25684
|
-
function
|
|
25685
|
-
|
|
25686
|
-
return void 0;
|
|
25687
|
-
const rounded = Math.round(value);
|
|
25688
|
-
return rounded >= 0 && Number.isSafeInteger(rounded) ? rounded : void 0;
|
|
25862
|
+
function capture(pattern, value) {
|
|
25863
|
+
return group(pattern.exec(value));
|
|
25689
25864
|
}
|
|
25690
|
-
|
|
25691
|
-
|
|
25692
|
-
|
|
25693
|
-
|
|
25694
|
-
|
|
25695
|
-
|
|
25696
|
-
|
|
25697
|
-
|
|
25698
|
-
|
|
25699
|
-
|
|
25700
|
-
|
|
25701
|
-
|
|
25702
|
-
|
|
25703
|
-
|
|
25704
|
-
|
|
25705
|
-
|
|
25706
|
-
|
|
25707
|
-
|
|
25708
|
-
|
|
25709
|
-
|
|
25710
|
-
|
|
25865
|
+
var GENERIC_VERSION = /^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/;
|
|
25866
|
+
var VERSION_PARSERS = {
|
|
25867
|
+
node: (output2) => capture(/^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/, firstNonEmptyLine(output2)),
|
|
25868
|
+
python: (output2) => capture(/^Python\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
|
|
25869
|
+
php: (output2) => capture(/^PHP\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
|
|
25870
|
+
ruby: (output2) => capture(/^ruby\s+(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)/, firstNonEmptyLine(output2)),
|
|
25871
|
+
go: (output2) => capture(/^go version go(\S+)/, firstNonEmptyLine(output2)),
|
|
25872
|
+
java: (output2) => capture(/^(?:openjdk|java)\s+version\s+"([^"]+)"/, firstNonEmptyLine(output2)),
|
|
25873
|
+
deno: (output2) => capture(/^deno\s+(\S+)/, firstNonEmptyLine(output2)),
|
|
25874
|
+
perl: (output2) => capture(/^v?(\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?)\s*$/, firstNonEmptyLine(output2)) ?? capture(/\(v(\d+\.\d+(?:\.\d+)?)\)/, output2),
|
|
25875
|
+
rust: (output2) => capture(/^rustc\s+(\S+)/, firstNonEmptyLine(output2)),
|
|
25876
|
+
nginx: (output2) => capture(/nginx\/(\S+)/, output2),
|
|
25877
|
+
apache: (output2) => capture(/Server version:\s*Apache\/(\S+)/, output2),
|
|
25878
|
+
caddy: (output2) => capture(/^v?(\d\S*)/, firstNonEmptyLine(output2)),
|
|
25879
|
+
haproxy: (output2) => capture(/^HAProxy version\s+(\S+)/, firstNonEmptyLine(output2)),
|
|
25880
|
+
traefik: (output2) => capture(/^Version:\s*(\S+)/m, output2),
|
|
25881
|
+
mysql: (output2) => /MariaDB/i.test(output2) ? null : capture(/\bVer\s+(\S+)/, output2),
|
|
25882
|
+
mariadb: (output2) => capture(/(\d+\.\d+(?:\.\d+)?)-MariaDB/, output2),
|
|
25883
|
+
postgresql: (output2) => capture(/PostgreSQL\)\s+(\S+)/, output2),
|
|
25884
|
+
redis: (output2) => capture(/\bv=(\S+)/, output2),
|
|
25885
|
+
mongodb: (output2) => capture(/db version v(\S+)/, output2),
|
|
25886
|
+
sqlite: (output2) => capture(/^(\d+\.\d+(?:\.\d+)?)/, firstNonEmptyLine(output2)),
|
|
25887
|
+
docker: (output2) => capture(/Docker version\s+([^,\s]+)/, output2),
|
|
25888
|
+
podman: (output2) => capture(/podman version\s+(\S+)/, output2),
|
|
25889
|
+
kubectl: (output2) => capture(/Client Version:\s*v?(\S+)/, output2),
|
|
25890
|
+
git: (output2) => capture(/git version\s+(\S+)/, output2),
|
|
25891
|
+
openssl: (output2) => capture(/^(?:OpenSSL|LibreSSL)\s+(\S+)/, firstNonEmptyLine(output2)),
|
|
25892
|
+
openssh: (output2) => capture(/^OpenSSH_([^,\s]+)/, firstNonEmptyLine(output2)),
|
|
25893
|
+
composer: (output2) => capture(/Composer version\s+(\S+)/, output2),
|
|
25894
|
+
curl: (output2) => capture(/^curl\s+(\S+)/, firstNonEmptyLine(output2)),
|
|
25895
|
+
powershell: (output2) => capture(/^PowerShell\s+(\S+)/, firstNonEmptyLine(output2)),
|
|
25896
|
+
bash: (output2) => capture(/version\s+(\d+\.\d+(?:\.\d+)?)/, firstNonEmptyLine(output2)),
|
|
25897
|
+
certbot: (output2) => capture(/^certbot\s+(\S+)/, firstNonEmptyLine(output2))
|
|
25898
|
+
};
|
|
25899
|
+
function extractVersion(key, output2) {
|
|
25900
|
+
if (typeof key !== "string" || typeof output2 !== "string")
|
|
25901
|
+
return null;
|
|
25902
|
+
const parser = VERSION_PARSERS[key];
|
|
25903
|
+
const version6 = parser ? parser(output2) : capture(GENERIC_VERSION, firstNonEmptyLine(output2));
|
|
25904
|
+
if (!version6)
|
|
25905
|
+
return null;
|
|
25906
|
+
return version6.slice(0, 128);
|
|
25711
25907
|
}
|
|
25712
|
-
|
|
25713
|
-
|
|
25714
|
-
|
|
25715
|
-
|
|
25716
|
-
|
|
25717
|
-
|
|
25718
|
-
|
|
25908
|
+
|
|
25909
|
+
// dist/inventory/ssh.js
|
|
25910
|
+
var SSH_INVENTORY_TIMEOUT_S = 120;
|
|
25911
|
+
var SSH_INVENTORY_MAX_BYTES = 8 * 1024 * 1024;
|
|
25912
|
+
var SCRIPT_BODY = [
|
|
25913
|
+
`M="${SECTION_MARKER}"`,
|
|
25914
|
+
"export LC_ALL=C",
|
|
25915
|
+
'echo "$M os-release"',
|
|
25916
|
+
"{ cat /etc/os-release 2>/dev/null || cat /usr/lib/os-release 2>/dev/null; }",
|
|
25917
|
+
'echo "$M uname"',
|
|
25918
|
+
"uname -srm 2>/dev/null",
|
|
25919
|
+
'if command -v dpkg-query >/dev/null 2>&1; then echo "$M dpkg"; dpkg-query -W -f="\\${Package}\\t\\${Version}\\t\\${Architecture}\\t\\${Installed-Size}\\t\\${db:Status-Abbrev}\\t\\${source:Package}\\t\\${source:Version}\\n" 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; elif command -v rpm >/dev/null 2>&1; then echo "$M rpm"; rpm -qa --qf "%{NAME}\\t%{EPOCH}\\t%{VERSION}\\t%{RELEASE}\\t%{ARCH}\\t%{SIZE}\\n" 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; elif command -v apk >/dev/null 2>&1; then echo "$M apk"; apk list --installed 2>/dev/null; r=$?; echo "$M rc"; echo "$r"; fi',
|
|
25920
|
+
'echo "$M end"'
|
|
25921
|
+
].join("; ");
|
|
25922
|
+
var SSH_INVENTORY_SCRIPT = `/bin/sh -c '${SCRIPT_BODY}'`;
|
|
25923
|
+
var PACKAGE_SECTIONS = Object.freeze([
|
|
25924
|
+
["dpkg", parseDpkg],
|
|
25925
|
+
["rpm", parseRpm],
|
|
25926
|
+
["apk", parseApk]
|
|
25927
|
+
]);
|
|
25928
|
+
function selectInventoryHosts(ids, hosts) {
|
|
25929
|
+
const byId = new Map(hosts.map((host) => [host.resource_id, host]));
|
|
25930
|
+
const seen = /* @__PURE__ */ new Set();
|
|
25931
|
+
const selected = [];
|
|
25932
|
+
for (const id of ids) {
|
|
25933
|
+
const host = byId.get(id);
|
|
25934
|
+
if (!host || seen.has(id))
|
|
25719
25935
|
continue;
|
|
25720
|
-
|
|
25721
|
-
|
|
25722
|
-
|
|
25936
|
+
seen.add(id);
|
|
25937
|
+
selected.push(host);
|
|
25938
|
+
}
|
|
25939
|
+
return selected;
|
|
25940
|
+
}
|
|
25941
|
+
function familyOf(kernelName) {
|
|
25942
|
+
const name3 = kernelName.toLowerCase();
|
|
25943
|
+
if (name3 === "linux")
|
|
25944
|
+
return "linux";
|
|
25945
|
+
if (name3 === "darwin")
|
|
25946
|
+
return "darwin";
|
|
25947
|
+
return "other";
|
|
25948
|
+
}
|
|
25949
|
+
function osFrom(osRelease2, uname) {
|
|
25950
|
+
const release2 = parseOsRelease(osRelease2);
|
|
25951
|
+
const [kernelName = "", kernel = "", ...rest] = uname.trim().split(/\s+/);
|
|
25952
|
+
const arch3 = rest.at(-1) ?? "";
|
|
25953
|
+
const os = {
|
|
25954
|
+
family: familyOf(kernelName),
|
|
25955
|
+
name: release2.prettyName ?? release2.name ?? (kernelName || "Unknown"),
|
|
25956
|
+
version: release2.versionId ?? release2.version ?? "",
|
|
25957
|
+
arch: arch3.slice(0, 32),
|
|
25958
|
+
...kernel ? { kernel } : {},
|
|
25959
|
+
...release2.id ? { distro_id: release2.id } : {},
|
|
25960
|
+
...release2.versionId ? { distro_version: release2.versionId } : {},
|
|
25961
|
+
...release2.codename ? { distro_codename: release2.codename } : {}
|
|
25962
|
+
};
|
|
25963
|
+
return inventoryOsSchema.safeParse(os).success ? os : { family: familyOf(kernelName), name: kernelName || "Unknown", version: "", arch: "" };
|
|
25964
|
+
}
|
|
25965
|
+
function buildSshSnapshot(output2, now = /* @__PURE__ */ new Date(), durationMs = 0) {
|
|
25966
|
+
const { sections, complete } = splitSections(output2);
|
|
25967
|
+
if (!complete)
|
|
25968
|
+
return null;
|
|
25969
|
+
const coverage = [];
|
|
25970
|
+
const duration3 = Math.max(0, Math.round(durationMs));
|
|
25971
|
+
const os = osFrom(sections.get("os-release") ?? "", sections.get("uname") ?? "");
|
|
25972
|
+
coverage.push({ collector: "os", status: sections.has("os-release") || sections.has("uname") ? "ok" : "failed", count: 0, duration_ms: duration3 });
|
|
25973
|
+
let packages = [];
|
|
25974
|
+
const found = PACKAGE_SECTIONS.find(([name3]) => sections.has(name3));
|
|
25975
|
+
if (found) {
|
|
25976
|
+
const [name3, parse3] = found;
|
|
25977
|
+
if ((sections.get("rc") ?? "").trim() === "0") {
|
|
25978
|
+
packages = parse3(sections.get(name3) ?? "").filter((item) => inventoryPackageSchema.safeParse(item).success);
|
|
25979
|
+
coverage.push({ collector: name3, status: packages.length >= INVENTORY_LIMITS.packages ? "truncated" : "ok", count: packages.length, duration_ms: duration3 });
|
|
25980
|
+
} else {
|
|
25981
|
+
coverage.push({ collector: name3, status: "failed", count: 0, duration_ms: duration3 });
|
|
25982
|
+
}
|
|
25983
|
+
} else {
|
|
25984
|
+
coverage.push({ collector: "packages", status: "unavailable", count: 0, duration_ms: duration3 });
|
|
25723
25985
|
}
|
|
25724
|
-
return
|
|
25986
|
+
return inventorySnapshotSchema.parse({
|
|
25987
|
+
schema: 1,
|
|
25988
|
+
collected_at: now.toISOString(),
|
|
25989
|
+
agent_version: AGENT_VERSION,
|
|
25990
|
+
os,
|
|
25991
|
+
packages: packages.slice(0, INVENTORY_LIMITS.packages),
|
|
25992
|
+
software: [],
|
|
25993
|
+
services: [],
|
|
25994
|
+
containers: [],
|
|
25995
|
+
images: [],
|
|
25996
|
+
pods: [],
|
|
25997
|
+
coverage: coverage.filter((entry) => inventoryCoverageSchema.safeParse(entry).success)
|
|
25998
|
+
});
|
|
25725
25999
|
}
|
|
25726
|
-
function
|
|
25727
|
-
|
|
25728
|
-
|
|
25729
|
-
|
|
26000
|
+
function defaultSshInventoryExec(paths, binaries, env) {
|
|
26001
|
+
return (host) => runProcess(binaries.ssh, buildSshArgs(paths, host, SSH_INVENTORY_SCRIPT), {
|
|
26002
|
+
timeoutMs: SSH_INVENTORY_TIMEOUT_S * 1e3,
|
|
26003
|
+
maxBytes: SSH_INVENTORY_MAX_BYTES,
|
|
26004
|
+
env: sshChildEnv(env)
|
|
26005
|
+
});
|
|
25730
26006
|
}
|
|
25731
|
-
function
|
|
25732
|
-
|
|
25733
|
-
|
|
25734
|
-
|
|
25735
|
-
|
|
25736
|
-
|
|
25737
|
-
|
|
25738
|
-
|
|
25739
|
-
|
|
25740
|
-
|
|
25741
|
-
|
|
25742
|
-
|
|
25743
|
-
|
|
25744
|
-
|
|
25745
|
-
|
|
25746
|
-
|
|
25747
|
-
|
|
25748
|
-
|
|
25749
|
-
if (ports.length >= MAX_PORTS)
|
|
25750
|
-
break;
|
|
25751
|
-
}
|
|
25752
|
-
return ports;
|
|
26007
|
+
async function collectSshHostInventory(host, exec, now = () => /* @__PURE__ */ new Date()) {
|
|
26008
|
+
const result2 = await exec(host);
|
|
26009
|
+
if (result2.spawnError)
|
|
26010
|
+
return { ok: false, reason: "ssh could not be started" };
|
|
26011
|
+
if (isHostKeyFailure(result2))
|
|
26012
|
+
return { ok: false, reason: "host key does not match the pin" };
|
|
26013
|
+
if (result2.timedOut)
|
|
26014
|
+
return { ok: false, reason: `timed out after ${SSH_INVENTORY_TIMEOUT_S} s` };
|
|
26015
|
+
if (result2.truncated)
|
|
26016
|
+
return { ok: false, reason: "output over 8 MB" };
|
|
26017
|
+
if (result2.exitCode === 255)
|
|
26018
|
+
return { ok: false, reason: "unreachable or authentication failed" };
|
|
26019
|
+
if (result2.exitCode !== 0)
|
|
26020
|
+
return { ok: false, reason: `script exited with ${result2.exitCode === null ? "a signal" : String(result2.exitCode)}` };
|
|
26021
|
+
const snapshot = buildSshSnapshot(result2.stdout, now(), result2.durationMs);
|
|
26022
|
+
if (!snapshot)
|
|
26023
|
+
return { ok: false, reason: "incomplete output" };
|
|
26024
|
+
return { ok: true, snapshot };
|
|
25753
26025
|
}
|
|
25754
|
-
|
|
25755
|
-
|
|
25756
|
-
|
|
25757
|
-
|
|
25758
|
-
|
|
25759
|
-
|
|
25760
|
-
|
|
25761
|
-
|
|
25762
|
-
const
|
|
25763
|
-
const
|
|
25764
|
-
|
|
25765
|
-
|
|
25766
|
-
|
|
25767
|
-
|
|
25768
|
-
|
|
25769
|
-
|
|
25770
|
-
|
|
25771
|
-
|
|
26026
|
+
|
|
26027
|
+
// dist/inventory/loop.js
|
|
26028
|
+
var SEND_SPACING_MS = 2e3;
|
|
26029
|
+
var HOST_MIN_INTERVAL_MS = 6e4;
|
|
26030
|
+
function encodeSnapshot(snapshot, requestId, runId = (0, import_node_crypto9.randomUUID)(), resourceId) {
|
|
26031
|
+
const gz = (0, import_node_zlib.gzipSync)(Buffer.from(JSON.stringify(snapshot), "utf8"), { level: 9 });
|
|
26032
|
+
if (gz.byteLength > INVENTORY_MAX_COMPRESSED_BYTES)
|
|
26033
|
+
return null;
|
|
26034
|
+
const sha2563 = (0, import_node_crypto9.createHash)("sha256").update(gz).digest("hex");
|
|
26035
|
+
const data = gz.toString("base64");
|
|
26036
|
+
const total = Math.max(1, Math.ceil(data.length / INVENTORY_PART_CHARS));
|
|
26037
|
+
return Array.from({ length: total }, (_, sequence) => ({
|
|
26038
|
+
run_id: runId,
|
|
26039
|
+
request_id: requestId,
|
|
26040
|
+
sequence,
|
|
26041
|
+
total,
|
|
26042
|
+
sha256: sha2563,
|
|
26043
|
+
data: data.slice(sequence * INVENTORY_PART_CHARS, (sequence + 1) * INVENTORY_PART_CHARS),
|
|
26044
|
+
...resourceId !== void 0 ? { resource_id: resourceId } : {}
|
|
26045
|
+
}));
|
|
25772
26046
|
}
|
|
25773
|
-
|
|
25774
|
-
|
|
25775
|
-
|
|
25776
|
-
|
|
25777
|
-
|
|
25778
|
-
|
|
25779
|
-
|
|
25780
|
-
|
|
25781
|
-
|
|
25782
|
-
|
|
25783
|
-
|
|
25784
|
-
|
|
25785
|
-
|
|
26047
|
+
var InventoryLoop = class {
|
|
26048
|
+
#options;
|
|
26049
|
+
#logger;
|
|
26050
|
+
#intervalS = null;
|
|
26051
|
+
/** `ssh_hosts` of the latest config; missing means none. */
|
|
26052
|
+
#sshHostIds = [];
|
|
26053
|
+
/** When the last snapshot's parts finished sending (any snapshot, this connection). */
|
|
26054
|
+
#lastSendEndMs = null;
|
|
26055
|
+
/** When each SSH host's snapshot was last sent (this connection). */
|
|
26056
|
+
#hostSentAtMs = /* @__PURE__ */ new Map();
|
|
26057
|
+
#timer = null;
|
|
26058
|
+
#running = false;
|
|
26059
|
+
#stopped = false;
|
|
26060
|
+
constructor(options) {
|
|
26061
|
+
this.#options = options;
|
|
26062
|
+
this.#logger = options.logger ?? silentLogger;
|
|
25786
26063
|
}
|
|
25787
|
-
|
|
25788
|
-
|
|
25789
|
-
function podmanComposeProject(value) {
|
|
25790
|
-
const labels = asRecord3(value);
|
|
25791
|
-
if (!labels)
|
|
25792
|
-
return void 0;
|
|
25793
|
-
for (const key of ["com.docker.compose.project", "io.podman.compose.project"]) {
|
|
25794
|
-
const project = nameOf2(labels[key]);
|
|
25795
|
-
if (project)
|
|
25796
|
-
return project;
|
|
26064
|
+
get enabled() {
|
|
26065
|
+
return this.#intervalS !== null;
|
|
25797
26066
|
}
|
|
25798
|
-
|
|
25799
|
-
|
|
25800
|
-
|
|
25801
|
-
|
|
25802
|
-
|
|
25803
|
-
|
|
25804
|
-
|
|
25805
|
-
|
|
25806
|
-
|
|
25807
|
-
|
|
25808
|
-
|
|
25809
|
-
|
|
25810
|
-
|
|
26067
|
+
apply(config2) {
|
|
26068
|
+
if (this.#stopped)
|
|
26069
|
+
return;
|
|
26070
|
+
this.#sshHostIds = config2.enabled ? [...new Set(config2.ssh_hosts ?? [])] : [];
|
|
26071
|
+
if (!config2.enabled) {
|
|
26072
|
+
if (this.#intervalS !== null)
|
|
26073
|
+
this.#logger.info("software inventory stopped");
|
|
26074
|
+
this.#intervalS = null;
|
|
26075
|
+
this.#clear();
|
|
26076
|
+
return;
|
|
26077
|
+
}
|
|
26078
|
+
if (this.#intervalS === config2.interval_s && this.#timer)
|
|
26079
|
+
return;
|
|
26080
|
+
const first = this.#intervalS === null;
|
|
26081
|
+
this.#intervalS = config2.interval_s;
|
|
26082
|
+
this.#clear();
|
|
26083
|
+
const jitter = (this.#options.firstRunMs ?? (() => 5e3 + Math.floor(Math.random() * 25e3)))();
|
|
26084
|
+
const last = this.#options.lastSentAtMs?.() ?? null;
|
|
26085
|
+
const now = (this.#options.now ?? Date.now)();
|
|
26086
|
+
const due = last === null ? jitter : Math.max(jitter, last + config2.interval_s * 1e3 - now);
|
|
26087
|
+
this.#schedule(first ? due : config2.interval_s * 1e3);
|
|
26088
|
+
this.#logger.info("software inventory scheduled", { interval_s: config2.interval_s });
|
|
25811
26089
|
}
|
|
25812
|
-
|
|
25813
|
-
|
|
25814
|
-
|
|
25815
|
-
|
|
25816
|
-
|
|
25817
|
-
const match = /^(\d+(?:\.\d+)?)\s*([a-z]+)$/i.exec(value.trim());
|
|
25818
|
-
if (!match)
|
|
25819
|
-
return null;
|
|
25820
|
-
const amount = Number(match[1]);
|
|
25821
|
-
const multiplier = BYTE_MULTIPLIERS[(match[2] ?? "").toLowerCase()];
|
|
25822
|
-
if (multiplier === void 0 || !Number.isFinite(amount) || amount < 0)
|
|
25823
|
-
return null;
|
|
25824
|
-
const bytes3 = Math.round(amount * multiplier);
|
|
25825
|
-
return Number.isSafeInteger(bytes3) ? bytes3 : null;
|
|
25826
|
-
}
|
|
25827
|
-
function parseDockerTime(value) {
|
|
25828
|
-
if (typeof value !== "string")
|
|
25829
|
-
return null;
|
|
25830
|
-
const match = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) ([+-]\d{2})(\d{2})/.exec(value.trim());
|
|
25831
|
-
if (!match)
|
|
25832
|
-
return null;
|
|
25833
|
-
return `${match[1]}T${match[2]}${match[3]}:${match[4]}`;
|
|
25834
|
-
}
|
|
25835
|
-
function parseDockerPs(jsonLines) {
|
|
25836
|
-
const result2 = [];
|
|
25837
|
-
for (const line of lines3(jsonLines)) {
|
|
25838
|
-
const info = asRecord3(parseJson3(line));
|
|
25839
|
-
if (!info)
|
|
25840
|
-
continue;
|
|
25841
|
-
const id = shortId(info.ID);
|
|
25842
|
-
if (!id)
|
|
25843
|
-
continue;
|
|
25844
|
-
const name3 = firstName(info.Names);
|
|
25845
|
-
const image = nameOf2(info.Image);
|
|
25846
|
-
if (!name3 || !image)
|
|
25847
|
-
continue;
|
|
25848
|
-
const item = {
|
|
25849
|
-
id,
|
|
25850
|
-
name: name3,
|
|
25851
|
-
image,
|
|
25852
|
-
engine: "docker",
|
|
25853
|
-
state: containerState(info.State),
|
|
25854
|
-
status: text3(info.Status, STATUS_MAX),
|
|
25855
|
-
ports: dockerPorts(info.Ports)
|
|
25856
|
-
};
|
|
25857
|
-
const createdAt = parseDockerTime(typeof info.CreatedAt === "string" ? info.CreatedAt : "");
|
|
25858
|
-
if (createdAt)
|
|
25859
|
-
item.created_at = createdAt;
|
|
25860
|
-
const size = dockerSize(info.Size);
|
|
25861
|
-
if (size.rw !== void 0)
|
|
25862
|
-
item.size_rw_bytes = size.rw;
|
|
25863
|
-
if (size.root !== void 0)
|
|
25864
|
-
item.size_root_fs_bytes = size.root;
|
|
25865
|
-
const composeProject = dockerComposeProject(info.Labels);
|
|
25866
|
-
if (composeProject)
|
|
25867
|
-
item.compose_project = composeProject;
|
|
25868
|
-
push2(result2, item, MAX_CONTAINERS);
|
|
26090
|
+
/** Console Refresh: one run now (ignored while off or while a run is in progress). */
|
|
26091
|
+
request(requestId) {
|
|
26092
|
+
if (this.#stopped || this.#intervalS === null || this.#running)
|
|
26093
|
+
return;
|
|
26094
|
+
void this.#run(requestId);
|
|
25869
26095
|
}
|
|
25870
|
-
|
|
26096
|
+
/** SSH host ids of the latest config (deduplicated, not yet filtered by the pinned list). */
|
|
26097
|
+
get sshHostIds() {
|
|
26098
|
+
return this.#sshHostIds;
|
|
26099
|
+
}
|
|
26100
|
+
stop() {
|
|
26101
|
+
this.#stopped = true;
|
|
26102
|
+
this.#intervalS = null;
|
|
26103
|
+
this.#sshHostIds = [];
|
|
26104
|
+
this.#clear();
|
|
26105
|
+
}
|
|
26106
|
+
#clear() {
|
|
26107
|
+
if (this.#timer)
|
|
26108
|
+
clearTimeout(this.#timer);
|
|
26109
|
+
this.#timer = null;
|
|
26110
|
+
}
|
|
26111
|
+
#schedule(ms) {
|
|
26112
|
+
this.#timer = setTimeout(() => {
|
|
26113
|
+
this.#timer = null;
|
|
26114
|
+
void this.#run(null).finally(() => {
|
|
26115
|
+
if (!this.#stopped && this.#intervalS !== null && !this.#timer)
|
|
26116
|
+
this.#schedule(this.#intervalS * 1e3);
|
|
26117
|
+
});
|
|
26118
|
+
}, ms);
|
|
26119
|
+
this.#timer.unref?.();
|
|
26120
|
+
}
|
|
26121
|
+
async #run(requestId) {
|
|
26122
|
+
if (this.#running)
|
|
26123
|
+
return;
|
|
26124
|
+
if (!this.#options.allowed()) {
|
|
26125
|
+
this.#logger.info("software inventory is off on this computer (conbridge-agent config inventory on)");
|
|
26126
|
+
return;
|
|
26127
|
+
}
|
|
26128
|
+
this.#running = true;
|
|
26129
|
+
try {
|
|
26130
|
+
await this.#runComputer(requestId);
|
|
26131
|
+
await this.#runSshHosts(requestId);
|
|
26132
|
+
} finally {
|
|
26133
|
+
this.#running = false;
|
|
26134
|
+
}
|
|
26135
|
+
}
|
|
26136
|
+
#now() {
|
|
26137
|
+
return (this.#options.now ?? Date.now)();
|
|
26138
|
+
}
|
|
26139
|
+
/** Waits out the gap since the previous send; false when the loop stopped or was turned off meanwhile. */
|
|
26140
|
+
async #awaitSpacing() {
|
|
26141
|
+
const spacing = this.#options.sendSpacingMs ?? SEND_SPACING_MS;
|
|
26142
|
+
const wait = this.#lastSendEndMs === null ? 0 : this.#lastSendEndMs + spacing - this.#now();
|
|
26143
|
+
if (wait > 0)
|
|
26144
|
+
await new Promise((resolve8) => {
|
|
26145
|
+
setTimeout(resolve8, wait).unref?.();
|
|
26146
|
+
});
|
|
26147
|
+
return this.#active;
|
|
26148
|
+
}
|
|
26149
|
+
#sendParts(parts) {
|
|
26150
|
+
try {
|
|
26151
|
+
this.#options.send(parts);
|
|
26152
|
+
} finally {
|
|
26153
|
+
this.#lastSendEndMs = this.#now();
|
|
26154
|
+
}
|
|
26155
|
+
}
|
|
26156
|
+
get #active() {
|
|
26157
|
+
return !this.#stopped && this.#intervalS !== null;
|
|
26158
|
+
}
|
|
26159
|
+
async #runComputer(requestId) {
|
|
26160
|
+
const started = Date.now();
|
|
26161
|
+
try {
|
|
26162
|
+
const snapshot = await this.#options.collect();
|
|
26163
|
+
if (!this.#active)
|
|
26164
|
+
return;
|
|
26165
|
+
const parts = encodeSnapshot(snapshot, requestId);
|
|
26166
|
+
if (!parts) {
|
|
26167
|
+
this.#logger.warn("software inventory too large to send");
|
|
26168
|
+
return;
|
|
26169
|
+
}
|
|
26170
|
+
if (!await this.#awaitSpacing())
|
|
26171
|
+
return;
|
|
26172
|
+
this.#sendParts(parts);
|
|
26173
|
+
this.#options.onSent?.(this.#now());
|
|
26174
|
+
this.#logger.info("software inventory sent", { packages: snapshot.packages.length, containers: snapshot.containers.length, parts: parts.length, ms: Date.now() - started });
|
|
26175
|
+
} catch (error63) {
|
|
26176
|
+
this.#logger.warn("software inventory failed", { error: error63 instanceof Error ? error63.name : "unknown" });
|
|
26177
|
+
}
|
|
26178
|
+
}
|
|
26179
|
+
/** Listed, pinned hosts one after another; the list and the pin are re-checked before each host. */
|
|
26180
|
+
async #runSshHosts(requestId) {
|
|
26181
|
+
const { sshHosts, collectSshHost } = this.#options;
|
|
26182
|
+
if (!sshHosts || !collectSshHost)
|
|
26183
|
+
return;
|
|
26184
|
+
const ids = this.#sshHostIds;
|
|
26185
|
+
for (const id of ids) {
|
|
26186
|
+
if (!this.#active || !this.#sshHostIds.includes(id))
|
|
26187
|
+
continue;
|
|
26188
|
+
const [host] = selectInventoryHosts([id], sshHosts());
|
|
26189
|
+
if (!host)
|
|
26190
|
+
continue;
|
|
26191
|
+
const last = this.#hostSentAtMs.get(id);
|
|
26192
|
+
if (last !== void 0 && this.#now() - last < (this.#options.hostMinIntervalMs ?? HOST_MIN_INTERVAL_MS)) {
|
|
26193
|
+
this.#logger.info("ssh host inventory skipped", { host: host.alias, reason: "sent less than a minute ago" });
|
|
26194
|
+
continue;
|
|
26195
|
+
}
|
|
26196
|
+
const started = Date.now();
|
|
26197
|
+
try {
|
|
26198
|
+
const outcome = await collectSshHost(host);
|
|
26199
|
+
if (!outcome.ok) {
|
|
26200
|
+
this.#logger.warn("ssh host inventory skipped", { host: host.alias, reason: outcome.reason });
|
|
26201
|
+
continue;
|
|
26202
|
+
}
|
|
26203
|
+
const parts = encodeSnapshot(outcome.snapshot, requestId, (0, import_node_crypto9.randomUUID)(), host.resource_id);
|
|
26204
|
+
if (!parts) {
|
|
26205
|
+
this.#logger.warn("ssh host inventory skipped", { host: host.alias, reason: "snapshot too large to send" });
|
|
26206
|
+
continue;
|
|
26207
|
+
}
|
|
26208
|
+
if (!await this.#awaitSpacing())
|
|
26209
|
+
return;
|
|
26210
|
+
if (!this.#sshHostIds.includes(id) || selectInventoryHosts([id], sshHosts()).length === 0)
|
|
26211
|
+
continue;
|
|
26212
|
+
this.#sendParts(parts);
|
|
26213
|
+
this.#hostSentAtMs.set(id, this.#now());
|
|
26214
|
+
this.#logger.info("ssh host inventory sent", { host: host.alias, packages: outcome.snapshot.packages.length, parts: parts.length, ms: Date.now() - started });
|
|
26215
|
+
} catch (error63) {
|
|
26216
|
+
this.#logger.warn("ssh host inventory skipped", { host: host.alias, reason: error63 instanceof Error ? error63.name : "unknown" });
|
|
26217
|
+
}
|
|
26218
|
+
}
|
|
26219
|
+
}
|
|
26220
|
+
};
|
|
26221
|
+
|
|
26222
|
+
// dist/inventory/collector.js
|
|
26223
|
+
var import_node_child_process7 = require("node:child_process");
|
|
26224
|
+
var import_promises12 = require("node:fs/promises");
|
|
26225
|
+
var import_node_os4 = require("node:os");
|
|
26226
|
+
|
|
26227
|
+
// dist/inventory/parsers/services.js
|
|
26228
|
+
var NAME_MAX2 = 200;
|
|
26229
|
+
var DESCRIPTION_MAX = 200;
|
|
26230
|
+
var MAX_SERVICES = INVENTORY_LIMITS.services;
|
|
26231
|
+
function text2(value, max) {
|
|
26232
|
+
if (typeof value !== "string")
|
|
26233
|
+
return "";
|
|
26234
|
+
const trimmed = value.trim();
|
|
26235
|
+
if (trimmed.length <= max)
|
|
26236
|
+
return trimmed;
|
|
26237
|
+
return trimmed.slice(0, max).trimEnd();
|
|
25871
26238
|
}
|
|
25872
|
-
function
|
|
25873
|
-
|
|
25874
|
-
|
|
25875
|
-
|
|
25876
|
-
|
|
25877
|
-
|
|
25878
|
-
|
|
25879
|
-
|
|
25880
|
-
|
|
25881
|
-
|
|
25882
|
-
|
|
25883
|
-
|
|
25884
|
-
|
|
25885
|
-
|
|
25886
|
-
|
|
26239
|
+
function asRecord3(value) {
|
|
26240
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
26241
|
+
}
|
|
26242
|
+
function lines2(stdout) {
|
|
26243
|
+
if (typeof stdout !== "string")
|
|
26244
|
+
return [];
|
|
26245
|
+
return stdout.split(/\r?\n/).filter((line) => line.trim() !== "");
|
|
26246
|
+
}
|
|
26247
|
+
function parseJson2(value) {
|
|
26248
|
+
if (typeof value !== "string")
|
|
26249
|
+
return void 0;
|
|
26250
|
+
try {
|
|
26251
|
+
return JSON.parse(value);
|
|
26252
|
+
} catch {
|
|
26253
|
+
return void 0;
|
|
26254
|
+
}
|
|
26255
|
+
}
|
|
26256
|
+
function sorted(result2) {
|
|
26257
|
+
result2.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
26258
|
+
return result2.slice(0, MAX_SERVICES);
|
|
26259
|
+
}
|
|
26260
|
+
function unitName(unit) {
|
|
26261
|
+
return unit.endsWith(".service") ? unit.slice(0, -".service".length) : unit;
|
|
26262
|
+
}
|
|
26263
|
+
function systemdState(active, sub) {
|
|
26264
|
+
if (active === "active")
|
|
26265
|
+
return sub === "running" ? "running" : "stopped";
|
|
26266
|
+
if (active === "failed")
|
|
26267
|
+
return "failed";
|
|
26268
|
+
if (active === "activating" || active === "reloading")
|
|
26269
|
+
return "starting";
|
|
26270
|
+
if (active === "deactivating")
|
|
26271
|
+
return "stopping";
|
|
26272
|
+
if (active === "inactive")
|
|
26273
|
+
return "stopped";
|
|
26274
|
+
return "unknown";
|
|
26275
|
+
}
|
|
26276
|
+
function unitFileEnablement(unitFiles) {
|
|
26277
|
+
const enablement = /* @__PURE__ */ new Map();
|
|
26278
|
+
for (const line of lines2(unitFiles)) {
|
|
26279
|
+
const parts = line.trim().split(/\s+/);
|
|
26280
|
+
const unit = parts[0];
|
|
26281
|
+
const state2 = parts[1];
|
|
26282
|
+
if (!unit || !state2)
|
|
25887
26283
|
continue;
|
|
25888
|
-
|
|
25889
|
-
|
|
25890
|
-
|
|
25891
|
-
|
|
25892
|
-
|
|
25893
|
-
|
|
25894
|
-
if (size !== null)
|
|
25895
|
-
item.size_bytes = size;
|
|
25896
|
-
push2(result2, item, MAX_IMAGES);
|
|
26284
|
+
if (state2 === "enabled" || state2 === "enabled-runtime")
|
|
26285
|
+
enablement.set(unitName(unit), true);
|
|
26286
|
+
else if (state2 === "disabled" || state2 === "masked")
|
|
26287
|
+
enablement.set(unitName(unit), false);
|
|
26288
|
+
else
|
|
26289
|
+
enablement.set(unitName(unit), null);
|
|
25897
26290
|
}
|
|
25898
|
-
return
|
|
26291
|
+
return enablement;
|
|
25899
26292
|
}
|
|
25900
|
-
function
|
|
25901
|
-
const
|
|
25902
|
-
if (!Array.isArray(parsed))
|
|
25903
|
-
return [];
|
|
26293
|
+
function parseSystemd(units, unitFiles) {
|
|
26294
|
+
const enablement = unitFileEnablement(unitFiles);
|
|
25904
26295
|
const result2 = [];
|
|
25905
|
-
for (const
|
|
25906
|
-
const
|
|
25907
|
-
|
|
26296
|
+
for (const rawLine of lines2(units)) {
|
|
26297
|
+
const line = rawLine.trim().replace(/^[●*]\s+/, "");
|
|
26298
|
+
const match = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)(?:\s+(.*))?$/.exec(line);
|
|
26299
|
+
if (!match)
|
|
25908
26300
|
continue;
|
|
25909
|
-
const
|
|
25910
|
-
|
|
26301
|
+
const unitToken = match[1];
|
|
26302
|
+
const load = match[2];
|
|
26303
|
+
const active = match[3];
|
|
26304
|
+
const sub = match[4];
|
|
26305
|
+
if (!unitToken || !load || !active || !sub)
|
|
25911
26306
|
continue;
|
|
25912
|
-
|
|
25913
|
-
|
|
25914
|
-
|
|
26307
|
+
if (load === "not-found")
|
|
26308
|
+
continue;
|
|
26309
|
+
const name3 = text2(unitName(unitToken), NAME_MAX2);
|
|
26310
|
+
if (!name3)
|
|
25915
26311
|
continue;
|
|
25916
26312
|
const item = {
|
|
25917
|
-
id,
|
|
25918
26313
|
name: name3,
|
|
25919
|
-
|
|
25920
|
-
|
|
25921
|
-
|
|
25922
|
-
status: text3(info.Status, STATUS_MAX),
|
|
25923
|
-
ports: podmanPorts(info.Ports)
|
|
26314
|
+
manager: "systemd",
|
|
26315
|
+
state: systemdState(active.toLowerCase(), sub.toLowerCase()),
|
|
26316
|
+
enabled: enablement.get(name3) ?? null
|
|
25924
26317
|
};
|
|
25925
|
-
const
|
|
25926
|
-
if (
|
|
25927
|
-
item.
|
|
25928
|
-
|
|
25929
|
-
const rw = nonNegativeInteger(size?.rwSize);
|
|
25930
|
-
if (rw !== void 0)
|
|
25931
|
-
item.size_rw_bytes = rw;
|
|
25932
|
-
const root = nonNegativeInteger(size?.rootFsSize);
|
|
25933
|
-
if (root !== void 0)
|
|
25934
|
-
item.size_root_fs_bytes = root;
|
|
25935
|
-
const pod = nameOf2(info.PodName);
|
|
25936
|
-
if (pod)
|
|
25937
|
-
item.pod = pod;
|
|
25938
|
-
const composeProject = podmanComposeProject(info.Labels);
|
|
25939
|
-
if (composeProject)
|
|
25940
|
-
item.compose_project = composeProject;
|
|
25941
|
-
push2(result2, item, MAX_CONTAINERS);
|
|
26318
|
+
const description = text2(match[5] ?? "", DESCRIPTION_MAX);
|
|
26319
|
+
if (description)
|
|
26320
|
+
item.description = description;
|
|
26321
|
+
result2.push(item);
|
|
25942
26322
|
}
|
|
25943
|
-
return result2;
|
|
26323
|
+
return sorted(result2);
|
|
25944
26324
|
}
|
|
25945
|
-
function
|
|
25946
|
-
const parsed = parseJson3(json2);
|
|
25947
|
-
if (!Array.isArray(parsed))
|
|
25948
|
-
return [];
|
|
26325
|
+
function parseLaunchctl(stdout) {
|
|
25949
26326
|
const result2 = [];
|
|
25950
|
-
for (const
|
|
25951
|
-
const
|
|
25952
|
-
if (
|
|
25953
|
-
continue;
|
|
25954
|
-
const id = shortId(info.Id);
|
|
25955
|
-
if (!id)
|
|
26327
|
+
for (const line of lines2(stdout)) {
|
|
26328
|
+
const parts = line.split(" ");
|
|
26329
|
+
if (parts.length < 3)
|
|
25956
26330
|
continue;
|
|
25957
|
-
const
|
|
25958
|
-
const
|
|
25959
|
-
const
|
|
25960
|
-
|
|
25961
|
-
|
|
25962
|
-
|
|
25963
|
-
|
|
25964
|
-
|
|
25965
|
-
|
|
25966
|
-
|
|
25967
|
-
|
|
25968
|
-
|
|
25969
|
-
|
|
26331
|
+
const pid = (parts[0] ?? "").trim();
|
|
26332
|
+
const statusText = (parts[1] ?? "").trim();
|
|
26333
|
+
const label = text2(parts[2], NAME_MAX2);
|
|
26334
|
+
if (!label)
|
|
26335
|
+
continue;
|
|
26336
|
+
if (label.startsWith("com.apple.") || label.startsWith("application."))
|
|
26337
|
+
continue;
|
|
26338
|
+
let state2;
|
|
26339
|
+
if (pid === "-") {
|
|
26340
|
+
if (!/^\d+$/.test(statusText))
|
|
26341
|
+
continue;
|
|
26342
|
+
state2 = Number(statusText) === 0 ? "stopped" : "failed";
|
|
26343
|
+
} else if (/^\d+$/.test(pid)) {
|
|
26344
|
+
state2 = "running";
|
|
26345
|
+
} else {
|
|
26346
|
+
continue;
|
|
26347
|
+
}
|
|
26348
|
+
result2.push({ name: label, manager: "launchd", state: state2, enabled: null });
|
|
25970
26349
|
}
|
|
25971
|
-
return result2;
|
|
26350
|
+
return sorted(result2);
|
|
25972
26351
|
}
|
|
25973
|
-
function
|
|
25974
|
-
const parsed =
|
|
26352
|
+
function parseBrewServices(json2) {
|
|
26353
|
+
const parsed = parseJson2(json2);
|
|
25975
26354
|
if (!Array.isArray(parsed))
|
|
25976
26355
|
return [];
|
|
25977
26356
|
const result2 = [];
|
|
@@ -25979,267 +26358,551 @@ function parsePodmanPods(json2) {
|
|
|
25979
26358
|
const info = asRecord3(value);
|
|
25980
26359
|
if (!info)
|
|
25981
26360
|
continue;
|
|
25982
|
-
const name3 =
|
|
26361
|
+
const name3 = text2(info.name, NAME_MAX2);
|
|
25983
26362
|
if (!name3)
|
|
25984
26363
|
continue;
|
|
25985
|
-
const
|
|
25986
|
-
|
|
25987
|
-
|
|
25988
|
-
|
|
25989
|
-
|
|
25990
|
-
|
|
25991
|
-
|
|
25992
|
-
|
|
25993
|
-
|
|
25994
|
-
|
|
25995
|
-
|
|
25996
|
-
|
|
25997
|
-
|
|
25998
|
-
|
|
25999
|
-
|
|
26000
|
-
|
|
26364
|
+
const status = typeof info.status === "string" ? info.status.trim().toLowerCase() : "";
|
|
26365
|
+
let state2;
|
|
26366
|
+
let enabled;
|
|
26367
|
+
switch (status) {
|
|
26368
|
+
case "started":
|
|
26369
|
+
state2 = "running";
|
|
26370
|
+
enabled = true;
|
|
26371
|
+
break;
|
|
26372
|
+
case "error":
|
|
26373
|
+
state2 = "failed";
|
|
26374
|
+
enabled = true;
|
|
26375
|
+
break;
|
|
26376
|
+
case "scheduled":
|
|
26377
|
+
state2 = "starting";
|
|
26378
|
+
enabled = true;
|
|
26379
|
+
break;
|
|
26380
|
+
case "none":
|
|
26381
|
+
case "stopped":
|
|
26382
|
+
state2 = "stopped";
|
|
26383
|
+
enabled = false;
|
|
26384
|
+
break;
|
|
26385
|
+
default:
|
|
26386
|
+
state2 = "unknown";
|
|
26387
|
+
enabled = null;
|
|
26001
26388
|
}
|
|
26002
|
-
|
|
26003
|
-
if (createdAt)
|
|
26004
|
-
item.created_at = createdAt;
|
|
26005
|
-
push2(result2, item, MAX_PODS);
|
|
26389
|
+
result2.push({ name: name3, manager: "brew", state: state2, enabled });
|
|
26006
26390
|
}
|
|
26007
|
-
return result2;
|
|
26391
|
+
return sorted(result2);
|
|
26008
26392
|
}
|
|
26009
|
-
|
|
26393
|
+
var WINDOWS_STATES = {
|
|
26394
|
+
"4": "running",
|
|
26395
|
+
running: "running",
|
|
26396
|
+
"1": "stopped",
|
|
26397
|
+
stopped: "stopped",
|
|
26398
|
+
"2": "starting",
|
|
26399
|
+
startpending: "starting",
|
|
26400
|
+
"3": "stopping",
|
|
26401
|
+
stoppending: "stopping",
|
|
26402
|
+
"7": "stopped",
|
|
26403
|
+
paused: "stopped"
|
|
26404
|
+
};
|
|
26405
|
+
var WINDOWS_START_TYPES = {
|
|
26406
|
+
"2": true,
|
|
26407
|
+
automatic: true,
|
|
26408
|
+
"3": false,
|
|
26409
|
+
manual: false,
|
|
26410
|
+
"4": false,
|
|
26411
|
+
disabled: false
|
|
26412
|
+
};
|
|
26413
|
+
function windowsState(value) {
|
|
26414
|
+
if (typeof value === "number")
|
|
26415
|
+
return WINDOWS_STATES[String(value)] ?? "unknown";
|
|
26416
|
+
if (typeof value === "string")
|
|
26417
|
+
return WINDOWS_STATES[value.trim().toLowerCase()] ?? "unknown";
|
|
26418
|
+
return "unknown";
|
|
26419
|
+
}
|
|
26420
|
+
function windowsEnabled(value) {
|
|
26421
|
+
if (typeof value === "number")
|
|
26422
|
+
return WINDOWS_START_TYPES[String(value)] ?? null;
|
|
26423
|
+
if (typeof value === "string")
|
|
26424
|
+
return WINDOWS_START_TYPES[value.trim().toLowerCase()] ?? null;
|
|
26425
|
+
return null;
|
|
26426
|
+
}
|
|
26427
|
+
function parseWindowsServices(json2) {
|
|
26428
|
+
const parsed = parseJson2(json2);
|
|
26429
|
+
if (parsed === void 0 || parsed === null)
|
|
26430
|
+
return [];
|
|
26431
|
+
const entries = Array.isArray(parsed) ? parsed : [parsed];
|
|
26010
26432
|
const result2 = [];
|
|
26011
|
-
for (const
|
|
26012
|
-
const
|
|
26013
|
-
if (
|
|
26433
|
+
for (const value of entries) {
|
|
26434
|
+
const info = asRecord3(value);
|
|
26435
|
+
if (!info)
|
|
26014
26436
|
continue;
|
|
26015
|
-
const
|
|
26016
|
-
const name3 = nameOf2(parts[1]);
|
|
26437
|
+
const name3 = text2(info.Name, NAME_MAX2);
|
|
26017
26438
|
if (!name3)
|
|
26018
26439
|
continue;
|
|
26019
|
-
const readyField = parts[5] ?? "";
|
|
26020
|
-
const restartsField = parts[6] ?? "";
|
|
26021
|
-
let containers = 0;
|
|
26022
|
-
let ready;
|
|
26023
|
-
if (readyField !== "<none>") {
|
|
26024
|
-
const values = readyField.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
26025
|
-
containers = values.length;
|
|
26026
|
-
ready = values.filter((entry) => entry.toLowerCase() === "true").length;
|
|
26027
|
-
}
|
|
26028
|
-
let restarts;
|
|
26029
|
-
if (restartsField !== "<none>") {
|
|
26030
|
-
const values = restartsField.split(",").map((entry) => entry.trim()).filter((entry) => /^\d+$/.test(entry));
|
|
26031
|
-
if (values.length > 0)
|
|
26032
|
-
restarts = values.reduce((total, entry) => total + Number(entry), 0);
|
|
26033
|
-
}
|
|
26034
26440
|
const item = {
|
|
26035
26441
|
name: name3,
|
|
26036
|
-
|
|
26037
|
-
|
|
26038
|
-
|
|
26442
|
+
manager: "windows",
|
|
26443
|
+
state: windowsState(info.Status),
|
|
26444
|
+
enabled: windowsEnabled(info.StartType)
|
|
26039
26445
|
};
|
|
26040
|
-
|
|
26041
|
-
|
|
26042
|
-
|
|
26043
|
-
|
|
26044
|
-
if (restarts !== void 0)
|
|
26045
|
-
item.restarts = restarts;
|
|
26046
|
-
const node2 = nameOf2(parts[3]);
|
|
26047
|
-
if (node2 && node2 !== "<none>")
|
|
26048
|
-
item.node = node2;
|
|
26049
|
-
const created = text3(parts[4], 64);
|
|
26050
|
-
if (created && created !== "<none>") {
|
|
26051
|
-
const createdAt = isoString(created);
|
|
26052
|
-
if (createdAt)
|
|
26053
|
-
item.created_at = createdAt;
|
|
26054
|
-
}
|
|
26055
|
-
push2(result2, item, MAX_PODS);
|
|
26446
|
+
const description = text2(info.DisplayName, DESCRIPTION_MAX);
|
|
26447
|
+
if (description && description !== name3)
|
|
26448
|
+
item.description = description;
|
|
26449
|
+
result2.push(item);
|
|
26056
26450
|
}
|
|
26057
|
-
return result2;
|
|
26451
|
+
return sorted(result2);
|
|
26058
26452
|
}
|
|
26059
26453
|
|
|
26060
|
-
// dist/inventory/parsers/
|
|
26061
|
-
var
|
|
26062
|
-
|
|
26063
|
-
|
|
26064
|
-
|
|
26065
|
-
|
|
26066
|
-
|
|
26067
|
-
|
|
26454
|
+
// dist/inventory/parsers/containers.js
|
|
26455
|
+
var NAME_MAX3 = 200;
|
|
26456
|
+
var STATUS_MAX = 200;
|
|
26457
|
+
var PORT_MAX = 80;
|
|
26458
|
+
var TAG_MAX = 128;
|
|
26459
|
+
var POD_STATUS_MAX = 40;
|
|
26460
|
+
var MAX_CONTAINERS = INVENTORY_LIMITS.containers;
|
|
26461
|
+
var MAX_IMAGES = INVENTORY_LIMITS.images;
|
|
26462
|
+
var MAX_PODS = INVENTORY_LIMITS.pods;
|
|
26463
|
+
var MAX_PORTS = INVENTORY_LIMITS.ports;
|
|
26464
|
+
var CONTAINER_STATE_VALUES = /* @__PURE__ */ new Set([
|
|
26465
|
+
"running",
|
|
26466
|
+
"paused",
|
|
26467
|
+
"restarting",
|
|
26468
|
+
"exited",
|
|
26469
|
+
"created",
|
|
26470
|
+
"dead",
|
|
26471
|
+
"removing"
|
|
26472
|
+
]);
|
|
26473
|
+
var BYTE_MULTIPLIERS = {
|
|
26474
|
+
b: 1,
|
|
26475
|
+
kb: 1e3,
|
|
26476
|
+
mb: 1e6,
|
|
26477
|
+
gb: 1e9,
|
|
26478
|
+
tb: 1e12,
|
|
26479
|
+
kib: 1024,
|
|
26480
|
+
mib: 1024 * 1024,
|
|
26481
|
+
gib: 1024 * 1024 * 1024,
|
|
26482
|
+
tib: 1024 * 1024 * 1024 * 1024
|
|
26068
26483
|
};
|
|
26069
|
-
function
|
|
26070
|
-
|
|
26071
|
-
|
|
26072
|
-
|
|
26073
|
-
|
|
26074
|
-
|
|
26075
|
-
|
|
26076
|
-
|
|
26077
|
-
|
|
26078
|
-
|
|
26079
|
-
|
|
26484
|
+
function text3(value, max) {
|
|
26485
|
+
if (typeof value !== "string")
|
|
26486
|
+
return "";
|
|
26487
|
+
const trimmed = value.trim();
|
|
26488
|
+
if (trimmed.length <= max)
|
|
26489
|
+
return trimmed;
|
|
26490
|
+
return trimmed.slice(0, max).trimEnd();
|
|
26491
|
+
}
|
|
26492
|
+
function nameOf2(value) {
|
|
26493
|
+
return text3(value, NAME_MAX3);
|
|
26494
|
+
}
|
|
26495
|
+
function asRecord4(value) {
|
|
26496
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
26497
|
+
}
|
|
26498
|
+
function lines3(stdout) {
|
|
26499
|
+
if (typeof stdout !== "string")
|
|
26500
|
+
return [];
|
|
26501
|
+
return stdout.split(/\r?\n/).filter((line) => line.trim() !== "");
|
|
26502
|
+
}
|
|
26503
|
+
function parseJson3(value) {
|
|
26504
|
+
if (typeof value !== "string")
|
|
26505
|
+
return void 0;
|
|
26506
|
+
try {
|
|
26507
|
+
return JSON.parse(value);
|
|
26508
|
+
} catch {
|
|
26509
|
+
return void 0;
|
|
26080
26510
|
}
|
|
26081
|
-
return value;
|
|
26082
26511
|
}
|
|
26083
|
-
function
|
|
26084
|
-
|
|
26085
|
-
|
|
26086
|
-
|
|
26087
|
-
|
|
26088
|
-
|
|
26089
|
-
|
|
26512
|
+
function push2(result2, item, max) {
|
|
26513
|
+
if (result2.length < max)
|
|
26514
|
+
result2.push(item);
|
|
26515
|
+
}
|
|
26516
|
+
function shortId(value) {
|
|
26517
|
+
if (typeof value !== "string")
|
|
26518
|
+
return void 0;
|
|
26519
|
+
let raw = value.trim().toLowerCase();
|
|
26520
|
+
if (raw.startsWith("sha256:"))
|
|
26521
|
+
raw = raw.slice("sha256:".length);
|
|
26522
|
+
if (raw.length < 12 || !/^[0-9a-f]+$/.test(raw))
|
|
26523
|
+
return void 0;
|
|
26524
|
+
return raw.slice(0, 12);
|
|
26525
|
+
}
|
|
26526
|
+
function containerState(value) {
|
|
26527
|
+
if (typeof value !== "string")
|
|
26528
|
+
return "unknown";
|
|
26529
|
+
const state2 = value.trim().toLowerCase();
|
|
26530
|
+
return CONTAINER_STATE_VALUES.has(state2) ? state2 : "unknown";
|
|
26531
|
+
}
|
|
26532
|
+
function nonNegativeInteger(value) {
|
|
26533
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
26534
|
+
return void 0;
|
|
26535
|
+
const rounded = Math.round(value);
|
|
26536
|
+
return rounded >= 0 && Number.isSafeInteger(rounded) ? rounded : void 0;
|
|
26537
|
+
}
|
|
26538
|
+
function isoFromUnix(value) {
|
|
26539
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
26540
|
+
return void 0;
|
|
26541
|
+
const date5 = new Date(value * 1e3);
|
|
26542
|
+
return Number.isNaN(date5.getTime()) ? void 0 : date5.toISOString();
|
|
26543
|
+
}
|
|
26544
|
+
function isoString(value) {
|
|
26545
|
+
if (typeof value !== "string")
|
|
26546
|
+
return void 0;
|
|
26547
|
+
const raw = value.trim();
|
|
26548
|
+
if (!raw)
|
|
26549
|
+
return void 0;
|
|
26550
|
+
return Number.isNaN(new Date(raw).getTime()) ? void 0 : raw;
|
|
26551
|
+
}
|
|
26552
|
+
function stringList(value) {
|
|
26553
|
+
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
26554
|
+
}
|
|
26555
|
+
function firstName(value) {
|
|
26556
|
+
if (typeof value !== "string")
|
|
26557
|
+
return "";
|
|
26558
|
+
return nameOf2(value.split(",")[0] ?? "");
|
|
26559
|
+
}
|
|
26560
|
+
function dockerPorts(value) {
|
|
26561
|
+
if (typeof value !== "string")
|
|
26562
|
+
return [];
|
|
26563
|
+
const ports = [];
|
|
26564
|
+
for (const part of value.split(",")) {
|
|
26565
|
+
const port = text3(part, PORT_MAX);
|
|
26566
|
+
if (!port)
|
|
26090
26567
|
continue;
|
|
26091
|
-
|
|
26092
|
-
if (
|
|
26568
|
+
ports.push(port);
|
|
26569
|
+
if (ports.length >= MAX_PORTS)
|
|
26570
|
+
break;
|
|
26571
|
+
}
|
|
26572
|
+
return ports;
|
|
26573
|
+
}
|
|
26574
|
+
function portText(value) {
|
|
26575
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
26576
|
+
return String(value);
|
|
26577
|
+
return text3(value, 16);
|
|
26578
|
+
}
|
|
26579
|
+
function podmanPorts(value) {
|
|
26580
|
+
if (!Array.isArray(value))
|
|
26581
|
+
return [];
|
|
26582
|
+
const ports = [];
|
|
26583
|
+
for (const entry of value) {
|
|
26584
|
+
const port = asRecord4(entry);
|
|
26585
|
+
if (!port)
|
|
26093
26586
|
continue;
|
|
26094
|
-
const
|
|
26095
|
-
const
|
|
26096
|
-
|
|
26587
|
+
const hostIp = text3(port.host_ip, 64) || "0.0.0.0";
|
|
26588
|
+
const hostPort = portText(port.host_port);
|
|
26589
|
+
const containerPort = portText(port.container_port);
|
|
26590
|
+
if (!hostPort || !containerPort)
|
|
26097
26591
|
continue;
|
|
26098
|
-
const
|
|
26099
|
-
|
|
26592
|
+
const protocol = text3(port.protocol, 8) || "tcp";
|
|
26593
|
+
const rendered = text3(`${hostIp}:${hostPort}->${containerPort}/${protocol}`, PORT_MAX);
|
|
26594
|
+
if (!rendered)
|
|
26100
26595
|
continue;
|
|
26101
|
-
|
|
26596
|
+
ports.push(rendered);
|
|
26597
|
+
if (ports.length >= MAX_PORTS)
|
|
26598
|
+
break;
|
|
26102
26599
|
}
|
|
26103
|
-
return
|
|
26600
|
+
return ports;
|
|
26104
26601
|
}
|
|
26105
|
-
function
|
|
26602
|
+
function dockerSize(value) {
|
|
26603
|
+
if (typeof value !== "string")
|
|
26604
|
+
return {};
|
|
26605
|
+
const raw = value.trim();
|
|
26606
|
+
if (!raw)
|
|
26607
|
+
return {};
|
|
26608
|
+
const virtual = /\(virtual\s+([^)]+)\)/i.exec(raw);
|
|
26609
|
+
const rwText = raw.replace(/\(virtual[^)]*\)/i, "").trim();
|
|
26106
26610
|
const result2 = {};
|
|
26107
|
-
|
|
26108
|
-
|
|
26109
|
-
|
|
26110
|
-
|
|
26111
|
-
|
|
26112
|
-
|
|
26113
|
-
|
|
26611
|
+
const rw = parseHumanBytes(rwText);
|
|
26612
|
+
if (rw !== null)
|
|
26613
|
+
result2.rw = rw;
|
|
26614
|
+
if (virtual) {
|
|
26615
|
+
const root = parseHumanBytes(virtual[1] ?? "");
|
|
26616
|
+
if (root !== null)
|
|
26617
|
+
result2.root = root;
|
|
26618
|
+
}
|
|
26619
|
+
return result2;
|
|
26620
|
+
}
|
|
26621
|
+
function dockerComposeProject(value) {
|
|
26622
|
+
if (typeof value !== "string")
|
|
26623
|
+
return void 0;
|
|
26624
|
+
for (const pair of value.split(",")) {
|
|
26625
|
+
const separator = pair.indexOf("=");
|
|
26114
26626
|
if (separator <= 0)
|
|
26115
26627
|
continue;
|
|
26116
|
-
const key =
|
|
26117
|
-
|
|
26118
|
-
if (!value)
|
|
26628
|
+
const key = pair.slice(0, separator).trim();
|
|
26629
|
+
if (key !== "com.docker.compose.project")
|
|
26119
26630
|
continue;
|
|
26120
|
-
|
|
26121
|
-
|
|
26122
|
-
|
|
26123
|
-
result2.productVersion = value;
|
|
26124
|
-
else if (key === "BuildVersion")
|
|
26125
|
-
result2.buildVersion = value;
|
|
26631
|
+
const project = nameOf2(pair.slice(separator + 1));
|
|
26632
|
+
if (project)
|
|
26633
|
+
return project;
|
|
26126
26634
|
}
|
|
26127
|
-
return
|
|
26128
|
-
}
|
|
26129
|
-
function asRecord4(value) {
|
|
26130
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
26131
|
-
}
|
|
26132
|
-
function stringField(value) {
|
|
26133
|
-
return typeof value === "string" ? value.trim() : "";
|
|
26635
|
+
return void 0;
|
|
26134
26636
|
}
|
|
26135
|
-
function
|
|
26136
|
-
const
|
|
26137
|
-
|
|
26138
|
-
|
|
26139
|
-
|
|
26140
|
-
|
|
26141
|
-
|
|
26142
|
-
return
|
|
26143
|
-
case "32-bit":
|
|
26144
|
-
return "x86";
|
|
26145
|
-
default:
|
|
26146
|
-
return arch3;
|
|
26637
|
+
function podmanComposeProject(value) {
|
|
26638
|
+
const labels = asRecord4(value);
|
|
26639
|
+
if (!labels)
|
|
26640
|
+
return void 0;
|
|
26641
|
+
for (const key of ["com.docker.compose.project", "io.podman.compose.project"]) {
|
|
26642
|
+
const project = nameOf2(labels[key]);
|
|
26643
|
+
if (project)
|
|
26644
|
+
return project;
|
|
26147
26645
|
}
|
|
26646
|
+
return void 0;
|
|
26148
26647
|
}
|
|
26149
|
-
function
|
|
26150
|
-
|
|
26151
|
-
|
|
26152
|
-
|
|
26153
|
-
|
|
26154
|
-
|
|
26155
|
-
|
|
26156
|
-
return
|
|
26648
|
+
function splitImageName(value) {
|
|
26649
|
+
const name3 = value.trim();
|
|
26650
|
+
if (!name3)
|
|
26651
|
+
return { repository: "<none>", tag: "" };
|
|
26652
|
+
const slash = name3.lastIndexOf("/");
|
|
26653
|
+
const colon = name3.lastIndexOf(":");
|
|
26654
|
+
if (colon > slash) {
|
|
26655
|
+
return {
|
|
26656
|
+
repository: nameOf2(name3.slice(0, colon)) || "<none>",
|
|
26657
|
+
tag: text3(name3.slice(colon + 1), TAG_MAX)
|
|
26658
|
+
};
|
|
26157
26659
|
}
|
|
26158
|
-
|
|
26159
|
-
if (!info)
|
|
26160
|
-
return null;
|
|
26161
|
-
const caption = stringField(info.Caption).replace(/^Microsoft\s+/i, "");
|
|
26162
|
-
const version6 = stringField(info.Version);
|
|
26163
|
-
if (!caption || !version6)
|
|
26164
|
-
return null;
|
|
26165
|
-
const buildNumber = stringField(info.BuildNumber);
|
|
26166
|
-
const ubr = info.UBR;
|
|
26167
|
-
const build = typeof ubr === "number" ? `${buildNumber}.${ubr}` : buildNumber;
|
|
26168
|
-
return { caption, version: version6, build, arch: windowsArch(stringField(info.OSArchitecture)) };
|
|
26660
|
+
return { repository: nameOf2(name3) || "<none>", tag: "" };
|
|
26169
26661
|
}
|
|
26170
|
-
|
|
26171
|
-
|
|
26172
|
-
if (typeof text4 !== "string")
|
|
26662
|
+
function parseHumanBytes(value) {
|
|
26663
|
+
if (typeof value !== "string")
|
|
26173
26664
|
return null;
|
|
26174
|
-
const
|
|
26175
|
-
if (!
|
|
26665
|
+
const match = /^(\d+(?:\.\d+)?)\s*([a-z]+)$/i.exec(value.trim());
|
|
26666
|
+
if (!match)
|
|
26176
26667
|
return null;
|
|
26177
|
-
|
|
26668
|
+
const amount = Number(match[1]);
|
|
26669
|
+
const multiplier = BYTE_MULTIPLIERS[(match[2] ?? "").toLowerCase()];
|
|
26670
|
+
if (multiplier === void 0 || !Number.isFinite(amount) || amount < 0)
|
|
26178
26671
|
return null;
|
|
26179
|
-
|
|
26180
|
-
|
|
26181
|
-
function firstNonEmptyLine(output2) {
|
|
26182
|
-
for (const line of output2.split(/\r?\n/)) {
|
|
26183
|
-
const trimmed = line.trim();
|
|
26184
|
-
if (trimmed)
|
|
26185
|
-
return trimmed;
|
|
26186
|
-
}
|
|
26187
|
-
return "";
|
|
26672
|
+
const bytes3 = Math.round(amount * multiplier);
|
|
26673
|
+
return Number.isSafeInteger(bytes3) ? bytes3 : null;
|
|
26188
26674
|
}
|
|
26189
|
-
function
|
|
26190
|
-
if (!match)
|
|
26191
|
-
return null;
|
|
26192
|
-
const value = match[1];
|
|
26675
|
+
function parseDockerTime(value) {
|
|
26193
26676
|
if (typeof value !== "string")
|
|
26194
26677
|
return null;
|
|
26195
|
-
const
|
|
26196
|
-
|
|
26197
|
-
|
|
26198
|
-
|
|
26199
|
-
return group(pattern.exec(value));
|
|
26678
|
+
const match = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) ([+-]\d{2})(\d{2})/.exec(value.trim());
|
|
26679
|
+
if (!match)
|
|
26680
|
+
return null;
|
|
26681
|
+
return `${match[1]}T${match[2]}${match[3]}:${match[4]}`;
|
|
26200
26682
|
}
|
|
26201
|
-
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
|
|
26205
|
-
|
|
26206
|
-
|
|
26207
|
-
|
|
26208
|
-
|
|
26209
|
-
|
|
26210
|
-
|
|
26211
|
-
|
|
26212
|
-
|
|
26213
|
-
|
|
26214
|
-
|
|
26215
|
-
|
|
26216
|
-
|
|
26217
|
-
|
|
26218
|
-
|
|
26219
|
-
|
|
26220
|
-
|
|
26221
|
-
|
|
26222
|
-
|
|
26223
|
-
|
|
26224
|
-
|
|
26225
|
-
|
|
26226
|
-
|
|
26227
|
-
|
|
26228
|
-
|
|
26229
|
-
|
|
26230
|
-
|
|
26231
|
-
|
|
26232
|
-
|
|
26233
|
-
|
|
26234
|
-
|
|
26235
|
-
|
|
26236
|
-
|
|
26237
|
-
|
|
26238
|
-
|
|
26239
|
-
const
|
|
26240
|
-
|
|
26241
|
-
|
|
26242
|
-
|
|
26683
|
+
function parseDockerPs(jsonLines) {
|
|
26684
|
+
const result2 = [];
|
|
26685
|
+
for (const line of lines3(jsonLines)) {
|
|
26686
|
+
const info = asRecord4(parseJson3(line));
|
|
26687
|
+
if (!info)
|
|
26688
|
+
continue;
|
|
26689
|
+
const id = shortId(info.ID);
|
|
26690
|
+
if (!id)
|
|
26691
|
+
continue;
|
|
26692
|
+
const name3 = firstName(info.Names);
|
|
26693
|
+
const image = nameOf2(info.Image);
|
|
26694
|
+
if (!name3 || !image)
|
|
26695
|
+
continue;
|
|
26696
|
+
const item = {
|
|
26697
|
+
id,
|
|
26698
|
+
name: name3,
|
|
26699
|
+
image,
|
|
26700
|
+
engine: "docker",
|
|
26701
|
+
state: containerState(info.State),
|
|
26702
|
+
status: text3(info.Status, STATUS_MAX),
|
|
26703
|
+
ports: dockerPorts(info.Ports)
|
|
26704
|
+
};
|
|
26705
|
+
const createdAt = parseDockerTime(typeof info.CreatedAt === "string" ? info.CreatedAt : "");
|
|
26706
|
+
if (createdAt)
|
|
26707
|
+
item.created_at = createdAt;
|
|
26708
|
+
const size = dockerSize(info.Size);
|
|
26709
|
+
if (size.rw !== void 0)
|
|
26710
|
+
item.size_rw_bytes = size.rw;
|
|
26711
|
+
if (size.root !== void 0)
|
|
26712
|
+
item.size_root_fs_bytes = size.root;
|
|
26713
|
+
const composeProject = dockerComposeProject(info.Labels);
|
|
26714
|
+
if (composeProject)
|
|
26715
|
+
item.compose_project = composeProject;
|
|
26716
|
+
push2(result2, item, MAX_CONTAINERS);
|
|
26717
|
+
}
|
|
26718
|
+
return result2;
|
|
26719
|
+
}
|
|
26720
|
+
function parseDockerImages(jsonLines) {
|
|
26721
|
+
const result2 = [];
|
|
26722
|
+
const seen = /* @__PURE__ */ new Set();
|
|
26723
|
+
for (const line of lines3(jsonLines)) {
|
|
26724
|
+
const info = asRecord4(parseJson3(line));
|
|
26725
|
+
if (!info)
|
|
26726
|
+
continue;
|
|
26727
|
+
const id = shortId(info.ID);
|
|
26728
|
+
if (!id)
|
|
26729
|
+
continue;
|
|
26730
|
+
const repository = nameOf2(info.Repository) || "<none>";
|
|
26731
|
+
const rawTag = text3(info.Tag, TAG_MAX);
|
|
26732
|
+
const tag = rawTag === "<none>" ? "" : rawTag;
|
|
26733
|
+
const key = `${id}\0${repository}\0${tag}`;
|
|
26734
|
+
if (seen.has(key))
|
|
26735
|
+
continue;
|
|
26736
|
+
seen.add(key);
|
|
26737
|
+
const item = { id, repository, tag, engine: "docker" };
|
|
26738
|
+
const createdAt = parseDockerTime(typeof info.CreatedAt === "string" ? info.CreatedAt : "");
|
|
26739
|
+
if (createdAt)
|
|
26740
|
+
item.created_at = createdAt;
|
|
26741
|
+
const size = parseHumanBytes(typeof info.Size === "string" ? info.Size : "");
|
|
26742
|
+
if (size !== null)
|
|
26743
|
+
item.size_bytes = size;
|
|
26744
|
+
push2(result2, item, MAX_IMAGES);
|
|
26745
|
+
}
|
|
26746
|
+
return result2;
|
|
26747
|
+
}
|
|
26748
|
+
function parsePodmanPs(json2) {
|
|
26749
|
+
const parsed = parseJson3(json2);
|
|
26750
|
+
if (!Array.isArray(parsed))
|
|
26751
|
+
return [];
|
|
26752
|
+
const result2 = [];
|
|
26753
|
+
for (const value of parsed) {
|
|
26754
|
+
const info = asRecord4(value);
|
|
26755
|
+
if (!info)
|
|
26756
|
+
continue;
|
|
26757
|
+
const id = shortId(info.Id);
|
|
26758
|
+
if (!id)
|
|
26759
|
+
continue;
|
|
26760
|
+
const name3 = firstName(stringList(info.Names).join(","));
|
|
26761
|
+
const image = nameOf2(info.Image);
|
|
26762
|
+
if (!name3 || !image)
|
|
26763
|
+
continue;
|
|
26764
|
+
const item = {
|
|
26765
|
+
id,
|
|
26766
|
+
name: name3,
|
|
26767
|
+
image,
|
|
26768
|
+
engine: "podman",
|
|
26769
|
+
state: containerState(info.State),
|
|
26770
|
+
status: text3(info.Status, STATUS_MAX),
|
|
26771
|
+
ports: podmanPorts(info.Ports)
|
|
26772
|
+
};
|
|
26773
|
+
const createdAt = isoFromUnix(info.Created) ?? isoString(info.CreatedAt);
|
|
26774
|
+
if (createdAt)
|
|
26775
|
+
item.created_at = createdAt;
|
|
26776
|
+
const size = asRecord4(info.Size);
|
|
26777
|
+
const rw = nonNegativeInteger(size?.rwSize);
|
|
26778
|
+
if (rw !== void 0)
|
|
26779
|
+
item.size_rw_bytes = rw;
|
|
26780
|
+
const root = nonNegativeInteger(size?.rootFsSize);
|
|
26781
|
+
if (root !== void 0)
|
|
26782
|
+
item.size_root_fs_bytes = root;
|
|
26783
|
+
const pod = nameOf2(info.PodName);
|
|
26784
|
+
if (pod)
|
|
26785
|
+
item.pod = pod;
|
|
26786
|
+
const composeProject = podmanComposeProject(info.Labels);
|
|
26787
|
+
if (composeProject)
|
|
26788
|
+
item.compose_project = composeProject;
|
|
26789
|
+
push2(result2, item, MAX_CONTAINERS);
|
|
26790
|
+
}
|
|
26791
|
+
return result2;
|
|
26792
|
+
}
|
|
26793
|
+
function parsePodmanImages(json2) {
|
|
26794
|
+
const parsed = parseJson3(json2);
|
|
26795
|
+
if (!Array.isArray(parsed))
|
|
26796
|
+
return [];
|
|
26797
|
+
const result2 = [];
|
|
26798
|
+
for (const value of parsed) {
|
|
26799
|
+
const info = asRecord4(value);
|
|
26800
|
+
if (!info)
|
|
26801
|
+
continue;
|
|
26802
|
+
const id = shortId(info.Id);
|
|
26803
|
+
if (!id)
|
|
26804
|
+
continue;
|
|
26805
|
+
const first = stringList(info.Names)[0] ?? "";
|
|
26806
|
+
const { repository, tag } = splitImageName(first);
|
|
26807
|
+
const item = { id, repository, tag, engine: "podman" };
|
|
26808
|
+
const size = nonNegativeInteger(info.Size);
|
|
26809
|
+
if (size !== void 0)
|
|
26810
|
+
item.size_bytes = size;
|
|
26811
|
+
const createdAt = isoFromUnix(info.Created);
|
|
26812
|
+
if (createdAt)
|
|
26813
|
+
item.created_at = createdAt;
|
|
26814
|
+
const containers = nonNegativeInteger(info.Containers);
|
|
26815
|
+
if (containers !== void 0)
|
|
26816
|
+
item.containers = containers;
|
|
26817
|
+
push2(result2, item, MAX_IMAGES);
|
|
26818
|
+
}
|
|
26819
|
+
return result2;
|
|
26820
|
+
}
|
|
26821
|
+
function parsePodmanPods(json2) {
|
|
26822
|
+
const parsed = parseJson3(json2);
|
|
26823
|
+
if (!Array.isArray(parsed))
|
|
26824
|
+
return [];
|
|
26825
|
+
const result2 = [];
|
|
26826
|
+
for (const value of parsed) {
|
|
26827
|
+
const info = asRecord4(value);
|
|
26828
|
+
if (!info)
|
|
26829
|
+
continue;
|
|
26830
|
+
const name3 = nameOf2(info.Name);
|
|
26831
|
+
if (!name3)
|
|
26832
|
+
continue;
|
|
26833
|
+
const containerList = Array.isArray(info.Containers) ? info.Containers : void 0;
|
|
26834
|
+
const containers = containerList ? containerList.length : nonNegativeInteger(info.NumberOfContainers) ?? 0;
|
|
26835
|
+
const item = {
|
|
26836
|
+
name: name3,
|
|
26837
|
+
engine: "podman",
|
|
26838
|
+
status: text3(info.Status, POD_STATUS_MAX) || "Unknown",
|
|
26839
|
+
containers
|
|
26840
|
+
};
|
|
26841
|
+
if (containerList) {
|
|
26842
|
+
let ready = 0;
|
|
26843
|
+
for (const entry of containerList) {
|
|
26844
|
+
const container = asRecord4(entry);
|
|
26845
|
+
if (container && text3(container.Status, POD_STATUS_MAX).toLowerCase() === "running")
|
|
26846
|
+
ready += 1;
|
|
26847
|
+
}
|
|
26848
|
+
item.ready = ready;
|
|
26849
|
+
}
|
|
26850
|
+
const createdAt = isoString(info.Created) ?? isoString(info.CreatedAt);
|
|
26851
|
+
if (createdAt)
|
|
26852
|
+
item.created_at = createdAt;
|
|
26853
|
+
push2(result2, item, MAX_PODS);
|
|
26854
|
+
}
|
|
26855
|
+
return result2;
|
|
26856
|
+
}
|
|
26857
|
+
function parseKubectlPods(stdout) {
|
|
26858
|
+
const result2 = [];
|
|
26859
|
+
for (const line of lines3(stdout)) {
|
|
26860
|
+
const parts = line.trim().split(/\s+/);
|
|
26861
|
+
if (parts.length < 7)
|
|
26862
|
+
continue;
|
|
26863
|
+
const namespace = nameOf2(parts[0]);
|
|
26864
|
+
const name3 = nameOf2(parts[1]);
|
|
26865
|
+
if (!name3)
|
|
26866
|
+
continue;
|
|
26867
|
+
const readyField = parts[5] ?? "";
|
|
26868
|
+
const restartsField = parts[6] ?? "";
|
|
26869
|
+
let containers = 0;
|
|
26870
|
+
let ready;
|
|
26871
|
+
if (readyField !== "<none>") {
|
|
26872
|
+
const values = readyField.split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
26873
|
+
containers = values.length;
|
|
26874
|
+
ready = values.filter((entry) => entry.toLowerCase() === "true").length;
|
|
26875
|
+
}
|
|
26876
|
+
let restarts;
|
|
26877
|
+
if (restartsField !== "<none>") {
|
|
26878
|
+
const values = restartsField.split(",").map((entry) => entry.trim()).filter((entry) => /^\d+$/.test(entry));
|
|
26879
|
+
if (values.length > 0)
|
|
26880
|
+
restarts = values.reduce((total, entry) => total + Number(entry), 0);
|
|
26881
|
+
}
|
|
26882
|
+
const item = {
|
|
26883
|
+
name: name3,
|
|
26884
|
+
engine: "kubernetes",
|
|
26885
|
+
status: text3(parts[2], POD_STATUS_MAX) || "Unknown",
|
|
26886
|
+
containers
|
|
26887
|
+
};
|
|
26888
|
+
if (namespace)
|
|
26889
|
+
item.namespace = namespace;
|
|
26890
|
+
if (ready !== void 0)
|
|
26891
|
+
item.ready = ready;
|
|
26892
|
+
if (restarts !== void 0)
|
|
26893
|
+
item.restarts = restarts;
|
|
26894
|
+
const node2 = nameOf2(parts[3]);
|
|
26895
|
+
if (node2 && node2 !== "<none>")
|
|
26896
|
+
item.node = node2;
|
|
26897
|
+
const created = text3(parts[4], 64);
|
|
26898
|
+
if (created && created !== "<none>") {
|
|
26899
|
+
const createdAt = isoString(created);
|
|
26900
|
+
if (createdAt)
|
|
26901
|
+
item.created_at = createdAt;
|
|
26902
|
+
}
|
|
26903
|
+
push2(result2, item, MAX_PODS);
|
|
26904
|
+
}
|
|
26905
|
+
return result2;
|
|
26243
26906
|
}
|
|
26244
26907
|
|
|
26245
26908
|
// dist/inventory/collector.js
|
|
@@ -26253,7 +26916,7 @@ function collectorEnv(env = process.env, platform2 = process.platform) {
|
|
|
26253
26916
|
return { ...base2, PATH: path };
|
|
26254
26917
|
}
|
|
26255
26918
|
var defaultRunner = (file2, args, { timeoutMs, maxBytes }) => new Promise((resolve8) => {
|
|
26256
|
-
(0,
|
|
26919
|
+
(0, import_node_child_process7.execFile)(file2, [...args], {
|
|
26257
26920
|
timeout: timeoutMs,
|
|
26258
26921
|
maxBuffer: maxBytes,
|
|
26259
26922
|
killSignal: "SIGKILL",
|
|
@@ -26274,7 +26937,7 @@ var defaultRunner = (file2, args, { timeoutMs, maxBytes }) => new Promise((resol
|
|
|
26274
26937
|
});
|
|
26275
26938
|
});
|
|
26276
26939
|
});
|
|
26277
|
-
var defaultReader = async (path) => (0,
|
|
26940
|
+
var defaultReader = async (path) => (0, import_promises12.readFile)(path, "utf8").catch(() => null);
|
|
26278
26941
|
var defaultCollectorSystem = {
|
|
26279
26942
|
platform: (0, import_node_os4.platform)(),
|
|
26280
26943
|
arch: (0, import_node_os4.arch)(),
|
|
@@ -26567,523 +27230,202 @@ async function collectContainers(c) {
|
|
|
26567
27230
|
}
|
|
26568
27231
|
for (const image of c.images) {
|
|
26569
27232
|
if (image.containers !== void 0)
|
|
26570
|
-
continue;
|
|
26571
|
-
const ref = `${image.repository}:${image.tag}`;
|
|
26572
|
-
const count3 = c.containers.filter((ct) => ct.engine === image.engine && (ct.image === ref || image.tag === "latest" && ct.image === image.repository || ct.image.startsWith(image.id))).length;
|
|
26573
|
-
image.containers = count3;
|
|
26574
|
-
}
|
|
26575
|
-
}
|
|
26576
|
-
async function collectInventory(system = defaultCollectorSystem) {
|
|
26577
|
-
const c = new Collection(system);
|
|
26578
|
-
const os = await collectOs(c);
|
|
26579
|
-
await collectPackages(c);
|
|
26580
|
-
await collectSoftware(c);
|
|
26581
|
-
await collectServices(c);
|
|
26582
|
-
await collectContainers(c);
|
|
26583
|
-
const snapshot = {
|
|
26584
|
-
schema: 1,
|
|
26585
|
-
collected_at: system.now().toISOString(),
|
|
26586
|
-
agent_version: AGENT_VERSION,
|
|
26587
|
-
os: inventoryOsSchema.safeParse(os).success ? os : { family: "other", name: system.platform, version: "", arch: system.arch },
|
|
26588
|
-
packages: valid(inventoryPackageSchema, c.packages, INVENTORY_LIMITS.packages),
|
|
26589
|
-
software: valid(inventorySoftwareSchema, c.software, INVENTORY_LIMITS.software),
|
|
26590
|
-
services: valid(inventoryServiceSchema, c.services, INVENTORY_LIMITS.services),
|
|
26591
|
-
containers: valid(inventoryContainerSchema, c.containers, INVENTORY_LIMITS.containers),
|
|
26592
|
-
images: valid(inventoryImageSchema, c.images, INVENTORY_LIMITS.images),
|
|
26593
|
-
pods: valid(inventoryPodSchema, c.pods, INVENTORY_LIMITS.pods),
|
|
26594
|
-
coverage: valid(inventoryCoverageSchema, c.coverage, INVENTORY_LIMITS.coverage)
|
|
26595
|
-
};
|
|
26596
|
-
return inventorySnapshotSchema.parse(snapshot);
|
|
26597
|
-
}
|
|
26598
|
-
|
|
26599
|
-
// dist/relay.js
|
|
26600
|
-
var HEARTBEAT_INTERVAL_MS = 2e4;
|
|
26601
|
-
var AUTH_TIMEOUT_MS = 2e4;
|
|
26602
|
-
var CLOSE_POLICY_VIOLATION = 4008;
|
|
26603
|
-
function relayUrl(gatewayUrl, deviceUuid2) {
|
|
26604
|
-
const url2 = new URL("/v1/agent/connect", gatewayUrl);
|
|
26605
|
-
url2.protocol = url2.protocol === "https:" ? "wss:" : "ws:";
|
|
26606
|
-
url2.search = new URLSearchParams({ device: deviceUuid2 }).toString();
|
|
26607
|
-
return url2.toString();
|
|
26608
|
-
}
|
|
26609
|
-
async function signRelayChallenge(key, deviceUuid2, nonce, connectionId) {
|
|
26610
|
-
const message = agentAuthMessage({ deviceUuid: deviceUuid2, nonce, connectionId });
|
|
26611
|
-
return toBase64Url(await key.sign(new TextEncoder().encode(message)));
|
|
26612
|
-
}
|
|
26613
|
-
var RelaySession = class {
|
|
26614
|
-
#options;
|
|
26615
|
-
#logger;
|
|
26616
|
-
#state = "challenge";
|
|
26617
|
-
#connectionEpoch = 0;
|
|
26618
|
-
#queue = Promise.resolve();
|
|
26619
|
-
constructor(options) {
|
|
26620
|
-
this.#options = options;
|
|
26621
|
-
this.#logger = options.logger ?? silentLogger;
|
|
26622
|
-
}
|
|
26623
|
-
get state() {
|
|
26624
|
-
return this.#state;
|
|
26625
|
-
}
|
|
26626
|
-
get identity() {
|
|
26627
|
-
const { tenant_id, user_id, device_uuid } = this.#options.identity;
|
|
26628
|
-
return { tenant_id, user_id, device_uuid };
|
|
26629
|
-
}
|
|
26630
|
-
/** Feed one incoming text frame; frames are processed strictly in order. */
|
|
26631
|
-
onMessage(text4) {
|
|
26632
|
-
const next = this.#queue.then(() => this.#process(text4));
|
|
26633
|
-
this.#queue = next.catch(() => void 0);
|
|
26634
|
-
return next;
|
|
26635
|
-
}
|
|
26636
|
-
#fail(reason) {
|
|
26637
|
-
if (this.#state === "closed")
|
|
26638
|
-
return;
|
|
26639
|
-
this.#logger.warn("closing relay connection", { reason });
|
|
26640
|
-
this.#state = "closed";
|
|
26641
|
-
this.#options.close(CLOSE_POLICY_VIOLATION, reason);
|
|
26642
|
-
}
|
|
26643
|
-
markClosed() {
|
|
26644
|
-
this.#state = "closed";
|
|
26645
|
-
}
|
|
26646
|
-
async #process(text4) {
|
|
26647
|
-
if (this.#state === "closed")
|
|
26648
|
-
return;
|
|
26649
|
-
if (this.#state === "challenge" || this.#state === "auth_sent") {
|
|
26650
|
-
let frame;
|
|
26651
|
-
try {
|
|
26652
|
-
frame = JSON.parse(text4);
|
|
26653
|
-
} catch {
|
|
26654
|
-
return this.#fail("invalid pre-auth frame");
|
|
26655
|
-
}
|
|
26656
|
-
if (this.#state === "challenge")
|
|
26657
|
-
return this.#onChallenge(frame);
|
|
26658
|
-
return this.#onAuthOk(frame);
|
|
26659
|
-
}
|
|
26660
|
-
let envelope;
|
|
26661
|
-
try {
|
|
26662
|
-
envelope = decodeEnvelope(text4);
|
|
26663
|
-
} catch (error63) {
|
|
26664
|
-
this.#logger.warn("ignoring invalid envelope", { code: error63 instanceof ProtocolDecodeError ? error63.code : "INVALID_MESSAGE" });
|
|
26665
|
-
return;
|
|
26666
|
-
}
|
|
26667
|
-
const identity = this.#options.identity;
|
|
26668
|
-
if (envelope.tenant_id !== identity.tenant_id || envelope.user_id !== identity.user_id || envelope.device_uuid !== identity.device_uuid) {
|
|
26669
|
-
return this.#fail("envelope identity mismatch");
|
|
26670
|
-
}
|
|
26671
|
-
switch (envelope.kind) {
|
|
26672
|
-
case "DISPATCH":
|
|
26673
|
-
void this.#options.dispatcher.handle(envelope);
|
|
26674
|
-
return;
|
|
26675
|
-
case "CANCEL":
|
|
26676
|
-
void this.#options.dispatcher.cancel(envelope).catch((error63) => {
|
|
26677
|
-
this.#logger.error("cancel handling failed", { task_id: envelope.task_id, error: error63 instanceof Error ? error63.name : "unknown" });
|
|
26678
|
-
});
|
|
26679
|
-
return;
|
|
26680
|
-
case "ERROR":
|
|
26681
|
-
this.#logger.warn("relay error", { code: envelope.code, message: envelope.safe_message });
|
|
26682
|
-
return;
|
|
26683
|
-
case "MONITOR_CONFIG":
|
|
26684
|
-
this.#options.onMonitorConfig?.({ enabled: envelope.enabled, interval_s: envelope.interval_s });
|
|
26685
|
-
return;
|
|
26686
|
-
case "SOFTWARE_INVENTORY_CONFIG":
|
|
26687
|
-
this.#options.onInventoryConfig?.({ enabled: envelope.enabled, interval_s: envelope.interval_s });
|
|
26688
|
-
return;
|
|
26689
|
-
case "SOFTWARE_INVENTORY_REQUEST":
|
|
26690
|
-
this.#options.onInventoryRequest?.(envelope.request_id);
|
|
26691
|
-
return;
|
|
26692
|
-
default:
|
|
26693
|
-
return;
|
|
26694
|
-
}
|
|
26695
|
-
}
|
|
26696
|
-
async #onChallenge(frame) {
|
|
26697
|
-
const parsed = relayChallengeSchema.safeParse(frame);
|
|
26698
|
-
if (!parsed.success)
|
|
26699
|
-
return this.#fail("expected CHALLENGE");
|
|
26700
|
-
const now = (this.#options.now ?? Date.now)();
|
|
26701
|
-
if (parsed.data.expires_at_ms <= now)
|
|
26702
|
-
return this.#fail("challenge expired");
|
|
26703
|
-
const deviceUuid2 = this.#options.identity.device_uuid;
|
|
26704
|
-
const signature = await signRelayChallenge(this.#options.key, deviceUuid2, parsed.data.nonce, parsed.data.connection_id);
|
|
26705
|
-
this.#state = "auth_sent";
|
|
26706
|
-
this.#options.send(JSON.stringify({ kind: "AUTH", device_uuid: deviceUuid2, connection_id: parsed.data.connection_id, signature }));
|
|
26707
|
-
}
|
|
26708
|
-
#onAuthOk(frame) {
|
|
26709
|
-
const parsed = relayAuthOkSchema.safeParse(frame);
|
|
26710
|
-
if (!parsed.success)
|
|
26711
|
-
return this.#fail("expected AUTH_OK");
|
|
26712
|
-
const identity = this.#options.identity;
|
|
26713
|
-
if (parsed.data.tenant_id !== identity.tenant_id || parsed.data.user_id !== identity.user_id || parsed.data.device_uuid !== identity.device_uuid) {
|
|
26714
|
-
return this.#fail("AUTH_OK identity mismatch");
|
|
26715
|
-
}
|
|
26716
|
-
this.#connectionEpoch = parsed.data.connection_epoch;
|
|
26717
|
-
this.#state = "ready";
|
|
26718
|
-
this.#sendEnvelope(buildEnvelope(this.identity, "HELLO", null, {
|
|
26719
|
-
agent_id: identity.device_uuid,
|
|
26720
|
-
supported_versions: [...SUPPORTED_VERSIONS],
|
|
26721
|
-
capabilities: [...DESKTOP_CAPABILITIES, ...SSH_CAPABILITIES, ...SHELL_CAPABILITIES]
|
|
26722
|
-
}));
|
|
26723
|
-
this.sendInventory();
|
|
26724
|
-
this.#options.onReady?.();
|
|
26725
|
-
}
|
|
26726
|
-
#sendEnvelope(envelope) {
|
|
26727
|
-
if (this.#state !== "ready")
|
|
26728
|
-
return;
|
|
26729
|
-
this.#options.send(encode3(envelope));
|
|
26730
|
-
}
|
|
26731
|
-
sendInventory() {
|
|
26732
|
-
const roots = this.#options.config().roots.map(({ root_id, label, writable }) => ({ root_id, label, writable }));
|
|
26733
|
-
const resources = this.#options.resources?.().map((resource) => ({ ...resource, ...resource.attrs ? { attrs: { ...resource.attrs } } : {} }));
|
|
26734
|
-
this.#sendEnvelope(buildEnvelope(this.identity, "INVENTORY", null, { roots, ...resources && resources.length > 0 ? { resources } : {}, agent_version: AGENT_VERSION }));
|
|
26735
|
-
}
|
|
26736
|
-
sendHeartbeat() {
|
|
26737
|
-
this.#sendEnvelope(buildEnvelope(this.identity, "HEARTBEAT", null, { connection_epoch: this.#connectionEpoch, status: "ONLINE" }));
|
|
26738
|
-
}
|
|
26739
|
-
/** One resource sample (telemetry, never a task); dropped silently unless authenticated. */
|
|
26740
|
-
sendMetrics(body) {
|
|
26741
|
-
if (this.#state !== "ready")
|
|
26742
|
-
return;
|
|
26743
|
-
this.#sendEnvelope(buildEnvelope(this.identity, "METRICS", null, body));
|
|
26744
|
-
}
|
|
26745
|
-
/** The parts of one software inventory run (telemetry, never a task); dropped silently unless authenticated. */
|
|
26746
|
-
sendInventoryParts(parts) {
|
|
26747
|
-
if (this.#state !== "ready")
|
|
26748
|
-
return;
|
|
26749
|
-
for (const part of parts)
|
|
26750
|
-
this.#sendEnvelope(buildEnvelope(this.identity, "SOFTWARE_INVENTORY_PART", null, part));
|
|
26751
|
-
}
|
|
26752
|
-
/** Forward a pre-encoded task frame (ACK/CHUNK/RESULT) if authenticated. */
|
|
26753
|
-
sendFrame(frame) {
|
|
26754
|
-
if (this.#state !== "ready")
|
|
26755
|
-
throw new Error("Relay session is not authenticated");
|
|
26756
|
-
this.#options.send(frame);
|
|
26757
|
-
}
|
|
26758
|
-
};
|
|
26759
|
-
function backoffDelay(attempt, options) {
|
|
26760
|
-
const cap = Math.min(options.maxMs, options.baseMs * 2 ** Math.min(attempt, 16));
|
|
26761
|
-
return Math.floor(cap / 2 + (options.random ?? Math.random)() * (cap / 2));
|
|
26762
|
-
}
|
|
26763
|
-
|
|
26764
|
-
// dist/ssh/exec.js
|
|
26765
|
-
var import_node_child_process7 = require("node:child_process");
|
|
26766
|
-
var import_node_path13 = require("node:path");
|
|
26767
|
-
|
|
26768
|
-
// dist/ssh/hosts.js
|
|
26769
|
-
var import_node_crypto9 = require("node:crypto");
|
|
26770
|
-
var import_promises12 = require("node:fs/promises");
|
|
26771
|
-
var import_node_path12 = require("node:path");
|
|
26772
|
-
var MAX_SSH_HOSTS = 64;
|
|
26773
|
-
var SSH_ALIAS = /^[a-z0-9][a-z0-9_-]{0,62}$/;
|
|
26774
|
-
var DNS_HOST = /^(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
|
|
26775
|
-
var IPV6_HOST = /^(?=.{2,45}$)[0-9A-Fa-f:.]*:[0-9A-Fa-f:.]*$/;
|
|
26776
|
-
var SSH_USER = /^[A-Za-z_][A-Za-z0-9_.-]{0,31}$/;
|
|
26777
|
-
function isValidSshHost(value) {
|
|
26778
|
-
return DNS_HOST.test(value) || IPV6_HOST.test(value);
|
|
26779
|
-
}
|
|
26780
|
-
function isValidIdentityPath(value) {
|
|
26781
|
-
return (0, import_node_path12.isAbsolute)(value) && value.length <= 1024 && !/[\u0000-\u001f\u007f%"]/.test(value);
|
|
26782
|
-
}
|
|
26783
|
-
var PINNABLE_KEY_TYPES = Object.freeze([
|
|
26784
|
-
"ssh-ed25519",
|
|
26785
|
-
"ecdsa-sha2-nistp256",
|
|
26786
|
-
"ecdsa-sha2-nistp384",
|
|
26787
|
-
"ecdsa-sha2-nistp521",
|
|
26788
|
-
"ssh-rsa"
|
|
26789
|
-
]);
|
|
26790
|
-
var base643 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
26791
|
-
var sshHostSchema = external_exports.strictObject({
|
|
26792
|
-
resource_id: external_exports.uuid(),
|
|
26793
|
-
alias: external_exports.string().regex(SSH_ALIAS),
|
|
26794
|
-
host: external_exports.string().refine(isValidSshHost, "Invalid host"),
|
|
26795
|
-
port: external_exports.number().int().min(1).max(65535),
|
|
26796
|
-
user: external_exports.string().regex(SSH_USER).optional(),
|
|
26797
|
-
identity: external_exports.string().refine(isValidIdentityPath, "Invalid identity path").optional(),
|
|
26798
|
-
production: external_exports.boolean(),
|
|
26799
|
-
key_type: external_exports.enum(PINNABLE_KEY_TYPES),
|
|
26800
|
-
public_key: external_exports.string().min(16).max(8192).regex(base643),
|
|
26801
|
-
fingerprint: external_exports.string().regex(/^SHA256:[A-Za-z0-9+/]{43}$/),
|
|
26802
|
-
pinned_at: external_exports.iso.datetime({ offset: true })
|
|
26803
|
-
});
|
|
26804
|
-
var hostsFileSchema = external_exports.strictObject({ version: external_exports.literal(1), hosts: external_exports.array(sshHostSchema).max(MAX_SSH_HOSTS) });
|
|
26805
|
-
function sshPaths(stateDir) {
|
|
26806
|
-
const dir = (0, import_node_path12.join)(stateDir, "ssh");
|
|
26807
|
-
return { dir, hosts: (0, import_node_path12.join)(dir, "hosts.json"), knownHostsDir: (0, import_node_path12.join)(dir, "known_hosts") };
|
|
26808
|
-
}
|
|
26809
|
-
function knownHostsPath(paths, resourceId) {
|
|
26810
|
-
return (0, import_node_path12.join)(paths.knownHostsDir, external_exports.uuid().parse(resourceId));
|
|
26811
|
-
}
|
|
26812
|
-
function hostKeyAlias(host) {
|
|
26813
|
-
return "conbridge-" + host.resource_id;
|
|
26814
|
-
}
|
|
26815
|
-
function fingerprintOf(publicKey) {
|
|
26816
|
-
return "SHA256:" + (0, import_node_crypto9.createHash)("sha256").update(Buffer.from(publicKey, "base64")).digest("base64").replace(/=+$/, "");
|
|
26817
|
-
}
|
|
26818
|
-
function normalizeFingerprint(value) {
|
|
26819
|
-
const trimmed = value.trim();
|
|
26820
|
-
return trimmed.startsWith("SHA256:") ? trimmed : "SHA256:" + trimmed;
|
|
26821
|
-
}
|
|
26822
|
-
function parseKeyscan(output2) {
|
|
26823
|
-
const keys = [];
|
|
26824
|
-
for (const line of output2.split("\n")) {
|
|
26825
|
-
const trimmed = line.trim();
|
|
26826
|
-
if (trimmed === "" || trimmed.startsWith("#"))
|
|
26827
|
-
continue;
|
|
26828
|
-
const [, type, key] = trimmed.split(/\s+/);
|
|
26829
|
-
if (!type || !key || !PINNABLE_KEY_TYPES.includes(type) || !base643.test(key) || key.length > 8192)
|
|
26830
|
-
continue;
|
|
26831
|
-
keys.push({ key_type: type, public_key: key, fingerprint: fingerprintOf(key) });
|
|
26832
|
-
}
|
|
26833
|
-
return keys;
|
|
26834
|
-
}
|
|
26835
|
-
function preferredKey(keys) {
|
|
26836
|
-
for (const type of PINNABLE_KEY_TYPES) {
|
|
26837
|
-
const key = keys.find((candidate) => candidate.key_type === type);
|
|
26838
|
-
if (key)
|
|
26839
|
-
return key;
|
|
26840
|
-
}
|
|
26841
|
-
return null;
|
|
26842
|
-
}
|
|
26843
|
-
async function loadSshHosts(paths) {
|
|
26844
|
-
let text4;
|
|
26845
|
-
try {
|
|
26846
|
-
text4 = await (0, import_promises12.readFile)(paths.hosts, "utf8");
|
|
26847
|
-
} catch (error63) {
|
|
26848
|
-
if (errorCode2(error63) === "ENOENT")
|
|
26849
|
-
return [];
|
|
26850
|
-
throw error63;
|
|
26851
|
-
}
|
|
26852
|
-
return hostsFileSchema.parse(JSON.parse(text4)).hosts;
|
|
26853
|
-
}
|
|
26854
|
-
async function ensureSshDirs(paths) {
|
|
26855
|
-
for (const dir of [paths.dir, paths.knownHostsDir]) {
|
|
26856
|
-
await (0, import_promises12.mkdir)(dir, { recursive: true, mode: 448 });
|
|
26857
|
-
await (0, import_promises12.chmod)(dir, 448);
|
|
26858
|
-
}
|
|
26859
|
-
}
|
|
26860
|
-
async function saveSshHosts(paths, hosts) {
|
|
26861
|
-
await ensureSshDirs(paths);
|
|
26862
|
-
await writeFileAtomic(paths.hosts, JSON.stringify(hostsFileSchema.parse({ version: 1, hosts }), null, 2) + "\n", 384);
|
|
26863
|
-
}
|
|
26864
|
-
async function writeKnownHosts(paths, host) {
|
|
26865
|
-
await ensureSshDirs(paths);
|
|
26866
|
-
await writeFileAtomic(knownHostsPath(paths, host.resource_id), `${hostKeyAlias(host)} ${host.key_type} ${host.public_key}
|
|
26867
|
-
`, 384);
|
|
26868
|
-
}
|
|
26869
|
-
async function validateNewHost(input2) {
|
|
26870
|
-
if (!SSH_ALIAS.test(input2.alias))
|
|
26871
|
-
throw new Error('Alias must be 1-63 lowercase letters, digits, "-" or "_", starting with a letter or digit');
|
|
26872
|
-
if (!isValidSshHost(input2.host))
|
|
26873
|
-
throw new Error("Host must be a DNS name, IPv4 or IPv6 address");
|
|
26874
|
-
if (input2.port !== void 0 && (!Number.isInteger(input2.port) || input2.port < 1 || input2.port > 65535))
|
|
26875
|
-
throw new Error("Port must be 1-65535");
|
|
26876
|
-
if (input2.user !== void 0 && !SSH_USER.test(input2.user))
|
|
26877
|
-
throw new Error("User must be a plain login name");
|
|
26878
|
-
if (input2.identity !== void 0) {
|
|
26879
|
-
if (!isValidIdentityPath(input2.identity))
|
|
26880
|
-
throw new Error("Identity must be an absolute path without quotes, % or control characters");
|
|
26881
|
-
const info = await (0, import_promises12.stat)(input2.identity).catch(() => null);
|
|
26882
|
-
if (!info?.isFile())
|
|
26883
|
-
throw new Error("Identity file not found");
|
|
26884
|
-
}
|
|
26885
|
-
}
|
|
26886
|
-
async function addSshHost(paths, input2, key, now = /* @__PURE__ */ new Date()) {
|
|
26887
|
-
await validateNewHost(input2);
|
|
26888
|
-
const hosts = await loadSshHosts(paths);
|
|
26889
|
-
if (hosts.some((host2) => host2.alias === input2.alias))
|
|
26890
|
-
throw new Error(`An SSH host named ${input2.alias} already exists`);
|
|
26891
|
-
if (hosts.length >= MAX_SSH_HOSTS)
|
|
26892
|
-
throw new Error(`At most ${MAX_SSH_HOSTS} SSH hosts are supported`);
|
|
26893
|
-
const host = sshHostSchema.parse({
|
|
26894
|
-
resource_id: (0, import_node_crypto9.randomUUID)(),
|
|
26895
|
-
alias: input2.alias,
|
|
26896
|
-
host: input2.host,
|
|
26897
|
-
port: input2.port ?? 22,
|
|
26898
|
-
...input2.user !== void 0 ? { user: input2.user } : {},
|
|
26899
|
-
...input2.identity !== void 0 ? { identity: input2.identity } : {},
|
|
26900
|
-
production: input2.production === true,
|
|
26901
|
-
key_type: key.key_type,
|
|
26902
|
-
public_key: key.public_key,
|
|
26903
|
-
fingerprint: key.fingerprint,
|
|
26904
|
-
pinned_at: now.toISOString()
|
|
26905
|
-
});
|
|
26906
|
-
await writeKnownHosts(paths, host);
|
|
26907
|
-
await saveSshHosts(paths, [...hosts, host]);
|
|
26908
|
-
return host;
|
|
26909
|
-
}
|
|
26910
|
-
async function findSshHost(paths, alias) {
|
|
26911
|
-
return (await loadSshHosts(paths)).find((host) => host.alias === alias) ?? null;
|
|
26912
|
-
}
|
|
26913
|
-
async function updateHost(paths, alias, change) {
|
|
26914
|
-
const hosts = await loadSshHosts(paths);
|
|
26915
|
-
const index = hosts.findIndex((host) => host.alias === alias);
|
|
26916
|
-
if (index < 0)
|
|
26917
|
-
throw new Error(`No SSH host named ${alias}`);
|
|
26918
|
-
const updated = sshHostSchema.parse(change(hosts[index]));
|
|
26919
|
-
const next = [...hosts];
|
|
26920
|
-
next[index] = updated;
|
|
26921
|
-
if (updated.public_key !== hosts[index].public_key || updated.key_type !== hosts[index].key_type)
|
|
26922
|
-
await writeKnownHosts(paths, updated);
|
|
26923
|
-
await saveSshHosts(paths, next);
|
|
26924
|
-
return updated;
|
|
26925
|
-
}
|
|
26926
|
-
async function repinSshHost(paths, alias, key, now = /* @__PURE__ */ new Date()) {
|
|
26927
|
-
return await updateHost(paths, alias, (host) => ({ ...host, key_type: key.key_type, public_key: key.public_key, fingerprint: key.fingerprint, pinned_at: now.toISOString() }));
|
|
26928
|
-
}
|
|
26929
|
-
async function setSshHostProduction(paths, alias, production) {
|
|
26930
|
-
return await updateHost(paths, alias, (host) => ({ ...host, production }));
|
|
26931
|
-
}
|
|
26932
|
-
async function removeSshHost(paths, alias) {
|
|
26933
|
-
const hosts = await loadSshHosts(paths);
|
|
26934
|
-
const host = hosts.find((entry) => entry.alias === alias);
|
|
26935
|
-
if (!host)
|
|
26936
|
-
return false;
|
|
26937
|
-
await saveSshHosts(paths, hosts.filter((entry) => entry !== host));
|
|
26938
|
-
await (0, import_promises12.unlink)(knownHostsPath(paths, host.resource_id)).catch(() => void 0);
|
|
26939
|
-
return true;
|
|
26940
|
-
}
|
|
26941
|
-
function hostAddress(host) {
|
|
26942
|
-
if (host.port === 22)
|
|
26943
|
-
return host.host;
|
|
26944
|
-
return host.host.includes(":") ? `[${host.host}]:${host.port}` : `${host.host}:${host.port}`;
|
|
26945
|
-
}
|
|
26946
|
-
function inventoryResource2(host) {
|
|
26947
|
-
return { resource_id: host.resource_id, kind: "ssh_host", label: host.alias, attrs: { production: host.production, address: hostAddress(host) } };
|
|
26948
|
-
}
|
|
26949
|
-
|
|
26950
|
-
// dist/ssh/exec.js
|
|
26951
|
-
var DEFAULT_SSH_BINARIES = Object.freeze({ ssh: "/usr/bin/ssh", keyscan: "/usr/bin/ssh-keyscan" });
|
|
26952
|
-
function sshBinariesFromEnv(env = process.env) {
|
|
26953
|
-
const pick2 = (value, fallback) => value && (0, import_node_path13.isAbsolute)(value) ? value : fallback;
|
|
26954
|
-
return { ssh: pick2(env.CONBRIDGE_SSH_BIN, DEFAULT_SSH_BINARIES.ssh), keyscan: pick2(env.CONBRIDGE_SSH_KEYSCAN_BIN, DEFAULT_SSH_BINARIES.keyscan) };
|
|
26955
|
-
}
|
|
26956
|
-
function sshChildEnv(env = process.env) {
|
|
26957
|
-
const child = {};
|
|
26958
|
-
for (const key of ["PATH", "HOME", "USER", "LOGNAME", "SSH_AUTH_SOCK", "LANG", "TMPDIR"]) {
|
|
26959
|
-
if (env[key] !== void 0)
|
|
26960
|
-
child[key] = env[key];
|
|
26961
|
-
}
|
|
26962
|
-
return child;
|
|
26963
|
-
}
|
|
26964
|
-
function runProcess(file2, args, options) {
|
|
26965
|
-
const started = Date.now();
|
|
26966
|
-
return new Promise((resolve8) => {
|
|
26967
|
-
const kept = { stdout: [], stderr: [] };
|
|
26968
|
-
const totals = { stdout: 0, stderr: 0 };
|
|
26969
|
-
let keptBytes = 0;
|
|
26970
|
-
let truncated = false;
|
|
26971
|
-
let timedOut = false;
|
|
26972
|
-
let settled = false;
|
|
26973
|
-
const child = (0, import_node_child_process7.spawn)(file2, [...args], { stdio: ["ignore", "pipe", "pipe"], env: options.env, shell: false });
|
|
26974
|
-
const collect = (stream) => (chunk2) => {
|
|
26975
|
-
totals[stream] += chunk2.length;
|
|
26976
|
-
const room = options.maxBytes - keptBytes;
|
|
26977
|
-
if (room <= 0) {
|
|
26978
|
-
truncated = true;
|
|
26979
|
-
return;
|
|
26980
|
-
}
|
|
26981
|
-
const piece = chunk2.length > room ? chunk2.subarray(0, room) : chunk2;
|
|
26982
|
-
if (piece.length < chunk2.length)
|
|
26983
|
-
truncated = true;
|
|
26984
|
-
kept[stream].push(piece);
|
|
26985
|
-
keptBytes += piece.length;
|
|
26986
|
-
};
|
|
26987
|
-
child.stdout.on("data", collect("stdout"));
|
|
26988
|
-
child.stderr.on("data", collect("stderr"));
|
|
26989
|
-
let killTimer;
|
|
26990
|
-
const timer = setTimeout(() => {
|
|
26991
|
-
timedOut = true;
|
|
26992
|
-
child.kill("SIGTERM");
|
|
26993
|
-
killTimer = setTimeout(() => child.kill("SIGKILL"), 2e3);
|
|
26994
|
-
}, options.timeoutMs);
|
|
26995
|
-
const finish = (exitCode, spawnError) => {
|
|
26996
|
-
if (settled)
|
|
26997
|
-
return;
|
|
26998
|
-
settled = true;
|
|
26999
|
-
clearTimeout(timer);
|
|
27000
|
-
if (killTimer)
|
|
27001
|
-
clearTimeout(killTimer);
|
|
27002
|
-
resolve8({
|
|
27003
|
-
exitCode,
|
|
27004
|
-
timedOut,
|
|
27005
|
-
truncated,
|
|
27006
|
-
durationMs: Date.now() - started,
|
|
27007
|
-
stdout: Buffer.concat(kept.stdout).toString("utf8"),
|
|
27008
|
-
stderr: Buffer.concat(kept.stderr).toString("utf8"),
|
|
27009
|
-
stdoutBytes: totals.stdout,
|
|
27010
|
-
stderrBytes: totals.stderr,
|
|
27011
|
-
...spawnError !== void 0 ? { spawnError } : {}
|
|
27012
|
-
});
|
|
27013
|
-
};
|
|
27014
|
-
child.on("error", (error63) => finish(null, error63.code ?? "SPAWN_FAILED"));
|
|
27015
|
-
child.on("close", (code) => finish(code));
|
|
27016
|
-
});
|
|
27017
|
-
}
|
|
27018
|
-
function keyscanType(type) {
|
|
27019
|
-
if (type === "ssh-ed25519")
|
|
27020
|
-
return "ed25519";
|
|
27021
|
-
if (type === "ssh-rsa")
|
|
27022
|
-
return "rsa";
|
|
27023
|
-
return "ecdsa";
|
|
27024
|
-
}
|
|
27025
|
-
function hostKeyAlgorithms(type) {
|
|
27026
|
-
return type === "ssh-rsa" ? "rsa-sha2-512,rsa-sha2-256" : type;
|
|
27233
|
+
continue;
|
|
27234
|
+
const ref = `${image.repository}:${image.tag}`;
|
|
27235
|
+
const count3 = c.containers.filter((ct) => ct.engine === image.engine && (ct.image === ref || image.tag === "latest" && ct.image === image.repository || ct.image.startsWith(image.id))).length;
|
|
27236
|
+
image.containers = count3;
|
|
27237
|
+
}
|
|
27027
27238
|
}
|
|
27028
|
-
function
|
|
27029
|
-
|
|
27030
|
-
|
|
27031
|
-
|
|
27032
|
-
|
|
27239
|
+
async function collectInventory(system = defaultCollectorSystem) {
|
|
27240
|
+
const c = new Collection(system);
|
|
27241
|
+
const os = await collectOs(c);
|
|
27242
|
+
await collectPackages(c);
|
|
27243
|
+
await collectSoftware(c);
|
|
27244
|
+
await collectServices(c);
|
|
27245
|
+
await collectContainers(c);
|
|
27246
|
+
const snapshot = {
|
|
27247
|
+
schema: 1,
|
|
27248
|
+
collected_at: system.now().toISOString(),
|
|
27249
|
+
agent_version: AGENT_VERSION,
|
|
27250
|
+
os: inventoryOsSchema.safeParse(os).success ? os : { family: "other", name: system.platform, version: "", arch: system.arch },
|
|
27251
|
+
packages: valid(inventoryPackageSchema, c.packages, INVENTORY_LIMITS.packages),
|
|
27252
|
+
software: valid(inventorySoftwareSchema, c.software, INVENTORY_LIMITS.software),
|
|
27253
|
+
services: valid(inventoryServiceSchema, c.services, INVENTORY_LIMITS.services),
|
|
27254
|
+
containers: valid(inventoryContainerSchema, c.containers, INVENTORY_LIMITS.containers),
|
|
27255
|
+
images: valid(inventoryImageSchema, c.images, INVENTORY_LIMITS.images),
|
|
27256
|
+
pods: valid(inventoryPodSchema, c.pods, INVENTORY_LIMITS.pods),
|
|
27257
|
+
coverage: valid(inventoryCoverageSchema, c.coverage, INVENTORY_LIMITS.coverage)
|
|
27258
|
+
};
|
|
27259
|
+
return inventorySnapshotSchema.parse(snapshot);
|
|
27033
27260
|
}
|
|
27034
|
-
|
|
27035
|
-
|
|
27036
|
-
|
|
27037
|
-
|
|
27038
|
-
|
|
27039
|
-
|
|
27040
|
-
|
|
27041
|
-
|
|
27042
|
-
|
|
27261
|
+
|
|
27262
|
+
// dist/relay.js
|
|
27263
|
+
var HEARTBEAT_INTERVAL_MS = 2e4;
|
|
27264
|
+
var AUTH_TIMEOUT_MS = 2e4;
|
|
27265
|
+
var CLOSE_POLICY_VIOLATION = 4008;
|
|
27266
|
+
function relayUrl(gatewayUrl, deviceUuid2) {
|
|
27267
|
+
const url2 = new URL("/v1/agent/connect", gatewayUrl);
|
|
27268
|
+
url2.protocol = url2.protocol === "https:" ? "wss:" : "ws:";
|
|
27269
|
+
url2.search = new URLSearchParams({ device: deviceUuid2 }).toString();
|
|
27270
|
+
return url2.toString();
|
|
27043
27271
|
}
|
|
27044
|
-
function
|
|
27045
|
-
const
|
|
27046
|
-
|
|
27047
|
-
"StrictHostKeyChecking=yes",
|
|
27048
|
-
`UserKnownHostsFile=${sshConfigPath(knownHostsPath(paths, host.resource_id))}`,
|
|
27049
|
-
"GlobalKnownHostsFile=/dev/null",
|
|
27050
|
-
`HostKeyAlias=${hostKeyAlias(host)}`,
|
|
27051
|
-
`HostKeyAlgorithms=${hostKeyAlgorithms(host.key_type)}`,
|
|
27052
|
-
"UpdateHostKeys=no",
|
|
27053
|
-
"CheckHostIP=no",
|
|
27054
|
-
"PasswordAuthentication=no",
|
|
27055
|
-
"KbdInteractiveAuthentication=no",
|
|
27056
|
-
"ProxyCommand=none",
|
|
27057
|
-
"PermitLocalCommand=no",
|
|
27058
|
-
"ForwardAgent=no",
|
|
27059
|
-
"ForwardX11=no",
|
|
27060
|
-
"ClearAllForwardings=yes",
|
|
27061
|
-
"ControlMaster=no",
|
|
27062
|
-
"ControlPath=none",
|
|
27063
|
-
"RequestTTY=no",
|
|
27064
|
-
"ConnectTimeout=15",
|
|
27065
|
-
"ServerAliveInterval=15",
|
|
27066
|
-
"ServerAliveCountMax=3",
|
|
27067
|
-
"LogLevel=ERROR",
|
|
27068
|
-
...host.identity !== void 0 ? ["IdentitiesOnly=yes"] : []
|
|
27069
|
-
];
|
|
27070
|
-
return [
|
|
27071
|
-
"-F",
|
|
27072
|
-
"/dev/null",
|
|
27073
|
-
...options.flatMap((option) => ["-o", option]),
|
|
27074
|
-
...host.identity !== void 0 ? ["-i", host.identity] : [],
|
|
27075
|
-
"-p",
|
|
27076
|
-
String(host.port),
|
|
27077
|
-
...host.user !== void 0 ? ["-l", host.user] : [],
|
|
27078
|
-
"-n",
|
|
27079
|
-
"-T",
|
|
27080
|
-
"--",
|
|
27081
|
-
host.host,
|
|
27082
|
-
command2
|
|
27083
|
-
];
|
|
27272
|
+
async function signRelayChallenge(key, deviceUuid2, nonce, connectionId) {
|
|
27273
|
+
const message = agentAuthMessage({ deviceUuid: deviceUuid2, nonce, connectionId });
|
|
27274
|
+
return toBase64Url(await key.sign(new TextEncoder().encode(message)));
|
|
27084
27275
|
}
|
|
27085
|
-
|
|
27086
|
-
|
|
27276
|
+
var RelaySession = class {
|
|
27277
|
+
#options;
|
|
27278
|
+
#logger;
|
|
27279
|
+
#state = "challenge";
|
|
27280
|
+
#connectionEpoch = 0;
|
|
27281
|
+
#queue = Promise.resolve();
|
|
27282
|
+
constructor(options) {
|
|
27283
|
+
this.#options = options;
|
|
27284
|
+
this.#logger = options.logger ?? silentLogger;
|
|
27285
|
+
}
|
|
27286
|
+
get state() {
|
|
27287
|
+
return this.#state;
|
|
27288
|
+
}
|
|
27289
|
+
get identity() {
|
|
27290
|
+
const { tenant_id, user_id, device_uuid } = this.#options.identity;
|
|
27291
|
+
return { tenant_id, user_id, device_uuid };
|
|
27292
|
+
}
|
|
27293
|
+
/** Feed one incoming text frame; frames are processed strictly in order. */
|
|
27294
|
+
onMessage(text4) {
|
|
27295
|
+
const next = this.#queue.then(() => this.#process(text4));
|
|
27296
|
+
this.#queue = next.catch(() => void 0);
|
|
27297
|
+
return next;
|
|
27298
|
+
}
|
|
27299
|
+
#fail(reason) {
|
|
27300
|
+
if (this.#state === "closed")
|
|
27301
|
+
return;
|
|
27302
|
+
this.#logger.warn("closing relay connection", { reason });
|
|
27303
|
+
this.#state = "closed";
|
|
27304
|
+
this.#options.close(CLOSE_POLICY_VIOLATION, reason);
|
|
27305
|
+
}
|
|
27306
|
+
markClosed() {
|
|
27307
|
+
this.#state = "closed";
|
|
27308
|
+
}
|
|
27309
|
+
async #process(text4) {
|
|
27310
|
+
if (this.#state === "closed")
|
|
27311
|
+
return;
|
|
27312
|
+
if (this.#state === "challenge" || this.#state === "auth_sent") {
|
|
27313
|
+
let frame;
|
|
27314
|
+
try {
|
|
27315
|
+
frame = JSON.parse(text4);
|
|
27316
|
+
} catch {
|
|
27317
|
+
return this.#fail("invalid pre-auth frame");
|
|
27318
|
+
}
|
|
27319
|
+
if (this.#state === "challenge")
|
|
27320
|
+
return this.#onChallenge(frame);
|
|
27321
|
+
return this.#onAuthOk(frame);
|
|
27322
|
+
}
|
|
27323
|
+
let envelope;
|
|
27324
|
+
try {
|
|
27325
|
+
envelope = decodeEnvelope(text4);
|
|
27326
|
+
} catch (error63) {
|
|
27327
|
+
this.#logger.warn("ignoring invalid envelope", { code: error63 instanceof ProtocolDecodeError ? error63.code : "INVALID_MESSAGE" });
|
|
27328
|
+
return;
|
|
27329
|
+
}
|
|
27330
|
+
const identity = this.#options.identity;
|
|
27331
|
+
if (envelope.tenant_id !== identity.tenant_id || envelope.user_id !== identity.user_id || envelope.device_uuid !== identity.device_uuid) {
|
|
27332
|
+
return this.#fail("envelope identity mismatch");
|
|
27333
|
+
}
|
|
27334
|
+
switch (envelope.kind) {
|
|
27335
|
+
case "DISPATCH":
|
|
27336
|
+
void this.#options.dispatcher.handle(envelope);
|
|
27337
|
+
return;
|
|
27338
|
+
case "CANCEL":
|
|
27339
|
+
void this.#options.dispatcher.cancel(envelope).catch((error63) => {
|
|
27340
|
+
this.#logger.error("cancel handling failed", { task_id: envelope.task_id, error: error63 instanceof Error ? error63.name : "unknown" });
|
|
27341
|
+
});
|
|
27342
|
+
return;
|
|
27343
|
+
case "ERROR":
|
|
27344
|
+
this.#logger.warn("relay error", { code: envelope.code, message: envelope.safe_message });
|
|
27345
|
+
return;
|
|
27346
|
+
case "MONITOR_CONFIG":
|
|
27347
|
+
this.#options.onMonitorConfig?.({ enabled: envelope.enabled, interval_s: envelope.interval_s });
|
|
27348
|
+
return;
|
|
27349
|
+
case "SOFTWARE_INVENTORY_CONFIG":
|
|
27350
|
+
this.#options.onInventoryConfig?.({
|
|
27351
|
+
enabled: envelope.enabled,
|
|
27352
|
+
interval_s: envelope.interval_s,
|
|
27353
|
+
...envelope.ssh_hosts !== void 0 ? { ssh_hosts: envelope.ssh_hosts } : {}
|
|
27354
|
+
});
|
|
27355
|
+
return;
|
|
27356
|
+
case "SOFTWARE_INVENTORY_REQUEST":
|
|
27357
|
+
this.#options.onInventoryRequest?.(envelope.request_id);
|
|
27358
|
+
return;
|
|
27359
|
+
default:
|
|
27360
|
+
return;
|
|
27361
|
+
}
|
|
27362
|
+
}
|
|
27363
|
+
async #onChallenge(frame) {
|
|
27364
|
+
const parsed = relayChallengeSchema.safeParse(frame);
|
|
27365
|
+
if (!parsed.success)
|
|
27366
|
+
return this.#fail("expected CHALLENGE");
|
|
27367
|
+
const now = (this.#options.now ?? Date.now)();
|
|
27368
|
+
if (parsed.data.expires_at_ms <= now)
|
|
27369
|
+
return this.#fail("challenge expired");
|
|
27370
|
+
const deviceUuid2 = this.#options.identity.device_uuid;
|
|
27371
|
+
const signature = await signRelayChallenge(this.#options.key, deviceUuid2, parsed.data.nonce, parsed.data.connection_id);
|
|
27372
|
+
this.#state = "auth_sent";
|
|
27373
|
+
this.#options.send(JSON.stringify({ kind: "AUTH", device_uuid: deviceUuid2, connection_id: parsed.data.connection_id, signature }));
|
|
27374
|
+
}
|
|
27375
|
+
#onAuthOk(frame) {
|
|
27376
|
+
const parsed = relayAuthOkSchema.safeParse(frame);
|
|
27377
|
+
if (!parsed.success)
|
|
27378
|
+
return this.#fail("expected AUTH_OK");
|
|
27379
|
+
const identity = this.#options.identity;
|
|
27380
|
+
if (parsed.data.tenant_id !== identity.tenant_id || parsed.data.user_id !== identity.user_id || parsed.data.device_uuid !== identity.device_uuid) {
|
|
27381
|
+
return this.#fail("AUTH_OK identity mismatch");
|
|
27382
|
+
}
|
|
27383
|
+
this.#connectionEpoch = parsed.data.connection_epoch;
|
|
27384
|
+
this.#state = "ready";
|
|
27385
|
+
this.#sendEnvelope(buildEnvelope(this.identity, "HELLO", null, {
|
|
27386
|
+
agent_id: identity.device_uuid,
|
|
27387
|
+
supported_versions: [...SUPPORTED_VERSIONS],
|
|
27388
|
+
capabilities: [...DESKTOP_CAPABILITIES, ...SSH_CAPABILITIES, ...SHELL_CAPABILITIES]
|
|
27389
|
+
}));
|
|
27390
|
+
this.sendInventory();
|
|
27391
|
+
this.#options.onReady?.();
|
|
27392
|
+
}
|
|
27393
|
+
#sendEnvelope(envelope) {
|
|
27394
|
+
if (this.#state !== "ready")
|
|
27395
|
+
return;
|
|
27396
|
+
this.#options.send(encode3(envelope));
|
|
27397
|
+
}
|
|
27398
|
+
sendInventory() {
|
|
27399
|
+
const roots = this.#options.config().roots.map(({ root_id, label, writable }) => ({ root_id, label, writable }));
|
|
27400
|
+
const resources = this.#options.resources?.().map((resource) => ({ ...resource, ...resource.attrs ? { attrs: { ...resource.attrs } } : {} }));
|
|
27401
|
+
this.#sendEnvelope(buildEnvelope(this.identity, "INVENTORY", null, { roots, ...resources && resources.length > 0 ? { resources } : {}, agent_version: AGENT_VERSION }));
|
|
27402
|
+
}
|
|
27403
|
+
sendHeartbeat() {
|
|
27404
|
+
this.#sendEnvelope(buildEnvelope(this.identity, "HEARTBEAT", null, { connection_epoch: this.#connectionEpoch, status: "ONLINE" }));
|
|
27405
|
+
}
|
|
27406
|
+
/** One resource sample (telemetry, never a task); dropped silently unless authenticated. */
|
|
27407
|
+
sendMetrics(body) {
|
|
27408
|
+
if (this.#state !== "ready")
|
|
27409
|
+
return;
|
|
27410
|
+
this.#sendEnvelope(buildEnvelope(this.identity, "METRICS", null, body));
|
|
27411
|
+
}
|
|
27412
|
+
/** The parts of one software inventory run (telemetry, never a task); dropped silently unless authenticated. */
|
|
27413
|
+
sendInventoryParts(parts) {
|
|
27414
|
+
if (this.#state !== "ready")
|
|
27415
|
+
return;
|
|
27416
|
+
for (const part of parts)
|
|
27417
|
+
this.#sendEnvelope(buildEnvelope(this.identity, "SOFTWARE_INVENTORY_PART", null, part));
|
|
27418
|
+
}
|
|
27419
|
+
/** Forward a pre-encoded task frame (ACK/CHUNK/RESULT) if authenticated. */
|
|
27420
|
+
sendFrame(frame) {
|
|
27421
|
+
if (this.#state !== "ready")
|
|
27422
|
+
throw new Error("Relay session is not authenticated");
|
|
27423
|
+
this.#options.send(frame);
|
|
27424
|
+
}
|
|
27425
|
+
};
|
|
27426
|
+
function backoffDelay(attempt, options) {
|
|
27427
|
+
const cap = Math.min(options.maxMs, options.baseMs * 2 ** Math.min(attempt, 16));
|
|
27428
|
+
return Math.floor(cap / 2 + (options.random ?? Math.random)() * (cap / 2));
|
|
27087
27429
|
}
|
|
27088
27430
|
|
|
27089
27431
|
// dist/ssh/handler.js
|
|
@@ -27809,6 +28151,8 @@ var AgentRunner = class {
|
|
|
27809
28151
|
#logger;
|
|
27810
28152
|
#dispatcher;
|
|
27811
28153
|
#shell;
|
|
28154
|
+
/** Runs the constant SSH inventory script on one pinned host (ADR SECURITY_INTELLIGENCE 11.6). */
|
|
28155
|
+
#sshInventoryExec;
|
|
27812
28156
|
#config = null;
|
|
27813
28157
|
#sshHosts = [];
|
|
27814
28158
|
#session = null;
|
|
@@ -27824,6 +28168,8 @@ var AgentRunner = class {
|
|
|
27824
28168
|
this.#options = options;
|
|
27825
28169
|
this.#logger = options.logger ?? silentLogger;
|
|
27826
28170
|
this.#shell = new ShellExecutor({ logger: this.#logger });
|
|
28171
|
+
const binaries = options.sshBinaries ?? sshBinariesFromEnv();
|
|
28172
|
+
this.#sshInventoryExec = options.inventory?.sshExec ?? defaultSshInventoryExec(sshPaths(options.paths.dir), binaries);
|
|
27827
28173
|
const dispatcherOptions = {
|
|
27828
28174
|
shell: this.#shell,
|
|
27829
28175
|
identity: options.identity,
|
|
@@ -27842,7 +28188,7 @@ var AgentRunner = class {
|
|
|
27842
28188
|
logger: this.#logger,
|
|
27843
28189
|
protectedPaths: options.protectedPaths ?? protectedAgentPaths(options.paths.dir),
|
|
27844
28190
|
sshHosts: () => this.#sshHosts,
|
|
27845
|
-
ssh: new SshExecutor({ paths: sshPaths(options.paths.dir), binaries
|
|
28191
|
+
ssh: new SshExecutor({ paths: sshPaths(options.paths.dir), binaries, logger: this.#logger })
|
|
27846
28192
|
};
|
|
27847
28193
|
this.#dispatcher = new Dispatcher(options.confirmWrite ? { ...dispatcherOptions, confirmWrite: options.confirmWrite } : dispatcherOptions);
|
|
27848
28194
|
}
|
|
@@ -28001,6 +28347,8 @@ var AgentRunner = class {
|
|
|
28001
28347
|
onSent: (at) => {
|
|
28002
28348
|
this.#inventorySentAtMs = at;
|
|
28003
28349
|
},
|
|
28350
|
+
sshHosts: () => this.#sshHosts,
|
|
28351
|
+
collectSshHost: (host) => collectSshHostInventory(host, this.#sshInventoryExec),
|
|
28004
28352
|
send: (parts) => session.sendInventoryParts(parts),
|
|
28005
28353
|
logger: this.#logger
|
|
28006
28354
|
});
|
|
@@ -28222,7 +28570,6 @@ async function cmdSsh(stateDir, args, io) {
|
|
|
28222
28570
|
}
|
|
28223
28571
|
|
|
28224
28572
|
// dist/cli.js
|
|
28225
|
-
var import_promises16 = require("node:fs/promises");
|
|
28226
28573
|
var USAGE = `conbridge-agent ${AGENT_VERSION}
|
|
28227
28574
|
|
|
28228
28575
|
Usage:
|
|
@@ -28271,17 +28618,30 @@ async function exists(path) {
|
|
|
28271
28618
|
async function runInstalledCopy(paths, argv, io, keepsIdentity = true) {
|
|
28272
28619
|
if (!runningFromNpm() || await runningFromRuntime(paths.dir))
|
|
28273
28620
|
return null;
|
|
28274
|
-
const
|
|
28275
|
-
|
|
28621
|
+
const previous = await loadIdentity(paths).catch(() => null);
|
|
28622
|
+
const blocked = await keychainUpdateProblem(previous, (descriptor) => openKeyStore(paths, descriptor, { env: io.env }));
|
|
28623
|
+
if (blocked && keepsIdentity) {
|
|
28276
28624
|
io.err(blocked);
|
|
28277
28625
|
return 2;
|
|
28278
28626
|
}
|
|
28279
28627
|
await ensureStateDir(paths.dir);
|
|
28280
|
-
const
|
|
28281
|
-
|
|
28282
|
-
|
|
28283
|
-
|
|
28284
|
-
|
|
28628
|
+
const snapshot = blocked ? await snapshotRuntime(paths.dir) : null;
|
|
28629
|
+
let status;
|
|
28630
|
+
try {
|
|
28631
|
+
const { entry } = await installRuntime(paths.dir);
|
|
28632
|
+
const child = (0, import_node_child_process10.spawnSync)(process.execPath, [entry, ...argv], { stdio: "inherit", env: io.env });
|
|
28633
|
+
if (child.error)
|
|
28634
|
+
throw child.error;
|
|
28635
|
+
status = child.status ?? 1;
|
|
28636
|
+
} catch (error63) {
|
|
28637
|
+
await snapshot?.restore();
|
|
28638
|
+
throw error63;
|
|
28639
|
+
}
|
|
28640
|
+
if (snapshot) {
|
|
28641
|
+
const replaced = (await loadIdentity(paths).catch(() => null))?.device_uuid !== previous?.device_uuid;
|
|
28642
|
+
await (status !== 0 && !replaced ? snapshot.restore() : snapshot.discard());
|
|
28643
|
+
}
|
|
28644
|
+
return status;
|
|
28285
28645
|
}
|
|
28286
28646
|
async function keychainUpdateProblem(identity, open6) {
|
|
28287
28647
|
const descriptor = identity?.key_store;
|
|
@@ -28296,6 +28656,9 @@ async function keychainUpdateProblem(identity, open6) {
|
|
|
28296
28656
|
To move to ${AGENT_VERSION}, create a pairing code in the ConBridge Console and run: npx --yes conbridge-agent@latest pair --force --code XXXX-XXXX (then remove the old device in the Console).`;
|
|
28297
28657
|
}
|
|
28298
28658
|
}
|
|
28659
|
+
function pendingKeyPath(paths) {
|
|
28660
|
+
return `${paths.key}.pending`;
|
|
28661
|
+
}
|
|
28299
28662
|
async function newKeyStore(paths, values, env) {
|
|
28300
28663
|
const helper = await findKeychainHelper({ env });
|
|
28301
28664
|
const requested = values["key-store"] ?? (values.keychain !== void 0 ? "keychain" : void 0);
|
|
@@ -28308,7 +28671,7 @@ async function newKeyStore(paths, values, env) {
|
|
|
28308
28671
|
if (type === "file") {
|
|
28309
28672
|
if (values.keychain !== void 0)
|
|
28310
28673
|
throw new UsageError("--keychain only applies to the keychain key store");
|
|
28311
|
-
return new FileKeyStore(paths
|
|
28674
|
+
return new FileKeyStore(pendingKeyPath(paths));
|
|
28312
28675
|
}
|
|
28313
28676
|
if (values.keychain !== void 0 && !(0, import_node_path17.isAbsolute)(values.keychain))
|
|
28314
28677
|
throw new UsageError("--keychain needs an absolute path");
|
|
@@ -28348,12 +28711,8 @@ async function cmdPair(paths, args, io) {
|
|
|
28348
28711
|
const name3 = (values.name ?? (0, import_node_os8.hostname)()).trim().slice(0, 64) || "My computer";
|
|
28349
28712
|
const keyStore = await newKeyStore(paths, values, io.env);
|
|
28350
28713
|
const previous = await loadIdentity(paths);
|
|
28351
|
-
if (previous)
|
|
28352
|
-
|
|
28353
|
-
throw new UsageError("This agent is already paired; use --force to pair again (the old identity is discarded)");
|
|
28354
|
-
await (0, import_promises16.unlink)(paths.identity).catch(() => void 0);
|
|
28355
|
-
await discardOldKey(paths, previous, io.env);
|
|
28356
|
-
}
|
|
28714
|
+
if (previous && !values.force)
|
|
28715
|
+
throw new UsageError("This agent is already paired; use --force to pair again (the old identity is replaced once the new pairing is approved)");
|
|
28357
28716
|
await ensureStateDir(paths.dir);
|
|
28358
28717
|
io.out(`Device key store: ${keyStore.descriptor.type === "keychain" ? "macOS Keychain" : `file ${paths.key}`}`);
|
|
28359
28718
|
const identity = await pairDevice({
|
|
@@ -28365,8 +28724,14 @@ async function cmdPair(paths, args, io) {
|
|
|
28365
28724
|
onOffered: ({ fingerprint }) => {
|
|
28366
28725
|
io.out(`Offer sent. Device fingerprint: ${fingerprint}`);
|
|
28367
28726
|
io.out("Approve this device in the ConBridge Console and check that the fingerprint matches. Waiting...");
|
|
28727
|
+
},
|
|
28728
|
+
onApproved: async () => {
|
|
28729
|
+
if (keyStore.descriptor.type === "file")
|
|
28730
|
+
await (0, import_promises15.rename)(pendingKeyPath(paths), paths.key);
|
|
28368
28731
|
}
|
|
28369
28732
|
});
|
|
28733
|
+
if (previous && !(keyStore.descriptor.type === "file" && previous.key_store?.type !== "keychain"))
|
|
28734
|
+
await discardOldKey(paths, previous, io.env);
|
|
28370
28735
|
io.out(`Paired as "${identity.display_name}" (device ${identity.device_uuid}).`);
|
|
28371
28736
|
if (values["full-access"])
|
|
28372
28737
|
await cmdAccess(paths, ["full"], io);
|