Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/mailout-debugger.php
Go to the documentation of this file.
00001 #!/usr/bin/php
00002 <?php
00003   /*
00004    * Utility to debug mailouts - will save the content of emails to a
00005    * logfile instead of sending them out. Use it as a sendmail
00006    * "stand-in" when testing mailouts.
00007    *
00008    * It is not Moodle specific - use it anywhere by setting the php
00009    * "sendmail_path" setting to this file with a logfile parameter.
00010    *
00011    * - Set in php.ini (not settable in config.php):
00012    *     sendmail_path=/path-to-moodle/admin/mailout-debugger.php');
00013    *   Or from the commandline
00014    *     php -d sendmail_path='/path-to-moodle/admin/mailout-debugger.php' /path/to/cron.php
00015    *
00016    * - Create a file in admin called mailout-debugger.enable
00017    *   (this is a security check to prevent execution in prod environments)
00018    *   touch /path/to/moodle/admin/mailout-debugger.enable
00019    *
00020    * - Mark as executable: chmod ugo+rx mailout-debugger.php
00021    *
00022    * - Run your admin/cron.php
00023    *
00024    * - Read /tmp/moodle-mailout.log
00025    *
00026    *
00027    * This script will create logfiles in /tmp/ or in $TMPDIR if set.
00028    * On windows, use php -r 'print sys_get_temp_dir()' to see where the file is saved.
00029    */
00030 
00031 // Security check.
00032 if (!file_exists(dirname(__FILE__).'/mailout-debugger.enable')) {
00033     mdie("Disabled.");
00034 }
00035 $tmpdir=sys_get_temp_dir(); // default
00036 
00037 if (isset($_SERVER['REMOTE_ADDR'])) {
00038     mdie("should not be called from web server!");
00039 }
00040 
00041 if (isset($_ENV['TMPDIR']) && is_dir($_ENV['TMPDIR'])) {
00042     $tmpdir = $_ENV['TMPDIR'];
00043 }
00044 
00045 $tmpfile = $tmpdir . '/moodle-mailout.log';
00046 $fh = fopen($tmpfile, 'a+', false)
00047     or mdie("Error openning $tmpfile on append\n");
00048 fwrite($fh, "==== ".strftime("%a %b %e %H:%M:%S %Y", time())." ====\n");
00049 fwrite($fh, "==== Commandline: " . implode(' ',$argv) . "\n");
00050 
00051 $stdin = fopen('php://stdin', 'r');
00052 
00053 while ($line = fgets($stdin)) {
00054     fwrite($fh, $line);
00055 }
00056 fwrite($fh, "\n");
00057 fclose($fh);
00058 fclose($stdin);
00059 
00072 function mdie($msg='', $errorcode=1) {
00073     trigger_error($msg);
00074     exit($errorcode);
00075 }
00076 
00077 
 All Data Structures Namespaces Files Functions Variables Enumerations