File size: 981 Bytes
a12650e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const io = require("socket.io-client");
const socket = io("https://SSHManager.onenew.repl.co");
const { spawn } = require('child_process');
var ls = spawn("echo", ["Hello World"]);
ls.kill()

socket.on("message", (data) => {
  console.log(data)
  if (data == "Ready") {
    console.log("send code")
    socket.emit("type", "node")
  }
})

socket.on("client-connection", data => {
  console.log("client " + data + " connected")
})

socket.on("TERMINATE", () => {
  console.log("TERMINATING...")
  ls.kill()
})

socket.on("command", (data) => {
  console.log(data)
  command = data.command;
  args = data.args;
  ls = spawn(command, args);

  ls.stdout.on('data', (data) => {
    console.log(`${data}`);
    data = `${data}`
    socket.emit("data", data)
  });

  ls.stderr.on('data', (data) => {
    console.error(`${data}`);
    socket.emit("data", data)
  });

  ls.on('close', (code) => {
    console.log(`child process exited with code ${code}`);
    socket.emit("end")
  });
})