forked from n00bady/bluam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
66 lines (56 loc) · 1.29 KB
/
helpers.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
package main
import (
"os"
"os/exec"
"strings"
)
// takes a string and checks for a number of prefixes and suffixes then removes them
// and returns the string with trimed spaces
func toPlainDomain(s string) string {
// Check prefixes 1st then another pass for suffixes
switch {
case strings.HasPrefix(s, ":"):
return ""
case strings.HasPrefix(s, "["):
return ""
case strings.HasPrefix(s, "#"):
return ""
case strings.HasPrefix(s, "!"):
return ""
case strings.HasPrefix(s, "*"):
s = strings.TrimSpace(s[1:])
case strings.HasPrefix(s, "||"):
s = strings.TrimSpace(s[2:])
case strings.HasPrefix(s, "0.0.0.0"):
s = strings.TrimSpace(s[len("0.0.0.0"):])
case strings.HasPrefix(s, "127.0.0.1"):
s = strings.TrimSpace(s[len("127.0.0.1"):])
default:
return strings.TrimSpace(s)
}
if strings.HasSuffix(s, "^") {
s = strings.TrimSpace(s[0 : len(s)-1])
}
return s
}
func runCmd(name string, args ...string) error {
cmd := exec.Command(name, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
return nil
}
func blocklistsChanged() (bool, error) {
cmd := exec.Command("git", "diff", "dns")
out, err := cmd.CombinedOutput()
if err != nil {
return false, err
}
if len(out) > 0 {
return true, nil
}
return false, nil
}