|
|
Riga 15: |
Riga 15: |
| con contenuto: | | con contenuto: |
| <pre> | | <pre> |
| #!/usr/bin/php | | #!/bin/sh |
| <?php
| | # Logging sendmail wrapper |
|
| |
|
| /** | | SENDMAIL="/usr/sbin/sendmail" |
| Script per tracciare in un log tutti gli script che fanno uso
| | LOGFILE="/var/log/mail_php.log" |
| della funzione PHP mail().
| |
| Author: Till Brehm, www.ispconfig.org
| |
| (Hopefully) secured by David Goodwin <david @ _palepurple_.co.uk>
| |
| Test e implementazione: Ferdinando Bassi per Debianizzati.org
| |
| */
| |
|
| |
|
| $sendmail_bin = '/usr/sbin/sendmail';
| | DT=`date "+%Y-%m-%d %H:%M:%S"` |
| $logfile = '/var/log/mail_php.log';
| | DTFN=`date "+%Y%m%d-%H%M%S"` |
| | TMPFP=`tempfile --prefix=lsm_` |
|
| |
|
| //* Get the email content
| | cat | tee "$TMPFP" | $SENDMAIL $* |
| $logline = '';
| | RETVAL=$? |
| $pointer = fopen('php://stdin', 'r'); | |
|
| |
|
| while ($line = fgets($pointer)) {
| | TO=`grep "To:" <"$TMPFP"` |
| if(preg_match('/^to:/i', $line) || preg_match('/^from:/i', $line)) {
| | rm -f "$TMPFP" |
| $logline .= trim($line).' ';
| |
| }
| |
| $mail .= $line;
| |
| }
| |
|
| |
|
| //* compose the sendmail command
| | echo "$DT: $PWD sends e-mail $TO" >>$LOGFILE |
| $command = 'echo ' . escapeshellarg($mail) . ' | '.$sendmail_bin.' -t -i';
| |
| for ($i = 1; $i < $_SERVER['argc']; $i++) {
| |
| $command .= escapeshellarg($_SERVER['argv'][$i]).' ';
| |
| }
| |
|
| |
|
| | | exit $RETVAL |
| //* 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);
| |
| ?>
| |
| </pre> | | </pre> |
| Rendiamo eseguibile lo script appena creato: | | Rendiamo eseguibile lo script appena creato: |