This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck-surbl.go
89 lines (76 loc) · 1.67 KB
/
check-surbl.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Check for an IP that is in the surbl.org blacklist.
//
package main
import (
"mvdan.cc/xurls"
"net"
"net/url"
"strings"
)
//
// Register ourself as a blogspam-plugin.
//
func init() {
registerPlugin(BlogspamPlugin{Name: "60-surbl.js",
Description: "Test links in messages against surbl.org",
Author: "Steve Kemp <[email protected]>",
Test: checkSurblBlacklist,
RedisCache: true})
}
//
// Lookup the hyperlinks in the Surbl.org blacklist.
//
func checkSurblBlacklist(x Submission) (PluginResult, string) {
//
// We'll store lookups to perform here.
//
lookups := make(map[string]int)
//
// Find the links in the body of our comment.
//
urlsRe := xurls.Relaxed()
links := urlsRe.FindAllString(x.Comment, -1)
//
// If we got any we must process them.
//
// This means removing any `https?://` prefix
// and any URL part.
//
for _, link := range links {
//
// If we don't have a protocol-prefix, add it.
//
if !strings.HasPrefix(link, "http://") &&
!strings.HasPrefix(link, "https://") {
link = "http://" + link
}
//
// Now parse out the hostname of the link.
//
u, err := url.Parse(link)
if err == nil {
hostname := u.Hostname()
//
// The thing we lookup - stored in our map
// to ensure we don't have duplicates
//
lookups[hostname+".multi.surbl.org"] = 1
}
}
//
// Now we have a list of things to lookup.
//
// Let us do that, if any result in a result we know we've got spam.
//
for host := range lookups {
reply, _ := net.LookupHost(host)
if len(reply) != 0 {
return Spam, "Posted link(s) listed in surbl.org"
}
}
//
// We got no listing, so we're OK.
//
return Undecided, ""
}