-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_window.go
More file actions
67 lines (57 loc) · 1.66 KB
/
main_window.go
File metadata and controls
67 lines (57 loc) · 1.66 KB
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
//go:build windows
package main
import (
"fmt"
"log"
"os"
"github.com/akamensky/argparse"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/debug"
)
var activeInterfaces []listeningInterface
var err error
func main() {
// config file argument parsing
parser := argparse.NewParser("Local Packet Capture", "Listen to any interface and log traffic to a file or send it to an API endpoint.")
configFilePath := parser.String("c", "config", &argparse.Options{Required: true, Help: "YAML configuration file"})
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
}
// load yaml configuration
err = LoadConfig(*configFilePath)
if err != nil {
log.Fatalln(fmt.Errorf("error loading configuration: %v", err))
}
// initialize logger
var APP_LOGLEVEL int
switch AppConfig.ApplicationLogLevel {
case "LOGLEVEL_DEBUG":
APP_LOGLEVEL = LOGLEVEL_DEBUG
case "LOGLEVEL_WARNING":
APP_LOGLEVEL = LOGLEVEL_WARNING
case "LOGLEVEL_ERROR":
APP_LOGLEVEL = LOGLEVEL_ERROR
default:
APP_LOGLEVEL = LOGLEVEL_INFO
}
InitLogger(APP_LOGLEVEL)
if AppConfig.ApplicationLogFile != "" {
SetLogToFile(AppConfig.ApplicationLogFile)
}
// start in interactive mode or as a Windows service
isWindowsService, err := svc.IsWindowsService()
if err != nil {
log.Fatalln(fmt.Errorf("error checking if running in an interactive session or as a service: %v", err))
}
if isWindowsService {
runService("nMonitorService", false)
} else {
logMessage(LOGLEVEL_INFO, "Running in interactive mode.")
err = debug.Run("nMonitorService", &nMonitorService{})
if err != nil {
log.Fatalf("Error running service in interactive mode: %v", err)
}
return
}
}