Add net/contactspam API for contact form spam filtering
parent
6e95e50830
commit
b22658f329
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
// Minimum message length checks
|
||||
const MSG_MIN_CHARS = 20;
|
||||
const MSG_MIN_WORDS = 5;
|
||||
// Banned words check, file should be one match (word or phrase) per line
|
||||
const BANNED_WORDLIST = __DIR__ . "/net.contactspam/bannedwords.txt";
|
||||
// Banned email domain check, one domain per line, useful if you get lots of spam from
|
||||
// a domain your customers probably won't legitimately use
|
||||
const BANNED_DOMAINS = __DIR__ . "/net.contactspam/banneddomains.txt";
|
||||
const BANNED_IP_LIST = __DIR__ . "/net.contactspam/bannedips.txt";
|
||||
const BANNED_IP_CIDR = __DIR__ . "/net.contactspam/toxic_ip_cidr.txt";
|
||||
|
||||
$message = $VARS["message"] ?? "";
|
||||
$fromemail = $VARS["email"] ?? "";
|
||||
$clientip = $VARS["ipaddr"] ?? "";
|
||||
$contactformdomain = trim(strtolower($VARS["domain"] ?? ""));
|
||||
|
||||
$msg_lower = trim(strtolower($message));
|
||||
$email_lower = trim(strtolower($fromemail));
|
||||
$email_parts = explode("@", $email_lower);
|
||||
$email_domain = $email_parts[count($email_parts) - 1];
|
||||
|
||||
//
|
||||
// If message too short (chars and/or words)
|
||||
//
|
||||
if (isset($VARS["message"])) {
|
||||
if (strlen($msg_lower) < MSG_MIN_CHARS) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "length_chars", "hit" => "", "message" => "Message too short."]);
|
||||
} else if (str_word_count($msg_lower) < MSG_MIN_WORDS) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "length_words", "hit" => "", "message" => "Message too short."]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Check email domain
|
||||
//
|
||||
$banneddomainlist = file(BANNED_DOMAINS, FILE_IGNORE_NEW_LINES);
|
||||
foreach ($banneddomainlist as $domain) {
|
||||
if ($email_domain == $domain) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "domain", "hit" => $domain, "message" => "Emails from \"" . htmlspecialchars($domain) . "\" are not allowed because of spam/abuse." . ($domain == "googlemail.com" ? " (Hint: use gmail.com instead)" : "")]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check if email address is sketchy
|
||||
//
|
||||
if (!empty($email_parts) && count($email_parts) == 2) {
|
||||
if ($email_parts[0] == $email_parts[1]) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "email_fake", "hit" => "", "message" => "Unacceptable email address."]);
|
||||
}
|
||||
}
|
||||
if (!empty($contactformdomain)) {
|
||||
if ($contactformdomain == $email_domain && $email_parts[0] != "test") {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "email_self", "hit" => "", "message" => "Please use your own email address, not ours."]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Check for blocked spammy words
|
||||
//
|
||||
$bannedwordlist = file(BANNED_WORDLIST, FILE_IGNORE_NEW_LINES);
|
||||
foreach ($bannedwordlist as $word) {
|
||||
if (strpos($msg_lower, $word) !== false) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "word", "hit" => $word, "message" => "\"" . htmlspecialchars($word) . "\" is not allowed because of spam/abuse."]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Lookup reported client IP address against stopforumspam.com CIDR range list
|
||||
//
|
||||
/**
|
||||
* https://stackoverflow.com/a/594134
|
||||
*/
|
||||
function cidr_match($ip, $range) {
|
||||
list ($subnet, $bits) = explode('/', $range);
|
||||
if ($bits === null) {
|
||||
$bits = 32;
|
||||
}
|
||||
$ip = ip2long($ip);
|
||||
$subnet = ip2long($subnet);
|
||||
$mask = -1 << (32 - $bits);
|
||||
$subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned
|
||||
return ($ip & $mask) == $subnet;
|
||||
}
|
||||
|
||||
if (filter_var($clientip, FILTER_VALIDATE_IP, [FILTER_FLAG_IPV4])) {
|
||||
$bannedipcidrlist = file(BANNED_IP_CIDR, FILE_IGNORE_NEW_LINES);
|
||||
foreach ($bannedipcidrlist as $cidr) {
|
||||
if (cidr_match($clientip, $cidr)) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "toxic_ip_cidr", "hit" => $clientip, "message" => "Your computer's IP address is on a spam blacklist."]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Lookup reported client IP address against stopforumspam.com full IP list
|
||||
//
|
||||
if (filter_var($clientip, FILTER_VALIDATE_IP, [FILTER_FLAG_IPV4])) {
|
||||
$bannediplist = file(BANNED_IP_LIST, FILE_IGNORE_NEW_LINES);
|
||||
foreach ($bannediplist as $ip) {
|
||||
if ($clientip == $ip) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "banned_ip", "hit" => $clientip, "message" => "Your computer's IP address is blacklisted for sending spam."]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Lookup reported client IP address to see if it's in a botnet or something and sending spam
|
||||
//
|
||||
try {
|
||||
if (filter_var($clientip, FILTER_VALIDATE_IP, [FILTER_FLAG_IPV4])) {
|
||||
$blacklist = "xbl.spamhaus.org";
|
||||
$url = implode(".", array_reverse(explode(".", $clientip))) . "." . $blacklist;
|
||||
|
||||
// Cache IPs so we don't do a DNS lookup each time
|
||||
$cacheresp = $memcache->get("net.contactspam.$url");
|
||||
if ($cacheresp !== false) {
|
||||
$dns_result = $cacheresp;
|
||||
} else {
|
||||
$dns_result = `host -t A $url b.gns.spamhaus.org`;
|
||||
$memcache->set("net.contactspam.$url", $dns_result, 60 * 60 * 24);
|
||||
}
|
||||
if (strpos($dns_result, "NXDOMAIN") === false && strpos($dns_result, "127.0.") !== false) {
|
||||
exitWithJson(["status" => "OK", "clean" => false, "filter" => "spamhaus_xbl", "hit" => $clientip, "message" => "Your computer or a device on your network is infected with a virus and is sending spam messages, so our system is blocking your message."]);
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Well if we got here then the message tested negative for spam
|
||||
//
|
||||
exitWithJson(["status" => "OK", "clean" => true, "filter" => null, "hit" => null]);
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,37 @@
|
||||
face mask
|
||||
n95
|
||||
surgical masks
|
||||
influencer
|
||||
seo
|
||||
talk with web visitor
|
||||
talkwithwebvisitor.com
|
||||
bit.ly
|
||||
sponsored content
|
||||
kickshades.online
|
||||
next 24 hours
|
||||
oakley sunglasses
|
||||
mofos
|
||||
sluts
|
||||
fucked
|
||||
<a href
|
||||
</a>
|
||||
yourdomainregistration.ga
|
||||
domain-register.ga
|
||||
termination
|
||||
expire within 24 hours
|
||||
will be terminated
|
||||
renewal of your domain
|
||||
notice#
|
||||
fake id
|
||||
fake ids
|
||||
stardatagroup.com
|
||||
pharmacyusa.online
|
||||
domain services
|
||||
expiration notice
|
||||
affiliate site
|
||||
need extra income?
|
||||
backlink
|
||||
guest post article
|
||||
bestlocaldata.com
|
||||
ray-ban
|
||||
lifemail.studio
|
@ -0,0 +1,43 @@
|
||||
103.81.182.0/24
|
||||
109.200.1.0/24
|
||||
109.200.2.0/23
|
||||
109.200.4.0/22
|
||||
109.200.8.0/21
|
||||
109.200.16.0/20
|
||||
146.185.223.0/24
|
||||
174.76.30.11/32
|
||||
174.76.30.12/30
|
||||
174.76.30.16/28
|
||||
174.76.30.32/27
|
||||
174.76.30.64/30
|
||||
174.76.30.68/31
|
||||
174.76.30.70/32
|
||||
176.227.192.0/19
|
||||
178.159.37.0/24
|
||||
188.143.232.0/23
|
||||
188.143.234.0/24
|
||||
193.201.224.0/24
|
||||
194.26.29.0/24
|
||||
212.129.0.0/18
|
||||
23.106.192.0/20
|
||||
23.106.208.0/21
|
||||
23.106.216.0/22
|
||||
23.106.220.0/23
|
||||
23.106.222.0/24
|
||||
23.106.223.0/25
|
||||
23.106.223.128/26
|
||||
23.106.223.192/27
|
||||
23.106.223.224/28
|
||||
23.106.223.240/29
|
||||
23.106.223.248/30
|
||||
23.106.223.252/31
|
||||
23.106.223.254/32
|
||||
23.106.64.0/19
|
||||
23.19.0.0/16
|
||||
46.118.115.0/24
|
||||
46.161.9.0/24
|
||||
5.188.210.0/23
|
||||
5.9.182.96/28
|
||||
91.200.12.0/22
|
||||
91.210.104.0/22
|
||||
91.236.74.0/23
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
echo "Downloading...\n";
|
||||
file_put_contents(__DIR__ . "/bannedips.zip", file_get_contents("https://www.stopforumspam.com/downloads/bannedips.zip"));
|
||||
file_put_contents(__DIR__ . "/toxic_ip_cidr.txt", file_get_contents("https://www.stopforumspam.com/downloads/toxic_ip_cidr.txt"));
|
||||
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open(__DIR__ . "/bannedips.zip");
|
||||
if ($res === TRUE) {
|
||||
$zip->extractTo(__DIR__ . "/");
|
||||
$zip->close();
|
||||
echo 'Unzipped.';
|
||||
} else {
|
||||
echo 'Unzip failed.';
|
||||
}
|
||||
unlink(__DIR__ . "/bannedips.zip");
|
||||
|
||||
$csv = file_get_contents(__DIR__ . "/bannedips.csv");
|
||||
$ips = explode(",", $csv);
|
||||
file_put_contents("bannedips.txt", implode("\n", $ips));
|
||||
echo "\nConverted.\n";
|
||||
unlink(__DIR__ . "/bannedips.csv");
|
Loading…
Reference in New Issue