diff --git a/cleantalk.antispam/default_option.php b/cleantalk.antispam/default_option.php index c296e6c..1ef1f12 100644 --- a/cleantalk.antispam/default_option.php +++ b/cleantalk.antispam/default_option.php @@ -21,4 +21,5 @@ 'form_exclusions_fields__regexp' => 0, 'form_exclusions_webform' => '', 'complete_deactivation' => 0, + 'use_custom_server' => '', ); diff --git a/cleantalk.antispam/include.php b/cleantalk.antispam/include.php index 707dbdb..c7b3761 100644 --- a/cleantalk.antispam/include.php +++ b/cleantalk.antispam/include.php @@ -182,7 +182,14 @@ public static function OnPageStartHandler() if( ! $USER->IsAdmin() ){ if ( $bot_detector ) { - Asset::getInstance()->addJs('https://moderate.cleantalk.org/ct-bot-detector-wrapper.js'); + if (class_exists('COption')) { + $use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' ); + if ($use_custom_server !== '') { + Asset::getInstance()->addJs('https://moderate.' . $use_custom_server . '/ct-bot-detector-wrapper.js'); + } else { + Asset::getInstance()->addJs('https://moderate.cleantalk.org/ct-bot-detector-wrapper.js'); + } + } } // Set cookies @@ -1710,6 +1717,19 @@ static function GetCleanTalkResume($module, $id) { */ private static function GetWorkServer() { global $DB; + + if (class_exists('COption')) { + $use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' ); + if ($use_custom_server !== '') { + return array( + 'work_url' => 'http://moderate.' . $use_custom_server, + 'server_url' => 'http://moderate.' . $use_custom_server, + 'server_ttl' => 0, + 'server_changed' => 0, + ); + } + } + $result = $DB->Query('SELECT work_url,server_url,server_ttl,server_changed FROM cleantalk_server LIMIT 1')->Fetch(); if($result !== FALSE) return array( @@ -1750,7 +1770,17 @@ private static function ExceptionList($value = null) */ private static function SetWorkServer($work_url = 'http://moderate.cleantalk.org', $server_url = 'http://moderate.cleantalk.org', $server_ttl = 0, $server_changed = 0) { global $DB; + $result = $DB->Query('SELECT count(*) AS count FROM cleantalk_server')->Fetch(); + + if (class_exists('COption')) { + $use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' ); + if ($use_custom_server !== '') { + $work_url = 'http://moderate.' . $use_custom_server; + $server_url = 'http://moderate.' . $use_custom_server; + } + } + if($result['count'] == 0){ $arInsert = $DB->PrepareInsert( 'cleantalk_server', diff --git a/cleantalk.antispam/install/version.php b/cleantalk.antispam/install/version.php index b14aac0..45647b9 100644 --- a/cleantalk.antispam/install/version.php +++ b/cleantalk.antispam/install/version.php @@ -1,5 +1,5 @@ "3.13.0", - "VERSION_DATE" => "2024-10-14 10:00:00", + "VERSION" => "3.14.0", + "VERSION_DATE" => "2025-06-06 10:00:00", ); diff --git a/cleantalk.antispam/lang/en/options.php b/cleantalk.antispam/lang/en/options.php index 41da049..99a5314 100644 --- a/cleantalk.antispam/lang/en/options.php +++ b/cleantalk.antispam/lang/en/options.php @@ -54,4 +54,6 @@ $MESS['CLEANTALK_WRONG_DEFAULT_SETTINGS'] = 'Can not load default options. Module name is incorrect.'; $MESS['CLEANTALK_WRONG_CURRENT_SETTINGS'] = 'Can not load current options.'; $MESS['CLEANTALK_RESET_OPTIONS_FAILED'] = 'Can not reset options to defaults.'; -$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'If you want to use specific Access Key for this website paste it here. Otherwise, leave it empty.'; \ No newline at end of file +$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'If you want to use specific Access Key for this website paste it here. Otherwise, leave it empty.'; +$MESS['CLEANTALK_USE_CUSTOM_SERVER'] = 'Use custom server'; +$MESS['CLEANTALK_USE_CUSTOM_SERVER_DESCRIPTION'] = 'Use custom server for spam checking. You can enter cleantalk.ru and the plugin will use only ru servers. This option is for critical situations when it is impossible to choose the server automatically.'; \ No newline at end of file diff --git a/cleantalk.antispam/lang/ru/options.php b/cleantalk.antispam/lang/ru/options.php index 30761d1..47adc3e 100644 --- a/cleantalk.antispam/lang/ru/options.php +++ b/cleantalk.antispam/lang/ru/options.php @@ -54,4 +54,7 @@ $MESS['CLEANTALK_WRONG_DEFAULT_SETTINGS'] = 'Невоможно загрузить опции по умолчанию. Ошибка в имени модуля.'; $MESS['CLEANTALK_WRONG_CURRENT_SETTINGS'] = 'Невоможно загрузить текущие опции.'; $MESS['CLEANTALK_RESET_OPTIONS_FAILED'] = 'Невоможно сбросить опции.'; -$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'Если вы хотите использовать отдельный ключ доступа для этого сайта, вставьте его здесь. В противном случае оставьте поле пустым.'; \ No newline at end of file +$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'Если вы хотите использовать отдельный ключ доступа для этого сайта, вставьте его здесь. В противном случае оставьте поле пустым.'; +$MESS['CLEANTALK_USE_CUSTOM_SERVER'] = 'Использовать кастомный сервер'; +$MESS['CLEANTALK_USE_CUSTOM_SERVER_DESCRIPTION'] = 'Использовать кастомный сервер для проверки спама. Можете ввести cleantalk.ru и плагин будет использовать только ru сервера. Опция для критических ситуаций, когда невозможен выбор сервера автоматически.'; +$MESS['CLEANTALK_SERVER_NOT_AVAILABLE'] = 'Указанные сервера не доступны, обратитесь в тех поддержку https://cleantalk.org/my/support/open'; \ No newline at end of file diff --git a/cleantalk.antispam/lib/Cleantalk/Common/API.php b/cleantalk.antispam/lib/Cleantalk/Common/API.php index bb6d8a8..62a2177 100644 --- a/cleantalk.antispam/lib/Cleantalk/Common/API.php +++ b/cleantalk.antispam/lib/Cleantalk/Common/API.php @@ -16,7 +16,7 @@ class API { /* Default params */ - const URL = 'https://api.cleantalk.org'; + public static $URL = 'https://api.cleantalk.org'; const AGENT = 'ct-php-lib-1.0'; /** @@ -205,7 +205,7 @@ public static function method__spam_check_cms($api_key, $data, $date = null, $do if($date) $request['date'] = $date; - $result = static::send_request($request, self::URL, 20); + $result = static::send_request($request, self::$URL, 20); $result = $do_check ? static::check_response($result, 'spam_check_cms') : $result; return $result; @@ -234,7 +234,7 @@ public static function method__spam_check($api_key, $data, $date = null, $do_che $request['date'] = $date; } - $result = static::send_request($request, self::URL, 10); + $result = static::send_request($request, self::$URL, 10); $result = $do_check ? static::check_response($result, 'spam_check') : $result; return $result; @@ -631,8 +631,13 @@ public static function method__request_checksums($api_key, $plugins_and_themes_t * * @return array|bool */ - public static function send_request($data, $url = self::URL, $timeout = 10, $ssl = false, $ssl_path = '') + public static function send_request($data, $url = null, $timeout = 10, $ssl = false, $ssl_path = '') { + // Set default URL if not provided + if ($url === null) { + $url = self::$URL; + } + // Possibility to switch agent vaersion $data['agent'] = !empty($data['agent']) ? $data['agent'] @@ -650,6 +655,14 @@ public static function send_request($data, $url = self::URL, $timeout = 10, $ssl } // Possibility to switch API url + if ($url == self::$URL) { + if (class_exists('COption')) { + $use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' ); + if ($use_custom_server !== '') { + $url = 'https://api.' . $use_custom_server; + } + } + } $url = defined('CLEANTALK_API_URL') ? CLEANTALK_API_URL : $url; if(function_exists('curl_init')){ diff --git a/cleantalk.antispam/options.php b/cleantalk.antispam/options.php index cfd43ec..73dd1d0 100644 --- a/cleantalk.antispam/options.php +++ b/cleantalk.antispam/options.php @@ -201,6 +201,33 @@ } else { CAgent::RemoveModuleAgents("cleantalk.antispam"); } + + // Custom server + if (isset($_POST['use_custom_server']) && $_POST['use_custom_server'] == '' && COption::GetOptionString($sModuleId, "use_custom_server") !== '') { + Option::set( $sModuleId, 'use_custom_server', '' ); + } + if (isset($_POST['use_custom_server']) && $_POST['use_custom_server'] !== '') { + // Remove path, query, fragment + $domain = preg_replace('/[\/\?#].*$/', '', $_POST['use_custom_server']); + // Remove invalid characters (keep letters, numbers, hyphens, dots) + $domain = preg_replace('/[^a-zA-Z0-9\.\-]/', '', $domain); + // Convert to lowercase and trim + $domain = strtolower(trim($domain)); + // use default bitrix http client to make request + $httpClient = new \Bitrix\Main\Web\HttpClient(); + $response = $httpClient->get('https://moderate.' . $domain); + if ($response === false) { + Option::set( $sModuleId, 'use_custom_server', '' ); + CAdminNotify::Add(array( + 'MESSAGE' => GetMessage( 'CLEANTALK_SERVER_NOT_AVAILABLE' ), + 'TAG' => 'server_not_available', + 'MODULE_ID' => 'main', + 'ENABLE_CLOSE' => 'Y')); + } else { + Option::set( $sModuleId, 'use_custom_server', $domain ); + CAdminNotify::DeleteByTag('server_not_available'); + } + } } foreach( $sites as $site ) { @@ -710,6 +737,20 @@ function ctDisableInputLine(ct_input_line){ value="1" /> +