Update server.js
Browse files
server.js
CHANGED
@@ -16,9 +16,12 @@ wss.on('connection', (ws) => {
|
|
16 |
console.log(`Received message: ${message}`);
|
17 |
|
18 |
// Convert message (Buffer) to string
|
19 |
-
|
20 |
|
21 |
-
//
|
|
|
|
|
|
|
22 |
exec(command, (error, stdout, stderr) => {
|
23 |
if (error) {
|
24 |
ws.send(`Error: ${error.message}`);
|
|
|
16 |
console.log(`Received message: ${message}`);
|
17 |
|
18 |
// Convert message (Buffer) to string
|
19 |
+
let command = message.toString();
|
20 |
|
21 |
+
// Prefix command with 'sudo'
|
22 |
+
command = `sudo ${command}`;
|
23 |
+
|
24 |
+
// Execute the command with superuser privileges
|
25 |
exec(command, (error, stdout, stderr) => {
|
26 |
if (error) {
|
27 |
ws.send(`Error: ${error.message}`);
|