summaryrefslogtreecommitdiff
path: root/domain.go
diff options
context:
space:
mode:
authorHorus32015-06-02 05:38:12 +0200
committerHorus32015-06-02 05:38:12 +0200
commitf8a4da578bc8f58924ef060b60c472ade8390d55 (patch)
treed9b1b35966149ad69f0d638a7c158ea3aff1883e /domain.go
parent0a00051d30184c94a666638f66f1d145df855995 (diff)
downloadfreemail-f8a4da578bc8f58924ef060b60c472ade8390d55.tar.gz
Bug fix and better wording.
Diffstat (limited to 'domain.go')
-rw-r--r--domain.go28
1 files changed, 22 insertions, 6 deletions
diff --git a/domain.go b/domain.go
index 252cab4..e18b379 100644
--- a/domain.go
+++ b/domain.go
@@ -32,6 +32,7 @@ func (vD VirtualDomain) CreateDomain() bool {
return true
}
+// TODO: Needs better handling with multiple IPs.
func (vD VirtualDomain) ValidateDomain(ref string) bool {
log.Println("Info: Validating " + vD.Name)
if vD.Name == "" {
@@ -52,36 +53,51 @@ func (vD VirtualDomain) ValidateDomain(ref string) bool {
}
return reflect.DeepEqual(serverIP, addr)
}
+
func (vD VirtualDomain) ValidateDomainMX(ref string) bool {
log.Println("Info: Validating MX " + vD.Name)
+ var isValid bool = false // Has the domain an MX entry pointing to this server?
+
if vD.Name == "" {
log.Println("Info: Empty domain.")
return false
}
+
+ // All the MX entries for the desired domain.
mx, err := net.LookupMX(vD.Name)
if err != nil {
log.Println("Info: Lookup error " + vD.Name + " " + err.Error())
return false
}
- match := false
- serverIP, err := net.LookupIP(ref)
+ // Our IPs.
+ serverIPs, err := net.LookupIP(ref)
if err != nil {
log.Println("Info: Lookup error for server " + ref + " " + err.Error())
return false
}
+
+ // We loop over MX entries, each one has a host field.
for _, v := range mx {
- mxIP, err := net.LookupIP(v.Host)
+ // Each host field may have multiple IPs.
+ mxIPs, err := net.LookupIP(v.Host)
if err != nil {
log.Println("Info: ", err)
}
- if reflect.DeepEqual(serverIP, mxIP) {
- match = true
+ // Our server has probably more than one IP as well...
+ for _, serverIP := range serverIPs {
+ // ... thus we need to compare all of them.
+ for _, mxIP := range mxIPs {
+ if string(serverIP) == string(mxIP) {
+ isValid = true
+ }
+ }
}
}
- return match
+ return isValid
}
+// Returns the last fragment from a string splitted by '@'.
func GetDomain(email string) string {
fragments := strings.Split(email, "@")
return fragments[len(fragments)-1]