Files

121 lines
4.0 KiB
PHP
Raw Permalink Normal View History

2024-02-23 09:48:44 +01:00
<?php
class ContactController extends ContactControllerCore
{
public function postProcess()
{
session_start();
2024-03-08 12:37:03 +01:00
$_SESSION["bannedctc"] = "notbanned";
$_SESSION["ipo"] = "";
$filename = _PS_ROOT_DIR_ . '/banned.txt';
2024-02-23 09:48:44 +01:00
if (Tools::isSubmit('submitMessage')) {
2024-03-08 12:37:03 +01:00
//$message = Tools::getValue('message');
2024-02-23 09:48:44 +01:00
$from = Tools::getValue('from');
2024-03-08 12:37:03 +01:00
$ip_address = Tools::getRemoteAddr();
2024-02-23 09:48:44 +01:00
2024-03-08 12:37:03 +01:00
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";
}
}
}
2024-02-23 09:48:44 +01:00
2024-03-08 12:37:03 +01:00
if (file_exists($filename)) {
2024-02-23 09:48:44 +01:00
$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";
}
}
2024-03-08 12:37:03 +01:00
}
}
2024-02-23 09:48:44 +01:00
2024-03-08 12:37:03 +01:00
/* 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>';
2024-02-23 09:48:44 +01:00
}
}
}
2024-03-08 12:37:03 +01:00
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;
2024-02-23 09:48:44 +01:00
}
}