Version Description
Jul 28 2020 = * Fix: Blocking good bots.
Download this release
Release Info
Developer | Safronik |
Plugin | Spam protection, AntiSpam, FireWall by CleanTalk |
Version | 5.142.1 |
Comparing to | |
See all releases |
Code changes from version 5.142 to 5.142.1
- cleantalk.php +11 -10
- inc/cleantalk-admin.php +1 -1
- inc/cleantalk-settings.php +12 -12
- inc/cleantalk-updater.php +12 -0
- lib/Cleantalk/ApbctWP/Firewall/AntiBot.php +0 -150
- lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php +59 -101
- lib/Cleantalk/ApbctWP/Firewall/AntiFlood.php +175 -0
- lib/Cleantalk/ApbctWP/Firewall/SFW.php +43 -52
- lib/Cleantalk/ApbctWP/Firewall/{die_page__antibot.html → die_page__AntiCrawler.html} +1 -1
- lib/Cleantalk/ApbctWP/Firewall/{die_page__anticrawler.html → die_page__AntiFlood.html} +0 -0
- lib/Cleantalk/ApbctWP/Firewall/{die_page__sfw.html → die_page__SFW.html} +1 -0
- lib/Cleantalk/ApbctWP/State.php +2 -2
- lib/Cleantalk/Common/Firewall.php +1 -1
- lib/Cleantalk/Common/Firewall/FirewallModule.php +13 -0
- readme.txt +5 -2
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.142
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: https://cleantalk.org
|
9 |
Text Domain: cleantalk-spam-protect
|
@@ -628,8 +628,8 @@ function apbct_sfw__check()
|
|
628 |
)
|
629 |
) );
|
630 |
|
631 |
-
if( $apbct->settings['
|
632 |
-
$firewall->load_fw_module( new \Cleantalk\ApbctWP\Firewall\
|
633 |
defined( 'APBCT_TBL_FIREWALL_LOG' ) ? APBCT_TBL_FIREWALL_LOG : $this->db->prefix . 'cleantalk_sfw_logs',
|
634 |
defined( 'APBCT_TBL_AC_LOG' ) ? APBCT_TBL_AC_LOG : $this->db->prefix . 'cleantalk_ac_log',
|
635 |
array(
|
@@ -639,15 +639,16 @@ function apbct_sfw__check()
|
|
639 |
) );
|
640 |
}
|
641 |
|
642 |
-
if( $apbct->settings['
|
643 |
-
$firewall->load_fw_module( new \Cleantalk\ApbctWP\Firewall\
|
644 |
-
defined( 'APBCT_TBL_FIREWALL_LOG' )
|
645 |
-
defined( 'APBCT_TBL_AC_LOG' )
|
646 |
array(
|
647 |
-
'view_limit' => $apbct->settings['
|
648 |
'apbct' => $apbct,
|
649 |
)
|
650 |
) );
|
|
|
651 |
|
652 |
$firewall->run();
|
653 |
|
@@ -672,7 +673,7 @@ function apbct_activation( $network = false ) {
|
|
672 |
$sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
|
673 |
`id` VARCHAR(40) NOT NULL,
|
674 |
`ip` VARCHAR(15) NOT NULL,
|
675 |
-
`status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'
|
676 |
`all_entries` INT NOT NULL,
|
677 |
`blocked_entries` INT NOT NULL,
|
678 |
`entries_timestamp` INT NOT NULL,
|
@@ -775,7 +776,7 @@ function apbct_activation__new_blog($blog_id, $user_id, $domain, $path, $site_id
|
|
775 |
$sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
|
776 |
`id` VARCHAR(40) NOT NULL,
|
777 |
`ip` VARCHAR(15) NOT NULL,
|
778 |
-
`status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'
|
779 |
`all_entries` INT NOT NULL,
|
780 |
`blocked_entries` INT NOT NULL,
|
781 |
`entries_timestamp` INT NOT NULL,
|
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.142.1
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: https://cleantalk.org
|
9 |
Text Domain: cleantalk-spam-protect
|
628 |
)
|
629 |
) );
|
630 |
|
631 |
+
if( $apbct->settings['sfw__anti_crawler'] ){
|
632 |
+
$firewall->load_fw_module( new \Cleantalk\ApbctWP\Firewall\AntiCrawler(
|
633 |
defined( 'APBCT_TBL_FIREWALL_LOG' ) ? APBCT_TBL_FIREWALL_LOG : $this->db->prefix . 'cleantalk_sfw_logs',
|
634 |
defined( 'APBCT_TBL_AC_LOG' ) ? APBCT_TBL_AC_LOG : $this->db->prefix . 'cleantalk_ac_log',
|
635 |
array(
|
639 |
) );
|
640 |
}
|
641 |
|
642 |
+
if( $apbct->settings['sfw__anti_flood'] ){
|
643 |
+
$firewall->load_fw_module( new \Cleantalk\ApbctWP\Firewall\AntiFlood(
|
644 |
+
defined( 'APBCT_TBL_FIREWALL_LOG' ) ? APBCT_TBL_FIREWALL_LOG : $this->db->prefix . 'cleantalk_sfw_logs',
|
645 |
+
defined( 'APBCT_TBL_AC_LOG' ) ? APBCT_TBL_AC_LOG : $this->db->prefix . 'cleantalk_ac_log',
|
646 |
array(
|
647 |
+
'view_limit' => $apbct->settings['sfw__anti_flood__view_limit'],
|
648 |
'apbct' => $apbct,
|
649 |
)
|
650 |
) );
|
651 |
+
}
|
652 |
|
653 |
$firewall->run();
|
654 |
|
673 |
$sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
|
674 |
`id` VARCHAR(40) NOT NULL,
|
675 |
`ip` VARCHAR(15) NOT NULL,
|
676 |
+
`status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTICRAWLER\',\'DENY_ANTIFLOOD\') NULL DEFAULT NULL,
|
677 |
`all_entries` INT NOT NULL,
|
678 |
`blocked_entries` INT NOT NULL,
|
679 |
`entries_timestamp` INT NOT NULL,
|
776 |
$sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
|
777 |
`id` VARCHAR(40) NOT NULL,
|
778 |
`ip` VARCHAR(15) NOT NULL,
|
779 |
+
`status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTICRAWLER\',\'DENY_ANTIFLOOD\') NULL DEFAULT NULL,
|
780 |
`all_entries` INT NOT NULL,
|
781 |
`blocked_entries` INT NOT NULL,
|
782 |
`entries_timestamp` INT NOT NULL,
|
inc/cleantalk-admin.php
CHANGED
@@ -10,7 +10,7 @@ add_action( 'manage_users_extra_tablenav', 'apbct_add_buttons_to_comments_and_us
|
|
10 |
add_action( 'wp_ajax_apbct_settings__check_renew_banner', 'apbct_settings__check_renew_banner');
|
11 |
|
12 |
// Crunch for Anti-Bot
|
13 |
-
add_action( 'admin_head',
|
14 |
|
15 |
function apbct_admin_set_cookie_for_anti_bot(){
|
16 |
global $apbct;
|
10 |
add_action( 'wp_ajax_apbct_settings__check_renew_banner', 'apbct_settings__check_renew_banner');
|
11 |
|
12 |
// Crunch for Anti-Bot
|
13 |
+
add_action( 'admin_head','apbct_admin_set_cookie_for_anti_bot' );
|
14 |
|
15 |
function apbct_admin_set_cookie_for_anti_bot(){
|
16 |
global $apbct;
|
inc/cleantalk-settings.php
CHANGED
@@ -95,17 +95,17 @@ function apbct_settings__set_fileds( $fields ){
|
|
95 |
'type' => 'checkbox',
|
96 |
'title' => __('SpamFireWall', 'cleantalk-spam-protect'),
|
97 |
'description' => __("This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.", 'cleantalk-spam-protect'),
|
98 |
-
'childrens' => array('
|
99 |
),
|
100 |
-
'
|
101 |
'type' => 'checkbox',
|
102 |
-
'title' => __('
|
103 |
'class' => 'apbct_settings-field_wrapper--sub',
|
104 |
'parent' => 'spam_firewall',
|
105 |
-
'childrens' => array('
|
106 |
'description' => __('Shows SpamFireWall page for bot which are trying to scan your website. Look for the page limit setting below.', 'cleantalk-spam-protect'),
|
107 |
),
|
108 |
-
'
|
109 |
'type' => 'checkbox',
|
110 |
'title' => __('Anti-Crawler', 'cleantalk-spam-protect'),
|
111 |
'class' => 'apbct_settings-field_wrapper--sub',
|
@@ -434,11 +434,11 @@ function apbct_settings__set_fileds( $fields ){
|
|
434 |
'options_callback_params' => array(true),
|
435 |
'class' => 'apbct_settings-field_wrapper--sub',
|
436 |
),
|
437 |
-
'
|
438 |
'type' => 'text',
|
439 |
-
'title' => __('
|
440 |
'class' => 'apbct_settings-field_wrapper',
|
441 |
-
'parent' => '
|
442 |
'description' => __('Count of page view per 1 minute before plugin shows SpamFireWall page. SpamFireWall page active for 30 second after that valid visitor (with JavaScript) passes the page to the demanded page of the site.', 'cleantalk-spam-protect'),
|
443 |
),
|
444 |
'complete_deactivation' => array(
|
@@ -1333,10 +1333,10 @@ function apbct_settings__validate($settings) {
|
|
1333 |
}
|
1334 |
} unset($setting, $value);
|
1335 |
|
1336 |
-
//Sanitizing
|
1337 |
-
$settings['
|
1338 |
-
$settings['
|
1339 |
-
$settings['
|
1340 |
|
1341 |
// Validating API key
|
1342 |
$settings['apikey'] = !empty($settings['apikey']) ? trim($settings['apikey']) : '';
|
95 |
'type' => 'checkbox',
|
96 |
'title' => __('SpamFireWall', 'cleantalk-spam-protect'),
|
97 |
'description' => __("This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.", 'cleantalk-spam-protect'),
|
98 |
+
'childrens' => array('sfw__anti_flood', 'sfw__anti_crawler'),
|
99 |
),
|
100 |
+
'sfw__anti_flood' => array(
|
101 |
'type' => 'checkbox',
|
102 |
+
'title' => __('Anti-Flood', 'cleantalk-spam-protect'),
|
103 |
'class' => 'apbct_settings-field_wrapper--sub',
|
104 |
'parent' => 'spam_firewall',
|
105 |
+
'childrens' => array('sfw__anti_flood__view_limit',),
|
106 |
'description' => __('Shows SpamFireWall page for bot which are trying to scan your website. Look for the page limit setting below.', 'cleantalk-spam-protect'),
|
107 |
),
|
108 |
+
'sfw__anti_crawler' => array(
|
109 |
'type' => 'checkbox',
|
110 |
'title' => __('Anti-Crawler', 'cleantalk-spam-protect'),
|
111 |
'class' => 'apbct_settings-field_wrapper--sub',
|
434 |
'options_callback_params' => array(true),
|
435 |
'class' => 'apbct_settings-field_wrapper--sub',
|
436 |
),
|
437 |
+
'sfw__anti_flood__view_limit' => array(
|
438 |
'type' => 'text',
|
439 |
+
'title' => __('Anti-Flood Page Views Limit', 'cleantalk-spam-protect'),
|
440 |
'class' => 'apbct_settings-field_wrapper',
|
441 |
+
'parent' => 'sfw__anti_flood',
|
442 |
'description' => __('Count of page view per 1 minute before plugin shows SpamFireWall page. SpamFireWall page active for 30 second after that valid visitor (with JavaScript) passes the page to the demanded page of the site.', 'cleantalk-spam-protect'),
|
443 |
),
|
444 |
'complete_deactivation' => array(
|
1333 |
}
|
1334 |
} unset($setting, $value);
|
1335 |
|
1336 |
+
//Sanitizing sfw__anti_flood__view_limit setting
|
1337 |
+
$settings['sfw__anti_flood__view_limit'] = floor( intval( $settings['sfw__anti_flood__view_limit'] ) );
|
1338 |
+
$settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] == 0 ? 10 : $settings['sfw__anti_flood__view_limit'] ); // Default if 0 passed
|
1339 |
+
$settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] < 5 ? 5 : $settings['sfw__anti_flood__view_limit'] ); //
|
1340 |
|
1341 |
// Validating API key
|
1342 |
$settings['apikey'] = !empty($settings['apikey']) ? trim($settings['apikey']) : '';
|
inc/cleantalk-updater.php
CHANGED
@@ -518,6 +518,7 @@ function apbct_update_to_5_138_0() {
|
|
518 |
}
|
519 |
|
520 |
}
|
|
|
521 |
function apbct_update_to_5_142_0() {
|
522 |
|
523 |
$sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
|
@@ -535,4 +536,15 @@ function apbct_update_to_5_142_0() {
|
|
535 |
|
536 |
apbct_activation__create_tables( $sqls );
|
537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
}
|
518 |
}
|
519 |
|
520 |
}
|
521 |
+
|
522 |
function apbct_update_to_5_142_0() {
|
523 |
|
524 |
$sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
|
536 |
|
537 |
apbct_activation__create_tables( $sqls );
|
538 |
|
539 |
+
}
|
540 |
+
|
541 |
+
function apbct_update_to_5_142_1() {
|
542 |
+
|
543 |
+
$sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
|
544 |
+
|
545 |
+
$sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
|
546 |
+
CHANGE `status` `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTICRAWLER\',\'DENY_ANTIFLOOD\') NOT NULL AFTER `ip`;';
|
547 |
+
|
548 |
+
apbct_activation__create_tables( $sqls );
|
549 |
+
|
550 |
}
|
lib/Cleantalk/ApbctWP/Firewall/AntiBot.php
DELETED
@@ -1,150 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
namespace Cleantalk\ApbctWP\Firewall;
|
5 |
-
|
6 |
-
|
7 |
-
use Cleantalk\Variables\Cookie;
|
8 |
-
use Cleantalk\Variables\Server;
|
9 |
-
|
10 |
-
class AntiBot extends \Cleantalk\Common\Firewall\FirewallModule{
|
11 |
-
|
12 |
-
public $module_name = 'ANTIBOT';
|
13 |
-
|
14 |
-
private $db__table__ac_logs;
|
15 |
-
private $api_key = '';
|
16 |
-
private $apbct = false;
|
17 |
-
|
18 |
-
/**
|
19 |
-
* AntiBot constructor.
|
20 |
-
*
|
21 |
-
* @param $log_table
|
22 |
-
* @param $ac_logs_table
|
23 |
-
* @param array $params
|
24 |
-
*/
|
25 |
-
public function __construct( $log_table, $ac_logs_table, $params = array() ) {
|
26 |
-
|
27 |
-
$this->db__table__logs = $log_table ?: null;
|
28 |
-
$this->db__table__ac_logs = $ac_logs_table ?: null;
|
29 |
-
|
30 |
-
foreach( $params as $param_name => $param ){
|
31 |
-
$this->$param_name = isset( $this->$param_name ) ? $param : false;
|
32 |
-
}
|
33 |
-
|
34 |
-
}
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Use this method to execute main logic of the module.
|
38 |
-
*
|
39 |
-
* @return array Array of the check results
|
40 |
-
*/
|
41 |
-
public function check() {
|
42 |
-
|
43 |
-
$results = array();
|
44 |
-
|
45 |
-
foreach( $this->ip_array as $ip_origin => $current_ip ){
|
46 |
-
|
47 |
-
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
48 |
-
|
49 |
-
$result = $this->db->fetch(
|
50 |
-
"SELECT ip"
|
51 |
-
. ' FROM `' . $this->db__table__ac_logs . '`'
|
52 |
-
. " WHERE ip = '$current_ip'"
|
53 |
-
. " LIMIT 1;"
|
54 |
-
);
|
55 |
-
|
56 |
-
if( ! empty( $result ) && isset( $result['ip'] ) ){
|
57 |
-
if( Cookie::get('apbct_antibot') !== md5( $this->api_key . $current_ip ) ){
|
58 |
-
$results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTIBOT', );
|
59 |
-
}
|
60 |
-
}else{
|
61 |
-
add_action( 'wp_head', array( '\Cleantalk\ApbctWP\Firewall\AntiBot', 'set_cookie' ) );
|
62 |
-
global $apbct_antibot_ip;
|
63 |
-
$apbct_antibot_ip = $current_ip;
|
64 |
-
}
|
65 |
-
}
|
66 |
-
|
67 |
-
return $results;
|
68 |
-
|
69 |
-
}
|
70 |
-
|
71 |
-
public static function set_cookie(){
|
72 |
-
global $apbct, $apbct_antibot_ip;
|
73 |
-
echo '<script>document.cookie = "apbct_antibot=' . md5( $apbct->api_key . $apbct_antibot_ip ) . '; path=/; expires=0; samesite=lax";</script>';
|
74 |
-
}
|
75 |
-
|
76 |
-
/**
|
77 |
-
* Add entry to SFW log.
|
78 |
-
* Writes to database.
|
79 |
-
*
|
80 |
-
* @param string $ip
|
81 |
-
* @param $status
|
82 |
-
*/
|
83 |
-
public function update_log( $ip, $status ) {
|
84 |
-
|
85 |
-
$blocked = ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' );
|
86 |
-
|
87 |
-
if( $blocked ){
|
88 |
-
|
89 |
-
$id = md5( $ip . $status );
|
90 |
-
$time = time();
|
91 |
-
|
92 |
-
$query = "INSERT INTO " . $this->db__table__logs . "
|
93 |
-
SET
|
94 |
-
id = '$id',
|
95 |
-
ip = '$ip',
|
96 |
-
status = '$status',
|
97 |
-
all_entries = 1,
|
98 |
-
blocked_entries = 1,
|
99 |
-
entries_timestamp = '" . intval( $time ) . "'
|
100 |
-
ON DUPLICATE KEY
|
101 |
-
UPDATE
|
102 |
-
all_entries = all_entries + 1,
|
103 |
-
blocked_entries = blocked_entries" . strval( $blocked ) . ",
|
104 |
-
entries_timestamp = '" . intval( $time ) . "'";
|
105 |
-
|
106 |
-
$this->db->execute( $query );
|
107 |
-
}
|
108 |
-
}
|
109 |
-
|
110 |
-
public function _die( $result ){
|
111 |
-
|
112 |
-
// Headers
|
113 |
-
if(headers_sent() === false){
|
114 |
-
header('Expires: '.date(DATE_RFC822, mktime(0, 0, 0, 1, 1, 1971)));
|
115 |
-
header('Cache-Control: no-store, no-cache, must-revalidate');
|
116 |
-
header('Cache-Control: post-check=0, pre-check=0', FALSE);
|
117 |
-
header('Pragma: no-cache');
|
118 |
-
header("HTTP/1.0 403 Forbidden");
|
119 |
-
}
|
120 |
-
|
121 |
-
// File exists?
|
122 |
-
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__antibot.html")){
|
123 |
-
|
124 |
-
$sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__antibot.html");
|
125 |
-
|
126 |
-
// Translation
|
127 |
-
$request_uri = Server::get( 'REQUEST_URI' );
|
128 |
-
$sfw_die_page = str_replace('{SFW_DIE_NOTICE_IP}', __('Anti-Crawler Protection is activated for your IP ', 'cleantalk-spam-protect'), $sfw_die_page);
|
129 |
-
$sfw_die_page = str_replace('{SFW_DIE_MAKE_SURE_JS_ENABLED}', __('To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect'), $sfw_die_page);
|
130 |
-
$sfw_die_page = str_replace('{SFW_DIE_YOU_WILL_BE_REDIRECTED}', sprintf(__('You will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect'), 30), $sfw_die_page);
|
131 |
-
$sfw_die_page = str_replace('{CLEANTALK_TITLE}', __('Antispam by CleanTalk', 'cleantalk-spam-protect'), $sfw_die_page);
|
132 |
-
|
133 |
-
$sfw_die_page = str_replace('{REMOTE_ADDRESS}', $result['ip'], $sfw_die_page);
|
134 |
-
|
135 |
-
// Service info
|
136 |
-
$sfw_die_page = str_replace('{SERVICE_ID}', $this->apbct->data['service_id'], $sfw_die_page);
|
137 |
-
$sfw_die_page = str_replace('{HOST}', Server::get( 'HTTP_HOST' ), $sfw_die_page);
|
138 |
-
|
139 |
-
$sfw_die_page = str_replace('{SFW_COOKIE}', md5( $this->api_key . $result['ip'] ), $sfw_die_page );
|
140 |
-
|
141 |
-
$sfw_die_page = str_replace('{GENERATED}', "<p>The page was generated at ".date("D, d M Y H:i:s")."</p>",$sfw_die_page);
|
142 |
-
|
143 |
-
wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
|
144 |
-
|
145 |
-
}else{
|
146 |
-
wp_die("IP BLACKLISTED", "Blacklisted", Array('response'=>403));
|
147 |
-
}
|
148 |
-
|
149 |
-
}
|
150 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php
CHANGED
@@ -2,7 +2,8 @@
|
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\Firewall;
|
4 |
|
5 |
-
|
|
|
6 |
use Cleantalk\Variables\Server;
|
7 |
|
8 |
class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
@@ -10,15 +11,11 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
10 |
public $module_name = 'ANTICRAWLER';
|
11 |
|
12 |
private $db__table__ac_logs;
|
13 |
-
|
14 |
-
private $
|
15 |
-
private $apbct = array();
|
16 |
-
private $store_interval = 30;
|
17 |
-
private $block_period = 30;
|
18 |
-
private $chance_to_clean = 100;
|
19 |
|
20 |
/**
|
21 |
-
*
|
22 |
*
|
23 |
* @param $log_table
|
24 |
* @param $ac_logs_table
|
@@ -37,77 +34,42 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
37 |
|
38 |
/**
|
39 |
* Use this method to execute main logic of the module.
|
40 |
-
*
|
|
|
41 |
*/
|
42 |
public function check() {
|
43 |
|
44 |
$results = array();
|
45 |
|
46 |
-
$this->clear_table();
|
47 |
-
|
48 |
-
$time = time() - $this->store_interval;
|
49 |
-
|
50 |
foreach( $this->ip_array as $ip_origin => $current_ip ){
|
51 |
|
52 |
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
53 |
|
54 |
-
$result = $this->db->
|
55 |
-
"SELECT
|
56 |
. ' FROM `' . $this->db__table__ac_logs . '`'
|
57 |
-
. " WHERE ip = '$current_ip'
|
|
|
58 |
);
|
59 |
|
60 |
-
if( ! empty( $result ) && isset( $result[
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
}
|
63 |
}
|
64 |
|
65 |
-
if( ! empty( $results ) ){
|
66 |
-
// Do block page
|
67 |
-
return $results;
|
68 |
-
} else{
|
69 |
-
// Do logging entries
|
70 |
-
$this->update_ac_log();
|
71 |
-
}
|
72 |
-
|
73 |
return $results;
|
74 |
|
75 |
}
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
82 |
-
|
83 |
-
foreach( $this->ip_array as $ip_origin => $current_ip ){
|
84 |
-
$id = md5( $current_ip . $interval_time );
|
85 |
-
$this->db->execute(
|
86 |
-
"INSERT INTO " . $this->db__table__ac_logs . " SET
|
87 |
-
id = '$id',
|
88 |
-
ip = '$current_ip',
|
89 |
-
entries = 1,
|
90 |
-
interval_start = $interval_time
|
91 |
-
ON DUPLICATE KEY UPDATE
|
92 |
-
ip = ip,
|
93 |
-
entries = entries + 1,
|
94 |
-
interval_start = $interval_time;"
|
95 |
-
);
|
96 |
-
}
|
97 |
-
|
98 |
-
}
|
99 |
-
|
100 |
-
private function clear_table() {
|
101 |
-
|
102 |
-
if( rand( 0, 1000 ) < $this->chance_to_clean ){
|
103 |
-
$interval_start = \Cleantalk\ApbctWP\Helper::time__get_interval_start( $this->block_period );
|
104 |
-
$this->db->execute(
|
105 |
-
'DELETE
|
106 |
-
FROM ' . $this->db__table__ac_logs . '
|
107 |
-
WHERE interval_start < '. $interval_start .'
|
108 |
-
LIMIT 100000;'
|
109 |
-
);
|
110 |
-
}
|
111 |
}
|
112 |
|
113 |
/**
|
@@ -119,58 +81,54 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
119 |
*/
|
120 |
public function update_log( $ip, $status ) {
|
121 |
|
122 |
-
$id = md5($ip.$status);
|
123 |
$blocked = ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' );
|
124 |
-
$time = time();
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
id
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
}
|
142 |
|
143 |
public function _die( $result ){
|
144 |
|
145 |
-
// Headers
|
146 |
-
if(headers_sent() === false){
|
147 |
-
header('Expires: '.date(DATE_RFC822, mktime(0, 0, 0, 1, 1, 1971)));
|
148 |
-
header('Cache-Control: no-store, no-cache, must-revalidate');
|
149 |
-
header('Cache-Control: post-check=0, pre-check=0', FALSE);
|
150 |
-
header('Pragma: no-cache');
|
151 |
-
header("HTTP/1.0 403 Forbidden");
|
152 |
-
}
|
153 |
-
|
154 |
// File exists?
|
155 |
-
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/
|
156 |
|
157 |
-
$sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/
|
158 |
|
159 |
// Translation
|
160 |
-
$
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
$sfw_die_page = str_replace('{HOST}', Server::get( 'HTTP_HOST' ), $sfw_die_page);;
|
172 |
|
173 |
-
|
|
|
|
|
174 |
|
175 |
wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
|
176 |
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\Firewall;
|
4 |
|
5 |
+
|
6 |
+
use Cleantalk\Variables\Cookie;
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
9 |
class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
11 |
public $module_name = 'ANTICRAWLER';
|
12 |
|
13 |
private $db__table__ac_logs;
|
14 |
+
private $api_key = '';
|
15 |
+
private $apbct = false;
|
|
|
|
|
|
|
|
|
16 |
|
17 |
/**
|
18 |
+
* AntiBot constructor.
|
19 |
*
|
20 |
* @param $log_table
|
21 |
* @param $ac_logs_table
|
34 |
|
35 |
/**
|
36 |
* Use this method to execute main logic of the module.
|
37 |
+
*
|
38 |
+
* @return array Array of the check results
|
39 |
*/
|
40 |
public function check() {
|
41 |
|
42 |
$results = array();
|
43 |
|
|
|
|
|
|
|
|
|
44 |
foreach( $this->ip_array as $ip_origin => $current_ip ){
|
45 |
|
46 |
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
47 |
|
48 |
+
$result = $this->db->fetch(
|
49 |
+
"SELECT ip"
|
50 |
. ' FROM `' . $this->db__table__ac_logs . '`'
|
51 |
+
. " WHERE ip = '$current_ip'"
|
52 |
+
. " LIMIT 1;"
|
53 |
);
|
54 |
|
55 |
+
if( ! empty( $result ) && isset( $result['ip'] ) ){
|
56 |
+
if( Cookie::get('apbct_antibot') !== md5( $this->api_key . $current_ip ) ){
|
57 |
+
$results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTICRAWLER', );
|
58 |
+
}
|
59 |
+
}else{
|
60 |
+
add_action( 'wp_head', array( '\Cleantalk\ApbctWP\Firewall\AntiCrawler', 'set_cookie' ) );
|
61 |
+
global $apbct_anticrawler_ip;
|
62 |
+
$apbct_anticrawler_ip = $current_ip;
|
63 |
}
|
64 |
}
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
return $results;
|
67 |
|
68 |
}
|
69 |
|
70 |
+
public static function set_cookie(){
|
71 |
+
global $apbct, $apbct_anticrawler_ip;
|
72 |
+
echo '<script>document.cookie = "apbct_antibot=' . md5( $apbct->api_key . $apbct_anticrawler_ip ) . '; path=/; expires=0; samesite=lax";</script>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
74 |
|
75 |
/**
|
81 |
*/
|
82 |
public function update_log( $ip, $status ) {
|
83 |
|
|
|
84 |
$blocked = ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' );
|
|
|
85 |
|
86 |
+
if( $blocked ){
|
87 |
+
|
88 |
+
$id = md5( $ip . $status );
|
89 |
+
$time = time();
|
90 |
+
|
91 |
+
$query = "INSERT INTO " . $this->db__table__logs . "
|
92 |
+
SET
|
93 |
+
id = '$id',
|
94 |
+
ip = '$ip',
|
95 |
+
status = '$status',
|
96 |
+
all_entries = 1,
|
97 |
+
blocked_entries = 1,
|
98 |
+
entries_timestamp = '" . intval( $time ) . "'
|
99 |
+
ON DUPLICATE KEY
|
100 |
+
UPDATE
|
101 |
+
all_entries = all_entries + 1,
|
102 |
+
blocked_entries = blocked_entries" . strval( $blocked ) . ",
|
103 |
+
entries_timestamp = '" . intval( $time ) . "'";
|
104 |
+
|
105 |
+
$this->db->execute( $query );
|
106 |
+
}
|
107 |
}
|
108 |
|
109 |
public function _die( $result ){
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
// File exists?
|
112 |
+
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__AntiCrawler.html")){
|
113 |
|
114 |
+
$sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__AntiCrawler.html");
|
115 |
|
116 |
// Translation
|
117 |
+
$replaces = array(
|
118 |
+
'{SFW_DIE_NOTICE_IP}' => __('Anti-Crawler Protection is activated for your IP ', 'cleantalk-spam-protect'),
|
119 |
+
'{SFW_DIE_MAKE_SURE_JS_ENABLED}' => __( 'To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect' ),
|
120 |
+
'{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => sprintf( __( 'You will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect' ), 30 ),
|
121 |
+
'{CLEANTALK_TITLE}' => __( 'Antispam by CleanTalk', 'cleantalk-spam-protect' ),
|
122 |
+
'{REMOTE_ADDRESS}' => $result['ip'],
|
123 |
+
'{SERVICE_ID}' => $this->apbct->data['service_id'],
|
124 |
+
'{HOST}' => Server::get( 'HTTP_HOST' ),
|
125 |
+
'{COOKIE_ANTICRAWLER}' => md5( $this->api_key . $result['ip'] ),
|
126 |
+
'{GENERATED}' => '<p>The page was generated at ' . date( 'D, d M Y H:i:s' ) . "</p>",
|
127 |
+
);
|
|
|
128 |
|
129 |
+
foreach( $replaces as $place_holder => $replace ){
|
130 |
+
$sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
|
131 |
+
}
|
132 |
|
133 |
wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
|
134 |
|
lib/Cleantalk/ApbctWP/Firewall/AntiFlood.php
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace Cleantalk\ApbctWP\Firewall;
|
4 |
+
|
5 |
+
use Cleantalk\Common\Helper as Helper;
|
6 |
+
use Cleantalk\Variables\Server;
|
7 |
+
|
8 |
+
class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
9 |
+
|
10 |
+
public $module_name = 'ANTIFLOOD';
|
11 |
+
|
12 |
+
private $db__table__ac_logs;
|
13 |
+
|
14 |
+
private $view_limit = 10;
|
15 |
+
private $apbct = array();
|
16 |
+
private $store_interval = 30;
|
17 |
+
private $block_period = 30;
|
18 |
+
private $chance_to_clean = 100;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* AntiCrawler constructor.
|
22 |
+
*
|
23 |
+
* @param $log_table
|
24 |
+
* @param $ac_logs_table
|
25 |
+
* @param array $params
|
26 |
+
*/
|
27 |
+
public function __construct( $log_table, $ac_logs_table, $params = array() ) {
|
28 |
+
|
29 |
+
$this->db__table__logs = $log_table ?: null;
|
30 |
+
$this->db__table__ac_logs = $ac_logs_table ?: null;
|
31 |
+
|
32 |
+
foreach( $params as $param_name => $param ){
|
33 |
+
$this->$param_name = isset( $this->$param_name ) ? $param : false;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Use this method to execute main logic of the module.
|
39 |
+
* @return array
|
40 |
+
*/
|
41 |
+
public function check() {
|
42 |
+
|
43 |
+
$results = array();
|
44 |
+
|
45 |
+
$this->clear_table();
|
46 |
+
|
47 |
+
$time = time() - $this->store_interval;
|
48 |
+
|
49 |
+
foreach( $this->ip_array as $ip_origin => $current_ip ){
|
50 |
+
|
51 |
+
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
52 |
+
|
53 |
+
$result = $this->db->fetch_all(
|
54 |
+
"SELECT SUM(entries) as total_count"
|
55 |
+
. ' FROM `' . $this->db__table__ac_logs . '`'
|
56 |
+
. " WHERE ip = '$current_ip' AND interval_start > '$time';"
|
57 |
+
);
|
58 |
+
|
59 |
+
if( ! empty( $result ) && isset( $result[0]['total_count'] ) && $result[0]['total_count'] >= $this->view_limit ){
|
60 |
+
$results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTIFLOOD', );
|
61 |
+
}
|
62 |
+
}
|
63 |
+
|
64 |
+
if( ! empty( $results ) ){
|
65 |
+
// Do block page
|
66 |
+
return $results;
|
67 |
+
} else{
|
68 |
+
// Do logging entries
|
69 |
+
$this->update_ac_log();
|
70 |
+
}
|
71 |
+
|
72 |
+
return $results;
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
+
private function update_ac_log() {
|
77 |
+
|
78 |
+
$interval_time = Helper::time__get_interval_start( $this->store_interval );
|
79 |
+
|
80 |
+
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
81 |
+
|
82 |
+
foreach( $this->ip_array as $ip_origin => $current_ip ){
|
83 |
+
$id = md5( $current_ip . $interval_time );
|
84 |
+
$this->db->execute(
|
85 |
+
"INSERT INTO " . $this->db__table__ac_logs . " SET
|
86 |
+
id = '$id',
|
87 |
+
ip = '$current_ip',
|
88 |
+
entries = 1,
|
89 |
+
interval_start = $interval_time
|
90 |
+
ON DUPLICATE KEY UPDATE
|
91 |
+
ip = ip,
|
92 |
+
entries = entries + 1,
|
93 |
+
interval_start = $interval_time;"
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
private function clear_table() {
|
100 |
+
|
101 |
+
if( rand( 0, 1000 ) < $this->chance_to_clean ){
|
102 |
+
$interval_start = \Cleantalk\ApbctWP\Helper::time__get_interval_start( $this->block_period );
|
103 |
+
$this->db->execute(
|
104 |
+
'DELETE
|
105 |
+
FROM ' . $this->db__table__ac_logs . '
|
106 |
+
WHERE interval_start < '. $interval_start .'
|
107 |
+
LIMIT 100000;'
|
108 |
+
);
|
109 |
+
}
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Add entry to SFW log.
|
114 |
+
* Writes to database.
|
115 |
+
*
|
116 |
+
* @param string $ip
|
117 |
+
* @param $status
|
118 |
+
*/
|
119 |
+
public function update_log( $ip, $status ) {
|
120 |
+
|
121 |
+
$id = md5($ip.$status);
|
122 |
+
$blocked = ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' );
|
123 |
+
$time = time();
|
124 |
+
|
125 |
+
$query = "INSERT INTO " . $this->db__table__logs . "
|
126 |
+
SET
|
127 |
+
id = '$id',
|
128 |
+
ip = '$ip',
|
129 |
+
status = '$status',
|
130 |
+
all_entries = 1,
|
131 |
+
blocked_entries = 1,
|
132 |
+
entries_timestamp = '" . intval( $time ) . "'
|
133 |
+
ON DUPLICATE KEY
|
134 |
+
UPDATE
|
135 |
+
all_entries = all_entries + 1,
|
136 |
+
blocked_entries = blocked_entries" . strval( $blocked ) . ",
|
137 |
+
entries_timestamp = '" . intval( $time ) . "'";
|
138 |
+
|
139 |
+
$this->db->execute( $query );
|
140 |
+
}
|
141 |
+
|
142 |
+
public function _die( $result ) {
|
143 |
+
|
144 |
+
parent::_die( $result );
|
145 |
+
|
146 |
+
// File exists?
|
147 |
+
if( file_exists( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page__AntiFlood.html' ) ){
|
148 |
+
|
149 |
+
$sfw_die_page = file_get_contents( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page__AntiFlood.html' );
|
150 |
+
|
151 |
+
// Translation
|
152 |
+
$replaces = array(
|
153 |
+
'{SFW_DIE_NOTICE_IP}' => __( 'Anti-Flood is activated for your IP', 'cleantalk-spam-protect' ),
|
154 |
+
'{SFW_DIE_MAKE_SURE_JS_ENABLED}' => __( 'To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect' ),
|
155 |
+
'{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => sprintf( __( 'You will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect' ), 30 ),
|
156 |
+
'{CLEANTALK_TITLE}' => __( 'Antispam by CleanTalk', 'cleantalk-spam-protect' ),
|
157 |
+
'{REMOTE_ADDRESS}' => $result['ip'],
|
158 |
+
'{REQUEST_URI}' => Server::get( 'REQUEST_URI' ),
|
159 |
+
'{SERVICE_ID}' => $this->apbct->data['service_id'],
|
160 |
+
'{HOST}' => Server::get( 'HTTP_HOST' ),
|
161 |
+
'{GENERATED}' => '<p>The page was generated at ' . date( 'D, d M Y H:i:s' ) . "</p>",
|
162 |
+
);
|
163 |
+
|
164 |
+
foreach( $replaces as $place_holder => $replace ){
|
165 |
+
$sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
|
166 |
+
}
|
167 |
+
|
168 |
+
wp_die( $sfw_die_page, 'Blacklisted', array( 'response' => 403 ) );
|
169 |
+
|
170 |
+
} else{
|
171 |
+
wp_die( 'IP BLACKLISTED', 'Blacklisted', array( 'response' => 403 ) );
|
172 |
+
}
|
173 |
+
|
174 |
+
}
|
175 |
+
}
|
lib/Cleantalk/ApbctWP/Firewall/SFW.php
CHANGED
@@ -119,7 +119,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
119 |
|
120 |
foreach( $db_results as $db_result ){
|
121 |
|
122 |
-
if( $db_result['status']
|
123 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_SFW_BY_WHITELIST',);
|
124 |
else
|
125 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_SFW',);
|
@@ -185,11 +185,11 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
185 |
* Stops script executing.
|
186 |
*
|
187 |
* @param $result
|
188 |
-
* @param string $cookie_domain
|
189 |
-
* @param bool $test
|
190 |
*/
|
191 |
public function _die( $result ){
|
192 |
|
|
|
|
|
193 |
// Statistics
|
194 |
if(!empty($this->blocked_ips)){
|
195 |
reset($this->blocked_ips);
|
@@ -198,58 +198,48 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
198 |
$this->apbct->save('stats');
|
199 |
}
|
200 |
|
201 |
-
// Headers
|
202 |
-
if(headers_sent() === false){
|
203 |
-
header('Expires: '.date(DATE_RFC822, mktime(0, 0, 0, 1, 1, 1971)));
|
204 |
-
header('Cache-Control: no-store, no-cache, must-revalidate');
|
205 |
-
header('Cache-Control: post-check=0, pre-check=0', FALSE);
|
206 |
-
header('Pragma: no-cache');
|
207 |
-
header("HTTP/1.0 403 Forbidden");
|
208 |
-
}
|
209 |
-
|
210 |
// File exists?
|
211 |
-
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/
|
212 |
|
213 |
-
$sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/
|
214 |
|
215 |
// Translation
|
216 |
-
$
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
|
|
224 |
if($this->test){
|
225 |
-
$
|
226 |
-
$
|
227 |
-
$
|
228 |
-
$
|
229 |
-
|
230 |
-
$sfw_die_page = str_replace('{REAL_IP__HEADER}', '', $sfw_die_page);
|
231 |
-
$sfw_die_page = str_replace('{TEST_IP__HEADER}', '', $sfw_die_page);
|
232 |
-
$sfw_die_page = str_replace('{TEST_IP}', '', $sfw_die_page);
|
233 |
-
$sfw_die_page = str_replace('{REAL_IP}', '', $sfw_die_page);
|
234 |
}
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
// Service info
|
239 |
-
$sfw_die_page = str_replace('{REQUEST_URI}', $request_uri, $sfw_die_page);
|
240 |
-
$sfw_die_page = str_replace('{COOKIE_PREFIX}', '', $sfw_die_page);
|
241 |
-
$sfw_die_page = str_replace('{COOKIE_DOMAIN}', $this->cookie_domain, $sfw_die_page);
|
242 |
-
$sfw_die_page = str_replace('{SERVICE_ID}', $this->apbct->data['service_id'], $sfw_die_page);
|
243 |
-
$sfw_die_page = str_replace('{HOST}', Server::get( 'HTTP_HOST' ), $sfw_die_page);
|
244 |
-
|
245 |
-
$sfw_die_page = str_replace(
|
246 |
-
'{SFW_COOKIE}',
|
247 |
-
$this->test
|
248 |
-
? $this->test_ip
|
249 |
-
: md5( $result['ip'] . $this->api_key ),
|
250 |
-
$sfw_die_page
|
251 |
-
);
|
252 |
-
|
253 |
if($this->debug){
|
254 |
$debug = '<h1>Headers</h1>'
|
255 |
. var_export(apache_request_headers(), true)
|
@@ -261,11 +251,12 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
261 |
. var_export($this->ip_array, true)
|
262 |
. '<h1>ADDITIONAL</h1>'
|
263 |
. var_export($this->debug_data, true);
|
264 |
-
}
|
265 |
-
|
266 |
|
267 |
-
$
|
268 |
-
|
|
|
269 |
|
270 |
wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
|
271 |
|
@@ -297,7 +288,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
297 |
foreach( $db->result as $key => $value ){
|
298 |
|
299 |
$value['status'] = $value['status'] === 'DENY_ANTICRAWLER' ? 'BOT_PROTECTION' : $value['status'];
|
300 |
-
$value['status'] = $value['status'] === '
|
301 |
|
302 |
$data[] = array(
|
303 |
trim( $value['ip'] ),
|
119 |
|
120 |
foreach( $db_results as $db_result ){
|
121 |
|
122 |
+
if( $db_result['status'] == 1 )
|
123 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_SFW_BY_WHITELIST',);
|
124 |
else
|
125 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_SFW',);
|
185 |
* Stops script executing.
|
186 |
*
|
187 |
* @param $result
|
|
|
|
|
188 |
*/
|
189 |
public function _die( $result ){
|
190 |
|
191 |
+
parent::_die( $result );
|
192 |
+
|
193 |
// Statistics
|
194 |
if(!empty($this->blocked_ips)){
|
195 |
reset($this->blocked_ips);
|
198 |
$this->apbct->save('stats');
|
199 |
}
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
// File exists?
|
202 |
+
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__SFW.html")){
|
203 |
|
204 |
+
$sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__SFW.html");
|
205 |
|
206 |
// Translation
|
207 |
+
$replaces = array(
|
208 |
+
'{SFW_DIE_NOTICE_IP}' => __('SpamFireWall is activated for your IP ', 'cleantalk-spam-protect'),
|
209 |
+
'{SFW_DIE_MAKE_SURE_JS_ENABLED}' => __( 'To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect' ),
|
210 |
+
'{SFW_DIE_CLICK_TO_PASS}' => __('Please click the link below to pass the protection,', 'cleantalk-spam-protect'),
|
211 |
+
'{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => sprintf(__('Or you will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect'), 3),
|
212 |
+
'{CLEANTALK_TITLE}' => ($this->test ? __('This is the testing page for SpamFireWall', 'cleantalk-spam-protect') : ''),
|
213 |
+
'{REMOTE_ADDRESS}' => $result['ip'],
|
214 |
+
'{SERVICE_ID}' => $this->apbct->data['service_id'],
|
215 |
+
'{HOST}' => Server::get( 'HTTP_HOST' ),
|
216 |
+
'{GENERATED}' => '<p>The page was generated at ' . date( 'D, d M Y H:i:s' ) . "</p>",
|
217 |
+
'{REQUEST_URI}' => Server::get( 'REQUEST_URI' ),
|
218 |
+
|
219 |
+
// Cookie
|
220 |
+
'{COOKIE_PREFIX}' => '',
|
221 |
+
'{COOKIE_DOMAIN}' => $this->cookie_domain,
|
222 |
+
'{COOKIE_SFW}' => $this->test ? $this->test_ip : md5( $result['ip'] . $this->api_key ),
|
223 |
+
'{COOKIE_ANTICRAWLER}' => md5( $this->api_key . $result['ip'] ),
|
224 |
+
|
225 |
+
// Test
|
226 |
+
'{TEST_TITLE}' => '',
|
227 |
+
'{REAL_IP__HEADER}' => '',
|
228 |
+
'{TEST_IP__HEADER}' => '',
|
229 |
+
'{TEST_IP}' => '',
|
230 |
+
'{REAL_IP}' => '',
|
231 |
+
);
|
232 |
|
233 |
+
// Test
|
234 |
if($this->test){
|
235 |
+
$replaces['{TEST_TITLE}'] = __( 'This is the testing page for SpamFireWall', 'cleantalk-spam-protect' );
|
236 |
+
$replaces['{REAL_IP__HEADER}'] = 'Real IP:';
|
237 |
+
$replaces['{TEST_IP__HEADER}'] = 'Test IP:';
|
238 |
+
$replaces['{TEST_IP}'] = $this->test_ip;
|
239 |
+
$replaces['{REAL_IP}'] = $this->real_ip;
|
|
|
|
|
|
|
|
|
240 |
}
|
241 |
|
242 |
+
// Debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
if($this->debug){
|
244 |
$debug = '<h1>Headers</h1>'
|
245 |
. var_export(apache_request_headers(), true)
|
251 |
. var_export($this->ip_array, true)
|
252 |
. '<h1>ADDITIONAL</h1>'
|
253 |
. var_export($this->debug_data, true);
|
254 |
+
}
|
255 |
+
$replaces['{DEBUG}'] = isset( $debug ) ? $debug : '';
|
256 |
|
257 |
+
foreach( $replaces as $place_holder => $replace ){
|
258 |
+
$sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
|
259 |
+
}
|
260 |
|
261 |
wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
|
262 |
|
288 |
foreach( $db->result as $key => $value ){
|
289 |
|
290 |
$value['status'] = $value['status'] === 'DENY_ANTICRAWLER' ? 'BOT_PROTECTION' : $value['status'];
|
291 |
+
$value['status'] = $value['status'] === 'DENY_ANTIFLOOD' ? 'FLOOD_PROTECTION' : $value['status'];
|
292 |
|
293 |
$data[] = array(
|
294 |
trim( $value['ip'] ),
|
lib/Cleantalk/ApbctWP/Firewall/{die_page__antibot.html → die_page__AntiCrawler.html}
RENAMED
@@ -118,7 +118,7 @@
|
|
118 |
document.getElementById('js_info').style.display = 'none';
|
119 |
document.getElementById('js_passed').style.display = 'block';
|
120 |
document.getElementById('curr_date').innerHTML = ct_date.toGMTString();
|
121 |
-
set_spamFireWallCookie('apbct_antibot','{
|
122 |
|
123 |
if(location.search.search('debug=1') === -1) {
|
124 |
setTimeout(function(){
|
118 |
document.getElementById('js_info').style.display = 'none';
|
119 |
document.getElementById('js_passed').style.display = 'block';
|
120 |
document.getElementById('curr_date').innerHTML = ct_date.toGMTString();
|
121 |
+
set_spamFireWallCookie('apbct_antibot','{COOKIE_ANTICRAWLER}');
|
122 |
|
123 |
if(location.search.search('debug=1') === -1) {
|
124 |
setTimeout(function(){
|
lib/Cleantalk/ApbctWP/Firewall/{die_page__anticrawler.html → die_page__AntiFlood.html}
RENAMED
File without changes
|
lib/Cleantalk/ApbctWP/Firewall/{die_page__sfw.html → die_page__SFW.html}
RENAMED
@@ -126,6 +126,7 @@
|
|
126 |
document.getElementById('js_passed').style.display = 'block';
|
127 |
document.getElementById('curr_date').innerHTML = ct_date.toGMTString();
|
128 |
set_spamFireWallCookie('{COOKIE_PREFIX}ct_sfw_pass_key','{SFW_COOKIE}');
|
|
|
129 |
set_spamFireWallCookie('{COOKIE_PREFIX}ct_sfw_passed','1');
|
130 |
|
131 |
if(location.search.search('debug=1') === -1) {
|
126 |
document.getElementById('js_passed').style.display = 'block';
|
127 |
document.getElementById('curr_date').innerHTML = ct_date.toGMTString();
|
128 |
set_spamFireWallCookie('{COOKIE_PREFIX}ct_sfw_pass_key','{SFW_COOKIE}');
|
129 |
+
set_spamFireWallCookie('{COOKIE_PREFIX}apbct_antibot','{COOKIE_ANTICRAWLER}');
|
130 |
set_spamFireWallCookie('{COOKIE_PREFIX}ct_sfw_passed','1');
|
131 |
|
132 |
if(location.search.search('debug=1') === -1) {
|
lib/Cleantalk/ApbctWP/State.php
CHANGED
@@ -56,9 +56,9 @@ class State
|
|
56 |
public $def_settings = array(
|
57 |
|
58 |
'spam_firewall' => 1,
|
|
|
|
|
59 |
'sfw__anti_crawler' => 0,
|
60 |
-
'sfw__anti_crawler__view_limit' => 10,
|
61 |
-
'sfw__bot_protection' => 0,
|
62 |
'apikey' => '',
|
63 |
'autoPubRevelantMess' => 0,
|
64 |
|
56 |
public $def_settings = array(
|
57 |
|
58 |
'spam_firewall' => 1,
|
59 |
+
'sfw__anti_flood' => 0,
|
60 |
+
'sfw__anti_flood__view_limit' => 10,
|
61 |
'sfw__anti_crawler' => 0,
|
|
|
|
|
62 |
'apikey' => '',
|
63 |
'autoPubRevelantMess' => 0,
|
64 |
|
lib/Cleantalk/Common/Firewall.php
CHANGED
@@ -36,7 +36,7 @@ class Firewall
|
|
36 |
'PASS_SFW',
|
37 |
'DENY_SFW',
|
38 |
'PASS_SFW_BY_COOKIE',
|
39 |
-
'
|
40 |
'DENY_ANTICRAWLER',
|
41 |
'PASS_SFW_BY_WHITELIST',
|
42 |
// Highest
|
36 |
'PASS_SFW',
|
37 |
'DENY_SFW',
|
38 |
'PASS_SFW_BY_COOKIE',
|
39 |
+
'DENY_ANTIFLOOD',
|
40 |
'DENY_ANTICRAWLER',
|
41 |
'PASS_SFW_BY_WHITELIST',
|
42 |
// Highest
|
lib/Cleantalk/Common/Firewall/FirewallModule.php
CHANGED
@@ -70,4 +70,17 @@ class FirewallModule extends FirewallModule_abstract {
|
|
70 |
public function setDbTableLogs( $db__table__logs ) {
|
71 |
$this->db__table__logs = $db__table__logs;
|
72 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
}
|
70 |
public function setDbTableLogs( $db__table__logs ) {
|
71 |
$this->db__table__logs = $db__table__logs;
|
72 |
}
|
73 |
+
|
74 |
+
public function _die( $result ){
|
75 |
+
|
76 |
+
// Headers
|
77 |
+
if(headers_sent() === false){
|
78 |
+
header('Expires: '.date(DATE_RFC822, mktime(0, 0, 0, 1, 1, 1971)));
|
79 |
+
header('Cache-Control: no-store, no-cache, must-revalidate');
|
80 |
+
header('Cache-Control: post-check=0, pre-check=0', FALSE);
|
81 |
+
header('Pragma: no-cache');
|
82 |
+
header("HTTP/1.0 403 Forbidden");
|
83 |
+
}
|
84 |
+
|
85 |
+
}
|
86 |
}
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: safronik
|
3 |
Tags: spam, antispam, woocommerce, comments, firewall
|
4 |
Requires at least: 3.0
|
5 |
-
Tested up to: 5.
|
6 |
Requires PHP: 5.4
|
7 |
-
Stable tag: 5.142
|
8 |
License: GPLv2
|
9 |
|
10 |
Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
|
@@ -574,6 +574,9 @@ If your website has forms that send data to external sources, you can enable opt
|
|
574 |
|
575 |
== Changelog ==
|
576 |
|
|
|
|
|
|
|
577 |
= 5.142 Jul 27 2020 =
|
578 |
* New: Bot Protection module for Firewall.
|
579 |
* New: Anti-Crawler module for Firewall.
|
2 |
Contributors: safronik
|
3 |
Tags: spam, antispam, woocommerce, comments, firewall
|
4 |
Requires at least: 3.0
|
5 |
+
Tested up to: 5.5
|
6 |
Requires PHP: 5.4
|
7 |
+
Stable tag: 5.142.1
|
8 |
License: GPLv2
|
9 |
|
10 |
Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
|
574 |
|
575 |
== Changelog ==
|
576 |
|
577 |
+
= 5.142.1 Jul 28 2020 =
|
578 |
+
* Fix: Blocking good bots.
|
579 |
+
|
580 |
= 5.142 Jul 27 2020 =
|
581 |
* New: Bot Protection module for Firewall.
|
582 |
* New: Anti-Crawler module for Firewall.
|