-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
62 lines (56 loc) · 1.33 KB
/
utils.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
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
)
func getWGServer() error {
configFile, _ := os.Open(FILES[1])
wg0 = make(map[string]string)
scanner := bufio.NewScanner(configFile)
var isGlobalConfig = false
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "[") {
if strings.Contains(line, "[Interface]") {
isGlobalConfig = true
} else {
isGlobalConfig = false
}
}
if strings.Contains(line, "=") && isGlobalConfig {
value := strings.Split(line, "=")
wg0[strings.TrimSpace(value[0])] = strings.TrimSpace(value[1])
}
}
wg0["ServerPublicKey"] = getServerPublicKey()
defer func(configFile *os.File) {
err := configFile.Close()
if err != nil {
fmt.Printf("There was an error closing the %s file\n", FILES[0])
}
}(configFile)
return nil
}
func getServerPublicKey() string {
c := exec.Command("cat", FILES[3])
outputC, err := c.Output()
if err != nil {
fmt.Println("Error reading the server public key")
os.Exit(-1)
}
return string(outputC[:len(outputC)-1])
}
func configEndPoint(endpoint string) {
if endpoint != "" {
var command = "echo '" + endpoint + "' > " + DIRS[2] + "/endpoint.conf"
cmd := exec.Command("bash", "-c", command)
_, errO := cmd.Output()
if errO != nil {
fmt.Printf("Error setting endpoint \n %v \n", errO)
os.Exit(-1)
}
}
}