catch spam from apache

Sometimes is very hard to debug from which virtual host spam is
This can be check very easy with this trick

create a new file

 vim /usr/local/bin/phpsendmail

place inside it

#!/usr/bin/php
<?php

$sendmail = ‘/usr/sbin/sendmail’;
$logfile = ‘/var/log/mail.form’;

/* Get email content */
$logline = “;
$mail = “;
$fp = fopen(‘php://stdin’, ‘r’);

while ($line = fgets($fp))
{
if(preg_match(‘/^to:/i’, $line) || preg_match(‘/^from:/i’, $line))
{
$logline .= trim($line).’ ‘;
}
$mail .= $line;
}

/* Build sendmail command */
$cmd = ‘echo ‘ . escapeshellarg($mail) . ‘ | ‘.$sendmail.’ -t -i’;
for ($i = 1; $i < $_SERVER[‘argc’]; $i++)
{
$cmd .= escapeshellarg($_SERVER[‘argv’][$i]).’ ‘;
}

/* Log line */
$path = isset($_ENV[‘PWD’]) ? $_ENV[‘PWD’] : $_SERVER[‘PWD’];
file_put_contents($logfile, date(‘Y-m-d H:i:s’) . ‘ ‘ . $logline .’  ==> ‘ .$path.“\n“, FILE_APPEND);

/* Call sendmail */
return shell_exec($cmd);
?>

Then you need to make it executable

chmod +x /usr/local/bin/phpsendmail

touch /var/log/mail.form

chmod a+w /var/log/mail.form

In your php.ini file you need to add

sendmail_path = /usr/local/bin/phpsendmail

Restart apache

This will cause all emails which are send from apache to be logged in the file /var/log/mail.form

С етикет: , , , ,
Публикувано в linux, php

Вашият коментар

Вашият имейл адрес няма да бъде публикуван. Задължителните полета са отбелязани с *

*