/**
  * Checks user registration to spam
  *
  * @param array	$spam_check		Array with values to check
  * @return array				Array with result flags
  */
 public static function check_spam($spam_check)
 {
     global $config, $user, $request, $phpbb_root_path, $phpEx, $phpbb_log;
     require_once 'cleantalk.class.php';
     $ct_checkjs_val = $request->variable(self::JS_FIELD_NAME, '', false, \phpbb\request\request_interface::COOKIE);
     if ($ct_checkjs_val === '') {
         $checkjs = NULL;
     } elseif (in_array($ct_checkjs_val, self::get_check_js_array())) {
         $checkjs = 1;
     } else {
         $checkjs = 0;
     }
     $ct = new \CleanTalkBase\Cleantalk();
     $root_dir = realpath(dirname(__FILE__) . '/../../../../');
     if (file_exists($root_dir . "/cleantalk.pem")) {
         $ct->ssl_on = true;
         $ct->ssl_path = $root_dir . "/cleantalk.pem";
     }
     $ct->work_url = $config['cleantalk_antispam_work_url'];
     $ct->server_url = $config['cleantalk_antispam_server_url'];
     $ct->server_ttl = $config['cleantalk_antispam_server_ttl'];
     $ct->server_changed = $config['cleantalk_antispam_server_changed'];
     $user_agent = $request->server('HTTP_USER_AGENT');
     $refferrer = $request->server('HTTP_REFERER');
     $sender_info = json_encode(array('cms_lang' => $config['default_lang'], 'REFFERRER' => $refferrer, 'post_url' => $refferrer, 'USER_AGENT' => $user_agent));
     $composer_json = json_decode(file_get_contents($phpbb_root_path . 'ext/cleantalk/antispam/composer.json'));
     $ct_request = new \CleanTalkBase\CleantalkRequest();
     if (isset($spam_check['auth_key'])) {
         $ct_request->auth_key = $spam_check['auth_key'];
     } else {
         $ct_request->auth_key = $config['cleantalk_antispam_apikey'];
     }
     $ct_request->agent = 'phpbb3-' . preg_replace("/(\\d)\\.(\\w+)/", "\$1\$2", $composer_json->version);
     $ct_request->js_on = $checkjs;
     $ct_request->sender_info = $sender_info;
     $ct_request->sender_email = array_key_exists('sender_email', $spam_check) ? $spam_check['sender_email'] : '';
     $ct_request->sender_nickname = array_key_exists('sender_nickname', $spam_check) ? $spam_check['sender_nickname'] : '';
     $ct_request->sender_ip = $user->ip;
     $ct_request->submit_time = !empty($user->data['ct_submit_time']) ? time() - $user->data['ct_submit_time'] : null;
     switch ($spam_check['type']) {
         case 'comment':
             $ct_request->message = (array_key_exists('message_title', $spam_check) ? $spam_check['message_title'] : '') . " \n\n" . (array_key_exists('message_body', $spam_check) ? $spam_check['message_body'] : '');
             $ct_result = $ct->isAllowMessage($ct_request);
             break;
         case 'register':
             $ct_request->tz = array_key_exists('timezone', $spam_check) ? $spam_check['timezone'] : '';
             $ct_result = $ct->isAllowUser($ct_request);
             break;
     }
     $ret_val = array();
     $ret_val['errno'] = 0;
     $ret_val['allow'] = 1;
     $ret_val['ct_request_id'] = $ct_result->id;
     if ($ct->server_change) {
         $config->set('cleantalk_antispam_work_url', $ct->work_url);
         $config->set('cleantalk_antispam_server_url', $ct->server_url);
         $config->set('cleantalk_antispam_server_ttl', $ct->server_ttl);
         $config->set('cleantalk_antispam_server_changed', time());
     }
     // First check errstr flag.
     if (!empty($ct_result->errstr) && ($checkjs = 1 || !empty($ct_result->inactive) && $ct_result->inactive == 1)) {
         // Cleantalk error so we go default way (no action at all).
         $ret_val['errno'] = 1;
         $ct_result->allow = 1;
         if (!empty($ct_result->errstr)) {
             $ret_val['errstr'] = self::filter_response($ct_result->errstr);
         } else {
             $ret_val['errstr'] = self::filter_response($ct_result->comment);
         }
         $phpbb_log->add('admin', ANONYMOUS, '127.0.0.1', 'LOG_CLEANTALK_ERROR', time(), array($ret_val['errstr']));
         // Email to admin once per 15 min
         if (time() - 900 > $config['cleantalk_antispam_error_time']) {
             $config->set('cleantalk_antispam_error_time', time());
             if (!function_exists('phpbb_mail')) {
                 include $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
             }
             $hr_url = str_replace(array('http://', 'https://'), array('', ''), generate_board_url());
             $err_title = $hr_url . ' - ' . $user->lang['MAIL_CLEANTALK_ERROR'];
             $err_message = $hr_url . ' - ' . $user->lang['MAIL_CLEANTALK_ERROR'] . " :\n" . $ret_val['errstr'];
             $headers = array();
             $headers[] = 'Reply-To: ' . $config['board_email'];
             $headers[] = 'Return-Path: <' . $config['board_email'] . '>';
             $headers[] = 'Sender: <' . $config['board_email'] . '>';
             $headers[] = 'MIME-Version: 1.0';
             $headers[] = 'X-Mailer: phpBB3';
             $headers[] = 'X-MimeOLE: phpBB3';
             $headers[] = 'X-phpBB-Origin: phpbb://' . $hr_url;
             $headers[] = 'Content-Type: text/plain; charset=UTF-8';
             // format=flowed
             $headers[] = 'Content-Transfer-Encoding: 8bit';
             // 7bit
             $dummy = '';
             phpbb_mail($config['board_email'], $err_title, $err_message, $headers, "\n", $dummy);
         }
         return $ret_val;
     } else {
         if (!empty($ct_result->errstr) && ($checkjs = 0)) {
             $ct_result->allow = 0;
         }
     }
     if ($ct_result->allow == 0) {
         // Spammer.
         $ret_val['allow'] = 0;
         $ret_val['ct_result_comment'] = self::filter_response($ct_result->comment);
         // Check stop_queue flag.
         if ($spam_check['type'] == 'comment' && $ct_result->stop_queue == 0) {
             // Spammer and stop_queue == 0 - to manual approvement.
             $ret_val['stop_queue'] = 0;
         } else {
             // New user or Spammer and stop_queue == 1 - display form error message.
             $ret_val['stop_queue'] = 1;
         }
     }
     return $ret_val;
 }
 /**
  * Process queue
  * Using lock file
  */
 function process()
 {
     global $db, $config, $phpEx, $phpbb_root_path, $user;
     set_config('last_queue_run', time(), true);
     // Delete stale lock file
     if (file_exists($this->cache_file . '.lock') && !file_exists($this->cache_file)) {
         @unlink($this->cache_file . '.lock');
         return;
     }
     if (!file_exists($this->cache_file) || file_exists($this->cache_file . '.lock') && filemtime($this->cache_file) > time() - $config['queue_interval']) {
         return;
     }
     $fp = @fopen($this->cache_file . '.lock', 'wb');
     fclose($fp);
     @chmod($this->cache_file . '.lock', 0777);
     include $this->cache_file;
     foreach ($this->queue_data as $object => $data_ary) {
         @set_time_limit(0);
         if (!isset($data_ary['package_size'])) {
             $data_ary['package_size'] = 0;
         }
         $package_size = $data_ary['package_size'];
         $num_items = !$package_size || sizeof($data_ary['data']) < $package_size ? sizeof($data_ary['data']) : $package_size;
         // If the amount of emails to be sent is way more than package_size than we need to increase it to prevent backlogs...
         if (sizeof($data_ary['data']) > $package_size * 2.5) {
             $num_items = sizeof($data_ary['data']);
         }
         switch ($object) {
             case 'email':
                 // Delete the email queued objects if mailing is disabled
                 if (!$config['email_enable']) {
                     unset($this->queue_data['email']);
                     continue 2;
                 }
                 break;
             case 'jabber':
                 if (!$config['jab_enable']) {
                     unset($this->queue_data['jabber']);
                     continue 2;
                 }
                 include_once $phpbb_root_path . 'includes/functions_jabber.' . $phpEx;
                 $this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], $config['jab_password'], $config['jab_use_ssl']);
                 if (!$this->jabber->connect()) {
                     messenger::error('JABBER', $user->lang['ERR_JAB_CONNECT']);
                     continue 2;
                 }
                 if (!$this->jabber->login()) {
                     messenger::error('JABBER', $user->lang['ERR_JAB_AUTH']);
                     continue 2;
                 }
                 break;
             default:
                 return;
         }
         for ($i = 0; $i < $num_items; $i++) {
             // Make variables available...
             extract(array_shift($this->queue_data[$object]['data']));
             switch ($object) {
                 case 'email':
                     $err_msg = '';
                     $to = !$to ? 'undisclosed-recipients:;' : $to;
                     if ($config['smtp_delivery']) {
                         $result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers);
                     } else {
                         $result = phpbb_mail($to, $subject, $msg, $headers, $this->eol, $err_msg);
                     }
                     if (!$result) {
                         @unlink($this->cache_file . '.lock');
                         messenger::error('EMAIL', $err_msg);
                         continue 2;
                     }
                     break;
                 case 'jabber':
                     foreach ($addresses as $address) {
                         if ($this->jabber->send_message($address, $msg, $subject) === false) {
                             messenger::error('JABBER', $this->jabber->get_log());
                             continue 3;
                         }
                     }
                     break;
             }
         }
         // No more data for this object? Unset it
         if (!sizeof($this->queue_data[$object]['data'])) {
             unset($this->queue_data[$object]);
         }
         // Post-object processing
         switch ($object) {
             case 'jabber':
                 // Hang about a couple of secs to ensure the messages are
                 // handled, then disconnect
                 $this->jabber->disconnect();
                 break;
         }
     }
     if (!sizeof($this->queue_data)) {
         @unlink($this->cache_file);
     } else {
         if ($fp = @fopen($this->cache_file, 'wb')) {
             @flock($fp, LOCK_EX);
             fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
             @flock($fp, LOCK_UN);
             fclose($fp);
             phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
         }
     }
     @unlink($this->cache_file . '.lock');
 }
 /**
  * Process queue
  * Using lock file
  */
 function process()
 {
     global $db, $config, $phpEx, $phpbb_root_path, $user;
     $lock = new \phpbb\lock\flock($this->cache_file);
     $lock->acquire();
     // avoid races, check file existence once
     $have_cache_file = file_exists($this->cache_file);
     if (!$have_cache_file || $config['last_queue_run'] > time() - $config['queue_interval']) {
         if (!$have_cache_file) {
             set_config('last_queue_run', time(), true);
         }
         $lock->release();
         return;
     }
     set_config('last_queue_run', time(), true);
     include $this->cache_file;
     foreach ($this->queue_data as $object => $data_ary) {
         @set_time_limit(0);
         if (!isset($data_ary['package_size'])) {
             $data_ary['package_size'] = 0;
         }
         $package_size = $data_ary['package_size'];
         $num_items = !$package_size || sizeof($data_ary['data']) < $package_size ? sizeof($data_ary['data']) : $package_size;
         /*
         * This code is commented out because it causes problems on some web hosts.
         * The core problem is rather restrictive email sending limits.
         * This code is nly useful if you have no such restrictions from the
         * web host and the package size setting is wrong.
         
         // If the amount of emails to be sent is way more than package_size than we need to increase it to prevent backlogs...
         if (sizeof($data_ary['data']) > $package_size * 2.5)
         {
         	$num_items = sizeof($data_ary['data']);
         }
         */
         switch ($object) {
             case 'email':
                 // Delete the email queued objects if mailing is disabled
                 if (!$config['email_enable']) {
                     unset($this->queue_data['email']);
                     continue 2;
                 }
                 break;
             case 'jabber':
                 if (!$config['jab_enable']) {
                     unset($this->queue_data['jabber']);
                     continue 2;
                 }
                 include_once $phpbb_root_path . 'includes/functions_jabber.' . $phpEx;
                 $this->jabber = new jabber($config['jab_host'], $config['jab_port'], $config['jab_username'], htmlspecialchars_decode($config['jab_password']), $config['jab_use_ssl']);
                 if (!$this->jabber->connect()) {
                     $messenger = new messenger();
                     $messenger->error('JABBER', $user->lang['ERR_JAB_CONNECT']);
                     continue 2;
                 }
                 if (!$this->jabber->login()) {
                     $messenger = new messenger();
                     $messenger->error('JABBER', $user->lang['ERR_JAB_AUTH']);
                     continue 2;
                 }
                 break;
             default:
                 $lock->release();
                 return;
         }
         for ($i = 0; $i < $num_items; $i++) {
             // Make variables available...
             extract(array_shift($this->queue_data[$object]['data']));
             switch ($object) {
                 case 'email':
                     $err_msg = '';
                     $to = !$to ? 'undisclosed-recipients:;' : $to;
                     if ($config['smtp_delivery']) {
                         $result = smtpmail($addresses, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $err_msg, $headers);
                     } else {
                         $result = phpbb_mail($to, $subject, $msg, $headers, $this->eol, $err_msg);
                     }
                     if (!$result) {
                         $messenger = new messenger();
                         $messenger->error('EMAIL', $err_msg);
                         continue 2;
                     }
                     break;
                 case 'jabber':
                     foreach ($addresses as $address) {
                         if ($this->jabber->send_message($address, $msg, $subject) === false) {
                             $messenger = new messenger();
                             $messenger->error('JABBER', $this->jabber->get_log());
                             continue 3;
                         }
                     }
                     break;
             }
         }
         // No more data for this object? Unset it
         if (!sizeof($this->queue_data[$object]['data'])) {
             unset($this->queue_data[$object]);
         }
         // Post-object processing
         switch ($object) {
             case 'jabber':
                 // Hang about a couple of secs to ensure the messages are
                 // handled, then disconnect
                 $this->jabber->disconnect();
                 break;
         }
     }
     if (!sizeof($this->queue_data)) {
         @unlink($this->cache_file);
     } else {
         if ($fp = @fopen($this->cache_file, 'wb')) {
             fwrite($fp, "<?php\nif (!defined('IN_PHPBB')) exit;\n\$this->queue_data = unserialize(" . var_export(serialize($this->queue_data), true) . ");\n\n?>");
             fclose($fp);
             phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE);
         }
     }
     $lock->release();
 }
示例#4
0
 /**
  * Send out emails
  */
 function msg_email($is_html = false)
 {
     global $config;
     if (empty($config['email_enable'])) {
         return false;
     }
     // Addresses to send to?
     if (empty($this->addresses) || empty($this->addresses['to']) && empty($this->addresses['cc']) && empty($this->addresses['bcc'])) {
         // Send was successful. ;)
         return true;
     }
     $contact_name = htmlspecialchars_decode($config['board_contact_name']);
     $board_contact = ($contact_name !== '' ? '"' . mail_encode($contact_name) . '" ' : '') . '<' . $config['board_contact'] . '>';
     if (empty($this->replyto)) {
         $this->replyto = $board_contact;
     }
     if (empty($this->from)) {
         $this->from = $board_contact;
     }
     $encode_eol = $config['smtp_delivery'] ? "\r\n" : $this->eol;
     // Build to, cc and bcc strings
     $to = $cc = $bcc = '';
     foreach ($this->addresses as $type => $address_ary) {
         if ($type == 'im') {
             continue;
         }
         foreach ($address_ary as $which_ary) {
             ${$type} .= (${$type} != '' ? ', ' : '') . ($which_ary['name'] != '' ? mail_encode($which_ary['name'], $encode_eol) . ' <' . $which_ary['email'] . '>' : $which_ary['email']);
         }
     }
     // Build header
     $headers = $this->build_header($to, $cc, $bcc, $is_html);
     // Send message ...
     $mail_to = $to == '' ? 'undisclosed-recipients:;' : $to;
     $err_msg = '';
     if ($config['smtp_delivery']) {
         $result = smtpmail($this->addresses, mail_encode($this->subject), wordwrap(utf8_wordwrap($this->msg), 997, "\n", true), $err_msg, $headers);
     } else {
         $result = phpbb_mail($mail_to, $this->subject, $this->msg, $headers, $this->eol, $err_msg);
     }
     if (!$result) {
         $this->error('EMAIL', $err_msg);
         return false;
     }
     return true;
 }