A Framework for managing crash reports, bug reports, and messages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
6.1 KiB

  1. <?php
  2. /*
  3. * sendreport.php
  4. * GeckoReporter
  5. *
  6. * Created by Mr. Gecko on 12/28/09.
  7. * Copyright 2010 by Mr. Gecko's Media (James Coleman). All rights reserved. http://mrgeckosmedia.com/
  8. *
  9. */
  10. //Debug
  11. //print_r($_FILES);
  12. //print_r($_POST);
  13. function buildBody($FILES, $BOUNDARY) {
  14. $BODY = "\n\r\n";
  15. $KEYS = array_keys($FILES);
  16. for ($i=0; $i<count($KEYS); $i++) {
  17. $KEY = $KEYS[$i];
  18. $FILE = $_FILES[$KEY]['tmp_name'];
  19. $FILENAME = $_FILES[$KEY]['name'];
  20. $FILETYPE = $_FILES[$KEY]['type'];
  21. $FILESIZE = $_FILES[$KEY]['size'];
  22. $BODY .= "--$BOUNDARY\r\n";
  23. $BODY .= "Content-Disposition: attachment; filename=\"{$FILENAME}\"\r\n";
  24. $BODY .= "Content-Type: {$FILETYPE}; name=\"{$FILENAME}\"\r\n";
  25. $BODY .= "Content-Transfer-Encoding: binary\r\n\r\n";
  26. $FILEPIPE = fopen($FILE, "r");
  27. $BODY .= fread($FILEPIPE, $FILESIZE);
  28. fclose($FILEPIPE);
  29. $BODY .= "\r\n";
  30. }
  31. $BODY .= "--{$BOUNDARY}--";
  32. return $BODY;
  33. }
  34. //Word of warning, IP is for debugging, do not include the IP of your user without the knowledge that your user may not use your application.
  35. //$_POST['IP'] = $_SERVER['HTTP_PC_REMOTE_ADDR']!="" ? $_SERVER['HTTP_PC_REMOTE_ADDR'] : $_SERVER['REMOTE_ADDR'];
  36. $_POST['User_Agent'] = urldecode($_SERVER['HTTP_USER_AGENT']);
  37. if ($_POST['GRType']=="crash") {
  38. unset($_POST['GRType']);
  39. $email = $_POST['GREmail'];
  40. unset($_POST['GREmail']);
  41. $subject = $_POST['GRSubject'];
  42. unset($_POST['GRSubject']);
  43. $userReport = isset($_POST['GRUserReport']) ? trim($_POST['GRUserReport']) : "";
  44. unset($_POST['GRUserReport']);
  45. $boundary = "--Boundary+".rand(0, 100000);
  46. if ($_POST['GRReportAttached']=="NO") {
  47. if (isset($_FILES['reportFile'])) {
  48. $filePipe = fopen($_FILES['reportFile']['tmp_name'], "r");
  49. $reportFileContents = fread($filePipe, $_FILES['reportFile']['size']);
  50. fclose($filePipe);
  51. unset($_FILES['reportFile']);
  52. $_POST['Report'] = "\n\n".$reportFileContents;
  53. }
  54. }
  55. unset($_POST['GRReportAttached']);
  56. if (preg_match("/([\w\.\-]+)(\@[\w\.\-]+)(\.[a-z]{2,4})+/i", $_POST['User_Email_Address'])) {
  57. $fromEmail = "{$_POST['User_Email_Address']}";
  58. } else {
  59. $fromEmail = "\"Mr. Gecko's Media\" <webmaster@mrgeckosmedia.com>";
  60. }
  61. $headers = "From: {$fromEmail}\r\n";
  62. $headers .= "X-Mailer: GeckoReporter/{$_POST['GRVersion']}\r\n";
  63. unset($_POST['GRVersion']);
  64. $headers .= "MIME-Version: 1.0\r\n";
  65. $headers .= "Content-Type: multipart/mixed; boundary={$boundary}\r\n\r\n";
  66. $headers .= "--$boundary\r\n";
  67. $headers .= "Content-Type: text/plain; charset=utf-8\r\n";
  68. $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  69. $KEYS = array_keys($_POST);
  70. sort($KEYS);
  71. for ($i=0; $i<count($KEYS); $i++) {
  72. $KEY = $KEYS[$i];
  73. $NAME = str_replace("_", " ", $KEY);
  74. $headers .= "{$NAME}: {$_POST[$KEY]}\n";
  75. }
  76. if ($userReport!="")
  77. $headers .= "\nThe user was\n$userReport\n";
  78. $headers .= buildBody($_FILES, $boundary);
  79. $sent = mail($email, $subject, "This is a multipart message, your email client needs to support mime 1.0 in order to read this message.", $headers);
  80. echo ($sent ? "Crash Report Was Sent" : "Crash Report Was Not Sent");
  81. } else if ($_POST['GRType']=="bug") {
  82. unset($_POST['GRType']);
  83. $email = $_POST['GREmail'];
  84. unset($_POST['GREmail']);
  85. $subject = $_POST['GRSubject'];
  86. unset($_POST['GRSubject']);
  87. $bug = isset($_POST['GRBug']) ? trim($_POST['GRBug']) : "";
  88. unset($_POST['GRBug']);
  89. $reproduce = isset($_POST['GRReproduce']) ? trim($_POST['GRReproduce']) : "";
  90. unset($_POST['GRReproduce']);
  91. $boundary = "--Boundary+".rand(0, 100000);
  92. if (preg_match("/([\w\.\-]+)(\@[\w\.\-]+)(\.[a-z]{2,4})+/i", $_POST['User_Email_Address'])) {
  93. $fromEmail = "{$_POST['User_Email_Address']}";
  94. } else {
  95. $fromEmail = "\"Mr. Gecko's Media\" <webmaster@mrgeckosmedia.com>";
  96. }
  97. $headers = "From: {$fromEmail}\r\n";
  98. $headers .= "X-Mailer: GeckoReporter/{$_POST['GRVersion']}\r\n";
  99. unset($_POST['GRVersion']);
  100. $headers .= "MIME-Version: 1.0\r\n";
  101. $headers .= "Content-Type: multipart/mixed; boundary={$boundary}\r\n\r\n";
  102. $headers .= "--$boundary\r\n";
  103. $headers .= "Content-Type: text/plain; charset=utf-8\r\n";
  104. $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  105. $KEYS = array_keys($_POST);
  106. sort($KEYS);
  107. for ($i=0; $i<count($KEYS); $i++) {
  108. $KEY = $KEYS[$i];
  109. $NAME = str_replace("_", " ", $KEY);
  110. $headers .= "{$NAME}: {$_POST[$KEY]}\n";
  111. }
  112. if ($bug!="")
  113. $headers .= "\nThe Bug\n$bug\n";
  114. if ($reproduce!="")
  115. $headers .= "\nHow you can reproduce it\n$reproduce\n";
  116. $headers .= buildBody($_FILES, $boundary);
  117. $sent = mail($email, $subject, "This is a multipart message, your email client needs to support mime 1.0 in order to read this message.", $headers);
  118. echo ($sent ? "Bug Report Was Sent" : "Bug Report Was Not Sent");
  119. } else if ($_POST['GRType']=="contact") {
  120. unset($_POST['GRType']);
  121. $email = $_POST['GREmail'];
  122. unset($_POST['GREmail']);
  123. $subject = $_POST['GRSubject'];
  124. unset($_POST['GRSubject']);
  125. $message = isset($_POST['GRMessage']) ? trim($_POST['GRMessage']) : "";
  126. unset($_POST['GRMessage']);
  127. $boundary = "--Boundary+".rand(0, 100000);
  128. if (preg_match("/([\w\.\-]+)(\@[\w\.\-]+)(\.[a-z]{2,4})+/i", $_POST['User_Email_Address'])) {
  129. $fromEmail = "\"{$_POST['User_Name']}\" <{$_POST['User_Email_Address']}>";
  130. } else {
  131. $fromEmail = "\"Mr. Gecko's Media\" <webmaster@mrgeckosmedia.com>";
  132. }
  133. $headers = "From: {$fromEmail}\r\n";
  134. $headers .= "X-Mailer: GeckoReporter/{$_POST['GRVersion']}\r\n";
  135. unset($_POST['GRVersion']);
  136. $headers .= "MIME-Version: 1.0\r\n";
  137. $headers .= "Content-Type: multipart/mixed; boundary={$boundary}\r\n\r\n";
  138. $headers .= "--$boundary\r\n";
  139. $headers .= "Content-Type: text/plain; charset=utf-8\r\n";
  140. $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  141. $KEYS = array_keys($_POST);
  142. sort($KEYS);
  143. for ($i=0; $i<count($KEYS); $i++) {
  144. $KEY = $KEYS[$i];
  145. $NAME = str_replace("_", " ", $KEY);
  146. $headers .= "{$NAME}: {$_POST[$KEY]}\n";
  147. }
  148. if ($message!="")
  149. $headers .= "\nThe message\n$message\n";
  150. $headers .= buildBody($_FILES, $boundary);
  151. $sent = mail($email, $subject, "This is a multipart message, your email client needs to support mime 1.0 in order to read this message.", $headers);
  152. echo ($sent ? "Message Was Sent" : "Message Was Not Sent");
  153. }
  154. ?>