-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrequest.go
More file actions
90 lines (69 loc) · 1.88 KB
/
request.go
File metadata and controls
90 lines (69 loc) · 1.88 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"regexp"
"strings"
)
type request struct {
inputEmail string
inputHost string
inputUser string
validPreliminary bool
validUser bool
validHost bool
validBlacklist bool
invalidReason string
}
func (r *request) buildFromEmail(email string) {
r.inputEmail = email
atPos := strings.Index(r.inputEmail, "@")
if atPos == -1 {
r.invalidReason = "Missing @"
r.validPreliminary = false
return
}
r.inputUser = r.inputEmail[0:atPos]
r.inputHost = r.inputEmail[atPos+1:]
if r.inputUser == "" {
r.invalidReason = "Missing user"
r.validPreliminary = false
return
}
if r.inputHost == "" {
r.invalidReason = "Missing host"
r.validPreliminary = false
return
}
r.validPreliminary = true
}
func (r *request) validateUser(complete chan bool, validUserRegex *regexp.Regexp) {
r.validUser = validUserRegex.MatchString(r.inputUser)
if r.validUser == false {
r.invalidReason = "User " + r.inputUser + " does not appear valid."
}
complete <- true
}
func (r *request) validateHost(complete chan bool, validHostRegex *regexp.Regexp, validHostIPRegex *regexp.Regexp) {
//@TODO need a better way of making sure we end up on IP address if we think its a messed up ip address
r.validHost = validHostRegex.MatchString(r.inputHost) || validHostIPRegex.MatchString(r.inputHost)
if r.validHost == false {
r.invalidReason = "Host " + r.inputHost + " does not appear valid."
}
complete <- true
}
func (r *request) validateBlackList(complete chan bool, c *Configuration) {
testHost := strings.ToLower(r.inputHost)
hostValue, ok := c.HostList[testHost]
// Domain not found in blacklist
if ok == false {
r.validBlacklist = true
complete <- true
return
}
// Domain exists and is blacklisted
if hostValue == 1 {
r.invalidReason = "Host " + r.inputHost + " found in blacklist."
r.validBlacklist = false
complete <- true
return
}
}