This commit is contained in:
Raven Scott 2024-12-01 22:16:05 -05:00
parent c38f23d50e
commit b370169aaf

View File

@ -110,10 +110,10 @@ swarm.on('connection', (peer) => {
case 'dockerCommand': case 'dockerCommand':
console.log(`[INFO] Executing Docker CLI command: ${parsedData.data}`); console.log(`[INFO] Executing Docker CLI command: ${parsedData.data}`);
try { try {
const exec = spawn('sh', ['-c', parsedData.data]); // Use `spawn` to execute the command const exec = spawn('sh', ['-c', parsedData.data]); // Use `spawn` to execute the Docker command
exec.stdout.on('data', (output) => { exec.stdout.on('data', (output) => {
console.log(`[DEBUG] Command output: ${output.toString()}`); console.log(`[DEBUG] Command output: ${output.toString()}`); // Log the command output
peer.write( peer.write(
JSON.stringify({ JSON.stringify({
type: 'dockerOutput', type: 'dockerOutput',
@ -124,7 +124,7 @@ swarm.on('connection', (peer) => {
}); });
exec.stderr.on('data', (error) => { exec.stderr.on('data', (error) => {
console.error(`[ERROR] Command error output: ${error.toString()}`); console.error(`[ERROR] Command error output: ${error.toString()}`); // Log any errors
peer.write( peer.write(
JSON.stringify({ JSON.stringify({
type: 'dockerOutput', type: 'dockerOutput',
@ -148,7 +148,9 @@ swarm.on('connection', (peer) => {
console.error(`[ERROR] Failed to execute command: ${error.message}`); console.error(`[ERROR] Failed to execute command: ${error.message}`);
peer.write( peer.write(
JSON.stringify({ JSON.stringify({
error: `Failed to execute command: ${error.message}` type: 'dockerOutput',
connectionId: parsedData.connectionId,
data: `[ERROR] Failed to execute command: ${error.message}`,
}) })
); );
} }