MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / StartWebShell

Function StartWebShell

daemon/utils/webshell.go:27–57  ·  view source on GitHub ↗
(addr string, port int, writeable bool, cmd string, args []string, timeoutMin int, callback func())

Source from the content-addressed store, hash-verified

25}
26
27func StartWebShell(addr string, port int, writeable bool, cmd string, args []string, timeoutMin int, callback func()) (WebShellInfo, error) {
28 finalCmd := []string{
29 "./gotty",
30 "-a", addr,
31 "-p", strconv.Itoa(port),
32 "--timeout", strconv.Itoa(60 * timeoutMin),
33 "--title-format", "WebShell",
34 }
35 if writeable {
36 finalCmd = append(finalCmd, "-w")
37 }
38 finalCmd = append(finalCmd, cmd)
39 finalCmd = append(finalCmd, args...)
40 execCmd := exec.Command(finalCmd[0], finalCmd[1:]...)
41 err := execCmd.Start()
42 if err != nil {
43 return WebShellInfo{}, fmt.Errorf("start webShell error: %s", err.Error())
44 }
45 go func() {
46 execCmd.Wait()
47 if err != nil {
48 logrus.Errorf("WebShell Running Error: %s", err.Error())
49 }
50 callback()
51 }()
52 return WebShellInfo{
53 Addr: addr,
54 Port: port,
55 Pid: execCmd.Process.Pid,
56 }, nil
57}
58
59func KillWebShell(pid int) error {
60 execCmd := exec.Command("kill", "-9", strconv.Itoa(pid))

Callers

nothing calls this directly

Calls 1

WaitMethod · 0.65

Tested by

no test coverage detected