| | <?php |
---|
| | include('/opt/GoSMS/config.php'); |
---|
| | |
---|
| | $email = file_get_contents("php://stdin"); |
---|
| | $lines = explode("\n", $email); |
---|
| | |
---|
| | $from = ""; |
---|
| | $subject = ""; |
---|
| | $to = ""; |
---|
| | $orig = ""; |
---|
| | $headers = ""; |
---|
| | $message = ""; |
---|
| | $splittingheaders = true; |
---|
| | for ($i=0; $i < count($lines); $i++) { |
---|
| | if ($splittingheaders) { |
---|
| | $headers .= $lines[$i]."\n"; |
---|
| | if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { |
---|
| | $subject = $matches[1]; |
---|
| | } |
---|
| | if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { |
---|
| | $from = $matches[1]; |
---|
| | } |
---|
| | if (preg_match("/^To: (.*)/", $lines[$i], $matches)) { |
---|
| | $to = $matches[1]; |
---|
| | } |
---|
| | if (preg_match("/^X-Original-To: (.*)/", $lines[$i], $matches)){ |
---|
| | $orig = $matches[1]; |
---|
| | } |
---|
| | } else { |
---|
| | // not a header, but message |
---|
| | $lines[$i] = str_replace("?rid=3D", "?rid=", $lines[$i]); |
---|
| | if(substr($lines[$i], -1) == "="){ |
---|
| | $message .= rtrim($lines[$i], "="); |
---|
| | }else{ |
---|
| | $message .= $lines[$i]."\n"; |
---|
| | } |
---|
| | } |
---|
| | if (trim($lines[$i])=="") { |
---|
| | $splittingheaders = false; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | // Got email and processed, time to send SMS... |
---|
| | |
---|
| | $orig = str_replace("@gophish.sms", "", $orig); |
---|
| | $url = "https://api.twilio.com/2010-04-01/Accounts/$TwilioID/Messages.json"; |
---|
| | $data = array ( |
---|
| | 'From' => $SMSFrom, |
---|
| | 'To' => $orig, |
---|
| | 'StatusCallback' => $Callback, |
---|
| | 'Body' => $message, |
---|
| | ); |
---|
| | $post = http_build_query($data); |
---|
| | $auth = "$TwilioID:$AuthToken"; |
---|
| | |
---|
| | $response = SendSMS($url, $post, $auth); |
---|
| | |
---|
| | function SendSMS($url,$post=false,$auth=false,$timeout=30) { |
---|
| | $ch = curl_init(); |
---|
| | |
---|
| | curl_setopt($ch, CURLOPT_URL, $url); |
---|
| | if ($post) { |
---|
| | curl_setopt($ch, CURLOPT_POST, 1); |
---|
| | curl_setopt($ch, CURLOPT_POSTFIELDS, $post); |
---|
| | } |
---|
| | if($auth) |
---|
| | curl_setopt($ch, CURLOPT_USERPWD, $auth); |
---|
| | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
---|
| | curl_setopt($ch,CURLOPT_ENCODING , ""); |
---|
| | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
---|
| | curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"); |
---|
| | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
---|
| | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
---|
| | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); |
---|
| | curl_setopt($ch, CURLOPT_HEADER, false); //debug |
---|
| | curl_setopt($ch, CURLINFO_HEADER_OUT, true); // enable tracking DEBUG |
---|
| | $output=curl_exec($ch); |
---|
| | |
---|
| | curl_close($ch); |
---|
| | return $output; |
---|
| | } |
---|
| | |
---|
| | ?> |
---|
| | |
---|
| | |