Add spammaster.org api check

This commit is contained in:
2024-03-08 12:37:03 +01:00
parent 00c63da237
commit 7856305dae
6 changed files with 99 additions and 727 deletions

View File

@@ -4,19 +4,31 @@ class ContactController extends ContactControllerCore
public function postProcess()
{
session_start();
$filename = _PS_ROOT_DIR_ . 'banned.txt';
$_SESSION["bannedctc"] = "notbanned";
$_SESSION["ipo"] = "";
$filename = _PS_ROOT_DIR_ . '/banned.txt';
if (Tools::isSubmit('submitMessage')) {
$message = Tools::getValue('message');
//$message = Tools::getValue('message');
$from = Tools::getValue('from');
$ip_address = Tools::getRemoteAddr();
if (isset($ip_address) && $ip_address != null) {
if (filter_var($ip_address, FILTER_VALIDATE_IP)) {
//$_SESSION["ipo"] = $this->dnsbllookup($ip_address); /*check IP address against DNSBL*/
//if($_SESSION["ipo"] == 'listed'){$_SESSION["bannedctc"] = "banned";}
$_SESSION["ipo"] = $this->emaillookup($ip_address, $from); /*check email adress and IP address against DNSBL*/
$data = json_decode($_SESSION["ipo"], true);
if (isset($data['threat'])) {
$_SESSION["bannedctc"] = "banned";
}
}
}
if (file_exists($filename)) {
$banned_in_email = array();
$banned_content = ['email marketing'];
$target = Context::getContext()->link->getPageLink('contact');
try {
$file = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $filename);
$file = new SplFileObject($file);
@@ -29,27 +41,80 @@ class ContactController extends ContactControllerCore
}
$file = null;
$_SESSION["bannedctc"] = "notbanned";
foreach ($banned_in_email as $string) {
if (strstr($from, $string)) {
//$this->errors[] = Tools::displayError('This email address is not allowed');
$_SESSION["bannedctc"] = "banned";
Tools::redirectAdmin($target);
}
}
foreach ($banned_content as $string) {
if (strstr($message, $string)) {
//$this->errors[] = Tools::displayError('Invalid Content');
$_SESSION["bannedctc"] = "banned";
Tools::redirectAdmin($target);
}
}
}
}
echo $_SESSION["bannedctc"];
/* printf($_SESSION["bannedctc"]);
die(); */
if ($_SESSION["bannedctc"] == "banned") {
$this->errors[] = $this->trans('Invalid email address.', [], 'Shop.Notifications.Error');
}
parent::postProcess();
}
/**
* The IP-address to be looked up.
* @param string $ip
*/
protected function dnsbllookup($ip)
{
// Add your preferred list of DNSBL's
$dnsbl_lookup = [
"dnsbl-1.uceprotect.net",
"dnsbl-2.uceprotect.net",
"dnsbl-3.uceprotect.net",
"dnsbl.dronebl.org",
"dnsbl.sorbs.net",
"zen.spamhaus.org",
"bl.spamcop.net",
"list.dsbl.org"
];
$listed = "";
if ($ip) {
$reverse_ip = implode(".", array_reverse(explode(".", $ip)));
foreach ($dnsbl_lookup as $host) {
if (checkdnsrr($reverse_ip . "." . $host . ".", "A")) {
$listed .= $reverse_ip . '.' . $host . ' <span style="color:red">Listed</span>';
}
}
}
if (empty($listed)) {
return '"A" record was not found';
} else {
return $listed;
}
}
//email check via spammaster.otg - account laurent.desmarets@solido.com
protected function emaillookup($ip, $address)
{
$url = 'https://www.spammaster.org/api/';
$agent = '8e4c82d4b1c7sdrd058763a52b5b0';
$data = array(
'key' => "8e4c82d4b1c7sdrd058763a52b5b0",
'ip' => $ip,
'email' => $address,
);
$data = http_build_query($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
// Returns the result of the scan.
return $result;
}
}