Newer
Older
GoSMS / SendSMS.php
root on 18 May 2019 2 KB Initial commit
  1. <?php
  2. include('/opt/GoSMS/config.php');
  3.  
  4. $email = file_get_contents("php://stdin");
  5. $lines = explode("\n", $email);
  6.  
  7. $from = "";
  8. $subject = "";
  9. $to = "";
  10. $orig = "";
  11. $headers = "";
  12. $message = "";
  13. $splittingheaders = true;
  14. for ($i=0; $i < count($lines); $i++) {
  15. if ($splittingheaders) {
  16. $headers .= $lines[$i]."\n";
  17. if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
  18. $subject = $matches[1];
  19. }
  20. if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
  21. $from = $matches[1];
  22. }
  23. if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
  24. $to = $matches[1];
  25. }
  26. if (preg_match("/^X-Original-To: (.*)/", $lines[$i], $matches)){
  27. $orig = $matches[1];
  28. }
  29. } else {
  30. // not a header, but message
  31. $lines[$i] = str_replace("?rid=3D", "?rid=", $lines[$i]);
  32. if(substr($lines[$i], -1) == "="){
  33. $message .= rtrim($lines[$i], "=");
  34. }else{
  35. $message .= $lines[$i]."\n";
  36. }
  37. }
  38. if (trim($lines[$i])=="") {
  39. $splittingheaders = false;
  40. }
  41. }
  42.  
  43. // Got email and processed, time to send SMS...
  44.  
  45. $orig = str_replace("@gophish.sms", "", $orig);
  46. $url = "https://api.twilio.com/2010-04-01/Accounts/$TwilioID/Messages.json";
  47. $data = array (
  48. 'From' => $SMSFrom,
  49. 'To' => $orig,
  50. 'StatusCallback' => $Callback,
  51. 'Body' => $message,
  52. );
  53. $post = http_build_query($data);
  54. $auth = "$TwilioID:$AuthToken";
  55.  
  56. $response = SendSMS($url, $post, $auth);
  57.  
  58. function SendSMS($url,$post=false,$auth=false,$timeout=30) {
  59. $ch = curl_init();
  60.  
  61. curl_setopt($ch, CURLOPT_URL, $url);
  62. if ($post) {
  63. curl_setopt($ch, CURLOPT_POST, 1);
  64. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  65. }
  66. if($auth)
  67. curl_setopt($ch, CURLOPT_USERPWD, $auth);
  68. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  69. curl_setopt($ch,CURLOPT_ENCODING , "");
  70. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  71. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0");
  72. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  73. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  74. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
  75. curl_setopt($ch, CURLOPT_HEADER, false); //debug
  76. curl_setopt($ch, CURLINFO_HEADER_OUT, true); // enable tracking DEBUG
  77. $output=curl_exec($ch);
  78. curl_close($ch);
  79. return $output;
  80. }
  81.  
  82. ?>
Buy Me A Coffee