From 1bafffec6a32006f04d12d52f2fdfda4367bf295 Mon Sep 17 00:00:00 2001 From: Roman Safronov Date: Tue, 10 Oct 2017 14:31:51 +0500 Subject: [PATCH 1/5] Added web-forms protection Version: 3.10.2 --- cleantalk.antispam/description.en | 4 +- cleantalk.antispam/description.ru | 4 +- cleantalk.antispam/include.php | 94 +++++++++++++++++++++++++- cleantalk.antispam/install/index.php | 7 ++ cleantalk.antispam/install/version.php | 2 +- cleantalk.antispam/lang/en/options.php | 1 + cleantalk.antispam/lang/ru/options.php | 1 + cleantalk.antispam/options.php | 9 ++- cleantalk.antispam/updater.php | 8 ++- 9 files changed, 118 insertions(+), 12 deletions(-) diff --git a/cleantalk.antispam/description.en b/cleantalk.antispam/description.en index 149a1d6..c91a722 100644 --- a/cleantalk.antispam/description.en +++ b/cleantalk.antispam/description.en @@ -1,3 +1 @@ -- Improved spam protection -- Errors fixes -- Improved JS code \ No newline at end of file +- Added protection for Web-form component \ No newline at end of file diff --git a/cleantalk.antispam/description.ru b/cleantalk.antispam/description.ru index 6dedbf2..6275f32 100644 --- a/cleantalk.antispam/description.ru +++ b/cleantalk.antispam/description.ru @@ -1,3 +1 @@ -- -- -- JS \ No newline at end of file +- - \ No newline at end of file diff --git a/cleantalk.antispam/include.php b/cleantalk.antispam/include.php index fe0b562..c37e687 100644 --- a/cleantalk.antispam/include.php +++ b/cleantalk.antispam/include.php @@ -361,6 +361,79 @@ function OnBeforeOrderAddHandler(&$arFields) } } + /** + * *** Web forms section *** + */ + + /** + * Checking web forms + * @param $WEB_FORM_ID, &$arFields, &$arrVALUES Comment fields to check + * @return null|boolean NULL when success or FALSE when spam detected + */ + + function OnBeforeResultAddHandler($WEB_FORM_ID, &$arFields, &$arrVALUES) + { + global $APPLICATION; + + $ct_status = COption::GetOptionString('cleantalk.antispam', 'status', '0'); + $ct_webform= COption::GetOptionString('cleantalk.antispam', 'web_form', '0'); + + if ($ct_status == 1 && $ct_webform == 1){ + + $sender_email = null; + $message = ''; + + $skip_keys = array( + 'WEB_FORM_ID', + 'RESULT_ID', + 'formresult', + 'sessid', + 'captcha_', + 'web_form_submit' + ); + + foreach ($arrVALUES as $key => $value){ + + // Skipping keys + foreach($skip_keys as $skip){ + if(strpos($key, $skip) !== false) + continue 2; + } + + if ($sender_email === null && preg_match("/^\S+@\S+\.\S+$/", $value)) + $sender_email = $value; + else + $message.="$value\n"; + } + + $arUser = array(); + $arUser["type"] = "webform"; + $arUser["sender_email"] = $sender_email; + $arUser["sender_nickname"] = ''; + $arUser["sender_ip"] = $_SERVER['REMOTE_ADDR']; + $arUser["message_title"] = ""; + $arUser["message_body"] = $message; + $arUser["example_title"] = ""; + $arUser["example_body"] = ""; + $arUser["example_comments"] = ""; + + $aResult = CleantalkAntispam::CheckAllBefore($arUser,FALSE); + + if(isset($aResult) && is_array($aResult)){ + + if($aResult['errno'] == 0){ + + if($aResult['allow'] == 1){ + return; //Not spammer - just return; + }else{ + $APPLICATION->ThrowException($aResult['ct_result_comment']); + return false; + } + } + } + } + } + /** * *** TreeLike comments section *** */ @@ -959,7 +1032,7 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) { } $type = $arEntity['type']; - if($type != 'comment' && $type != 'register' && $type != 'order' && $type != 'feedback_general_contact_form' && $type != 'private_message'){ + if($type != 'comment' && $type != 'webform' &&$type != 'register' && $type != 'order' && $type != 'feedback_general_contact_form' && $type != 'private_message'){ CEventLog::Add(array( 'SEVERITY' => 'SECURITY', 'AUDIT_TYPE_ID' => 'CLEANTALK_E_INTERNAL', @@ -982,6 +1055,7 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) { $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); @@ -1034,7 +1108,7 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) { $ct_request->sender_email = isset($arEntity['sender_email']) ? $arEntity['sender_email'] : ''; $ct_request->sender_nickname = isset($arEntity['sender_nickname']) ? $arEntity['sender_nickname'] : ''; $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']); - $ct_request->agent = 'bitrix-3101'; + $ct_request->agent = 'bitrix-3102'; $ct_request->response_lang = 'ru'; $ct_request->js_on = $checkjs; $ct_request->sender_info = $sender_info; @@ -1091,6 +1165,20 @@ static function CheckAllBefore(&$arEntity, $bSendEmail = FALSE) { $timelabels_key = 'mail_error_comment'; $ct_request->submit_time = $ct_submit_time; + $ct_request->message .= isset($arEntity['message_body']) ? $arEntity['message_body'] : ''; + + $ct_result = $ct->isAllowMessage($ct_request); + break; + + case 'webform': + + $a_post_info['comment_type'] = 'webform'; + $post_info = json_encode($a_post_info); + $ct_request->post_info = $post_info; + + $timelabels_key = 'mail_error_comment'; + $ct_request->submit_time = $ct_submit_time; + $ct_request->message .= isset($arEntity['message_body']) ? $arEntity['message_body'] : ''; $ct_result = $ct->isAllowMessage($ct_request); @@ -1302,7 +1390,7 @@ static function SendFeedback($module, $id, $feedback) { $ct_request = new CleantalkRequest(); $ct_request->auth_key = $ct_key; - $ct_request->agent = 'bitrix-3101'; + $ct_request->agent = 'bitrix-3102'; $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']); $ct_request->feedback = $request_id . ':' . ($feedback == 'Y' ? '1' : '0'); diff --git a/cleantalk.antispam/install/index.php b/cleantalk.antispam/install/index.php index b24596c..c1b5fa6 100644 --- a/cleantalk.antispam/install/index.php +++ b/cleantalk.antispam/install/index.php @@ -134,6 +134,10 @@ function DoInstall() { { RegisterModuleDependences('sale', 'OnBeforeOrderAdd', 'cleantalk.antispam', 'CleantalkAntispam', 'OnBeforeOrderAddHandler'); } + if (IsModuleInstalled('form')) + { + RegisterModuleDependences('form', 'OnBeforeResultAdd', 'cleantalk.antispam', 'CleantalkAntispam', 'OnBeforeResultAddHandler'); + } } //Adding agents @@ -186,6 +190,9 @@ function DoUninstall() { UnRegisterModuleDependences('main', 'OnBeforeUserRegister', 'cleantalk.antispam', 'CleantalkAntispam', 'OnBeforeUserRegisterHandler'); UnRegisterModuleDependences('main', 'OnEndBufferContent', 'cleantalk.antispam', 'CleantalkAntispam', 'OnEndBufferContentHandler'); UnRegisterModuleDependences('main', 'OnEventLogGetAuditTypes', 'cleantalk.antispam', 'CleantalkAntispam', 'OnEventLogGetAuditTypesHandler'); + if (IsModuleInstalled('form')){ + UnRegisterModuleDependences('form', 'OnBeforeResultAdd', 'cleantalk.antispam', 'CleantalkAntispam', 'OnBeforeResultAddHandler'); + } UnRegisterModule('cleantalk.antispam'); $this->UnInstallDB(); $this->UnInstallFiles(); diff --git a/cleantalk.antispam/install/version.php b/cleantalk.antispam/install/version.php index 7477687..98c2044 100644 --- a/cleantalk.antispam/install/version.php +++ b/cleantalk.antispam/install/version.php @@ -1,5 +1,5 @@ "3.10.1", + "VERSION" => "3.10.2", "VERSION_DATE" => "2017-09-12 24:00:00" ); diff --git a/cleantalk.antispam/lang/en/options.php b/cleantalk.antispam/lang/en/options.php index c083987..e980209 100644 --- a/cleantalk.antispam/lang/en/options.php +++ b/cleantalk.antispam/lang/en/options.php @@ -8,6 +8,7 @@ $MESS['CLEANTALK_LABEL_COMMENT_TREELIKE'] = 'Treelike comments forms protection'; $MESS['CLEANTALK_LABEL_SEND_EXAMPLE'] = 'Send texts for off-top analysis'; $MESS['CLEANTALK_LABEL_ORDER'] = 'Order form protection'; +$MESS['CLEANTALK_LABEL_WEB_FORMS'] = 'Web forms protection'; $MESS['CLEANTALK_BUTTON_SAVE'] = 'Save'; $MESS['CLEANTALK_GET_AUTO_KEY'] = 'Get access key automatically'; $MESS['CLEANTALK_GET_MANUAL_KEY'] = 'Get access key manually'; diff --git a/cleantalk.antispam/lang/ru/options.php b/cleantalk.antispam/lang/ru/options.php index a28cc6c..e2b1d5e 100644 --- a/cleantalk.antispam/lang/ru/options.php +++ b/cleantalk.antispam/lang/ru/options.php @@ -8,6 +8,7 @@ $MESS['CLEANTALK_LABEL_COMMENT_TREELIKE'] = ' '; $MESS['CLEANTALK_LABEL_SEND_EXAMPLE'] = ' - '; $MESS['CLEANTALK_LABEL_ORDER'] = ' '; +$MESS['CLEANTALK_LABEL_WEB_FORMS'] = ' -'; $MESS['CLEANTALK_BUTTON_SAVE'] = ''; $MESS['CLEANTALK_GET_AUTO_KEY'] = ' '; $MESS['CLEANTALK_GET_MANUAL_KEY'] = ' '; diff --git a/cleantalk.antispam/options.php b/cleantalk.antispam/options.php index cb0704c..b5c6b8e 100644 --- a/cleantalk.antispam/options.php +++ b/cleantalk.antispam/options.php @@ -40,7 +40,7 @@ } // Send empty feedback for version comparison in Dashboard - $result = CleantalkHelper::sendEmptyFeedback($new_key, 'bitrix-3101'); + $result = CleantalkHelper::sendEmptyFeedback($new_key, 'bitrix-3102'); /** * Set settings when submit @@ -59,6 +59,7 @@ COption::SetOptionString( $sModuleId, 'form_comment_treelike', $_POST['form_comment_treelike'] == '1' ? '1' : '0' ); COption::SetOptionString( $sModuleId, 'form_send_example', $_POST['form_send_example'] == '1' ? '1' : '0' ); COption::SetOptionString( $sModuleId, 'form_order', $_POST['form_order'] == '1' ? '1' : '0' ); + COption::SetOptionString( $sModuleId, 'web_form', $_POST['web_form'] == '1' ? '1' : '0' ); COption::SetOptionString( $sModuleId, 'is_paid', $_POST['is_paid'] == '1' ? '1' : '0' ); COption::SetOptionString( $sModuleId, 'last_checked', $_POST['last_checked'] == '1' ? '1' : '0' ); COption::SetOptionString( $sModuleId, 'form_global_check', $_POST['form_global_check'] == '1' ? '1' : '0' ); @@ -173,6 +174,12 @@ function ctDdisableInputLine(ct_input_line){ checked="checked" value="1" /> + + +