-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
96 lines (80 loc) · 1.77 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"flag"
"net"
"os"
"os/signal"
"syscall"
"github.com/evilsocket/opensnitch/daemon/log"
"github.com/evilsocket/opensnitch/daemon/ui/protocol"
"google.golang.org/grpc"
)
const (
uiSocket = "/tmp/osui.sock"
)
var (
sigChan chan os.Signal
statChan chan *protocol.Statistics
server *grpc.Server
)
// flag variables
var (
configFile string
debug = false
)
func main() {
flag.StringVar(&configFile, "config", "~/.opensnitch/ui-config.json", "UI configuration file")
flag.BoolVar(&debug, "debug", debug, "Enable debug logs.")
flag.Parse()
if debug {
log.MinLevel = log.DEBUG
} else {
log.MinLevel = log.INFO
}
sigChan = make(chan os.Signal, 1)
signal.Notify(sigChan,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
cfg, err := loadConfigFromFile(configFile)
if err != nil {
log.Error("Error loading configuration file %s. %v", configFile, err)
}
statChan = make(chan *protocol.Statistics)
osApp := newApp(sigChan, cfg)
go func() {
//Starts the gRPC server
lis, err := net.Listen("unix", uiSocket)
if err != nil {
log.Error("OpenSnitch gRPC server failed to listen on socket unix://%s: %v", uiSocket, err)
}
server = grpc.NewServer()
protocol.RegisterUIServer(
server,
&osServer{
osApp: osApp,
},
)
log.Info("OpenSnitch gRPC server listening on socket: unix://%s", uiSocket)
if err := server.Serve(lis); err != nil {
log.Fatal("failed to serve: %v", err)
}
}()
go func() {
for {
select {
case st := <-statChan:
osApp.RefreshStats(st)
case sig := <-sigChan:
log.Raw("\n")
log.Important("Got signal: %v", sig)
log.Info("Shutting down grpc server...")
server.Stop()
log.Info("All done, bye")
os.Exit(0)
}
}
}()
osApp.ShowAndRun()
}