Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > HOWTO-Related Questions

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 16th September 2010, 12:08
j.smith1981 j.smith1981 is offline
Member
 
Join Date: Nov 2008
Posts: 63
Thanks: 0
Thanked 3 Times in 3 Posts
Question 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);
?>


Thats the shell script for it anyways.

Thanks in advance,
Jeremy
Reply With Quote
Sponsored Links
  #2  
Old 16th September 2010, 12:30
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 35,687
Thanks: 819
Thanked 5,318 Times in 4,171 Posts
Default

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.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sneaking suspicion my postfix config has gone awry mjbarfoot Installation/Configuration 7 24th August 2010 12:23
Mail server using Postfix, Dovecot, Mysql... Postfix virtual maps doesn't work?? tarasbuljba HOWTO-Related Questions 33 28th May 2010 14:33
Postfix + postfixadmin = SMTP errors... Rashef Server Operation 4 25th June 2009 16:12
Need help setting up domainpop with postfix kameelperdza Installation/Configuration 6 15th June 2009 07:49
cyrus-sasl won't install on my ubuntu9.04 kameelperdza Installation/Configuration 1 13th June 2009 10:28


All times are GMT +2. The time now is 10:45.


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