-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildersettings.go
62 lines (52 loc) · 1.56 KB
/
buildersettings.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 blacklist
import (
"strconv"
"strings"
"inet.af/netaddr"
)
type BuilderSettings struct {
BlockMalicious bool
BlockAds bool
BlockSurveillance bool
AllowedHosts []string
AddBlockedHosts []string
AddBlockedIPs []netaddr.IP
AddBlockedIPPrefixes []netaddr.IPPrefix
}
func (s *BuilderSettings) String() string {
const (
subSection = " |--"
indent = " " // used if lines already contain the subSection
)
return strings.Join(s.Lines(indent, subSection), "\n")
}
func (s *BuilderSettings) Lines(indent, subSection string) (lines []string) {
var blockedCategories []string
if s.BlockMalicious {
blockedCategories = append(blockedCategories, "malicious")
}
if s.BlockSurveillance {
blockedCategories = append(blockedCategories, "surveillance")
}
if s.BlockAds {
blockedCategories = append(blockedCategories, "ads")
}
lines = append(lines, subSection+"Blocked categories: "+strings.Join(blockedCategories, ", "))
if len(s.AllowedHosts) > 0 {
lines = append(lines, subSection+"Hostnames unblocked: "+
strconv.Itoa(len(s.AllowedHosts)))
}
if len(s.AddBlockedHosts) > 0 {
lines = append(lines, subSection+"Additional hostnames blocked: "+
strconv.Itoa(len(s.AddBlockedHosts)))
}
if len(s.AddBlockedIPs) > 0 {
lines = append(lines, subSection+"Additional IP addresses blocked: "+
strconv.Itoa(len(s.AddBlockedIPs)))
}
if len(s.AddBlockedIPPrefixes) > 0 {
lines = append(lines, subSection+"Additional IP networks blocked: "+
strconv.Itoa(len(s.AddBlockedIPPrefixes)))
}
return lines
}