#8 Target filter implemented
This commit is contained in:
parent
0cf4548d45
commit
152a800a4a
@ -15,6 +15,9 @@ This plugin adds customizable blacklist to Statify to allow blocking of referer
|
|||||||
#### Referer Blacklist ####
|
#### Referer Blacklist ####
|
||||||
Add a list of domains (for simplicity only second-level, e.g. _example.com_ which blocks _everything.example.com_).
|
Add a list of domains (for simplicity only second-level, e.g. _example.com_ which blocks _everything.example.com_).
|
||||||
|
|
||||||
|
#### Target Blacklist ####
|
||||||
|
Add a list of target pages (e.g. _/test/page/_, _/?page_id=123_) that will be excluded from tracking.
|
||||||
|
|
||||||
#### IP Blacklist ####
|
#### IP Blacklist ####
|
||||||
Add a list of IP addresses or subnets (e.g. _192.0.2.123_, _198.51.100.0/24_, _2001:db8:a0b:12f0::/64_).
|
Add a list of IP addresses or subnets (e.g. _192.0.2.123_, _198.51.100.0/24_, _2001:db8:a0b:12f0::/64_).
|
||||||
|
|
||||||
@ -74,6 +77,7 @@ Because of this, an IP blacklist can only be applied while processing the reques
|
|||||||
|
|
||||||
### 1.4.0 / work in progress ###
|
### 1.4.0 / work in progress ###
|
||||||
* IP blacklist implemented (#7)
|
* IP blacklist implemented (#7)
|
||||||
|
* Target page blacklist implemented (#8)
|
||||||
|
|
||||||
### 1.3.1 / 09.12.2016 ###
|
### 1.3.1 / 09.12.2016 ###
|
||||||
* Continue filtering if no filter applies (#6)
|
* Continue filtering if no filter applies (#6)
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 66 KiB |
@ -85,7 +85,7 @@ class StatifyBlacklist {
|
|||||||
|
|
||||||
/* CronJob to clean up database */
|
/* CronJob to clean up database */
|
||||||
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
||||||
if ( self::$_options['cron_referer'] == 1 ) {
|
if ( self::$_options['cron_referer'] == 1 || self::$_options['cron_target'] == 1 ) {
|
||||||
add_action( 'statify_cleanup', array( 'StatifyBlacklist_Admin', 'cleanup_database' ) );
|
add_action( 'statify_cleanup', array( 'StatifyBlacklist_Admin', 'cleanup_database' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,6 +119,10 @@ class StatifyBlacklist {
|
|||||||
'cron_referer' => 0,
|
'cron_referer' => 0,
|
||||||
'referer' => array(),
|
'referer' => array(),
|
||||||
'referer_regexp' => 0,
|
'referer_regexp' => 0,
|
||||||
|
'active_target' => 0,
|
||||||
|
'cron_target' => 0,
|
||||||
|
'target' => array(),
|
||||||
|
'target_regexp' => 0,
|
||||||
'active_ip' => 0,
|
'active_ip' => 0,
|
||||||
'ip' => array(),
|
'ip' => array(),
|
||||||
'version' => self::VERSION_MAIN
|
'version' => self::VERSION_MAIN
|
||||||
@ -130,8 +134,8 @@ class StatifyBlacklist {
|
|||||||
*
|
*
|
||||||
* @return TRUE if referer matches blacklist.
|
* @return TRUE if referer matches blacklist.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @changed 1.4.0
|
* @since 1.4.0 Target and IP blacklist
|
||||||
*/
|
*/
|
||||||
public static function apply_blacklist_filter() {
|
public static function apply_blacklist_filter() {
|
||||||
/* Referer blacklist */
|
/* Referer blacklist */
|
||||||
@ -163,6 +167,33 @@ class StatifyBlacklist {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Target blacklist (since 1.4.0) */
|
||||||
|
if ( isset( self::$_options['active_target'] ) && self::$_options['active_target'] != 0 ) {
|
||||||
|
/* Regular Expression filtering since 1.3.0 */
|
||||||
|
if ( isset( self::$_options['target_regexp'] ) && self::$_options['target_regexp'] > 0 ) {
|
||||||
|
/* Get full referer string */
|
||||||
|
$target = ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '/' );
|
||||||
|
/* Merge given regular expressions into one */
|
||||||
|
$regexp = '/' . implode( "|", array_keys( self::$_options['target'] ) ) . '/';
|
||||||
|
if ( self::$_options['target_regexp'] == 2 ) {
|
||||||
|
$regexp .= 'i';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check blacklist (return NULL to continue filtering) */
|
||||||
|
|
||||||
|
return ( preg_match( $regexp, $target ) === 1 ) ? true : null;
|
||||||
|
} else {
|
||||||
|
/* Extract target page */
|
||||||
|
$target = ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '/' );
|
||||||
|
/* Get blacklist */
|
||||||
|
$blacklist = self::$_options['target'];
|
||||||
|
/* Check blacklist */
|
||||||
|
if ( isset( $blacklist[ $target ] ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* IP blacklist (since 1.4.0) */
|
/* IP blacklist (since 1.4.0) */
|
||||||
if ( isset ( self::$_options['active_ip'] ) && self::$_options['active_ip'] != 0 ) {
|
if ( isset ( self::$_options['active_ip'] ) && self::$_options['active_ip'] != 0 ) {
|
||||||
if ( ( $ip = self::getIP() ) !== false ) {
|
if ( ( $ip = self::getIP() ) !== false ) {
|
||||||
|
@ -131,26 +131,57 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
|||||||
die( __( 'Are you sure you want to do this?' ) );
|
die( __( 'Are you sure you want to do this?' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
global $wpdb;
|
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
||||||
|
$cleanRef = ( self::$_options['cron_referer'] == 1 );
|
||||||
if ( isset( self::$_options['referer_regexp'] ) && self::$_options['referer_regexp'] > 0 ) {
|
$cleanTrg = ( self::$_options['cron_target'] == 1 );
|
||||||
/* Merge given regular expressions into one */
|
|
||||||
$refererRegexp = implode( "|", array_keys( self::$_options['referer'] ) );
|
|
||||||
} else {
|
} else {
|
||||||
/* Sanitize URLs */
|
$cleanRef = true;
|
||||||
$referer = self::sanitizeURLs( self::$_options['referer'] );
|
$cleanTrg = true;
|
||||||
|
|
||||||
/* Build filter regexp */
|
|
||||||
$refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $refererRegexp ) ) {
|
|
||||||
|
if ( $cleanRef ) {
|
||||||
|
if ( isset( self::$_options['referer_regexp'] ) && self::$_options['referer_regexp'] > 0 ) {
|
||||||
|
/* Merge given regular expressions into one */
|
||||||
|
$refererRegexp = implode( "|", array_keys( self::$_options['referer'] ) );
|
||||||
|
} else {
|
||||||
|
/* Sanitize URLs */
|
||||||
|
$referer = self::sanitizeURLs( self::$_options['referer'] );
|
||||||
|
|
||||||
|
/* Build filter regexp */
|
||||||
|
$refererRegexp = str_replace( '.', '\.', implode( '|', array_flip( $referer ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $cleanTrg ) {
|
||||||
|
if ( isset( self::$_options['target_regexp'] ) && self::$_options['target_regexp'] > 0 ) {
|
||||||
|
/* Merge given regular expressions into one */
|
||||||
|
$targetRegexp = implode( "|", array_keys( self::$_options['target'] ) );
|
||||||
|
} else {
|
||||||
|
/* Build filter regexp */
|
||||||
|
$targetRegexp = str_replace( '.', '\.', implode( '|', array_flip( self::$_options['target'] ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( ! empty( $refererRegexp ) || ! empty( $targetRegexp ) ) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
/* Execute filter on database */
|
/* Execute filter on database */
|
||||||
$wpdb->query(
|
if ( ! empty( $refererRegexp ) ) {
|
||||||
$wpdb->prepare( "DELETE FROM `$wpdb->statify` WHERE "
|
$wpdb->query(
|
||||||
. ( ( self::$_options['referer_regexp'] == 1 ) ? " BINARY " : "" )
|
$wpdb->prepare( "DELETE FROM `$wpdb->statify` WHERE "
|
||||||
. "referrer REGEXP %s", $refererRegexp )
|
. ( ( self::$_options['referer_regexp'] == 1 ) ? " BINARY " : "" )
|
||||||
);
|
. "referrer REGEXP %s", $refererRegexp )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( ! empty( $targetRegexp ) ) {
|
||||||
|
$wpdb->query(
|
||||||
|
$wpdb->prepare( "DELETE FROM `$wpdb->statify` WHERE "
|
||||||
|
. ( ( self::$_options['target_regexp'] == 1 ) ? " BINARY " : "" )
|
||||||
|
. "target REGEXP %s", $targetRegexp )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/* Optimize DB */
|
/* Optimize DB */
|
||||||
$wpdb->query( "OPTIMIZE TABLE `$wpdb->statify`" );
|
$wpdb->query( "OPTIMIZE TABLE `$wpdb->statify`" );
|
||||||
@ -195,10 +226,10 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
|||||||
*/
|
*/
|
||||||
private static function sanitizeIPs( $ips ) {
|
private static function sanitizeIPs( $ips ) {
|
||||||
return array_filter( $ips, function ( $ip ) {
|
return array_filter( $ips, function ( $ip ) {
|
||||||
return preg_match('/^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])'.
|
return preg_match( '/^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])' .
|
||||||
'(\/([0-9]|[1-2][0-9]|3[0-2]))?$/', $ip) ||
|
'(\/([0-9]|[1-2][0-9]|3[0-2]))?$/', $ip ) ||
|
||||||
preg_match('/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'.
|
preg_match( '/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))' .
|
||||||
'(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/', $ip);
|
'(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/', $ip );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase {
|
|||||||
$optionsUpdated = get_option( 'statify-blacklist' );
|
$optionsUpdated = get_option( 'statify-blacklist' );
|
||||||
|
|
||||||
/* Verify size against default options (no junk left) */
|
/* Verify size against default options (no junk left) */
|
||||||
$this->assertEquals( 7, sizeof( $optionsUpdated ) );
|
$this->assertEquals( 11, sizeof( $optionsUpdated ) );
|
||||||
|
|
||||||
/* Verify that original attributes are unchanged */
|
/* Verify that original attributes are unchanged */
|
||||||
$this->assertEquals( $options13['active_referer'], $optionsUpdated['active_referer'] );
|
$this->assertEquals( $options13['active_referer'], $optionsUpdated['active_referer'] );
|
||||||
@ -294,6 +294,114 @@ class StatifyBlacklistTest extends PHPUnit_Framework_TestCase {
|
|||||||
$_SERVER['HTTP_X_REAL_IP'] = '2001:db8:a0b:12f0:0::1';
|
$_SERVER['HTTP_X_REAL_IP'] = '2001:db8:a0b:12f0:0::1';
|
||||||
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test simple target filter.
|
||||||
|
*/
|
||||||
|
public function testTargetFilter() {
|
||||||
|
/* Prepare Options: 2 blacklisted domains, disabled */
|
||||||
|
StatifyBlacklist::$_options = array(
|
||||||
|
'active_referer' => 0,
|
||||||
|
'cron_referer' => 0,
|
||||||
|
'referer' => array(
|
||||||
|
'example.com' => 0,
|
||||||
|
'example.net' => 1
|
||||||
|
),
|
||||||
|
'referer_regexp' => 0,
|
||||||
|
'active_target' => 0,
|
||||||
|
'cron_target' => 0,
|
||||||
|
'target' => array(
|
||||||
|
'/excluded/page/' => 0,
|
||||||
|
'/?page_id=3' => 1
|
||||||
|
),
|
||||||
|
'target_regexp' => 0,
|
||||||
|
'active_ip' => 0,
|
||||||
|
'ip' => array(),
|
||||||
|
'version' => StatifyBlacklist::VERSION_MAIN
|
||||||
|
);
|
||||||
|
|
||||||
|
/* No multisite */
|
||||||
|
StatifyBlacklist::$multisite = false;
|
||||||
|
|
||||||
|
/* Empty target */
|
||||||
|
unset( $_SERVER['REQUEST_URI'] );
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
/* Non-blacklisted targets */
|
||||||
|
$_SERVER['REQUEST_URI'] = '';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/?page_id=1';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
/* Blacklisted referer */
|
||||||
|
$_SERVER['REQUEST_URI'] = '/excluded/page/';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/?page_id=3';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
|
||||||
|
/* Activate filter and run tests again */
|
||||||
|
StatifyBlacklist::$_options['active_target'] = 1;
|
||||||
|
|
||||||
|
unset( $_SERVER['REQUEST_URI'] );
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_URI'] = '';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/?page_id=1';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
|
||||||
|
$_SERVER['REQUEST_URI'] = '/excluded/page/';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/?page_id=3';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
$_SERVER['REQUEST_URI'] = '/?page_id=3';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test target filter using regular expressions.
|
||||||
|
*/
|
||||||
|
public function testTargetRegexFilter() {
|
||||||
|
/* Prepare Options: 2 regular expressions */
|
||||||
|
StatifyBlacklist::$_options = array(
|
||||||
|
'active_referer' => 1,
|
||||||
|
'cron_referer' => 0,
|
||||||
|
'referer' => array(
|
||||||
|
'example.[a-z]+' => 0,
|
||||||
|
'test' => 1
|
||||||
|
),
|
||||||
|
'referer_regexp' => 1,
|
||||||
|
'version' => 1.3
|
||||||
|
);
|
||||||
|
|
||||||
|
/* No multisite */
|
||||||
|
StatifyBlacklist::$multisite = false;
|
||||||
|
|
||||||
|
/* No referer */
|
||||||
|
unset( $_SERVER['HTTP_REFERER'] );
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
/* Non-blacklisted referer */
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'http://not.evil';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
/* Blacklisted referer */
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'http://example.com';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
/* Blacklisted referer with path */
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'http://foobar.net/test/me';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
/* Matching both */
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'http://example.net/test/me';
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
/* Mathinc with wrong case */
|
||||||
|
$_SERVER['HTTP_REFERER'] = 'http://eXaMpLe.NeT/tEsT/mE';
|
||||||
|
$this->assertNull( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
|
||||||
|
/* Set RegExp filter to case insensitive */
|
||||||
|
StatifyBlacklist::$_options['referer_regexp'] = 2;
|
||||||
|
$this->assertTrue( StatifyBlacklist::apply_blacklist_filter() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -346,3 +454,7 @@ function update_option( $option, $value, $autoload = null ) {
|
|||||||
global $mock_options;
|
global $mock_options;
|
||||||
$mock_options[ $option ] = $value;
|
$mock_options[ $option ] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wp_unslash ( $value ) {
|
||||||
|
return is_string( $value ) ? stripslashes( $value ) : $value;
|
||||||
|
}
|
@ -24,6 +24,13 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
$referer = explode( "\r\n", $_POST['statifyblacklist']['referer'] );
|
$referer = explode( "\r\n", $_POST['statifyblacklist']['referer'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Extract target array */
|
||||||
|
if ( empty( trim( $_POST['statifyblacklist']['target'] ) ) ) {
|
||||||
|
$target = array();
|
||||||
|
} else {
|
||||||
|
$target = explode( "\r\n", str_replace( '\\\\', '\\', $_POST['statifyblacklist']['target'] ) );
|
||||||
|
}
|
||||||
|
|
||||||
/* Extract IP array */
|
/* Extract IP array */
|
||||||
if ( empty( trim( $_POST['statifyblacklist']['ip'] ) ) ) {
|
if ( empty( trim( $_POST['statifyblacklist']['ip'] ) ) ) {
|
||||||
$ip = array();
|
$ip = array();
|
||||||
@ -38,9 +45,13 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
'cron_referer' => (int) @$_POST['statifyblacklist']['cron_referer'],
|
'cron_referer' => (int) @$_POST['statifyblacklist']['cron_referer'],
|
||||||
'referer' => array_flip( $referer ),
|
'referer' => array_flip( $referer ),
|
||||||
'referer_regexp' => (int) @$_POST['statifyblacklist']['referer_regexp'],
|
'referer_regexp' => (int) @$_POST['statifyblacklist']['referer_regexp'],
|
||||||
'active_ip' => (int) @$_POST['statifyblacklist']['active_ip'],
|
'active_target' => (int) @$_POST['statifyblacklist']['active_target'],
|
||||||
'ip' => $ip,
|
'cron_target' => (int) @$_POST['statifyblacklist']['cron_target'],
|
||||||
'version' => StatifyBlacklist::VERSION_MAIN
|
'target' => array_flip( $target ),
|
||||||
|
'target_regexp' => (int) @$_POST['statifyblacklist']['target_regexp'],
|
||||||
|
'active_ip' => (int) @$_POST['statifyblacklist']['active_ip'],
|
||||||
|
'ip' => $ip,
|
||||||
|
'version' => StatifyBlacklist::VERSION_MAIN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -52,81 +63,87 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
$statifyBlacklistPostWarning = sprintf( __( 'Some IPs are invalid : %s', 'statify-blacklist' ), implode( ', ', $statifyBlacklistUpdateResult['ip'] ) );
|
$statifyBlacklistPostWarning = sprintf( __( 'Some IPs are invalid : %s', 'statify-blacklist' ), implode( ', ', $statifyBlacklistUpdateResult['ip'] ) );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$statifyBlacklistPostSuccess = __('Settings updated successfully.', 'statify-blacklist');
|
$statifyBlacklistPostSuccess = __( 'Settings updated successfully.', 'statify-blacklist' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h1><?php _e( 'Statify Blacklist', 'statify-blacklist' ) ?></h1>
|
<h1><?php _e( 'Statify Blacklist', 'statify-blacklist' ) ?></h1>
|
||||||
<?php
|
<?php
|
||||||
if ( is_plugin_inactive( 'statify/statify.php' ) ) {
|
if ( is_plugin_inactive( 'statify/statify.php' ) ) {
|
||||||
print '<div class="notice notice-warning"><p>';
|
print '<div class="notice notice-warning"><p>';
|
||||||
esc_html( 'Statify plugin is not active.');
|
esc_html( 'Statify plugin is not active.' );
|
||||||
print '</p></div>';
|
print '</p></div>';
|
||||||
}
|
}
|
||||||
if ( isset( $statifyBlacklistPostWarning ) ) {
|
if ( isset( $statifyBlacklistPostWarning ) ) {
|
||||||
print '<div class="notice notice-warning"><p>' .
|
print '<div class="notice notice-warning"><p>' .
|
||||||
esc_html( $statifyBlacklistPostWarning );
|
esc_html( $statifyBlacklistPostWarning );
|
||||||
print '<br/>';
|
print '<br/>';
|
||||||
esc_html_e('Settings have not been saved yet.', 'statify-blacklist');
|
esc_html_e( 'Settings have not been saved yet.', 'statify-blacklist' );
|
||||||
print '</p></div>';
|
print '</p></div>';
|
||||||
}
|
}
|
||||||
if ( isset( $statifyBlacklistPostSuccess ) ) {
|
if ( isset( $statifyBlacklistPostSuccess ) ) {
|
||||||
print '<div class="notice notice-success"><p>'.
|
print '<div class="notice notice-success"><p>' .
|
||||||
esc_html( $statifyBlacklistPostSuccess ).
|
esc_html( $statifyBlacklistPostSuccess ) .
|
||||||
'</p></div>';
|
'</p></div>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<form action="" method="post" id="statify-blacklist-settings">
|
<form action="" method="post" id="statify-blacklist-settings">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<h2><?php esc_html_e( 'Referer blacklist', 'statify-blacklist' ); ?></h2>
|
<h2><?php esc_html_e( 'Referer blacklist', 'statify-blacklist' ); ?></h2>
|
||||||
<ul style="list-style: none;">
|
<ul style="list-style: none;">
|
||||||
<li>
|
<li>
|
||||||
<label for="statify-blacklist_active_referer">
|
<label for="statify-blacklist_active_referer">
|
||||||
<input type="checkbox" name="statifyblacklist[active_referer]" id="statifyblacklist_active_referer"
|
<input type="checkbox" name="statifyblacklist[active_referer]"
|
||||||
|
id="statifyblacklist_active_referer"
|
||||||
value="1" <?php checked( StatifyBlacklist::$_options['active_referer'], 1 ); ?> />
|
value="1" <?php checked( StatifyBlacklist::$_options['active_referer'], 1 ); ?> />
|
||||||
<?php esc_html_e( 'Activate live fiter', 'statify-blacklist' ); ?>
|
<?php esc_html_e( 'Activate live fiter', 'statify-blacklist' ); ?>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="statify-blacklist_cron_referer">
|
<label for="statify-blacklist_cron_referer">
|
||||||
<input type="checkbox" name="statifyblacklist[cron_referer]" id="statifyblacklist_cron_referer"
|
<input type="checkbox" name="statifyblacklist[cron_referer]" id="statifyblacklist_cron_referer"
|
||||||
value="1" <?php checked( StatifyBlacklist::$_options['cron_referer'], 1 ); ?> />
|
value="1" <?php checked( StatifyBlacklist::$_options['cron_referer'], 1 ); ?> />
|
||||||
<?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?>
|
<?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?>
|
||||||
<small>(<?php esc_html_e( 'Clean database periodically in background', 'statify-blacklist' ); ?>)</small>
|
<small>(<?php esc_html_e( 'Clean database periodically in background', 'statify-blacklist' ); ?>
|
||||||
|
)
|
||||||
|
</small>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="statify-blacklist_referer_regexp">
|
<label for="statify-blacklist_referer_regexp">
|
||||||
<?php esc_html_e( 'Use regular expressions', 'statify-blacklist' ); ?>:
|
<?php esc_html_e( 'Use regular expressions', 'statify-blacklist' ); ?>:
|
||||||
<br />
|
<br/>
|
||||||
<select name="statifyblacklist[referer_regexp]" id="statifyblacklist_referer_regexp">
|
<select name="statifyblacklist[referer_regexp]" id="statifyblacklist_referer_regexp">
|
||||||
<option value="0" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 0 ); ?>>
|
<option value="0" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 0 ); ?>>
|
||||||
<?php esc_html_e( 'Disabled', 'statify-blacklist' ); ?>
|
<?php esc_html_e( 'Disabled', 'statify-blacklist' ); ?>
|
||||||
</option>
|
</option>
|
||||||
<option value="1" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 1 ); ?>>
|
<option value="1" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 1 ); ?>>
|
||||||
<?php esc_html_e( 'Case-sensitive', 'statify-blacklist' ); ?>
|
<?php esc_html_e( 'Case-sensitive', 'statify-blacklist' ); ?>
|
||||||
</option>
|
</option>
|
||||||
<option value="2" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 2 ); ?>>
|
<option value="2" <?php selected( StatifyBlacklist::$_options['referer_regexp'], 2 ); ?>>
|
||||||
<?php esc_html_e( 'Case-insensitive', 'statify-blacklist' ); ?>
|
<?php esc_html_e( 'Case-insensitive', 'statify-blacklist' ); ?>
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<small>(<?php esc_html_e( 'Performance slower than standard domain filter. Recommended for cron or manual execition only.', 'statify-blacklist' ); ?>)</small>
|
<small>
|
||||||
|
(<?php esc_html_e( 'Performance slower than standard filter. Recommended for cron or manual execition only.', 'statify-blacklist' ); ?>
|
||||||
|
)
|
||||||
|
</small>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="statify-blacklist_referer">
|
<label for="statify-blacklist_referer">
|
||||||
<?php esc_html_e( 'Referer blacklist:', 'statify-blacklist' ); ?><br/>
|
<?php esc_html_e( 'Referer blacklist:', 'statify-blacklist' ); ?><br/>
|
||||||
<textarea cols="40" rows="5" name="statifyblacklist[referer]" id="statify-blacklist_referer"><?php
|
<textarea cols="40" rows="5" name="statifyblacklist[referer]" id="statify-blacklist_referer"><?php
|
||||||
if ( isset( $statifyBlacklistUpdateResult['referer'] ) ) {
|
if ( isset( $statifyBlacklistUpdateResult['referer'] ) ) {
|
||||||
print esc_html( implode( "\r\n", array_keys( $statifyBlacklistUpdateResult['referer'] ) ) );
|
print esc_html( implode( "\r\n", array_keys( $statifyBlacklistUpdateResult['referer'] ) ) );
|
||||||
} else {
|
} else {
|
||||||
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['referer'] ) ) );
|
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['referer'] ) ) );
|
||||||
}
|
}
|
||||||
?></textarea>
|
?></textarea>
|
||||||
<br />
|
<br/>
|
||||||
<small>
|
<small>
|
||||||
(<?php esc_html_e( 'Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist' ); ?>
|
(<?php esc_html_e( 'Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist' ); ?>
|
||||||
)
|
)
|
||||||
@ -136,6 +153,69 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
</ul>
|
</ul>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<h2><?php esc_html_e( 'Target blacklist', 'statify-blacklist' ); ?></h2>
|
||||||
|
<ul style="list-style: none;">
|
||||||
|
<li>
|
||||||
|
<label for="statify-blacklist_active_target">
|
||||||
|
<input type="checkbox" name="statifyblacklist[active_target]"
|
||||||
|
id="statifyblacklist_active_target"
|
||||||
|
value="1" <?php checked( StatifyBlacklist::$_options['active_target'], 1 ); ?> />
|
||||||
|
<?php esc_html_e( 'Activate live fiter', 'statify-blacklist' ); ?>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="statify-blacklist_cron_target">
|
||||||
|
<input type="checkbox" name="statifyblacklist[cron_target]" id="statifyblacklist_cron_target"
|
||||||
|
value="1" <?php checked( StatifyBlacklist::$_options['cron_target'], 1 ); ?> />
|
||||||
|
<?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?>
|
||||||
|
<small>(<?php esc_html_e( 'Clean database periodically in background', 'statify-blacklist' ); ?>
|
||||||
|
)
|
||||||
|
</small>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="statify-blacklist_target_regexp">
|
||||||
|
<?php esc_html_e( 'Use regular expressions', 'statify-blacklist' ); ?>:
|
||||||
|
<br/>
|
||||||
|
<select name="statifyblacklist[target_regexp]" id="statifyblacklist_target_regexp">
|
||||||
|
<option value="0" <?php selected( StatifyBlacklist::$_options['target_regexp'], 0 ); ?>>
|
||||||
|
<?php esc_html_e( 'Disabled', 'statify-blacklist' ); ?>
|
||||||
|
</option>
|
||||||
|
<option value="1" <?php selected( StatifyBlacklist::$_options['target_regexp'], 1 ); ?>>
|
||||||
|
<?php esc_html_e( 'Case-sensitive', 'statify-blacklist' ); ?>
|
||||||
|
</option>
|
||||||
|
<option value="2" <?php selected( StatifyBlacklist::$_options['target_regexp'], 2 ); ?>>
|
||||||
|
<?php esc_html_e( 'Case-insensitive', 'statify-blacklist' ); ?>
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<small>
|
||||||
|
(<?php esc_html_e( 'Performance slower than standard filter. Recommended for cron or manual execition only.', 'statify-blacklist' ); ?>
|
||||||
|
)
|
||||||
|
</small>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="statify-blacklist_target">
|
||||||
|
<?php esc_html_e( 'Target blacklist:', 'statify-blacklist' ); ?><br/>
|
||||||
|
<textarea cols="40" rows="5" name="statifyblacklist[target]" id="statify-blacklist_target"><?php
|
||||||
|
if ( isset( $statifyBlacklistUpdateResult['target'] ) ) {
|
||||||
|
print esc_html( implode( "\r\n", array_keys( $statifyBlacklistUpdateResult['target'] ) ) );
|
||||||
|
} else {
|
||||||
|
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['target'] ) ) );
|
||||||
|
}
|
||||||
|
?></textarea>
|
||||||
|
<br/>
|
||||||
|
<small>
|
||||||
|
(<?php esc_html_e( 'Add one target URL each line, e.g.', 'statify-blacklist' );
|
||||||
|
print ' /, /test/page/, /?page_id=123' ?>
|
||||||
|
)
|
||||||
|
</small>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<h2><?php esc_html_e( 'IP blacklist', 'statify-blacklist' ); ?></h2>
|
<h2><?php esc_html_e( 'IP blacklist', 'statify-blacklist' ); ?></h2>
|
||||||
<ul style="list-style: none;">
|
<ul style="list-style: none;">
|
||||||
@ -147,7 +227,10 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<small>(<?php esc_html_e( 'Cron execution is not possible for IP filter, because IP addresses are not stored.', 'statify-blacklist' ); ?>)</small>
|
<small>
|
||||||
|
(<?php esc_html_e( 'Cron execution is not possible for IP filter, because IP addresses are not stored.', 'statify-blacklist' ); ?>
|
||||||
|
)
|
||||||
|
</small>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="statify-blacklist_ip">
|
<label for="statify-blacklist_ip">
|
||||||
@ -172,14 +255,14 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
|
|
||||||
<?php wp_nonce_field( 'statify-blacklist-settings' ); ?>
|
<?php wp_nonce_field( 'statify-blacklist-settings' ); ?>
|
||||||
|
|
||||||
<p class="submit">
|
<p class="submit">
|
||||||
<input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes' ) ?>">
|
<input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes' ) ?>">
|
||||||
<hr />
|
<hr/>
|
||||||
<input class="button-secondary" type="submit" name="cleanUp"
|
<input class="button-secondary" type="submit" name="cleanUp"
|
||||||
value="<?php esc_html_e( 'CleanUp Database', 'statify-blacklist' ) ?>"
|
value="<?php esc_html_e( 'CleanUp Database', 'statify-blacklist' ) ?>"
|
||||||
onclick="return confirm('Do you really want to apply filters to database? This cannot be undone.');">
|
onclick="return confirm('Do you really want to apply filters to database? This cannot be undone.');">
|
||||||
<br />
|
<br/>
|
||||||
<small><?php esc_html_e( 'Applies referer filter (even if disabled) to data stored in database. This cannot be undone!', 'statify-blacklist' ); ?></small>
|
<small><?php esc_html_e( 'Applies referer and target filter (even if disabled) to data stored in database.', 'statify-blacklist' ); ?> <b><?php esc_html_e( 'This cannot be undone!', 'statify-blacklist' ); ?></b></small>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user