121 lines
4.0 KiB
PHP
121 lines
4.0 KiB
PHP
<?php
|
|
class ContactController extends ContactControllerCore
|
|
{
|
|
public function postProcess()
|
|
{
|
|
session_start();
|
|
$_SESSION["bannedctc"] = "notbanned";
|
|
$_SESSION["ipo"] = "";
|
|
$filename = _PS_ROOT_DIR_ . '/banned.txt';
|
|
|
|
if (Tools::isSubmit('submitMessage')) {
|
|
|
|
//$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();
|
|
$target = Context::getContext()->link->getPageLink('contact');
|
|
try {
|
|
$file = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $filename);
|
|
$file = new SplFileObject($file);
|
|
} catch (LogicException $exception) {
|
|
die('SplFileObject : ' . $exception->getMessage());
|
|
}
|
|
while ($file->valid()) {
|
|
$line = $file->fgets();
|
|
array_push($banned_in_email, trim($line));
|
|
}
|
|
$file = null;
|
|
|
|
foreach ($banned_in_email as $string) {
|
|
if (strstr($from, $string)) {
|
|
$_SESSION["bannedctc"] = "banned";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* 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;
|
|
}
|
|
}
|