~ubuntu-branches/ubuntu/jaunty/moodle/jaunty

« back to all changes in this revision

Viewing changes to admin/mailout-debugger.php

  • Committer: Bazaar Package Importer
  • Author(s): Jordan Mantha, Matt Oquist
  • Date: 2009-02-25 15:16:22 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090225151622-0ekt1liwhv2obfza
Tags: 1.9.4.dfsg-0ubuntu1
* Merge with Debian git (Closes LP: #322961, #239481, #334611):
  - use Ubuntu's smarty lib directory for linking
  - use internal yui library 
  - add update-notifier support back in

[Matt Oquist]
  * renamed prerm script
  * significantly rewrote postinst and other maintainer scripts to improve
    user experience and package maintainability
    (Closes LP: #225662, #325450, #327843, #303078, #234609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/php
 
2
<?php
 
3
  /*
 
4
   * Utility to debug mailouts - will save the content of emails to a
 
5
   * logfile instead of sending them out. Use it as a sendmail
 
6
   * "stand-in" when testing mailouts.
 
7
   *
 
8
   * It is not Moodle specific - use it anywhere by setting the php
 
9
   * "sendmail_path" setting to this file with a logfile parameter.
 
10
   *
 
11
   * - Set in php.ini (not settable in config.php):
 
12
   *     sendmail_path=/path-to-moodle/admin/mailout-debugger.php');
 
13
   *   Or from the commandline
 
14
   *     php -d sendmail_path='/path-to-moodle/admin/mailout-debugger.php' /path/to/cron.php
 
15
   *
 
16
   * - Create a file in admin called mailout-debugger.enable
 
17
   *   (this is a security check to prevent execution in prod environments)
 
18
   *   touch /path/to/moodle/admin/mailout-debugger.enable
 
19
   *
 
20
   * - Mark as executable: chmod ugo+rx mailout-debugger.php
 
21
   *
 
22
   * - Run your admin/cron.php
 
23
   *
 
24
   * - Read /tmp/moodle-mailout.log
 
25
   *   
 
26
   *
 
27
   * This script will create logfiles in /tmp/ or in $TMPDIR if set.
 
28
   * On windows, use php -r 'print sys_get_temp_dir()' to see where the file is saved.
 
29
   */
 
30
 
 
31
// Security check.
 
32
if (!file_exists(dirname(__FILE__).'/mailout-debugger.enable')) {
 
33
    mdie("Disabled.");
 
34
}
 
35
$tmpdir=sys_get_temp_dir(); // default
 
36
 
 
37
if (isset($_SERVER['REMOTE_ADDR'])) {
 
38
    mdie("should not be called from web server!");
 
39
}
 
40
 
 
41
if (isset($_ENV['TMPDIR']) && is_dir($_ENV['TMPDIR'])) {
 
42
    $tmpdir = $_ENV['TMPDIR'];
 
43
}
 
44
 
 
45
$tmpfile = $tmpdir . '/moodle-mailout.log';
 
46
$fh = fopen($tmpfile, 'a+', false)
 
47
    or mdie("Error openning $tmpfile on append\n");
 
48
fwrite($fh, "==== ".strftime("%a %b %e %H:%M:%S %Y", time())." ====\n");
 
49
fwrite($fh, "==== Commandline: " . implode(' ',$argv) . "\n");
 
50
 
 
51
$stdin = fopen('php://stdin', 'r');
 
52
 
 
53
while ($line = fgets($stdin)) {
 
54
    fwrite($fh, $line);
 
55
}
 
56
fwrite($fh, "\n");
 
57
fclose($fh);
 
58
fclose($stdin);
 
59
 
 
60
/**
 
61
 * Print an error to STDOUT and exit with a non-zero code. For commandline scripts.
 
62
 * Default errorcode is 1.
 
63
 *
 
64
 * Very useful for perl-like error-handling:
 
65
 *
 
66
 * do_somethting() or mdie("Something went wrong");
 
67
 *
 
68
 * @param string  $msg       Error message
 
69
 * @param integer $errorcode Error code to emit
 
70
 *
 
71
 */
 
72
function mdie($msg='', $errorcode=1) {
 
73
    trigger_error($msg);
 
74
    exit($errorcode);
 
75
}
 
76
 
 
77
?>