Version Description
March 22 2018 = * IP detection improved. * Fix: SSL connection. * Fix: False positives spam detection in Contact Form 7. * Minor fixes.
Download this release
Release Info
Developer | Safronik |
Plugin | Spam protection, AntiSpam, FireWall by CleanTalk |
Version | 5.92 |
Comparing to | |
See all releases |
Code changes from version 5.91 to 5.92
- cleantalk.php +17 -15
- inc/cleantalk-admin.php +30 -34
- inc/cleantalk-ajax.php +1 -1
- inc/cleantalk-comments.php +26 -47
- inc/cleantalk-common.php +6 -11
- inc/cleantalk-public.php +46 -59
- inc/cleantalk-users.php +8 -31
- inc/cleantalk.class.php → lib/Cleantalk.php +5 -477
- lib/CleantalkHelper.php +201 -172
- lib/CleantalkRequest.php +170 -0
- lib/CleantalkResponse.php +155 -0
- lib/CleantalkSFW.php +10 -268
- lib/cleantalk-php-patch.php +80 -0
- readme.txt +14 -2
cleantalk.php
CHANGED
@@ -3,17 +3,15 @@
|
|
3 |
Plugin Name: Anti-Spam by CleanTalk
|
4 |
Plugin URI: http://cleantalk.org
|
5 |
Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
|
6 |
-
Version: 5.
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: http://cleantalk.org
|
9 |
*/
|
10 |
|
11 |
-
$cleantalk_plugin_version='5.91';
|
12 |
-
$ct_agent_version = 'wordpress-591';
|
13 |
$cleantalk_executed = false;
|
14 |
|
15 |
-
define('APBCT_VERSION', '5.
|
16 |
-
define('APBCT_AGENT', 'wordpress-
|
17 |
|
18 |
define('CLEANTALK_REMOTE_CALL_SLEEP', 10); // Minimum time between remote call
|
19 |
define('APBCT_CASERT_PATH', file_exists(ABSPATH . WPINC . '/certificates/ca-bundle.crt')
|
@@ -27,11 +25,15 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
|
|
27 |
|
28 |
define('CLEANTALK_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
$ct_options=ct_get_options();
|
36 |
$ct_data=ct_get_data();
|
37 |
|
@@ -78,9 +80,9 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
|
|
78 |
if(isset($_GET['spbc_remote_call_token'], $_GET['spbc_remote_call_action'], $_GET['plugin_name']) && in_array($_GET['plugin_name'], array('antispam','anti-spam'))){
|
79 |
|
80 |
// Comparing with cleantalk's IP
|
81 |
-
$spbc_remote_ip = CleantalkHelper::
|
82 |
|
83 |
-
if($spbc_remote_ip
|
84 |
|
85 |
$resolved = gethostbyaddr($spbc_remote_ip);
|
86 |
|
@@ -167,9 +169,9 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
|
|
167 |
|
168 |
$is_sfw_check = true;
|
169 |
$sfw = new CleantalkSFW();
|
170 |
-
$
|
171 |
-
|
172 |
-
foreach($
|
173 |
if(isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key'] == md5($ct_cur_ip.$ct_options['apikey'])){
|
174 |
$is_sfw_check=false;
|
175 |
if(isset($_COOKIE['ct_sfw_passed'])){
|
@@ -574,7 +576,7 @@ function cleantalk_get_brief_data(){
|
|
574 |
$ct_options = ct_get_options();
|
575 |
$ct_data = ct_get_data();
|
576 |
|
577 |
-
$ct_data['brief_data'] = CleantalkHelper::
|
578 |
|
579 |
update_option('cleantalk_data', $ct_data);
|
580 |
|
3 |
Plugin Name: Anti-Spam by CleanTalk
|
4 |
Plugin URI: http://cleantalk.org
|
5 |
Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
|
6 |
+
Version: 5.92
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: http://cleantalk.org
|
9 |
*/
|
10 |
|
|
|
|
|
11 |
$cleantalk_executed = false;
|
12 |
|
13 |
+
define('APBCT_VERSION', '5.92');
|
14 |
+
define('APBCT_AGENT', 'wordpress-592');
|
15 |
|
16 |
define('CLEANTALK_REMOTE_CALL_SLEEP', 10); // Minimum time between remote call
|
17 |
define('APBCT_CASERT_PATH', file_exists(ABSPATH . WPINC . '/certificates/ca-bundle.crt')
|
25 |
|
26 |
define('CLEANTALK_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
27 |
|
28 |
+
require_once( CLEANTALK_PLUGIN_DIR . 'lib/cleantalk-php-patch.php'); // Pathces fpr different functions which not exists
|
29 |
+
require_once( CLEANTALK_PLUGIN_DIR . 'lib/CleantalkHelper.php'); // Helper class. Different useful functions
|
30 |
+
require_once( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk.php'); // Main class for request
|
31 |
+
require_once( CLEANTALK_PLUGIN_DIR . 'lib/CleantalkRequest.php'); // Holds request data
|
32 |
+
require_once( CLEANTALK_PLUGIN_DIR . 'lib/CleantalkResponse.php'); // Holds response data
|
33 |
+
require_once( CLEANTALK_PLUGIN_DIR . 'lib/CleantalkCron.php'); // Cron handling
|
34 |
require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
|
35 |
+
require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
|
36 |
+
|
|
|
37 |
$ct_options=ct_get_options();
|
38 |
$ct_data=ct_get_data();
|
39 |
|
80 |
if(isset($_GET['spbc_remote_call_token'], $_GET['spbc_remote_call_action'], $_GET['plugin_name']) && in_array($_GET['plugin_name'], array('antispam','anti-spam'))){
|
81 |
|
82 |
// Comparing with cleantalk's IP
|
83 |
+
$spbc_remote_ip = CleantalkHelper::ip_get(array('real'));
|
84 |
|
85 |
+
if(!empty($spbc_remote_ip)){
|
86 |
|
87 |
$resolved = gethostbyaddr($spbc_remote_ip);
|
88 |
|
169 |
|
170 |
$is_sfw_check = true;
|
171 |
$sfw = new CleantalkSFW();
|
172 |
+
$sfw->ip_array = CleantalkSFW::ip_get();
|
173 |
+
|
174 |
+
foreach($sfw->ip_array as $ct_cur_ip){
|
175 |
if(isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key'] == md5($ct_cur_ip.$ct_options['apikey'])){
|
176 |
$is_sfw_check=false;
|
177 |
if(isset($_COOKIE['ct_sfw_passed'])){
|
576 |
$ct_options = ct_get_options();
|
577 |
$ct_data = ct_get_data();
|
578 |
|
579 |
+
$ct_data['brief_data'] = CleantalkHelper::api_method__get_antispam_report_breif($ct_options['apikey']);
|
580 |
|
581 |
update_option('cleantalk_data', $ct_data);
|
582 |
|
inc/cleantalk-admin.php
CHANGED
@@ -37,8 +37,8 @@ function ct_dashboard_statistics_widget_output( $post, $callback_args ) {
|
|
37 |
|
38 |
$brief_data = $ct_data['brief_data'];
|
39 |
|
40 |
-
if(!empty($_POST['ct_brief_refresh'])){
|
41 |
-
$brief_data = CleantalkHelper::
|
42 |
$ct_data['brief_data'] = $brief_data;
|
43 |
update_option('cleantalk_data', $ct_data);
|
44 |
}
|
@@ -103,9 +103,7 @@ function ct_dashboard_statistics_widget_output( $post, $callback_args ) {
|
|
103 |
<td><?php echo $val[0]; ?></td>
|
104 |
<td><?php echo $val[1] ? "<img src='https://cleantalk.org/images/flags/".strtolower($val[1]).".png'>" : ''; ?> <?php
|
105 |
echo $val[1]
|
106 |
-
? (
|
107 |
-
? locale_get_display_region('sl-Latn-'.$val[1].'-nedis', substr(get_locale(), 0, 2))
|
108 |
-
: $val[1])
|
109 |
: 'Unknown'; ?></td>
|
110 |
<td style='text-align: center;'><?php echo $val[2]; ?></td>
|
111 |
</tr>
|
@@ -174,11 +172,11 @@ add_action( 'wp_ajax_ajax_get_timezone', 'ct_ajax_get_timezone' );
|
|
174 |
*/
|
175 |
function apbct_enqueue_scripts($hook) {
|
176 |
|
177 |
-
global $
|
178 |
|
179 |
// Scripts to all admin pages
|
180 |
-
wp_enqueue_script('ct_admin_js_notices', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin.js'), array(),
|
181 |
-
wp_enqueue_style ('ct_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin.css'), array(),
|
182 |
|
183 |
wp_localize_script( 'jquery', 'ctAdminCommon', array(
|
184 |
'logo_small_colored' => '<img src="' . plugin_dir_url(__FILE__) . 'images/logo_color.png" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />'
|
@@ -186,15 +184,15 @@ function apbct_enqueue_scripts($hook) {
|
|
186 |
|
187 |
// Scripts & Styles to main dashboard page
|
188 |
if($hook == 'index.php' && current_user_can('activate_plugins')){
|
189 |
-
wp_enqueue_script('ct_gstatic_charts_loader', 'https://www.gstatic.com/charts/loader.js', array(),
|
190 |
-
wp_enqueue_script('ct_admin_js_widget_dashboard', plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget.js'), array('ct_gstatic_charts_loader'),
|
191 |
-
wp_enqueue_style('ct_admin_css_widget_dashboard', plugins_url('/cleantalk-spam-protect/css/cleantalk-dashboard-widget.css'), array(),
|
192 |
}
|
193 |
|
194 |
// Scripts & Styles for CleanTalk's settings page
|
195 |
if( $hook == 'settings_page_cleantalk' ){
|
196 |
-
wp_enqueue_script('cleantalk_admin_js_settings_page', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin-settings-page.js'),
|
197 |
-
wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin-settings-page.css'), array(),
|
198 |
|
199 |
$ajax_nonce = wp_create_nonce( "ct_secret_nonce" );
|
200 |
wp_localize_script( 'jquery', 'ctSettingsPage', array(
|
@@ -205,8 +203,8 @@ function apbct_enqueue_scripts($hook) {
|
|
205 |
// Scripts for comments check
|
206 |
if( $hook == 'comments_page_ct_check_spam' || $hook == 'edit-comments.php'){
|
207 |
|
208 |
-
wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url('/cleantalk-spam-protect/css/cleantalk-spam-check.css'), array(),
|
209 |
-
wp_enqueue_style('jqueryui_css', plugins_url('/cleantalk-spam-protect/css/jquery-ui.min.css'), array(), '1.21.1',
|
210 |
|
211 |
$ajax_nonce = wp_create_nonce( "ct_secret_nonce" );
|
212 |
$user_token = !empty($ct_data['user_token']) ? $ct_data['user_token'] : '';
|
@@ -214,8 +212,8 @@ function apbct_enqueue_scripts($hook) {
|
|
214 |
if(!empty($_COOKIE['ct_paused_comments_check']))
|
215 |
$prev_check = json_decode(stripslashes($_COOKIE['ct_paused_comments_check']), true);
|
216 |
|
217 |
-
wp_enqueue_script('ct_comments_checkspam', plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-checkspam.js'), array(),
|
218 |
-
wp_enqueue_script('ct_comments_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-editscreen.js'), array(),
|
219 |
wp_enqueue_script('jqueryui', plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'), array('jquery'), '1.12.1');
|
220 |
|
221 |
wp_localize_script( 'jquery', 'ctCommentsCheck', array(
|
@@ -248,7 +246,7 @@ function apbct_enqueue_scripts($hook) {
|
|
248 |
// Scripts for users check
|
249 |
if( $hook == 'users_page_ct_check_users' || $hook == 'users.php'){
|
250 |
|
251 |
-
wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url().'/cleantalk-spam-protect/css/cleantalk-spam-check.css', array(),
|
252 |
wp_enqueue_style('jqueryui_css', plugins_url().'/cleantalk-spam-protect/css/jquery-ui.min.css', array(), '1.21.1', 'all');
|
253 |
|
254 |
$current_user = wp_get_current_user();
|
@@ -257,8 +255,8 @@ function apbct_enqueue_scripts($hook) {
|
|
257 |
if(!empty($_COOKIE['ct_paused_users_check']))
|
258 |
$prev_check = json_decode(stripslashes($_COOKIE['ct_paused_users_check']), true);
|
259 |
|
260 |
-
wp_enqueue_script('ct_users_checkspam', plugins_url('/cleantalk-spam-protect/js/cleantalk-users-checkspam.js'), array(),
|
261 |
-
wp_enqueue_script('ct_users_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-users-editscreen.js'), array(),
|
262 |
wp_enqueue_script('jqueryui', plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'), array('jquery'), '1.12.1');
|
263 |
|
264 |
wp_localize_script( 'jquery', 'ctUsersCheck', array(
|
@@ -316,7 +314,7 @@ function ct_account_status_check(){
|
|
316 |
? $ct_options['apikey']
|
317 |
: null);
|
318 |
|
319 |
-
$result = CleantalkHelper::
|
320 |
|
321 |
if(empty($result['error'])){
|
322 |
|
@@ -370,7 +368,7 @@ function ct_account_status_check(){
|
|
370 |
*/
|
371 |
function apbct_admin_init(){
|
372 |
|
373 |
-
global $ct_server_timeout, $show_ct_notice_autokey, $ct_notice_autokey_label, $ct_notice_autokey_value, $show_ct_notice_renew, $ct_notice_renew_label, $show_ct_notice_trial, $ct_notice_trial_label, $show_ct_notice_online, $ct_notice_online_label, $renew_notice_showtime, $trial_notice_showtime, $ct_plugin_name, $ct_options, $ct_data, $ct_user_token_label, $
|
374 |
|
375 |
$ct_options = ct_get_options();
|
376 |
$ct_data = ct_get_data();
|
@@ -378,16 +376,16 @@ function apbct_admin_init(){
|
|
378 |
// Update logic
|
379 |
$current_version = (!empty($ct_data['plugin_version']) ? $ct_data['plugin_version'] : '1.0.0');
|
380 |
|
381 |
-
if($current_version !=
|
382 |
if(is_main_site()){
|
383 |
require_once('cleantalk-updater.php');
|
384 |
-
$result = ct_run_update_actions($current_version,
|
385 |
//If update is successfull
|
386 |
if($result === true){
|
387 |
ct_send_feedback(
|
388 |
-
'0:' .
|
389 |
);
|
390 |
-
$ct_data['plugin_version'] =
|
391 |
update_option( 'cleantalk_data' , $ct_data);
|
392 |
}
|
393 |
}
|
@@ -404,7 +402,7 @@ function apbct_admin_init(){
|
|
404 |
$ct_options['apikey']=$_POST['cleantalk_settings']['apikey'];
|
405 |
update_option('cleantalk_settings', $ct_options);
|
406 |
ct_send_feedback(
|
407 |
-
'0:' .
|
408 |
);
|
409 |
}
|
410 |
|
@@ -423,9 +421,7 @@ function apbct_admin_init(){
|
|
423 |
$platform = 'wordpress';
|
424 |
$timezone = $_POST['ct_admin_timezone'];
|
425 |
|
426 |
-
|
427 |
-
|
428 |
-
$result = CleantalkHelper::getAutoKey(ct_get_admin_email(), $website, $platform, $timezone);
|
429 |
|
430 |
if ($result)
|
431 |
{
|
@@ -1419,7 +1415,7 @@ function ct_input_set_cookies() {
|
|
1419 |
echo "<input type='radio' id='cleantalk_set_cookies1' name='cleantalk_settings[set_cookies]' value='1' " . (!empty($ct_options['set_cookies']) ? 'checked' : '') . " /><label for='cleantalk_set_cookies1'> " . __('Yes') . "</label>";
|
1420 |
echo ' ';
|
1421 |
echo "<input type='radio' id='cleantalk_set_cookies0' name='cleantalk_settings[set_cookies]' value='0' " . (empty($ct_options['set_cookies']) ? 'checked' : '') . " /><label for='cleantalk_set_cookies0'> " . __('No') . "</label>";
|
1422 |
-
ct_add_descriptions_to_fields(sprintf(__('Turn this option off to deny plugin generates any cookies on website front-end. This option is helpful if you use Varnish. But most of contact forms will not be protected by CleanTalk if the option is turned off!', 'cleantalk')));
|
1423 |
}
|
1424 |
|
1425 |
function ct_input_ssl_on() {
|
@@ -1696,7 +1692,7 @@ function cleantalk_admin_notice_message(){
|
|
1696 |
$show_notice = false;
|
1697 |
}
|
1698 |
|
1699 |
-
//"Trial period ends" notice from apbct_admin_init().
|
1700 |
if ($show_notice && $show_ct_notice_trial == 1) {
|
1701 |
echo '<div class="error">
|
1702 |
<h3>' . sprintf(__("%s trial period ends, please upgrade to %s!", 'cleantalk'),
|
@@ -1707,7 +1703,7 @@ function cleantalk_admin_notice_message(){
|
|
1707 |
$show_notice = false;
|
1708 |
}
|
1709 |
|
1710 |
-
//Renew notice from apbct_admin_init().
|
1711 |
if ($show_notice && $show_ct_notice_renew == 1) {
|
1712 |
$renew_link = "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%%20backend%%20renew$user_token&cp_mode=antispam\" target=\"_blank\">%s</a>";
|
1713 |
$button_html = sprintf($renew_link, '<input type="button" class="button button-primary" value="'.__('RENEW ANTI-SPAM', 'cleantalk').'" />');
|
@@ -1942,7 +1938,7 @@ function ct_update_option($option_name) {
|
|
1942 |
}
|
1943 |
}
|
1944 |
|
1945 |
-
$result = CleantalkHelper::
|
1946 |
|
1947 |
if (empty($result['error'])){
|
1948 |
if($result['valid'] == 1){
|
37 |
|
38 |
$brief_data = $ct_data['brief_data'];
|
39 |
|
40 |
+
if(!empty($_POST['ct_brief_refresh']) or empty($brief_data['spam_stat'])){
|
41 |
+
$brief_data = CleantalkHelper::api_method__get_antispam_report_breif($ct_options['apikey']);
|
42 |
$ct_data['brief_data'] = $brief_data;
|
43 |
update_option('cleantalk_data', $ct_data);
|
44 |
}
|
103 |
<td><?php echo $val[0]; ?></td>
|
104 |
<td><?php echo $val[1] ? "<img src='https://cleantalk.org/images/flags/".strtolower($val[1]).".png'>" : ''; ?> <?php
|
105 |
echo $val[1]
|
106 |
+
? locale_get_display_region('sl-Latn-'.$val[1].'-nedis', substr(get_locale(), 0, 2))
|
|
|
|
|
107 |
: 'Unknown'; ?></td>
|
108 |
<td style='text-align: center;'><?php echo $val[2]; ?></td>
|
109 |
</tr>
|
172 |
*/
|
173 |
function apbct_enqueue_scripts($hook) {
|
174 |
|
175 |
+
global $ct_data, $ct_options;
|
176 |
|
177 |
// Scripts to all admin pages
|
178 |
+
wp_enqueue_script('ct_admin_js_notices', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin.js'), array(), APBCT_VERSION);
|
179 |
+
wp_enqueue_style ('ct_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin.css'), array(), APBCT_VERSION, 'all');
|
180 |
|
181 |
wp_localize_script( 'jquery', 'ctAdminCommon', array(
|
182 |
'logo_small_colored' => '<img src="' . plugin_dir_url(__FILE__) . 'images/logo_color.png" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />'
|
184 |
|
185 |
// Scripts & Styles to main dashboard page
|
186 |
if($hook == 'index.php' && current_user_can('activate_plugins')){
|
187 |
+
wp_enqueue_script('ct_gstatic_charts_loader', 'https://www.gstatic.com/charts/loader.js', array(), APBCT_VERSION);
|
188 |
+
wp_enqueue_script('ct_admin_js_widget_dashboard', plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget.js'), array('ct_gstatic_charts_loader'), APBCT_VERSION);
|
189 |
+
wp_enqueue_style('ct_admin_css_widget_dashboard', plugins_url('/cleantalk-spam-protect/css/cleantalk-dashboard-widget.css'), array(), APBCT_VERSION, 'all');
|
190 |
}
|
191 |
|
192 |
// Scripts & Styles for CleanTalk's settings page
|
193 |
if( $hook == 'settings_page_cleantalk' ){
|
194 |
+
wp_enqueue_script('cleantalk_admin_js_settings_page', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin-settings-page.js'), array(), APBCT_VERSION);
|
195 |
+
wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin-settings-page.css'), array(), APBCT_VERSION, 'all');
|
196 |
|
197 |
$ajax_nonce = wp_create_nonce( "ct_secret_nonce" );
|
198 |
wp_localize_script( 'jquery', 'ctSettingsPage', array(
|
203 |
// Scripts for comments check
|
204 |
if( $hook == 'comments_page_ct_check_spam' || $hook == 'edit-comments.php'){
|
205 |
|
206 |
+
wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url('/cleantalk-spam-protect/css/cleantalk-spam-check.css'), array(), APBCT_VERSION, 'all');
|
207 |
+
wp_enqueue_style('jqueryui_css', plugins_url('/cleantalk-spam-protect/css/jquery-ui.min.css'), array(), '1.21.1', 'all');
|
208 |
|
209 |
$ajax_nonce = wp_create_nonce( "ct_secret_nonce" );
|
210 |
$user_token = !empty($ct_data['user_token']) ? $ct_data['user_token'] : '';
|
212 |
if(!empty($_COOKIE['ct_paused_comments_check']))
|
213 |
$prev_check = json_decode(stripslashes($_COOKIE['ct_paused_comments_check']), true);
|
214 |
|
215 |
+
wp_enqueue_script('ct_comments_checkspam', plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-checkspam.js'), array(), APBCT_VERSION);
|
216 |
+
wp_enqueue_script('ct_comments_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-editscreen.js'), array(), APBCT_VERSION);
|
217 |
wp_enqueue_script('jqueryui', plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'), array('jquery'), '1.12.1');
|
218 |
|
219 |
wp_localize_script( 'jquery', 'ctCommentsCheck', array(
|
246 |
// Scripts for users check
|
247 |
if( $hook == 'users_page_ct_check_users' || $hook == 'users.php'){
|
248 |
|
249 |
+
wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url().'/cleantalk-spam-protect/css/cleantalk-spam-check.css', array(), APBCT_VERSION, 'all');
|
250 |
wp_enqueue_style('jqueryui_css', plugins_url().'/cleantalk-spam-protect/css/jquery-ui.min.css', array(), '1.21.1', 'all');
|
251 |
|
252 |
$current_user = wp_get_current_user();
|
255 |
if(!empty($_COOKIE['ct_paused_users_check']))
|
256 |
$prev_check = json_decode(stripslashes($_COOKIE['ct_paused_users_check']), true);
|
257 |
|
258 |
+
wp_enqueue_script('ct_users_checkspam', plugins_url('/cleantalk-spam-protect/js/cleantalk-users-checkspam.js'), array(), APBCT_VERSION);
|
259 |
+
wp_enqueue_script('ct_users_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-users-editscreen.js'), array(), APBCT_VERSION);
|
260 |
wp_enqueue_script('jqueryui', plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'), array('jquery'), '1.12.1');
|
261 |
|
262 |
wp_localize_script( 'jquery', 'ctUsersCheck', array(
|
314 |
? $ct_options['apikey']
|
315 |
: null);
|
316 |
|
317 |
+
$result = CleantalkHelper::api_method__notice_paid_till($api_key);
|
318 |
|
319 |
if(empty($result['error'])){
|
320 |
|
368 |
*/
|
369 |
function apbct_admin_init(){
|
370 |
|
371 |
+
global $ct_server_timeout, $show_ct_notice_autokey, $ct_notice_autokey_label, $ct_notice_autokey_value, $show_ct_notice_renew, $ct_notice_renew_label, $show_ct_notice_trial, $ct_notice_trial_label, $show_ct_notice_online, $ct_notice_online_label, $renew_notice_showtime, $trial_notice_showtime, $ct_plugin_name, $ct_options, $ct_data, $ct_user_token_label, $notice_check_timeout;
|
372 |
|
373 |
$ct_options = ct_get_options();
|
374 |
$ct_data = ct_get_data();
|
376 |
// Update logic
|
377 |
$current_version = (!empty($ct_data['plugin_version']) ? $ct_data['plugin_version'] : '1.0.0');
|
378 |
|
379 |
+
if($current_version != APBCT_VERSION){
|
380 |
if(is_main_site()){
|
381 |
require_once('cleantalk-updater.php');
|
382 |
+
$result = ct_run_update_actions($current_version, APBCT_VERSION);
|
383 |
//If update is successfull
|
384 |
if($result === true){
|
385 |
ct_send_feedback(
|
386 |
+
'0:' . APBCT_AGENT // 0 - request_id, agent version.
|
387 |
);
|
388 |
+
$ct_data['plugin_version'] = APBCT_VERSION;
|
389 |
update_option( 'cleantalk_data' , $ct_data);
|
390 |
}
|
391 |
}
|
402 |
$ct_options['apikey']=$_POST['cleantalk_settings']['apikey'];
|
403 |
update_option('cleantalk_settings', $ct_options);
|
404 |
ct_send_feedback(
|
405 |
+
'0:' . APBCT_AGENT // 0 - request_id, agent version.
|
406 |
);
|
407 |
}
|
408 |
|
421 |
$platform = 'wordpress';
|
422 |
$timezone = $_POST['ct_admin_timezone'];
|
423 |
|
424 |
+
$result = CleantalkHelper::api_method__get_api_key(ct_get_admin_email(), $website, $platform, $timezone);
|
|
|
|
|
425 |
|
426 |
if ($result)
|
427 |
{
|
1415 |
echo "<input type='radio' id='cleantalk_set_cookies1' name='cleantalk_settings[set_cookies]' value='1' " . (!empty($ct_options['set_cookies']) ? 'checked' : '') . " /><label for='cleantalk_set_cookies1'> " . __('Yes') . "</label>";
|
1416 |
echo ' ';
|
1417 |
echo "<input type='radio' id='cleantalk_set_cookies0' name='cleantalk_settings[set_cookies]' value='0' " . (empty($ct_options['set_cookies']) ? 'checked' : '') . " /><label for='cleantalk_set_cookies0'> " . __('No') . "</label>";
|
1418 |
+
ct_add_descriptions_to_fields(sprintf(__('Turn this option off to deny plugin generates any cookies on website front-end. This option is helpful if you use Varnish. But most of contact forms will not be protected by CleanTalk if the option is turned off! Warning: We strongly recommend you to enable this otherwise it could give false positives spam detection.', 'cleantalk')));
|
1419 |
}
|
1420 |
|
1421 |
function ct_input_ssl_on() {
|
1692 |
$show_notice = false;
|
1693 |
}
|
1694 |
|
1695 |
+
//"Trial period ends" notice from apbct_admin_init().api_method__notice_paid_till()
|
1696 |
if ($show_notice && $show_ct_notice_trial == 1) {
|
1697 |
echo '<div class="error">
|
1698 |
<h3>' . sprintf(__("%s trial period ends, please upgrade to %s!", 'cleantalk'),
|
1703 |
$show_notice = false;
|
1704 |
}
|
1705 |
|
1706 |
+
//Renew notice from apbct_admin_init().api_method__notice_paid_till()
|
1707 |
if ($show_notice && $show_ct_notice_renew == 1) {
|
1708 |
$renew_link = "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%%20backend%%20renew$user_token&cp_mode=antispam\" target=\"_blank\">%s</a>";
|
1709 |
$button_html = sprintf($renew_link, '<input type="button" class="button button-primary" value="'.__('RENEW ANTI-SPAM', 'cleantalk').'" />');
|
1938 |
}
|
1939 |
}
|
1940 |
|
1941 |
+
$result = CleantalkHelper::api_method__notice_validate_key($api_key, preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1));
|
1942 |
|
1943 |
if (empty($result['error'])){
|
1944 |
if($result['valid'] == 1){
|
inc/cleantalk-ajax.php
CHANGED
@@ -248,7 +248,7 @@ function ct_mc4wp_ajax_hook( array $errors )
|
|
248 |
function ct_ajax_hook($message_obj = false, $additional = false)
|
249 |
{
|
250 |
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
|
251 |
-
global $
|
252 |
|
253 |
$ct_options = ct_get_options();
|
254 |
$ct_data = ct_get_data();
|
248 |
function ct_ajax_hook($message_obj = false, $additional = false)
|
249 |
{
|
250 |
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
|
251 |
+
global $ct_checkjs_register_form, $bp, $ct_signup_done, $ct_negative_comment, $ct_options, $ct_data, $current_user;
|
252 |
|
253 |
$ct_options = ct_get_options();
|
254 |
$ct_data = ct_get_data();
|
inc/cleantalk-comments.php
CHANGED
@@ -379,58 +379,37 @@ function ct_ajax_check_comments(){
|
|
379 |
die();
|
380 |
}
|
381 |
|
382 |
-
$
|
383 |
|
384 |
-
$
|
385 |
-
$request['method_name'] = 'spam_check_cms';
|
386 |
-
$request['auth_key'] = $ct_options['apikey'];
|
387 |
-
$request['data'] = $data;
|
388 |
-
if(!empty($_POST['accurate_check']))
|
389 |
-
$request['date'] = $curr_date;
|
390 |
-
|
391 |
-
$url='https://api.cleantalk.org';
|
392 |
-
|
393 |
-
if(!function_exists('sendRawRequest'))
|
394 |
-
require_once('cleantalk.class.php');
|
395 |
-
|
396 |
-
$result=sendRawRequest($url, $request, false, 5);
|
397 |
-
|
398 |
-
if(empty($result)){
|
399 |
-
$check_result['error'] = 1;
|
400 |
-
$check_result['error_message'] = __('Connection error', 'cleantalk');
|
401 |
-
echo json_encode($check_result);
|
402 |
-
}else{
|
403 |
-
|
404 |
-
$result=json_decode($result);
|
405 |
|
406 |
-
|
407 |
-
|
408 |
-
$
|
409 |
-
|
410 |
-
}else{
|
411 |
-
for($i=0;$i<sizeof($c);$i++){
|
412 |
-
|
413 |
-
$mark_spam_ip = false;
|
414 |
-
$mark_spam_email = false;
|
415 |
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
}
|
431 |
}
|
432 |
-
print json_encode($check_result);
|
433 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
}
|
435 |
}else{
|
436 |
$check_result['end'] = 1;
|
379 |
die();
|
380 |
}
|
381 |
|
382 |
+
$result = CleantalkHelper::api_method__spam_check_cms($ct_options['apikey'], $data, !empty($_POST['accurate_check']) ? $curr_date : null);
|
383 |
|
384 |
+
if(empty($result['error'])){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
+
for($i=0;$i<sizeof($c);$i++){
|
387 |
+
|
388 |
+
$mark_spam_ip = false;
|
389 |
+
$mark_spam_email = false;
|
|
|
|
|
|
|
|
|
|
|
390 |
|
391 |
+
$check_result['checked']++;
|
392 |
+
update_comment_meta($c[$i]->comment_ID,'ct_checked',date("Y-m-d H:m:s"));
|
393 |
+
$uip=$c[$i]->comment_author_IP;
|
394 |
+
$uim=$c[$i]->comment_author_email;
|
395 |
+
|
396 |
+
if(isset($result[$uip]) && $result[$uip]['appears'] == 1)
|
397 |
+
$mark_spam_ip = true;
|
398 |
+
|
399 |
+
if(isset($result[$uim]) && $result[$uim]['appears'] == 1)
|
400 |
+
$mark_spam_email = true;
|
401 |
+
|
402 |
+
if ($mark_spam_ip || $mark_spam_email){
|
403 |
+
$check_result['spam']++;
|
404 |
+
update_comment_meta($c[$i]->comment_ID,'ct_marked_as_spam','1');
|
|
|
405 |
}
|
|
|
406 |
}
|
407 |
+
print json_encode($check_result);
|
408 |
+
|
409 |
+
}else{
|
410 |
+
$check_result['error'] = 1;
|
411 |
+
$check_result['error_message'] = $result['error_string'];
|
412 |
+
echo json_encode($check_result);
|
413 |
}
|
414 |
}else{
|
415 |
$check_result['end'] = 1;
|
inc/cleantalk-common.php
CHANGED
@@ -126,14 +126,12 @@ function apbct_base_call($params = array(), $reg_flag = false){
|
|
126 |
|
127 |
$config = ct_get_server();
|
128 |
|
129 |
-
require_once('cleantalk.class.php');
|
130 |
-
|
131 |
$ct_request = new CleantalkRequest();
|
132 |
|
133 |
// IPs
|
134 |
-
$ct_request->sender_ip = defined('CT_TEST_IP') ? CT_TEST_IP : (isset($params['sender_ip']) ? $params['sender_ip'] : CleantalkHelper::
|
135 |
-
$ct_request->x_forwarded_for = CleantalkHelper::
|
136 |
-
$ct_request->x_real_ip = CleantalkHelper::
|
137 |
|
138 |
// Misc
|
139 |
$ct_request->auth_key = $ct_options['apikey'];
|
@@ -219,7 +217,7 @@ function apbct_get_sender_info() {
|
|
219 |
: null;
|
220 |
|
221 |
return array(
|
222 |
-
'remote_addr' => CleantalkHelper::
|
223 |
'REFFERRER' => isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : null,
|
224 |
'USER_AGENT' => isset($_SERVER['HTTP_USER_AGENT']) ? htmlspecialchars($_SERVER['HTTP_USER_AGENT']) : null,
|
225 |
'page_url' => isset($_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI']) ? htmlspecialchars($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']) : null,
|
@@ -477,10 +475,8 @@ function ct_get_data($force=false) {
|
|
477 |
*/
|
478 |
function ct_def_data() {
|
479 |
|
480 |
-
global $cleantalk_plugin_version;
|
481 |
-
|
482 |
return array(
|
483 |
-
'start_version' =>
|
484 |
'user_token' => '', // User token
|
485 |
'js_keys' => array(), // Keys to do JavaScript antispam test
|
486 |
'js_keys_store_days' => 14, // JavaScript keys store days - 8 days now
|
@@ -569,8 +565,7 @@ function ct_send_feedback($feedback_request = null) {
|
|
569 |
}
|
570 |
|
571 |
if ($feedback_request !== null) {
|
572 |
-
|
573 |
-
require_once('cleantalk.class.php');
|
574 |
$config = ct_get_server();
|
575 |
|
576 |
$ct = new Cleantalk();
|
126 |
|
127 |
$config = ct_get_server();
|
128 |
|
|
|
|
|
129 |
$ct_request = new CleantalkRequest();
|
130 |
|
131 |
// IPs
|
132 |
+
$ct_request->sender_ip = defined('CT_TEST_IP') ? CT_TEST_IP : (isset($params['sender_ip']) ? $params['sender_ip'] : CleantalkHelper::ip_get(array('real')));
|
133 |
+
$ct_request->x_forwarded_for = CleantalkHelper::ip_get(array('x_forwarded_for'));
|
134 |
+
$ct_request->x_real_ip = CleantalkHelper::ip_get(array('x_real_ip'));
|
135 |
|
136 |
// Misc
|
137 |
$ct_request->auth_key = $ct_options['apikey'];
|
217 |
: null;
|
218 |
|
219 |
return array(
|
220 |
+
'remote_addr' => CleantalkHelper::ip_get(array('remote_addr')),
|
221 |
'REFFERRER' => isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : null,
|
222 |
'USER_AGENT' => isset($_SERVER['HTTP_USER_AGENT']) ? htmlspecialchars($_SERVER['HTTP_USER_AGENT']) : null,
|
223 |
'page_url' => isset($_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI']) ? htmlspecialchars($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']) : null,
|
475 |
*/
|
476 |
function ct_def_data() {
|
477 |
|
|
|
|
|
478 |
return array(
|
479 |
+
'start_version' => APBCT_VERSION,
|
480 |
'user_token' => '', // User token
|
481 |
'js_keys' => array(), // Keys to do JavaScript antispam test
|
482 |
'js_keys_store_days' => 14, // JavaScript keys store days - 8 days now
|
565 |
}
|
566 |
|
567 |
if ($feedback_request !== null) {
|
568 |
+
|
|
|
569 |
$config = ct_get_server();
|
570 |
|
571 |
$ct = new Cleantalk();
|
inc/cleantalk-public.php
CHANGED
@@ -5,7 +5,7 @@
|
|
5 |
* @return mixed[] Array of options
|
6 |
*/
|
7 |
function apbct_init() {
|
8 |
-
global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $ct_options, $ct_data, $ct_check_post_result, $test_external_forms, $cleantalk_executed, $wpdb
|
9 |
|
10 |
$ct_options = ct_get_options();
|
11 |
$ct_data=ct_get_data();
|
@@ -140,12 +140,12 @@ function apbct_init() {
|
|
140 |
|
141 |
// Contact Form7
|
142 |
if(defined('WPCF7_VERSION')){
|
143 |
-
add_filter('wpcf7_form_elements', '
|
144 |
|
145 |
if(WPCF7_VERSION >= '3.0.0')
|
146 |
-
add_filter('wpcf7_spam', '
|
147 |
else
|
148 |
-
add_filter('wpcf7_acceptance', '
|
149 |
|
150 |
}
|
151 |
|
@@ -210,9 +210,9 @@ function apbct_init() {
|
|
210 |
// Gravity forms
|
211 |
//
|
212 |
if (defined('GF_MIN_WP_VERSION')) {
|
213 |
-
add_filter('gform_get_form_filter', '
|
214 |
-
add_filter('gform_entry_is_spam', '
|
215 |
-
add_filter('gform_confirmation', '
|
216 |
}
|
217 |
|
218 |
//
|
@@ -666,7 +666,7 @@ function ct_frm_entries_footer_scripts($fields, $form) {
|
|
666 |
* return @array with errors if spam has found
|
667 |
*/
|
668 |
function ct_frm_validate_entry ($errors, $values) {
|
669 |
-
global $wpdb, $current_user, $
|
670 |
|
671 |
$ct_options = ct_get_options();
|
672 |
$ct_data = ct_get_data();
|
@@ -790,7 +790,7 @@ function ct_preprocess_comment($comment) {
|
|
790 |
// this action is called just when WP process POST request (adds new comment)
|
791 |
// this action is called by wp-comments-post.php
|
792 |
// after processing WP makes redirect to post page with comment's form by GET request (see above)
|
793 |
-
global $wpdb, $current_user, $comment_post_id, $
|
794 |
|
795 |
$ct_options = ct_get_options();
|
796 |
$ct_data = ct_get_data();
|
@@ -1311,7 +1311,7 @@ function ct_test_registration($nickname, $email, $ip){
|
|
1311 |
* @return array with errors
|
1312 |
*/
|
1313 |
function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
|
1314 |
-
global $
|
1315 |
|
1316 |
$ct_options=ct_get_options();
|
1317 |
$ct_data=ct_get_data();
|
@@ -1591,11 +1591,10 @@ function ct_contact_form_is_spam_jetpack($is_spam,$form) {
|
|
1591 |
/**
|
1592 |
* Inserts anti-spam hidden to CF7
|
1593 |
*/
|
1594 |
-
function
|
1595 |
-
global $
|
1596 |
|
1597 |
$ct_options = ct_get_options();
|
1598 |
-
$ct_data = ct_get_data();
|
1599 |
|
1600 |
if ($ct_options['contact_forms_test'] == 0) {
|
1601 |
return $html;
|
@@ -1609,32 +1608,23 @@ function ct_wpcf7_form_elements($html) {
|
|
1609 |
/**
|
1610 |
* Test CF7 message for spam
|
1611 |
*/
|
1612 |
-
function
|
1613 |
-
global $
|
1614 |
|
1615 |
$ct_options = ct_get_options();
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
if ($ct_options['contact_forms_test'] == 0) {
|
1627 |
-
return $param;
|
1628 |
-
}
|
1629 |
-
|
1630 |
-
// Skip processing for logged in users.
|
1631 |
-
if ($ct_options['protect_logged_in'] != 1 && is_user_logged_in()) {
|
1632 |
-
return $param;
|
1633 |
-
}
|
1634 |
|
1635 |
-
$checkjs =
|
1636 |
-
? apbct_js_test(
|
1637 |
-
: apbct_js_test(
|
1638 |
|
1639 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
1640 |
|
@@ -1666,7 +1656,7 @@ function ct_wpcf7_spam($param) {
|
|
1666 |
$param = false;
|
1667 |
|
1668 |
$ct_cf7_comment = $ct_result->comment;
|
1669 |
-
add_filter('wpcf7_display_message', '
|
1670 |
}
|
1671 |
|
1672 |
return $param;
|
@@ -1676,7 +1666,7 @@ function ct_wpcf7_spam($param) {
|
|
1676 |
* Changes CF7 status message
|
1677 |
* @param string $hook URL of hooked page
|
1678 |
*/
|
1679 |
-
function
|
1680 |
global $ct_cf7_comment;
|
1681 |
|
1682 |
if ($status == 'spam') {
|
@@ -1835,7 +1825,7 @@ function ct_check_wplp(){
|
|
1835 |
* Places a hidding field to Gravity forms.
|
1836 |
* @return string
|
1837 |
*/
|
1838 |
-
function
|
1839 |
$ct_hidden_field = 'ct_checkjs';
|
1840 |
|
1841 |
// Do not add a hidden field twice.
|
@@ -1860,21 +1850,18 @@ function ct_gforms_hidden_field ( $form_string, $form ) {
|
|
1860 |
* Gravity forms anti-spam test.
|
1861 |
* @return boolean
|
1862 |
*/
|
1863 |
-
function
|
1864 |
|
1865 |
global $ct_options, $ct_data, $cleantalk_executed, $ct_gform_is_spam, $ct_gform_response;
|
1866 |
|
1867 |
$ct_options = ct_get_options();
|
1868 |
$ct_data = ct_get_data();
|
1869 |
|
1870 |
-
if (
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
// Return unchanged result if the submission was already tested.
|
1877 |
-
if ($cleantalk_executed)
|
1878 |
return $is_spam;
|
1879 |
|
1880 |
$ct_temp = array();
|
@@ -1897,9 +1884,8 @@ function ct_gforms_spam_test ($is_spam, $form, $entry) {
|
|
1897 |
} unset($value);
|
1898 |
$message = array_flip($message);
|
1899 |
|
1900 |
-
if($subject != '')
|
1901 |
$message['subject'] = $subject;
|
1902 |
-
}
|
1903 |
|
1904 |
$checkjs = apbct_js_test('ct_checkjs', $_POST, true)
|
1905 |
? apbct_js_test('ct_checkjs', $_POST, true)
|
@@ -1914,6 +1900,7 @@ function ct_gforms_spam_test ($is_spam, $form, $entry) {
|
|
1914 |
'checkjs' => $checkjs,
|
1915 |
)
|
1916 |
);
|
|
|
1917 |
$ct_result = $base_call_result['ct_result'];
|
1918 |
if ($ct_result->allow == 0) {
|
1919 |
$is_spam = true;
|
@@ -1924,7 +1911,7 @@ function ct_gforms_spam_test ($is_spam, $form, $entry) {
|
|
1924 |
return $is_spam;
|
1925 |
}
|
1926 |
|
1927 |
-
function
|
1928 |
|
1929 |
global $ct_gform_is_spam, $ct_gform_response;
|
1930 |
|
@@ -2341,22 +2328,22 @@ function ct_print_form($arr,$k)
|
|
2341 |
*/
|
2342 |
function ct_enqueue_scripts_public($hook){
|
2343 |
|
2344 |
-
global $
|
2345 |
|
2346 |
-
wp_enqueue_script('
|
2347 |
|
2348 |
if(!defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') || (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') && CLEANTALK_AJAX_USE_FOOTER_HEADER)){
|
2349 |
if(!empty($ct_options['use_ajax']) && stripos($_SERVER['REQUEST_URI'],'.xml') === false && stripos($_SERVER['REQUEST_URI'],'.xsl') === false){
|
2350 |
if(strpos($_SERVER['REQUEST_URI'],'jm-ajax') === false){
|
2351 |
|
2352 |
if(!empty($ct_options['use_ajax']))
|
2353 |
-
wp_enqueue_script('ct_nocache', plugins_url('/cleantalk-spam-protect/inc/cleantalk_nocache.js'), array(),
|
2354 |
|
2355 |
if(!empty($ct_options['check_external']))
|
2356 |
-
wp_enqueue_script('ct_external', plugins_url('/cleantalk-spam-protect/js/cleantalk_external.js'), array('jquery'),
|
2357 |
|
2358 |
if(!empty($ct_options['check_internal']))
|
2359 |
-
wp_enqueue_script('ct_internal', plugins_url('/cleantalk-spam-protect/js/cleantalk_internal.js'), array('jquery'),
|
2360 |
|
2361 |
wp_localize_script('ct_nocache', 'ctNocache', array(
|
2362 |
'ajaxurl' => admin_url('admin-ajax.php'),
|
@@ -2375,8 +2362,8 @@ function ct_enqueue_scripts_public($hook){
|
|
2375 |
$ajax_nonce = wp_create_nonce( "ct_secret_nonce" );
|
2376 |
$user_token = !empty($ct_data['user_token']) ? $ct_data['user_token'] : null;
|
2377 |
|
2378 |
-
wp_enqueue_style ('ct_public_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-public-admin.css'), array(),
|
2379 |
-
wp_enqueue_script('ct_public_admin_js', plugins_url('/cleantalk-spam-protect/js/cleantalk-public-admin.js'), array('jquery'),
|
2380 |
|
2381 |
wp_localize_script('ct_public_admin_js', 'ctPublic', array(
|
2382 |
'ct_ajax_nonce' => $ajax_nonce,
|
@@ -2390,7 +2377,7 @@ function ct_enqueue_scripts_public($hook){
|
|
2390 |
}
|
2391 |
|
2392 |
if(!empty($ct_options['debug_ajax'])){
|
2393 |
-
wp_enqueue_script('ct_debug_js', plugins_url('/cleantalk-spam-protect/js/cleantalk-debug-ajax.js'), array('jquery'),
|
2394 |
}
|
2395 |
}
|
2396 |
|
5 |
* @return mixed[] Array of options
|
6 |
*/
|
7 |
function apbct_init() {
|
8 |
+
global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $ct_options, $ct_data, $ct_check_post_result, $test_external_forms, $cleantalk_executed, $wpdb;
|
9 |
|
10 |
$ct_options = ct_get_options();
|
11 |
$ct_data=ct_get_data();
|
140 |
|
141 |
// Contact Form7
|
142 |
if(defined('WPCF7_VERSION')){
|
143 |
+
add_filter('wpcf7_form_elements', 'apbct_form__contactForm7__addField');
|
144 |
|
145 |
if(WPCF7_VERSION >= '3.0.0')
|
146 |
+
add_filter('wpcf7_spam', 'apbct_form__contactForm7__testSpam');
|
147 |
else
|
148 |
+
add_filter('wpcf7_acceptance', 'apbct_form__contactForm7__testSpam');
|
149 |
|
150 |
}
|
151 |
|
210 |
// Gravity forms
|
211 |
//
|
212 |
if (defined('GF_MIN_WP_VERSION')) {
|
213 |
+
add_filter('gform_get_form_filter', 'apbct_form__gravityForms__addField', 10, 2);
|
214 |
+
add_filter('gform_entry_is_spam', 'apbct_form__gravityForms__testSpam', 999, 3);
|
215 |
+
add_filter('gform_confirmation', 'apbct_form__gravityForms__showResponse', 999, 4 );
|
216 |
}
|
217 |
|
218 |
//
|
666 |
* return @array with errors if spam has found
|
667 |
*/
|
668 |
function ct_frm_validate_entry ($errors, $values) {
|
669 |
+
global $wpdb, $current_user, $ct_checkjs_frm, $ct_options, $ct_data;
|
670 |
|
671 |
$ct_options = ct_get_options();
|
672 |
$ct_data = ct_get_data();
|
790 |
// this action is called just when WP process POST request (adds new comment)
|
791 |
// this action is called by wp-comments-post.php
|
792 |
// after processing WP makes redirect to post page with comment's form by GET request (see above)
|
793 |
+
global $wpdb, $current_user, $comment_post_id, $ct_comment_done, $ct_approved_request_id_label, $ct_jp_comments, $ct_options, $ct_data;
|
794 |
|
795 |
$ct_options = ct_get_options();
|
796 |
$ct_data = ct_get_data();
|
1311 |
* @return array with errors
|
1312 |
*/
|
1313 |
function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
|
1314 |
+
global $ct_checkjs_register_form, $apbct_cookie_request_id_label, $apbct_cookie_register_ok_label, $bp, $ct_signup_done, $ct_negative_comment, $ct_options, $ct_data, $ct_registration_error_comment;
|
1315 |
|
1316 |
$ct_options=ct_get_options();
|
1317 |
$ct_data=ct_get_data();
|
1591 |
/**
|
1592 |
* Inserts anti-spam hidden to CF7
|
1593 |
*/
|
1594 |
+
function apbct_form__contactForm7__addField($html) {
|
1595 |
+
global $ct_checkjs_cf7, $ct_options;
|
1596 |
|
1597 |
$ct_options = ct_get_options();
|
|
|
1598 |
|
1599 |
if ($ct_options['contact_forms_test'] == 0) {
|
1600 |
return $html;
|
1608 |
/**
|
1609 |
* Test CF7 message for spam
|
1610 |
*/
|
1611 |
+
function apbct_form__contactForm7__testSpam($param) {
|
1612 |
+
global $ct_checkjs_cf7, $ct_cf7_comment, $ct_options;
|
1613 |
|
1614 |
$ct_options = ct_get_options();
|
1615 |
+
|
1616 |
+
if(
|
1617 |
+
$ct_options['contact_forms_test'] == 0 ||
|
1618 |
+
$param == false && WPCF7_VERSION < '3.0.0' ||
|
1619 |
+
$param === true && WPCF7_VERSION >= '3.0.0' ||
|
1620 |
+
$ct_options['protect_logged_in'] != 1 && is_user_logged_in() // Skip processing for logged in users.
|
1621 |
+
){
|
1622 |
+
return $param;
|
1623 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1624 |
|
1625 |
+
$checkjs = apbct_js_test($ct_checkjs_cf7, $_POST, true)
|
1626 |
+
? apbct_js_test($ct_checkjs_cf7, $_POST, true)
|
1627 |
+
: apbct_js_test('ct_checkjs', $_COOKIE, true);
|
1628 |
|
1629 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
1630 |
|
1656 |
$param = false;
|
1657 |
|
1658 |
$ct_cf7_comment = $ct_result->comment;
|
1659 |
+
add_filter('wpcf7_display_message', 'apbct_form__contactForm7__showResponse', 10, 2);
|
1660 |
}
|
1661 |
|
1662 |
return $param;
|
1666 |
* Changes CF7 status message
|
1667 |
* @param string $hook URL of hooked page
|
1668 |
*/
|
1669 |
+
function apbct_form__contactForm7__showResponse($message, $status = 'spam') {
|
1670 |
global $ct_cf7_comment;
|
1671 |
|
1672 |
if ($status == 'spam') {
|
1825 |
* Places a hidding field to Gravity forms.
|
1826 |
* @return string
|
1827 |
*/
|
1828 |
+
function apbct_form__gravityForms__addField($form_string, $form){
|
1829 |
$ct_hidden_field = 'ct_checkjs';
|
1830 |
|
1831 |
// Do not add a hidden field twice.
|
1850 |
* Gravity forms anti-spam test.
|
1851 |
* @return boolean
|
1852 |
*/
|
1853 |
+
function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
|
1854 |
|
1855 |
global $ct_options, $ct_data, $cleantalk_executed, $ct_gform_is_spam, $ct_gform_response;
|
1856 |
|
1857 |
$ct_options = ct_get_options();
|
1858 |
$ct_data = ct_get_data();
|
1859 |
|
1860 |
+
if (
|
1861 |
+
$ct_options['contact_forms_test'] == 0 ||
|
1862 |
+
$is_spam ||
|
1863 |
+
$cleantalk_executed // Return unchanged result if the submission was already tested.
|
1864 |
+
)
|
|
|
|
|
|
|
1865 |
return $is_spam;
|
1866 |
|
1867 |
$ct_temp = array();
|
1884 |
} unset($value);
|
1885 |
$message = array_flip($message);
|
1886 |
|
1887 |
+
if($subject != '')
|
1888 |
$message['subject'] = $subject;
|
|
|
1889 |
|
1890 |
$checkjs = apbct_js_test('ct_checkjs', $_POST, true)
|
1891 |
? apbct_js_test('ct_checkjs', $_POST, true)
|
1900 |
'checkjs' => $checkjs,
|
1901 |
)
|
1902 |
);
|
1903 |
+
|
1904 |
$ct_result = $base_call_result['ct_result'];
|
1905 |
if ($ct_result->allow == 0) {
|
1906 |
$is_spam = true;
|
1911 |
return $is_spam;
|
1912 |
}
|
1913 |
|
1914 |
+
function apbct_form__gravityForms__showResponse( $confirmation, $form, $entry, $ajax ){
|
1915 |
|
1916 |
global $ct_gform_is_spam, $ct_gform_response;
|
1917 |
|
2328 |
*/
|
2329 |
function ct_enqueue_scripts_public($hook){
|
2330 |
|
2331 |
+
global $current_user, $ct_data, $ct_options;
|
2332 |
|
2333 |
+
wp_enqueue_script('ct_public', plugins_url('/cleantalk-spam-protect/js/apbct-public.js'), array(), APBCT_VERSION, 'in_footer');
|
2334 |
|
2335 |
if(!defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') || (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') && CLEANTALK_AJAX_USE_FOOTER_HEADER)){
|
2336 |
if(!empty($ct_options['use_ajax']) && stripos($_SERVER['REQUEST_URI'],'.xml') === false && stripos($_SERVER['REQUEST_URI'],'.xsl') === false){
|
2337 |
if(strpos($_SERVER['REQUEST_URI'],'jm-ajax') === false){
|
2338 |
|
2339 |
if(!empty($ct_options['use_ajax']))
|
2340 |
+
wp_enqueue_script('ct_nocache', plugins_url('/cleantalk-spam-protect/inc/cleantalk_nocache.js'), array(), APBCT_VERSION, 'in_footer');
|
2341 |
|
2342 |
if(!empty($ct_options['check_external']))
|
2343 |
+
wp_enqueue_script('ct_external', plugins_url('/cleantalk-spam-protect/js/cleantalk_external.js'), array('jquery'), APBCT_VERSION, 'in_footer');
|
2344 |
|
2345 |
if(!empty($ct_options['check_internal']))
|
2346 |
+
wp_enqueue_script('ct_internal', plugins_url('/cleantalk-spam-protect/js/cleantalk_internal.js'), array('jquery'), APBCT_VERSION, 'in_footer');
|
2347 |
|
2348 |
wp_localize_script('ct_nocache', 'ctNocache', array(
|
2349 |
'ajaxurl' => admin_url('admin-ajax.php'),
|
2362 |
$ajax_nonce = wp_create_nonce( "ct_secret_nonce" );
|
2363 |
$user_token = !empty($ct_data['user_token']) ? $ct_data['user_token'] : null;
|
2364 |
|
2365 |
+
wp_enqueue_style ('ct_public_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-public-admin.css'), array(), APBCT_VERSION, 'all');
|
2366 |
+
wp_enqueue_script('ct_public_admin_js', plugins_url('/cleantalk-spam-protect/js/cleantalk-public-admin.js'), array('jquery'), APBCT_VERSION, true);
|
2367 |
|
2368 |
wp_localize_script('ct_public_admin_js', 'ctPublic', array(
|
2369 |
'ct_ajax_nonce' => $ajax_nonce,
|
2377 |
}
|
2378 |
|
2379 |
if(!empty($ct_options['debug_ajax'])){
|
2380 |
+
wp_enqueue_script('ct_debug_js', plugins_url('/cleantalk-spam-protect/js/cleantalk-debug-ajax.js'), array('jquery'), APBCT_VERSION, true);
|
2381 |
}
|
2382 |
}
|
2383 |
|
inc/cleantalk-users.php
CHANGED
@@ -367,35 +367,9 @@ function ct_ajax_check_users(){
|
|
367 |
die();
|
368 |
}
|
369 |
|
370 |
-
$
|
371 |
|
372 |
-
|
373 |
-
$request['method_name'] = 'spam_check_cms';
|
374 |
-
$request['auth_key'] = $ct_options['apikey'];
|
375 |
-
$request['data'] = $data;
|
376 |
-
if(!empty($_POST['accurate_check']))
|
377 |
-
$request['date'] = $curr_date;
|
378 |
-
|
379 |
-
$url='https://api.cleantalk.org';
|
380 |
-
|
381 |
-
if(!function_exists('sendRawRequest'))
|
382 |
-
require_once('cleantalk.class.php');
|
383 |
-
|
384 |
-
$result=sendRawRequest($url, $request, false, 5);
|
385 |
-
|
386 |
-
if(empty($result)){
|
387 |
-
$check_result['error'] = 1;
|
388 |
-
$check_result['error_message'] = __('Connection error', 'cleantalk');
|
389 |
-
print json_encode($check_result);
|
390 |
-
}else{
|
391 |
-
|
392 |
-
$result = json_decode($result);
|
393 |
-
|
394 |
-
if(isset($result->error_message)){
|
395 |
-
$check_result['error'] = 1;
|
396 |
-
$check_result['error_message'] = __('Server response: ', 'cleantalk').$result->error_message;
|
397 |
-
print "Server response: ".$result->error_message;
|
398 |
-
}else{
|
399 |
|
400 |
// Opening CSV file
|
401 |
$current_user = wp_get_current_user();
|
@@ -428,10 +402,10 @@ function ct_ajax_check_users(){
|
|
428 |
$uip = $u[$i]->data->user_ip;
|
429 |
$uim = $u[$i]->data->user_email;
|
430 |
|
431 |
-
if(isset($result
|
432 |
$mark_spam_ip = true;
|
433 |
|
434 |
-
if(isset($result
|
435 |
$mark_spam_email = true;
|
436 |
|
437 |
if ($mark_spam_ip || $mark_spam_email){
|
@@ -446,7 +420,10 @@ function ct_ajax_check_users(){
|
|
446 |
fwrite($file_desc, $text);
|
447 |
fclose($file_desc);
|
448 |
print json_encode($check_result);
|
449 |
-
|
|
|
|
|
|
|
450 |
}
|
451 |
}else{
|
452 |
$check_result['end'] = 1;
|
367 |
die();
|
368 |
}
|
369 |
|
370 |
+
$result = CleantalkHelper::api_method__spam_check_cms($ct_options['apikey'], $data, !empty($_POST['accurate_check']) ? $curr_date : null);
|
371 |
|
372 |
+
if(empty($result['error'])){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
// Opening CSV file
|
375 |
$current_user = wp_get_current_user();
|
402 |
$uip = $u[$i]->data->user_ip;
|
403 |
$uim = $u[$i]->data->user_email;
|
404 |
|
405 |
+
if(isset($result[$uip]) && $result[$uip]['appears'] == 1)
|
406 |
$mark_spam_ip = true;
|
407 |
|
408 |
+
if(isset($result[$uim]) && $result[$uim]['appears'] == 1)
|
409 |
$mark_spam_email = true;
|
410 |
|
411 |
if ($mark_spam_ip || $mark_spam_email){
|
420 |
fwrite($file_desc, $text);
|
421 |
fclose($file_desc);
|
422 |
print json_encode($check_result);
|
423 |
+
}else{
|
424 |
+
$check_result['error'] = 1;
|
425 |
+
$check_result['error_message'] = $result['error_string'];
|
426 |
+
echo json_encode($check_result);
|
427 |
}
|
428 |
}else{
|
429 |
$check_result['end'] = 1;
|
inc/cleantalk.class.php → lib/Cleantalk.php
RENAMED
@@ -1,339 +1,4 @@
|
|
1 |
<?php
|
2 |
-
/**
|
3 |
-
* Cleantalk base class
|
4 |
-
*
|
5 |
-
* @version 2.1.4
|
6 |
-
* @package Cleantalk
|
7 |
-
* @subpackage Base
|
8 |
-
* @author Cleantalk team (welcome@cleantalk.org)
|
9 |
-
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
10 |
-
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
11 |
-
* @see https://github.com/CleanTalk/php-antispam
|
12 |
-
*
|
13 |
-
*/
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Response class
|
17 |
-
*/
|
18 |
-
class CleantalkResponse {
|
19 |
-
|
20 |
-
/**
|
21 |
-
* Received feedback nubmer
|
22 |
-
* @var int
|
23 |
-
*/
|
24 |
-
public $received = null;
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Is stop words
|
28 |
-
* @var int
|
29 |
-
*/
|
30 |
-
public $stop_words = null;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Cleantalk comment
|
34 |
-
* @var string
|
35 |
-
*/
|
36 |
-
public $comment = null;
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Is blacklisted
|
40 |
-
* @var int
|
41 |
-
*/
|
42 |
-
public $blacklisted = null;
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Is allow, 1|0
|
46 |
-
* @var int
|
47 |
-
*/
|
48 |
-
public $allow = null;
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Request ID
|
52 |
-
* @var int
|
53 |
-
*/
|
54 |
-
public $id = null;
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Request errno
|
58 |
-
* @var int
|
59 |
-
*/
|
60 |
-
public $errno = null;
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Error string
|
64 |
-
* @var string
|
65 |
-
*/
|
66 |
-
public $errstr = null;
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Is fast submit, 1|0
|
70 |
-
* @var string
|
71 |
-
*/
|
72 |
-
public $fast_submit = null;
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Is spam comment
|
76 |
-
* @var string
|
77 |
-
*/
|
78 |
-
public $spam = null;
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Is JS
|
82 |
-
* @var type
|
83 |
-
*/
|
84 |
-
public $js_disabled = null;
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Sms check
|
88 |
-
* @var type
|
89 |
-
*/
|
90 |
-
public $sms_allow = null;
|
91 |
-
|
92 |
-
/**
|
93 |
-
* Sms code result
|
94 |
-
* @var type
|
95 |
-
*/
|
96 |
-
public $sms = null;
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Sms error code
|
100 |
-
* @var type
|
101 |
-
*/
|
102 |
-
public $sms_error_code = null;
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Sms error code
|
106 |
-
* @var type
|
107 |
-
*/
|
108 |
-
public $sms_error_text = null;
|
109 |
-
|
110 |
-
/**
|
111 |
-
* Stop queue message, 1|0
|
112 |
-
* @var int
|
113 |
-
*/
|
114 |
-
public $stop_queue = null;
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Account shuld by deactivated after registration, 1|0
|
118 |
-
* @var int
|
119 |
-
*/
|
120 |
-
public $inactive = null;
|
121 |
-
|
122 |
-
/**
|
123 |
-
* Account status
|
124 |
-
* @var int
|
125 |
-
*/
|
126 |
-
public $account_status = -1;
|
127 |
-
|
128 |
-
/**
|
129 |
-
* Create server response
|
130 |
-
*
|
131 |
-
* @param type $response
|
132 |
-
* @param type $obj
|
133 |
-
*/
|
134 |
-
function __construct($response = null, $obj = null) {
|
135 |
-
if ($response && is_array($response) && count($response) > 0) {
|
136 |
-
foreach ($response as $param => $value) {
|
137 |
-
$this->{$param} = $value;
|
138 |
-
}
|
139 |
-
} else {
|
140 |
-
$this->errno = $obj->errno;
|
141 |
-
$this->errstr = $obj->errstr;
|
142 |
-
|
143 |
-
$this->errstr = preg_replace("/.+(\*\*\*.+\*\*\*).+/", "$1", $this->errstr);
|
144 |
-
|
145 |
-
$this->stop_words = isset($obj->stop_words) ? utf8_decode($obj->stop_words) : null;
|
146 |
-
$this->comment = isset($obj->comment) ? utf8_decode($obj->comment) : null;
|
147 |
-
$this->blacklisted = (isset($obj->blacklisted)) ? $obj->blacklisted : null;
|
148 |
-
$this->allow = (isset($obj->allow)) ? $obj->allow : 0;
|
149 |
-
$this->id = (isset($obj->id)) ? $obj->id : null;
|
150 |
-
$this->fast_submit = (isset($obj->fast_submit)) ? $obj->fast_submit : 0;
|
151 |
-
$this->spam = (isset($obj->spam)) ? $obj->spam : 0;
|
152 |
-
$this->js_disabled = (isset($obj->js_disabled)) ? $obj->js_disabled : 0;
|
153 |
-
$this->sms_allow = (isset($obj->sms_allow)) ? $obj->sms_allow : null;
|
154 |
-
$this->sms = (isset($obj->sms)) ? $obj->sms : null;
|
155 |
-
$this->sms_error_code = (isset($obj->sms_error_code)) ? $obj->sms_error_code : null;
|
156 |
-
$this->sms_error_text = (isset($obj->sms_error_text)) ? $obj->sms_error_text : null;
|
157 |
-
$this->stop_queue = (isset($obj->stop_queue)) ? $obj->stop_queue : 0;
|
158 |
-
$this->inactive = (isset($obj->inactive)) ? $obj->inactive : 0;
|
159 |
-
$this->account_status = (isset($obj->account_status)) ? $obj->account_status : -1;
|
160 |
-
$this->received = (isset($obj->received)) ? $obj->received : -1;
|
161 |
-
|
162 |
-
if ($this->errno !== 0 && $this->errstr !== null && $this->comment === null)
|
163 |
-
$this->comment = '*** ' . $this->errstr . ' Antispam service cleantalk.org ***';
|
164 |
-
}
|
165 |
-
}
|
166 |
-
|
167 |
-
}
|
168 |
-
|
169 |
-
/**
|
170 |
-
* Request class
|
171 |
-
*/
|
172 |
-
class CleantalkRequest {
|
173 |
-
|
174 |
-
/**
|
175 |
-
* All http request headers
|
176 |
-
* @var string
|
177 |
-
*/
|
178 |
-
public $all_headers = null;
|
179 |
-
|
180 |
-
/**
|
181 |
-
* IP address of connection
|
182 |
-
* @var string
|
183 |
-
*/
|
184 |
-
//public $remote_addr = null;
|
185 |
-
|
186 |
-
/**
|
187 |
-
* Last error number
|
188 |
-
* @var integer
|
189 |
-
*/
|
190 |
-
public $last_error_no = null;
|
191 |
-
|
192 |
-
/**
|
193 |
-
* Last error time
|
194 |
-
* @var integer
|
195 |
-
*/
|
196 |
-
public $last_error_time = null;
|
197 |
-
|
198 |
-
/**
|
199 |
-
* Last error text
|
200 |
-
* @var string
|
201 |
-
*/
|
202 |
-
public $last_error_text = null;
|
203 |
-
|
204 |
-
/**
|
205 |
-
* User message
|
206 |
-
* @var string
|
207 |
-
*/
|
208 |
-
public $message = null;
|
209 |
-
|
210 |
-
/**
|
211 |
-
* Post example with last comments
|
212 |
-
* @var string
|
213 |
-
*/
|
214 |
-
public $example = null;
|
215 |
-
|
216 |
-
/**
|
217 |
-
* Auth key
|
218 |
-
* @var string
|
219 |
-
*/
|
220 |
-
public $auth_key = null;
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Engine
|
224 |
-
* @var string
|
225 |
-
*/
|
226 |
-
public $agent = null;
|
227 |
-
|
228 |
-
/**
|
229 |
-
* Is check for stoplist,
|
230 |
-
* valid are 0|1
|
231 |
-
* @var int
|
232 |
-
*/
|
233 |
-
public $stoplist_check = null;
|
234 |
-
|
235 |
-
/**
|
236 |
-
* Language server response,
|
237 |
-
* valid are 'en' or 'ru'
|
238 |
-
* @var string
|
239 |
-
*/
|
240 |
-
public $response_lang = null;
|
241 |
-
|
242 |
-
/**
|
243 |
-
* User IP
|
244 |
-
* @var strings
|
245 |
-
*/
|
246 |
-
public $sender_ip = null;
|
247 |
-
|
248 |
-
/**
|
249 |
-
* User email
|
250 |
-
* @var strings
|
251 |
-
*/
|
252 |
-
public $sender_email = null;
|
253 |
-
|
254 |
-
/**
|
255 |
-
* User nickname
|
256 |
-
* @var string
|
257 |
-
*/
|
258 |
-
public $sender_nickname = null;
|
259 |
-
|
260 |
-
/**
|
261 |
-
* Sender info JSON string
|
262 |
-
* @var string
|
263 |
-
*/
|
264 |
-
public $sender_info = null;
|
265 |
-
|
266 |
-
/**
|
267 |
-
* Post info JSON string
|
268 |
-
* @var string
|
269 |
-
*/
|
270 |
-
public $post_info = null;
|
271 |
-
|
272 |
-
/**
|
273 |
-
* Is allow links, email and icq,
|
274 |
-
* valid are 1|0
|
275 |
-
* @var int
|
276 |
-
*/
|
277 |
-
public $allow_links = null;
|
278 |
-
|
279 |
-
/**
|
280 |
-
* Time form filling
|
281 |
-
* @var int
|
282 |
-
*/
|
283 |
-
public $submit_time = null;
|
284 |
-
|
285 |
-
public $x_forwarded_for = '';
|
286 |
-
public $x_real_ip = '';
|
287 |
-
|
288 |
-
/**
|
289 |
-
* Is enable Java Script,
|
290 |
-
* valid are 0|1|2
|
291 |
-
* Status:
|
292 |
-
* null - JS html code not inserted into phpBB templates
|
293 |
-
* 0 - JS disabled at the client browser
|
294 |
-
* 1 - JS enabled at the client broswer
|
295 |
-
* @var int
|
296 |
-
*/
|
297 |
-
public $js_on = null;
|
298 |
-
|
299 |
-
/**
|
300 |
-
* user time zone
|
301 |
-
* @var string
|
302 |
-
*/
|
303 |
-
public $tz = null;
|
304 |
-
|
305 |
-
/**
|
306 |
-
* Feedback string,
|
307 |
-
* valid are 'requset_id:(1|0)'
|
308 |
-
* @var string
|
309 |
-
*/
|
310 |
-
public $feedback = null;
|
311 |
-
|
312 |
-
/**
|
313 |
-
* Phone number
|
314 |
-
* @var type
|
315 |
-
*/
|
316 |
-
public $phone = null;
|
317 |
-
|
318 |
-
/**
|
319 |
-
* Method name
|
320 |
-
* @var string
|
321 |
-
*/
|
322 |
-
public $method_name = 'check_message';
|
323 |
-
|
324 |
-
/**
|
325 |
-
* Fill params with constructor
|
326 |
-
* @param type $params
|
327 |
-
*/
|
328 |
-
public function __construct($params = null) {
|
329 |
-
if (is_array($params) && count($params) > 0) {
|
330 |
-
foreach ($params as $param => $value) {
|
331 |
-
$this->{$param} = $value;
|
332 |
-
}
|
333 |
-
}
|
334 |
-
}
|
335 |
-
|
336 |
-
}
|
337 |
|
338 |
/**
|
339 |
* Cleantalk class create request
|
@@ -610,13 +275,11 @@ class Cleantalk {
|
|
610 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // resolve 'Expect: 100-continue' issue
|
611 |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // see http://stackoverflow.com/a/23322368
|
612 |
|
|
|
|
|
|
|
613 |
if ($this->ssl_on && $this->ssl_path != '') {
|
614 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
615 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
616 |
curl_setopt($ch, CURLOPT_CAINFO, $this->ssl_path);
|
617 |
-
}else{ // Disabling CA cert verivication and common name verification
|
618 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
619 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
620 |
}
|
621 |
|
622 |
$result = curl_exec($ch);
|
@@ -650,7 +313,7 @@ class Cleantalk {
|
|
650 |
}
|
651 |
}
|
652 |
|
653 |
-
if (!$result || !
|
654 |
$response = null;
|
655 |
$response['errno'] = 1;
|
656 |
if ($curl_error) {
|
@@ -1009,143 +672,8 @@ class Cleantalk {
|
|
1009 |
*/
|
1010 |
function stringFromUTF8($str, $data_codepage = null)
|
1011 |
{
|
1012 |
-
if (preg_match('
|
1013 |
return mb_convert_encoding($str, $data_codepage, 'UTF-8');
|
1014 |
return $str;
|
1015 |
}
|
1016 |
-
}
|
1017 |
-
/**
|
1018 |
-
* Function sends raw request to API server
|
1019 |
-
*
|
1020 |
-
* @param string url of API server
|
1021 |
-
* @param array data to send
|
1022 |
-
* @param boolean is data have to be JSON encoded or not
|
1023 |
-
* @param integer connect timeout
|
1024 |
-
* @return type
|
1025 |
-
*/
|
1026 |
-
|
1027 |
-
function sendRawRequest($url,$data,$isJSON=false,$timeout=3)
|
1028 |
-
{
|
1029 |
-
$result=null;
|
1030 |
-
if(!$isJSON)
|
1031 |
-
{
|
1032 |
-
$data=http_build_query($data);
|
1033 |
-
$data=str_replace("&", "&", $data);
|
1034 |
-
}
|
1035 |
-
else
|
1036 |
-
{
|
1037 |
-
$data= json_encode($data);
|
1038 |
-
}
|
1039 |
-
$curl_exec=false;
|
1040 |
-
if (function_exists('curl_init') && function_exists('json_decode'))
|
1041 |
-
{
|
1042 |
-
|
1043 |
-
$ch = curl_init();
|
1044 |
-
curl_setopt($ch, CURLOPT_URL, $url);
|
1045 |
-
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
1046 |
-
curl_setopt($ch, CURLOPT_POST, true);
|
1047 |
-
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
1048 |
-
|
1049 |
-
// receive server response ...
|
1050 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
1051 |
-
// resolve 'Expect: 100-continue' issue
|
1052 |
-
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
|
1053 |
-
|
1054 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
1055 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
1056 |
-
|
1057 |
-
$result = @curl_exec($ch);
|
1058 |
-
if($result!==false)
|
1059 |
-
{
|
1060 |
-
$curl_exec=true;
|
1061 |
-
}
|
1062 |
-
@curl_close($ch);
|
1063 |
-
}
|
1064 |
-
if(!$curl_exec)
|
1065 |
-
{
|
1066 |
-
$opts = array(
|
1067 |
-
'http'=>array(
|
1068 |
-
'method' => "POST",
|
1069 |
-
'timeout'=> $timeout,
|
1070 |
-
'content' => $data
|
1071 |
-
)
|
1072 |
-
);
|
1073 |
-
$context = stream_context_create($opts);
|
1074 |
-
$result = @file_get_contents($url, 0, $context);
|
1075 |
-
}
|
1076 |
-
return $result;
|
1077 |
-
}
|
1078 |
-
|
1079 |
-
// Creating apache_request_headers() if not exists
|
1080 |
-
if(!function_exists('apache_request_headers')){
|
1081 |
-
function apache_request_headers(){
|
1082 |
-
$arh = array();
|
1083 |
-
$rx_http = '/\AHTTP_/';
|
1084 |
-
foreach($_SERVER as $key => $val){
|
1085 |
-
if(preg_match($rx_http, $key)){
|
1086 |
-
$arh_key = preg_replace($rx_http, '', $key);
|
1087 |
-
// do some nasty string manipulations to restore the original letter case
|
1088 |
-
// this should work in most cases
|
1089 |
-
$rx_matches = array();
|
1090 |
-
$rx_matches = explode('_', $arh_key);
|
1091 |
-
if( count($rx_matches) > 0 and strlen($arh_key) > 2 ){
|
1092 |
-
foreach($rx_matches as $ak_key => $ak_val) $rx_matches[$ak_key] = ucfirst($ak_val);
|
1093 |
-
$arh_key = implode('-', $rx_matches);
|
1094 |
-
}
|
1095 |
-
$arh[$arh_key] = $val;
|
1096 |
-
}
|
1097 |
-
}
|
1098 |
-
return( $arh );
|
1099 |
-
}
|
1100 |
-
}
|
1101 |
-
|
1102 |
-
function cleantalk_is_JSON($string)
|
1103 |
-
{
|
1104 |
-
return ((is_string($string) && (is_object(json_decode($string)) || is_array(json_decode($string))))) ? true : false;
|
1105 |
-
}
|
1106 |
-
|
1107 |
-
// Patch for locale_get_display_region() for old PHP versions
|
1108 |
-
if( !function_exists('locale_get_display_region') ){
|
1109 |
-
function locale_get_display_region($locale){
|
1110 |
-
return $locale;
|
1111 |
-
}
|
1112 |
-
}
|
1113 |
-
|
1114 |
-
/*
|
1115 |
-
* From getID3() by James Heinrich <info@getid3.org> under GNU GPL
|
1116 |
-
*/
|
1117 |
-
if(!function_exists('utf8_decode')){
|
1118 |
-
function utf8_decode($string){
|
1119 |
-
$newcharstring = '';
|
1120 |
-
$offset = 0;
|
1121 |
-
$stringlength = strlen($string);
|
1122 |
-
while ($offset < $stringlength) {
|
1123 |
-
if ((ord($string{$offset}) | 0x07) == 0xF7) {
|
1124 |
-
$charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
|
1125 |
-
((ord($string{($offset + 1)}) & 0x3F) << 12) &
|
1126 |
-
((ord($string{($offset + 2)}) & 0x3F) << 6) &
|
1127 |
-
(ord($string{($offset + 3)}) & 0x3F);
|
1128 |
-
$offset += 4;
|
1129 |
-
} elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
|
1130 |
-
$charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
|
1131 |
-
((ord($string{($offset + 1)}) & 0x3F) << 6) &
|
1132 |
-
(ord($string{($offset + 2)}) & 0x3F);
|
1133 |
-
$offset += 3;
|
1134 |
-
} elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
|
1135 |
-
$charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
|
1136 |
-
(ord($string{($offset + 1)}) & 0x3F);
|
1137 |
-
$offset += 2;
|
1138 |
-
} elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
|
1139 |
-
$charval = ord($string{$offset});
|
1140 |
-
$offset += 1;
|
1141 |
-
} else {
|
1142 |
-
$charval = false;
|
1143 |
-
$offset += 1;
|
1144 |
-
}
|
1145 |
-
if ($charval !== false) {
|
1146 |
-
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
|
1147 |
-
}
|
1148 |
-
}
|
1149 |
-
return $newcharstring;
|
1150 |
-
}
|
1151 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Cleantalk class create request
|
275 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // resolve 'Expect: 100-continue' issue
|
276 |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // see http://stackoverflow.com/a/23322368
|
277 |
|
278 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disabling CA cert verivication and
|
279 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // Disabling common name verification
|
280 |
+
|
281 |
if ($this->ssl_on && $this->ssl_path != '') {
|
|
|
|
|
282 |
curl_setopt($ch, CURLOPT_CAINFO, $this->ssl_path);
|
|
|
|
|
|
|
283 |
}
|
284 |
|
285 |
$result = curl_exec($ch);
|
313 |
}
|
314 |
}
|
315 |
|
316 |
+
if (!$result || !CleantalkHelper::is_json($result)) {
|
317 |
$response = null;
|
318 |
$response['errno'] = 1;
|
319 |
if ($curl_error) {
|
672 |
*/
|
673 |
function stringFromUTF8($str, $data_codepage = null)
|
674 |
{
|
675 |
+
if (preg_match('u', $str) && function_exists('mb_convert_encoding') && $data_codepage !== null)
|
676 |
return mb_convert_encoding($str, $data_codepage, 'UTF-8');
|
677 |
return $str;
|
678 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
679 |
}
|
lib/CleantalkHelper.php
CHANGED
@@ -6,144 +6,135 @@ class CleantalkHelper
|
|
6 |
|
7 |
public static $cdn_pool = array(
|
8 |
'cloud_flare' => array(
|
9 |
-
'
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
),
|
24 |
);
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
/*
|
27 |
* Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)
|
28 |
* reutrns array('remote_addr' => 'val', ['x_forwarded_for' => 'val', ['x_real_ip' => 'val', ['cloud_flare' => 'val']]])
|
29 |
*/
|
30 |
-
static public function
|
31 |
{
|
32 |
-
$
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
);
|
38 |
-
$headers = self::get_request_headers();
|
39 |
-
|
40 |
-
// Getting IP
|
41 |
|
42 |
// REMOTE_ADDR
|
43 |
-
$ips['remote_addr']
|
|
|
|
|
44 |
|
45 |
// X-Forwarded-For
|
46 |
-
if(
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
}
|
50 |
|
51 |
// X-Real-Ip
|
52 |
-
if(isset($
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
}
|
56 |
|
57 |
// Cloud Flare
|
58 |
-
if(isset($
|
59 |
-
|
60 |
-
if(
|
61 |
$ips['cloud_flare'] = $headers['Cf_Connecting_Ip'];
|
62 |
-
break;
|
63 |
}
|
64 |
}
|
65 |
}
|
66 |
|
67 |
-
//
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
// REMOTE_ADDR
|
85 |
-
$ip = $_SERVER['REMOTE_ADDR'];
|
86 |
-
|
87 |
-
// Cloud Flare
|
88 |
-
if(isset($headers['Cf_Connecting_Ip'])){
|
89 |
-
foreach(self::$cdn_pool['cloud_flare'] as $cidr){
|
90 |
-
if($this->ip_mask_match($ips['remote_addr'], $cidr)){
|
91 |
-
$ip = $headers['Cf_Connecting_Ip'];
|
92 |
-
break;
|
93 |
}
|
94 |
}
|
95 |
}
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
{
|
103 |
-
if(isset($_SERVER['REMOTE_ADDR'])){
|
104 |
-
$ip = $_SERVER['REMOTE_ADDR'];
|
105 |
-
}
|
106 |
-
return isset($ip) && self::ip_validate($ip) ? $ip : null;
|
107 |
-
}
|
108 |
-
|
109 |
-
// Return validated X-Forwarded-For
|
110 |
-
static public function get_ip_x_forwarded_for()
|
111 |
-
{
|
112 |
-
$headers = self::get_request_headers();
|
113 |
-
if(isset($headers['X-Forwarded-For'])){
|
114 |
-
$tmp = explode(',', trim($headers['X-Forwarded-For']));
|
115 |
-
$ip = trim($tmp[0]);
|
116 |
-
}
|
117 |
-
return isset($ip) && self::ip_validate($ip) ? $ip : null;
|
118 |
-
}
|
119 |
-
|
120 |
-
// Return validated X-Real-Ip
|
121 |
-
static public function get_ip_x_real_ip()
|
122 |
-
{
|
123 |
-
$headers = self::get_request_headers();
|
124 |
-
if(isset($headers['X-Real-Ip'])){
|
125 |
-
$tmp = explode(',', trim($headers['X-Real-Ip']));
|
126 |
-
$ip = trim($tmp[0]);
|
127 |
-
}
|
128 |
-
return isset($ip) && self::ip_validate($ip) ? $ip : null;
|
129 |
-
}
|
130 |
-
|
131 |
-
// Return validated Cloud Flare
|
132 |
-
static public function get_ip_cloud_flare()
|
133 |
-
{
|
134 |
-
$headers = self::get_request_headers();
|
135 |
-
if(isset($headers['Cf_Connecting_Ip'])){
|
136 |
-
foreach(self::$cdn_pool['cloud_flare'] as $cidr){
|
137 |
-
if($this->ip_mask_match($_SERVER['remote_addr'], $cidr)){
|
138 |
-
$ip = $headers['Cf_Connecting_Ip'];
|
139 |
-
break;
|
140 |
-
}
|
141 |
}
|
142 |
}
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
}
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
146 |
static public function ip_mask_match($ip, $cidr){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
$exploded = explode ('/', $cidr);
|
148 |
$net = $exploded[0];
|
149 |
$mask = 4294967295 << (32 - $exploded[1]);
|
@@ -157,61 +148,50 @@ class CleantalkHelper
|
|
157 |
*/
|
158 |
static public function ip_validate($ip)
|
159 |
{
|
160 |
-
// IPv4
|
161 |
-
if(filter_var($ip, FILTER_VALIDATE_IP,
|
162 |
-
|
163 |
-
// IPv6
|
164 |
-
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
|
165 |
-
return 'v6';
|
166 |
-
// Unknown
|
167 |
-
return false;
|
168 |
}
|
169 |
|
170 |
-
/*
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
{
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
$headers[$server_key] = $val;
|
189 |
-
}
|
190 |
-
}
|
191 |
-
return $headers;
|
192 |
}
|
193 |
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
static public function get_2s_blacklists_db($api_key, $do_check = true)
|
202 |
-
{
|
203 |
$request = array(
|
204 |
'agent' => APBCT_AGENT,
|
205 |
'method_name' => '2s_blacklists_db',
|
206 |
'auth_key' => $api_key,
|
207 |
);
|
208 |
|
209 |
-
$result = self::
|
210 |
-
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
/**
|
216 |
* Function gets access key automatically
|
217 |
*
|
@@ -220,7 +200,7 @@ class CleantalkHelper
|
|
220 |
* @param string website platform
|
221 |
* @return type
|
222 |
*/
|
223 |
-
static public function
|
224 |
{
|
225 |
$request = array(
|
226 |
'method_name' => 'get_api_key',
|
@@ -232,8 +212,8 @@ class CleantalkHelper
|
|
232 |
'product_name' => 'antispam',
|
233 |
);
|
234 |
|
235 |
-
$result = self::
|
236 |
-
// $result = $do_check ? self::
|
237 |
|
238 |
return $result;
|
239 |
}
|
@@ -244,7 +224,7 @@ class CleantalkHelper
|
|
244 |
* @param string api_key
|
245 |
* @return type
|
246 |
*/
|
247 |
-
static public function
|
248 |
{
|
249 |
$request = array(
|
250 |
'agent' => APBCT_AGENT,
|
@@ -253,8 +233,8 @@ class CleantalkHelper
|
|
253 |
'path_to_cms' => $path_to_cms
|
254 |
);
|
255 |
|
256 |
-
$result = self::
|
257 |
-
$result = $do_check ? self::
|
258 |
|
259 |
return $result;
|
260 |
}
|
@@ -265,7 +245,7 @@ class CleantalkHelper
|
|
265 |
* @param string api_key
|
266 |
* @return type
|
267 |
*/
|
268 |
-
static public function
|
269 |
{
|
270 |
$request = array(
|
271 |
'agent' => APBCT_AGENT,
|
@@ -273,8 +253,8 @@ class CleantalkHelper
|
|
273 |
'auth_key' => $api_key
|
274 |
);
|
275 |
|
276 |
-
$result = self::
|
277 |
-
$result = $do_check ? self::
|
278 |
|
279 |
return $result;
|
280 |
}
|
@@ -286,7 +266,7 @@ class CleantalkHelper
|
|
286 |
* @param integer report days
|
287 |
* @return type
|
288 |
*/
|
289 |
-
static public function
|
290 |
{
|
291 |
$request=Array(
|
292 |
'agent' => APBCT_AGENT,
|
@@ -295,8 +275,8 @@ class CleantalkHelper
|
|
295 |
'period' => $period
|
296 |
);
|
297 |
|
298 |
-
$result = self::
|
299 |
-
// $result = $do_check ? self::
|
300 |
|
301 |
return $result;
|
302 |
}
|
@@ -308,7 +288,7 @@ class CleantalkHelper
|
|
308 |
* @param integer report days
|
309 |
* @return type
|
310 |
*/
|
311 |
-
static public function
|
312 |
{
|
313 |
|
314 |
$request = array(
|
@@ -317,8 +297,8 @@ class CleantalkHelper
|
|
317 |
'auth_key' => $api_key,
|
318 |
);
|
319 |
|
320 |
-
$result = self::
|
321 |
-
$result = $do_check ? self::
|
322 |
|
323 |
$tmp = array();
|
324 |
for( $i = 0; $i < 7; $i++ )
|
@@ -330,11 +310,47 @@ class CleantalkHelper
|
|
330 |
return $result;
|
331 |
}
|
332 |
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
{
|
|
|
335 |
$result = null;
|
336 |
$curl_error = false;
|
337 |
|
|
|
|
|
338 |
if(!$isJSON){
|
339 |
$data = http_build_query($data);
|
340 |
$data = str_replace("&", "&", $data);
|
@@ -362,8 +378,7 @@ class CleantalkHelper
|
|
362 |
|
363 |
if($result === false){
|
364 |
if($ssl === false){
|
365 |
-
$
|
366 |
-
return self::sendRawRequest($args[0], $args[1], $isJSON, $timeout, true);
|
367 |
}
|
368 |
$curl_error = curl_error($ch);
|
369 |
}
|
@@ -388,7 +403,7 @@ class CleantalkHelper
|
|
388 |
}
|
389 |
|
390 |
if(!$result && $curl_error)
|
391 |
-
return array('error' => true, 'error_string' => $curl_error);
|
392 |
|
393 |
return $result;
|
394 |
}
|
@@ -400,8 +415,9 @@ class CleantalkHelper
|
|
400 |
* @param string request_method
|
401 |
* @return mixed (array || array('error' => true))
|
402 |
*/
|
403 |
-
static public function
|
404 |
-
{
|
|
|
405 |
// Errors handling
|
406 |
|
407 |
// Bad connection
|
@@ -421,6 +437,14 @@ class CleantalkHelper
|
|
421 |
);
|
422 |
}
|
423 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
// Server errors
|
425 |
if($result && (isset($result['error_no']) || isset($result['error_message']))){
|
426 |
return array(
|
@@ -538,4 +562,9 @@ class CleantalkHelper
|
|
538 |
|
539 |
update_option('cleantalk_data', $ct_data);
|
540 |
}
|
|
|
|
|
|
|
|
|
|
|
541 |
}
|
6 |
|
7 |
public static $cdn_pool = array(
|
8 |
'cloud_flare' => array(
|
9 |
+
'ipv4' => array(
|
10 |
+
'103.21.244.0/22',
|
11 |
+
'103.22.200.0/22',
|
12 |
+
'103.31.4.0/22',
|
13 |
+
'104.16.0.0/12',
|
14 |
+
'108.162.192.0/18',
|
15 |
+
'131.0.72.0/22',
|
16 |
+
'141.101.64.0/18',
|
17 |
+
'162.158.0.0/15',
|
18 |
+
'172.64.0.0/13',
|
19 |
+
'173.245.48.0/20',
|
20 |
+
'188.114.96.0/20',
|
21 |
+
'190.93.240.0/20',
|
22 |
+
'197.234.240.0/22',
|
23 |
+
'198.41.128.0/17',
|
24 |
+
),
|
25 |
+
'ipv6' => array(
|
26 |
+
'2400:cb00::/32',
|
27 |
+
'2405:8100::/32',
|
28 |
+
'2405:b500::/32',
|
29 |
+
'2606:4700::/32',
|
30 |
+
'2803:f800::/32',
|
31 |
+
'2c0f:f248::/32',
|
32 |
+
'2a06:98c0::/29',
|
33 |
+
),
|
34 |
),
|
35 |
);
|
36 |
|
37 |
+
public static $private_networks = array(
|
38 |
+
'10.0.0.0/8',
|
39 |
+
'100.64.0.0/10',
|
40 |
+
'172.16.0.0/12',
|
41 |
+
'192.168.0.0/16',
|
42 |
+
'127.0.0.1/32',
|
43 |
+
);
|
44 |
+
|
45 |
/*
|
46 |
* Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)
|
47 |
* reutrns array('remote_addr' => 'val', ['x_forwarded_for' => 'val', ['x_real_ip' => 'val', ['cloud_flare' => 'val']]])
|
48 |
*/
|
49 |
+
static public function ip_get($ips_input = array('real', 'remote_addr', 'x_forwarded_for', 'x_real_ip', 'cloud_flare'), $ips = array())
|
50 |
{
|
51 |
+
foreach($ips_input as $ip_type){
|
52 |
+
$ips[$ip_type] = '';
|
53 |
+
} unset($ip_type);
|
54 |
+
|
55 |
+
$headers = apache_request_headers();
|
|
|
|
|
|
|
|
|
56 |
|
57 |
// REMOTE_ADDR
|
58 |
+
if(isset($ips['remote_addr'])){
|
59 |
+
$ips['remote_addr'] = $_SERVER['REMOTE_ADDR'];
|
60 |
+
}
|
61 |
|
62 |
// X-Forwarded-For
|
63 |
+
if(isset($ips['x_forwarded_for'])){
|
64 |
+
if(isset($headers['X-Forwarded-For'])){
|
65 |
+
$tmp = explode(",", trim($headers['X-Forwarded-For']));
|
66 |
+
$ips['x_forwarded_for']= trim($tmp[0]);
|
67 |
+
}
|
68 |
}
|
69 |
|
70 |
// X-Real-Ip
|
71 |
+
if(isset($ips['x_real_ip'])){
|
72 |
+
if(isset($headers['X-Real-Ip'])){
|
73 |
+
$tmp = explode(",", trim($headers['X-Real-Ip']));
|
74 |
+
$ips['x_real_ip']= trim($tmp[0]);
|
75 |
+
}
|
76 |
}
|
77 |
|
78 |
// Cloud Flare
|
79 |
+
if(isset($ips['cloud_flare'])){
|
80 |
+
if(isset($headers['Cf_Connecting_Ip'])){
|
81 |
+
if(self::ip_mask_match($ips['remote_addr'], self::$cdn_pool['cloud_flare']['ipv4'])){
|
82 |
$ips['cloud_flare'] = $headers['Cf_Connecting_Ip'];
|
|
|
83 |
}
|
84 |
}
|
85 |
}
|
86 |
|
87 |
+
// Getting real IP from REMOTE_ADDR or Cf_Connecting_Ip if set or from (X-Forwarded-For, X-Real-Ip) if REMOTE_ADDR is local.
|
88 |
+
if(isset($ips['real'])){
|
89 |
+
|
90 |
+
$ips['real'] = $_SERVER['REMOTE_ADDR'];
|
91 |
+
|
92 |
+
// Cloud Flare
|
93 |
+
if(isset($headers['Cf_Connecting_Ip'])){
|
94 |
+
if(self::ip_mask_match($ips['real'], self::$cdn_pool['cloud_flare']['ipv4'])){
|
95 |
+
$ips['real'] = $headers['Cf_Connecting_Ip'];
|
96 |
+
}
|
97 |
+
// Private networks. Looking for X-Forwarded-For and X-Real-Ip
|
98 |
+
}elseif(self::ip_mask_match($ips['real'], self::$private_networks)){
|
99 |
+
if(isset($headers['X-Forwarded-For'])){
|
100 |
+
$ips['real'] = $headers['X-Forwarded-For'];
|
101 |
+
}elseif(isset($headers['X-Real-Ip'])){
|
102 |
+
$ips['real'] = $headers['X-Real-Ip'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
}
|
104 |
}
|
105 |
}
|
106 |
|
107 |
+
// Validating IPs
|
108 |
+
$result = array();
|
109 |
+
foreach($ips as $key => $ip){
|
110 |
+
if($ip && self::ip_validate($ip) == 'v4'){
|
111 |
+
$result[$key] = $ip;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
}
|
114 |
+
|
115 |
+
$result = array_unique($result);
|
116 |
+
|
117 |
+
return count($ips_input) > 1
|
118 |
+
? $result
|
119 |
+
: (reset($result) !== false
|
120 |
+
? reset($result)
|
121 |
+
: null);
|
122 |
}
|
123 |
+
|
124 |
+
/*
|
125 |
+
* Check if the IP belong to mask. Recursivly if array given
|
126 |
+
* @param ip string
|
127 |
+
* @param cird mixed (string|array of strings)
|
128 |
+
*/
|
129 |
static public function ip_mask_match($ip, $cidr){
|
130 |
+
if(is_array($cidr)){
|
131 |
+
foreach($cidr as $curr_mask){
|
132 |
+
if(self::ip_mask_match($ip, $curr_mask)){
|
133 |
+
return true;
|
134 |
+
}
|
135 |
+
} unset($curr_mask);
|
136 |
+
return false;
|
137 |
+
}
|
138 |
$exploded = explode ('/', $cidr);
|
139 |
$net = $exploded[0];
|
140 |
$mask = 4294967295 << (32 - $exploded[1]);
|
148 |
*/
|
149 |
static public function ip_validate($ip)
|
150 |
{
|
151 |
+
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) return 'v4'; // IPv4
|
152 |
+
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) return 'v6'; // IPv6
|
153 |
+
return false; // Unknown
|
|
|
|
|
|
|
|
|
|
|
154 |
}
|
155 |
|
156 |
+
/*
|
157 |
+
* Wrapper for sfw_logs API method
|
158 |
+
*
|
159 |
+
* returns mixed STRING || array('error' => true, 'error_string' => STRING)
|
160 |
+
*/
|
161 |
+
static public function api_method__sfw_logs($api_key, $data, $do_check = true){
|
162 |
+
|
163 |
+
$request = array(
|
164 |
+
'auth_key' => $api_key,
|
165 |
+
'method_name' => 'sfw_logs',
|
166 |
+
'data' => json_encode($data),
|
167 |
+
'rows' => count($data),
|
168 |
+
'timestamp' => time()
|
169 |
+
);
|
170 |
+
$result = self::api_send_request($request);
|
171 |
+
$result = $do_check ? self::api_check_response($result, 'sfw_logs') : $result;
|
172 |
+
|
173 |
+
return $result;
|
|
|
|
|
|
|
|
|
174 |
}
|
175 |
|
176 |
+
/*
|
177 |
+
* Wrapper for 2s_blacklists_db API method
|
178 |
+
*
|
179 |
+
* returns mixed STRING || array('error' => true, 'error_string' => STRING)
|
180 |
+
*/
|
181 |
+
static public function api_method__get_2s_blacklists_db($api_key, $do_check = true){
|
182 |
+
|
|
|
|
|
183 |
$request = array(
|
184 |
'agent' => APBCT_AGENT,
|
185 |
'method_name' => '2s_blacklists_db',
|
186 |
'auth_key' => $api_key,
|
187 |
);
|
188 |
|
189 |
+
$result = self::api_send_request($request);
|
190 |
+
$result = $do_check ? self::api_check_response($result, '2s_blacklists_db') : $result;
|
191 |
|
192 |
+
return $result;
|
193 |
+
}
|
194 |
+
|
195 |
/**
|
196 |
* Function gets access key automatically
|
197 |
*
|
200 |
* @param string website platform
|
201 |
* @return type
|
202 |
*/
|
203 |
+
static public function api_method__get_api_key($email, $host, $platform, $timezone = null, $do_check = true)
|
204 |
{
|
205 |
$request = array(
|
206 |
'method_name' => 'get_api_key',
|
212 |
'product_name' => 'antispam',
|
213 |
);
|
214 |
|
215 |
+
$result = self::api_send_request($request);
|
216 |
+
// $result = $do_check ? self::api_check_response($result, 'get_api_key') : $result;
|
217 |
|
218 |
return $result;
|
219 |
}
|
224 |
* @param string api_key
|
225 |
* @return type
|
226 |
*/
|
227 |
+
static public function api_method__notice_validate_key($api_key, $path_to_cms, $do_check = true)
|
228 |
{
|
229 |
$request = array(
|
230 |
'agent' => APBCT_AGENT,
|
233 |
'path_to_cms' => $path_to_cms
|
234 |
);
|
235 |
|
236 |
+
$result = self::api_send_request($request);
|
237 |
+
$result = $do_check ? self::api_check_response($result, 'notice_validate_key') : $result;
|
238 |
|
239 |
return $result;
|
240 |
}
|
245 |
* @param string api_key
|
246 |
* @return type
|
247 |
*/
|
248 |
+
static public function api_method__notice_paid_till($api_key, $do_check = true)
|
249 |
{
|
250 |
$request = array(
|
251 |
'agent' => APBCT_AGENT,
|
253 |
'auth_key' => $api_key
|
254 |
);
|
255 |
|
256 |
+
$result = self::api_send_request($request);
|
257 |
+
$result = $do_check ? self::api_check_response($result, 'notice_paid_till') : $result;
|
258 |
|
259 |
return $result;
|
260 |
}
|
266 |
* @param integer report days
|
267 |
* @return type
|
268 |
*/
|
269 |
+
static public function api_method__get_antispam_report($host, $period = 1)
|
270 |
{
|
271 |
$request=Array(
|
272 |
'agent' => APBCT_AGENT,
|
275 |
'period' => $period
|
276 |
);
|
277 |
|
278 |
+
$result = self::api_send_request($request);
|
279 |
+
// $result = $do_check ? self::api_check_response($result, 'get_antispam_report') : $result;
|
280 |
|
281 |
return $result;
|
282 |
}
|
288 |
* @param integer report days
|
289 |
* @return type
|
290 |
*/
|
291 |
+
static public function api_method__get_antispam_report_breif($api_key, $do_check = true)
|
292 |
{
|
293 |
|
294 |
$request = array(
|
297 |
'auth_key' => $api_key,
|
298 |
);
|
299 |
|
300 |
+
$result = self::api_send_request($request);
|
301 |
+
$result = $do_check ? self::api_check_response($result, 'get_antispam_report_breif') : $result;
|
302 |
|
303 |
$tmp = array();
|
304 |
for( $i = 0; $i < 7; $i++ )
|
310 |
return $result;
|
311 |
}
|
312 |
|
313 |
+
/**
|
314 |
+
* Function gets spam report
|
315 |
+
*
|
316 |
+
* @param string website host
|
317 |
+
* @param integer report days
|
318 |
+
* @return type
|
319 |
+
*/
|
320 |
+
static public function api_method__spam_check_cms($api_key, $data, $date = null, $do_check = true)
|
321 |
+
{
|
322 |
+
$request=Array(
|
323 |
+
'agent' => APBCT_AGENT,
|
324 |
+
'method_name' => 'spam_check_cms',
|
325 |
+
'auth_key' => $api_key,
|
326 |
+
'data' => is_array($data) ? implode(',',$data) : $data,
|
327 |
+
);
|
328 |
+
|
329 |
+
if($date) $request['date'] = $date;
|
330 |
+
|
331 |
+
$result = self::api_send_request($request);
|
332 |
+
$result = $do_check ? self::api_check_response($result, 'spam_check_cms') : $result;
|
333 |
+
|
334 |
+
return $result;
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Function sends raw request to API server
|
339 |
+
*
|
340 |
+
* @param string url of API server
|
341 |
+
* @param array data to send
|
342 |
+
* @param boolean is data have to be JSON encoded or not
|
343 |
+
* @param integer connect timeout
|
344 |
+
* @return type
|
345 |
+
*/
|
346 |
+
static public function api_send_request($data, $url = self::URL, $isJSON = false, $timeout=3, $ssl = false)
|
347 |
{
|
348 |
+
|
349 |
$result = null;
|
350 |
$curl_error = false;
|
351 |
|
352 |
+
$original_data = $data;
|
353 |
+
|
354 |
if(!$isJSON){
|
355 |
$data = http_build_query($data);
|
356 |
$data = str_replace("&", "&", $data);
|
378 |
|
379 |
if($result === false){
|
380 |
if($ssl === false){
|
381 |
+
return self::sendRawRequest($url, $original_data, $isJSON, $timeout, true);
|
|
|
382 |
}
|
383 |
$curl_error = curl_error($ch);
|
384 |
}
|
403 |
}
|
404 |
|
405 |
if(!$result && $curl_error)
|
406 |
+
return json_encode(array('error' => true, 'error_string' => $curl_error));
|
407 |
|
408 |
return $result;
|
409 |
}
|
415 |
* @param string request_method
|
416 |
* @return mixed (array || array('error' => true))
|
417 |
*/
|
418 |
+
static public function api_check_response($result, $method_name = null)
|
419 |
+
{
|
420 |
+
|
421 |
// Errors handling
|
422 |
|
423 |
// Bad connection
|
437 |
);
|
438 |
}
|
439 |
|
440 |
+
// cURL error
|
441 |
+
if(!empty($result['error'])){
|
442 |
+
return array(
|
443 |
+
'error' => true,
|
444 |
+
'error_string' => 'CONNECTION_ERROR: ' . $result['error_string'],
|
445 |
+
);
|
446 |
+
}
|
447 |
+
|
448 |
// Server errors
|
449 |
if($result && (isset($result['error_no']) || isset($result['error_message']))){
|
450 |
return array(
|
562 |
|
563 |
update_option('cleantalk_data', $ct_data);
|
564 |
}
|
565 |
+
|
566 |
+
static public function is_json($string)
|
567 |
+
{
|
568 |
+
return is_string($string) && is_array(json_decode($string, true)) ? true : false;
|
569 |
+
}
|
570 |
}
|
lib/CleantalkRequest.php
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Request class
|
5 |
+
*/
|
6 |
+
class CleantalkRequest {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* All http request headers
|
10 |
+
* @var string
|
11 |
+
*/
|
12 |
+
public $all_headers = null;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* IP address of connection
|
16 |
+
* @var string
|
17 |
+
*/
|
18 |
+
//public $remote_addr = null;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Last error number
|
22 |
+
* @var integer
|
23 |
+
*/
|
24 |
+
public $last_error_no = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Last error time
|
28 |
+
* @var integer
|
29 |
+
*/
|
30 |
+
public $last_error_time = null;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Last error text
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
+
public $last_error_text = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* User message
|
40 |
+
* @var string
|
41 |
+
*/
|
42 |
+
public $message = null;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Post example with last comments
|
46 |
+
* @var string
|
47 |
+
*/
|
48 |
+
public $example = null;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Auth key
|
52 |
+
* @var string
|
53 |
+
*/
|
54 |
+
public $auth_key = null;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Engine
|
58 |
+
* @var string
|
59 |
+
*/
|
60 |
+
public $agent = null;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Is check for stoplist,
|
64 |
+
* valid are 0|1
|
65 |
+
* @var int
|
66 |
+
*/
|
67 |
+
public $stoplist_check = null;
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Language server response,
|
71 |
+
* valid are 'en' or 'ru'
|
72 |
+
* @var string
|
73 |
+
*/
|
74 |
+
public $response_lang = null;
|
75 |
+
|
76 |
+
/**
|
77 |
+
* User IP
|
78 |
+
* @var strings
|
79 |
+
*/
|
80 |
+
public $sender_ip = null;
|
81 |
+
|
82 |
+
/**
|
83 |
+
* User email
|
84 |
+
* @var strings
|
85 |
+
*/
|
86 |
+
public $sender_email = null;
|
87 |
+
|
88 |
+
/**
|
89 |
+
* User nickname
|
90 |
+
* @var string
|
91 |
+
*/
|
92 |
+
public $sender_nickname = null;
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Sender info JSON string
|
96 |
+
* @var string
|
97 |
+
*/
|
98 |
+
public $sender_info = null;
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Post info JSON string
|
102 |
+
* @var string
|
103 |
+
*/
|
104 |
+
public $post_info = null;
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Is allow links, email and icq,
|
108 |
+
* valid are 1|0
|
109 |
+
* @var int
|
110 |
+
*/
|
111 |
+
public $allow_links = null;
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Time form filling
|
115 |
+
* @var int
|
116 |
+
*/
|
117 |
+
public $submit_time = null;
|
118 |
+
|
119 |
+
public $x_forwarded_for = '';
|
120 |
+
public $x_real_ip = '';
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Is enable Java Script,
|
124 |
+
* valid are 0|1|2
|
125 |
+
* Status:
|
126 |
+
* null - JS html code not inserted into phpBB templates
|
127 |
+
* 0 - JS disabled at the client browser
|
128 |
+
* 1 - JS enabled at the client broswer
|
129 |
+
* @var int
|
130 |
+
*/
|
131 |
+
public $js_on = null;
|
132 |
+
|
133 |
+
/**
|
134 |
+
* user time zone
|
135 |
+
* @var string
|
136 |
+
*/
|
137 |
+
public $tz = null;
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Feedback string,
|
141 |
+
* valid are 'requset_id:(1|0)'
|
142 |
+
* @var string
|
143 |
+
*/
|
144 |
+
public $feedback = null;
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Phone number
|
148 |
+
* @var type
|
149 |
+
*/
|
150 |
+
public $phone = null;
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Method name
|
154 |
+
* @var string
|
155 |
+
*/
|
156 |
+
public $method_name = 'check_message';
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Fill params with constructor
|
160 |
+
* @param type $params
|
161 |
+
*/
|
162 |
+
public function __construct($params = null) {
|
163 |
+
if (is_array($params) && count($params) > 0) {
|
164 |
+
foreach ($params as $param => $value) {
|
165 |
+
$this->{$param} = $value;
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
}
|
lib/CleantalkResponse.php
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Response class
|
5 |
+
*/
|
6 |
+
class CleantalkResponse {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Received feedback nubmer
|
10 |
+
* @var int
|
11 |
+
*/
|
12 |
+
public $received = null;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Is stop words
|
16 |
+
* @var int
|
17 |
+
*/
|
18 |
+
public $stop_words = null;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Cleantalk comment
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
public $comment = null;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Is blacklisted
|
28 |
+
* @var int
|
29 |
+
*/
|
30 |
+
public $blacklisted = null;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Is allow, 1|0
|
34 |
+
* @var int
|
35 |
+
*/
|
36 |
+
public $allow = null;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Request ID
|
40 |
+
* @var int
|
41 |
+
*/
|
42 |
+
public $id = null;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Request errno
|
46 |
+
* @var int
|
47 |
+
*/
|
48 |
+
public $errno = null;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Error string
|
52 |
+
* @var string
|
53 |
+
*/
|
54 |
+
public $errstr = null;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Is fast submit, 1|0
|
58 |
+
* @var string
|
59 |
+
*/
|
60 |
+
public $fast_submit = null;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Is spam comment
|
64 |
+
* @var string
|
65 |
+
*/
|
66 |
+
public $spam = null;
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Is JS
|
70 |
+
* @var type
|
71 |
+
*/
|
72 |
+
public $js_disabled = null;
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Sms check
|
76 |
+
* @var type
|
77 |
+
*/
|
78 |
+
public $sms_allow = null;
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Sms code result
|
82 |
+
* @var type
|
83 |
+
*/
|
84 |
+
public $sms = null;
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Sms error code
|
88 |
+
* @var type
|
89 |
+
*/
|
90 |
+
public $sms_error_code = null;
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Sms error code
|
94 |
+
* @var type
|
95 |
+
*/
|
96 |
+
public $sms_error_text = null;
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Stop queue message, 1|0
|
100 |
+
* @var int
|
101 |
+
*/
|
102 |
+
public $stop_queue = null;
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Account shuld by deactivated after registration, 1|0
|
106 |
+
* @var int
|
107 |
+
*/
|
108 |
+
public $inactive = null;
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Account status
|
112 |
+
* @var int
|
113 |
+
*/
|
114 |
+
public $account_status = -1;
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Create server response
|
118 |
+
*
|
119 |
+
* @param type $response
|
120 |
+
* @param type $obj
|
121 |
+
*/
|
122 |
+
function __construct($response = null, $obj = null) {
|
123 |
+
if ($response && is_array($response) && count($response) > 0) {
|
124 |
+
foreach ($response as $param => $value) {
|
125 |
+
$this->{$param} = $value;
|
126 |
+
}
|
127 |
+
} else {
|
128 |
+
$this->errno = $obj->errno;
|
129 |
+
$this->errstr = $obj->errstr;
|
130 |
+
|
131 |
+
$this->errstr = preg_replace("/.+(\*\*\*.+\*\*\*).+/", "$1", $this->errstr);
|
132 |
+
|
133 |
+
$this->stop_words = isset($obj->stop_words) ? utf8_decode($obj->stop_words) : null;
|
134 |
+
$this->comment = isset($obj->comment) ? utf8_decode($obj->comment) : null;
|
135 |
+
$this->blacklisted = (isset($obj->blacklisted)) ? $obj->blacklisted : null;
|
136 |
+
$this->allow = (isset($obj->allow)) ? $obj->allow : 0;
|
137 |
+
$this->id = (isset($obj->id)) ? $obj->id : null;
|
138 |
+
$this->fast_submit = (isset($obj->fast_submit)) ? $obj->fast_submit : 0;
|
139 |
+
$this->spam = (isset($obj->spam)) ? $obj->spam : 0;
|
140 |
+
$this->js_disabled = (isset($obj->js_disabled)) ? $obj->js_disabled : 0;
|
141 |
+
$this->sms_allow = (isset($obj->sms_allow)) ? $obj->sms_allow : null;
|
142 |
+
$this->sms = (isset($obj->sms)) ? $obj->sms : null;
|
143 |
+
$this->sms_error_code = (isset($obj->sms_error_code)) ? $obj->sms_error_code : null;
|
144 |
+
$this->sms_error_text = (isset($obj->sms_error_text)) ? $obj->sms_error_text : null;
|
145 |
+
$this->stop_queue = (isset($obj->stop_queue)) ? $obj->stop_queue : 0;
|
146 |
+
$this->inactive = (isset($obj->inactive)) ? $obj->inactive : 0;
|
147 |
+
$this->account_status = (isset($obj->account_status)) ? $obj->account_status : -1;
|
148 |
+
$this->received = (isset($obj->received)) ? $obj->received : -1;
|
149 |
+
|
150 |
+
if ($this->errno !== 0 && $this->errstr !== null && $this->comment === null)
|
151 |
+
$this->comment = '*** ' . $this->errstr . ' Antispam service cleantalk.org ***';
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
}
|
lib/CleantalkSFW.php
CHANGED
@@ -3,14 +3,14 @@
|
|
3 |
/*
|
4 |
* CleanTalk SpamFireWall base class
|
5 |
* Compatible only with Wordpress.
|
6 |
-
* Version
|
7 |
* author Cleantalk team (welcome@cleantalk.org)
|
8 |
* copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
9 |
* license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
10 |
* see https://github.com/CleanTalk/php-antispam
|
11 |
*/
|
12 |
|
13 |
-
class CleantalkSFW
|
14 |
{
|
15 |
public $ip = 0;
|
16 |
public $ip_str = '';
|
@@ -27,33 +27,6 @@ class CleantalkSFW
|
|
27 |
private $db_result;
|
28 |
private $db_result_data = array();
|
29 |
|
30 |
-
public static $cdn_pool = array(
|
31 |
-
'cloud_flare' => array(
|
32 |
-
'103.21.244.0/22',
|
33 |
-
'103.22.200.0/22',
|
34 |
-
'103.31.4.0/22',
|
35 |
-
'104.16.0.0/12',
|
36 |
-
'108.162.192.0/18',
|
37 |
-
'131.0.72.0/22',
|
38 |
-
'141.101.64.0/18',
|
39 |
-
'162.158.0.0/15',
|
40 |
-
'172.64.0.0/13',
|
41 |
-
'173.245.48.0/20',
|
42 |
-
'188.114.96.0/20',
|
43 |
-
'190.93.240.0/20',
|
44 |
-
'197.234.240.0/22',
|
45 |
-
'198.41.128.0/17',
|
46 |
-
),
|
47 |
-
);
|
48 |
-
|
49 |
-
public static $private_networks = array(
|
50 |
-
'10.0.0.0/8',
|
51 |
-
'100.64.0.0/10',
|
52 |
-
'172.16.0.0/12',
|
53 |
-
'192.168.0.0/16',
|
54 |
-
'127.0.0.1/32',
|
55 |
-
);
|
56 |
-
|
57 |
public function __construct()
|
58 |
{
|
59 |
global $wpdb;
|
@@ -81,67 +54,23 @@ class CleantalkSFW
|
|
81 |
|
82 |
|
83 |
/*
|
84 |
-
* Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For,
|
85 |
-
*
|
86 |
-
* reutrns array
|
87 |
*/
|
88 |
-
public function
|
89 |
|
90 |
-
$
|
91 |
-
? apache_request_headers()
|
92 |
-
: self::apache_request_headers();
|
93 |
|
94 |
-
$result
|
95 |
-
|
96 |
-
// Cloud Flare
|
97 |
-
if(isset($headers['Cf-Connecting-Ip'])){
|
98 |
-
if($this->ip_mask_match($result['remote_addr'], self::$cdn_pool['cloud_flare'])){
|
99 |
-
$result['cf_connecting_ip'] = filter_var( $headers['Cf-Connecting-Ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
|
100 |
-
unset($result['remote_addr']);
|
101 |
-
}
|
102 |
-
// Private networks. Looking for HTTP_X_FORWARDED_FOR and HTTP_X_REAL_IP
|
103 |
-
}elseif($this->ip_mask_match($result['remote_addr'], self::$private_networks)){
|
104 |
-
if(isset($headers['X-Forwarded_For'])){
|
105 |
-
$result['x_forwarded_for'] = filter_var( $headers['X-Forwarded_For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
|
106 |
-
}
|
107 |
-
if(isset($headers['X-Real-Ip'])){
|
108 |
-
$result['x_real_ip'] = filter_var( $headers['X-Real-Ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
|
109 |
-
}
|
110 |
-
if(isset($result['x_forwarded_for']) || isset($result['x_real_ip'])){
|
111 |
-
unset($result['remote_addr']);
|
112 |
-
}
|
113 |
-
}
|
114 |
|
115 |
if(isset($_GET['sfw_test_ip'])){
|
116 |
-
$result['
|
117 |
}
|
118 |
|
119 |
-
$this->ip_array = $result;
|
120 |
-
|
121 |
return $result;
|
122 |
|
123 |
}
|
124 |
|
125 |
-
/*
|
126 |
-
* Check if the IP belong to mask. Recursivly if array given
|
127 |
-
* @param ip string
|
128 |
-
* @param cird mixed (string|array of strings)
|
129 |
-
*/
|
130 |
-
public function ip_mask_match($ip, $cidr){
|
131 |
-
if(is_array($cidr)){
|
132 |
-
foreach($cidr as $curr_mask){
|
133 |
-
if($this->ip_mask_match($ip, $curr_mask)){
|
134 |
-
return true;
|
135 |
-
}
|
136 |
-
} unset($curr_mask);
|
137 |
-
return false;
|
138 |
-
}
|
139 |
-
$exploded = explode ('/', $cidr);
|
140 |
-
$net = $exploded[0];
|
141 |
-
$mask = 4294967295 << (32 - $exploded[1]);
|
142 |
-
return (ip2long($ip) & $mask) == (ip2long($net) & $mask);
|
143 |
-
}
|
144 |
-
|
145 |
/*
|
146 |
* Checks IP via Database
|
147 |
*/
|
@@ -199,7 +128,7 @@ class CleantalkSFW
|
|
199 |
*/
|
200 |
public function sfw_update($ct_key){
|
201 |
|
202 |
-
$result = self::
|
203 |
|
204 |
if(empty($result['error'])){
|
205 |
|
@@ -250,7 +179,7 @@ class CleantalkSFW
|
|
250 |
unset($key, $value);
|
251 |
|
252 |
//Sending the request
|
253 |
-
$result = self::
|
254 |
|
255 |
//Checking answer and deleting all lines from the table
|
256 |
if(empty($result['error'])){
|
@@ -311,191 +240,4 @@ class CleantalkSFW
|
|
311 |
wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
|
312 |
|
313 |
}
|
314 |
-
|
315 |
-
/*
|
316 |
-
* Wrapper for sfw_logs API method
|
317 |
-
*
|
318 |
-
* returns mixed STRING || array('error' => true, 'error_string' => STRING)
|
319 |
-
*/
|
320 |
-
static public function sfwLogs($api_key, $data, $do_check = true){
|
321 |
-
$url='https://api.cleantalk.org';
|
322 |
-
$request = array(
|
323 |
-
'auth_key' => $api_key,
|
324 |
-
'method_name' => 'sfw_logs',
|
325 |
-
'data' => json_encode($data),
|
326 |
-
'rows' => count($data),
|
327 |
-
'timestamp' => time()
|
328 |
-
);
|
329 |
-
$result = self::sendRawRequest($url, $request);
|
330 |
-
$result = $do_check ? self::checkRequestResult($result, 'sfw_logs') : $result;
|
331 |
-
|
332 |
-
return $result;
|
333 |
-
}
|
334 |
-
|
335 |
-
/*
|
336 |
-
* Wrapper for 2s_blacklists_db API method
|
337 |
-
*
|
338 |
-
* returns mixed STRING || array('error' => true, 'error_string' => STRING)
|
339 |
-
*/
|
340 |
-
static public function get_2sBlacklistsDb($api_key, $do_check = true){
|
341 |
-
$url='https://api.cleantalk.org';
|
342 |
-
$request = array(
|
343 |
-
'auth_key' => $api_key,
|
344 |
-
'method_name' => '2s_blacklists_db'
|
345 |
-
);
|
346 |
-
|
347 |
-
$result = self::sendRawRequest($url, $request);
|
348 |
-
$result = $do_check ? self::checkRequestResult($result, '2s_blacklists_db') : $result;
|
349 |
-
|
350 |
-
return $result;
|
351 |
-
}
|
352 |
-
|
353 |
-
/**
|
354 |
-
* Function sends raw request to API server
|
355 |
-
*
|
356 |
-
* @param string url of API server
|
357 |
-
* @param array data to send
|
358 |
-
* @param boolean is data have to be JSON encoded or not
|
359 |
-
* @param integer connect timeout
|
360 |
-
* @return type
|
361 |
-
*/
|
362 |
-
static public function sendRawRequest($url, $data, $isJSON = false, $timeout=3, $ssl = false)
|
363 |
-
{
|
364 |
-
$result = null;
|
365 |
-
$curl_error = false;
|
366 |
-
|
367 |
-
if(!$isJSON){
|
368 |
-
$data = http_build_query($data);
|
369 |
-
$data = str_replace("&", "&", $data);
|
370 |
-
}else{
|
371 |
-
$data = json_encode($data);
|
372 |
-
}
|
373 |
-
|
374 |
-
if (function_exists('curl_init') && function_exists('json_decode')){
|
375 |
-
|
376 |
-
$ch = curl_init();
|
377 |
-
curl_setopt($ch, CURLOPT_URL, $url);
|
378 |
-
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
379 |
-
curl_setopt($ch, CURLOPT_POST, true);
|
380 |
-
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
381 |
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
382 |
-
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
|
383 |
-
|
384 |
-
if ($ssl === true) {
|
385 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
386 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
387 |
-
curl_setopt($ch, CURLOPT_CAINFO, APBCT_CASERT_PATH);
|
388 |
-
}
|
389 |
-
|
390 |
-
$result = curl_exec($ch);
|
391 |
-
|
392 |
-
if($result === false){
|
393 |
-
if($ssl === false){
|
394 |
-
$args = func_get_args();
|
395 |
-
return self::sendRawRequest($args[0], $args[1], $isJSON, $timeout, true);
|
396 |
-
}
|
397 |
-
$curl_error = curl_error($ch);
|
398 |
-
}
|
399 |
-
|
400 |
-
curl_close($ch);
|
401 |
-
|
402 |
-
}else{
|
403 |
-
$curl_error = 'CURL_NOT_INSTALLED';
|
404 |
-
}
|
405 |
-
|
406 |
-
if($curl_error){
|
407 |
-
|
408 |
-
$opts = array(
|
409 |
-
'http'=>array(
|
410 |
-
'method' => "POST",
|
411 |
-
'timeout' => $timeout,
|
412 |
-
'content' => $data,
|
413 |
-
)
|
414 |
-
);
|
415 |
-
$context = stream_context_create($opts);
|
416 |
-
$result = @file_get_contents($url, 0, $context);
|
417 |
-
}
|
418 |
-
|
419 |
-
if(!$result && $curl_error)
|
420 |
-
return array('error' => true, 'error_string' => $curl_error);
|
421 |
-
|
422 |
-
return $result;
|
423 |
-
}
|
424 |
-
|
425 |
-
/**
|
426 |
-
* Function checks server response
|
427 |
-
*
|
428 |
-
* @param string request_method
|
429 |
-
* @param string result
|
430 |
-
* @return mixed (array || array('error' => true, 'error_string' => STRING))
|
431 |
-
*/
|
432 |
-
static public function checkRequestResult($result, $method_name = null)
|
433 |
-
{
|
434 |
-
|
435 |
-
// Errors handling
|
436 |
-
// Bad connection
|
437 |
-
if(empty($result)){
|
438 |
-
$result = array(
|
439 |
-
'error' => true,
|
440 |
-
'error_string' => 'CONNECTION_ERROR'
|
441 |
-
);
|
442 |
-
return $result;
|
443 |
-
}
|
444 |
-
|
445 |
-
// JSON decode errors
|
446 |
-
$result = json_decode($result, true);
|
447 |
-
if(empty($result)){
|
448 |
-
$result = array(
|
449 |
-
'error' => true,
|
450 |
-
'error_string' => 'JSON_DECODE_ERROR'
|
451 |
-
);
|
452 |
-
return $result;
|
453 |
-
}
|
454 |
-
|
455 |
-
// Server errors
|
456 |
-
if($result && (isset($result['error_no']) || isset($result['error_message']))){
|
457 |
-
$result = array(
|
458 |
-
'error' => true,
|
459 |
-
'error_string' => "SERVER_ERROR NO:{$result['error_no']} MSG:{$result['error_message']}",
|
460 |
-
'error_no' => $result['error_no'],
|
461 |
-
'error_message' => $result['error_message']
|
462 |
-
);
|
463 |
-
return $result;
|
464 |
-
}
|
465 |
-
|
466 |
-
/* mehod_name = notice_validate_key */
|
467 |
-
if($method_name == 'notice_validate_key' && isset($result['valid'])){
|
468 |
-
$result['error'] = false;
|
469 |
-
return $result;
|
470 |
-
}
|
471 |
-
|
472 |
-
/* Other methods */
|
473 |
-
if(isset($result['data']) && is_array($result['data'])){
|
474 |
-
return $result['data'];
|
475 |
-
}
|
476 |
-
}
|
477 |
-
|
478 |
-
/*
|
479 |
-
* If Apache web server is missing then making
|
480 |
-
* Patch for apache_request_headers()
|
481 |
-
*/
|
482 |
-
static function apache_request_headers(){
|
483 |
-
|
484 |
-
$headers = array();
|
485 |
-
foreach($_SERVER as $key => $val){
|
486 |
-
if(preg_match('/\AHTTP_/', $key)){
|
487 |
-
$server_key = preg_replace('/\AHTTP_/', '', $key);
|
488 |
-
$key_parts = explode('_', $server_key);
|
489 |
-
if(count($key_parts) > 0 and strlen($server_key) > 2){
|
490 |
-
foreach($key_parts as $part_index => $part){
|
491 |
-
$key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part);
|
492 |
-
$key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
|
493 |
-
}
|
494 |
-
$server_key = implode('-', $key_parts);
|
495 |
-
}
|
496 |
-
$headers[$server_key] = $val;
|
497 |
-
}
|
498 |
-
}
|
499 |
-
return $headers;
|
500 |
-
}
|
501 |
}
|
3 |
/*
|
4 |
* CleanTalk SpamFireWall base class
|
5 |
* Compatible only with Wordpress.
|
6 |
+
* Version 2.0-wp
|
7 |
* author Cleantalk team (welcome@cleantalk.org)
|
8 |
* copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
9 |
* license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
10 |
* see https://github.com/CleanTalk/php-antispam
|
11 |
*/
|
12 |
|
13 |
+
class CleantalkSFW extends CleantalkHelper
|
14 |
{
|
15 |
public $ip = 0;
|
16 |
public $ip_str = '';
|
27 |
private $db_result;
|
28 |
private $db_result_data = array();
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
public function __construct()
|
31 |
{
|
32 |
global $wpdb;
|
54 |
|
55 |
|
56 |
/*
|
57 |
+
* Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)
|
58 |
+
* reutrns array('remote_addr' => 'val', ['x_forwarded_for' => 'val', ['x_real_ip' => 'val', ['cloud_flare' => 'val']]])
|
|
|
59 |
*/
|
60 |
+
static public function ip_get($ips_input = array('real', 'remote_addr', 'x_forwarded_for', 'x_real_ip', 'cloud_flare'), $ips = array()){
|
61 |
|
62 |
+
$result = parent::ip_get($ips_input, $ips);
|
|
|
|
|
63 |
|
64 |
+
$result = !empty($result) ? $result : array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
if(isset($_GET['sfw_test_ip'])){
|
67 |
+
$result['sfw_test'] = $_GET['sfw_test_ip'];
|
68 |
}
|
69 |
|
|
|
|
|
70 |
return $result;
|
71 |
|
72 |
}
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
/*
|
75 |
* Checks IP via Database
|
76 |
*/
|
128 |
*/
|
129 |
public function sfw_update($ct_key){
|
130 |
|
131 |
+
$result = self::api_method__get_2s_blacklists_db($ct_key);
|
132 |
|
133 |
if(empty($result['error'])){
|
134 |
|
179 |
unset($key, $value);
|
180 |
|
181 |
//Sending the request
|
182 |
+
$result = self::api_method__sfw_logs($ct_key, $data);
|
183 |
|
184 |
//Checking answer and deleting all lines from the table
|
185 |
if(empty($result['error'])){
|
240 |
wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
|
241 |
|
242 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
}
|
lib/cleantalk-php-patch.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Patch for apache_request_headers()
|
5 |
+
* If Apache web server is missing then making
|
6 |
+
*/
|
7 |
+
if( !function_exists('apache_request_headers') ){
|
8 |
+
function apache_request_headers(){
|
9 |
+
|
10 |
+
$headers = array();
|
11 |
+
foreach($_SERVER as $key => $val){
|
12 |
+
if(preg_match('/\AHTTP_/', $key)){
|
13 |
+
$server_key = preg_replace('/\AHTTP_/', '', $key);
|
14 |
+
$key_parts = explode('_', $server_key);
|
15 |
+
if(count($key_parts) > 0 and strlen($server_key) > 2){
|
16 |
+
foreach($key_parts as $part_index => $part){
|
17 |
+
$key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part);
|
18 |
+
$key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
|
19 |
+
}
|
20 |
+
$server_key = implode('-', $key_parts);
|
21 |
+
}
|
22 |
+
$headers[$server_key] = $val;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
return $headers;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
|
29 |
+
/*
|
30 |
+
* Patch for locale_get_display_region()
|
31 |
+
* For old PHP versions
|
32 |
+
*/
|
33 |
+
if( !function_exists('locale_get_display_region') ){
|
34 |
+
function locale_get_display_region($locale, $in_locale = 'EN'){
|
35 |
+
|
36 |
+
return 'Unkonwn' . ($locale ? ': ' . $locale : '');
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
/*
|
41 |
+
* Patch for utf8_decode()
|
42 |
+
* If PHP complied without XML support
|
43 |
+
* From getID3() by James Heinrich <info@getid3.org> under GNU GPL
|
44 |
+
*/
|
45 |
+
if(!function_exists('utf8_decode')){
|
46 |
+
function utf8_decode($string){
|
47 |
+
|
48 |
+
$newcharstring = '';
|
49 |
+
$offset = 0;
|
50 |
+
$stringlength = strlen($string);
|
51 |
+
while ($offset < $stringlength) {
|
52 |
+
if ((ord($string{$offset}) | 0x07) == 0xF7) {
|
53 |
+
$charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
|
54 |
+
((ord($string{($offset + 1)}) & 0x3F) << 12) &
|
55 |
+
((ord($string{($offset + 2)}) & 0x3F) << 6) &
|
56 |
+
(ord($string{($offset + 3)}) & 0x3F);
|
57 |
+
$offset += 4;
|
58 |
+
} elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
|
59 |
+
$charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
|
60 |
+
((ord($string{($offset + 1)}) & 0x3F) << 6) &
|
61 |
+
(ord($string{($offset + 2)}) & 0x3F);
|
62 |
+
$offset += 3;
|
63 |
+
} elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
|
64 |
+
$charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
|
65 |
+
(ord($string{($offset + 1)}) & 0x3F);
|
66 |
+
$offset += 2;
|
67 |
+
} elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
|
68 |
+
$charval = ord($string{$offset});
|
69 |
+
$offset += 1;
|
70 |
+
} else {
|
71 |
+
$charval = false;
|
72 |
+
$offset += 1;
|
73 |
+
}
|
74 |
+
if ($charval !== false) {
|
75 |
+
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
|
76 |
+
}
|
77 |
+
}
|
78 |
+
return $newcharstring;
|
79 |
+
}
|
80 |
+
}
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: znaeff, shagimuratov, sartemd174
|
3 |
Tags: spam, antispam, protection, comments, firewall
|
4 |
Requires at least: 3.0
|
5 |
-
Tested up to: 4.9.
|
6 |
-
Stable tag: 5.
|
7 |
License: GPLv2
|
8 |
|
9 |
Spam protection, antispam, all-in-one, premium plugin. No spam comments & users, no spam contact form & WooCommerce spam. Forget spam.
|
@@ -515,6 +515,12 @@ We develop plugin to do it as optimized as possible, CleanTalk doesn't downgrade
|
|
515 |
10. Website's options.
|
516 |
|
517 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
= 5.91 March 15 2018 =
|
519 |
* Fix: Errors for PHP compiled without XML support.
|
520 |
* Fix: Spelling and translation.
|
@@ -1547,6 +1553,12 @@ We develop plugin to do it as optimized as possible, CleanTalk doesn't downgrade
|
|
1547 |
* First version
|
1548 |
|
1549 |
== Upgrade Notice ==
|
|
|
|
|
|
|
|
|
|
|
|
|
1550 |
= 5.91 March 15 2018 =
|
1551 |
* Fix: Errors for PHP compiled without XML support.
|
1552 |
* Fix: Spelling and translation.
|
2 |
Contributors: znaeff, shagimuratov, sartemd174
|
3 |
Tags: spam, antispam, protection, comments, firewall
|
4 |
Requires at least: 3.0
|
5 |
+
Tested up to: 4.9.4
|
6 |
+
Stable tag: 5.92
|
7 |
License: GPLv2
|
8 |
|
9 |
Spam protection, antispam, all-in-one, premium plugin. No spam comments & users, no spam contact form & WooCommerce spam. Forget spam.
|
515 |
10. Website's options.
|
516 |
|
517 |
== Changelog ==
|
518 |
+
= 5.92 March 22 2018 =
|
519 |
+
* IP detection improved.
|
520 |
+
* Fix: SSL connection.
|
521 |
+
* Fix: False positives spam detection in Contact Form 7.
|
522 |
+
* Minor fixes.
|
523 |
+
|
524 |
= 5.91 March 15 2018 =
|
525 |
* Fix: Errors for PHP compiled without XML support.
|
526 |
* Fix: Spelling and translation.
|
1553 |
* First version
|
1554 |
|
1555 |
== Upgrade Notice ==
|
1556 |
+
= 5.92 March 22 2018 =
|
1557 |
+
* IP detection improved.
|
1558 |
+
* Fix: SSL connection.
|
1559 |
+
* Fix: False positives spam detection in Contact Form 7.
|
1560 |
+
* Minor fixes.
|
1561 |
+
|
1562 |
= 5.91 March 15 2018 =
|
1563 |
* Fix: Errors for PHP compiled without XML support.
|
1564 |
* Fix: Spelling and translation.
|