diff --git a/README.md b/README.md index 776032e..4f0dc7e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ bitrix-antispam =============== -1C Bitrix anti-spam mod. 3.11.16 +1C Bitrix anti-spam mod. 3.11.17 Information page, http://cleantalk.org/bitrix-antispam-module-bez-captcha diff --git a/cleantalk.antispam/include.php b/cleantalk.antispam/include.php index 19d2146..de13de0 100644 --- a/cleantalk.antispam/include.php +++ b/cleantalk.antispam/include.php @@ -22,7 +22,7 @@ use Cleantalk\Common\Firewall\Modules\SFW; if ( ! defined( 'CLEANTALK_USER_AGENT' ) ) - define( 'CLEANTALK_USER_AGENT', 'bitrix-31116' ); + define( 'CLEANTALK_USER_AGENT', 'bitrix-31117' ); define('APBCT_TBL_FIREWALL_DATA', 'cleantalk_sfw'); // Table with firewall data. define('APBCT_TBL_FIREWALL_LOG', 'cleantalk_sfw_logs'); // Table with firewall logs. @@ -138,12 +138,28 @@ private static function apbct_run_cron() * Checking all forms for spam * @return null|boolean NULL when success or FALSE when spam detected */ - public function OnPageStartHandler() + public static function OnPageStartHandler() { global $USER; + $cleantalk_site_exclusions = COption::GetOptionString('cleantalk.antispam', 'site_exclusions', ''); + + if (!empty($cleantalk_site_exclusions)) { + $context = \Bitrix\Main\Application::getInstance()->getContext(); + $siteId = $context->getSite(); + $cleantalk_site_exclusions = explode(',', $cleantalk_site_exclusions); + if (in_array($siteId, $cleantalk_site_exclusions)) { + return; + } + } // Set exclusions to the class $cleantalk_url_exclusions = COption::GetOptionString( 'cleantalk.antispam', 'form_exclusions_url', '' ); + if (!empty($cleantalk_url_exclusions)) { + $cleantalk_url_exclusions = explode(',', $cleantalk_url_exclusions); + foreach ($cleantalk_url_exclusions as $key=>$value) + if (strpos($_SERVER['REQUEST_URI'],$value) !== false) + return; + } $cleantalk_fields_exclusions = COption::GetOptionString( 'cleantalk.antispam', 'form_exclusions_fields', '' ); $cleantalk_webforms_checking = COption::GetOptionString( 'cleantalk.antispam', 'form_exclusions_webform', '' ); @@ -1012,7 +1028,7 @@ function OnEventLogGetAuditTypesHandler(){ * * @param string Content to modify */ - function OnEndBufferContentHandler( &$content ) { + public static function OnEndBufferContentHandler( &$content ) { global $USER, $APPLICATION; if( @@ -1033,6 +1049,16 @@ static function FormAddon() { if(!defined("ADMIN_SECTION") && COption::GetOptionInt( 'cleantalk.antispam', 'status', 0 ) == 1 ) { + $cleantalk_site_exclusions = COption::GetOptionString('cleantalk.antispam', 'site_exclusions', ''); + + if (!empty($cleantalk_site_exclusions)) { + $context = \Bitrix\Main\Application::getInstance()->getContext(); + $siteId = $context->getSite(); + $cleantalk_site_exclusions = explode(',', $cleantalk_site_exclusions); + if (in_array($siteId, $cleantalk_site_exclusions)) { + return; + } + } $field_name = 'ct_checkjs'; $ct_check_def = '0'; if (!isset($_COOKIE[$field_name])) setcookie($field_name, $ct_check_def, 0, '/'); @@ -1254,330 +1280,353 @@ function ct_remove_event_handler(elem, event, callback){ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE, $form_errors = null) { global $DB, $USER; - if (class_exists('Bitrix\Main\Context')) { - $isAdminSection = \Bitrix\Main\Context::getCurrent()->getRequest()->isAdminSection(); - } else { - $isAdminSection = (strpos($_SERVER['REQUEST_URI'], 'bitrix/admin') !== false) ? true : false; - } - - if ($USER->IsAdmin() || $isAdminSection) - return; + static $executed_check = true; - if(!is_array($arEntity) || !array_key_exists('type', $arEntity)){ - CEventLog::Add(array( - 'SEVERITY' => 'SECURITY', - 'AUDIT_TYPE_ID' => 'CLEANTALK_E_INTERNAL', - 'MODULE_ID' => 'cleantalk.antispam', - 'DESCRIPTION' => GetMessage('CLEANTALK_E_PARAM') - )); - return; - } + if ($executed_check) { - $type = $arEntity['type']; - if($type != 'comment' && $type != 'webform' && $type != 'register' && $type != 'order' && $type != 'feedback_general_contact_form' && $type != 'private_message' && strpos($type, 'contact_form_bitrix') === false){ - CEventLog::Add(array( - 'SEVERITY' => 'SECURITY', - 'AUDIT_TYPE_ID' => 'CLEANTALK_E_INTERNAL', - 'MODULE_ID' => 'cleantalk.antispam', - 'DESCRIPTION' => GetMessage('CLEANTALK_E_TYPE') - )); - return; - } + $executed_check = false; - $url_exclusion = COption::GetOptionString( 'cleantalk.antispam', 'form_exclusions_url', '' ); - if (!empty($url_exclusion)) - { - $url_exclusion = explode(',', $url_exclusion); - foreach ($url_exclusion as $key=>$value) - if (strpos($_SERVER['REQUEST_URI'],$value) !== false) - return; - } + if (class_exists('Bitrix\Main\Context')) { + $isAdminSection = \Bitrix\Main\Context::getCurrent()->getRequest()->isAdminSection(); + } else { + $isAdminSection = (strpos($_SERVER['REQUEST_URI'], 'bitrix/admin') !== false) ? true : false; + } + + if ($USER->IsAdmin() || $isAdminSection) + return; - $ct_key = COption::GetOptionString('cleantalk.antispam', 'key', ''); - $ct_ws = self::GetWorkServer(); + if(!is_array($arEntity) || !array_key_exists('type', $arEntity)){ + CEventLog::Add(array( + 'SEVERITY' => 'SECURITY', + 'AUDIT_TYPE_ID' => 'CLEANTALK_E_INTERNAL', + 'MODULE_ID' => 'cleantalk.antispam', + 'DESCRIPTION' => GetMessage('CLEANTALK_E_PARAM') + )); + return; + } - if (!isset($_COOKIE['ct_checkjs'])) - $checkjs = NULL; - elseif (in_array($_COOKIE['ct_checkjs'], self::GetCheckJSValues())) - $checkjs = 1; - else - $checkjs = 0; - - $pointer_data = (isset($_COOKIE['ct_pointer_data']) ? json_decode($_COOKIE['ct_pointer_data']) : ''); - $js_timezone = (isset($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : 'none'); - $first_key_timestamp = (isset($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : 0); - $page_set_timestamp = (isset($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : 0); + $type = $arEntity['type']; + if($type != 'comment' && $type != 'webform' && $type != 'register' && $type != 'order' && $type != 'feedback_general_contact_form' && $type != 'private_message' && strpos($type, 'contact_form_bitrix') === false){ + CEventLog::Add(array( + 'SEVERITY' => 'SECURITY', + 'AUDIT_TYPE_ID' => 'CLEANTALK_E_INTERNAL', + 'MODULE_ID' => 'cleantalk.antispam', + 'DESCRIPTION' => GetMessage('CLEANTALK_E_TYPE') + )); + return; + } + if (isset($arEntity['sender_email']) && empty($arEntity['sender_email']) && COption::GetOptionInt('cleantalk.antispam', 'form_global_check_without_email', 0) != 1) { + return; + } + $cleantalk_site_exclusions = COption::GetOptionString('cleantalk.antispam', 'site_exclusions', ''); + + if (!empty($cleantalk_site_exclusions)) { + $context = \Bitrix\Main\Application::getInstance()->getContext(); + $siteId = $context->getSite(); + + $cleantalk_site_exclusions = explode(',', $cleantalk_site_exclusions); + if (in_array($siteId, $cleantalk_site_exclusions)) { + return; + } + } - if(isset($_SERVER['HTTP_USER_AGENT'])) - $user_agent = htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']); - else - $user_agent = NULL; + $url_exclusion = COption::GetOptionString( 'cleantalk.antispam', 'form_exclusions_url', '' ); + if (!empty($url_exclusion)) + { + $url_exclusion = explode(',', $url_exclusion); + foreach ($url_exclusion as $key=>$value) + if (strpos($_SERVER['REQUEST_URI'],$value) !== false) + return; + } - if(isset($_SERVER['HTTP_REFERER'])) - $refferrer = htmlspecialchars((string) $_SERVER['HTTP_REFERER']); - else - $refferrer = NULL; - - $ct_options=Array( - 'access_key' => COption::GetOptionString('cleantalk.antispam', 'key', ''), - 'form_new_user' => COption::GetOptionInt('cleantalk.antispam', 'form_new_user', 0), - 'form_comment_blog' => COption::GetOptionInt('cleantalk.antispam', 'form_comment_blog', 0), - 'form_comment_forum' => COption::GetOptionInt('cleantalk.antispam', 'form_comment_forum', 0), - 'form_forum_private_messages' => COption::GetOptionInt('cleantalk.antispam', 'form_forum_private_messages', 0), - 'form_comment_treelike' => COption::GetOptionInt('cleantalk.antispam', 'form_comment_treelike', 0), - 'form_send_example' => COption::GetOptionInt('cleantalk.antispam', 'form_send_example', 0), - 'form_order' => COption::GetOptionInt('cleantalk.antispam', 'form_order', 0), - 'web_form' => COption::GetOptionInt('cleantalk.antispam', 'web_form', 0), - 'form_global_check' => COption::GetOptionInt('cleantalk.antispam', 'form_global_check', 0), - 'form_global_check_without_email' => COption::GetOptionInt('cleantalk.antispam', 'form_global_check_without_email', 0), - 'form_sfw' => COption::GetOptionInt('cleantalk.antispam', 'form_sfw', 0), - ); + $ct_key = COption::GetOptionString('cleantalk.antispam', 'key', ''); + $ct_ws = self::GetWorkServer(); - $sender_info = array( - 'cms_lang' => 'ru', - 'REFFERRER' => $refferrer, - 'post_url' => $refferrer, - 'USER_AGENT' => $user_agent, - 'js_timezone' => $js_timezone, - 'mouse_cursor_positions' => $pointer_data, - 'key_press_timestamp' => $first_key_timestamp, - 'page_set_timestamp' => $page_set_timestamp, - 'REFFERRER_PREVIOUS' => isset($_COOKIE['ct_prev_referer']) ? $_COOKIE['ct_prev_referer'] : null, - 'cookies_enabled' => self::ct_cookies_test(), - 'ct_options' => json_encode($ct_options), - 'form_validation' => ($form_errors && is_array($form_errors)) ? json_encode(array('validation_notice' => json_encode($form_errors), 'page_url' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) : null, - 'apbct_visible_fields' => !empty($_COOKIE['ct_visible_fields']) ? self::ct_visibile_fields__process($_COOKIE['ct_visible_fields']) : null, - ); - $sender_info = json_encode($sender_info); - - $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']; - - if(defined('BX_UTF')) - $logicalEncoding = "utf-8"; - elseif(defined("SITE_CHARSET") && (strlen(SITE_CHARSET) > 0)) - $logicalEncoding = SITE_CHARSET; - elseif(defined("LANG_CHARSET") && (strlen(LANG_CHARSET) > 0)) - $logicalEncoding = LANG_CHARSET; - elseif(defined("BX_DEFAULT_CHARSET")) - $logicalEncoding = BX_DEFAULT_CHARSET; - else - $logicalEncoding = "windows-1251"; - - $logicalEncoding = strtolower($logicalEncoding); - $ct->data_codepage = $logicalEncoding == 'utf-8' ? NULL : $logicalEncoding; - - $request_params = array( - 'auth_key' => $ct_key, - 'sender_email' => isset($arEntity['sender_email']) ? $arEntity['sender_email'] : '', - 'sender_nickname' => isset($arEntity['sender_nickname']) ? $arEntity['sender_nickname'] : '', - 'sender_ip' => CleantalkHelper::ip__get(array('real'), false), - 'x_forwarded_for' => CleantalkHelper::ip__get(array('x_forwarded_for'), false), - 'x_real_ip' => CleantalkHelper::ip__get(array('x_real_ip'), false), - 'agent' => CLEANTALK_USER_AGENT, - 'response_lang' => 'ru', - 'js_on' => $checkjs, - 'sender_info' => $sender_info, - 'submit_time' => self::ct_cookies_test() == 1 ? time() - (int)$_COOKIE['ct_timestamp'] : null, - ); + if (!isset($_COOKIE['ct_checkjs'])) + $checkjs = NULL; + elseif (in_array($_COOKIE['ct_checkjs'], self::GetCheckJSValues())) + $checkjs = 1; + else + $checkjs = 0; + + $pointer_data = (isset($_COOKIE['ct_pointer_data']) ? json_decode($_COOKIE['ct_pointer_data']) : ''); + $js_timezone = (isset($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : 'none'); + $first_key_timestamp = (isset($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : 0); + $page_set_timestamp = (isset($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : 0); + + if(isset($_SERVER['HTTP_USER_AGENT'])) + $user_agent = htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']); + else + $user_agent = NULL; + + if(isset($_SERVER['HTTP_REFERER'])) + $refferrer = htmlspecialchars((string) $_SERVER['HTTP_REFERER']); + else + $refferrer = NULL; + + $ct_options=Array( + 'access_key' => COption::GetOptionString('cleantalk.antispam', 'key', ''), + 'form_new_user' => COption::GetOptionInt('cleantalk.antispam', 'form_new_user', 0), + 'form_comment_blog' => COption::GetOptionInt('cleantalk.antispam', 'form_comment_blog', 0), + 'form_comment_forum' => COption::GetOptionInt('cleantalk.antispam', 'form_comment_forum', 0), + 'form_forum_private_messages' => COption::GetOptionInt('cleantalk.antispam', 'form_forum_private_messages', 0), + 'form_comment_treelike' => COption::GetOptionInt('cleantalk.antispam', 'form_comment_treelike', 0), + 'form_send_example' => COption::GetOptionInt('cleantalk.antispam', 'form_send_example', 0), + 'form_order' => COption::GetOptionInt('cleantalk.antispam', 'form_order', 0), + 'web_form' => COption::GetOptionInt('cleantalk.antispam', 'web_form', 0), + 'form_global_check' => COption::GetOptionInt('cleantalk.antispam', 'form_global_check', 0), + 'form_global_check_without_email' => COption::GetOptionInt('cleantalk.antispam', 'form_global_check_without_email', 0), + 'form_sfw' => COption::GetOptionInt('cleantalk.antispam', 'form_sfw', 0), + ); - switch ($type) { - case 'comment': - $timelabels_key = 'mail_error_comment'; - if (is_array($arEntity['message'])) { - $arEntity['message'] = json_encode($arEntity['message']); - } - if (is_array($arEntity['example'])) { - $arEntity['example'] = json_encode($arEntity['example']); - } - $request_params['message'] = $arEntity['message']; - $request_params['example'] = $arEntity['example']; - $request_params['post_info']['comment_type'] = 'comment'; + $sender_info = array( + 'cms_lang' => 'ru', + 'REFFERRER' => $refferrer, + 'post_url' => $refferrer, + 'USER_AGENT' => $user_agent, + 'js_timezone' => $js_timezone, + 'mouse_cursor_positions' => $pointer_data, + 'key_press_timestamp' => $first_key_timestamp, + 'page_set_timestamp' => $page_set_timestamp, + 'REFFERRER_PREVIOUS' => isset($_COOKIE['ct_prev_referer']) ? $_COOKIE['ct_prev_referer'] : null, + 'cookies_enabled' => self::ct_cookies_test(), + 'ct_options' => json_encode($ct_options), + 'form_validation' => ($form_errors && is_array($form_errors)) ? json_encode(array('validation_notice' => json_encode($form_errors), 'page_url' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])) : null, + 'apbct_visible_fields' => !empty($_COOKIE['ct_visible_fields']) ? self::ct_visibile_fields__process($_COOKIE['ct_visible_fields']) : null, + ); + $sender_info = json_encode($sender_info); - $ct_request = new CleantalkRequest($request_params); - $ct_result = $ct->isAllowMessage($ct_request); + $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']; - break; - - case 'order': - $timelabels_key = 'mail_error_comment'; - if (is_array($arEntity['message'])) { - $arEntity['message'] = json_encode($arEntity['message']); - } - $request_params['message'] = $arEntity['message']; - $request_params['post_info']['comment_type'] = 'order'; - $ct_request = new CleantalkRequest($request_params); - $ct_result = $ct->isAllowMessage($ct_request); - break; - - case 'feedback_general_contact_form': - - $timelabels_key = 'mail_error_comment'; - if (is_array($arEntity['message'])) { - $arEntity['message'] = json_encode($arEntity['message']); - } - $request_params['message'] = $arEntity['message']; - - $request_params['post_info']['comment_type'] = 'feedback_general_contact_form'; - $ct_request = new CleantalkRequest($request_params); + if(defined('BX_UTF')) + $logicalEncoding = "utf-8"; + elseif(defined("SITE_CHARSET") && (strlen(SITE_CHARSET) > 0)) + $logicalEncoding = SITE_CHARSET; + elseif(defined("LANG_CHARSET") && (strlen(LANG_CHARSET) > 0)) + $logicalEncoding = LANG_CHARSET; + elseif(defined("BX_DEFAULT_CHARSET")) + $logicalEncoding = BX_DEFAULT_CHARSET; + else + $logicalEncoding = "windows-1251"; + + $logicalEncoding = strtolower($logicalEncoding); + $ct->data_codepage = $logicalEncoding == 'utf-8' ? NULL : $logicalEncoding; + + $request_params = array( + 'auth_key' => $ct_key, + 'sender_email' => isset($arEntity['sender_email']) ? $arEntity['sender_email'] : '', + 'sender_nickname' => isset($arEntity['sender_nickname']) ? $arEntity['sender_nickname'] : '', + 'sender_ip' => CleantalkHelper::ip__get(array('real'), false), + 'x_forwarded_for' => CleantalkHelper::ip__get(array('x_forwarded_for'), false), + 'x_real_ip' => CleantalkHelper::ip__get(array('x_real_ip'), false), + 'agent' => CLEANTALK_USER_AGENT, + 'response_lang' => 'ru', + 'js_on' => $checkjs, + 'sender_info' => $sender_info, + 'submit_time' => self::ct_cookies_test() == 1 ? time() - (int)$_COOKIE['ct_timestamp'] : null, + ); - $ct_result = $ct->isAllowMessage($ct_request); + switch ($type) { + case 'comment': + $timelabels_key = 'mail_error_comment'; + if (is_array($arEntity['message'])) { + $arEntity['message'] = json_encode($arEntity['message']); + } + if (is_array($arEntity['example'])) { + $arEntity['example'] = json_encode($arEntity['example']); + } + $request_params['message'] = $arEntity['message']; + $request_params['example'] = $arEntity['example']; + $request_params['post_info']['comment_type'] = 'comment'; - break; + $ct_request = new CleantalkRequest($request_params); + $ct_result = $ct->isAllowMessage($ct_request); - case strpos($type, 'contact_form_bitrix') !== false: - - $timelabels_key = 'mail_error_comment'; - if (is_array($arEntity['message'])) { - $arEntity['message'] = json_encode($arEntity['message']); - } - $request_params['message'] = $arEntity['message']; + break; + + case 'order': + $timelabels_key = 'mail_error_comment'; + if (is_array($arEntity['message'])) { + $arEntity['message'] = json_encode($arEntity['message']); + } + $request_params['message'] = $arEntity['message']; + $request_params['post_info']['comment_type'] = 'order'; + $ct_request = new CleantalkRequest($request_params); + $ct_result = $ct->isAllowMessage($ct_request); + break; + + case 'feedback_general_contact_form': + + $timelabels_key = 'mail_error_comment'; + if (is_array($arEntity['message'])) { + $arEntity['message'] = json_encode($arEntity['message']); + } + $request_params['message'] = $arEntity['message']; + + $request_params['post_info']['comment_type'] = 'feedback_general_contact_form'; + $ct_request = new CleantalkRequest($request_params); - $request_params['post_info']['comment_type'] = $type; - $ct_request = new CleantalkRequest($request_params); - $ct_result = $ct->isAllowMessage($ct_request); - break; - - case 'webform': - - $timelabels_key = 'mail_error_comment'; - if (is_array($arEntity['message'])) { - $arEntity['message'] = json_encode($arEntity['message']); - } - $request_params['message'] = $arEntity['message']; + $ct_result = $ct->isAllowMessage($ct_request); - $request_params['post_info']['comment_type'] = 'webform'; - $ct_request = new CleantalkRequest($request_params); - $ct_result = $ct->isAllowMessage($ct_request); - break; - - case 'register': - - $timelabels_key = 'mail_error_reg'; + break; + + case strpos($type, 'contact_form_bitrix') !== false: + + $timelabels_key = 'mail_error_comment'; + if (is_array($arEntity['message'])) { + $arEntity['message'] = json_encode($arEntity['message']); + } + $request_params['message'] = $arEntity['message']; - $request_params['tz'] = isset($arEntity['user_timezone']) ? $arEntity['user_timezone'] : NULL; - $ct_request = new CleantalkRequest($request_params); - $ct_result = $ct->isAllowUser($ct_request); - break; + $request_params['post_info']['comment_type'] = $type; + $ct_request = new CleantalkRequest($request_params); + $ct_result = $ct->isAllowMessage($ct_request); + break; + + case 'webform': + + $timelabels_key = 'mail_error_comment'; + if (is_array($arEntity['message'])) { + $arEntity['message'] = json_encode($arEntity['message']); + } + $request_params['message'] = $arEntity['message']; + + $request_params['post_info']['comment_type'] = 'webform'; + $ct_request = new CleantalkRequest($request_params); + $ct_result = $ct->isAllowMessage($ct_request); + break; + + case 'register': - case 'private_message': + $timelabels_key = 'mail_error_reg'; - $timelabels_key = 'mail_error_comment'; - if (is_array($arEntity['message'])) { - $arEntity['message'] = json_encode($arEntity['message']); - } - $request_params['message'] = $arEntity['message']; - $request_params['tz'] = isset($arEntity['user_timezone']) ? $arEntity['user_timezone'] : NULL; - $request_params['post_info']['comment_type'] = 'private_message'; - $ct_request = new CleantalkRequest($request_params); - $ct_result = $ct->isAllowMessage($ct_request); - } + $request_params['tz'] = isset($arEntity['user_timezone']) ? $arEntity['user_timezone'] : NULL; + $ct_request = new CleantalkRequest($request_params); + $ct_result = $ct->isAllowUser($ct_request); + break; + + case 'private_message': - $ret_val = array(); - $ret_val['ct_request_id'] = $ct_result->id; + $timelabels_key = 'mail_error_comment'; + if (is_array($arEntity['message'])) { + $arEntity['message'] = json_encode($arEntity['message']); + } + $request_params['message'] = $arEntity['message']; + $request_params['tz'] = isset($arEntity['user_timezone']) ? $arEntity['user_timezone'] : NULL; + $request_params['post_info']['comment_type'] = 'private_message'; + $ct_request = new CleantalkRequest($request_params); + $ct_result = $ct->isAllowMessage($ct_request); + } - if($ct->server_change) - self::SetWorkServer( - $ct->work_url, $ct->server_url, $ct->server_ttl, time() - ); + $ret_val = array(); + $ret_val['ct_request_id'] = $ct_result->id; - // 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 = 'CleanTalk module error'; - - if(isset($ct_result->inactive) && intval($ct_result->inactive) == 1) - COption::SetOptionInt( 'cleantalk.antispam', 'key_is_ok', 0); - - if(!empty($ct_result->errstr)){ + if($ct->server_change) + self::SetWorkServer( + $ct->work_url, $ct->server_url, $ct->server_ttl, 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 = 'CleanTalk module error'; - if (preg_match('//u', $ct_result->errstr)) - $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu', '', $ct_result->errstr); - else - $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i', '', $ct_result->errstr); + if(isset($ct_result->inactive) && intval($ct_result->inactive) == 1) + COption::SetOptionInt( 'cleantalk.antispam', 'key_is_ok', 0); - }else{ + if(!empty($ct_result->errstr)){ + + if (preg_match('//u', $ct_result->errstr)) + $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu', '', $ct_result->errstr); + else + $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i', '', $ct_result->errstr); + + }else{ + + if (preg_match('//u', $ct_result->comment)) + $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu', '', $ct_result->comment); + else + $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i', '', $ct_result->comment); + + } + + $ret_val['errstr'] = $err_str; - if (preg_match('//u', $ct_result->comment)) - $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu', '', $ct_result->comment); - else - $err_str = preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i', '', $ct_result->comment); + if(!empty($ct_result->errstr)){ + if($request_params['js_on'] == 1){ + $ct_result->allow = 0; + $ct_result->comment = str_replace('*** ', '*** JavaScript disabled. ', $ct_result->comment); + }else + $ct_result->allow = 1; + } - } + CEventLog::Add(array( + 'SEVERITY' => 'SECURITY', + 'AUDIT_TYPE_ID' => 'CLEANTALK_E_SERVER', + 'MODULE_ID' => 'cleantalk.antispam', + 'DESCRIPTION' => $err_str + )); - $ret_val['errstr'] = $err_str; - - if(!empty($ct_result->errstr)){ - if($request_params['js_on'] == 1){ - $ct_result->allow = 0; - $ct_result->comment = str_replace('*** ', '*** JavaScript disabled. ', $ct_result->comment); - }else - $ct_result->allow = 1; - } - - CEventLog::Add(array( - 'SEVERITY' => 'SECURITY', - 'AUDIT_TYPE_ID' => 'CLEANTALK_E_SERVER', - 'MODULE_ID' => 'cleantalk.antispam', - 'DESCRIPTION' => $err_str - )); - - if($bSendEmail){ - $send_flag = FALSE; - $insert_flag = FALSE; - $time = $DB->Query('SELECT ct_value FROM cleantalk_timelabels WHERE ct_key=\''. $timelabels_key .'\'')->Fetch(); - if($time === FALSE){ - $send_flag = TRUE; - $insert_flag = TRUE; - }elseif(time()-900 > $time['ct_value']) { // 15 minutes - $send_flag = TRUE; + if($bSendEmail){ + $send_flag = FALSE; $insert_flag = FALSE; - } - if($send_flag){ - if($insert_flag){ - $arInsert = $DB->PrepareInsert('cleantalk_timelabels', array('ct_key'=>$timelabels_key, 'ct_value' => time())); - $strSql = 'INSERT INTO cleantalk_timelabels('.$arInsert[0].') VALUES ('.$arInsert[1].')'; - }else{ - $strUpdate = $DB->PrepareUpdate('cleantalk_timelabels', array('ct_value' => time())); - $strSql = 'UPDATE cleantalk_timelabels SET '.$strUpdate.' WHERE ct_key = \''. $timelabels_key .'\''; + $time = $DB->Query('SELECT ct_value FROM cleantalk_timelabels WHERE ct_key=\''. $timelabels_key .'\'')->Fetch(); + if($time === FALSE){ + $send_flag = TRUE; + $insert_flag = TRUE; + }elseif(time()-900 > $time['ct_value']) { // 15 minutes + $send_flag = TRUE; + $insert_flag = FALSE; + } + if($send_flag){ + if($insert_flag){ + $arInsert = $DB->PrepareInsert('cleantalk_timelabels', array('ct_key'=>$timelabels_key, 'ct_value' => time())); + $strSql = 'INSERT INTO cleantalk_timelabels('.$arInsert[0].') VALUES ('.$arInsert[1].')'; + }else{ + $strUpdate = $DB->PrepareUpdate('cleantalk_timelabels', array('ct_value' => time())); + $strSql = 'UPDATE cleantalk_timelabels SET '.$strUpdate.' WHERE ct_key = \''. $timelabels_key .'\''; + } + $DB->Query($strSql); + bxmail( + COption::GetOptionString("main", "email_from"), + $err_title, + $err_str + ); } - $DB->Query($strSql); - bxmail( - COption::GetOptionString("main", "email_from"), - $err_title, - $err_str - ); } + // return $ret_val; } - // return $ret_val; - } - $ret_val['errno'] = 0; - if ($ct_result->allow == 1) { - // Not spammer. - $ret_val['allow'] = 1; - $GLOBALS['ct_request_id'] = $ct_result->id; - }else{ - $ret_val['allow'] = 0; - $ret_val['ct_result_comment'] = $ct_result->comment; - // Spammer. - // Check stop_queue flag. - if($type == 'comment' && $ct_result->stop_queue == 0) { - // Spammer and stop_queue == 0 - to manual approvement. - $ret_val['stop_queue'] = 0; + $ret_val['errno'] = 0; + if ($ct_result->allow == 1) { + // Not spammer. + $ret_val['allow'] = 1; $GLOBALS['ct_request_id'] = $ct_result->id; - $GLOBALS['ct_result_comment'] = $ct_result->comment; }else{ - // New user or Spammer and stop_queue == 1 - display message and exit. - $ret_val['stop_queue'] = 1; + $ret_val['allow'] = 0; + $ret_val['ct_result_comment'] = $ct_result->comment; + // Spammer. + // Check stop_queue flag. + if($type == 'comment' && $ct_result->stop_queue == 0) { + // Spammer and stop_queue == 0 - to manual approvement. + $ret_val['stop_queue'] = 0; + $GLOBALS['ct_request_id'] = $ct_result->id; + $GLOBALS['ct_result_comment'] = $ct_result->comment; + }else{ + // New user or Spammer and stop_queue == 1 - display message and exit. + $ret_val['stop_queue'] = 1; + } } + return $ret_val; } - return $ret_val; + + return false; } /** diff --git a/cleantalk.antispam/install/version.php b/cleantalk.antispam/install/version.php index 7a04e55..07482b1 100644 --- a/cleantalk.antispam/install/version.php +++ b/cleantalk.antispam/install/version.php @@ -1,5 +1,5 @@ "3.11.16", + "VERSION" => "3.11.17", "VERSION_DATE" => "2021-05-31 10:00:00" ); diff --git a/cleantalk.antispam/lang/en/options.php b/cleantalk.antispam/lang/en/options.php index 0ae600c..3fc4830 100644 --- a/cleantalk.antispam/lang/en/options.php +++ b/cleantalk.antispam/lang/en/options.php @@ -33,5 +33,7 @@ $MESS['CLEANTALK_EXCLUSIONS_FIELDS_DESCRIPTION'] = 'Exclude fields from spam check. List them separated by commas. Works on forms except for registration and comment forms.'; $MESS['CLEANTALK_EXCLUSIONS_WEBFORM'] = 'Web-form ID exclusion'; $MESS['CLEANTALK_EXCLUSIONS_WEBFORM_DESCRIPTION']= 'Exclude forms (Web-forms module) by provided IDs. List them separated by commas.'; +$MESS['CLEANTALK_EXCLUSIONS_SITES'] = 'Sites exclusions'; +$MESS['CLEANTALK_EXCLUSIONS_SITES_DESCRIPTION'] = 'Exclude sites from spam checking. You can select many'; $MESS['CLEANTALK_TRIAL_NOTIFY']= "Anti-spam by CleanTalk trial period ends, please, upgrade to premium version.."; $MESS['CLEANTALK_RENEW_NOTIFY']= "Please, renew your anti-spam license for Anti-spam by CleanTalk!"; \ No newline at end of file diff --git a/cleantalk.antispam/lang/ru/options.php b/cleantalk.antispam/lang/ru/options.php index 94b33c7..742a778 100644 --- a/cleantalk.antispam/lang/ru/options.php +++ b/cleantalk.antispam/lang/ru/options.php @@ -33,5 +33,7 @@ $MESS['CLEANTALK_EXCLUSIONS_FIELDS_DESCRIPTION'] = 'Исключение полей форм из спам-проверки. Перечислите через запятую. Это работает на формах, кроме форм регистрации и комментирования.'; $MESS['CLEANTALK_EXCLUSIONS_WEBFORM'] = 'Исключение Веб-форм по ID'; $MESS['CLEANTALK_EXCLUSIONS_WEBFORM_DESCRIPTION']= 'Исключение форм (модуль Веб-формы) из спам-проверки по ID. Перечислите через запятую.'; +$MESS['CLEANTALK_EXCLUSIONS_SITES'] = 'Исключение сайтов'; +$MESS['CLEANTALK_EXCLUSIONS_SITES_DESCRIPTION'] = 'Исключение сайтов из спам-проверки. Можно выбрать несколько'; $MESS['CLEANTALK_TRIAL_NOTIFY']= "Заканчивается ознакомительный срок пользования плагина Антиспам без CAPTCHA от CleanTalk. Пожалуйста, подключите тариф в панели управления."; $MESS['CLEANTALK_RENEW_NOTIFY']= "Пожалуйста, обновите вашу анти-спам лицензию для Антиспам без CAPTCHA от CleanTalk!"; \ No newline at end of file diff --git a/cleantalk.antispam/lib/Cleantalk/Common/Cron.php b/cleantalk.antispam/lib/Cleantalk/Common/Cron.php index 0d17dd9..7c26374 100644 --- a/cleantalk.antispam/lib/Cleantalk/Common/Cron.php +++ b/cleantalk.antispam/lib/Cleantalk/Common/Cron.php @@ -97,20 +97,22 @@ public function addTask( $task, $handler, $period, $first_call = null, $params = { // First call time() + period $first_call = ! $first_call ? time() + $period : $first_call; - - if( isset( $this->tasks[ $task ] ) ){ + + $tasks = ! empty( $this->tasks ) ? $this->tasks : $this->getTasks(); + + if( isset( $tasks[ $task ] ) ){ return false; } // Task entry - $this->tasks[$task] = array( + $tasks[$task] = array( 'handler' => $handler, 'next_call' => $first_call, 'period' => $period, 'params' => $params, ); - return $this->saveTasks( $this->tasks ); + return $this->saveTasks( $tasks ); } /** @@ -122,13 +124,15 @@ public function addTask( $task, $handler, $period, $first_call = null, $params = */ public function removeTask( $task ) { - if( ! isset( $this->tasks[ $task ] ) ){ + $tasks = ! empty( $this->tasks ) ? $this->tasks : $this->getTasks(); + + if( ! isset( $tasks[ $task ] ) ){ return false; } - unset( $this->tasks[ $task ] ); + unset( $tasks[ $task ] ); - return $this->saveTasks( $this->tasks ); + return $this->saveTasks( $tasks ); } /** @@ -144,8 +148,18 @@ public function removeTask( $task ) */ public function updateTask( $task, $handler, $period, $first_call = null, $params = array() ) { - $this->removeTask( $task ); - return $this->addTask( $task, $handler, $period, $first_call, $params ); + $tasks = ! empty( $this->tasks ) ? $this->tasks : $this->getTasks(); + if( isset( $tasks[ $task ] ) ){ + // Rewrite the task + $tasks[$task] = array( + 'handler' => $handler, + 'next_call' => is_null( $first_call ) ? time() + $period : $first_call, + 'period' => $period, + 'params' => $params, + ); + return $this->saveTasks( $tasks ); + } + return false; } /** diff --git a/cleantalk.antispam/lib/Cleantalk/Common/Helper.php b/cleantalk.antispam/lib/Cleantalk/Common/Helper.php index a889587..bdabd58 100644 --- a/cleantalk.antispam/lib/Cleantalk/Common/Helper.php +++ b/cleantalk.antispam/lib/Cleantalk/Common/Helper.php @@ -1262,7 +1262,9 @@ public static function http__get_headers(){ if(count($key_parts) > 0 and strlen($server_key) > 2){ foreach($key_parts as $part_index => $part){ $key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part); - $key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]); + if(!empty($key_parts[$part_index][0])) { + $key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]); + } } $server_key = implode('-', $key_parts); } @@ -1320,7 +1322,7 @@ public static function http__request__rc_to_host($rc_action, $request_params, $p if( empty( $result__rc_check_website['error'] ) ){ - if( preg_match( '@^.*?OK$@', $result__rc_check_website) ){ + if( is_string($result__rc_check_website) && preg_match( '@^.*?OK$@', $result__rc_check_website) ){ static::http__request( static::getSiteUrl(), diff --git a/cleantalk.antispam/options.php b/cleantalk.antispam/options.php index cb15547..5aaf2ad 100644 --- a/cleantalk.antispam/options.php +++ b/cleantalk.antispam/options.php @@ -17,10 +17,9 @@ use Cleantalk\Common\Helper as CleantalkHelper; if( $REQUEST_METHOD == 'POST' && $_POST['Update'] == 'Y' ) { - - $old_key = COption::GetOptionString( $sModuleId, 'key', '' ); - - + + $old_key = COption::GetOptionString( $sModuleId, 'key', '' ); + //Getting key automatically if(isset($_POST['getautokey'])){ @@ -100,6 +99,15 @@ COption::SetOptionInt( $sModuleId, 'form_global_check_without_email', $_POST['form_global_check_without_email'] == '1' ? 1 : 0 ); COption::SetOptionInt( $sModuleId, 'form_sfw', $_POST['form_sfw'] == '1' ? 1 : 0 ); + if (isset($_POST['form_exclusions_sites']) && is_array($_POST['form_exclusions_sites'])) { + $exclusion_sites = array(); + foreach ($_POST['form_exclusions_sites'] as $value) { + $exclusion_sites[] = $value; + } + COption::SetOptionString( $sModuleId, 'site_exclusions', implode(',', $exclusion_sites)); + } else { + COption::SetOptionString( $sModuleId, 'site_exclusions', ''); + } COption::SetOptionString( $sModuleId, 'form_exclusions_url', isset($_POST['form_exclusions_url']) ? $_POST['form_exclusions_url'] : '' ); COption::SetOptionString( $sModuleId, 'form_exclusions_fields', isset($_POST['form_exclusions_fields']) ? $_POST['form_exclusions_fields'] : '' ); COption::SetOptionString( $sModuleId, 'form_exclusions_webform', isset($_POST['form_exclusions_webform']) ? $_POST['form_exclusions_webform'] : '' ); @@ -112,14 +120,13 @@ // SFW scheduled actions if($_POST['form_sfw'] == 1) { - CAgent::RemoveModuleAgents( 'cleantalk.antispam' ); - CleantalkAntispam::apbct_sfw_update( $new_key ); - CleantalkAntispam::apbct_sfw_send_logs( $new_key ); + CAgent::RemoveModuleAgents( 'cleantalk.antispam' ); + CleantalkAntispam::apbct_sfw_update( $new_key ); + CleantalkAntispam::apbct_sfw_send_logs( $new_key ); // Remove it if SFW is disabled }else - CAgent::RemoveModuleAgents("cleantalk.antispam"); - + CAgent::RemoveModuleAgents("cleantalk.antispam"); } /** @@ -255,10 +262,25 @@ function ctDdisableInputLine(ct_input_line){ + +