-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchdomain.go
68 lines (66 loc) · 1.78 KB
/
searchdomain.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
67
68
package squidr
import (
"math/rand"
"time"
)
func searchDomain(domain string) search {
for _, item := range blocklist {
if domain == item {
return search{_blockDomain, true, false, false, true}
}
}
for target, searchlist := range rewrite {
for _, item := range searchlist {
if domain == item {
return search{target, false, true, false, true}
}
}
}
for target, searchlist := range redirect302 {
for _, item := range searchlist {
if domain == item {
return search{target, false, false, false, true}
}
}
}
for target, searchlist := range redirect301 {
for _, item := range searchlist {
if domain == item {
return search{target, false, false, true, true}
}
}
}
for target, searchlist := range redirect301randomMap {
for _, item := range searchlist {
if domain == item {
targetMap, ok := randomMap[target]
if !ok {
return search{domain, false, false, false, false} // map does not exist,
}
l := len(targetMap.targets)
if l < 1 {
return search{domain, false, false, false, false} // not map targets
}
rand.Seed(time.Now().UnixNano())
idx := rand.Intn(l - 1)
if targetMap.doNotValidate {
return search{targetMap.targets[idx], false, false, true, true}
}
for i := 0; i < l*3; i++ {
target := targetMap.targets[idx]
if isReachableViaProxy(targetMap, idx) {
return search{target, false, false, true, true} // random picked target is reachable
}
idx = rand.Intn(l - 1) // next
}
for i := 0; i < l; i++ {
if len(targetMap.targets[i]) > 0 {
return search{domain, false, false, false, false} // one valid target
}
}
delete(randomMap, target) // no valid target urls left, remove mapEntry
}
}
}
return search{domain, false, false, false, false}
}