Skip to content

Commit f405385

Browse files
authored
Upd. Settings. Add custom server option. (#30)
* Upd. Settings. Add custom server option. * Upd. Settings. Custom server option refactoring. * Upd. Settings. Improved server option.
1 parent 272f19b commit f405385

File tree

7 files changed

+99
-9
lines changed

7 files changed

+99
-9
lines changed

cleantalk.antispam/default_option.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
'form_exclusions_fields__regexp' => 0,
2222
'form_exclusions_webform' => '',
2323
'complete_deactivation' => 0,
24+
'use_custom_server' => '',
2425
);

cleantalk.antispam/include.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,14 @@ public static function OnPageStartHandler()
182182
if( ! $USER->IsAdmin() ){
183183

184184
if ( $bot_detector ) {
185-
Asset::getInstance()->addJs('https://moderate.cleantalk.org/ct-bot-detector-wrapper.js');
185+
if (class_exists('COption')) {
186+
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
187+
if ($use_custom_server !== '') {
188+
Asset::getInstance()->addJs('https://moderate.' . $use_custom_server . '/ct-bot-detector-wrapper.js');
189+
} else {
190+
Asset::getInstance()->addJs('https://moderate.cleantalk.org/ct-bot-detector-wrapper.js');
191+
}
192+
}
186193
}
187194

188195
// Set cookies
@@ -1710,6 +1717,19 @@ static function GetCleanTalkResume($module, $id) {
17101717
*/
17111718
private static function GetWorkServer() {
17121719
global $DB;
1720+
1721+
if (class_exists('COption')) {
1722+
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
1723+
if ($use_custom_server !== '') {
1724+
return array(
1725+
'work_url' => 'http://moderate.' . $use_custom_server,
1726+
'server_url' => 'http://moderate.' . $use_custom_server,
1727+
'server_ttl' => 0,
1728+
'server_changed' => 0,
1729+
);
1730+
}
1731+
}
1732+
17131733
$result = $DB->Query('SELECT work_url,server_url,server_ttl,server_changed FROM cleantalk_server LIMIT 1')->Fetch();
17141734
if($result !== FALSE)
17151735
return array(
@@ -1750,7 +1770,17 @@ private static function ExceptionList($value = null)
17501770
*/
17511771
private static function SetWorkServer($work_url = 'http://moderate.cleantalk.org', $server_url = 'http://moderate.cleantalk.org', $server_ttl = 0, $server_changed = 0) {
17521772
global $DB;
1773+
17531774
$result = $DB->Query('SELECT count(*) AS count FROM cleantalk_server')->Fetch();
1775+
1776+
if (class_exists('COption')) {
1777+
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
1778+
if ($use_custom_server !== '') {
1779+
$work_url = 'http://moderate.' . $use_custom_server;
1780+
$server_url = 'http://moderate.' . $use_custom_server;
1781+
}
1782+
}
1783+
17541784
if($result['count'] == 0){
17551785
$arInsert = $DB->PrepareInsert(
17561786
'cleantalk_server',
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22
$arModuleVersion = array(
3-
"VERSION" => "3.13.0",
4-
"VERSION_DATE" => "2024-10-14 10:00:00",
3+
"VERSION" => "3.14.0",
4+
"VERSION_DATE" => "2025-06-06 10:00:00",
55
);

cleantalk.antispam/lang/en/options.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@
5454
$MESS['CLEANTALK_WRONG_DEFAULT_SETTINGS'] = 'Can not load default options. Module name is incorrect.';
5555
$MESS['CLEANTALK_WRONG_CURRENT_SETTINGS'] = 'Can not load current options.';
5656
$MESS['CLEANTALK_RESET_OPTIONS_FAILED'] = 'Can not reset options to defaults.';
57-
$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'If you want to use specific Access Key for this website paste it here. Otherwise, leave it empty.';
57+
$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'If you want to use specific Access Key for this website paste it here. Otherwise, leave it empty.';
58+
$MESS['CLEANTALK_USE_CUSTOM_SERVER'] = 'Use custom server';
59+
$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.';

cleantalk.antispam/lang/ru/options.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@
5454
$MESS['CLEANTALK_WRONG_DEFAULT_SETTINGS'] = 'Невоможно загрузить опции по умолчанию. Ошибка в имени модуля.';
5555
$MESS['CLEANTALK_WRONG_CURRENT_SETTINGS'] = 'Невоможно загрузить текущие опции.';
5656
$MESS['CLEANTALK_RESET_OPTIONS_FAILED'] = 'Невоможно сбросить опции.';
57-
$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'Если вы хотите использовать отдельный ключ доступа для этого сайта, вставьте его здесь. В противном случае оставьте поле пустым.';
57+
$MESS['CLEANTALK_MULTISITE_LABEL_KEY'] = 'Если вы хотите использовать отдельный ключ доступа для этого сайта, вставьте его здесь. В противном случае оставьте поле пустым.';
58+
$MESS['CLEANTALK_USE_CUSTOM_SERVER'] = 'Использовать кастомный сервер';
59+
$MESS['CLEANTALK_USE_CUSTOM_SERVER_DESCRIPTION'] = 'Использовать кастомный сервер для проверки спама. Можете ввести cleantalk.ru и плагин будет использовать только ru сервера. Опция для критических ситуаций, когда невозможен выбор сервера автоматически.';
60+
$MESS['CLEANTALK_SERVER_NOT_AVAILABLE'] = 'Указанные сервера не доступны, обратитесь в тех поддержку https://cleantalk.org/my/support/open';

cleantalk.antispam/lib/Cleantalk/Common/API.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class API
1717
{
1818
/* Default params */
19-
const URL = 'https://api.cleantalk.org';
19+
public static $URL = 'https://api.cleantalk.org';
2020
const AGENT = 'ct-php-lib-1.0';
2121

2222
/**
@@ -205,7 +205,7 @@ public static function method__spam_check_cms($api_key, $data, $date = null, $do
205205

206206
if($date) $request['date'] = $date;
207207

208-
$result = static::send_request($request, self::URL, 20);
208+
$result = static::send_request($request, self::$URL, 20);
209209
$result = $do_check ? static::check_response($result, 'spam_check_cms') : $result;
210210

211211
return $result;
@@ -234,7 +234,7 @@ public static function method__spam_check($api_key, $data, $date = null, $do_che
234234
$request['date'] = $date;
235235
}
236236

237-
$result = static::send_request($request, self::URL, 10);
237+
$result = static::send_request($request, self::$URL, 10);
238238
$result = $do_check ? static::check_response($result, 'spam_check') : $result;
239239

240240
return $result;
@@ -631,8 +631,13 @@ public static function method__request_checksums($api_key, $plugins_and_themes_t
631631
*
632632
* @return array|bool
633633
*/
634-
public static function send_request($data, $url = self::URL, $timeout = 10, $ssl = false, $ssl_path = '')
634+
public static function send_request($data, $url = null, $timeout = 10, $ssl = false, $ssl_path = '')
635635
{
636+
// Set default URL if not provided
637+
if ($url === null) {
638+
$url = self::$URL;
639+
}
640+
636641
// Possibility to switch agent vaersion
637642
$data['agent'] = !empty($data['agent'])
638643
? $data['agent']
@@ -650,6 +655,14 @@ public static function send_request($data, $url = self::URL, $timeout = 10, $ssl
650655
}
651656

652657
// Possibility to switch API url
658+
if ($url == self::$URL) {
659+
if (class_exists('COption')) {
660+
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
661+
if ($use_custom_server !== '') {
662+
$url = 'https://api.' . $use_custom_server;
663+
}
664+
}
665+
}
653666
$url = defined('CLEANTALK_API_URL') ? CLEANTALK_API_URL : $url;
654667

655668
if(function_exists('curl_init')){

cleantalk.antispam/options.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,33 @@
201201
} else {
202202
CAgent::RemoveModuleAgents("cleantalk.antispam");
203203
}
204+
205+
// Custom server
206+
if (isset($_POST['use_custom_server']) && $_POST['use_custom_server'] == '' && COption::GetOptionString($sModuleId, "use_custom_server") !== '') {
207+
Option::set( $sModuleId, 'use_custom_server', '' );
208+
}
209+
if (isset($_POST['use_custom_server']) && $_POST['use_custom_server'] !== '') {
210+
// Remove path, query, fragment
211+
$domain = preg_replace('/[\/\?#].*$/', '', $_POST['use_custom_server']);
212+
// Remove invalid characters (keep letters, numbers, hyphens, dots)
213+
$domain = preg_replace('/[^a-zA-Z0-9\.\-]/', '', $domain);
214+
// Convert to lowercase and trim
215+
$domain = strtolower(trim($domain));
216+
// use default bitrix http client to make request
217+
$httpClient = new \Bitrix\Main\Web\HttpClient();
218+
$response = $httpClient->get('https://moderate.' . $domain);
219+
if ($response === false) {
220+
Option::set( $sModuleId, 'use_custom_server', '' );
221+
CAdminNotify::Add(array(
222+
'MESSAGE' => GetMessage( 'CLEANTALK_SERVER_NOT_AVAILABLE' ),
223+
'TAG' => 'server_not_available',
224+
'MODULE_ID' => 'main',
225+
'ENABLE_CLOSE' => 'Y'));
226+
} else {
227+
Option::set( $sModuleId, 'use_custom_server', $domain );
228+
CAdminNotify::DeleteByTag('server_not_available');
229+
}
230+
}
204231
}
205232

206233
foreach( $sites as $site ) {
@@ -710,6 +737,20 @@ function ctDisableInputLine(ct_input_line){
710737
value="1" />
711738
</td>
712739
</tr>
740+
<tr>
741+
<td width="50%" valign="top">
742+
<label for="use_custom_server"><?php echo GetMessage( 'CLEANTALK_USE_CUSTOM_SERVER' );?>:</td>
743+
<td valign="top">
744+
<input
745+
type="text"
746+
name="use_custom_server"
747+
id="use_custom_server"
748+
value="<?php echo $current_options['use_custom_server']; ?>" />
749+
<div style="padding: 10px 0 10px 0">
750+
<?php echo GetMessage( 'CLEANTALK_USE_CUSTOM_SERVER_DESCRIPTION' ); ?>
751+
</div>
752+
</td>
753+
</tr>
713754
<!--HIDDEN FIELDSET-->
714755
<input type="hidden" name="is_paid" value="<?php echo $current_options['is_paid'] ?>" />
715756
<input type="hidden" name="last_checked" value="0" />

0 commit comments

Comments
 (0)