summaryrefslogtreecommitdiff
path: root/domain.go
diff options
context:
space:
mode:
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]