Update server.js
Browse files
server.js
CHANGED
@@ -18,17 +18,23 @@ wss.on('connection', (ws) => {
|
|
18 |
// Convert message (Buffer) to string
|
19 |
const command = message.toString();
|
20 |
|
21 |
-
// Execute the command
|
22 |
exec(command, (error, stdout, stderr) => {
|
23 |
if (error) {
|
24 |
ws.send(`Error: ${error.message}`);
|
25 |
-
return;
|
26 |
}
|
27 |
if (stderr) {
|
28 |
ws.send(`stderr: ${stderr}`);
|
29 |
-
return;
|
30 |
}
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
});
|
33 |
});
|
34 |
|
|
|
18 |
// Convert message (Buffer) to string
|
19 |
const command = message.toString();
|
20 |
|
21 |
+
// Execute the command with superuser privileges
|
22 |
exec(command, (error, stdout, stderr) => {
|
23 |
if (error) {
|
24 |
ws.send(`Error: ${error.message}`);
|
|
|
25 |
}
|
26 |
if (stderr) {
|
27 |
ws.send(`stderr: ${stderr}`);
|
|
|
28 |
}
|
29 |
+
if (stdout) {
|
30 |
+
ws.send(`stdout: ${stdout}`);
|
31 |
+
}
|
32 |
+
}).stdout.on('data', (data) => {
|
33 |
+
// Send the stdout data to the WebSocket client
|
34 |
+
ws.send(`stdout: ${data}`);
|
35 |
+
}).stderr.on('data', (data) => {
|
36 |
+
// Send the stderr data to the WebSocket client
|
37 |
+
ws.send(`stderr: ${data}`);
|
38 |
});
|
39 |
});
|
40 |
|