Spam protection, AntiSpam, FireWall by CleanTalk - Version 5.160.3

Version Description

Aug 31 2021 = * New: Queue. Transaction system. * Fix. SFW. Updating for the new clients fixed. * Fix. SFW. Deleting UA file fixed. * Fix. SFW. Updating via cron fixed. * Fix. SFW. Updating process for multisite fixed.

Download this release

Release Info

Developer glomberg
Plugin Icon 128x128 Spam protection, AntiSpam, FireWall by CleanTalk
Version 5.160.3
Comparing to
See all releases

Code changes from version 5.160.2 to 5.160.3

cleantalk.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://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.160.2
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk-spam-protect
@@ -706,7 +706,8 @@ function apbct_sfw_update__init( $delay = 0 ){
706
  $apbct->fw_stats['calls'] = 0;
707
  $apbct->fw_stats['firewall_updating_id'] = md5( (string) rand( 0, 100000 ) );
708
  $apbct->fw_stats['firewall_updating_last_start'] = time();
709
- $apbct->save( 'fw_stats' );
 
710
 
711
  // Delete update errors
712
  $apbct->error_delete( 'sfw_update', 'save_data' );
@@ -742,7 +743,7 @@ function apbct_sfw_update__init( $delay = 0 ){
742
  *
743
  * @return array|bool|int|string[]
744
  */
745
- function apbct_sfw_update__worker() {
746
 
747
  global $apbct;
748
 
@@ -751,13 +752,15 @@ function apbct_sfw_update__worker() {
751
  if( ! $apbct->data['key_is_ok'] ){
752
  return array( 'error' => 'Worker: KEY_IS_NOT_VALID' );
753
  }
754
-
755
- if(
756
- Get::equal( 'firewall_updating_id', '' ) ||
757
- ! Get::equal( 'firewall_updating_id', $apbct->fw_stats['firewall_updating_id'] )
758
- ){
759
- return 'SFW UPDATE WORKER: WRONG_UPDATE_ID';
760
- }
 
 
761
 
762
  if( ! isset( $apbct->fw_stats['calls'] ) ){
763
  $apbct->fw_stats['calls'] = 0;
@@ -863,11 +866,13 @@ function apbct_sfw_update__get_multifiles(){
863
 
864
  function apbct_sfw_update__download_files( $urls ) {
865
 
 
 
866
  sleep(3);
867
 
868
  //Reset keys
869
  $urls = array_values( $urls );
870
- $results = Helper::http__multi_request( $urls, APBCT_DIR_PATH . '/fw_files/' );
871
  $count_urls = count( $urls );
872
  $count_results = count( $results );
873
 
@@ -932,8 +937,7 @@ function apbct_sfw_update__process_files() {
932
 
933
  global $apbct;
934
 
935
- $dir_name = APBCT_DIR_PATH . '/fw_files/';
936
- $files = glob( $dir_name . '/*csv.gz' );
937
  $files = array_filter( $files, static function( $element ) {
938
  return strpos( $element, 'list' ) !== false;
939
  } );
@@ -1190,7 +1194,11 @@ function apbct_sfw_update__is_in_progress() {
1190
  }
1191
 
1192
  function apbct_prepare_upd_dir() {
1193
- $dir_name = APBCT_DIR_PATH . '/fw_files/';
 
 
 
 
1194
  if( ! is_dir( $dir_name ) ) {
1195
  if( ! mkdir( $dir_name ) && ! is_dir( $dir_name ) ) {
1196
  return array( 'error' => 'Can not to make FW dir.' );
@@ -1217,7 +1225,7 @@ function apbct_sfw_update__checker() {
1217
  if( count( $queue->queue['stages'] ) ) {
1218
  foreach( $queue->queue['stages'] as $stage ) {
1219
  if ( $stage['status'] === 'NULL' ) {
1220
- return apbct_sfw_update__worker();
1221
  }
1222
  }
1223
  }
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://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.160.3
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk-spam-protect
706
  $apbct->fw_stats['calls'] = 0;
707
  $apbct->fw_stats['firewall_updating_id'] = md5( (string) rand( 0, 100000 ) );
708
  $apbct->fw_stats['firewall_updating_last_start'] = time();
709
+ $apbct->fw_stats['updating_folder'] = APBCT_DIR_PATH . DIRECTORY_SEPARATOR . 'fw_files_for_blog_' . get_current_blog_id() . DIRECTORY_SEPARATOR;
710
+ $apbct->save( 'fw_stats' );
711
 
712
  // Delete update errors
713
  $apbct->error_delete( 'sfw_update', 'save_data' );
743
  *
744
  * @return array|bool|int|string[]
745
  */
746
+ function apbct_sfw_update__worker( $checker_work = false ) {
747
 
748
  global $apbct;
749
 
752
  if( ! $apbct->data['key_is_ok'] ){
753
  return array( 'error' => 'Worker: KEY_IS_NOT_VALID' );
754
  }
755
+
756
+ if( ! $checker_work ){
757
+ if(
758
+ Get::equal( 'firewall_updating_id', '' ) ||
759
+ ! Get::equal( 'firewall_updating_id', $apbct->fw_stats['firewall_updating_id'] )
760
+ ){
761
+ return array( 'error' => 'Worker: WRONG_UPDATE_ID' );
762
+ }
763
+ }
764
 
765
  if( ! isset( $apbct->fw_stats['calls'] ) ){
766
  $apbct->fw_stats['calls'] = 0;
866
 
867
  function apbct_sfw_update__download_files( $urls ) {
868
 
869
+ global $apbct;
870
+
871
  sleep(3);
872
 
873
  //Reset keys
874
  $urls = array_values( $urls );
875
+ $results = Helper::http__multi_request( $urls, $apbct->fw_stats['updating_folder'] );
876
  $count_urls = count( $urls );
877
  $count_results = count( $results );
878
 
937
 
938
  global $apbct;
939
 
940
+ $files = glob( $apbct->fw_stats['updating_folder'] . '/*csv.gz' );
 
941
  $files = array_filter( $files, static function( $element ) {
942
  return strpos( $element, 'list' ) !== false;
943
  } );
1194
  }
1195
 
1196
  function apbct_prepare_upd_dir() {
1197
+
1198
+ global $apbct;
1199
+
1200
+ $dir_name = $apbct->fw_stats['updating_folder'];
1201
+
1202
  if( ! is_dir( $dir_name ) ) {
1203
  if( ! mkdir( $dir_name ) && ! is_dir( $dir_name ) ) {
1204
  return array( 'error' => 'Can not to make FW dir.' );
1225
  if( count( $queue->queue['stages'] ) ) {
1226
  foreach( $queue->queue['stages'] as $stage ) {
1227
  if ( $stage['status'] === 'NULL' ) {
1228
+ return apbct_sfw_update__worker( true );
1229
  }
1230
  }
1231
  }
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php CHANGED
@@ -92,7 +92,7 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
92
  $ua_template = isset($entry[1]) && apbct_is_regexp($entry[1]) ? Helper::db__prepare_param( $entry[1] ) : 0;
93
  $ua_status = isset($entry[2]) ? $entry[2] : 0;
94
 
95
- if( ! $ua_id || ! $ua_template ){
96
  continue;
97
  }
98
 
@@ -103,12 +103,14 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
103
  if( ! empty( $values ) ){
104
  $query = $query . implode( ',', $values ) . ';';
105
  \Cleantalk\ApbctWP\DB::getInstance()->execute( $query );
106
- if( file_exists( $file_path_ua ) ) {
107
- unlink($file_path_ua);
108
- }
109
  }
110
 
111
  }
 
 
 
 
 
112
  return $count_result;
113
  }else {
114
  return $result__clear_db;
92
  $ua_template = isset($entry[1]) && apbct_is_regexp($entry[1]) ? Helper::db__prepare_param( $entry[1] ) : 0;
93
  $ua_status = isset($entry[2]) ? $entry[2] : 0;
94
 
95
+ if( ! $ua_template ){
96
  continue;
97
  }
98
 
103
  if( ! empty( $values ) ){
104
  $query = $query . implode( ',', $values ) . ';';
105
  \Cleantalk\ApbctWP\DB::getInstance()->execute( $query );
 
 
 
106
  }
107
 
108
  }
109
+
110
+ if( file_exists( $file_path_ua ) ) {
111
+ unlink($file_path_ua);
112
+ }
113
+
114
  return $count_result;
115
  }else {
116
  return $result__clear_db;
lib/Cleantalk/ApbctWP/State.php CHANGED
@@ -300,6 +300,7 @@ class State
300
 
301
  private $default_fw_stats = array(
302
  'firewall_updating' => false,
 
303
  'firewall_updating_id' => null,
304
  'firewall_update_percent' => 0,
305
  'firewall_updating_last_start' => 0,
300
 
301
  private $default_fw_stats = array(
302
  'firewall_updating' => false,
303
+ 'updating_folder' => 'fw_files',
304
  'firewall_updating_id' => null,
305
  'firewall_update_percent' => 0,
306
  'firewall_updating_last_start' => 0,
lib/Cleantalk/Common/Helper.php CHANGED
@@ -613,8 +613,8 @@ class Helper
613
 
614
  // Make a request, don't wait for an answer
615
  case 'async':
616
- $opts[CURLOPT_CONNECTTIMEOUT_MS] = 1000;
617
- $opts[CURLOPT_TIMEOUT_MS] = 1000;
618
  break;
619
 
620
  case 'get':
613
 
614
  // Make a request, don't wait for an answer
615
  case 'async':
616
+ $opts[CURLOPT_CONNECTTIMEOUT_MS] = 2000;
617
+ $opts[CURLOPT_TIMEOUT_MS] = 2000;
618
  break;
619
 
620
  case 'get':
lib/Cleantalk/Common/Queue.php CHANGED
@@ -10,8 +10,19 @@ abstract class Queue {
10
 
11
  public $queue;
12
 
 
 
 
 
 
 
 
 
 
13
  public function __construct()
14
  {
 
 
15
  $queue = $this->getQueue();
16
  if( $queue !== false && isset( $queue['stages'] ) ) {
17
  $this->queue = $queue;
@@ -27,117 +38,147 @@ abstract class Queue {
27
  abstract public function getQueue();
28
 
29
  abstract public function saveQueue( $queue );
30
-
31
- /**
32
- * @param string $stage_name
33
- * @param array $args
34
- */
 
 
 
 
 
 
 
 
 
 
35
  public function addStage( $stage_name, $args = array() )
36
  {
37
  $this->queue['stages'][] = array(
38
  'name' => $stage_name,
39
  'status' => 'NULL',
40
  'tries' => '0',
41
- 'args' => $args
 
42
  );
43
  $this->saveQueue( $this->queue );
44
  }
45
 
46
  public function executeStage()
47
  {
48
- global $apbct;
49
-
50
- if( count( $this->queue['stages'] ) > 0 ) {
51
- foreach ( $this->queue['stages'] as & $stage ) {
52
- if( ( $stage['status'] === 'NULL' ) ) {
53
-
54
- $stage['status'] = 'IN_PROGRESS';
55
-
56
- if( is_callable( $stage['name'] ) ) {
57
-
58
- ++$stage['tries'];
59
-
60
- if( ! empty( $stage['args'] ) ) {
61
- $result = $stage['name']( $stage['args'] );
62
- } else {
63
- $result = $stage['name']();
64
- }
65
-
66
- if( isset( $result['error'] ) ) {
67
- $stage['status'] = 'NULL';
68
- if( isset( $result['update_args']['args'] ) ) {
69
- $stage['args'] = $result['update_args']['args'];
70
- }
71
- $this->saveQueue( $this->queue );
72
- if( $stage['tries'] >= 3 ) {
73
- $stage['status'] = 'FINISHED';
74
- $stage['error'] = $result['error'];
75
- $this->saveQueue( $this->queue );
76
- return $result;
77
- }
78
- return \Cleantalk\ApbctWP\Helper::http__request__rc_to_host(
79
- 'sfw_update__worker',
80
- array(
81
- 'firewall_updating_id' => $apbct->fw_stats['firewall_updating_id'],
82
- 'stage' => 'Repeat ' . $stage['name']
83
- ),
84
- array( 'async' )
85
- );
86
- }
87
-
88
- if( isset( $result['next_stage'] ) ) {
89
- $this->addStage(
90
- $result['next_stage']['name'],
91
- isset( $result['next_stage']['args'] ) ? $result['next_stage']['args'] : array()
92
- );
93
- }
94
-
95
- if( isset( $result['next_stages'] ) && count( $result['next_stages'] ) ) {
96
- foreach( $result['next_stages'] as $next_stage ) {
97
- $this->addStage(
98
- $next_stage['name'],
99
- isset( $next_stage['args'] ) ? $next_stage['args'] : array()
100
- );
101
- }
102
- }
103
-
104
- $stage['status'] = 'FINISHED';
105
- $this->saveQueue( $this->queue );
106
 
107
- return $result;
 
 
 
 
 
 
 
 
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- return array( 'error' => $stage['name'] . ' is not a callable function.' );
 
 
 
 
 
112
 
 
 
 
 
 
 
 
113
  }
114
- } unset( $stage );
 
 
 
 
 
 
 
 
 
115
  }
116
  }
117
 
118
  public function isQueueInProgress()
119
  {
120
- if( count( $this->queue['stages'] ) > 0 ) {
121
- foreach ( $this->queue['stages'] as $stage ) {
122
- if( $stage['status'] === 'FINISHED' ) {
123
- continue;
124
- }
125
- return true;
126
- }
127
- }
128
- return false;
129
  }
130
 
131
  public function isQueueFinished()
132
  {
133
- if( count( $this->queue['stages'] ) > 0 ) {
134
- foreach ( $this->queue['stages'] as $stage ) {
135
- if( $stage['status'] !== 'FINISHED' ) {
136
- return false;
137
- }
138
- }
 
 
 
 
 
 
 
139
  }
140
- return true;
 
141
  }
142
 
143
  }
10
 
11
  public $queue;
12
 
13
+ private $unstarted_stage;
14
+
15
+ /**
16
+ * Process identifier
17
+ *
18
+ * @var int
19
+ */
20
+ private $pid;
21
+
22
  public function __construct()
23
  {
24
+ $this->pid = mt_rand( 0, mt_getrandmax() );
25
+
26
  $queue = $this->getQueue();
27
  if( $queue !== false && isset( $queue['stages'] ) ) {
28
  $this->queue = $queue;
38
  abstract public function getQueue();
39
 
40
  abstract public function saveQueue( $queue );
41
+
42
+ /**
43
+ * Refreshes the $this->queue from the DB
44
+ *
45
+ * @return void
46
+ */
47
+ public function refreshQueue()
48
+ {
49
+ $this->queue = $this->getQueue();
50
+ }
51
+
52
+ /**
53
+ * @param string $stage_name
54
+ * @param array $args
55
+ */
56
  public function addStage( $stage_name, $args = array() )
57
  {
58
  $this->queue['stages'][] = array(
59
  'name' => $stage_name,
60
  'status' => 'NULL',
61
  'tries' => '0',
62
+ 'args' => $args,
63
+ 'pid' => null,
64
  );
65
  $this->saveQueue( $this->queue );
66
  }
67
 
68
  public function executeStage()
69
  {
70
+ global $apbct;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
+ $stage_to_execute = null;
73
+
74
+ if( $this->hasUnstartedStages() ){
75
+
76
+ $this->queue['stages'][ $this->unstarted_stage ]['status'] = 'IN_PROGRESS';
77
+ $this->queue['stages'][ $this->unstarted_stage ]['pid'] = $this->pid;
78
+
79
+ $this->saveQueue( $this->queue );
80
+
81
+ usleep( 1000 );
82
 
83
+ $this->refreshQueue();
84
+
85
+ if( $this->queue['stages'][ $this->unstarted_stage ]['pid'] !== $this->pid ){
86
+ return true;
87
+ }
88
+
89
+ $stage_to_execute = &$this->queue['stages'][ $this->unstarted_stage ];
90
+ }
91
+
92
+ if( $stage_to_execute ) {
93
+
94
+ if( is_callable( $stage_to_execute['name'] ) ) {
95
+
96
+ ++$stage_to_execute['tries'];
97
+
98
+ if( ! empty( $stage_to_execute['args'] ) ) {
99
+ $result = $stage_to_execute['name']( $stage_to_execute['args'] );
100
+ } else {
101
+ $result = $stage_to_execute['name']();
102
+ }
103
+
104
+ if( isset( $result['error'] ) ) {
105
+ $stage_to_execute['status'] = 'NULL';
106
+ if( isset( $result['update_args']['args'] ) ) {
107
+ $stage_to_execute['args'] = $result['update_args']['args'];
108
  }
109
+ $this->saveQueue( $this->queue );
110
+ if( $stage_to_execute['tries'] >= 3 ) {
111
+ $stage_to_execute['status'] = 'FINISHED';
112
+ $stage_to_execute['error'] = $result['error'];
113
+ $this->saveQueue( $this->queue );
114
+ return $result;
115
+ }
116
+ return \Cleantalk\ApbctWP\Helper::http__request__rc_to_host(
117
+ 'sfw_update__worker',
118
+ array(
119
+ 'firewall_updating_id' => $apbct->fw_stats['firewall_updating_id'],
120
+ 'stage' => 'Repeat ' . $stage_to_execute['name']
121
+ ),
122
+ array( 'async' )
123
+ );
124
+ }
125
 
126
+ if( isset( $result['next_stage'] ) ) {
127
+ $this->addStage(
128
+ $result['next_stage']['name'],
129
+ isset( $result['next_stage']['args'] ) ? $result['next_stage']['args'] : array()
130
+ );
131
+ }
132
 
133
+ if( isset( $result['next_stages'] ) && count( $result['next_stages'] ) ) {
134
+ foreach( $result['next_stages'] as $next_stage ) {
135
+ $this->addStage(
136
+ $next_stage['name'],
137
+ isset( $next_stage['args'] ) ? $next_stage['args'] : array()
138
+ );
139
+ }
140
  }
141
+
142
+ $stage_to_execute['status'] = 'FINISHED';
143
+ $this->saveQueue( $this->queue );
144
+
145
+ return $result;
146
+
147
+ }
148
+
149
+ return array( 'error' => $stage_to_execute['name'] . ' is not a callable function.' );
150
+
151
  }
152
  }
153
 
154
  public function isQueueInProgress()
155
  {
156
+ return
157
+ count( $this->queue['stages'] ) &&
158
+ (
159
+ in_array( 'NULL', array_column( $this->queue['stages'], 'status' ), true ) ||
160
+ in_array( 'IN_PROGRESS', array_column( $this->queue['stages'], 'status' ), true )
161
+ );
 
 
 
162
  }
163
 
164
  public function isQueueFinished()
165
  {
166
+ return ! $this->isQueueInProgress();
167
+ }
168
+
169
+ /**
170
+ * Checks if the queue is over
171
+ *
172
+ * @return bool
173
+ */
174
+ public function hasUnstartedStages()
175
+ {
176
+ if( count( $this->queue['stages'] ) > 0 ){
177
+ $this->unstarted_stage = array_search('NULL', array_column( $this->queue['stages'], 'status' ), true );
178
+ return is_int( $this->unstarted_stage );
179
  }
180
+
181
+ return false;
182
  }
183
 
184
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: spam, antispam, anti-spam, comments, firewall
4
  Requires at least: 3.0
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
- Stable tag: 5.160.2
8
  License: GPLv2
9
 
10
  Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
@@ -578,6 +578,13 @@ If your website has forms that send data to external sources, you can enable opt
578
 
579
  == Changelog ==
580
 
 
 
 
 
 
 
 
581
  = 5.160.2 Aug 26 2021 =
582
  * Fix. Pixel. Auto mode fixed.
583
 
4
  Requires at least: 3.0
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
+ Stable tag: 5.160.3
8
  License: GPLv2
9
 
10
  Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
578
 
579
  == Changelog ==
580
 
581
+ = 5.160.3 Aug 31 2021 =
582
+ * New: Queue. Transaction system.
583
+ * Fix. SFW. Updating for the new clients fixed.
584
+ * Fix. SFW. Deleting UA file fixed.
585
+ * Fix. SFW. Updating via cron fixed.
586
+ * Fix. SFW. Updating process for multisite fixed.
587
+
588
  = 5.160.2 Aug 26 2021 =
589
  * Fix. Pixel. Auto mode fixed.
590