Kano001 commited on
Commit
dd8c371
1 Parent(s): 8108cdd

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +10 -4
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 without sudo
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
- ws.send(`stdout: ${stdout}`);
 
 
 
 
 
 
 
 
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