HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   HOWTO-Related Questions (http://www.howtoforge.com/forums/forumdisplay.php?f=2)
-   -   Mail function to detect spam for PHP question (http://www.howtoforge.com/forums/showthread.php?t=48812)

j.smith1981 16th September 2010 12:08

Mail function to detect spam for PHP question
 
I am soo greatful for this tutorial here:

http://www.howtoforge.com/how-to-log...tect-form-spam

But, is there anyway of making the function itself in /usr/local/bin to make the log file run as root and not apache?

This would allow me to put it into the /var/log folder.

Quote:

#!/usr/bin/php
<?php

/**
This script is a sendmail wrapper for php to log calls of the php mail() function.
Author: Till Brehm, www.ispconfig.org
(Hopefully) secured by David Goodwin <david @ _palepurple_.co.uk>
*/

$sendmail_bin = '/usr/sbin/sendmail';
$logfile = '/tmp/mail_php.log';

//* Get the email content
$logline = '';
$pointer = fopen('php://stdin', 'r');

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

//* compose the sendmail command
$command = 'echo ' . escapeshellarg($mail) . ' | '.$sendmail_bin.' -t -i';
for ($i = 1; $i < $_SERVER['argc']; $i++) {
$command .= escapeshellarg($_SERVER['argv'][$i]).' ';
}



//* Write the log
file_put_contents($logfile, date('Y-m-d H:i:s') . ' ' . $_ENV['PWD'] . ' ' . $logline, FILE_APPEND);
//* Execute the command
return shell_exec($command);
?>
:confused:

Thats the shell script for it anyways.

Thanks in advance,
Jeremy

till 16th September 2010 12:30

Quote:

But, is there anyway of making the function itself in /usr/local/bin to make the log file run as root and not apache?
No, as the script runs always under the user that executes the PHP script and runing your apache as root user instead of the apache user is not a good idea for security reasons.


All times are GMT +2. The time now is 18:47.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.