@mgsoftwarebv/mg-dashboard-mcp 6.6.2 → 6.7.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/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18,7 +18,6 @@ import postgres from 'postgres';
|
|
|
18
18
|
import { readFile, mkdtemp, writeFile, rm } from 'fs/promises';
|
|
19
19
|
import { tmpdir } from 'os';
|
|
20
20
|
import { once } from 'events';
|
|
21
|
-
import https from 'https';
|
|
22
21
|
import { lookup } from 'dns/promises';
|
|
23
22
|
import { connect } from 'tls';
|
|
24
23
|
import { HeadObjectCommand, S3Client, ListObjectsV2Command, DeleteObjectsCommand, DeleteObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, CompleteMultipartUploadCommand, AbortMultipartUploadCommand, PutObjectCommand, GetObjectCommand, CopyObjectCommand } from '@aws-sdk/client-s3';
|
|
@@ -1593,33 +1592,49 @@ async function fetchViaSshProxy(options) {
|
|
|
1593
1592
|
})
|
|
1594
1593
|
]);
|
|
1595
1594
|
if (timer) clearTimeout(timer);
|
|
1595
|
+
const requestPath = `${parsedUrl.pathname || "/"}${parsedUrl.search}`;
|
|
1596
|
+
const headerLines = [`${method} ${requestPath} HTTP/1.1`];
|
|
1597
|
+
if (!("Connection" in headers)) headers.Connection = "close";
|
|
1598
|
+
for (const [k, v] of Object.entries(headers)) headerLines.push(`${k}: ${v}`);
|
|
1599
|
+
headerLines.push("", "");
|
|
1600
|
+
tlsSocket.write(headerLines.join("\r\n"));
|
|
1601
|
+
if (body) tlsSocket.write(body);
|
|
1596
1602
|
return await new Promise((resolve, reject) => {
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
(
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1603
|
+
const chunks = [];
|
|
1604
|
+
const onError = (err) => {
|
|
1605
|
+
tlsSocket.removeAllListeners();
|
|
1606
|
+
reject(err);
|
|
1607
|
+
};
|
|
1608
|
+
tlsSocket.on("data", (chunk) => chunks.push(chunk));
|
|
1609
|
+
tlsSocket.on("end", () => {
|
|
1610
|
+
const raw = Buffer.concat(chunks);
|
|
1611
|
+
const headerEnd = raw.indexOf("\r\n\r\n");
|
|
1612
|
+
if (headerEnd === -1) return reject(new Error("mijn.host response missing headers"));
|
|
1613
|
+
const headerBlob = raw.slice(0, headerEnd).toString("utf8");
|
|
1614
|
+
const [statusLine, ...headerLinesIn] = headerBlob.split("\r\n");
|
|
1615
|
+
const statusMatch = statusLine?.match(/^HTTP\/\d\.\d (\d{3}) ?(.*)$/);
|
|
1616
|
+
if (!statusMatch) return reject(new Error(`Invalid status line: ${statusLine}`));
|
|
1617
|
+
const status = Number(statusMatch[1]);
|
|
1618
|
+
const statusText = statusMatch[2] ?? "";
|
|
1619
|
+
let bodyBuf = raw.slice(headerEnd + 4);
|
|
1620
|
+
const transferEnc = headerLinesIn.find((l) => /^transfer-encoding:/i.test(l))?.split(":")[1]?.trim().toLowerCase();
|
|
1621
|
+
if (transferEnc === "chunked") {
|
|
1622
|
+
const decoded = [];
|
|
1623
|
+
let i = 0;
|
|
1624
|
+
while (i < bodyBuf.length) {
|
|
1625
|
+
const lineEnd = bodyBuf.indexOf("\r\n", i);
|
|
1626
|
+
if (lineEnd === -1) break;
|
|
1627
|
+
const size = parseInt(bodyBuf.slice(i, lineEnd).toString("ascii"), 16);
|
|
1628
|
+
if (!Number.isFinite(size) || size <= 0) break;
|
|
1629
|
+
i = lineEnd + 2;
|
|
1630
|
+
decoded.push(bodyBuf.slice(i, i + size));
|
|
1631
|
+
i += size + 2;
|
|
1632
|
+
}
|
|
1633
|
+
bodyBuf = Buffer.concat(decoded);
|
|
1618
1634
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
req.end();
|
|
1635
|
+
resolve({ status, statusText, body: bodyBuf.toString("utf8") });
|
|
1636
|
+
});
|
|
1637
|
+
tlsSocket.on("error", onError);
|
|
1623
1638
|
});
|
|
1624
1639
|
} finally {
|
|
1625
1640
|
if (timer) clearTimeout(timer);
|
|
@@ -2274,7 +2289,7 @@ async function getServerConnection(serverIdOrName) {
|
|
|
2274
2289
|
assertServerAccess(serverId);
|
|
2275
2290
|
const rows = await db.execute(sql`
|
|
2276
2291
|
SELECT hostname, port, username, password_encrypted, ssh_key_encrypted,
|
|
2277
|
-
ssh_key_passphrase_encrypted,
|
|
2292
|
+
ssh_key_passphrase_encrypted, os_type
|
|
2278
2293
|
FROM ssh_server
|
|
2279
2294
|
WHERE id = ${serverId}
|
|
2280
2295
|
LIMIT 1
|
|
@@ -2295,7 +2310,7 @@ async function getServerConnection(serverIdOrName) {
|
|
|
2295
2310
|
privateKey: data.ssh_key_encrypted ? decrypt(data.ssh_key_encrypted) : void 0,
|
|
2296
2311
|
passphrase: data.ssh_key_passphrase_encrypted ? decrypt(data.ssh_key_passphrase_encrypted) : void 0
|
|
2297
2312
|
};
|
|
2298
|
-
const needsProxy =
|
|
2313
|
+
const needsProxy = serverId !== SSH_PROXY_SERVER_ID;
|
|
2299
2314
|
const proxy = needsProxy ? await getProxyConnection() : void 0;
|
|
2300
2315
|
const os = data.os_type === "windows" ? "windows" : "linux";
|
|
2301
2316
|
return { serverId, conn, proxy, os };
|
|
@@ -4034,7 +4049,7 @@ async function mijnhostFetch(path, options = {}) {
|
|
|
4034
4049
|
"API-Key": key,
|
|
4035
4050
|
"Accept": "application/json",
|
|
4036
4051
|
"Content-Type": "application/json",
|
|
4037
|
-
"User-Agent": "mg-dashboard-mcp/6.6.
|
|
4052
|
+
"User-Agent": "mg-dashboard-mcp/6.6.3",
|
|
4038
4053
|
...options.headers || {}
|
|
4039
4054
|
};
|
|
4040
4055
|
const method = options.method ?? "GET";
|