コード例 #1
0
 public static function hookAdminSettings(XenForo_Visitor &$visitor)
 {
     $options = XenForo_Application::getOptions();
     if ($options->get('cleantalk', 'enabled') && sizeof($_POST) > 0 && isset($_POST['options']) && isset($_POST['options']['cleantalk'])) {
         require_once 'CleanTalk/Base/cleantalk.class.php';
         $ct_ws = array('work_url' => 'http://moderate.cleantalk.org', 'server_url' => 'http://moderate.cleantalk.org', 'server_ttl' => 0, 'server_changed' => 0);
         $ct = new Cleantalk();
         $ct->work_url = $ct_ws['work_url'];
         $ct->server_url = $ct_ws['server_url'];
         $ct->server_ttl = $ct_ws['server_ttl'];
         $ct->server_changed = $ct_ws['server_changed'];
         $options = XenForo_Application::getOptions();
         $ct_request = new CleantalkRequest();
         $ct_request->auth_key = $_POST['options']['cleantalk']['apikey'];
         $ct_request->agent = 'xenforo-15';
         $ct_request->response_lang = 'en';
         $ct_request->js_on = 1;
         $ct_request->sender_email = "*****@*****.**";
         $ct_request->sender_nickname = "CleanTalk";
         $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
         $ct_request->submit_time = 0;
         $ct_request->message = "This message is a test to check the connection to the CleanTalk servers.";
         $ct_result = $ct->isAllowMessage($ct_request);
     }
 }
コード例 #2
0
/**
 * Test S2member registration
 * @return array with errors 
 */
function ct_s2member_registration_test()
{
    global $ct_agent_version, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_options, $ct_data;
    $ct_options = ct_get_options();
    $ct_data = ct_get_data();
    if ($ct_options['registrations_test'] == 0) {
        return null;
    }
    $submit_time = submit_time_test();
    $checkjs = js_test('ct_checkjs', $_COOKIE, true);
    require_once 'cleantalk.class.php';
    $sender_info = get_sender_info();
    $sender_info = json_encode($sender_info);
    if ($sender_info === false) {
        $sender_info = '';
    }
    $sender_email = null;
    if (isset($_POST[$ct_post_data_label]['email'])) {
        $sender_email = $_POST[$ct_post_data_label]['email'];
    }
    if (isset($_POST[$ct_post_data_authnet_label]['email'])) {
        $sender_email = $_POST[$ct_post_data_authnet_label]['email'];
    }
    $sender_nickname = null;
    if (isset($_POST[$ct_post_data_label]['username'])) {
        $sender_nickname = $_POST[$ct_post_data_label]['username'];
    }
    if (isset($_POST[$ct_post_data_authnet_label]['username'])) {
        $sender_nickname = $_POST[$ct_post_data_authnet_label]['username'];
    }
    $config = get_option('cleantalk_server');
    $ct = new Cleantalk();
    $ct->work_url = $config['ct_work_url'];
    $ct->server_url = $ct_options['server'];
    $ct->server_ttl = $config['ct_server_ttl'];
    $ct->server_changed = $config['ct_server_changed'];
    $ct->ssl_on = $ct_options['ssl_on'];
    $ct_request = new CleantalkRequest();
    $ct_request->auth_key = $ct_options['apikey'];
    $ct_request->sender_email = $sender_email;
    $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
    $ct_request->sender_nickname = $sender_nickname;
    $ct_request->agent = $ct_agent_version;
    $ct_request->sender_info = $sender_info;
    $ct_request->js_on = $checkjs;
    $ct_request->submit_time = $submit_time;
    $ct_result = $ct->isAllowUser($ct_request);
    if ($ct->server_change) {
        update_option('cleantalk_server', array('ct_work_url' => $ct->work_url, 'ct_server_ttl' => $ct->server_ttl, 'ct_server_changed' => time()));
    }
    if ($ct_result->errno != 0) {
        return false;
    }
    // Restart submit form counter for failed requests
    if ($ct_result->allow == 0) {
        $_SESSION[$ct_formtime_label] = time();
    }
    if ($ct_result->allow == 0) {
        ct_die_extended($ct_result->comment);
    }
    return true;
}
コード例 #3
0
 protected function _checkSpam($spam_check, $options)
 {
     require_once 'CleanTalk/Base/cleantalk.class.php';
     $ct_authkey = $options->get('cleantalk', 'apikey');
     $dataRegistryModel = $this->getModelFromCache('XenForo_Model_DataRegistry');
     $ct_ws = $dataRegistryModel->get('cleantalk_ws');
     if (!$ct_ws) {
         $ct_ws = array('work_url' => 'http://moderate.cleantalk.ru', 'server_url' => 'http://moderate.cleantalk.ru', 'server_ttl' => 0, 'server_changed' => 0);
     }
     $field_name = CleanTalk_Base_CleanTalk::getCheckjsName();
     if (!isset($_COOKIE[$field_name])) {
         $checkjs = NULL;
     } elseif (in_array($_COOKIE[$field_name], CleanTalk_Base_CleanTalk::getCheckJSArray())) {
         $checkjs = 1;
     } else {
         $checkjs = 0;
     }
     $user_agent = $_SERVER['HTTP_USER_AGENT'];
     $refferrer = $_SERVER['HTTP_REFERER'];
     $ct = new Cleantalk();
     $ct->work_url = $ct_ws['work_url'];
     $ct->server_url = $ct_ws['server_url'];
     $ct->server_ttl = $ct_ws['server_ttl'];
     $ct->server_changed = $ct_ws['server_changed'];
     $options = XenForo_Application::getOptions();
     $ct_options = array('enabled' => $options->get('cleantalk', 'enabled'), 'apikey' => $options->get('cleantalk', 'apikey'));
     $sender_info = json_encode(array('cms_lang' => 'en', 'REFFERRER' => $refferrer, 'post_url' => $refferrer, 'USER_AGENT' => $user_agent, 'ct_options' => json_encode($ct_options)));
     $ct_request = new CleantalkRequest();
     $ct_request->auth_key = $ct_authkey;
     $ct_request->agent = 'xenforo-15';
     $ct_request->response_lang = 'en';
     $ct_request->js_on = $checkjs;
     $ct_request->sender_info = $sender_info;
     $ct_request->sender_email = $spam_check['sender_email'];
     $ct_request->sender_nickname = $spam_check['sender_nickname'];
     $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
     $ct_submit_time = NULL;
     //	session_start();
     switch ($spam_check['type']) {
         case 'comment':
             $stored_time = XenForo_Application::getSession()->get('ct_submit_comment_time');
             if (isset($stored_time)) {
                 $ct_submit_time = time() - $stored_time;
             }
             $timelabels_key = 'e_comm';
             $ct_request->submit_time = $ct_submit_time;
             $ct_request->message = $spam_check['message_title'] . " \n\n" . $spam_check['message_body'];
             $example = '';
             $a_example = array();
             $a_example['title'] = $spam_check['example_title'];
             $a_example['body'] = $spam_check['example_body'];
             $a_example['comments'] = $spam_check['example_comments'];
             // Additional info.
             $post_info = '';
             $a_post_info['comment_type'] = 'comment';
             // JSON format.
             $example = json_encode($a_example);
             $post_info = json_encode($a_post_info);
             // Plain text format.
             if ($example === FALSE) {
                 $example = '';
                 $example .= $a_example['title'] . " \n\n";
                 $example .= $a_example['body'] . " \n\n";
                 $example .= $a_example['comments'];
             }
             if ($post_info === FALSE) {
                 $post_info = '';
             }
             // Example text + last N comments in json or plain text format.
             $ct_request->example = $example;
             $ct_request->post_info = $post_info;
             $ct_result = $ct->isAllowMessage($ct_request);
             break;
         case 'register':
             $stored_time = XenForo_Application::getSession()->get('ct_submit_register_time');
             if (isset($stored_time)) {
                 $ct_submit_time = time() - $stored_time;
             }
             $timelabels_key = 'e_reg';
             $ct_request->submit_time = $ct_submit_time;
             $ct_request->tz = $spam_check['timezone'];
             $ct_result = $ct->isAllowUser($ct_request);
             break;
     }
     $ret_val = array();
     $ret_val['ct_request_id'] = $ct_result->id;
     if ($ct->server_change) {
         $dataRegistryModel->set('cleantalk_ws', array('work_url' => $ct->work_url, 'server_url' => $ct->server_url, 'server_ttl' => $ct->server_ttl, 'server_changed' => time()));
     }
     // First check errstr flag.
     if (!empty($ct_result->errstr) || !empty($ct_result->inactive) && $ct_result->inactive == 1) {
         // Cleantalk error so we go default way (no action at all).
         $ret_val['errno'] = 1;
         // Just inform admin.
         //$err_title = $_SERVER['SERVER_NAME'] . ' - CleanTalk hook error';
         if (!empty($ct_result->errstr)) {
             $ret_val['errstr'] = $this->_filterResponse($ct_result->errstr);
         } else {
             $ret_val['errstr'] = $this->_filterResponse($ct_result->comment);
         }
         $send_flag = FALSE;
         $ct_time = $dataRegistryModel->get('cleantalk_' . $timelabels_key);
         if (!$ct_time) {
             $send_flag = TRUE;
         } elseif (time() - 900 > $ct_time[0]) {
             // 15 minutes.
             $send_flag = TRUE;
         }
         if ($send_flag) {
             $dataRegistryModel->set('cleantalk_' . $timelabels_key, array(time()));
             $mail = XenForo_Mail::create('cleantalk_error', array('plainText' => $ret_val['errstr'], 'htmlText' => nl2br($ret_val['errstr'])));
             $mail->send($options->get('contactEmailAddress'));
         }
         return $ret_val;
     }
     $ret_val['errno'] = 0;
     if ($ct_result->allow == 1) {
         // Not spammer.
         $ret_val['allow'] = 1;
         /*
         	    // Store request_id in globals to store it in DB later.
         	    _cleantalk_ct_result('set', $ct_result->id);
         	    // Don't store 'ct_result_comment', means good comment.
         */
     } else {
         // Spammer.
         $ret_val['allow'] = 0;
         $ret_val['ct_result_comment'] = $this->_filterResponse($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;
             /*
             	      // Store request_id and comment in static to store them in DB later.
             	      // Store 'ct_result_comment' - means bad comment.
             	      _cleantalk_ct_result('set', $ct_result->id, $ret_val['ct_result_comment']);
             */
         } else {
             // New user or Spammer and stop_queue == 1 - display form error message.
             $ret_val['stop_queue'] = 1;
         }
     }
     return $ret_val;
 }
コード例 #4
0
/**
 * Inner function - Common part of request sending
 * @param array Array of parameters:
 *  'message' - string
 *  'example' - string
 *  'checkjs' - int
 *  'sender_email' - string
 *  'sender_nickname' - string
 *  'sender_info' - array
 *  'post_info' - string
 * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
 */
function ct_base_call($params = array())
{
    global $wpdb, $ct_agent_version, $ct_formtime_label, $ct_options, $ct_data;
    require_once 'cleantalk.class.php';
    $submit_time = submit_time_test();
    $sender_info = get_sender_info();
    if (array_key_exists('sender_info', $params)) {
        $sender_info = array_merge($sender_info, (array) $params['sender_info']);
    }
    $sender_info = json_encode($sender_info);
    if ($sender_info === false) {
        $sender_info = '';
    }
    $config = get_option('cleantalk_server');
    $ct = new Cleantalk();
    $ct->work_url = $config['ct_work_url'];
    $ct->server_url = $ct_options['server'];
    $ct->server_ttl = $config['ct_server_ttl'];
    $ct->server_changed = $config['ct_server_changed'];
    $ct->ssl_on = $ct_options['ssl_on'];
    $ct_request = new CleantalkRequest();
    $ct_request->auth_key = $ct_options['apikey'];
    $ct_request->message = $params['message'];
    $ct_request->example = $params['example'];
    $ct_request->sender_email = $params['sender_email'];
    $ct_request->sender_nickname = $params['sender_nickname'];
    $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
    $ct_request->agent = $ct_agent_version;
    $ct_request->sender_info = $sender_info;
    $ct_request->js_on = $params['checkjs'];
    $ct_request->submit_time = $submit_time;
    $ct_request->post_info = $params['post_info'];
    if (isset($ct_data['last_error_no'])) {
        $ct_request->last_error_no = $ct_data['last_error_no'];
        $ct_request->last_error_time = $ct_data['last_error_time'];
        $ct_request->last_error_text = $ct_data['last_error_text'];
    }
    $ct_result = $ct->isAllowMessage($ct_request);
    if ($ct->server_change) {
        update_option('cleantalk_server', array('ct_work_url' => $ct->work_url, 'ct_server_ttl' => $ct->server_ttl, 'ct_server_changed' => time()));
    }
    // Restart submit form counter for failed requests
    if ($ct_result->allow == 0) {
        $_SESSION[$ct_formtime_label] = time();
        ct_add_event('no');
    } else {
        if (isset($ct_result->errno)) {
            if ($ct_result->errno == 1 || $ct_result->errno == 0) {
                $ct_data['last_error_no'] = $ct_result->errno;
                $ct_data['last_error_time'] = time();
                $ct_data['last_error_text'] = $ct_result->errstr;
                update_option('cleantalk_data', $ct_data);
            }
        }
        ct_add_event('yes');
    }
    return array('ct' => $ct, 'ct_result' => $ct_result);
}
コード例 #5
0
/**
 * Calling by hook integrate_load_theme
 */
function cleantalk_load()
{
    global $context, $user_info, $modSettings, $smcFunc;
    if (isset($context['template_layers']) && is_array($context['template_layers']) && in_array('body', $context['template_layers']) && ($user_info['is_guest'] || $user_info['posts'] == 0) && !cleantalk_is_valid_js()) {
        $context['html_headers'] .= cleantalk_print_js_input();
    }
    if ($user_info['is_admin'] && isset($_POST['ct_del_user'])) {
        foreach ($_POST['ct_del_user'] as $key => $value) {
            $result = $smcFunc['db_query']('', 'delete from {db_prefix}members where id_member=' . intval($key), array());
            $result = $smcFunc['db_query']('', 'delete from {db_prefix}topics where id_member_started=' . intval($key), array());
            $result = $smcFunc['db_query']('', 'delete from {db_prefix}messages where id_member=' . intval($key), array());
        }
    }
    if ($user_info['is_admin'] && isset($_POST['ct_delete_all'])) {
        $result = $smcFunc['db_query']('', 'select * from {db_prefix}members where ct_marked=1', array());
        while ($row = $smcFunc['db_fetch_assoc']($result)) {
            $tmp = $smcFunc['db_query']('', 'delete from {db_prefix}topics where id_member_started=' . $row['id_member'], array());
            $tmp = $smcFunc['db_query']('', 'delete from {db_prefix}messages where id_member=' . $row['id_member'], array());
        }
        $result = $smcFunc['db_query']('', 'delete from {db_prefix}members where ct_marked=1', array());
    }
    if (isset($context['template_layers']) && $context['template_layers'] === array('html', 'body') && array_key_exists('cleantalk_tell_others', $modSettings) && $modSettings['cleantalk_tell_others']) {
        // add "tell others" templates
        $context['template_layers'][] = 'cleantalk';
    }
    if (isset($_POST['cleantalk_api_key'])) {
        $ct = new Cleantalk();
        $ct->server_url = CT_SERVER_URL;
        $ct_request = new CleantalkRequest();
        $ct_request->auth_key = cleantalk_get_api_key();
        $ct_request->response_lang = 'en';
        // SMF use any charset and language
        $ct_request->agent = CT_AGENT_VERSION;
        $ct_request->sender_email = '*****@*****.**';
        $ip = isset($user_info['ip']) ? $user_info['ip'] : $_SERVER['REMOTE_ADDR'];
        $ct_request->sender_ip = $ct->ct_session_ip($ip);
        $ct_request->sender_nickname = 'CleanTalk';
        $ct_request->message = 'This message is a test to check the connection to the CleanTalk servers.';
        $ct_request->submit_time = 10;
        $ct_request->js_on = 1;
        $ct_result = $ct->isAllowMessage($ct_request);
    }
    if (isset($_POST['cleantalk_sfw']) && $_POST['cleantalk_sfw'] == 1) {
        global $smcFunc;
        $sql = "DROP TABLE IF EXISTS `cleantalk_sfw`";
        $result = $smcFunc['db_query']('', $sql, array());
        $sql = "CREATE TABLE IF NOT EXISTS `cleantalk_sfw` (\n`network` int(11) unsigned NOT NULL,\n`mask` int(11) unsigned NOT NULL,\nINDEX (  `network` ,  `mask` )\n) ENGINE = MYISAM ";
        $result = $smcFunc['db_query']('', $sql, array());
        $data = array('auth_key' => cleantalk_get_api_key(), 'method_name' => '2s_blacklists_db');
        $result = sendRawRequest('https://api.cleantalk.org/2.1', $data, false);
        $result = json_decode($result, true);
        if (isset($result['data'])) {
            $result = $result['data'];
            $query = "INSERT INTO `cleantalk_sfw` VALUES ";
            for ($i = 0; $i < sizeof($result); $i++) {
                if ($i == sizeof($result) - 1) {
                    $query .= "(" . $result[$i][0] . "," . $result[$i][1] . ")";
                } else {
                    $query .= "(" . $result[$i][0] . "," . $result[$i][1] . "), ";
                }
            }
            $result = $smcFunc['db_query']('', $query, array());
        }
    }
    if (isset($modSettings['cleantalk_sfw']) && $modSettings['cleantalk_sfw'] == 1) {
        $is_sfw_check = true;
        $ip = CleantalkGetIP();
        $ip = array_unique($ip);
        $key = cleantalk_get_api_key();
        for ($i = 0; $i < sizeof($ip); $i++) {
            if (isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key'] == md5($ip[$i] . $key)) {
                $is_sfw_check = false;
                if (isset($_COOKIE['ct_sfw_passed'])) {
                    @setcookie('ct_sfw_passed', '0', 1, "/");
                }
            }
        }
        if ($is_sfw_check) {
            include_once "cleantalk-sfw.class.php";
            $sfw = new CleanTalkSFW();
            $sfw->cleantalk_get_real_ip();
            $sfw->check_ip();
            if ($sfw->result) {
                $sfw->sfw_die();
            }
        }
    }
}
コード例 #6
0
 /**
  * Sending of manual moderation result to CleanTalk server
  * It makes CleanTalk service better
  * Use it in your modules
  * @param string Name of event generated module ('blog', 'forum', etc.)
  * @param int ID of added entity (comment, message, etc)
  * @param string Feedback type - 'Y' or 'N' only
  */
 static function SendFeedback($module, $id, $feedback)
 {
     global $APPLICATION, $DB;
     if (empty($module)) {
         return;
     }
     if (empty($id) || intval($id) < 0) {
         return;
     }
     if (empty($feedback) || $feedback != 'Y' && $feedback != 'N') {
         return;
     }
     $request_id = $DB->Query('SELECT ct_request_id FROM cleantalk_cids WHERE module=\'' . $module . '\' AND cid=' . $id)->Fetch();
     if ($request_id !== FALSE) {
         $DB->Query('DELETE FROM cleantalk_cids WHERE module=\'' . $module . '\' AND cid=' . $id);
         require_once dirname(__FILE__) . '/classes/general/cleantalk.class.php';
         $ct_key = COption::GetOptionString('cleantalk.antispam', 'key', '0');
         $ct_ws = self::GetWorkServer();
         $ct = new Cleantalk();
         $ct->work_url = $ct_ws['work_url'];
         $ct->server_url = $ct_ws['server_url'];
         $ct->server_ttl = $ct_ws['server_ttl'];
         $ct->server_changed = $ct_ws['server_changed'];
         $ct_request = new CleantalkRequest();
         $ct_request->auth_key = $ct_key;
         $ct_request->agent = 'bitrix-370';
         $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
         $ct_request->feedback = $request_id . ':' . ($feedback == 'Y' ? '1' : '0');
         $ct->sendFeedback($ct_request);
     }
 }
コード例 #7
0
function ct_user_register_ajaxlogin($user_id)
{
    require_once CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php';
    global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options, $ct_data;
    $ct_options = ct_get_options();
    $ct_data = ct_get_data();
    if (class_exists('AjaxLogin') && isset($_POST['action']) && $_POST['action'] == 'register_submit') {
        $checkjs = js_test('ct_checkjs', $_COOKIE, true);
        $submit_time = submit_time_test();
        $sender_info = get_sender_info();
        $sender_info['post_checkjs_passed'] = $checkjs;
        if ($checkjs === null) {
            $checkjs = js_test('ct_checkjs', $_COOKIE, true);
            $sender_info['cookie_checkjs_passed'] = $checkjs;
        }
        $sender_info = json_encode($sender_info);
        if ($sender_info === false) {
            $sender_info = '';
        }
        require_once 'cleantalk.class.php';
        $config = get_option('cleantalk_server');
        $ct = new Cleantalk();
        $ct->work_url = $config['ct_work_url'];
        $ct->server_url = $ct_options['server'];
        $ct->server_ttl = $config['ct_server_ttl'];
        $ct->server_changed = $config['ct_server_changed'];
        $ct->ssl_on = $ct_options['ssl_on'];
        $ct_request = new CleantalkRequest();
        $ct_request->auth_key = $ct_options['apikey'];
        $ct_request->sender_email = sanitize_email($_POST['email']);
        $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
        $ct_request->sender_nickname = sanitize_email($_POST['login']);
        $ct_request->agent = $ct_agent_version;
        $ct_request->sender_info = $sender_info;
        $ct_request->js_on = $checkjs;
        $ct_request->submit_time = $submit_time;
        $ct_result = $ct->isAllowUser($ct_request);
        if ($ct->server_change) {
            update_option('cleantalk_server', array('ct_work_url' => $ct->work_url, 'ct_server_ttl' => $ct->server_ttl, 'ct_server_changed' => time()));
        }
        if ($ct_result->allow === 0) {
            wp_delete_user($user_id);
        }
    }
    return $user_id;
}
コード例 #8
0
/**
 * Calling by hook integrate_load_theme
 */
function cleantalk_load()
{
    global $context, $user_info, $modSettings;
    if (isset($context['template_layers']) && is_array($context['template_layers']) && in_array('body', $context['template_layers']) && ($user_info['is_guest'] || $user_info['posts'] == 0) && !cleantalk_is_valid_js()) {
        $context['html_headers'] .= cleantalk_print_js_input();
    }
    if (isset($context['template_layers']) && $context['template_layers'] === array('html', 'body') && array_key_exists('cleantalk_tell_others', $modSettings) && $modSettings['cleantalk_tell_others']) {
        // add "tell others" templates
        $context['template_layers'][] = 'cleantalk';
    }
    if (isset($_POST['cleantalk_api_key'])) {
        $ct = new Cleantalk();
        $ct->server_url = CT_SERVER_URL;
        $ct_request = new CleantalkRequest();
        $ct_request->auth_key = cleantalk_get_api_key();
        $ct_request->response_lang = 'en';
        // SMF use any charset and language
        $ct_request->agent = CT_AGENT_VERSION;
        $ct_request->sender_email = '*****@*****.**';
        $ip = isset($user_info['ip']) ? $user_info['ip'] : $_SERVER['REMOTE_ADDR'];
        $ct_request->sender_ip = $ct->ct_session_ip($ip);
        $ct_request->sender_nickname = 'CleanTalk';
        $ct_request->message = 'This message is a test to check the connection to the CleanTalk servers.';
        $ct_request->submit_time = 10;
        $ct_request->js_on = 1;
        $ct_result = $ct->isAllowMessage($ct_request);
    }
}
コード例 #9
0
/**
 * Inner function - Common part of request sending
 * @param array Array of parameters:
 *  'message' - string
 *  'example' - string
 *  'checkjs' - int
 *  'sender_email' - string
 *  'sender_nickname' - string
 *  'sender_info' - array
 *  'post_info' - string
 * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
 */
function ct_base_call($params = array())
{
    global $wpdb, $ct_agent_version, $ct_formtime_label, $ct_options, $ct_data;
    $ct_options = ct_get_options();
    $ct_data = ct_get_data();
    require_once 'cleantalk.class.php';
    $submit_time = submit_time_test();
    $sender_info = get_sender_info();
    if (array_key_exists('sender_info', $params)) {
        $sender_info = array_merge($sender_info, (array) $params['sender_info']);
    }
    $sender_info = json_encode($sender_info);
    if ($sender_info === false) {
        $sender_info = '';
    }
    $config = get_option('cleantalk_server');
    $ct = new Cleantalk();
    $ct->work_url = $config['ct_work_url'];
    $ct->server_url = $ct_options['server'];
    $ct->server_ttl = $config['ct_server_ttl'];
    $ct->server_changed = $config['ct_server_changed'];
    $ct->ssl_on = $ct_options['ssl_on'];
    $ct_request = new CleantalkRequest();
    $ct_request->auth_key = $ct_options['apikey'];
    $ct_request->message = $params['message'];
    $ct_request->example = $params['example'];
    $ct_request->sender_email = $params['sender_email'];
    $ct_request->sender_nickname = $params['sender_nickname'];
    $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
    $ct_request->agent = $ct_agent_version;
    $ct_request->sender_info = $sender_info;
    $ct_request->js_on = $params['checkjs'];
    $ct_request->submit_time = $submit_time;
    $ct_request->post_info = $params['post_info'];
    if (isset($ct_data['last_error_no'])) {
        $ct_request->last_error_no = $ct_data['last_error_no'];
        $ct_request->last_error_time = $ct_data['last_error_time'];
        $ct_request->last_error_text = $ct_data['last_error_text'];
    }
    $ct_result = $ct->isAllowMessage($ct_request);
    if ($ct->server_change) {
        update_option('cleantalk_server', array('ct_work_url' => $ct->work_url, 'ct_server_ttl' => $ct->server_ttl, 'ct_server_changed' => time()));
    }
    if (@intval($ct_result->errno) != 0) {
        if ($params['checkjs'] != 1) {
            $ct_result->allow = 0;
            $ct_result->spam = 1;
            $ct_result->comment = __('Forbidden. Please, enable Javascript.', 'cleantalk');
        } else {
            $ct_result->allow = 1;
            $ct_result->comment = __('Allow', 'cleantalk');
        }
    }
    // Restart submit form counter for failed requests
    if ($ct_result->allow == 0) {
        ct_init_session();
        $_SESSION[$ct_formtime_label] = time();
        ct_add_event('no');
    } else {
        ct_add_event('yes');
        /*if($is_logged_in)
         	{
         		$user_cnt++;
         		update_user_meta( $user_id, 'cleantalk_messages_number', $user_cnt);
         	}*/
    }
    return array('ct' => $ct, 'ct_result' => $ct_result);
}
コード例 #10
0
ファイル: comment.php プロジェクト: CleanTalk/ips4-antispam
 public static function create($item, $comment, $first = FALSE, $guestName = NULL, $incrementPostCount = NULL, $member = NULL, \IPS\DateTime $time = NULL)
 {
     $topic = $item;
     if ($member === NULL) {
         $member = \IPS\Member::loggedIn();
     }
     if (isset($_POST['topic_title'])) {
         $comment = $_POST['topic_title'] . "\n" . $comment;
     }
     $access_key = \IPS\Settings::i()->access_key;
     if (isset($member) && !$member->isAdmin() && $member->member_posts <= 10 && \IPS\Settings::i()->moderate_new == 1) {
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/cleantalk.class.php";
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/JSON.php";
         session_name('cleantalksession');
         if (!isset($_SESSION)) {
             session_start();
         }
         if (array_key_exists('formtime', $_SESSION)) {
             $submit_time = time() - (int) $_SESSION['formtime'];
         } else {
             $submit_time = NULL;
         }
         $_SESSION['formtime'] = time();
         $post_info = '';
         $lang = \IPS\Lang::getEnabledLanguages();
         $locale = $lang[\IPS\Lang::defaultLanguage()]->short;
         if (function_exists('json_encode')) {
             $arr = array('cms_lang' => $locale, 'REFFERRER' => $_SERVER['HTTP_REFERER'], 'USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
             $post_info = json_encode($arr);
         }
         if ($post_info === FALSE) {
             $post_info = '';
         }
         $ct_url = 'http://moderate.cleantalk.ru';
         $config_work_url = $ct_url;
         $config_ttl = 43200;
         $config_changed = 1349162987;
         $config_key = $access_key;
         $ct = new \Cleantalk();
         $ct->work_url = $config_work_url;
         $ct->server_url = $ct_url;
         $ct->server_ttl = $config_ttl;
         $ct->server_changed = $config_changed;
         $sender_email = filter_var($member->email, FILTER_SANITIZE_EMAIL);
         $sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
         $ct_request = new \CleantalkRequest();
         $ct_request->auth_key = $config_key;
         if (isset($_POST['guest_name'])) {
             $ct_request->sender_nickname = $_POST['guest_name'];
         } else {
             $ct_request->sender_nickname = $member->name;
         }
         $ct_request->sender_ip = $sender_ip;
         $ct_request->sender_email = $sender_email;
         $ct_request->sender_info = $post_info;
         $ct_request->agent = 'ipboard4-18';
         $js_keys = array();
         for ($i = -5; $i <= 1; $i++) {
             $js_keys[] = md5(\IPS\Settings::i()->access_key . '+' . \IPS\Settings::i()->email_in . date("Ymd", time() + 86400 * $i));
         }
         $ct_request->js_on = in_array($_COOKIE['ct_checkjs'], $js_keys) ? 1 : 0;
         $ct_request->submit_time = $submit_time;
         $ct_request->message = $comment;
         $ct_result = $ct->isAllowMessage($ct_request);
         if (isset($ct_result->errno) && $ct_result->errno > 0) {
             //sendErrorMessage("CleanTalk has some problems, errno is ".$ct_result->errno.", errstr is '".$ct_result->errstr."'")
         }
         if ($ct_result->allow == 1) {
             // Not spammer.
             //call_user_func_array( 'parent::save', func_get_args() );
             return call_user_func_array('parent::create', func_get_args());
         } else {
             if (isset($_POST['topic_title'])) {
                 $topic->delete();
             }
             if (\IPS\Request::i()->isAjax()) {
                 $result = array("type" => "error", "message" => $ct_result->comment);
                 $result = json_encode($result);
                 \IPS\Output::i()->sendOutput($result, 200, "application/json");
             } else {
                 \IPS\Output::i()->sidebar['enabled'] = FALSE;
                 \IPS\Output::i()->sendOutput(\IPS\Theme::i()->getTemplate('global', 'core')->globalTemplate("Forbidden", \IPS\Theme::i()->getTemplate('global', 'core')->error("Forbidden", $ct_result->comment, 1, ""), array('app' => \IPS\Dispatcher::i()->application ? \IPS\Dispatcher::i()->application->directory : NULL, 'module' => \IPS\Dispatcher::i()->module ? \IPS\Dispatcher::i()->module->key : NULL, 'controller' => \IPS\Dispatcher::i()->controller)), 200, 'text/html', array(), FALSE, FALSE);
             }
             die;
             return call_user_func_array('parent::create', func_get_args());
         }
     }
     return call_user_func_array('parent::create', func_get_args());
 }
コード例 #11
0
ファイル: member.php プロジェクト: CleanTalk/ips4-antispam
 /**
  * [ActiveRecord] Save Changed Columns
  *
  * @return	void
  * @note	We have to be careful when upgrading in case we are coming from an older version
  */
 public function save()
 {
     $new = $this->_new;
     $enabled = \IPS\Settings::i()->plugin_enabled;
     $access_key = \IPS\Settings::i()->access_key;
     if ($enabled == 1 && $new) {
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/cleantalk.class.php";
         require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/JSON.php";
         session_name('cleantalksession');
         if (!isset($_SESSION)) {
             session_start();
         }
         if (array_key_exists('formtime', $_SESSION)) {
             $submit_time = time() - (int) $_SESSION['formtime'];
         } else {
             $submit_time = NULL;
         }
         $_SESSION['formtime'] = time();
         $post_info = '';
         $lang = \IPS\Lang::getEnabledLanguages();
         $locale = $lang[\IPS\Lang::defaultLanguage()]->short;
         if (function_exists('json_encode')) {
             $arr = array('cms_lang' => $locale, 'REFFERRER' => $_SERVER['HTTP_REFERER'], 'USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
             $post_info = json_encode($arr);
         }
         if ($post_info === FALSE) {
             $post_info = '';
         }
         $ct_url = 'http://moderate.cleantalk.ru';
         $config_work_url = $ct_url;
         $config_ttl = 43200;
         $config_changed = 1349162987;
         $config_key = $access_key;
         $ct = new \Cleantalk();
         $ct->work_url = $config_work_url;
         $ct->server_url = $ct_url;
         $ct->server_ttl = $config_ttl;
         $ct->server_changed = $config_changed;
         $sender_email = filter_var($_POST['email_address'], FILTER_SANITIZE_EMAIL);
         $sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
         $ct_request = new \CleantalkRequest();
         $ct_request->auth_key = $config_key;
         $ct_request->sender_nickname = $_POST['username'];
         $ct_request->sender_ip = $sender_ip;
         $ct_request->sender_email = $sender_email;
         $ct_request->sender_info = $post_info;
         $ct_request->agent = 'ipboard4-18';
         //$ct_request->js_on = $_COOKIE['ct_checkjs'] == md5(\IPS\Settings::i()->access_key . '+' . \IPS\Settings::i()->email_in) ? 1 : 0;
         $ct_request->js_on = in_array($_COOKIE['ct_checkjs'], self::getCheckJSArray()) ? 1 : 0;
         $ct_request->submit_time = $submit_time;
         $ct_result = $ct->isAllowUser($ct_request);
         if (isset($ct_result->errno) && $ct_result->errno > 0) {
             //sendErrorMessage("CleanTalk has some problems, errno is ".$ct_result->errno.", errstr is '".$ct_result->errstr."'")
         }
         if ($ct_result->allow == 1) {
             // Not spammer.
             call_user_func_array('parent::save', func_get_args());
         } else {
             // Spammer - display message and exit.
             if (\IPS\Request::i()->isAjax()) {
                 $err_str = '<span style="color:#ab1f39;">' . $ct_result->comment . '</span><script>setTimeout("history.back()", 5000);</script>';
                 print $err_str;
             } else {
                 \IPS\Output::i()->sidebar['enabled'] = FALSE;
                 \IPS\Output::i()->sendOutput(\IPS\Theme::i()->getTemplate('global', 'core')->globalTemplate("Forbidden", \IPS\Theme::i()->getTemplate('global', 'core')->error("Forbidden", $ct_result->comment, 1, ""), array('app' => \IPS\Dispatcher::i()->application ? \IPS\Dispatcher::i()->application->directory : NULL, 'module' => \IPS\Dispatcher::i()->module ? \IPS\Dispatcher::i()->module->key : NULL, 'controller' => \IPS\Dispatcher::i()->controller)), 200, 'text/html', array(), FALSE, FALSE);
             }
             die;
         }
     }
     return call_user_func_array('parent::save', func_get_args());
 }