MCPcopy Create free account
hub / github.com/gnmyt/Nexterm / execCommand

Function execCommand

server/controllers/execCommand.js:8–57  ·  view source on GitHub ↗
(accountId, entryId, identityId, command)

Source from the content-addressed store, hash-verified

6const controlPlane = require("../lib/controlPlane/ControlPlaneServer");
7
8const execCommand = async (accountId, entryId, identityId, command) => {
9 const entry = await Entry.findByPk(entryId);
10 if (!entry) {
11 return { code: 404, message: "Entry not found" };
12 }
13
14 const accessResult = await validateEntryAccess(accountId, entry);
15 if (!accessResult.valid) {
16 return { code: 403, message: "Access denied" };
17 }
18
19 if (entry.config?.protocol !== "ssh") {
20 return { code: 400, message: "Command execution is only supported for SSH entries" };
21 }
22
23 if (!controlPlane.hasEngine()) {
24 return { code: 503, message: "No engine connected" };
25 }
26
27 const result = await resolveIdentity(entry, identityId, null, accountId);
28 const identity = result?.identity !== undefined ? result.identity : result;
29
30 if (result.accessDenied) {
31 return { code: 403, message: "You don't have access to this identity" };
32 }
33
34 if (!identity || !identity.id) {
35 return { code: 400, message: "No identity available for this entry" };
36 }
37
38 const credentials = await getIdentityCredentials(identity.id);
39 const params = buildSSHParams(identity, credentials);
40 const host = entry.config?.ip;
41 const port = entry.config?.port || 22;
42
43 if (!host) {
44 return { code: 400, message: "Missing host configuration" };
45 }
46
47 const jumpHosts = await resolveJumpHosts(entry);
48 const execResult = await controlPlane.execCommand(host, port, params, command, jumpHosts);
49
50 return {
51 success: execResult.success,
52 stdout: execResult.stdout || "",
53 stderr: execResult.stderr || "",
54 exitCode: execResult.exitCode ?? (execResult.success ? 0 : 1),
55 errorMessage: execResult.errorMessage || null,
56 };
57};
58
59module.exports = { execCommand };

Callers 1

serverSession.jsFile · 0.85

Calls 6

validateEntryAccessFunction · 0.85
resolveIdentityFunction · 0.85
buildSSHParamsFunction · 0.85
resolveJumpHostsFunction · 0.85
hasEngineMethod · 0.80
execCommandMethod · 0.80

Tested by

no test coverage detected