-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
executable file
·54 lines (41 loc) · 1.23 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
package main
import (
"flag"
"fmt"
"log"
"time"
)
const (
TUNNEL_RADAR_EOF = "TUNNEL_RADAR_EOF\n"
)
func main() {
time.Sleep(time.Second * 2)
// Configurations by flag
withCli := flag.Bool("i", false, "Enter in CLI mode to execute commands on TunnelRadar")
cliHost := flag.String("ih", "127.0.0.1", "CLI host to connect to (default 127.0.0.1)")
cliPort := flag.Int("ip", 7779, "CLI Port to connect to (default 7779)")
configPath := flag.String("c", "/etc/tunnel-radar/config.yml", "Configuration file path")
debug := flag.Bool("d", false, "Enable debugging")
flag.Parse()
if *withCli == true {
cliClient, err := NewCliClient(*cliHost, *cliPort)
if err != nil {
log.Fatalf("An error occurred connecting to the CLI server. Error: %s\r\n", err)
}
// Bind the terminal and listen for commands
defer cliClient.Conn.Close()
cliClient.listen()
} else {
// Load configuration
loadConfig(*configPath)
if *debug == true {
fmt.Println("Debug mode ON")
fmt.Printf("Configuration loaded %s\r\n", *configPath)
}
for _, tunnel := range tunnelRadarConfig.Tunnels {
go tunnel.Spawn()
}
// Start listening for commands
StartCliServer(tunnelRadarConfig.CliServerHost, tunnelRadarConfig.CliServerPort)
}
}