-
Notifications
You must be signed in to change notification settings - Fork 143
/
main.go
61 lines (57 loc) · 1.51 KB
/
main.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
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
oneWay := flag.Bool("o", false, "One-way connection with no response needed.")
verbose := flag.Bool("v", false, "Verbose logging")
nonInteractive := flag.Bool("non-interactive", false, "Set host to non-interactive")
ni := flag.Bool("ni", false, "Set host to non-interactive")
_ = flag.Bool("cmd", false, "The command to run. Default is \"bash -l\"\n"+
"Because this flag consumes the remainder of the command line,\n"+
"all other args (if present) must appear before this flag.\n"+
"eg: webtty -o -v -ni -cmd docker run -it --rm alpine:latest sh")
stunServer := flag.String("s", "stun:stun.l.google.com:19302", "The stun server to use")
cmd := []string{"bash", "-l"}
for i, arg := range os.Args {
if arg == "-cmd" {
cmd = os.Args[i+1:]
os.Args = os.Args[:i]
}
}
flag.Parse()
if *verbose {
log.SetFlags(log.LstdFlags | log.Lshortfile)
} else {
log.SetFlags(0)
log.SetOutput(ioutil.Discard)
}
args := flag.Args()
var offerString string
if len(args) > 0 {
offerString = args[len(args)-1]
}
var err error
if len(offerString) == 0 {
hc := hostSession{
oneWay: *oneWay,
cmd: cmd,
nonInteractive: *nonInteractive || *ni,
}
hc.stunServers = []string{*stunServer}
err = hc.run()
} else {
cc := clientSession{
offerString: offerString,
}
cc.stunServers = []string{*stunServer}
err = cc.run()
}
if err != nil {
fmt.Printf("Quitting with an unexpected error: \"%s\"\n", err)
}
}