Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cleantalk.antispam/default_option.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
'form_exclusions_fields__regexp' => 0,
'form_exclusions_webform' => '',
'complete_deactivation' => 0,
'use_custom_server' => '',
);
32 changes: 31 additions & 1 deletion cleantalk.antispam/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions cleantalk.antispam/install/version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$arModuleVersion = array(
"VERSION" => "3.13.0",
"VERSION_DATE" => "2024-10-14 10:00:00",
"VERSION" => "3.14.0",
"VERSION_DATE" => "2025-06-06 10:00:00",
);
4 changes: 3 additions & 1 deletion cleantalk.antispam/lang/en/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
$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.';
5 changes: 4 additions & 1 deletion cleantalk.antispam/lang/ru/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@
$MESS['CLEANTALK_WRONG_DEFAULT_SETTINGS'] = 'Невоможно загрузить опции по умолчанию. Ошибка в имени модуля.';
$MESS['CLEANTALK_WRONG_CURRENT_SETTINGS'] = 'Невоможно загрузить текущие опции.';
$MESS['CLEANTALK_RESET_OPTIONS_FAILED'] = 'Невоможно сбросить опции.';
$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'Если вы хотите использовать отдельный ключ доступа для этого сайта, вставьте его здесь. В противном случае оставьте поле пустым.';
$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';
21 changes: 17 additions & 4 deletions cleantalk.antispam/lib/Cleantalk/Common/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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']
Expand All @@ -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')){
Expand Down
41 changes: 41 additions & 0 deletions cleantalk.antispam/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -710,6 +737,20 @@ function ctDisableInputLine(ct_input_line){
value="1" />
</td>
</tr>
<tr>
<td width="50%" valign="top">
<label for="use_custom_server"><?php echo GetMessage( 'CLEANTALK_USE_CUSTOM_SERVER' );?>:</td>
<td valign="top">
<input
type="text"
name="use_custom_server"
id="use_custom_server"
value="<?php echo $current_options['use_custom_server']; ?>" />
<div style="padding: 10px 0 10px 0">
<?php echo GetMessage( 'CLEANTALK_USE_CUSTOM_SERVER_DESCRIPTION' ); ?>
</div>
</td>
</tr>
<!--HIDDEN FIELDSET-->
<input type="hidden" name="is_paid" value="<?php echo $current_options['is_paid'] ?>" />
<input type="hidden" name="last_checked" value="0" />
Expand Down