Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1. #!/usr/local/bin/php -q
  2. <?php
  3. /*
  4.  
  5. -- PIPE : "|/home/u0047/domains/krisa.be/public_html/112/pipe.php"
  6. -- DB
  7. CREATE TABLE IF NOT EXISTS `email_log` (
  8. `id` int(11) NOT NULL auto_increment,
  9. `to` varchar(100) NOT NULL,
  10. `subject` varchar(200) NOT NULL,
  11. `from` varchar(100) NOT NULL,
  12. `headers` text NOT NULL,
  13. `message` text NOT NULL,
  14. `source` text NOT NULL,
  15. `logged_at` timestamp NOT NULL default CURRENT_TIMESTAMP,
  16. PRIMARY KEY  (`id`)
  17. ) ENGINE=MyISAM;
  18.  
  19. */
  20.  
  21. // Config
  22. $dbuser = '';
  23. $dbpass = '';
  24. $dbname = '';
  25. $dbhost = 'localhost';
  26. $notify = 'kris@mymail.ext'; // an email address required in case of errors
  27. $FROMCHECK = 'astrid_pager_on3kdr@telenet.be'; // vanwaar de mail mag komen, andere worden genegeerd
  28.  
  29. // read from stdin
  30. $fd = fopen("php://stdin", "r");
  31. $email = "";
  32. while (!feof($fd))
  33.   $email .= fread($fd, 1024);
  34.  
  35. fclose($fd);
  36. // handle email
  37. $lines = explode("\n", $email);
  38.  
  39. // empty vars
  40. $from = "";
  41. $subject = "";
  42. $headers = "";
  43. $message = "";
  44. $splittingheaders = true;
  45. for ($i=0; $i < count($lines); $i++) {
  46.     if ($splittingheaders) {
  47.         // this is a header
  48.         $headers .= $lines[$i]."\n";
  49.  
  50.         // look out for special headers
  51.         if (preg_match("/^Subject: (.*)/", $lines[$i], $matches))
  52.             $subject = $matches[1];
  53.         if (preg_match("/^From: (.*)/", $lines[$i], $matches))
  54.             $from = $matches[1];
  55.         if (preg_match("/^To: (.*)/", $lines[$i], $matches))
  56.             $to = $matches[1];
  57.     }
  58.     else
  59.         $message .= $lines[$i]."\n";
  60.  
  61.     if (trim($lines[$i])=="") {
  62.         // empty line, header section has ended
  63.         $splittingheaders = false;
  64.     }
  65. }
  66. preg_match('/<(.*)>/', $from, $regexfrom);
  67.  
  68. $fromt = str_replace(array('<', '>'), '', $from);
  69.  
  70. if ( $fromt == $FROMCHECK OR $regexfrom[1] == $FROMCHECK ) // only allow from one e-mail address
  71. {
  72.  
  73.   if ($conn = @mysql_connect($dbhost,$dbuser,$dbpass)) {
  74.  
  75.     if(!@mysql_select_db($dbname,$conn))
  76.       mail($email,'Email Logger Error',"There was an error selecting the email logger database.\n\n".mysql_error());
  77.  
  78.     $from    = mysql_real_escape_string($from);
  79.     $to    = mysql_real_escape_string($to);
  80.     $subject = mysql_real_escape_string($subject);
  81.     $headers = mysql_real_escape_string($headers);
  82.     $message = mysql_real_escape_string($message);
  83.     $email   = mysql_real_escape_string($email);
  84.  
  85.     $double = mysql_query("SELECT subject FROM email_log WHERE subject='".$subject."'");
  86.    
  87.     if ( mysql_num_rows($double) == 0 )
  88.         $result = @mysql_query("INSERT INTO email_log (`to`,`from`,`subject`,`headers`,`message`,`source`) VALUES('$to','$from','$subject','$headers','$message','$email')");
  89.  
  90.  
  91.   }
  92.   else
  93.     mail($notify,'Email Logger Error',"There was an error connecting the email logger database.\n\n".mysql_error());
  94. }
  95.  
  96.  
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement