-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (42 loc) · 1.06 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
package main
import (
"flag"
"fmt"
"github.com/getlantern/systray"
"github.com/jurjevic/SplitVPN/icon"
"github.com/jurjevic/SplitVPN/split"
"github.com/jurjevic/SplitVPN/ui"
"log"
"os"
"os/exec"
"strconv"
"strings"
)
func main() {
log.SetPrefix("splitvpn ")
split.Version = Version
if getProcessOwner() != "root" {
log.Println("Starting ", flag.Arg(0), "Version:", Version, "failed")
log.Println("Routing changes can only be executed with 'root' privileges.")
log.Fatal("Fatal error: 'root' privileges required! Please start with 'sudo'")
}
systray.Run(onReady, onExit)
}
func onReady() {
systray.SetIcon(icon.Data_0_0)
systray.SetTooltip("Automatic VPN and Internet Split")
menu := ui.Setup()
splitInstance := split.NewSplit()
splitInstance.Start(menu.Refresh, menu.StateChanged)
}
func onExit() {
// clean up here
}
func getProcessOwner() string {
stdout, err := exec.Command("ps", "-o", "user=", "-p", strconv.Itoa(os.Getpid())).Output()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return strings.ReplaceAll(string(stdout), "\n", "")
}