-
Notifications
You must be signed in to change notification settings - Fork 0
/
spam.go
51 lines (47 loc) · 1.11 KB
/
spam.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
package main
import (
"github.com/adtac/go-akismet/akismet"
"github.com/mrichman/godnsbl"
"log"
"os"
)
func CheckBlockList(ip string) bool {
lookup := Lookup{Ip: ip}
blocklists := []string{
"sbl.spamhaus.org",
"xbl.spamhaus.org",
"spam.spamrats.com",
"all.s5h.net",
}
for _, source := range blocklists {
result := godnsbl.Lookup(source, lookup.Ip)
if len(result.Results) > 0 {
lookup.Blocked = result.Results[0].Listed
if lookup.Blocked {
return true
}
}
}
return false
}
func CheckAkismet(msg *Message) bool {
akismetKey, isSet := os.LookupEnv("AKISMET_KEY")
if isSet == false {
log.Printf("[INFO] [%s] AKISMET_KEY is not set", ServiceName)
return false
}
isSpam, err := akismet.Check(&akismet.Comment{
Blog: msg.Website,
UserIP: msg.SenderIp,
UserAgent: msg.UserAgent,
CommentType: "contact-form",
CommentAuthor: msg.FromName,
CommentAuthorEmail: msg.From,
CommentContent: msg.Text,
}, akismetKey)
if err != nil {
log.Printf("[ERROR] [%s] Akismet error: %s", ServiceName, err.Error())
return false
}
return isSpam
}