IP Geo Block - Version 3.0.0

Version Description

  • New feature: Add the function of blocking on front-end.
  • New filter hook: Add ip-geo-block-public to extend validation on front-end.
  • Improvement: Avoid conflict with "Open external links in a new window" plugin and some other reason to prevent duplicated window open. For more detail, see this discussion at support forum.
  • Improvement: Better compatibility with some plugins, themes and widgets.
  • Improvement: Deferred execution of SQL command to improve the response.
  • Improvement: Make the response compatible with WP original when it is requested by GET method.
  • See some details at release 3.0.0.
Download this release

Release Info

Developer tokkonopapa
Plugin Icon 128x128 IP Geo Block
Version 3.0.0
Comparing to
See all releases

Code changes from version 3.0.1.2 to 3.0.0

README.txt CHANGED
@@ -1,10 +1,10 @@
1
=== IP Geo Block ===
2
Contributors: tokkonopapa
3
Donate link:
4
- Tags: security, firewall, brute force, vulnerability, login, wp-admin, admin, ajax, xmlrpc, comment, pingback, trackback, spam, IP address, geo, geolocation, buddypress, bbPress
5
Requires at least: 3.7
6
- Tested up to: 4.7.2
7
- Stable tag: 3.0.1.2
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -64,7 +64,7 @@ about protection performance against 50 samples of vulnerable plugins.
64
or themes can be blocked. A numerous such attacks can be found in
65
[this article](http://www.ipgeoblock.com/article/exposure-of-wp-config-php.html "Prevent exposure of wp-config.php").
66
67
- * **Minimize server load against brute-force attacks:**
68
You can configure this plugin as a
69
[Must Use Plugins](https://codex.wordpress.org/Must_Use_Plugins "Must Use Plugins « WordPress Codex")
70
which would be loaded prior to regular plugins and can massively
@@ -170,7 +170,7 @@ All contributions will always be welcome. Or visit my
170
2. Search for 'IP Geo Block'
171
3. Click 'Install Now'
172
4. Activate the plugin on the Plugin dashboard
173
- 5. Try 'Best settings' button for easy setup at the bottom of this plugin's
174
setting page.
175
176
Please refer to
@@ -315,10 +315,6 @@ or following descriptions for your best setup.
315
316
== Frequently Asked Questions ==
317
318
- = Does it support multisite? =
319
-
320
- It works on multisite, but there's no network setting at this moment.
321
-
322
= I was locked down. What shall I do? =
323
324
Activate the following codes at the bottom of `ip-geo-block.php` and upload
@@ -344,23 +340,6 @@ that you should upload the original one to deactivate above feature.
344
[This document](http://www.ipgeoblock.com/codex/what-should-i-do-when-i-m-locked-out.html "What should I do when I'm locked out? | IP Geo Block")
345
can also help you.
346
347
- = How to resolve "Sorry, your request cannot be accepted."? =
348
-
349
- If you encounter this message, please refer to
350
- [this document](http://www.ipgeoblock.com/codex/you-are-not-allowed-to-access.html "Why “You are not allowed to access this page” ? | IP Geo Block")
351
- to resolve your blocking issue.
352
-
353
- = Some admin function doesn't work. How to solve it? =
354
-
355
- This could be happened because of the same reason as the previous FAQ. Please
356
- follow the steps in
357
- [this document](http://www.ipgeoblock.com/codex/you-are-not-allowed-to-access.html "Why “You are not allowed to access this page” ? | IP Geo Block").
358
-
359
- If you can't solve your issue, please let me know about it on the
360
- [support forum](https://wordpress.org/support/plugin/ip-geo-block/ "View: Plugin Support « WordPress.org Forums").
361
- Your logs in this plugin and "**Installation information**" at "**Plugin
362
- settings**" will be a great help to resolve the issue.
363
-
364
= How can I fix "Unable to write" error? =
365
366
When you enable "**Force to load WP core**" options, this plugin will try to
@@ -373,7 +352,7 @@ to WordPress. In this case, you can configure these `.htaccess` files by your
373
own hand instead of enabling "**Force to load WP core**" options.
374
375
Please refer to
376
- "[How can I fix permission troubles?](http://www.ipgeoblock.com/codex/how-can-i-fix-permission-troubles.html 'How can I fix permission troubles? | IP Geo Block')"
377
in order to fix this error.
378
379
= Does this plugin works well with caching? =
@@ -435,9 +414,9 @@ follows:
435
- **Bad signatures in query**
436
It blocks the request which has not been covered in the above three.
437
438
- Please try "**Best settings**" button at the bottom of this plugin's setting
439
page for easy setup. And also see more details in
440
- "[The best practice of target settings](http://www.ipgeoblock.com/codex/the-best-practice-for-target-settings.html 'The best practice of target settings | IP Geo Block')".
441
442
= Does this plugin validate all the requests? =
443
@@ -451,6 +430,30 @@ But there're exceptions: When you enable "**Force to load WP core**" for
451
able to be blocked. Sometimes this kind of file has some vulnerabilities.
452
This function protects your site against such a case.
453
454
== Other Notes ==
455
456
= Known issues =
@@ -475,37 +478,6 @@ This function protects your site against such a case.
475
476
== Changelog ==
477
478
- = 3.0.1.2 =
479
- * **Bug fix:** Fix the blocking issue in some environments when upgrading from
480
- 2.2.9.1 to 3.0.0.
481
- * **Bug fix:** Fix the blocking issue at opening a new window via context menu
482
- on dashboard.
483
- * **Bug fix:** Fix the potential issue of 500 Internal error in cron job.
484
- * **Improvement:** Revive 410 Gone for response code.
485
- * **Improvement:** Prevent the issue of resetting matching rule and country
486
- code at upgrading.
487
-
488
- = 3.0.1.1 =
489
- * **Bug fix:** Fix the issue where **Login form** could not be disabled on
490
- **Back-end target settings**.
491
- * **Bug fix:** Fix the issue where trackback and pingback could not be blocked
492
- since 2.2.4.
493
- * **Improved:** Apply the action hook 'pre_trackback_post' that was introduced
494
- in WP 4.7.0.
495
- * **Improved:** Use 'safe_redirect()' instead of 'redirect()' for secured
496
- internal redirection. If you set an external url for **Redirect URL**, please
497
- use the filter hook 'allowed_redirect_hosts'.
498
- * **Improved:** Better compatibility with the plugin "Anti-Malware Security
499
- and Brute-Force Firewall".
500
-
501
- = 3.0.1 =
502
- * **Bug fix:** Add lock mechanism for local geolocation DBs to avoid potential
503
- fatal error.
504
- * **Improvement:** Add self blocking prevention potentially caused by login
505
- attempts with the same IP address of logged in user.
506
- * **New feature:** Add "**Installation information**" button to make it easy
507
- to submit an issue at support forum.
508
-
509
= 3.0.0 =
510
* **New feature:** Add the function of blocking on front-end.
511
* **New filter hook:** Add `ip-geo-block-public` to extend validation on
1
=== IP Geo Block ===
2
Contributors: tokkonopapa
3
Donate link:
4
+ Tags: buddypress, bbPress, comment, pingback, trackback, spam, IP address, geo, geolocation, xmlrpc, login, wp-admin, admin, ajax, security, brute force, firewall, vulnerability
5
Requires at least: 3.7
6
+ Tested up to: 4.6.1
7
+ Stable tag: 3.0.0
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
64
or themes can be blocked. A numerous such attacks can be found in
65
[this article](http://www.ipgeoblock.com/article/exposure-of-wp-config-php.html "Prevent exposure of wp-config.php").
66
67
+ * ** Minimize server load against brute-force attacks:**
68
You can configure this plugin as a
69
[Must Use Plugins](https://codex.wordpress.org/Must_Use_Plugins "Must Use Plugins « WordPress Codex")
70
which would be loaded prior to regular plugins and can massively
170
2. Search for 'IP Geo Block'
171
3. Click 'Install Now'
172
4. Activate the plugin on the Plugin dashboard
173
+ 5. Try 'Best practice' button for easy setup at the bottom of this plugin's
174
setting page.
175
176
Please refer to
315
316
== Frequently Asked Questions ==
317
318
= I was locked down. What shall I do? =
319
320
Activate the following codes at the bottom of `ip-geo-block.php` and upload
340
[This document](http://www.ipgeoblock.com/codex/what-should-i-do-when-i-m-locked-out.html "What should I do when I'm locked out? | IP Geo Block")
341
can also help you.
342
343
= How can I fix "Unable to write" error? =
344
345
When you enable "**Force to load WP core**" options, this plugin will try to
352
own hand instead of enabling "**Force to load WP core**" options.
353
354
Please refer to
355
+ "[How can I fix permission troubles?](http://www.ipgeoblock.com/codex/how-can-i-fix-permission-troubles.html 'How can I fix permission troubles? | IP Geo Block')"
356
in order to fix this error.
357
358
= Does this plugin works well with caching? =
414
- **Bad signatures in query**
415
It blocks the request which has not been covered in the above three.
416
417
+ Please try "**Best practice**" button at the bottom of this plugin's setting
418
page for easy setup. And also see more details in
419
+ "[The best practice of target settings](http://www.ipgeoblock.com/codex/the-best-practice-of-target-settings.html 'The best practice of target settings | IP Geo Block')".
420
421
= Does this plugin validate all the requests? =
422
430
able to be blocked. Sometimes this kind of file has some vulnerabilities.
431
This function protects your site against such a case.
432
433
+ = Some admin function doesn't work when WP-ZEP is enabled. =
434
+
435
+ There are a few cases that WP-ZEP would not work. One is redirection at server
436
+ side (caused by PHP or `.htaccess`) and client side (caused by JavaScript
437
+ location object or meta tag for refresh).
438
+
439
+ Another is the case related to the content type. This plugin will only support
440
+ `application/x-www-form-urlencoded` and `multipart/form-data`.
441
+
442
+ The last case is that a ajax/post request comes from not jQuery but flash or
443
+ something.
444
+
445
+ In those cases, this plugin should bypass WP-ZEP. So please find the unique
446
+ strings in the requested queries and add it into the safe query list via the
447
+ filter hook `ip-geo-block-bypass-admins`.
448
+
449
+ If you can not figure out your troubles, please let me know your issues and
450
+ the name of plugins you are using at support forum.
451
+
452
+ = Are there any other useful filter hooks? =
453
+
454
+ Yes, you can find the list of all hooks and useful samples
455
+ [here](http://www.ipgeoblock.com/codex/#filter-hooks "Codex | IP Geo Block").
456
+
457
== Other Notes ==
458
459
= Known issues =
478
479
== Changelog ==
480
481
= 3.0.0 =
482
* **New feature:** Add the function of blocking on front-end.
483
* **New filter hook:** Add `ip-geo-block-public` to extend validation on
admin/class-ip-geo-block-admin.php CHANGED
@@ -28,6 +28,9 @@ class IP_Geo_Block_Admin {
28
* and adding a settings page and menu.
29
*/
30
private function __construct() {
31
// Load plugin text domain.
32
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
33
@@ -41,9 +44,8 @@ class IP_Geo_Block_Admin {
41
add_filter( 'wp_prepare_revision_for_js', array( $this, 'add_revision_nonce' ), 10, 3 );
42
43
// If multisite, then enque the authentication script for network admin
44
- if ( is_multisite() ) {
45
add_action( 'network_admin_menu', 'IP_Geo_Block::enqueue_nonce' );
46
- }
47
}
48
49
/**
@@ -153,7 +155,6 @@ class IP_Geo_Block_Admin {
153
'IP_GEO_BLOCK',
154
array(
155
'action' => 'ip_geo_block',
156
- 'tab' => $this->admin_tab,
157
'url' => admin_url( 'admin-ajax.php' ),
158
'nonce' => IP_Geo_Block_Util::create_nonce( $this->get_ajax_action() ),
159
'msg' => array(
@@ -214,37 +215,24 @@ class IP_Geo_Block_Admin {
214
}
215
216
/**
217
- * Show global notice.
218
*
219
*/
220
public function show_admin_notices() {
221
$key = IP_Geo_Block::PLUGIN_NAME . '-notice';
222
-
223
if ( FALSE !== ( $notices = get_transient( $key ) ) ) {
224
foreach ( $notices as $msg => $type ) {
225
- echo "\n", '<div class="notice is-dismissible ', esc_attr( $type ), '"><p>';
226
- if ( 'updated' === $type )
227
- echo '<strong>', IP_Geo_Block_Util::kses( $msg ), '</strong>';
228
- else
229
- echo '<strong>IP Geo Block:</strong> ', IP_Geo_Block_Util::kses( $msg );
230
- echo '</p></div>', "\n";
231
}
232
}
233
-
234
- // delete all admin noties
235
- delete_transient( $key );
236
}
237
238
- /**
239
- * Add global notice.
240
- *
241
- */
242
public static function add_admin_notice( $type, $msg ) {
243
$key = IP_Geo_Block::PLUGIN_NAME . '-notice';
244
if ( FALSE === ( $notices = get_transient( $key ) ) )
245
$notices = array();
246
247
- // can't overwrite the existent notice
248
if ( ! isset( $notices[ $msg ] ) ) {
249
$notices[ $msg ] = $type;
250
set_transient( $key, $notices, MINUTE_IN_SECONDS );
@@ -252,14 +240,18 @@ class IP_Geo_Block_Admin {
252
}
253
254
/**
255
- * Register the administration menu into the WordPress Dashboard menu.
256
*
257
*/
258
- private function add_plugin_admin_menu() {
259
- // Setup the tab number
260
- $this->admin_tab = isset( $_GET['tab'] ) ? (int)$_GET['tab'] : 0;
261
- $this->admin_tab = min( 4, max( 0, $this->admin_tab ) );
262
263
// Add a settings page for this plugin to the Settings menu.
264
$hook = add_options_page(
265
__( 'IP Geo Block', 'ip-geo-block' ),
@@ -279,25 +271,27 @@ class IP_Geo_Block_Admin {
279
*
280
*/
281
private function diagnose_admin_screen() {
282
// Check version and compatibility
283
if ( version_compare( get_bloginfo( 'version' ), '3.7.0' ) < 0 )
284
self::add_admin_notice( 'error', __( 'You need WordPress 3.7+.', 'ip-geo-block' ) );
285
286
$settings = IP_Geo_Block::get_option();
287
- $adminurl = 'options-general.php';
288
289
// Check consistency of matching rule
290
if ( -1 === (int)$settings['matching_rule'] ) {
291
if ( FALSE !== get_transient( IP_Geo_Block::CRON_NAME ) ) {
292
self::add_admin_notice( 'notice-warning', sprintf(
293
__( 'Now downloading geolocation databases in background. After a little while, please check your country code and &#8220;<strong>Matching rule</strong>&#8221; at <a href="%s">Validation rule settings</a>.', 'ip-geo-block' ),
294
- esc_url( add_query_arg( array( 'page' => IP_Geo_Block::PLUGIN_NAME ), $adminurl ) )
295
) );
296
}
297
else {
298
self::add_admin_notice( 'error', sprintf(
299
__( 'The &#8220;<strong>Matching rule</strong>&#8221; is not set properly. Please confirm it at <a href="%s">Validation rule settings</a>.', 'ip-geo-block' ),
300
- esc_url( add_query_arg( array( 'page' => IP_Geo_Block::PLUGIN_NAME ), $adminurl ) )
301
) );
302
}
303
}
@@ -305,27 +299,15 @@ class IP_Geo_Block_Admin {
305
// Check to finish updating matching rule
306
elseif ( 'done' === get_transient( IP_Geo_Block::CRON_NAME ) ) {
307
delete_transient( IP_Geo_Block::CRON_NAME );
308
- self::add_admin_notice( 'updated ', __( 'Local database and matching rule have been updated.', 'ip-geo-block' ) );
309
}
310
311
// Check self blocking
312
if ( 1 === (int)$settings['validation']['login'] ) {
313
$instance = IP_Geo_Block::get_instance();
314
- $validate = $instance->validate_ip( 'login', $settings, TRUE, FALSE, FALSE ); // skip authentication check
315
316
- switch( $validate['result'] ) {
317
- case 'limited':
318
- self::add_admin_notice( 'error',
319
- __( 'Once you logout, you will be unable to login again because the number of login attempts reaches the limit.', 'ip-geo-block' ) . ' ' .
320
- sprintf(
321
- __( 'Please execute "<strong>Clear cache</strong>" on <a href="%s">Statistics tab</a> to prevent locking yourself out.', 'ip-geo-block' ),
322
- esc_url( add_query_arg( array( 'page' => IP_Geo_Block::PLUGIN_NAME, 'tab' => 1 ), $adminurl ) )
323
- )
324
- );
325
- break;
326
-
327
- case 'blocked':
328
- case 'extra':
329
self::add_admin_notice( 'error',
330
( $settings['matching_rule'] ?
331
__( 'Once you logout, you will be unable to login again because your country code or IP address is in the blacklist.', 'ip-geo-block' ) :
@@ -333,7 +315,7 @@ class IP_Geo_Block_Admin {
333
) .
334
sprintf(
335
__( 'Please check your <a href="%s">Validation rule settings</a>.', 'ip-geo-block' ),
336
- esc_url( add_query_arg( array( 'page' => IP_Geo_Block::PLUGIN_NAME ), $adminurl ) ) . '#' . IP_Geo_Block::PLUGIN_NAME . '-settings-0'
337
)
338
);
339
}
@@ -355,17 +337,13 @@ class IP_Geo_Block_Admin {
355
*
356
*/
357
public function setup_admin_page() {
358
- // Avoid multiple validation.
359
- if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
360
- $this->diagnose_admin_screen();
361
- $this->add_plugin_admin_menu();
362
- }
363
364
- // Register settings page only if it is needed.
365
if ( ( isset( $_GET ['page' ] ) && IP_Geo_Block::PLUGIN_NAME === $_GET ['page' ] ) ||
366
- ( isset( $_POST['option_page'] ) && IP_Geo_Block::PLUGIN_NAME === $_POST['option_page'] ) ) {
367
$this->register_settings_tab();
368
- }
369
370
// Add an action link pointing to the options page. @since 2.7
371
else {
@@ -373,10 +351,8 @@ class IP_Geo_Block_Admin {
373
add_filter( 'plugin_action_links_' . IP_GEO_BLOCK_BASE, array( $this, 'add_action_links' ), 10, 1 );
374
}
375
376
- // Register scripts for admin.
377
add_action( 'admin_enqueue_scripts', array( 'IP_Geo_Block', 'enqueue_nonce' ) );
378
-
379
- // Show admin notices at the place where it should be.
380
add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
381
}
382
@@ -385,7 +361,6 @@ class IP_Geo_Block_Admin {
385
*
386
*/
387
public function display_plugin_admin_page() {
388
- $tab = $this->admin_tab;
389
$tabs = array(
390
0 => __( 'Settings', 'ip-geo-block' ),
391
1 => __( 'Statistics', 'ip-geo-block' ),
@@ -393,6 +368,7 @@ class IP_Geo_Block_Admin {
393
2 => __( 'Search', 'ip-geo-block' ),
394
3 => __( 'Attribution', 'ip-geo-block' ),
395
);
396
?>
397
<div class="wrap">
398
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
@@ -450,7 +426,7 @@ class IP_Geo_Block_Admin {
450
3 => 'admin/includes/tab-attribution.php',
451
);
452
453
- require_once IP_GEO_BLOCK_PATH . $files[ $this->admin_tab ];
454
IP_Geo_Block_Admin_Tab::tab_setup( $this );
455
}
456
@@ -573,7 +549,7 @@ class IP_Geo_Block_Admin {
573
}
574
575
/**
576
- * Sanitize options before saving them into DB.
577
*
578
* @param array $input The values to be validated.
579
*
@@ -589,14 +565,12 @@ class IP_Geo_Block_Admin {
589
$default = IP_Geo_Block::get_default();
590
591
// checkboxes not on the form (added after 2.0.0, just in case)
592
- foreach ( array( 'anonymize', 'network_wide' ) as $key ) {
593
$output[ $key ] = 0;
594
- }
595
596
// checkboxes not on the form
597
- foreach ( array( 'login', 'admin', 'ajax', 'plugins', 'themes', 'public' ) as $key ) {
598
$output['validation'][ $key ] = 0;
599
- }
600
601
// restore the 'signature' that might be transformed to avoid self blocking
602
if ( isset( $input['signature'] ) && FALSE === strpos( $input['signature'], ',' ) )
@@ -642,16 +616,18 @@ class IP_Geo_Block_Admin {
642
}
643
644
// Check providers setting
645
- if ( $error = IP_Geo_Block_Provider::diag_providers( $output[ $key ] ) )
646
- self::add_admin_notice( 'error', $error );
647
break;
648
649
case 'comment':
650
- if ( isset( $input[ $key ]['pos'] ) )
651
$output[ $key ]['pos'] = (int)$input[ $key ]['pos'];
652
-
653
- if ( isset( $input[ $key ]['msg'] ) )
654
$output[ $key ]['msg'] = IP_Geo_Block_Util::kses( $input[ $key ]['msg'] );
655
break;
656
657
case 'white_list':
@@ -788,28 +764,29 @@ class IP_Geo_Block_Admin {
788
* Check admin post
789
*
790
*/
791
- private function check_admin_post( $ajax = FALSE ) {
792
- if ( FALSE === $ajax ) {
793
- // a postfix '-options' is added at settings_fields().
794
- $nonce = check_admin_referer( IP_Geo_Block::PLUGIN_NAME . '-options' );
795
- } else {
796
- $nonce = IP_Geo_Block_Util::verify_nonce( IP_Geo_Block_Util::retrieve_nonce( 'nonce' ), $this->get_ajax_action() );
797
}
798
799
$action = IP_Geo_Block::PLUGIN_NAME . '-auth-nonce';
800
$nonce &= IP_Geo_Block_Util::verify_nonce( IP_Geo_Block_Util::retrieve_nonce( $action ), $action );
801
802
- if ( ! $nonce || ( ! current_user_can( 'manage_options' ) ) ) {
803
status_header( 403 );
804
wp_die(
805
__( 'You do not have sufficient permissions to access this page.' ), '',
806
- array( 'response' => 403, 'back_link' => TRUE )
807
);
808
}
809
}
810
811
/**
812
- * Validate settings and configure some features.
813
*
814
*/
815
public function validate_settings( $input = array() ) {
@@ -819,8 +796,10 @@ class IP_Geo_Block_Admin {
819
// validate setting options
820
$options = $this->validate_options( $input );
821
822
// activate rewrite rules
823
- require_once IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-rewrite.php';
824
$stat = IP_Geo_Block_Admin_Rewrite::activate_rewrite_all( $options['rewrite'] );
825
826
// check the status of rewrite rules
@@ -836,18 +815,20 @@ class IP_Geo_Block_Admin {
836
$file[] = '<code>' . $dirs[ $key ] . '.htaccess</code>';
837
}
838
839
- self::add_admin_notice( 'error',
840
sprintf( __( 'Unable to write %s. Please check the permission.', 'ip-geo-block' ), implode( ', ', $file ) ) . '&nbsp;' .
841
sprintf( _n( 'Or please refer to %s to set it manually.', 'Or please refer to %s to set them manually.', count( $file ), 'ip-geo-block' ), '<a href="http://ipgeoblock.com/codex/how-to-fix-permission-troubles.html" title="How to fix permission troubles? | IP Geo Block">How to fix permission troubles?</a>' )
842
);
843
}
844
845
- // additional configuration
846
- require_once IP_GEO_BLOCK_PATH . 'classes/class-ip-geo-block-opts.php';
847
$file = IP_Geo_Block_Opts::setup_validation_timing( $options );
848
if ( TRUE !== $file ) {
849
$options['validation']['timing'] = 0;
850
- self::add_admin_notice( 'error', sprintf(
851
__( 'Unable to write %s. Please check the permission.', 'ip-geo-block' ), $file
852
) );
853
}
@@ -855,6 +836,9 @@ class IP_Geo_Block_Admin {
855
// Force to finish update matching rule
856
delete_transient( IP_Geo_Block::CRON_NAME );
857
858
return $options;
859
}
860
@@ -869,8 +853,6 @@ class IP_Geo_Block_Admin {
869
// Check request origin, nonce, capability.
870
$this->check_admin_post( TRUE );
871
872
- require_once IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php';
873
-
874
$which = isset( $_POST['which'] ) ? $_POST['which'] : NULL;
875
switch ( isset( $_POST['cmd' ] ) ? $_POST['cmd' ] : NULL ) {
876
case 'download':
@@ -880,11 +862,13 @@ class IP_Geo_Block_Admin {
880
881
case 'search':
882
// Get geolocation by IP
883
$res = IP_Geo_Block_Admin_Ajax::search_ip( $which );
884
break;
885
886
case 'scan-code':
887
// Fetch providers to get country code
888
$res = IP_Geo_Block_Admin_Ajax::scan_country();
889
break;
890
@@ -919,26 +903,31 @@ class IP_Geo_Block_Admin {
919
920
case 'export-logs':
921
// Export logs from MySQL DB
922
IP_Geo_Block_Admin_Ajax::export_logs( $which );
923
break;
924
925
case 'restore':
926
// Get logs from MySQL DB
927
$res = IP_Geo_Block_Admin_Ajax::restore_logs( $which );
928
break;
929
930
case 'validate':
931
// Validate settings
932
IP_Geo_Block_Admin_Ajax::validate_settings( $this );
933
break;
934
935
case 'import-default':
936
// Import initial settings
937
$res = IP_Geo_Block_Admin_Ajax::settings_to_json( IP_Geo_Block::get_default() );
938
break;
939
940
case 'import-preferred':
941
// Import preference
942
$res = IP_Geo_Block_Admin_Ajax::preferred_to_json();
943
break;
944
@@ -955,10 +944,6 @@ class IP_Geo_Block_Admin {
955
}
956
break;
957
958
- case 'show-info':
959
- $res = IP_Geo_Block_Admin_Ajax::get_wp_info();
960
- break;
961
-
962
case 'create-table':
963
case 'delete-table':
964
// Need to define `IP_GEO_BLOCK_DEBUG` to true
@@ -970,7 +955,6 @@ class IP_Geo_Block_Admin {
970
$res = array(
971
'page' => 'options-general.php?page=' . IP_Geo_Block::PLUGIN_NAME,
972
);
973
- break;
974
}
975
976
if ( isset( $res ) ) // wp_send_json_{success,error}() @since 3.5.0
28
* and adding a settings page and menu.
29
*/
30
private function __construct() {
31
+ $this->admin_tab = isset( $_GET['tab'] ) ? (int)$_GET['tab'] : 0;
32
+ $this->admin_tab = min( 4, max( 0, $this->admin_tab ) );
33
+
34
// Load plugin text domain.
35
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
36
44
add_filter( 'wp_prepare_revision_for_js', array( $this, 'add_revision_nonce' ), 10, 3 );
45
46
// If multisite, then enque the authentication script for network admin
47
+ if ( is_multisite() )
48
add_action( 'network_admin_menu', 'IP_Geo_Block::enqueue_nonce' );
49
}
50
51
/**
155
'IP_GEO_BLOCK',
156
array(
157
'action' => 'ip_geo_block',
158
'url' => admin_url( 'admin-ajax.php' ),
159
'nonce' => IP_Geo_Block_Util::create_nonce( $this->get_ajax_action() ),
160
'msg' => array(
215
}
216
217
/**
218
+ * Display global notice
219
*
220
+ * Note: Sanitization should be done at the caller
221
*/
222
public function show_admin_notices() {
223
$key = IP_Geo_Block::PLUGIN_NAME . '-notice';
224
if ( FALSE !== ( $notices = get_transient( $key ) ) ) {
225
foreach ( $notices as $msg => $type ) {
226
+ echo "\n<div class=\"notice is-dismissible ", esc_attr( $type ), "\"><p><strong>IP Geo Block:</strong> ", IP_Geo_Block_Util::kses( $msg ), "</p></div>\n";
227
}
228
}
229
}
230
231
public static function add_admin_notice( $type, $msg ) {
232
$key = IP_Geo_Block::PLUGIN_NAME . '-notice';
233
if ( FALSE === ( $notices = get_transient( $key ) ) )
234
$notices = array();
235
236
if ( ! isset( $notices[ $msg ] ) ) {
237
$notices[ $msg ] = $type;
238
set_transient( $key, $notices, MINUTE_IN_SECONDS );
240
}
241
242
/**
243
+ * Display local notice
244
*
245
*/
246
+ private function show_setting_notice( $type, $msg ) {
247
+ add_settings_error( IP_Geo_Block::PLUGIN_NAME, IP_Geo_Block::OPTION_NAME, $msg, $type );
248
+ }
249
250
+ /**
251
+ * Register the administration menu into the WordPress Dashboard menu.
252
+ *
253
+ */
254
+ private function add_plugin_admin_page() {
255
// Add a settings page for this plugin to the Settings menu.
256
$hook = add_options_page(
257
__( 'IP Geo Block', 'ip-geo-block' ),
271
*
272
*/
273
private function diagnose_admin_screen() {
274
+ // delete all admin noties
275
+ delete_transient( IP_Geo_Block::PLUGIN_NAME . '-notice' );
276
+
277
// Check version and compatibility
278
if ( version_compare( get_bloginfo( 'version' ), '3.7.0' ) < 0 )
279
self::add_admin_notice( 'error', __( 'You need WordPress 3.7+.', 'ip-geo-block' ) );
280
281
$settings = IP_Geo_Block::get_option();
282
283
// Check consistency of matching rule
284
if ( -1 === (int)$settings['matching_rule'] ) {
285
if ( FALSE !== get_transient( IP_Geo_Block::CRON_NAME ) ) {
286
self::add_admin_notice( 'notice-warning', sprintf(
287
__( 'Now downloading geolocation databases in background. After a little while, please check your country code and &#8220;<strong>Matching rule</strong>&#8221; at <a href="%s">Validation rule settings</a>.', 'ip-geo-block' ),
288
+ esc_url( admin_url( 'options-general.php?page=' . IP_Geo_Block::PLUGIN_NAME ) )
289
) );
290
}
291
else {
292
self::add_admin_notice( 'error', sprintf(
293
__( 'The &#8220;<strong>Matching rule</strong>&#8221; is not set properly. Please confirm it at <a href="%s">Validation rule settings</a>.', 'ip-geo-block' ),
294
+ esc_url( admin_url( 'options-general.php?page=' . IP_Geo_Block::PLUGIN_NAME ) )
295
) );
296
}
297
}
299
// Check to finish updating matching rule
300
elseif ( 'done' === get_transient( IP_Geo_Block::CRON_NAME ) ) {
301
delete_transient( IP_Geo_Block::CRON_NAME );
302
+ self::add_admin_notice( 'updated', __( 'Local database and matching rule have been updated.', 'ip-geo-block' ) );
303
}
304
305
// Check self blocking
306
if ( 1 === (int)$settings['validation']['login'] ) {
307
$instance = IP_Geo_Block::get_instance();
308
+ $validate = $instance->validate_ip( 'login', $settings, TRUE, FALSE, FALSE );
309
310
+ if ( 'passed' !== $validate['result'] ) {
311
self::add_admin_notice( 'error',
312
( $settings['matching_rule'] ?
313
__( 'Once you logout, you will be unable to login again because your country code or IP address is in the blacklist.', 'ip-geo-block' ) :
315
) .
316
sprintf(
317
__( 'Please check your <a href="%s">Validation rule settings</a>.', 'ip-geo-block' ),
318
+ esc_url( admin_url( 'options-general.php?page=' . IP_Geo_Block::PLUGIN_NAME . '#' . IP_Geo_Block::PLUGIN_NAME . '-settings-0' ) )
319
)
320
);
321
}
337
*
338
*/
339
public function setup_admin_page() {
340
+ $this->diagnose_admin_screen();
341
+ $this->add_plugin_admin_page();
342
343
+ // Register settings page only if it is needed
344
if ( ( isset( $_GET ['page' ] ) && IP_Geo_Block::PLUGIN_NAME === $_GET ['page' ] ) ||
345
+ ( isset( $_POST['option_page'] ) && IP_Geo_Block::PLUGIN_NAME === $_POST['option_page'] ) )
346
$this->register_settings_tab();
347
348
// Add an action link pointing to the options page. @since 2.7
349
else {
351
add_filter( 'plugin_action_links_' . IP_GEO_BLOCK_BASE, array( $this, 'add_action_links' ), 10, 1 );
352
}
353
354
+ // Register scripts and admin notice
355
add_action( 'admin_enqueue_scripts', array( 'IP_Geo_Block', 'enqueue_nonce' ) );
356
add_action( 'admin_notices', array( $this, 'show_admin_notices' ) );
357
}
358
361
*
362
*/
363
public function display_plugin_admin_page() {
364
$tabs = array(
365
0 => __( 'Settings', 'ip-geo-block' ),
366
1 => __( 'Statistics', 'ip-geo-block' ),
368
2 => __( 'Search', 'ip-geo-block' ),
369
3 => __( 'Attribution', 'ip-geo-block' ),
370
);
371
+ $tab = $this->admin_tab;
372
?>
373
<div class="wrap">
374
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
426
3 => 'admin/includes/tab-attribution.php',
427
);
428
429
+ require_once( IP_GEO_BLOCK_PATH . $files[ $this->admin_tab ] );
430
IP_Geo_Block_Admin_Tab::tab_setup( $this );
431
}
432
549
}
550
551
/**
552
+ * A callback function that validates the option's value.
553
*
554
* @param array $input The values to be validated.
555
*
565
$default = IP_Geo_Block::get_default();
566
567
// checkboxes not on the form (added after 2.0.0, just in case)
568
+ foreach ( array( 'anonymize', 'network_wide' ) as $key )
569
$output[ $key ] = 0;
570
571
// checkboxes not on the form
572
+ foreach ( array( 'admin', 'ajax', 'plugins', 'themes', 'public' ) as $key )
573
$output['validation'][ $key ] = 0;
574
575
// restore the 'signature' that might be transformed to avoid self blocking
576
if ( isset( $input['signature'] ) && FALSE === strpos( $input['signature'], ',' ) )
616
}
617
618
// Check providers setting
619
+ if ( $error = IP_Geo_Block_Provider::diag_providers( $output[ $key ] ) ) {
620
+ $this->show_setting_notice( 'error', $error );
621
+ }
622
break;
623
624
case 'comment':
625
+ if ( isset( $input[ $key ]['pos'] ) ) {
626
$output[ $key ]['pos'] = (int)$input[ $key ]['pos'];
627
+ }
628
+ if ( isset( $input[ $key ]['msg'] ) ) {
629
$output[ $key ]['msg'] = IP_Geo_Block_Util::kses( $input[ $key ]['msg'] );
630
+ }
631
break;
632
633
case 'white_list':
764
* Check admin post
765
*
766
*/
767
+ private function check_admin_post( $ajax ) {
768
+ $nonce = TRUE;
769
+
770
+ if ( $ajax ) {
771
+ $action = $this->get_ajax_action();
772
+ $nonce &= IP_Geo_Block_Util::verify_nonce( IP_Geo_Block_Util::retrieve_nonce( 'nonce' ), $action );
773
+ // $nonce &= check_admin_referer( $this->get_ajax_action(), 'nonce' );
774
}
775
776
$action = IP_Geo_Block::PLUGIN_NAME . '-auth-nonce';
777
$nonce &= IP_Geo_Block_Util::verify_nonce( IP_Geo_Block_Util::retrieve_nonce( $action ), $action );
778
779
+ if ( ! current_user_can( 'manage_options' ) || ! $nonce ) {
780
status_header( 403 );
781
wp_die(
782
__( 'You do not have sufficient permissions to access this page.' ), '',
783
+ array( 'response' => 403, 'back_link' => true )
784
);
785
}
786
}
787
788
/**
789
+ * Sanitize options before saving them into DB.
790
*
791
*/
792
public function validate_settings( $input = array() ) {
796
// validate setting options
797
$options = $this->validate_options( $input );
798
799
+ //----------------------------------------
800
// activate rewrite rules
801
+ //----------------------------------------
802
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-rewrite.php' );
803
$stat = IP_Geo_Block_Admin_Rewrite::activate_rewrite_all( $options['rewrite'] );
804
805
// check the status of rewrite rules
815
$file[] = '<code>' . $dirs[ $key ] . '.htaccess</code>';
816
}
817
818
+ $this->show_setting_notice( 'error',
819
sprintf( __( 'Unable to write %s. Please check the permission.', 'ip-geo-block' ), implode( ', ', $file ) ) . '&nbsp;' .
820
sprintf( _n( 'Or please refer to %s to set it manually.', 'Or please refer to %s to set them manually.', count( $file ), 'ip-geo-block' ), '<a href="http://ipgeoblock.com/codex/how-to-fix-permission-troubles.html" title="How to fix permission troubles? | IP Geo Block">How to fix permission troubles?</a>' )
821
);
822
}
823
824
+ //----------------------------------------
825
+ // additional installation
826
+ //----------------------------------------
827
+ require_once( IP_GEO_BLOCK_PATH . 'classes/class-ip-geo-block-opts.php' );
828
$file = IP_Geo_Block_Opts::setup_validation_timing( $options );
829
if ( TRUE !== $file ) {
830
$options['validation']['timing'] = 0;
831
+ $this->show_setting_notice( 'error', sprintf(
832
__( 'Unable to write %s. Please check the permission.', 'ip-geo-block' ), $file
833
) );
834
}
836
// Force to finish update matching rule
837
delete_transient( IP_Geo_Block::CRON_NAME );
838
839
+ // register a settings error to be displayed to the user
840
+ $this->show_setting_notice( 'updated', __( 'Settings saved.' ) );
841
+
842
return $options;
843
}
844
853
// Check request origin, nonce, capability.
854
$this->check_admin_post( TRUE );
855
856
$which = isset( $_POST['which'] ) ? $_POST['which'] : NULL;
857
switch ( isset( $_POST['cmd' ] ) ? $_POST['cmd' ] : NULL ) {
858
case 'download':
862
863
case 'search':
864
// Get geolocation by IP
865
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php' );
866
$res = IP_Geo_Block_Admin_Ajax::search_ip( $which );
867
break;
868
869
case 'scan-code':
870
// Fetch providers to get country code
871
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php' );
872
$res = IP_Geo_Block_Admin_Ajax::scan_country();
873
break;
874
903
904
case 'export-logs':
905
// Export logs from MySQL DB
906
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php' );
907
IP_Geo_Block_Admin_Ajax::export_logs( $which );
908
break;
909
910
case 'restore':
911
// Get logs from MySQL DB
912
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php' );
913
$res = IP_Geo_Block_Admin_Ajax::restore_logs( $which );
914
break;
915
916
case 'validate':
917
// Validate settings
918
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php' );
919
IP_Geo_Block_Admin_Ajax::validate_settings( $this );
920
break;
921
922
case 'import-default':
923
// Import initial settings
924
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php' );
925
$res = IP_Geo_Block_Admin_Ajax::settings_to_json( IP_Geo_Block::get_default() );
926
break;
927
928
case 'import-preferred':
929
// Import preference
930
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-ajax.php' );
931
$res = IP_Geo_Block_Admin_Ajax::preferred_to_json();
932
break;
933
944
}
945
break;
946
947
case 'create-table':
948
case 'delete-table':
949
// Need to define `IP_GEO_BLOCK_DEBUG` to true
955
$res = array(
956
'page' => 'options-general.php?page=' . IP_Geo_Block::PLUGIN_NAME,
957
);
958
}
959
960
if ( isset( $res ) ) // wp_send_json_{success,error}() @since 3.5.0
admin/css/admin.css CHANGED
@@ -342,14 +342,6 @@ input#ip_geo_block_settings_filter_logs {
342
position: relative;
343
top: 1px;
344
}
345
- #ip-geo-block-wp-info textarea {
346
- margin-top: 0.5em;
347
- overflow: auto;
348
- width: 100%;
349
- word-wrap: normal;
350
- word-break: normal;
351
- white-space: pre;
352
- }
353
#ip-geo-block-cycle {
354
height: 16px;
355
width: 16px;
342
position: relative;
343
top: 1px;
344
}
345
#ip-geo-block-cycle {
346
height: 16px;
347
width: 16px;
admin/css/admin.min.css CHANGED
@@ -1,2 +1,2 @@
1
/* This stylesheet is used to style the admin option form of the plugin. */
2
- .ip-geo-block-log .footable-row-detail-value,table.ip-geo-block-table{white-space:normal;word-wrap:break-word;word-break:break-all}#ip-geo-block-scan-code,.ip-geo-block-loading,.ip-geo-block-log *{vertical-align:middle}#ip-geo-block-cycle,.ip-geo-block-loading{background-size:16px 16px;background-position:center center;background-repeat:no-repeat}dfn{cursor:help;border-bottom:1px dotted #888}.form-table{margin:0 1em}fieldset.ip-geo-block-field{border:1px solid #ccc;padding:.35em .625em .75em 1em;margin:1.35em 0 1.5em}fieldset.ip-geo-block-field h2,fieldset.ip-geo-block-field h3{padding:0;margin:0}fieldset.ip-geo-block-field .ip-geo-block-dropdown,fieldset.ip-geo-block-field .ip-geo-block-dropup{cursor:pointer;position:relative;padding-left:1em}fieldset.ip-geo-block-field .ip-geo-block-dropdown:before,fieldset.ip-geo-block-field .ip-geo-block-dropup:before{content:'';height:0;width:0;border:.4em solid transparent;position:absolute}fieldset.ip-geo-block-field .ip-geo-block-dropup:before{border-left:.4em solid #555;left:3px;top:15%}fieldset.ip-geo-block-field .ip-geo-block-dropdown:before{border-top:.4em solid #555;left:0;top:35%}fieldset.ip-geo-block-field ul.ip-geo-block-dropup:before{top:.25em}fieldset.ip-geo-block-field ul.ip-geo-block-dropdown:before{top:.45em}fieldset.ip-geo-block-field .form-table{margin:.5em 0 0}textarea.regular-text{width:25em}ul.ip_geo_block_settings_folding{margin:.5em 0}ul.ip_geo_block_settings_folding ul{margin-bottom:0}ul.ip_geo_block_settings_folding li:first-child{margin-top:.5em}.ip-geo-block-desc,ul.ip-geo-block-list{margin-top:.25em;margin-bottom:.25em}.folding-disable{pointer-events:none;opacity:.5}.folding-inactive{opacity:.5;font-style:oblique!important}.ip-geo-block-hide{display:none}.ip-geo-block-desc,.ip-geo-block-loading,.ip-geo-block-result,.ip-geo-block-sup,.ip-geo-block-title,ul.ip-geo-block-list label{display:inline-block}.ip-geo-block-sup{margin-left:.2em}ul.ip-geo-block-note{list-style:disc;margin-left:1em}@media screen and (min-width:782px){ul.ip-geo-block-list .code{width:15em}}.ip-geo-block-loading{background-image:url(data:image/gif;base64,R0lGODlhEAAQAPIGAAAAAMLCwkJCQpKSkmJiYoKCgv///wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCgAGACwAAAAAEAAQAAADM2i63P4wyklrC0IEKgAQnAdOmGYFBLExwboQWcG2rlHEwTDQLUsUOd2mBxkUCgNKa+dIAAAh+QQJCgAGACwAAAIACgAOAAADLWgWIqHQCABEVLPe1R4MBOFFRFNsRUNsYDFewTC8iixvQ1EMyxjEvyBLODQkAAAh+QQJCgAGACwAAAAACgAOAAADLWi6IRJrCQCECoU0ag1xxeBARuEQ0UUU5DUM7fK+qTEUYR0EcM3Ev51uB7wAEwAh+QQJCgAGACwAAAAADgAKAAADLWi6URQrLiJEkSaM0eqrkLFtAVEEAgAIylAUQ5SuSqCFNZjhWG3zmB8wOJQkAAAh+QQJCgAGACwCAAAADgAKAAADK2hqMRMrLuekCnCU8gqBDCZ2glBcYkSUxIJJgQdaUVDOtAAAAr3oPN/llgAAIfkECQoABgAsBgAAAAoADgAAAytoEdauiz0Yx5BQFTvN2EMXWNgUFETZFIJQdERLiGgZtKohAIDQ7T0RrpEAACH5BAkKAAYALAYAAgAKAA4AAAMqaKoR+609Fie1K4zhZiibNRSg1XAQUXQPIQgE835voQgAIARqh+ummSUBACH5BAUKAAYALAIABgAOAAoAAAMsaLpsES2+F9mEddEgBFbBMGACAAiMOCrlGRBFWBQD2L0dYYjfUuQZEKynSAAAOw==);height:16px;width:16px;margin-left:1em;margin-top:.2em}.ip-geo-block-notice{color:#dd3d36}.ip-geo-block-title{width:100px}.ip-geo-block-result{color:#2786C2}#ip-geo-block-map{height:400px;margin:1em auto}.gm-style-iw{width:18em;height:auto!important;height:100%;min-height:100%:}.gm-style-iw ul{margin:.1em}.gm-style-iw li{margin:.2em}ul.ip-geo-block-statistics-countries li{width:12em;float:left;text-align:right;padding:.2em}table.ip-geo-block-statistics-table{float:right}table.ip-geo-block-statistics-table td,table.ip-geo-block-statistics-table th{width:12em;margin:0;padding:.2em;text-align:right;line-height:1.5em;word-wrap:break-word}table.ip-geo-block-statistics-table tr:nth-child(even){background-color:#f7f7f7}.ip-geo-block-log{width:100%!important}.ip-geo-block-log *{font-size:13px!important;line-height:1.5em}.ip-geo-block-log .pagination ul{border-radius:4px;display:inline-block;margin-bottom:0;margin-left:0;padding-left:0}.ip-geo-block-log .pagination ul>li{display:inline}.ip-geo-block-log .pagination ul>li:first-child>a,.ip-geo-block-log .pagination ul>li:first-child>span{border-bottom-left-radius:4px;border-left-width:1px;border-top-left-radius:4px}.ip-geo-block-log .pagination ul>li:last-child>a,.ip-geo-block-log .pagination ul>li:last-child>span{border-bottom-right-radius:4px;border-top-right-radius:4px}.ip-geo-block-log .pagination ul>.disabled>a,.ip-geo-block-log .pagination ul>.disabled>a:focus,.ip-geo-block-log .pagination ul>.disabled>a:hover,.ip-geo-block-log .pagination ul>.disabled>span{background-color:transparent;color:#999;cursor:default}.ip-geo-block-log .pagination ul>li>a,.ip-geo-block-log .pagination ul>li>span{border-color:#ddd;border-image:none;border-style:solid;border-width:1px 1px 1px 0;float:left;line-height:20px;padding:4px;width:20px;text-decoration:none}.ip-geo-block-log .pagination ul>.active>a,.ip-geo-block-log .pagination ul>.active>span{color:#999;cursor:default}.ip-geo-block-log .pagination ul>.active>a,.ip-geo-block-log .pagination ul>.active>span,.ip-geo-block-log .pagination ul>li>a:focus,.ip-geo-block-log .pagination ul>li>a:hover{background-color:#f7f7f7}.ip-geo-block-log .pagination-centered{text-align:center}.ip-geo-block-log.breakpoint>tbody>tr>td>span.footable-toggle{font-size:60%!important;position:relative;top:-1px;left:2px}.ip-geo-block-log>tbody>tr>td,.ip-geo-block-log>thead>tr>th{padding:4px 0;word-wrap:break-word;width:20%}.ip-geo-block-log>tbody>tr>td:first-child,.ip-geo-block-log>thead>tr>th:first-child{width:25%}.ip-geo-block-log>tbody>tr>td:first-child+td,.ip-geo-block-log>thead>tr>th:first-child+th{width:35%}.ip-geo-block-log>tbody>tr>td:nth-child(5),.ip-geo-block-log>tbody>tr>td:nth-child(5)+td,.ip-geo-block-log>thead>tr>th:nth-child(5),.ip-geo-block-log>thead>tr>th:nth-child(5)+th{width:60%;text-align:left}@media screen and (min-width:1024px){.ip-geo-block-log>tbody>tr>td:nth-child(3),.ip-geo-block-log>tbody>tr>td:nth-child(3)+td,.ip-geo-block-log>thead>tr>th:nth-child(3),.ip-geo-block-log>thead>tr>th:nth-child(3)+th{width:10%}}.ip-geo-block-log>thead>tr>th>span.footable-sort-indicator{color:#888}.ip-geo-block-log>tbody>tr>td{text-align:center}.ip-geo-block-log>tbody>tr>td:first-child{text-align:left}.ip-geo-block-log .footable-row-detail-name,.ip-geo-block-log .footable-row-detail-row,.ip-geo-block-log .footable-row-detail-value{display:block}.ip-geo-block-log .footable-row-detail-value{padding:0 1em 4px}input#ip_geo_block_settings_filter_logs{width:16em;padding-top:3px}#ip-geo-block-code-list{display:none;margin-bottom:0}#ip-geo-block-countries,#ip-geo-block-targets{display:none}#ip-geo-block-chart-countries{height:200px}#ip-geo-block-chart-daily{height:240px}#ip_geo_block_settings_validation_plugins,#ip_geo_block_settings_validation_themes{margin-top:.5em}#ip-geo-block-back-to-top,#ip-geo-block-toggle-sections{box-shadow:none}#ip-geo-block-decode{box-shadow:none;text-decoration:none}#ip-geo-block-decode:active{position:relative;top:1px}#ip-geo-block-wp-info textarea{margin-top:.5em;overflow:auto;width:100%;word-wrap:normal;word-break:normal;white-space:pre}#ip-geo-block-cycle{height:16px;width:16px;margin:0;border:none;display:inline-block;vertical-align:text-bottom;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAh1BMVEUAda2otLp+rsSHprWHr8IBd7EpfKRGhaNajqeUqrRymKuKoq5yo7prlKgAcqoVe6w8gqQmgq5Tj6wIdqsVdKIshrEMea1Uhp+Anqw0hawDdq4gfKhljqE7hqoLdKYbgbM4jLQygKUGeK8CdawQd6gVeKcad6NKkrSerrZAj7UAc6sAc6rc3NySrVGQAAAALXRSTlP//////////////////////////////////////////////////////////wCl7wv9AAACOklEQVR4Ae2W15rzKgxF9xTZzhTX9B7S/gN6/9ebYqzzGZsw/S7LV3FZgCSIwD/kQ8FVcBU8xatZUczy8luC/ABNOn0DSHEsvyZ4PgLatNCYR3efFxyhTQ8g+qQgJxgv2JefERzJXATRh4LHOUwAHD4S7OGEztRJaN86hAUxtaNWDUf/bRdDBbQMWVDAO8jn89WUhag1MeyCAh6hHofyrliLgZKggDMYgzF3eVAwFq0uCZq5KY0TezjIHDDzC0qqmkwe2ctGDOQVLMkgu+F3/rGXwb4xIPcJ6P3JgkM8wFjmfcFAWfeKQywaAz33BJVuHsUcAt09gVbuLDThAJkdR687ggLmf4gDJLIGV7BydtB8yn3u+fbtuj/LS7G9wZAd1AKK+yxJ1x+aBmibTtgCcEHGHsh0wdbOgNLek4L7lI5BigY8nWuZUQ3qGEXes9JzOKGJztPaGtLslu3lIXJirdxCWkASHGDTMqg7V1DKPplygDG61YJukLHjEErGSXqCSos6xNSOgzP3BDmsQBcchNwkoV8oiNnPA78zIefUgCdJeGIfE7LmFWXsFTCFdzTJ/RlfEMRiSGnFXXbkC7AIeqcKDu4ynseozeouKJiSEYBDwkJyIC1nRUjgblkNWp/e/1vXc2gjoAoLksYgjrrFMi0oDgjEEIDij1scBXMJSH6DAj6RNl7o8MkuLak8Co15/Pk+MRmT0xilQJV/sdWNKg2kTaeroudvNNsDjmejYjSL+e6v2/2r4Cp4BXNajr0H7hRfAAAAAElFTkSuQmCC)}
1
/* This stylesheet is used to style the admin option form of the plugin. */
2
+ .ip-geo-block-log .footable-row-detail-value,table.ip-geo-block-table{white-space:normal;word-wrap:break-word;word-break:break-all}#ip-geo-block-scan-code,.ip-geo-block-loading,.ip-geo-block-log *{vertical-align:middle}#ip-geo-block-cycle,.ip-geo-block-loading{background-size:16px 16px;background-position:center center;background-repeat:no-repeat}dfn{cursor:help;border-bottom:1px dotted #888}.form-table{margin:0 1em}fieldset.ip-geo-block-field{border:1px solid #ccc;padding:.35em .625em .75em 1em;margin:1.35em 0 1.5em}fieldset.ip-geo-block-field h2,fieldset.ip-geo-block-field h3{padding:0;margin:0}fieldset.ip-geo-block-field .ip-geo-block-dropdown,fieldset.ip-geo-block-field .ip-geo-block-dropup{cursor:pointer;position:relative;padding-left:1em}fieldset.ip-geo-block-field .ip-geo-block-dropdown:before,fieldset.ip-geo-block-field .ip-geo-block-dropup:before{content:'';height:0;width:0;border:.4em solid transparent;position:absolute}fieldset.ip-geo-block-field .ip-geo-block-dropup:before{border-left:.4em solid #555;left:3px;top:15%}fieldset.ip-geo-block-field .ip-geo-block-dropdown:before{border-top:.4em solid #555;left:0;top:35%}fieldset.ip-geo-block-field ul.ip-geo-block-dropup:before{top:.25em}fieldset.ip-geo-block-field ul.ip-geo-block-dropdown:before{top:.45em}fieldset.ip-geo-block-field .form-table{margin:.5em 0 0}textarea.regular-text{width:25em}ul.ip_geo_block_settings_folding{margin:.5em 0}ul.ip_geo_block_settings_folding ul{margin-bottom:0}ul.ip_geo_block_settings_folding li:first-child{margin-top:.5em}.ip-geo-block-desc,ul.ip-geo-block-list{margin-top:.25em;margin-bottom:.25em}.folding-disable{pointer-events:none;opacity:.5}.folding-inactive{opacity:.5;font-style:oblique!important}.ip-geo-block-hide{display:none}.ip-geo-block-desc,.ip-geo-block-loading,.ip-geo-block-result,.ip-geo-block-sup,.ip-geo-block-title,ul.ip-geo-block-list label{display:inline-block}.ip-geo-block-sup{margin-left:.2em}ul.ip-geo-block-note{list-style:disc;margin-left:1em}@media screen and (min-width:782px){ul.ip-geo-block-list .code{width:15em}}.ip-geo-block-loading{background-image:url(data:image/gif;base64,R0lGODlhEAAQAPIGAAAAAMLCwkJCQpKSkmJiYoKCgv///wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCgAGACwAAAAAEAAQAAADM2i63P4wyklrC0IEKgAQnAdOmGYFBLExwboQWcG2rlHEwTDQLUsUOd2mBxkUCgNKa+dIAAAh+QQJCgAGACwAAAIACgAOAAADLWgWIqHQCABEVLPe1R4MBOFFRFNsRUNsYDFewTC8iixvQ1EMyxjEvyBLODQkAAAh+QQJCgAGACwAAAAACgAOAAADLWi6IRJrCQCECoU0ag1xxeBARuEQ0UUU5DUM7fK+qTEUYR0EcM3Ev51uB7wAEwAh+QQJCgAGACwAAAAADgAKAAADLWi6URQrLiJEkSaM0eqrkLFtAVEEAgAIylAUQ5SuSqCFNZjhWG3zmB8wOJQkAAAh+QQJCgAGACwCAAAADgAKAAADK2hqMRMrLuekCnCU8gqBDCZ2glBcYkSUxIJJgQdaUVDOtAAAAr3oPN/llgAAIfkECQoABgAsBgAAAAoADgAAAytoEdauiz0Yx5BQFTvN2EMXWNgUFETZFIJQdERLiGgZtKohAIDQ7T0RrpEAACH5BAkKAAYALAYAAgAKAA4AAAMqaKoR+609Fie1K4zhZiibNRSg1XAQUXQPIQgE835voQgAIARqh+ummSUBACH5BAUKAAYALAIABgAOAAoAAAMsaLpsES2+F9mEddEgBFbBMGACAAiMOCrlGRBFWBQD2L0dYYjfUuQZEKynSAAAOw==);height:16px;width:16px;margin-left:1em;margin-top:.2em}.ip-geo-block-notice{color:#dd3d36}.ip-geo-block-title{width:100px}.ip-geo-block-result{color:#2786C2}#ip-geo-block-map{height:400px;margin:1em auto}.gm-style-iw{width:18em;height:auto!important;height:100%;min-height:100%:}.gm-style-iw ul{margin:.1em}.gm-style-iw li{margin:.2em}ul.ip-geo-block-statistics-countries li{width:12em;float:left;text-align:right;padding:.2em}table.ip-geo-block-statistics-table{float:right}table.ip-geo-block-statistics-table td,table.ip-geo-block-statistics-table th{width:12em;margin:0;padding:.2em;text-align:right;line-height:1.5em;word-wrap:break-word}table.ip-geo-block-statistics-table tr:nth-child(even){background-color:#f7f7f7}.ip-geo-block-log{width:100%!important}.ip-geo-block-log *{font-size:13px!important;line-height:1.5em}.ip-geo-block-log .pagination ul{border-radius:4px;display:inline-block;margin-bottom:0;margin-left:0;padding-left:0}.ip-geo-block-log .pagination ul>li{display:inline}.ip-geo-block-log .pagination ul>li:first-child>a,.ip-geo-block-log .pagination ul>li:first-child>span{border-bottom-left-radius:4px;border-left-width:1px;border-top-left-radius:4px}.ip-geo-block-log .pagination ul>li:last-child>a,.ip-geo-block-log .pagination ul>li:last-child>span{border-bottom-right-radius:4px;border-top-right-radius:4px}.ip-geo-block-log .pagination ul>.disabled>a,.ip-geo-block-log .pagination ul>.disabled>a:focus,.ip-geo-block-log .pagination ul>.disabled>a:hover,.ip-geo-block-log .pagination ul>.disabled>span{background-color:transparent;color:#999;cursor:default}.ip-geo-block-log .pagination ul>li>a,.ip-geo-block-log .pagination ul>li>span{border-color:#ddd;border-image:none;border-style:solid;border-width:1px 1px 1px 0;float:left;line-height:20px;padding:4px;width:20px;text-decoration:none}.ip-geo-block-log .pagination ul>.active>a,.ip-geo-block-log .pagination ul>.active>span{color:#999;cursor:default}.ip-geo-block-log .pagination ul>.active>a,.ip-geo-block-log .pagination ul>.active>span,.ip-geo-block-log .pagination ul>li>a:focus,.ip-geo-block-log .pagination ul>li>a:hover{background-color:#f7f7f7}.ip-geo-block-log .pagination-centered{text-align:center}.ip-geo-block-log.breakpoint>tbody>tr>td>span.footable-toggle{font-size:60%!important;position:relative;top:-1px;left:2px}.ip-geo-block-log>tbody>tr>td,.ip-geo-block-log>thead>tr>th{padding:4px 0;word-wrap:break-word;width:20%}.ip-geo-block-log>tbody>tr>td:first-child,.ip-geo-block-log>thead>tr>th:first-child{width:25%}.ip-geo-block-log>tbody>tr>td:first-child+td,.ip-geo-block-log>thead>tr>th:first-child+th{width:35%}.ip-geo-block-log>tbody>tr>td:nth-child(5),.ip-geo-block-log>tbody>tr>td:nth-child(5)+td,.ip-geo-block-log>thead>tr>th:nth-child(5),.ip-geo-block-log>thead>tr>th:nth-child(5)+th{width:60%;text-align:left}@media screen and (min-width:1024px){.ip-geo-block-log>tbody>tr>td:nth-child(3),.ip-geo-block-log>tbody>tr>td:nth-child(3)+td,.ip-geo-block-log>thead>tr>th:nth-child(3),.ip-geo-block-log>thead>tr>th:nth-child(3)+th{width:10%}}.ip-geo-block-log>thead>tr>th>span.footable-sort-indicator{color:#888}.ip-geo-block-log>tbody>tr>td{text-align:center}.ip-geo-block-log>tbody>tr>td:first-child{text-align:left}.ip-geo-block-log .footable-row-detail-name,.ip-geo-block-log .footable-row-detail-row,.ip-geo-block-log .footable-row-detail-value{display:block}.ip-geo-block-log .footable-row-detail-value{padding:0 1em 4px}input#ip_geo_block_settings_filter_logs{width:16em;padding-top:3px}#ip-geo-block-code-list{display:none;margin-bottom:0}#ip-geo-block-countries,#ip-geo-block-targets{display:none}#ip-geo-block-chart-countries{height:200px}#ip-geo-block-chart-daily{height:240px}#ip_geo_block_settings_validation_plugins,#ip_geo_block_settings_validation_themes{margin-top:.5em}#ip-geo-block-back-to-top,#ip-geo-block-toggle-sections{box-shadow:none}#ip-geo-block-decode{box-shadow:none;text-decoration:none}#ip-geo-block-decode:active{position:relative;top:1px}#ip-geo-block-cycle{height:16px;width:16px;margin:0;border:none;display:inline-block;vertical-align:text-bottom;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAh1BMVEUAda2otLp+rsSHprWHr8IBd7EpfKRGhaNajqeUqrRymKuKoq5yo7prlKgAcqoVe6w8gqQmgq5Tj6wIdqsVdKIshrEMea1Uhp+Anqw0hawDdq4gfKhljqE7hqoLdKYbgbM4jLQygKUGeK8CdawQd6gVeKcad6NKkrSerrZAj7UAc6sAc6rc3NySrVGQAAAALXRSTlP//////////////////////////////////////////////////////////wCl7wv9AAACOklEQVR4Ae2W15rzKgxF9xTZzhTX9B7S/gN6/9ebYqzzGZsw/S7LV3FZgCSIwD/kQ8FVcBU8xatZUczy8luC/ABNOn0DSHEsvyZ4PgLatNCYR3efFxyhTQ8g+qQgJxgv2JefERzJXATRh4LHOUwAHD4S7OGEztRJaN86hAUxtaNWDUf/bRdDBbQMWVDAO8jn89WUhag1MeyCAh6hHofyrliLgZKggDMYgzF3eVAwFq0uCZq5KY0TezjIHDDzC0qqmkwe2ctGDOQVLMkgu+F3/rGXwb4xIPcJ6P3JgkM8wFjmfcFAWfeKQywaAz33BJVuHsUcAt09gVbuLDThAJkdR687ggLmf4gDJLIGV7BydtB8yn3u+fbtuj/LS7G9wZAd1AKK+yxJ1x+aBmibTtgCcEHGHsh0wdbOgNLek4L7lI5BigY8nWuZUQ3qGEXes9JzOKGJztPaGtLslu3lIXJirdxCWkASHGDTMqg7V1DKPplygDG61YJukLHjEErGSXqCSos6xNSOgzP3BDmsQBcchNwkoV8oiNnPA78zIefUgCdJeGIfE7LmFWXsFTCFdzTJ/RlfEMRiSGnFXXbkC7AIeqcKDu4ynseozeouKJiSEYBDwkJyIC1nRUjgblkNWp/e/1vXc2gjoAoLksYgjrrFMi0oDgjEEIDij1scBXMJSH6DAj6RNl7o8MkuLak8Co15/Pk+MRmT0xilQJV/sdWNKg2kTaeroudvNNsDjmejYjSL+e6v2/2r4Cp4BXNajr0H7hRfAAAAAElFTkSuQmCC)}
admin/includes/class-admin-ajax.php CHANGED
@@ -6,7 +6,7 @@ class IP_Geo_Block_Admin_Ajax {
6
*
7
*/
8
static public function search_ip( $which ) {
9
- require_once IP_GEO_BLOCK_PATH . 'classes/class-ip-geo-block-lkup.php';
10
11
// check format
12
if ( filter_var( $ip = $_POST['ip'], FILTER_VALIDATE_IP ) ) {
@@ -420,67 +420,9 @@ class IP_Geo_Block_Admin_Ajax {
420
// Fallback function for PHP 5.3 and under
421
static private function convert_encoding( $matches ) {
422
return mb_convert_encoding(
423
- pack( 'H*', str_replace( '\\u', '', $matches[0] ) ), 'UTF-8', 'UTF-16'
424
);
425
}
426
427
- static public function get_wp_info() {
428
- // PHP, WordPress
429
- $res = array();
430
- $res[] = array( 'PHP' => PHP_VERSION );
431
- $res[] = array( 'BC Math' => (extension_loaded('gmp') ? 'gmp ' : '') . (function_exists('bcadd') ? 'yes' : 'no') );
432
- $res[] = array( 'mb_strcut' => function_exists( 'mb_strcut' ) ? 'yes' : 'no' );
433
- $res[] = array( 'WordPress' => $GLOBALS['wp_version'] );
434
- $res[] = array( 'Multisite' => is_multisite() ? 'yes' : 'no' );
435
-
436
- // Child and parent themes
437
- $activated = wp_get_theme(); // @since 3.4.0
438
- $res[] = array( esc_html( $activated->get( 'Name' ) ) => esc_html( $activated->get( 'Version' ) ) );
439
-
440
- if ( $installed = $activated->get( 'Template' ) ) {
441
- $activated = wp_get_theme( $installed );
442
- $res[] = array( esc_html( $activated->get( 'Name' ) ) => esc_html( $activated->get( 'Version' ) ) );
443
- }
444
-
445
- // Plugins
446
- $installed = get_plugins(); // @since 1.5.0
447
- $activated = get_site_option( 'active_sitewide_plugins' ); // @since 2.8.0
448
- ! is_array( $activated ) and $activated = array();
449
- $activated = array_merge( $activated, array_fill_keys( get_option( 'active_plugins' ), TRUE ) );
450
-
451
- foreach ( $installed as $key => $val ) {
452
- if ( isset( $activated[ $key ] ) ) {
453
- $res[] = array(
454
- esc_html( $val['Name'] ) => esc_html( $val['Version'] )
455
- );
456
- }
457
- }
458
-
459
- // Logs (hook, time, ip, code, result, method, user_agent, headers, data)
460
- $installed = IP_Geo_Block_Logs::search_logs( IP_Geo_Block::get_ip_address() );
461
-
462
- foreach ( array_reverse( $installed ) as $val ) {
463
- // hide port and nonce
464
- $method = preg_replace( '/\[\d+\]/', '', $val['method'] );
465
- $method = preg_replace( '/(' . IP_Geo_Block::PLUGIN_NAME . '-auth-nonce)(?:=|%3D)([\w]+)/', '$1=...', $method );
466
-
467
- // add post data
468
- $query = array();
469
- foreach ( explode( ',', $val['data'] ) as $str ) {
470
- if ( FALSE !== strpos( $str, '=' ) )
471
- $query[] = $str;
472
- }
473
-
474
- if ( ! empty( $query ) )
475
- $method .= '(' . implode( ',', $query ) . ')';
476
-
477
- $res[] = array(
478
- esc_html( IP_Geo_Block_Util::localdate( $val['time'], 'Y-m-d H:i:s' ) ) =>
479
- esc_html( str_pad( $val['result'], 8 ) . $method )
480
- );
481
- }
482
-
483
- return $res;
484
- }
485
-
486
}
6
*
7
*/
8
static public function search_ip( $which ) {
9
+ require_once( IP_GEO_BLOCK_PATH . 'classes/class-ip-geo-block-lkup.php' );
10
11
// check format
12
if ( filter_var( $ip = $_POST['ip'], FILTER_VALIDATE_IP ) ) {
420
// Fallback function for PHP 5.3 and under
421
static private function convert_encoding( $matches ) {
422
return mb_convert_encoding(
423
+ pack( 'H*', str_replace( '\\u', '', $matches[0] ) ),
424
+ 'UTF-8', 'UTF-16'
425
);
426
}
427
428
}
admin/includes/tab-accesslog.php CHANGED
@@ -106,13 +106,13 @@ endif;
106
*/
107
public static function list_accesslog() {
108
// same as in tab-settings.php
109
- $dfn = __( '<dfn title="Validation log of request to %s.">%s</dfn>', 'ip-geo-block' );
110
$target = array(
111
- 'comment' => sprintf( $dfn, 'wp-comments-post.php', __( 'Comment post', 'ip-geo-block' ) ),
112
- 'xmlrpc' => sprintf( $dfn, 'xmlrpc.php', __( 'XML-RPC', 'ip-geo-block' ) ),
113
- 'login' => sprintf( $dfn, 'wp-login.php', __( 'Login form', 'ip-geo-block' ) ),
114
- 'admin' => sprintf( $dfn, 'wp-admin/*.php', __( 'Admin area', 'ip-geo-block' ) ),
115
- 'public' => sprintf( $dfn, __( 'public facing pages', 'ip-geo-block' ), __( 'Public facing pages', 'ip-geo-block' ) ),
116
);
117
118
foreach ( $target as $key => $val ) {
106
*/
107
public static function list_accesslog() {
108
// same as in tab-settings.php
109
+ $dfn = __( '<dfn title="Validate request to %s.">%s</dfn>', 'ip-geo-block' );
110
$target = array(
111
+ 'comment' => sprintf( $dfn, 'wp-comments-post.php', __( 'Comment post', 'ip-geo-block' ) ),
112
+ 'xmlrpc' => sprintf( $dfn, 'xmlrpc.php', __( 'XML-RPC', 'ip-geo-block' ) ),
113
+ 'login' => sprintf( $dfn, 'wp-login.php', __( 'Login form', 'ip-geo-block' ) ),
114
+ 'admin' => sprintf( $dfn, 'wp-admin/*.php', __( 'Admin area', 'ip-geo-block' ) ),
115
+ 'public' => sprintf( $dfn, 'public facing pages', __( 'Pubic facing pages', 'ip-geo-block' ) ),
116
);
117
118
foreach ( $target as $key => $val ) {
admin/includes/tab-settings.php CHANGED
@@ -1,9 +1,9 @@
1
<?php
2
- require_once IP_GEO_BLOCK_PATH . 'classes/class-ip-geo-block-opts.php';
3
- require_once IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-rewrite.php';
4
5
if ( ! function_exists( 'get_plugins' ) )
6
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
7
8
class IP_Geo_Block_Admin_Tab {
9
@@ -91,8 +91,8 @@ class IP_Geo_Block_Admin_Tab {
91
92
$rule_desc = array(
93
__( 'Please select either &#8220;Whitelist&#8221; or &#8220;Blacklist&#8221;.', 'ip-geo-block' ),
94
- __( '<dfn title="&#8220;Block by country&#8221; will be bypassed in case of empty. All the countries will be blocked in case you put &#8220;XX&#8221; only.">Whitelist of country code</dfn>', 'ip-geo-block' ) . '<br />(<a rel="noreferrer" href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements" title="ISO 3166-1 alpha-2 - Wikipedia, the free encyclopedia">ISO 3166-1 alpha-2</a>)',
95
- __( '<dfn title="&#8220;Block by country&#8221; will be bypassed in case of empty. Please consider to include &#8220;ZZ&#8221; which means UNKNOWN country.">Blacklist of country code</dfn>', 'ip-geo-block' ) . '<br />(<a rel="noreferrer" href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements" title="ISO 3166-1 alpha-2 - Wikipedia, the free encyclopedia">ISO 3166-1 alpha-2</a>)',
96
);
97
98
$comma = array(
@@ -163,7 +163,7 @@ class IP_Geo_Block_Admin_Tab {
163
add_settings_field(
164
$option_name.'_'.$field.'_'.$key,
165
__( '<dfn title="e.g. &#8220;192.0.64.0/18&#8221; for Jetpack server, &#8220;69.46.36.0/27&#8221; for WordFence server">Whitelist of extra IP addresses prior to country code</dfn>', 'ip-geo-block' ) .
166
- ' (<a rel="noreferrer" href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" title="Classless Inter-Domain Routing - Wikipedia, the free encyclopedia">CIDR</a>)',
167
array( $context, 'callback_field' ),
168
$option_slug,
169
$section,
@@ -182,7 +182,7 @@ class IP_Geo_Block_Admin_Tab {
182
add_settings_field(
183
$option_name.'_'.$field.'_'.$key,
184
__( '<dfn title="Server level access control is recommended (e.g. .htaccess).">Blacklist of extra IP addresses prior to country code</dfn>', 'ip-geo-block' ) .
185
- ' (<a rel="noreferrer" href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" title="Classless Inter-Domain Routing - Wikipedia, the free encyclopedia">CIDR</a>)',
186
array( $context, 'callback_field' ),
187
$option_slug,
188
$section,
@@ -236,7 +236,7 @@ class IP_Geo_Block_Admin_Tab {
236
$field = 'response_code';
237
add_settings_field(
238
$option_name.'_'.$field,
239
- sprintf( __( '<dfn title="You can put your original 403.php and so on into your theme directory.">Response code</dfn> %s', 'ip-geo-block' ), '(<a rel="noreferrer" href="http://tools.ietf.org/html/rfc2616#section-10" title="RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1">RFC 2616</a>)' ),
240
array( $context, 'callback_field' ),
241
$option_slug,
242
$section,
@@ -255,7 +255,6 @@ class IP_Geo_Block_Admin_Tab {
255
403 => '403 Forbidden',
256
404 => '404 Not Found',
257
406 => '406 Not Acceptable',
258
- 410 => '410 Gone',
259
500 => '500 Internal Server Error',
260
503 => '503 Service Unavailable',
261
),
@@ -343,7 +342,7 @@ class IP_Geo_Block_Admin_Tab {
343
),
344
'desc' => array(
345
0 => __( 'Validate at &#8220;init&#8221; action hook in the same manner as typical plugins.', 'ip-geo-block' ),
346
- 1 => __( 'Validate at an earlier phase than other typical plugins. It can reduce load on server but has <a rel=\'noreferrer\' href=\'http://www.ipgeoblock.com/codex/validation-timing.html\' title=\'Validation timing | IP Geo Block\'>some restrictions</a>.', 'ip-geo-block' ),
347
),
348
'after' => '<div class="ip-geo-block-desc"></div>',
349
)
@@ -363,12 +362,12 @@ class IP_Geo_Block_Admin_Tab {
363
// same as in tab-accesslog.php
364
$dfn = __( '<dfn title="Validate request to %s.">%s</dfn>', 'ip-geo-block' );
365
$target = array(
366
- 'comment' => sprintf( $dfn, 'wp-comments-post.php', __( 'Comment post', 'ip-geo-block' ) ),
367
- 'xmlrpc' => sprintf( $dfn, 'xmlrpc.php', __( 'XML-RPC', 'ip-geo-block' ) ),
368
- 'login' => sprintf( $dfn, 'wp-login.php', __( 'Login form', 'ip-geo-block' ) ),
369
- 'admin' => sprintf( $dfn, 'wp-admin/*.php', __( 'Admin area', 'ip-geo-block' ) ),
370
- 'others' => sprintf( $dfn, 'executable files', __( 'Other areas', 'ip-geo-block' ) ),
371
- 'public' => sprintf( $dfn, __( 'public facing pages', 'ip-geo-block' ), __( 'Public facing pages', 'ip-geo-block' ) ),
372
);
373
374
// Comment post
@@ -498,7 +497,7 @@ if ( defined( 'IP_GEO_BLOCK_DEBUG' ) && IP_GEO_BLOCK_DEBUG ):
498
$key = 'admin';
499
add_settings_field(
500
$option_name.'_exception_'.$key,
501
- __( '<dfn title="Same effect as &#8220;ip-geo-block-bypass-admins&#8221; filter hook.">Exception for admin action and page</dfn>', 'ip-geo-block' ),
502
array( $context, 'callback_field' ),
503
$option_slug,
504
$section,
@@ -508,7 +507,6 @@ if ( defined( 'IP_GEO_BLOCK_DEBUG' ) && IP_GEO_BLOCK_DEBUG ):
508
'field' => 'exception',
509
'sub-field' => $key,
510
'value' => implode( ',', $options['exception'][ $key ] ),
511
- 'after' => $comma[0],
512
)
513
);
514
endif;
@@ -516,7 +514,7 @@ endif;
516
array_unshift( $list, __( 'Disable', 'ip-geo-block' ) );
517
$desc = array(
518
__( 'Regardless of the country code, it will block a malicious request to <code>%s&hellip;/*.php</code>.', 'ip-geo-block' ),
519
- __( 'It configures &#8220;%s&#8221; to validate a request to the PHP file which does not load WordPress core.', 'ip-geo-block' ),
520
__( '<dfn title="Select the item which causes undesired blocking in order to exclude from the validation target. Grayed item indicates &#8220;INACTIVE&#8221;.">Exceptions</dfn>', 'ip-geo-block' ),
521
);
522
@@ -834,7 +832,7 @@ endif;
834
$key = 'simulate';
835
add_settings_field(
836
$option_name.'_'.$field.'_'.$key,
837
- '<dfn title="' . __( 'It enables to simulate validation without deployment. The results can be found at &#8220;Public facing pages&#8221; in Logs.', 'ip-geo-block' ) . '">' . __( 'Simulation mode', 'ip-geo-block' ) . '</dfn>',
838
array( $context, 'callback_field' ),
839
$option_slug,
840
$section,
@@ -884,7 +882,7 @@ endif;
884
if ( empty( $providers ) ) {
885
$context->add_admin_notice( 'error',
886
sprintf(
887
- __( 'Please download <a rel="noreferrer" href="https://github.com/tokkonopapa/WordPress-IP-Geo-API/archive/master.zip" title="Download the contents of tokkonopapa/WordPress-IP-Geo-API as a zip file">ZIP file</a> from <a rel="noreferrer" href="https://github.com/tokkonopapa/WordPress-IP-Geo-API" title="tokkonopapa/WordPress-IP-Geo-API - GitHub">WordPress-IP-Geo-API</a> and upload <code>ip-geo-api</code> to <code>%s</code> with write permission.', 'ip-geo-block' ),
888
apply_filters( 'ip-geo-block-api-dir', basename( WP_CONTENT_DIR ) )
889
)
890
);
@@ -1245,27 +1243,11 @@ endif;
1245
'type' => 'none',
1246
'before' =>
1247
'<a class="button button-secondary" id="ip-geo-block-default" title="' . __( 'Import the default settings to revert to the &#8220;Right after installing&#8221; state', 'ip-geo-block' ) . '" href="javascript:void(0)">' . __( 'Default settings', 'ip-geo-block' ) . '</a>&nbsp;' .
1248
- '<a class="button button-secondary" id="ip-geo-block-preferred" title="' . __( 'Import the preferred settings mainly for the &#8220;Validation target settings&#8221;', 'ip-geo-block' ) . '" href="javascript:void(0)">' . __( 'Best settings', 'ip-geo-block' ) . '</a>',
1249
'after' => '<div id="ip-geo-block-pre-defined"></div>',
1250
)
1251
);
1252
1253
- // Show WordPress installation info
1254
- $field = 'show-info';
1255
- add_settings_field(
1256
- $option_name.'_'.$field,
1257
- __( '<dfn title="Please copy &amp; paste when submitting your issue to support forum.">Installation information</dfn><br />[ <a rel="noreferrer" href="https://wordpress.org/support/plugin/ip-geo-block" title="WordPress &#8250; Support &raquo; IP Geo Block">support forum</a> ]', 'ip-geo-block' ),
1258
- array( $context, 'callback_field' ),
1259
- $option_slug,
1260
- $section,
1261
- array(
1262
- 'type' => 'none',
1263
- 'before' =>
1264
- '<a class="button button-secondary" id="ip-geo-block-show-info" title="' . __( 'Show PHP, WordPress, theme and plugins information.', 'ip-geo-block' ) . '" href="javascript:void(0)">' . __( 'Show information', 'ip-geo-block' ) . '</a>&nbsp;',
1265
- 'after' => '<div id="ip-geo-block-wp-info"></div>',
1266
- )
1267
- );
1268
-
1269
if ( defined( 'IP_GEO_BLOCK_DEBUG' ) && IP_GEO_BLOCK_DEBUG ):
1270
// Manipulate DB table for validation logs
1271
$field = 'delete_table';
@@ -1310,8 +1292,8 @@ endif;
1310
public static function note_target() {
1311
echo
1312
'<ul class="ip-geo-block-note">', "\n",
1313
- '<li>', __( 'To enhance the protection ability, please refer to &#8220;<a rel="noreferrer" href="http://www.ipgeoblock.com/codex/the-best-practice-for-target-settings.html" title="The best practice for target settings | IP Geo Block">The best practice for target settings</a>&#8221;.', 'ip-geo-block' ), '</li>', "\n",
1314
- '<li>', __( 'If you have any troubles with these, please check FAQ at <a rel="noreferrer" href="https://wordpress.org/plugins/ip-geo-block/faq/" title="IP Geo Block &mdash; WordPress Plugins">WordPress.org</a> and <a rel="noreferrer" href="http://www.ipgeoblock.com/codex/#faq" title="Codex | IP Geo Block">Codex</a>.', 'ip-geo-block' ), '</li>', "\n",
1315
'</ul>', "\n";
1316
}
1317
@@ -1326,8 +1308,8 @@ endif;
1326
public static function note_public() {
1327
echo
1328
'<ul class="ip-geo-block-note">', "\n",
1329
- '<li>', __( 'Please refer to the document &#8220;<a rel="noreferrer" href="http://www.ipgeoblock.com/codex/#blocking-on-front-end" title="Codex | IP Geo Block">Blocking on front-end</a>&#8221; for details, including restrictions on cache plugin.', 'ip-geo-block' ), '</li>', "\n",
1330
- '<li>', __( 'If you find any issues or have something to suggest, please feel free to open an issue at <a rel="noreferrer" href="https://wordpress.org/support/plugin/ip-geo-block" title="WordPress &#8250; Support &raquo; IP Geo Block">support forum</a>.', 'ip-geo-block' ), '</li>', "\n",
1331
'</ul>', "\n";
1332
}
1333
1
<?php
2
+ require_once( IP_GEO_BLOCK_PATH . 'classes/class-ip-geo-block-opts.php' );
3
+ require_once( IP_GEO_BLOCK_PATH . 'admin/includes/class-admin-rewrite.php' );
4
5
if ( ! function_exists( 'get_plugins' ) )
6
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
7
8
class IP_Geo_Block_Admin_Tab {
9
91
92
$rule_desc = array(
93
__( 'Please select either &#8220;Whitelist&#8221; or &#8220;Blacklist&#8221;.', 'ip-geo-block' ),
94
+ __( '<dfn title="&#8220;Block by country&#8221; will be bypassed in case of empty. All the countries will be blocked in case you put &#8220;XX&#8221; only.">Whitelist of country code</dfn>', 'ip-geo-block' ) . '<br/>(<a class="ip-geo-block-link" href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements" title="ISO 3166-1 alpha-2 - Wikipedia, the free encyclopedia" target=_blank>ISO 3166-1 alpha-2</a>)',
95
+ __( '<dfn title="&#8220;Block by country&#8221; will be bypassed in case of empty. Please consider to include &#8220;ZZ&#8221; which means UNKNOWN country.">Blacklist of country code</dfn>', 'ip-geo-block' ) . '<br/>(<a class="ip-geo-block-link" href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements" title="ISO 3166-1 alpha-2 - Wikipedia, the free encyclopedia" target=_blank>ISO 3166-1 alpha-2</a>)',
96
);
97
98
$comma = array(
163
add_settings_field(
164
$option_name.'_'.$field.'_'.$key,
165
__( '<dfn title="e.g. &#8220;192.0.64.0/18&#8221; for Jetpack server, &#8220;69.46.36.0/27&#8221; for WordFence server">Whitelist of extra IP addresses prior to country code</dfn>', 'ip-geo-block' ) .
166
+ ' (<a class="ip-geo-block-link" href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" title="Classless Inter-Domain Routing - Wikipedia, the free encyclopedia" target=_blank>CIDR</a>)',
167
array( $context, 'callback_field' ),
168
$option_slug,
169
$section,
182
add_settings_field(
183
$option_name.'_'.$field.'_'.$key,
184
__( '<dfn title="Server level access control is recommended (e.g. .htaccess).">Blacklist of extra IP addresses prior to country code</dfn>', 'ip-geo-block' ) .
185
+ ' (<a class="ip-geo-block-link" href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" title="Classless Inter-Domain Routing - Wikipedia, the free encyclopedia" target=_blank>CIDR</a>)',
186
array( $context, 'callback_field' ),
187
$option_slug,
188
$section,
236
$field = 'response_code';
237
add_settings_field(
238
$option_name.'_'.$field,
239
+ sprintf( __( '<dfn title="You can put your original 403.php and so on into your theme directory.">Response code</dfn> %s', 'ip-geo-block' ), '(<a class="ip-geo-block-link" href="http://tools.ietf.org/html/rfc2616#section-10" title="RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1" target=_blank>RFC 2616</a>)' ),
240
array( $context, 'callback_field' ),
241
$option_slug,
242
$section,
255
403 => '403 Forbidden',
256
404 => '404 Not Found',
257
406 => '406 Not Acceptable',
258
500 => '500 Internal Server Error',
259
503 => '503 Service Unavailable',
260
),
342
),
343
'desc' => array(
344
0 => __( 'Validate at &#8220;init&#8221; action hook in the same manner as typical plugins.', 'ip-geo-block' ),
345
+ 1 => __( 'Validate at an earlier phase than other typical plugins. It can reduce load on server but has <a href=\'http://www.ipgeoblock.com/codex/validation-timing.html\' title=\'Validation timing | IP Geo Block\'>some restrictions</a>.', 'ip-geo-block' ),
346
),
347
'after' => '<div class="ip-geo-block-desc"></div>',
348
)
362
// same as in tab-accesslog.php
363
$dfn = __( '<dfn title="Validate request to %s.">%s</dfn>', 'ip-geo-block' );
364
$target = array(
365
+ 'comment' => sprintf( $dfn, 'wp-comments-post.php', __( 'Comment post', 'ip-geo-block' ) ),
366
+ 'xmlrpc' => sprintf( $dfn, 'xmlrpc.php', __( 'XML-RPC', 'ip-geo-block' ) ),
367
+ 'login' => sprintf( $dfn, 'wp-login.php', __( 'Login form', 'ip-geo-block' ) ),
368
+ 'admin' => sprintf( $dfn, 'wp-admin/*.php', __( 'Admin area', 'ip-geo-block' ) ),
369
+ 'others' => sprintf( $dfn, 'executable files', __( 'Other areas', 'ip-geo-block' ) ),
370
+ 'public' => sprintf( $dfn, 'public facing pages', __( 'Pubic facing pages', 'ip-geo-block' ) ),
371
);
372
373
// Comment post
497
$key = 'admin';
498
add_settings_field(
499
$option_name.'_exception_'.$key,
500
+ __( 'Exception for admin action and page', 'ip-geo-block' ),
501
array( $context, 'callback_field' ),
502
$option_slug,
503
$section,
507
'field' => 'exception',
508
'sub-field' => $key,
509
'value' => implode( ',', $options['exception'][ $key ] ),
510
)
511
);
512
endif;
514
array_unshift( $list, __( 'Disable', 'ip-geo-block' ) );
515
$desc = array(
516
__( 'Regardless of the country code, it will block a malicious request to <code>%s&hellip;/*.php</code>.', 'ip-geo-block' ),
517
+ __( 'It configures &#8220%s&#8221 to validate a request to the PHP file which does not load WordPress core.', 'ip-geo-block' ),
518
__( '<dfn title="Select the item which causes undesired blocking in order to exclude from the validation target. Grayed item indicates &#8220;INACTIVE&#8221;.">Exceptions</dfn>', 'ip-geo-block' ),
519
);
520
832
$key = 'simulate';
833
add_settings_field(
834
$option_name.'_'.$field.'_'.$key,
835
+ '<dfn title="' . __( 'It enables to simulate validation without deployment. The results can be found at &#8220;Pubic facing pages&#8221; in Logs.', 'ip-geo-block' ) . '">' . __( 'Simulation mode', 'ip-geo-block' ) . '</dfn>',
836
array( $context, 'callback_field' ),
837
$option_slug,
838
$section,
882
if ( empty( $providers ) ) {
883
$context->add_admin_notice( 'error',
884
sprintf(
885
+ __( 'Please download <a href="https://github.com/tokkonopapa/WordPress-IP-Geo-API/archive/master.zip" title="Download the contents of tokkonopapa/WordPress-IP-Geo-API as a zip file">ZIP file</a> from <a href="https://github.com/tokkonopapa/WordPress-IP-Geo-API" title="tokkonopapa/WordPress-IP-Geo-API - GitHub">WordPress-IP-Geo-API</a> and upload <code>ip-geo-api</code> to <code>%s</code> with write permission.', 'ip-geo-block' ),
886
apply_filters( 'ip-geo-block-api-dir', basename( WP_CONTENT_DIR ) )
887
)
888
);
1243
'type' => 'none',
1244
'before' =>
1245
'<a class="button button-secondary" id="ip-geo-block-default" title="' . __( 'Import the default settings to revert to the &#8220;Right after installing&#8221; state', 'ip-geo-block' ) . '" href="javascript:void(0)">' . __( 'Default settings', 'ip-geo-block' ) . '</a>&nbsp;' .
1246
+ '<a class="button button-secondary" id="ip-geo-block-preferred" title="' . __( 'Import the preferred settings mainly for the &#8220;Validation target settings&#8221;', 'ip-geo-block' ) . '" href="javascript:void(0)">' . __( 'Best practice', 'ip-geo-block' ) . '</a>',
1247
'after' => '<div id="ip-geo-block-pre-defined"></div>',
1248
)
1249
);
1250
1251
if ( defined( 'IP_GEO_BLOCK_DEBUG' ) && IP_GEO_BLOCK_DEBUG ):
1252
// Manipulate DB table for validation logs
1253
$field = 'delete_table';
1292
public static function note_target() {
1293
echo
1294
'<ul class="ip-geo-block-note">', "\n",
1295
+ '<li>', __( 'To enhance the protection ability, please refer to &#8220;<a href="http://www.ipgeoblock.com/codex/the-best-practice-of-target-settings.html" title="The best practice of target settings | IP Geo Block">The best practice of target settings</a>&#8221;.', 'ip-geo-block' ), '</li>', "\n",
1296
+ '<li>', __( 'If you have any troubles with these, please open an issue at <a class="ip-geo-block-link" href="http://wordpress.org/support/plugin/ip-geo-block" title="WordPress &#8250; Support &raquo; IP Geo Block" target=_blank>support forum</a>.', 'ip-geo-block' ), '</li>', "\n",
1297
'</ul>', "\n";
1298
}
1299
1308
public static function note_public() {
1309
echo
1310
'<ul class="ip-geo-block-note">', "\n",
1311
+ '<li>', __( 'Please refer to the document &#8220;<a href="http://www.ipgeoblock.com/codex/#blocking-on-front-end" title="Codex | IP Geo Block" target=_blank>Blocking on front-end</a>&#8221; for details, including restrictions on cache plugin.', 'ip-geo-block' ), '</li>', "\n",
1312
+ '<li>', __( 'If you find any issues or have something to suggest, please feel free to open an issue at <a class="ip-geo-block-link" href="http://wordpress.org/support/plugin/ip-geo-block" title="WordPress &#8250; Support &raquo; IP Geo Block" target=_blank>support forum</a>.', 'ip-geo-block' ), '</li>', "\n",
1313
'</ul>', "\n";
1314
}
1315
admin/js/admin.js CHANGED
@@ -17,7 +17,7 @@ var ip_geo_block_time = new Date();
17
'#x27;: 'ip-geo-block-',
18
'%': 'ip_geo_block_'
19
};
20
- return 'undefined' !== typeof id ? keys[selector] + id : keys.$ + selector;
21
}
22
23
function sanitize(str) {
@@ -47,7 +47,7 @@ var ip_geo_block_time = new Date();
47
}
48
49
function warning(status, msg) {
50
- window.alert(status ? sanitize(status + ': ' + msg) : sanitize(msg));
51
}
52
53
function notice_html5() {
@@ -348,42 +348,6 @@ var ip_geo_block_time = new Date();
348
}
349
};
350
351
- // google chart
352
- function drawChart() {
353
- if ($(ID('#', 'chart-countries')).length) {
354
- chart.drawChart();
355
- }
356
- }
357
-
358
- // Load / Save cookie using wpCookies in wp-includes/js/utils.js
359
- function loadCookie(id) {
360
- return ('undefined' !== typeof wpCookies && wpCookies.getHash(ID('#x27;, id))) || {};
361
- }
362
-
363
- // setHash( name, value, expires, path, domain, secure )
364
- function saveCookie(id, cookie) {
365
- if ('undefined' !== typeof wpCookies) {
366
- var path = 'undefined' !== typeof IP_GEO_BLOCK_AUTH ? IP_GEO_BLOCK_AUTH.home + IP_GEO_BLOCK_AUTH.admin : '';
367
- wpCookies.setHash(ID('#x27;, id), cookie, new Date(Date.now() + 2592000000), path);
368
- }
369
- }
370
-
371
- // Click event handler to show/hide form-table
372
- function toggleSection(title, id, cookie) {
373
- var index = title.closest('fieldset').data('ip-geo-block');
374
-
375
- // Show/Hide
376
- title.parent().nextAll().toggle();
377
- title.toggleClass(ID('dropup')).toggleClass(ID('dropdown'));
378
-
379
- cookie[index] = title.hasClass(ID('dropdown')) ? 'o' : 'x';
380
- saveCookie(id, cookie); // Save cookie
381
-
382
- // redraw google chart
383
- drawChart();
384
- }
385
-
386
- // form for export / import
387
function add_hidden_form(cmd) {
388
$('body').append(
389
'<div style="display:none">' +
@@ -400,13 +364,19 @@ var ip_geo_block_time = new Date();
400
}
401
402
$(function () {
403
// Make form style with fieldset and legend
404
var fieldset = $('<fieldset class="' + ID('field') + '"></fieldset>'),
405
- legend = $('<legend></legend>'),
406
-
407
- // Get tab number and cookie
408
- tabNo = Number(IP_GEO_BLOCK.tab) || 0,
409
- cookie = loadCookie(tabNo);
410
411
$('.form-table').each(function (index) {
412
var $this = $(this),
@@ -422,7 +392,8 @@ var ip_geo_block_time = new Date();
422
423
// Initialize show/hide form-table on tab 0, 1
424
if (tabNo <= 1) {
425
- if ('undefined' === typeof cookie[index] || 'o' === cookie[index]) { // 'undefined', 'x' or 'o'
426
title.addClass(ID('dropdown')).parent().nextAll().show();
427
} else {
428
title.addClass(ID('dropup')).parent().nextAll().hide();
@@ -430,10 +401,34 @@ var ip_geo_block_time = new Date();
430
}
431
});
432
433
// Click event handler to show/hide form-table
434
if (tabNo <= 1) {
435
$('form').on('click', 'h2,h3', function (event) {
436
- toggleSection($(this), tabNo, cookie);
437
return false;
438
});
439
@@ -453,11 +448,13 @@ var ip_geo_block_time = new Date();
453
$this.parent().nextAll().toggle(n ? false : true);
454
$this.removeClass(id.join(' '))
455
.addClass(n ? id[1] : id[0]);
456
- cookie[i] = n ? 'x' : 'o';
457
});
458
459
// Save cookie
460
- saveCookie(tabNo, cookie);
461
462
// redraw google chart
463
drawChart();
@@ -701,29 +698,6 @@ var ip_geo_block_time = new Date();
701
}
702
}).trigger('change');
703
704
- // Show WordPress installation info
705
- $(ID('#', 'show-info')).on('click', function (event) {
706
- $(ID('#', 'wp-info')).empty();
707
- ajax_post('wp-info', {
708
- cmd: 'show-info'
709
- }, function (data) {
710
- var key, val, res = [];
711
- for (key in data) {
712
- if (data.hasOwnProperty(key)) {
713
- for (val in data[key]) {
714
- if (data[key].hasOwnProperty(val)) {
715
- res.push('- ' + val + ' ' + data[key][val]);
716
- }
717
- }
718
- }
719
- }
720
-
721
- // response should be escaped at server side
722
- $(ID('#', 'wp-info')).html('<textarea rows="' + res.length + '">' + /*sanitize*/(res.join("\n")) + '</textarea>').find('textarea').select();
723
- return false;
724
- });
725
- });
726
-
727
// Submit
728
$('#submit').on('click', function (event) {
729
var elm = $(ID('@', 'signature')),
@@ -898,7 +872,7 @@ var ip_geo_block_time = new Date();
898
ajax_post('logs', {
899
cmd: 'restore',
900
which: null,
901
- time: new Date() - ip_geo_block_time
902
}, function (data) {
903
var key;
904
for (key in data) {
@@ -938,7 +912,7 @@ var ip_geo_block_time = new Date();
938
// Export / Import settings
939
add_hidden_form('export-logs');
940
941
- // Export logs
942
$(ID('#', 'export-logs')).on('click', function (event) {
943
$(ID('#', 'export-form')).trigger('submit');
944
return false;
17
'#x27;: 'ip-geo-block-',
18
'%': 'ip_geo_block_'
19
};
20
+ return id ? keys[selector] + id : keys.$ + selector;
21
}
22
23
function sanitize(str) {
47
}
48
49
function warning(status, msg) {
50
+ window.alert(status ? sanitize(status + ': ' + msg) : msg);
51
}
52
53
function notice_html5() {
348
}
349
};
350
351
function add_hidden_form(cmd) {
352
$('body').append(
353
'<div style="display:none">' +
364
}
365
366
$(function () {
367
+ // processing time for the browser's performance
368
+ ip_geo_block_time = new Date() - ip_geo_block_time;
369
+
370
+ // Get tab number and check wpCookies in wp-includes/js/utils.js
371
+ var cookie = ('undefined' !== typeof wpCookies && wpCookies.getHash(ID('%', 'admin'))) || {},
372
+ tabIndex = [0, 9, 10],
373
+ tabNo = /&tab=(\d)/.exec(window.location.href);
374
+
375
+ tabNo = Number(tabNo && tabNo[1]);
376
+
377
// Make form style with fieldset and legend
378
var fieldset = $('<fieldset class="' + ID('field') + '"></fieldset>'),
379
+ legend = $('<legend></legend>');
380
381
$('.form-table').each(function (index) {
382
var $this = $(this),
392
393
// Initialize show/hide form-table on tab 0, 1
394
if (tabNo <= 1) {
395
+ index += tabIndex[tabNo];
396
+ if ('undefined' === typeof cookie[index] || cookie[index]) { // 'undefined' or 'o'
397
title.addClass(ID('dropdown')).parent().nextAll().show();
398
} else {
399
title.addClass(ID('dropup')).parent().nextAll().hide();
401
}
402
});
403
404
+ var drawChart = function () {
405
+ if ($(ID('#', 'chart-countries')).length) {
406
+ chart.drawChart();
407
+ }
408
+ };
409
+
410
+ // Click event handler to show/hide form-table
411
+ var toggle_section = function (title) {
412
+ var index = title.closest('fieldset').data('ip-geo-block');
413
+
414
+ // Show/Hide
415
+ title.parent().nextAll().toggle();
416
+ title.toggleClass(ID('dropup')).toggleClass(ID('dropdown'));
417
+
418
+ // Save cookie
419
+ if ('undefined' !== typeof wpCookies) {
420
+ cookie[index + tabIndex[tabNo]] = title.hasClass(ID('dropdown')) ? 'o' : '';
421
+ wpCookies.setHash(ID('%', 'admin'), cookie, new Date(Date.now() + 2592000000));
422
+ }
423
+
424
+ // redraw google chart
425
+ drawChart();
426
+ };
427
+
428
// Click event handler to show/hide form-table
429
if (tabNo <= 1) {
430
$('form').on('click', 'h2,h3', function (event) {
431
+ toggle_section($(this));
432
return false;
433
});
434
448
$this.parent().nextAll().toggle(n ? false : true);
449
$this.removeClass(id.join(' '))
450
.addClass(n ? id[1] : id[0]);
451
+ cookie[i + tabIndex[tabNo]] = n ? '' : 'o';
452
});
453
454
// Save cookie
455
+ if ('undefined' !== typeof wpCookies) {
456
+ wpCookies.setHash(ID('%', 'admin'), cookie, new Date(Date.now() + 2592000000));
457
+ }
458
459
// redraw google chart
460
drawChart();
698
}
699
}).trigger('change');
700
701
// Submit
702
$('#submit').on('click', function (event) {
703
var elm = $(ID('@', 'signature')),
872
ajax_post('logs', {
873
cmd: 'restore',
874
which: null,
875
+ time: ip_geo_block_time
876
}, function (data) {
877
var key;
878
for (key in data) {
912
// Export / Import settings
913
add_hidden_form('export-logs');
914
915
+ // Export settings
916
$(ID('#', 'export-logs')).on('click', function (event) {
917
$(ID('#', 'export-form')).trigger('submit');
918
return false;
admin/js/admin.min.js CHANGED
@@ -3,4 +3,4 @@
3
Copyright (c) 2015-2016 tokkonopapa (tokkonopapa@yahoo.com)
4
This software is released under the MIT License.
5
*/
6
- var ip_geo_block_time=new Date;(function(a,l,C){function b(a,b){var c={".":".ip-geo-block-","#":"#ip-geo-block-","@":"#ip_geo_block_settings_",$:"ip-geo-block-","%":"ip_geo_block_"};return"undefined"!==typeof b?c[a]+b:c.$+a}function h(a){return a?a.toString().replace(/[&<>"']/g,function(a){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[a]}):""}function x(c,f){f?a(b("#",c)).addClass(b("loading")):a(b("#",c)).removeClass(b("loading"))}function q(a,b){l.confirm(h(a))&&b()}function v(a,b){l.alert(a?h(a+": "+b):h(b))}function y(a,b){if(-1!==location.href.indexOf(a)){var c=h(a)+(b?"&"+h(b):"");"undefined"===typeof IP_GEO_BLOCK_ZEP?l.location.href=c:IP_GEO_BLOCK_ZEP.redirect(c)}}function p(b,f,m,g){b&&x(b,!0);f.action=IP_GEO_BLOCK.action;f.nonce=IP_GEO_BLOCK.nonce;a.post(IP_GEO_BLOCK.url,f).done(function(a,b,d){m(a)}).fail(function(a,b,d){v(b,a.responseText)}).always(function(){b&&(g?a.when.apply(a,g).then(function(){x(b,!1)}):x(b,!1))})}function z(a,b){p(a,{cmd:"clear-"+a,which:b},function(a){y(a.page,a.tab)})}function D(a){p(a,{cmd:a},function(a){y(a.page,a.tab)})}function A(c,f,m,g){var k=!1,k=k|(0===c.prop("type").indexOf("checkbox")&&c.is(":checked")),k=k|(0===c.prop("type").indexOf("select")&&"0"!==c.val());f.nextAll("."+m+"_folding").each(function(c,d){d=a(d);k&&g?d.removeClass("folding-disable"):(d.children("li").hide(),d.addClass("folding-disable"),d.removeClass(b("dropdown")).addClass(b("dropup")))})}function u(a){return String(a).replace(/[a-z]/gi,function(a){return String.fromCharCode(a.charCodeAt(0)+("n">a.toLowerCase()?13:-13))})}function J(a,b){var c=new FileReader;c.onload=function(a){b&&b(a.target.result)};c.onerror=function(a){v("Error",a.target.error.code)};c.readAsText(a)}function E(c){var f=b("%","settings"),m=c.is(":checked"),g=a(b("@","public_target_rule")),k=c.closest("tr").nextAll("tr");k.find('[name^="'+f+'"]').prop("disabled",!m);k.find(b(".","desc")).css("opacity",m?1:.5);A(c,g,f,"1"===g.val()?!0:!1)}function B(c){if(c){"string"===typeof c&&(c=JSON.parse(c));a(b("#","import")).closest("form").deserialize(c);a.each(["matching_rule","validation_login","validation_plugins","validation_themes"],function(c,g){a(b("@",g)).trigger("change")});E(a(b("@","validation_public")));var f=b("%","settings[providers][IPInfoDB]");a(b("@","providers_IPInfoDB")).prop("checked",c[f]?!0:!1)}}function F(){a(b("#","chart-countries")).length&&G.drawChart()}function H(a,f){if("undefined"!==typeof wpCookies){var c="undefined"!==typeof IP_GEO_BLOCK_AUTH?IP_GEO_BLOCK_AUTH.home+IP_GEO_BLOCK_AUTH.admin:"";wpCookies.setHash(b("quot;,a),f,new Date(Date.now()+2592E6),c)}}function I(c){a("body").append('<div style="display:none"><form method="POST" id="'+b("export-form")+'" action="'+IP_GEO_BLOCK.url.replace("ajax.php","post.php")+'"><input type="hidden" name="action" value="'+IP_GEO_BLOCK.action+'" /><input type="hidden" name="nonce" value="'+IP_GEO_BLOCK.nonce+'" /><input type="hidden" name="cmd" value="'+c+'" /><input type="hidden" name="data" value="" id="'+b("export-data")+'"/><input type="submit" value="submit" /></form><input type="file" name="settings" id="'+b("file-dialog")+'" /></div>')}a.fn.deserialize=function(b,f){return this.each(function(){var c,g,f,h=this,d={};for(c in b)b.hasOwnProperty(c)&&(g=decodeURIComponent(c),f=decodeURIComponent(b[c]),g in d||(d[g]=[]),d[g].push(f));a.each(d,function(b,d){a('[name="'+b+'"]:input',h).val(d)})})};var G={self:this,drawChart:function(){this.drawPie();this.drawLine()},dataPie:null,viewPie:null,drawPie:function(){if(!self.dataPie){self.dataPie=new google.visualization.DataTable;self.dataPie.addColumn("string","Country");self.dataPie.addColumn("number","Requests");var c;a(b("#","countries li")).each(function(){c=a(this).text().split(":");self.dataPie.addRow([c[0]||"",Number(c[1])])})}self.viewPie||(self.viewPie=new google.visualization.PieChart(C.getElementById(b("chart-countries"))));a(b("#","chart-countries")).width()&&self.viewPie.draw(self.dataPie,{backgroundColor:"#f1f1f1",chartArea:{left:0,top:"5%",width:"100%",height:"90%"},sliceVisibilityThreshold:.015})},dataLine:null,viewLine:null,drawLine:function(){if(!self.dataLine){self.dataLine=new google.visualization.DataTable;self.dataLine.addColumn("date","Date");self.dataLine.addColumn("number","comment");self.dataLine.addColumn("number","xmlrpc");self.dataLine.addColumn("number","login");self.dataLine.addColumn("number","admin");self.dataLine.addColumn("number","public");var c,f,h,g,k,l,d=[],e=a(b("#","targets tr"));g=e.length;for(c=0;c<g;c++)for(d[c]=[],l=e.eq(c).children(),k=l.length,f=0;f<k;f++)h=l.eq(f).text(),d[c].push(f?Number(h):new Date(h));self.dataLine.addRows(d)}self.viewLine||(self.viewLine=new google.visualization.LineChart(C.getElementById(b("chart-daily"))));if(c=a(b("#","chart-daily")).width())c=320<c?!0:!1,self.viewLine.draw(self.dataLine,{backgroundColor:"#f1f1f1",legend:{position:"bottom"},hAxis:{format:"MM/dd"},vAxis:{textPosition:c?"out":"in"},chartArea:{left:c?"10%":0,top:"5%",width:"100%",height:"75%"}})}};a(function(){var c=a('<fieldset class="'+b("field")+'"></fieldset>'),f=a("<legend></legend>"),m=Number(IP_GEO_BLOCK.tab)||0,g="undefined"!==typeof wpCookies&&wpCookies.getHash(b("quot;,m))||{};a(".form-table").each(function(d){var e=a(this),n=e.prevAll("h2,h3:first"),t=n.nextUntil(e);e.wrap(c).parent().attr("id",b("settings-"+d)).data("ip-geo-block",d).prepend(n.wrap(f).parent());t.insertBefore(e);1>=m&&("undefined"===typeof g[d]||"o"===g[d]?n.addClass(b("dropdown")).parent().nextAll().show():n.addClass(b("dropup")).parent().nextAll().hide())});1>=m&&(a("form").on("click","h2,h3",function(d){d=a(this);var e=d.closest("fieldset").data("ip-geo-block");d.parent().nextAll().toggle();d.toggleClass(b("dropup")).toggleClass(b("dropdown"));g[e]=d.hasClass(b("dropdown"))?"o":"x";H(m,g);F();return!1}),a(b("#","toggle-sections")).on("click",function(d){var e,c=0,t=[b("dropdown"),b("dropup")];d=a(b(".","field")).find("h2,h3");d.each(function(b){c+=a(this).hasClass(t[0])});d.each(function(b){e=a(this);e.parent().nextAll().toggle(c?!1:!0);e.removeClass(t.join(" ")).addClass(c?t[1]:t[0]);g[b]=c?"x":"o"});H(m,g);F();return!1}));a(b("#","inhibit")).on("submit",function(){return!1});switch(m){case 0:a(b("#","scan-code")).on("click",function(d){var c=a(this).parent();p("scanning",{cmd:"scan-code"},function(a){c.children("ul").length||c.append('<ul id="'+b("code-list")+'"></ul>');c=c.children("ul").empty();var d,e;for(d in a)a.hasOwnProperty(d)&&(d=h(d),"string"===typeof a[d]?e=h(a[d]):(e=h(a[d].code),d='<abbr title="'+h(a[d].type)+'">'+d+"</abbr>"),c.append("<li>"+d+' : <span class="'+b("notice")+'">'+e+"</span></li>"));c.show("slow")});return!1});a(b("@","matching_rule")).on("change",function(){a(b("@","white_list")).closest("tr").toggle("0"===this.value);a(b("@","black_list")).closest("tr").toggle("1"===this.value);return!1}).trigger("change");a(b("@","public_matching_rule")).on("change",function(){a(b("@","public_white_list")).closest("tr").toggle("0"===this.value);a(b("@","public_black_list")).closest("tr").toggle("1"===this.value);return!1}).trigger("change");a(b("@","update")).on("click",function(d){p("download",{cmd:"download"},function(d){var c,e,r;for(c in d)if(d.hasOwnProperty(c))for(e in r=d[c],r)r.hasOwnProperty(e)&&(e=h(e),r[e].filename&&a(b("@",c+"_"+e+"_path")).val(h(r[e].filename)),r[e].message&&a(b("#",c+"-"+e)).text(h(r[e].message)))});return!1});var k=b("%","settings");a(b("@","validation_login")).on("change",function(b){b=a(this);A(b,b,k,!0);return!1}).trigger("change");a('select[name^="'+k+'"]').on("change",function(d){d=a(this);var c,n=b(".","desc");d.next(n).empty();(c=d.children("option:selected").data("desc"))&&d.next(n).html(a.parseHTML(c));A(d,d,k,!0);return!1}).trigger("change");a(b("@","validation_public")).on("change",function(b){E(a(this));return!1}).trigger("change");I("validate");a(b("#","export")).on("click",function(d){if("undefined"===typeof JSON)return v(null,IP_GEO_BLOCK.msg[6]),!1;var c=k,n={};a.each(a(this).closest("form").serializeArray(),function(a,b){-1!==b.name.indexOf(c)&&(n[b.name]=b.value)});n[c+="[signature]"]=l.btoa(u(n[c]));a(b("#","export-data")).val(JSON.stringify(n));a(b("#","export-form")).trigger("submit");return!1});a(b("#","file-dialog")).on("change",function(a){if("undefined"===typeof FileReader)return v(null,IP_GEO_BLOCK.msg[6]),!1;var b;(a=a.target.files[0])&&J(a,function(a){a=JSON.parse(a);b=k+"[signature]";"undefined"!==typeof a[b]&&(a[b]=l.btoa(u(a[b])));p("export-import",{cmd:"validate",data:JSON.stringify(a)},B)});return!1});a(b("#","import")).on("click",function(d){a(b("#","file-dialog")).trigger("click");return!1});a(b("#","default")).on("click",function(a){q(IP_GEO_BLOCK.msg[0],function(){p("pre-defined",{cmd:"import-default"},B)});return!1});a(b("#","preferred")).on("click",function(a){q(IP_GEO_BLOCK.msg[0],function(){p("pre-defined",{cmd:"import-preferred"},B)});return!1});a(b("@","create_table")).on("click",function(a){q(IP_GEO_BLOCK.msg[1],function(){D("create-table")});return!1});a(b("@","delete_table")).on("click",function(a){q(IP_GEO_BLOCK.msg[2],function(){D("delete-table")});return!1});a("ul."+k+"_folding dfn").on("click",function(d){d=a(this).parent();d.children("li").toggle();d.toggleClass(b("dropup")).toggleClass(b("dropdown"));return!1});a(b("#","decode")).on("click",function(d){d=a(b("@","signature"));var c=d.val();-1===c.search(/,/)?d.val(u(l.atob(c))):d.val(l.btoa(u(c)));return!1});a(b("@","response_code")).on("change",function(b){b=parseInt(a(this).val()/100,10);var d=a(this).closest("tr").nextAll("tr");3>=b?d.each(function(b){0===b?a(this).show():1===b&&a(this).hide()}):d.each(function(b){0===b?a(this).hide():1===b&&a(this).show()})}).trigger("change");a(b("#","show-info")).on("click",function(d){a(b("#","wp-info")).empty();p("wp-info",{cmd:"show-info"},function(d){var c,e,f=[];for(c in d)if(d.hasOwnProperty(c))for(e in d[c])d[c].hasOwnProperty(e)&&f.push("- "+e+" "+d[c][e]);a(b("#","wp-info")).html('<textarea rows="'+f.length+'">'+f.join("\n")+"</textarea>").find("textarea").select();return!1})});a("#submit").on("click",function(d){d=a(b("@","signature"));var c=d.val();-1!==c.search(/,/)&&d.val(l.btoa(u(c)));return!0});break;case 1:a(b("#","chart-countries")).length&&"object"===typeof google&&google.load("visualization","1",{packages:["corechart"],callback:function(){G.drawChart()}});a(b("@","clear_statistics")).on("click",function(a){q(IP_GEO_BLOCK.msg[3],function(){z("statistics",null)});return!1});a(b("@","clear_cache")).on("click",function(a){q(IP_GEO_BLOCK.msg[4],function(){z("cache",null)});return!1});break;case 2:a(l).on(b("gmap-error"),function(){p(null,{cmd:"gmap-error"},function(a){y(a.page,a.tab)})});var w=a(b("#","map"));"object"===typeof google?w.each(function(){a(this).GmapRS()}):w.each(function(){a(this).empty().html('<iframe src="//maps.google.com/maps?output=embed" frameborder="0" style="width:100%; height:400px; border:0" allowfullscreen></iframe>')});a(b("@","get_location")).on("click",function(c){var d=a(b("#","whois")),f=a(b("@","ip_address")).val();f&&(d.hide().empty(),c=a.whois(f,function(c){var e,f="";for(e=0;e<c.length;e++)f+="<tr><td>"+c[e].name+"</td><td>"+c[e].value+"</td></tr>";d.html('<fieldset class="'+b("field")+'"><legend><h2 id="'+b("whois-title")+'" class="'+b("dropdown")+'">Whois</h2></legend><table class="'+b("table")+'">'+f+"</table><fieldset>").fadeIn("slow");a(b("#","whois-title")).on("click",function(c){c=a(this);c.parent().nextAll().toggle();c.toggleClass(b("dropup")).toggleClass(b("dropdown"));return!1})}),p("loading",{cmd:"search",ip:f,which:a(b("@","service")).val()},function(a){var c,d="",e=h(a.latitude||"0"),g=h(a.longitude||"0"),k=a.latitude||a.longitude?8:2;for(c in a)a.hasOwnProperty(c)&&(c=h(c),d+='<li><span class="'+b("title")+'">'+c+' : </span><span class="'+b("result")+'">'+h(a[c])+"</span></li>");"object"===typeof google?w.GmapRS("addMarker",{latitude:e,longitude:g,title:f,content:"<ul>"+d+"</ul>",show:!0,zoom:k}):w.css({height:"600px",backgroundColor:"transparent"}).empty().html('<ul style="margin-top:0; margin-left:1em;"><li><span class="'+b("title")+'">IP address : </span><span class="'+b("result")+'">'+h(f)+"</span></li>"+d+'</ul><iframe src="//maps.google.com/maps?q='+e+","+g+"&z="+k+'&output=embed" frameborder="0" style="width:100%; height:400px; border:0" allowfullscreen></iframe>')},[c]));return!1});a(b("@","ip_address")).val()&&a(b("@","get_location")).trigger("click");break;case 4:a(b(".","log")).hide().length&&p("logs",{cmd:"restore",which:null,time:new Date-ip_geo_block_time},function(c){for(var d in c)c.hasOwnProperty(d)&&(d=h(d),a(b("#","log-"+d)).html(c[d]));"function"===typeof a.fn.footable&&a(b(".","log")).fadeIn("slow").footable();a('tbody[id^="'+b("quot;,"log-")+'"]').on("click","a",function(b){l.open(l.location.href.replace(/tab=\d/,"tab=2")+"&ip="+a(this).text().replace(/[^\w\.\:\*]/,""));return!1})}),a(b("#","reset-filter")).on("click",function(b){a(".footable").trigger("footable_clear_filter");return!1}),a(b("@","clear_logs")).on("click",function(a){q(IP_GEO_BLOCK.msg[5],function(){z("logs",null)});return!1}),I("export-logs"),a(b("#","export-logs")).on("click",function(c){a(b("#","export-form")).trigger("submit");return!1})}})})(jQuery,window,document);
3
Copyright (c) 2015-2016 tokkonopapa (tokkonopapa@yahoo.com)
4
This software is released under the MIT License.
5
*/
6
+ var ip_geo_block_time=new Date;(function(a,h,t){function b(a,b){var c={".":".ip-geo-block-","#":"#ip-geo-block-","@":"#ip_geo_block_settings_",$:"ip-geo-block-","%":"ip_geo_block_"};return b?c[a]+b:c.$+a}function d(a){return a?a.toString().replace(/[&<>"']/g,function(a){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[a]}):""}function u(c,l){l?a(b("#",c)).addClass(b("loading")):a(b("#",c)).removeClass(b("loading"))}function n(a,b){h.confirm(d(a))&&b()}function w(a,b){h.alert(a?d(a+": "+b):b)}function x(a,b){if(-1!==location.href.indexOf(a)){var c=d(a)+(b?"&"+d(b):"");"undefined"===typeof IP_GEO_BLOCK_ZEP?h.location.href=c:IP_GEO_BLOCK_ZEP.redirect(c)}}function m(b,l,f,p){b&&u(b,!0);l.action=IP_GEO_BLOCK.action;l.nonce=IP_GEO_BLOCK.nonce;a.post(IP_GEO_BLOCK.url,l).done(function(a,b,c){f(a)}).fail(function(a,b,c){w(b,a.responseText)}).always(function(){b&&(p?a.when.apply(a,p).then(function(){u(b,!1)}):u(b,!1))})}function y(a,b){m(a,{cmd:"clear-"+a,which:b},function(a){x(a.page,a.tab)})}function B(a){m(a,{cmd:a},function(a){x(a.page,a.tab)})}function z(c,l,f,p){var d=!1,d=d|(0===c.prop("type").indexOf("checkbox")&&c.is(":checked")),d=d|(0===c.prop("type").indexOf("select")&&"0"!==c.val());l.nextAll("."+f+"_folding").each(function(c,f){f=a(f);d&&p?f.removeClass("folding-disable"):(f.children("li").hide(),f.addClass("folding-disable"),f.removeClass(b("dropdown")).addClass(b("dropup")))})}function v(a){return String(a).replace(/[a-z]/gi,function(a){return String.fromCharCode(a.charCodeAt(0)+("n">a.toLowerCase()?13:-13))})}function F(a,b){var c=new FileReader;c.onload=function(a){b&&b(a.target.result)};c.onerror=function(a){w("Error",a.target.error.code)};c.readAsText(a)}function C(c){var d=b("%","settings"),f=c.is(":checked"),p=a(b("@","public_target_rule")),h=c.closest("tr").nextAll("tr");h.find('[name^="'+d+'"]').prop("disabled",!f);h.find(b(".","desc")).css("opacity",f?1:.5);z(c,p,d,"1"===p.val()?!0:!1)}function A(c){if(c){"string"===typeof c&&(c=JSON.parse(c));a(b("#","import")).closest("form").deserialize(c);a.each(["matching_rule","validation_login","validation_plugins","validation_themes"],function(c,d){a(b("@",d)).trigger("change")});C(a(b("@","validation_public")));var d=b("%","settings[providers][IPInfoDB]");a(b("@","providers_IPInfoDB")).prop("checked",c[d]?!0:!1)}}function D(c){a("body").append('<div style="display:none"><form method="POST" id="'+b("export-form")+'" action="'+IP_GEO_BLOCK.url.replace("ajax.php","post.php")+'"><input type="hidden" name="action" value="'+IP_GEO_BLOCK.action+'" /><input type="hidden" name="nonce" value="'+IP_GEO_BLOCK.nonce+'" /><input type="hidden" name="cmd" value="'+c+'" /><input type="hidden" name="data" value="" id="'+b("export-data")+'"/><input type="submit" value="submit" /></form><input type="file" name="settings" id="'+b("file-dialog")+'" /></div>')}a.fn.deserialize=function(b,d){return this.each(function(){var c,d,l,h=this,k={};for(c in b)b.hasOwnProperty(c)&&(d=decodeURIComponent(c),l=decodeURIComponent(b[c]),d in k||(k[d]=[]),k[d].push(l));a.each(k,function(b,e){a('[name="'+b+'"]:input',h).val(e)})})};var E={self:this,drawChart:function(){this.drawPie();this.drawLine()},dataPie:null,viewPie:null,drawPie:function(){if(!self.dataPie){self.dataPie=new google.visualization.DataTable;self.dataPie.addColumn("string","Country");self.dataPie.addColumn("number","Requests");var c;a(b("#","countries li")).each(function(){c=a(this).text().split(":");self.dataPie.addRow([c[0]||"",Number(c[1])])})}self.viewPie||(self.viewPie=new google.visualization.PieChart(t.getElementById(b("chart-countries"))));a(b("#","chart-countries")).width()&&self.viewPie.draw(self.dataPie,{backgroundColor:"#f1f1f1",chartArea:{left:0,top:"5%",width:"100%",height:"90%"},sliceVisibilityThreshold:.015})},dataLine:null,viewLine:null,drawLine:function(){if(!self.dataLine){self.dataLine=new google.visualization.DataTable;self.dataLine.addColumn("date","Date");self.dataLine.addColumn("number","comment");self.dataLine.addColumn("number","xmlrpc");self.dataLine.addColumn("number","login");self.dataLine.addColumn("number","admin");self.dataLine.addColumn("number","public");var c,d,f,h,m,n,k=[],r=a(b("#","targets tr"));h=r.length;for(c=0;c<h;c++)for(k[c]=[],n=r.eq(c).children(),m=n.length,d=0;d<m;d++)f=n.eq(d).text(),k[c].push(d?Number(f):new Date(f));self.dataLine.addRows(k)}self.viewLine||(self.viewLine=new google.visualization.LineChart(t.getElementById(b("chart-daily"))));if(c=a(b("#","chart-daily")).width())c=320<c?!0:!1,self.viewLine.draw(self.dataLine,{backgroundColor:"#f1f1f1",legend:{position:"bottom"},hAxis:{format:"MM/dd"},vAxis:{textPosition:c?"out":"in"},chartArea:{left:c?"10%":0,top:"5%",width:"100%",height:"75%"}})}};a(function(){ip_geo_block_time=new Date-ip_geo_block_time;var c="undefined"!==typeof wpCookies&&wpCookies.getHash(b("%","admin"))||{},l=[0,9,10],f=/&tab=(\d)/.exec(h.location.href),f=Number(f&&f[1]),p=a('<fieldset class="'+b("field")+'"></fieldset>'),u=a("<legend></legend>");a(".form-table").each(function(e){var g=a(this),q=g.prevAll("h2,h3:first"),d=q.nextUntil(g);g.wrap(p).parent().attr("id",b("settings-"+e)).data("ip-geo-block",e).prepend(q.wrap(u).parent());d.insertBefore(g);1>=f&&(e+=l[f],"undefined"===typeof c[e]||c[e]?q.addClass(b("dropdown")).parent().nextAll().show():q.addClass(b("dropup")).parent().nextAll().hide())});var t=function(){a(b("#","chart-countries")).length&&E.drawChart()};1>=f&&(a("form").on("click","h2,h3",function(e){e=a(this);var g=e.closest("fieldset").data("ip-geo-block");e.parent().nextAll().toggle();e.toggleClass(b("dropup")).toggleClass(b("dropdown"));"undefined"!==typeof wpCookies&&(c[g+l[f]]=e.hasClass(b("dropdown"))?"o":"",wpCookies.setHash(b("%","admin"),c,new Date(Date.now()+2592E6)));t();return!1}),a(b("#","toggle-sections")).on("click",function(e){var g,q=0,d=[b("dropdown"),b("dropup")];e=a(b(".","field")).find("h2,h3");e.each(function(b){q+=a(this).hasClass(d[0])});e.each(function(b){g=a(this);g.parent().nextAll().toggle(q?!1:!0);g.removeClass(d.join(" ")).addClass(q?d[1]:d[0]);c[b+l[f]]=q?"":"o"});"undefined"!==typeof wpCookies&&wpCookies.setHash(b("%","admin"),c,new Date(Date.now()+2592E6));t();return!1}));a(b("#","inhibit")).on("submit",function(){return!1});switch(f){case 0:a(b("#","scan-code")).on("click",function(e){var c=a(this).parent();m("scanning",{cmd:"scan-code"},function(a){c.children("ul").length||c.append('<ul id="'+b("code-list")+'"></ul>');c=c.children("ul").empty();var e,g;for(e in a)a.hasOwnProperty(e)&&(e=d(e),"string"===typeof a[e]?g=d(a[e]):(g=d(a[e].code),e='<abbr title="'+d(a[e].type)+'">'+e+"</abbr>"),c.append("<li>"+e+' : <span class="'+b("notice")+'">'+g+"</span></li>"));c.show("slow")});return!1});a(b("@","matching_rule")).on("change",function(){a(b("@","white_list")).closest("tr").toggle("0"===this.value);a(b("@","black_list")).closest("tr").toggle("1"===this.value);return!1}).trigger("change");a(b("@","public_matching_rule")).on("change",function(){a(b("@","public_white_list")).closest("tr").toggle("0"===this.value);a(b("@","public_black_list")).closest("tr").toggle("1"===this.value);return!1}).trigger("change");a(b("@","update")).on("click",function(e){m("download",{cmd:"download"},function(e){var c,g,f;for(c in e)if(e.hasOwnProperty(c))for(g in f=e[c],f)f.hasOwnProperty(g)&&(g=d(g),f[g].filename&&a(b("@",c+"_"+g+"_path")).val(d(f[g].filename)),f[g].message&&a(b("#",c+"-"+g)).text(d(f[g].message)))});return!1});var k=b("%","settings");a(b("@","validation_login")).on("change",function(b){b=a(this);z(b,b,k,!0);return!1}).trigger("change");a('select[name^="'+k+'"]').on("change",function(e){e=a(this);var c,d=b(".","desc");e.next(d).empty();(c=e.children("option:selected").data("desc"))&&e.next(d).html(a.parseHTML(c));z(e,e,k,!0);return!1}).trigger("change");a(b("@","validation_public")).on("change",function(b){C(a(this));return!1}).trigger("change");D("validate");a(b("#","export")).on("click",function(e){if("undefined"===typeof JSON)return w(null,IP_GEO_BLOCK.msg[6]),!1;var c=k,d={};a.each(a(this).closest("form").serializeArray(),function(a,b){-1!==b.name.indexOf(c)&&(d[b.name]=b.value)});d[c+="[signature]"]=h.btoa(v(d[c]));a(b("#","export-data")).val(JSON.stringify(d));a(b("#","export-form")).trigger("submit");return!1});a(b("#","file-dialog")).on("change",function(a){if("undefined"===typeof FileReader)return w(null,IP_GEO_BLOCK.msg[6]),!1;var b;(a=a.target.files[0])&&F(a,function(a){a=JSON.parse(a);b=k+"[signature]";"undefined"!==typeof a[b]&&(a[b]=h.btoa(v(a[b])));m("export-import",{cmd:"validate",data:JSON.stringify(a)},A)});return!1});a(b("#","import")).on("click",function(c){a(b("#","file-dialog")).trigger("click");return!1});a(b("#","default")).on("click",function(a){n(IP_GEO_BLOCK.msg[0],function(){m("pre-defined",{cmd:"import-default"},A)});return!1});a(b("#","preferred")).on("click",function(a){n(IP_GEO_BLOCK.msg[0],function(){m("pre-defined",{cmd:"import-preferred"},A)});return!1});a(b("@","create_table")).on("click",function(a){n(IP_GEO_BLOCK.msg[1],function(){B("create-table")});return!1});a(b("@","delete_table")).on("click",function(a){n(IP_GEO_BLOCK.msg[2],function(){B("delete-table")});return!1});a("ul."+k+"_folding dfn").on("click",function(c){c=a(this).parent();c.children("li").toggle();c.toggleClass(b("dropup")).toggleClass(b("dropdown"));return!1});a(b("#","decode")).on("click",function(c){c=a(b("@","signature"));var e=c.val();-1===e.search(/,/)?c.val(v(h.atob(e))):c.val(h.btoa(v(e)));return!1});a(b("@","response_code")).on("change",function(b){b=parseInt(a(this).val()/100,10);var c=a(this).closest("tr").nextAll("tr");3>=b?c.each(function(b){0===b?a(this).show():1===b&&a(this).hide()}):c.each(function(b){0===b?a(this).hide():1===b&&a(this).show()})}).trigger("change");a("#submit").on("click",function(c){c=a(b("@","signature"));var e=c.val();-1!==e.search(/,/)&&c.val(h.btoa(v(e)));return!0});break;case 1:a(b("#","chart-countries")).length&&"object"===typeof google&&google.load("visualization","1",{packages:["corechart"],callback:function(){E.drawChart()}});a(b("@","clear_statistics")).on("click",function(a){n(IP_GEO_BLOCK.msg[3],function(){y("statistics",null)});return!1});a(b("@","clear_cache")).on("click",function(a){n(IP_GEO_BLOCK.msg[4],function(){y("cache",null)});return!1});break;case 2:a(h).on(b("gmap-error"),function(){m(null,{cmd:"gmap-error"},function(a){x(a.page,a.tab)})});var r=a(b("#","map"));"object"===typeof google?r.each(function(){a(this).GmapRS()}):r.each(function(){a(this).empty().html('<iframe src="//maps.google.com/maps?output=embed" frameborder="0" style="width:100%; height:400px; border:0" allowfullscreen></iframe>')});a(b("@","get_location")).on("click",function(c){var e=a(b("#","whois")),f=a(b("@","ip_address")).val();f&&(e.hide().empty(),c=a.whois(f,function(c){var d,f="";for(d=0;d<c.length;d++)f+="<tr><td>"+c[d].name+"</td><td>"+c[d].value+"</td></tr>";e.html('<fieldset class="'+b("field")+'"><legend><h2 id="'+b("whois-title")+'" class="'+b("dropdown")+'">Whois</h2></legend><table class="'+b("table")+'">'+f+"</table><fieldset>").fadeIn("slow");a(b("#","whois-title")).on("click",function(c){c=a(this);c.parent().nextAll().toggle();c.toggleClass(b("dropup")).toggleClass(b("dropdown"));return!1})}),m("loading",{cmd:"search",ip:f,which:a(b("@","service")).val()},function(a){var c,e="",g=d(a.latitude||"0"),h=d(a.longitude||"0"),k=a.latitude||a.longitude?8:2;for(c in a)a.hasOwnProperty(c)&&(c=d(c),e+='<li><span class="'+b("title")+'">'+c+' : </span><span class="'+b("result")+'">'+d(a[c])+"</span></li>");"object"===typeof google?r.GmapRS("addMarker",{latitude:g,longitude:h,title:f,content:"<ul>"+e+"</ul>",show:!0,zoom:k}):r.css({height:"600px",backgroundColor:"transparent"}).empty().html('<ul style="margin-top:0; margin-left:1em;"><li><span class="'+b("title")+'">IP address : </span><span class="'+b("result")+'">'+d(f)+"</span></li>"+e+'</ul><iframe src="//maps.google.com/maps?q='+g+","+h+"&z="+k+'&output=embed" frameborder="0" style="width:100%; height:400px; border:0" allowfullscreen></iframe>')},[c]));return!1});a(b("@","ip_address")).val()&&a(b("@","get_location")).trigger("click");break;case 4:a(b(".","log")).hide().length&&m("logs",{cmd:"restore",which:null,time:ip_geo_block_time},function(c){for(var e in c)c.hasOwnProperty(e)&&(e=d(e),a(b("#","log-"+e)).html(c[e]));"function"===typeof a.fn.footable&&a(b(".","log")).fadeIn("slow").footable();a('tbody[id^="'+b("quot;,"log-")+'"]').on("click","a",function(b){h.open(h.location.href.replace(/tab=\d/,"tab=2")+"&ip="+a(this).text().replace(/[^\w\.\:\*]/,""));return!1})}),a(b("#","reset-filter")).on("click",function(b){a(".footable").trigger("footable_clear_filter");return!1}),a(b("@","clear_logs")).on("click",function(a){n(IP_GEO_BLOCK.msg[5],function(){y("logs",null)});return!1}),D("export-logs"),a(b("#","export-logs")).on("click",function(c){a(b("#","export-form")).trigger("submit");return!1})}})})(jQuery,window,document);
admin/js/authenticate.js CHANGED
@@ -38,8 +38,7 @@ var IP_GEO_BLOCK_ZEP = {
38
39
// Parse a URL and return its components
40
function parse_uri(uri) {
41
- // avoid malformed URI error when uri includes '%'
42
- uri = /*decodeURIComponent*/(uri ? uri.toString() : '');
43
44
var m = uri.match(
45
// https://tools.ietf.org/html/rfc3986#appendix-B
@@ -122,14 +121,14 @@ var IP_GEO_BLOCK_ZEP = {
122
// returns the absloute path as a string
123
return real.join('/').replace(/\/\//g, '/');
124
}
125
- /*
126
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
127
function encodeURIComponentRFC3986(str) {
128
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
129
return '%' + c.charCodeAt(0).toString(16);
130
});
131
}
132
- */
133
// append the nonce as query strings to the uri
134
function add_query_nonce(uri, nonce) {
135
if (typeof uri !== 'object') { // `string` or `undefined`
@@ -147,7 +146,7 @@ var IP_GEO_BLOCK_ZEP = {
147
}
148
}
149
150
- data.push(IP_GEO_BLOCK_ZEP.auth + '=' + encodeURIComponent(nonce));//RFC3986
151
uri.query = data.join('&');
152
153
return compose_uri(uri);
@@ -248,7 +247,7 @@ var IP_GEO_BLOCK_ZEP = {
248
if (callback) {
249
data = callback(data);
250
}
251
- data.push(IP_GEO_BLOCK_ZEP.auth + '=' + encodeURIComponent(nonce));//RFC3986
252
settings.data = data.join('&');
253
}
254
}
@@ -318,7 +317,7 @@ var IP_GEO_BLOCK_ZEP = {
318
}
319
});
320
321
- $body.onFirst('click contextmenu', 'a', function (event) {
322
// attr() returns 'string' or 'undefined'
323
var $this = $(this),
324
href = $this.attr('href'),
@@ -344,7 +343,7 @@ var IP_GEO_BLOCK_ZEP = {
344
345
// stop event propagation
346
$this.removeAttr('target');
347
- $this.off('click contextmenu');
348
event.preventDefault();
349
event.stopPropagation();
350
event.stopImmediatePropagation();
38
39
// Parse a URL and return its components
40
function parse_uri(uri) {
41
+ uri = decodeURIComponent(uri ? uri.toString() : '');
42
43
var m = uri.match(
44
// https://tools.ietf.org/html/rfc3986#appendix-B
121
// returns the absloute path as a string
122
return real.join('/').replace(/\/\//g, '/');
123
}
124
+
125
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
126
function encodeURIComponentRFC3986(str) {
127
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
128
return '%' + c.charCodeAt(0).toString(16);
129
});
130
}
131
+
132
// append the nonce as query strings to the uri
133
function add_query_nonce(uri, nonce) {
134
if (typeof uri !== 'object') { // `string` or `undefined`
146
}
147
}
148
149
+ data.push(IP_GEO_BLOCK_ZEP.auth + '=' + encodeURIComponentRFC3986(nonce));
150
uri.query = data.join('&');
151
152
return compose_uri(uri);
247
if (callback) {
248
data = callback(data);
249
}
250
+ data.push(IP_GEO_BLOCK_ZEP.auth + '=' + encodeURIComponentRFC3986(nonce));
251
settings.data = data.join('&');
252
}
253
}
317
}
318
});
319
320
+ $body.onFirst('click', 'a', function (event) {
321
// attr() returns 'string' or 'undefined'
322
var $this = $(this),
323
href = $this.attr('href'),
343
344
// stop event propagation
345
$this.removeAttr('target');
346
+ $this.off('click');
347
event.preventDefault();
348
event.stopPropagation();
349
event.stopImmediatePropagation();
admin/js/authenticate.min.js CHANGED
@@ -3,4 +3,4 @@
3
Copyright (c) 2015-2016 tokkonopapa (tokkonopapa@yahoo.com)
4
This software is released under the MIT License.
5
*/
6
- var IP_GEO_BLOCK_ZEP={init:!1,auth:"ip-geo-block-auth-nonce",nonce:IP_GEO_BLOCK_AUTH.nonce||"",redirect:function(e){-1!==location.href.indexOf(e)&&(this.nonce&&(e+=(0<=e.indexOf("?")?"&":"?")+this.auth+"="+this.nonce),window.location.href=e)}};(function(e,r){function t(a){return a?a.toString().replace(/[&<>"']/g,function(a){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[a]}):""}function g(a){a=a?a.toString():"";a=a.match(/^(?:([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);return{scheme:a[1]||"",relative:a[2]||"",authority:a[3]||"",path:a[4]||"",query:a[5]||"",fragment:a[6]||""}}function h(a,b){"object"!==typeof a&&(a=g(a||location.href));for(var c=a.query?a.query.split("&"):[],d=c.length;0<d--;)if(0===c[d].indexOf(IP_GEO_BLOCK_ZEP.auth)){c.splice(d,1);break}c.push(IP_GEO_BLOCK_ZEP.auth+"="+encodeURIComponent(b));a.query=c.join("&");return(a.scheme?a.scheme+":":"")+(a.relative+a.path)+(a.query?"?"+a.query:"")+(a.fragment?"#"+a.fragment:"")}function k(a){a=g(a?a.toString().toLowerCase():location.pathname);var b,c=a,d=[];"object"!==typeof c&&(c=g(c));c=c.path;"/"!==c.charAt(0)&&(b=window.location.pathname,c=b.substring(0,b.lastIndexOf("/")+1)+c);c=c.split("/");""===c[c.length-1]&&(c.pop(),c[c.length-1]+="/");for(b in c)c.hasOwnProperty(b)&&"."!==c[b]&&(".."===c[b]?0<d.length&&d.pop():(1>d.length||""!==c[b])&&d.push(c[b]));b=d.join("/").replace(/\/\//g,"/");if(/https?/.test(a.scheme)||!a.scheme){if(a.authority&&a.authority!==location.host.toLowerCase())return-1;if((a.scheme||a.path||a.query)&&u.test(b))return 1}return 0}function m(a,b,c){var d=b.split(/\s+/);a.each(function(a){for(a=0;a<d.length;a++){var b=e.trim(d[a]).match(/[^\.]+/i)[0],f=e(this),l=b,b=c,f=e._data(f[0]).events[l],l=b?f.splice(f.delegateCount-1,1)[0]:f.pop();f.splice(b?0:f.delegateCount||0,0,l)}})}function n(){var a=IP_GEO_BLOCK_ZEP.nonce;if(a){var b=e("body");b.find("img").each(function(b){b=e(this).attr("src");1===k(b)&&e(this).attr("src",h(b,a))});b.onFirst("click contextmenu","a",function(b){var c=e(this),d=c.attr("href"),f=c.attr("rel"),g="undefined"!==typeof d?k(d):0;if(1===g)c.attr("href",h(d,!f||0>f.indexOf("nofollow")?a:"nofollow"));else if(-1===g)return d=window.open(),d.document.write('<meta name="referrer" content="never" /><meta name="referrer" content="no-referrer" /><meta http-equiv="refresh" content="0; url='+t(this.href)+'" />'),d.document.close(),c.removeAttr("target"),c.off("click contextmenu"),b.preventDefault(),b.stopPropagation(),b.stopImmediatePropagation(),!1});b.onFirst("submit","form",function(b){b=e(this);var c=b.attr("action");1===k(c)&&b.attr("action",h(c,a))});if("undefined"!==typeof _wpRevisionsSettings)for(var c=_wpRevisionsSettings.revisionData,d=c.length,b=0;b<d;b++)-1===c[b].restoreUrl.indexOf(IP_GEO_BLOCK_ZEP.auth)&&(_wpRevisionsSettings.revisionData[b].restoreUrl=h(c[b].restoreUrl,a))}}var u=new RegExp("^(?:"+(IP_GEO_BLOCK_AUTH.home||"")+IP_GEO_BLOCK_AUTH.admin+"|"+(IP_GEO_BLOCK_AUTH.home||"")+IP_GEO_BLOCK_AUTH.plugins+"|"+(IP_GEO_BLOCK_AUTH.home||"")+IP_GEO_BLOCK_AUTH.themes+")(?:.*.php|.*/)?quot;),p=function(a){for(var b=a.length;0<b--;)if(-1!==a[b].indexOf("request%5Bbrowse%5D=ip-geo-block-auth")){a[b]="request%5Bbrowse%5D=featured";break}return a},q={"upload.php":function(a){for(var b=a.length;0<b--;)if(-1!==a[b].indexOf("query%5Bip-geo-block-auth-nonce%5D=")){delete a[b];break}return a},"theme-install.php":p,"network/theme-install.php":p};e(r).ajaxSend(function(a,b,c){if((a=IP_GEO_BLOCK_ZEP.nonce)&&1===k(c.url))if("undefined"!==typeof window.FormData&&c.data instanceof FormData)c.data.append(IP_GEO_BLOCK_ZEP.auth,a);else if(b=g(c.url),"undefined"===typeof c.data||b.query)c.url=h(b,a);else{b=c.data?c.data.split("&"):[];var d;d=location.pathname;d=d.replace(IP_GEO_BLOCK_AUTH.home+IP_GEO_BLOCK_AUTH.admin,"");(d=q.hasOwnProperty(d)?q[d]:null)&&(b=d(b));b.push(IP_GEO_BLOCK_ZEP.auth+"="+encodeURIComponent(a));c.data=b.join("&")}});"undefined"===typeof e.fn.onFirst&&(e.fn.onFirst=function(a,b){var c,d=e(this),f="string"===typeof b;e.fn.on.apply(d,arguments);if("object"===typeof a)for(c in a)a.hasOwnProperty(c)&&m(d,c,f);else"string"===typeof a&&m(d,a,f);return d});e(function(){e("a").each(function(){this.hasAttribute("onClick")||this.setAttribute("onClick","javascript:void(0);")});n();IP_GEO_BLOCK_ZEP.init=!0});e(window).on("error",function(){IP_GEO_BLOCK_ZEP.init||n()})})(jQuery,document);
3
Copyright (c) 2015-2016 tokkonopapa (tokkonopapa@yahoo.com)
4
This software is released under the MIT License.
5
*/
6
+ var IP_GEO_BLOCK_ZEP={init:!1,auth:"ip-geo-block-auth-nonce",nonce:IP_GEO_BLOCK_AUTH.nonce||"",redirect:function(e){-1!==location.href.indexOf(e)&&(this.nonce&&(e+=(0<=e.indexOf("?")?"&":"?")+this.auth+"="+this.nonce),window.location.href=e)}};(function(e,t){function u(a){return a?a.toString().replace(/[&<>"']/g,function(a){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[a]}):""}function g(a){a=decodeURIComponent(a?a.toString():"");a=a.match(/^(?:([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);return{scheme:a[1]||"",relative:a[2]||"",authority:a[3]||"",path:a[4]||"",query:a[5]||"",fragment:a[6]||""}}function m(a){return encodeURIComponent(a).replace(/[!'()*]/g,function(a){return"%"+a.charCodeAt(0).toString(16)})}function h(a,b){"object"!==typeof a&&(a=g(a||location.href));for(var c=a.query?a.query.split("&"):[],d=c.length;0<d--;)if(0===c[d].indexOf(IP_GEO_BLOCK_ZEP.auth)){c.splice(d,1);break}c.push(IP_GEO_BLOCK_ZEP.auth+"="+m(b));a.query=c.join("&");return(a.scheme?a.scheme+":":"")+(a.relative+a.path)+(a.query?"?"+a.query:"")+(a.fragment?"#"+a.fragment:"")}function k(a){a=g(a?a.toString().toLowerCase():location.pathname);var b,c=a,d=[];"object"!==typeof c&&(c=g(c));c=c.path;"/"!==c.charAt(0)&&(b=window.location.pathname,c=b.substring(0,b.lastIndexOf("/")+1)+c);c=c.split("/");""===c[c.length-1]&&(c.pop(),c[c.length-1]+="/");for(b in c)c.hasOwnProperty(b)&&"."!==c[b]&&(".."===c[b]?0<d.length&&d.pop():(1>d.length||""!==c[b])&&d.push(c[b]));b=d.join("/").replace(/\/\//g,"/");if(/https?/.test(a.scheme)||!a.scheme){if(a.authority&&a.authority!==location.host.toLowerCase())return-1;if((a.scheme||a.path||a.query)&&v.test(b))return 1}return 0}function n(a,b,c){var d=b.split(/\s+/);a.each(function(a){for(a=0;a<d.length;a++){var b=e.trim(d[a]).match(/[^\.]+/i)[0],f=e(this),l=b,b=c,f=e._data(f[0]).events[l],l=b?f.splice(f.delegateCount-1,1)[0]:f.pop();f.splice(b?0:f.delegateCount||0,0,l)}})}function p(){var a=IP_GEO_BLOCK_ZEP.nonce;if(a){var b=e("body");b.find("img").each(function(b){b=e(this).attr("src");1===k(b)&&e(this).attr("src",h(b,a))});b.onFirst("click","a",function(b){var c=e(this),d=c.attr("href"),f=c.attr("rel"),g="undefined"!==typeof d?k(d):0;if(1===g)c.attr("href",h(d,!f||0>f.indexOf("nofollow")?a:"nofollow"));else if(-1===g)return d=window.open(),d.document.write('<meta name="referrer" content="never" /><meta name="referrer" content="no-referrer" /><meta http-equiv="refresh" content="0; url='+u(this.href)+'" />'),d.document.close(),c.removeAttr("target"),c.off("click"),b.preventDefault(),b.stopPropagation(),b.stopImmediatePropagation(),!1});b.onFirst("submit","form",function(b){b=e(this);var c=b.attr("action");1===k(c)&&b.attr("action",h(c,a))});if("undefined"!==typeof _wpRevisionsSettings)for(var c=_wpRevisionsSettings.revisionData,d=c.length,b=0;b<d;b++)-1===c[b].restoreUrl.indexOf(IP_GEO_BLOCK_ZEP.auth)&&(_wpRevisionsSettings.revisionData[b].restoreUrl=h(c[b].restoreUrl,a))}}var v=new RegExp("^(?:"+(IP_GEO_BLOCK_AUTH.home||"")+IP_GEO_BLOCK_AUTH.admin+"|"+(IP_GEO_BLOCK_AUTH.home||"")+IP_GEO_BLOCK_AUTH.plugins+"|"+(IP_GEO_BLOCK_AUTH.home||"")+IP_GEO_BLOCK_AUTH.themes+")(?:.*.php|.*/)?quot;),q=function(a){for(var b=a.length;0<b--;)if(-1!==a[b].indexOf("request%5Bbrowse%5D=ip-geo-block-auth")){a[b]="request%5Bbrowse%5D=featured";break}return a},r={"upload.php":function(a){for(var b=a.length;0<b--;)if(-1!==a[b].indexOf("query%5Bip-geo-block-auth-nonce%5D=")){delete a[b];break}return a},"theme-install.php":q,"network/theme-install.php":q};e(t).ajaxSend(function(a,b,c){if((a=IP_GEO_BLOCK_ZEP.nonce)&&1===k(c.url))if("undefined"!==typeof window.FormData&&c.data instanceof FormData)c.data.append(IP_GEO_BLOCK_ZEP.auth,a);else if(b=g(c.url),"undefined"===typeof c.data||b.query)c.url=h(b,a);else{b=c.data?c.data.split("&"):[];var d;d=location.pathname;d=d.replace(IP_GEO_BLOCK_AUTH.home+IP_GEO_BLOCK_AUTH.admin,"");(d=r.hasOwnProperty(d)?r[d]:null)&&(b=d(b));b.push(IP_GEO_BLOCK_ZEP.auth+"="+m(a));c.data=b.join("&")}});"undefined"===typeof e.fn.onFirst&&(e.fn.onFirst=function(a,b){var c,d=e(this),f="string"===typeof b;e.fn.on.apply(d,arguments);if("object"===typeof a)for(c in a)a.hasOwnProperty(c)&&n(d,c,f);else"string"===typeof a&&n(d,a,f);return d});e(function(){e("a").each(function(){this.hasAttribute("onClick")||this.setAttribute("onClick","javascript:void(0);")});p();IP_GEO_BLOCK_ZEP.init=!0});e(window).on("error",function(){IP_GEO_BLOCK_ZEP.init||p()})})(jQuery,document);
admin/js/footable.min.js CHANGED
@@ -3,8 +3,6 @@
3
* Version : 2.0.3
4
* http://fooplugins.com/plugins/footable-jquery/
5
*
6
- * Requires jQuery - http://jquery.com/
7
- *
8
* Copyright 2014 Steven Usher & Brad Vincent
9
* Released under the MIT license
10
* You are free to use FooTable in commercial projects as long as this copyright header is left intact.
3
* Version : 2.0.3
4
* http://fooplugins.com/plugins/footable-jquery/
5
*
6
* Copyright 2014 Steven Usher & Brad Vincent
7
* Released under the MIT license
8
* You are free to use FooTable in commercial projects as long as this copyright header is left intact.
classes/class-ip-geo-block-actv.php CHANGED
@@ -26,7 +26,7 @@ class IP_Geo_Block_Activate {
26
27
// initialize main blog
28
public static function init_main_blog() {
29
- if ( current_user_can( 'manage_options' ) ) {
30
$settings = IP_Geo_Block::get_option();
31
32
// kick off a cron job to download database immediately
@@ -66,9 +66,7 @@ class IP_Geo_Block_Activate {
66
self::activate_blog();
67
}
68
69
- // only after 'init' action hook for is_user_logged_in().
70
- if ( did_action( 'init' ) && is_user_logged_in() )
71
- self::init_main_blog(); // should be called with high priority
72
}
73
74
/**
26
27
// initialize main blog
28
public static function init_main_blog() {
29
+ if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
30
$settings = IP_Geo_Block::get_option();
31
32
// kick off a cron job to download database immediately
66
self::activate_blog();
67
}
68
69
+ self::init_main_blog(); // should be called with high priority
70
}
71
72
/**
classes/class-ip-geo-block-apis.php CHANGED
@@ -458,11 +458,11 @@ class IP_Geo_Block_API_Cache extends IP_Geo_Block_API {
458
$cache = self::get_cache( $ip = $validate['ip'] );
459
460
if ( $cache ) {
461
- $fail = $cache['fail'] + ( empty( $validate['fail'] ) ? 0 : 1 );
462
- $call = $cache['call'] + ( empty( $validate['fail'] ) ? 1 : 0 );
463
} else { // if new cache then reset these values
464
- $fail = 0;
465
$call = 1;
466
}
467
468
// update elements
@@ -472,7 +472,7 @@ class IP_Geo_Block_API_Cache extends IP_Geo_Block_API {
472
'hook' => $hook,
473
'code' => $validate['code'],
474
'auth' => $validate['auth'], // get_current_user_id() > 0
475
- 'fail' => $fail, // $validate['auth'] ? 0 : $fail,
476
'call' => $settings['save_statistics'] ? $call : 0,
477
'host' => isset( $validate['host'] ) ? $validate['host'] : NULL,
478
) );
@@ -482,7 +482,6 @@ class IP_Geo_Block_API_Cache extends IP_Geo_Block_API {
482
483
public static function clear_cache() {
484
IP_Geo_Block_Logs::clear_cache();
485
- self::$memcache = array();
486
}
487
488
public static function get_cache_all() {
@@ -519,43 +518,43 @@ class IP_Geo_Block_Provider {
519
'freegeoip.net' => array(
520
'key' => NULL,
521
'type' => 'IPv4, IPv6 / free',
522
- 'link' => '<a rel="noreferrer" href="http://freegeoip.net/" title="freegeoip.net: FREE IP Geolocation Web Service">http://freegeoip.net/</a>&nbsp;(IPv4, IPv6 / free)',
523
),
524
525
'ipinfo.io' => array(
526
'key' => NULL,
527
'type' => 'IPv4, IPv6 / free',
528
- 'link' => '<a rel="noreferrer" href="http://ipinfo.io/" title="ip address information including geolocation, hostname and network details">http://ipinfo.io/</a>&nbsp;(IPv4, IPv6 / free)',
529
),
530
531
'Nekudo' => array(
532
'key' => NULL,
533
'type' => 'IPv4, IPv6 / free',
534
- 'link' => '<a rel="noreferrer" href="http://geoip.nekudo.com/" title="geoip.nekudo.com | Free IP to geolocation API">http://geoip.nekudo.com/</a>&nbsp;(IPv4, IPv6 / free)',
535
),
536
537
'Xhanch' => array(
538
'key' => NULL,
539
'type' => 'IPv4 / free',
540
- 'link' => '<a rel="noreferrer" href="http://xhanch.com/xhanch-api-ip-get-detail/" title="Xhanch API &#8211; IP Get Detail | Xhanch Studio">http://xhanch.com/</a>&nbsp;(IPv4 / free)',
541
),
542
543
'GeoIPLookup' => array(
544
'key' => NULL,
545
'type' => 'IPv4, IPv6 / free',
546
- 'link' => '<a rel="noreferrer" href="http://geoiplookup.net/" title="What Is My IP Address | GeoIP Lookup">GeoIPLookup.net</a>&nbsp;(IPv4, IPv6 / free)',
547
),
548
549
'ip-api.com' => array(
550
'key' => FALSE,
551
'type' => 'IPv4, IPv6 / free for non-commercial use',
552
- 'link' => '<a rel="noreferrer" href="http://ip-api.com/" title="IP-API.com - Free Geolocation API">http://ip-api.com/</a>&nbsp;(IPv4, IPv6 / free for non-commercial use)',
553
),
554
555
'IPInfoDB' => array(
556
'key' => '',
557
'type' => 'IPv4, IPv6 / free for registered user',
558
- 'link' => '<a rel="noreferrer" href="http://ipinfodb.com/" title="IPInfoDB | Free IP Address Geolocation Tools">http://ipinfodb.com/</a>&nbsp;(IPv4, IPv6 / free for registered user)',
559
),
560
);
561
@@ -648,7 +647,10 @@ class IP_Geo_Block_Provider {
648
}
649
650
if ( 0 === $field )
651
- return __( 'You need to select at least one IP geolocation service. Otherwise <strong>you\'ll be blocked</strong> after the cache expires.', 'ip-geo-block' );
652
653
return NULL;
654
}
458
$cache = self::get_cache( $ip = $validate['ip'] );
459
460
if ( $cache ) {
461
+ $fail = $cache['fail'] + (int)isset( $validate['fail'] );
462
+ $call = $cache['call'] + (int)empty( $validate['fail'] );
463
} else { // if new cache then reset these values
464
$call = 1;
465
+ $fail = 0;
466
}
467
468
// update elements
472
'hook' => $hook,
473
'code' => $validate['code'],
474
'auth' => $validate['auth'], // get_current_user_id() > 0
475
+ 'fail' => $validate['auth'] ? 0 : $fail,
476
'call' => $settings['save_statistics'] ? $call : 0,
477
'host' => isset( $validate['host'] ) ? $validate['host'] : NULL,
478
) );
482
483
public static function clear_cache() {
484
IP_Geo_Block_Logs::clear_cache();
485
}
486
487
public static function get_cache_all() {
518
'freegeoip.net' => array(
519
'key' => NULL,
520
'type' => 'IPv4, IPv6 / free',
521
+ 'link' => '<a class="ip-geo-block-link" href="http://freegeoip.net/" title="freegeoip.net: FREE IP Geolocation Web Service" rel=noreferrer target=_blank>http://freegeoip.net/</a>&nbsp;(IPv4, IPv6 / free)',
522
),
523
524
'ipinfo.io' => array(
525
'key' => NULL,
526
'type' => 'IPv4, IPv6 / free',
527
+ 'link' => '<a class="ip-geo-block-link" href="http://ipinfo.io/" title="ip address information including geolocation, hostname and network details" rel=noreferrer target=_blank>http://ipinfo.io/</a>&nbsp;(IPv4, IPv6 / free)',
528
),
529
530
'Nekudo' => array(
531
'key' => NULL,
532
'type' => 'IPv4, IPv6 / free',
533
+ 'link' => '<a class="ip-geo-block-link" href="http://geoip.nekudo.com/" title="geoip.nekudo.com | Free IP to geolocation API" rel=noreferrer target=_blank>http://geoip.nekudo.com/</a>&nbsp;(IPv4, IPv6 / free)',
534
),
535
536
'Xhanch' => array(
537
'key' => NULL,
538
'type' => 'IPv4 / free',
539
+ 'link' => '<a class="ip-geo-block-link" href="http://xhanch.com/xhanch-api-ip-get-detail/" title="Xhanch API &#8211; IP Get Detail | Xhanch Studio" rel=noreferrer target=_blank>http://xhanch.com/</a>&nbsp;(IPv4 / free)',
540
),
541
542
'GeoIPLookup' => array(
543
'key' => NULL,
544
'type' => 'IPv4, IPv6 / free',
545
+ 'link' => '<a class="ip-geo-block-link" href="http://geoiplookup.net/" title="What Is My IP Address | GeoIP Lookup" rel=noreferrer target=_blank>GeoIPLookup.net</a>&nbsp;(IPv4, IPv6 / free)',
546
),
547
548
'ip-api.com' => array(
549
'key' => FALSE,
550
'type' => 'IPv4, IPv6 / free for non-commercial use',
551
+ 'link' => '<a class="ip-geo-block-link" href="http://ip-api.com/" title="IP-API.com - Free Geolocation API" rel=noreferrer target=_blank>http://ip-api.com/</a>&nbsp;(IPv4, IPv6 / free for non-commercial use)',
552
),
553
554
'IPInfoDB' => array(
555
'key' => '',
556
'type' => 'IPv4, IPv6 / free for registered user',
557
+ 'link' => '<a class="ip-geo-block-link" href="http://ipinfodb.com/" title="IPInfoDB | Free IP Address Geolocation Tools" rel=noreferrer target=_blank>http://ipinfodb.com/</a>&nbsp;(IPv4, IPv6 / free for registered user)',
558
),
559
);
560
647
}
648
649
if ( 0 === $field )
650
+ return __(
651
+ 'You need to select at least one IP geolocation service. Otherwise <strong>you\'ll be blocked</strong> after the cache expires.',
652
+ 'ip-geo-block'
653
+ );
654
655
return NULL;
656
}
classes/class-ip-geo-block-cron.php CHANGED
@@ -73,7 +73,7 @@ class IP_Geo_Block_Cron {
73
74
// if blocking may happen then disable validation
75
if ( -1 !== (int)$settings['matching_rule'] && 'passed' !== $validate['result'] &&
76
- ( empty( $_SERVER['HTTP_X_REQUESTED_FROM'] ) || FALSE === strpos( $_SERVER['HTTP_X_REQUESTED_FROM'], 'InfiniteWP' ) ) ) {
77
$settings['matching_rule'] = -1;
78
}
79
@@ -144,11 +144,7 @@ class IP_Geo_Block_Cron {
144
*
145
*/
146
public static function start_update_db( $settings ) {
147
- if ( ! function_exists( 'is_plugin_active' ) )
148
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
149
-
150
- // the status is still inactive when this plugin is activated on dashboard.
151
- if ( ! is_plugin_active( IP_GEO_BLOCK_BASE ) ) {
152
set_transient( IP_Geo_Block::CRON_NAME, IP_Geo_Block::get_ip_address(), MINUTE_IN_SECONDS );
153
self::schedule_cron_job( $settings['update'], NULL, TRUE );
154
}
@@ -170,8 +166,9 @@ class IP_Geo_Block_Cron {
170
}
171
172
public static function start_cache_gc( $settings ) {
173
- if ( ! wp_next_scheduled( IP_Geo_Block::CACHE_NAME ) )
174
wp_schedule_single_event( time() + $settings['cache_time_gc'], IP_Geo_Block::CACHE_NAME );
175
}
176
177
public static function stop_cache_gc() {
@@ -252,83 +249,50 @@ class IP_Geo_Block_Cron {
252
if ( 'gz' === $args && function_exists( 'gzopen' ) ) {
253
if ( FALSE === ( $gz = gzopen( $src, 'r' ) ) )
254
throw new Exception(
255
- sprintf( __( 'Unable to read %s. Please check the permission.', 'ip-geo-block' ), $src )
256
- );
257
-
258
- if ( FALSE === ( $fp = @fopen( $filename, 'cb' ) ) )
259
- throw new Exception(
260
- sprintf( __( 'Unable to write %s. Please check the permission.', 'ip-geo-block' ), $filename )
261
);
262
263
- if ( ! flock( $fp, LOCK_EX ) )
264
throw new Exception(
265
- sprintf( __( 'Can\'t lock %s. Please try again after a while.', 'ip-geo-block' ), $filename )
266
);
267
268
- ftruncate( $fp, 0 ); // truncate file
269
-
270
// same block size in wp-includes/class-http.php
271
- while ( $data = gzread( $gz, 4096 ) ) {
272
fwrite( $fp, $data, strlen( $data ) );
273
- }
274
}
275
276
elseif ( 'zip' === $args && class_exists( 'ZipArchive' ) ) {
277
// https://codex.wordpress.org/Function_Reference/unzip_file
278
WP_Filesystem();
279
- $tmp = get_temp_dir(); // @since 2.5
280
- $ret = unzip_file( $src, $tmp ); // @since 2.5
281
282
if ( is_wp_error( $ret ) )
283
throw new Exception(
284
$ret->get_error_code() . ' ' . $ret->get_error_message()
285
);
286
-
287
- if ( FALSE === ( $gz = @fopen( $tmp .= basename( $filename ), 'r' ) ) )
288
- throw new Exception(
289
- sprintf( __( 'Unable to read %s. Please check the permission.', 'ip-geo-block' ), $src )
290
- );
291
-
292
- if ( FALSE === ( $fp = @fopen( $filename, 'cb' ) ) )
293
- throw new Exception(
294
- sprintf( __( 'Unable to write %s. Please check the permission.', 'ip-geo-block' ), $filename )
295
- );
296
-
297
- if ( ! flock( $fp, LOCK_EX ) )
298
- throw new Exception(
299
- sprintf( __( 'Can\'t lock %s. Please try again after a while.', 'ip-geo-block' ), $filename )
300
- );
301
-
302
- ftruncate( $fp, 0 ); // truncate file
303
-
304
- // same block size in wp-includes/class-http.php
305
- while ( $data = fread( $gz, 4096 ) ) {
306
- fwrite( $fp, $data, strlen( $data ) );
307
- }
308
}
309
310
- if ( ! empty( $fp ) ) {
311
- fflush( $fp ); // flush output before releasing the lock
312
- flock ( $fp, LOCK_UN ); // release the lock
313
- fclose( $fp );
314
- }
315
-
316
- ! empty( $gz ) and gzclose( $gz );
317
- ! empty( $tmp ) && @is_file( $tmp ) and @unlink( $tmp );
318
- ! is_wp_error( $src ) && @is_file( $src ) and @unlink( $src );
319
}
320
321
// error handler
322
catch ( Exception $e ) {
323
- if ( ! empty( $fp ) ) {
324
- fflush( $fp ); // flush output before releasing the lock
325
- flock ( $fp, LOCK_UN ); // release the lock
326
- fclose( $fp );
327
}
328
329
- ! empty( $gz ) and gzclose( $gz );
330
- ! empty( $tmp ) && @is_file( $tmp ) and @unlink( $tmp );
331
- ! is_wp_error( $src ) && @is_file( $src ) and @unlink( $src );
332
333
return array(
334
'code' => $e->getCode(),
73
74
// if blocking may happen then disable validation
75
if ( -1 !== (int)$settings['matching_rule'] && 'passed' !== $validate['result'] &&
76
+ FALSE === strpos( $_SERVER['HTTP_X_REQUESTED_FROM'], 'InfiniteWP' ) ) {
77
$settings['matching_rule'] = -1;
78
}
79
144
*
145
*/
146
public static function start_update_db( $settings ) {
147
+ if ( has_action( 'activate_' . IP_GEO_BLOCK_BASE ) ) {
148
set_transient( IP_Geo_Block::CRON_NAME, IP_Geo_Block::get_ip_address(), MINUTE_IN_SECONDS );
149
self::schedule_cron_job( $settings['update'], NULL, TRUE );
150
}
166
}
167
168
public static function start_cache_gc( $settings ) {
169
+ if ( ! wp_next_scheduled( IP_Geo_Block::CACHE_NAME ) ) {
170
wp_schedule_single_event( time() + $settings['cache_time_gc'], IP_Geo_Block::CACHE_NAME );
171
+ }
172
}
173
174
public static function stop_cache_gc() {
249
if ( 'gz' === $args && function_exists( 'gzopen' ) ) {
250
if ( FALSE === ( $gz = gzopen( $src, 'r' ) ) )
251
throw new Exception(
252
+ sprintf(
253
+ __( 'Unable to read %s. Please check the permission.', 'ip-geo-block' ),
254
+ $src
255
+ )
256
);
257
258
+ if ( FALSE === ( $fp = @fopen( $filename, 'wb' ) ) )
259
throw new Exception(
260
+ sprintf(
261
+ __( 'Unable to write %s. Please check the permission.', 'ip-geo-block' ),
262
+ $filename
263
+ )
264
);
265
266
// same block size in wp-includes/class-http.php
267
+ while ( $data = gzread( $gz, 4096 ) )
268
fwrite( $fp, $data, strlen( $data ) );
269
+
270
+ gzclose( $gz );
271
+ fclose ( $fp );
272
}
273
274
elseif ( 'zip' === $args && class_exists( 'ZipArchive' ) ) {
275
// https://codex.wordpress.org/Function_Reference/unzip_file
276
WP_Filesystem();
277
+ $ret = unzip_file( $src, dirname( $filename ) ); // @since 2.5
278
279
if ( is_wp_error( $ret ) )
280
throw new Exception(
281
$ret->get_error_code() . ' ' . $ret->get_error_message()
282
);
283
}
284
285
+ @unlink( $src );
286
}
287
288
// error handler
289
catch ( Exception $e ) {
290
+ if ( 'gz' === $args && function_exists( 'gzopen' ) ) {
291
+ ! empty( $gz ) and gzclose( $gz );
292
+ ! empty( $fp ) and fclose ( $fp );
293
}
294
295
+ ! is_wp_error( $src ) and @unlink( $src );
296
297
return array(
298
'code' => $e->getCode(),
classes/class-ip-geo-block-load.php CHANGED
@@ -125,25 +125,11 @@ class IP_Geo_Block_Loader {
125
*/
126
public function run() {
127
128
- /**
129
- * This part will be executed after loading this plugin.
130
- * Register all the rest of the action and filter hooks.
131
- */
132
- if ( IP_Geo_Block_Util::may_be_logged_in() ) {
133
- foreach ( $this->filters as $hook ) {
134
- add_filter( $hook['hook'], $hook['callback'], $hook['priority'], $hook['accepted_args'] );
135
- }
136
-
137
- foreach ( $this->actions as $hook ) {
138
- add_action( $hook['hook'], $hook['callback'], $hook['priority'], $hook['accepted_args'] );
139
- }
140
- }
141
-
142
/**
143
* This part will be executed at the very beginning of WordPress core.
144
* Execute callbacks that are specified by the component with 'init'.
145
*/
146
- else {
147
foreach ( $this->actions as $index => $hook ) {
148
if ( in_array( $hook['hook'], array( 'init', 'wp_loaded' ) ) ) {
149
// Execute callback directly
@@ -155,6 +141,20 @@ class IP_Geo_Block_Loader {
155
}
156
}
157
158
}
159
160
}
125
*/
126
public function run() {
127
128
/**
129
* This part will be executed at the very beginning of WordPress core.
130
* Execute callbacks that are specified by the component with 'init'.
131
*/
132
+ if ( ! IP_Geo_Block_Util::may_be_logged_in() ) {
133
foreach ( $this->actions as $index => $hook ) {
134
if ( in_array( $hook['hook'], array( 'init', 'wp_loaded' ) ) ) {
135
// Execute callback directly
141
}
142
}
143
144
+ /**
145
+ * This part will be executed after loading this plugin.
146
+ * Register all the rest of the action and filter hooks.
147
+ */
148
+ else {
149
+ foreach ( $this->filters as $hook ) {
150
+ add_filter( $hook['hook'], $hook['callback'], $hook['priority'], $hook['accepted_args'] );
151
+ }
152
+
153
+ foreach ( $this->actions as $hook ) {
154
+ add_action( $hook['hook'], $hook['callback'], $hook['priority'], $hook['accepted_args'] );
155
+ }
156
+ }
157
+
158
}
159
160
}
classes/class-ip-geo-block-logs.php CHANGED
@@ -29,6 +29,8 @@ class IP_Geo_Block_Logs {
29
'daystats' => array(),
30
);
31
32
/**
33
* Create
34
*
@@ -59,10 +61,10 @@ class IP_Geo_Block_Logs {
59
`user_agent` varchar(" . IP_GEO_BLOCK_MAX_STR_LEN . ") NULL,
60
`headers` varchar(" . IP_GEO_BLOCK_MAX_TXT_LEN . ") NULL,
61
`data` text NULL,
62
- PRIMARY KEY (`No`),
63
KEY `time` (`time`),
64
KEY `hook` (`hook`)
65
- ) CHARACTER SET $charset"
66
) ) or self::error( __LINE__ ); // utf8mb4 ENGINE=InnoDB or MyISAM
67
68
// for statistics
@@ -70,8 +72,8 @@ class IP_Geo_Block_Logs {
70
$result &= ( FALSE !== $wpdb->query( "CREATE TABLE IF NOT EXISTS `$table` (
71
`No` tinyint(4) unsigned NOT NULL AUTO_INCREMENT,
72
`data` longtext NULL,
73
- PRIMARY KEY (`No`)
74
- ) CHARACTER SET $charset"
75
) ) or self::error( __LINE__ ); // utf8mb4 ENGINE=InnoDB or MyISAM
76
77
// Create 1 record if not exists
@@ -92,45 +94,25 @@ class IP_Geo_Block_Logs {
92
`fail` int(10) unsigned NOT NULL DEFAULT 0,
93
`call` int(10) unsigned NOT NULL DEFAULT 0,
94
`host` tinytext NOT NULL,
95
- PRIMARY KEY (`No`),
96
- UNIQUE KEY (`ip`)
97
- ) CHARACTER SET $charset"
98
) ) or self::error( __LINE__ ); // utf8mb4 ENGINE=InnoDB or MyISAM
99
100
return $result;
101
}
102
103
- /**
104
- * Search table by specific IP address
105
- *
106
- */
107
- private static function search_table( $table, $ip, $type = FALSE ) {
108
- global $wpdb;
109
- $table = $wpdb->prefix . $table;
110
-
111
- $sql = $wpdb->prepare(
112
- "SELECT * FROM `$table` WHERE `ip` = '%s'", $ip
113
- ) and $result = $wpdb->get_results( $sql, ARRAY_A ) or self::error( __LINE__ );
114
-
115
- if ( ! $type )
116
- return ! empty( $result[0] ) ? $result[0] : NULL; // for cache
117
- else
118
- return ! empty( $result ) ? $result : array(); // for logs
119
- }
120
-
121
/**
122
* Delete
123
*
124
*/
125
- public static function delete_tables( $which = 'all' ) {
126
global $wpdb;
127
$tables = array( self::TABLE_LOGS, self::TABLE_STAT, IP_Geo_Block::CACHE_NAME );
128
129
foreach ( $tables as $table ) {
130
- if ( 'all' === $which || $table === $which ) {
131
- $table = $wpdb->prefix . $table;
132
- $wpdb->query( "DROP TABLE IF EXISTS `$table`" ) or self::error( __LINE__ );
133
- }
134
}
135
}
136
@@ -195,27 +177,35 @@ class IP_Geo_Block_Logs {
195
* Record statistics data.
196
*
197
*/
198
- public static function record_stat( $stat ) {
199
global $wpdb;
200
$table = $wpdb->prefix . self::TABLE_STAT;
201
202
- if ( ! is_array( $stat ) ) {
203
- $stat = self::$default;
204
}
205
206
$sql = $wpdb->prepare(
207
- "UPDATE `$table` SET `data` = '%s'", serialize( $stat )
208
- // "REPLACE INTO `$table` (`No`, `data`) VALUES (%d, %s)", 1, serialize( $stat )
209
- ) and $wpdb->query( $sql ) or self::error( __LINE__ );
210
}
211
212
/**
213
- * Limit the number of rows to send to the user agent according the processing time [msec]
214
*
215
*/
216
public static function limit_rows( $time ) {
217
$options = IP_Geo_Block::get_option();
218
- return (int)( $options['validation']['maxlogs'] / ((int)$time < 50 ? 1 : 2) );
219
}
220
221
/**
@@ -368,11 +358,10 @@ class IP_Geo_Block_Logs {
368
369
// XML-RPC
370
if ( 'xmlrpc' === $hook ) {
371
$posts = self::truncate_utf8(
372
file_get_contents( 'php://input' ), '!\s*([<>])\s*!', '$1', IP_GEO_BLOCK_MAX_STR_LEN
373
);
374
-
375
- // mask the password
376
if ( $mask_pwd &&
377
preg_match_all( '/<string>(\S*?)<\/string>/', $posts, $matches ) >= 2 &&
378
strpos( $matches[1][1], home_url() ) !== 0 ) { // except pingback
@@ -485,7 +474,7 @@ class IP_Geo_Block_Logs {
485
$sql = $wpdb->prepare(
486
"DELETE FROM `$table` WHERE `hook` = '%s' ORDER BY `No` ASC LIMIT %d",
487
$hook, $count - $rows + 1
488
- ) and $wpdb->query( $sql ) or self::error( __LINE__ );
489
}
490
491
// insert into DB
@@ -503,7 +492,7 @@ class IP_Geo_Block_Logs {
503
$agent,
504
$heads,
505
$posts
506
- ) and $wpdb->query( $sql ) or self::error( __LINE__ );
507
508
// backup logs to text files
509
if ( $dir = apply_filters(
@@ -526,7 +515,10 @@ class IP_Geo_Block_Logs {
526
global $wpdb;
527
$table = $wpdb->prefix . self::TABLE_LOGS;
528
529
- $sql = "SELECT `hook`, `time`, `ip`, `code`, `result`, `method`, `user_agent`, `headers`, `data` FROM `$table`";
530
531
if ( ! $hook )
532
$sql .= " ORDER BY `hook`, `No` DESC";
@@ -536,48 +528,40 @@ class IP_Geo_Block_Logs {
536
return $sql ? $wpdb->get_results( $sql, ARRAY_N ) : array();
537
}
538
539
- /**
540
- * Search logs by specific IP address
541
- *
542
- */
543
- public static function search_logs( $ip ) {
544
- return self::search_table( self::TABLE_LOGS, $ip, TRUE );
545
- }
546
-
547
/**
548
* Update statistics.
549
*
550
*/
551
public static function update_stat( $hook, $validate, $settings ) {
552
// Restore statistics.
553
- if ( $stat = self::restore_stat() ) {
554
555
$provider = isset( $validate['provider'] ) ? $validate['provider'] : 'ZZ';
556
- if ( empty( $stat['providers'][ $provider ] ) )
557
- $stat['providers'][ $provider ] = array( 'count' => 0, 'time' => 0.0 );
558
559
- $stat['providers'][ $provider ]['count']++; // undefined in auth_fail()
560
- $stat['providers'][ $provider ]['time'] += (float)@$validate['time'];
561
562
if ( 'passed' !== $validate['result'] ) {
563
// Blocked by type of IP address
564
if ( filter_var( $validate['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
565
- $stat['IPv4']++;
566
elseif ( filter_var( $validate['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 ) )
567
- $stat['IPv6']++;
568
569
- @$stat['blocked' ]++;
570
- @$stat['countries'][ $validate['code'] ]++;
571
- @$stat['daystats' ][ mktime( 0, 0, 0 ) ][ $hook ]++;
572
}
573
574
- if ( count( $stat['daystats'] ) > max( 30, min( 365, (int)@$settings['validation']['recdays'] ) ) ) {
575
- reset( $stat['daystats'] );
576
- unset( $stat['daystats'][ key( $stat['daystats'] ) ] );
577
}
578
579
// Record statistics.
580
- self::record_stat( $stat );
581
}
582
}
583
@@ -592,11 +576,18 @@ class IP_Geo_Block_Logs {
592
}
593
594
/**
595
- * Search cache by specific IP address
596
*
597
*/
598
public static function search_cache( $ip ) {
599
- return self::search_table( IP_Geo_Block::CACHE_NAME, $ip );
600
}
601
602
/**
@@ -609,7 +600,7 @@ class IP_Geo_Block_Logs {
609
$result = $wpdb->get_results( "SELECT * FROM `$table`", ARRAY_A ) or self::error( __LINE__ );
610
611
// transform DB to cache format
612
- $cache = $hash = array();
613
foreach ( $result as $key => $val ) {
614
$ip = $val['ip'];
615
unset( $val['ip'] );
@@ -653,7 +644,7 @@ class IP_Geo_Block_Logs {
653
$cache['fail'],
654
$cache['call'],
655
$cache['host']
656
- ) and $wpdb->query( $sql ) or self::error( __LINE__ );
657
}
658
659
/**
@@ -677,14 +668,33 @@ class IP_Geo_Block_Logs {
677
*
678
*/
679
private static function error( $line ) {
680
- global $wpdb;
681
- if ( $wpdb->last_error ) {
682
- if ( class_exists( 'IP_Geo_Block_Admin' ) )
683
IP_Geo_Block_Admin::add_admin_notice( 'error', __FILE__ . ' (' . $line . ') ' . $wpdb->last_error );
684
-
685
- if ( defined( 'IP_GEO_BLOCK_DEBUG' ) && IP_GEO_BLOCK_DEBUG )
686
- error_log( __FILE__ . ' (' . $line . ') ' . $wpdb->last_error );
687
}
688
}
689
690
}
29
'daystats' => array(),
30
);
31
32
+ private static $sqlist = array();
33
+
34
/**
35
* Create
36
*
61
`user_agent` varchar(" . IP_GEO_BLOCK_MAX_STR_LEN . ") NULL,
62
`headers` varchar(" . IP_GEO_BLOCK_MAX_TXT_LEN . ") NULL,
63
`data` text NULL,
64
+ PRIMARY KEY (`No`),
65
KEY `time` (`time`),
66
KEY `hook` (`hook`)
67
+ ) CHARACTER SET " . $charset
68
) ) or self::error( __LINE__ ); // utf8mb4 ENGINE=InnoDB or MyISAM
69
70
// for statistics
72
$result &= ( FALSE !== $wpdb->query( "CREATE TABLE IF NOT EXISTS `$table` (
73
`No` tinyint(4) unsigned NOT NULL AUTO_INCREMENT,
74
`data` longtext NULL,
75
+ PRIMARY KEY (`No`)
76
+ ) CHARACTER SET " . $charset
77
) ) or self::error( __LINE__ ); // utf8mb4 ENGINE=InnoDB or MyISAM
78
79
// Create 1 record if not exists
94
`fail` int(10) unsigned NOT NULL DEFAULT 0,
95
`call` int(10) unsigned NOT NULL DEFAULT 0,
96
`host` tinytext NOT NULL,
97
+ PRIMARY KEY (`No`),
98
+ UNIQUE (`ip`)
99
+ ) CHARACTER SET " . $charset
100
) ) or self::error( __LINE__ ); // utf8mb4 ENGINE=InnoDB or MyISAM
101
102
return $result;
103
}
104
105
/**
106
* Delete
107
*
108
*/
109
+ public static function delete_tables() {
110
global $wpdb;
111
$tables = array( self::TABLE_LOGS, self::TABLE_STAT, IP_Geo_Block::CACHE_NAME );
112
113
foreach ( $tables as $table ) {
114
+ $table = $wpdb->prefix . $table;
115
+ $wpdb->query( "DROP TABLE IF EXISTS `$table`" ) or self::error( __LINE__ );
116
}
117
}
118
177
* Record statistics data.
178
*
179
*/
180
+ public static function record_stat( $statistics ) {
181
global $wpdb;
182
$table = $wpdb->prefix . self::TABLE_STAT;
183
184
+ if ( ! is_array( $statistics ) ) {
185
+ $statistics = self::$default;
186
}
187
188
$sql = $wpdb->prepare(
189
+ "UPDATE `$table` SET `data` = '%s'", serialize( $statistics )
190
+ // "REPLACE INTO `$table` (`No`, `data`) VALUES (%d, %s)", 1, serialize( $statistics )
191
+ ) and self::add_sql( 'stat', $sql ); // $data = $wpdb->query( $sql ) or self::error( __LINE__ );
192
}
193
194
/**
195
+ * Limit the number of rows to send to the user agent
196
*
197
*/
198
public static function limit_rows( $time ) {
199
+ $time = intval( $time );
200
$options = IP_Geo_Block::get_option();
201
+
202
+ if ( $time < 90 /* msec */ )
203
+ return (int)$options['validation']['maxlogs'];
204
+
205
+ elseif ( $time < 200 /* msec */ )
206
+ return (int)($options['validation']['maxlogs'] / 2);
207
+
208
+ return (int)($options['validation']['maxlogs'] / 5);
209
}
210
211
/**
358
359
// XML-RPC
360
if ( 'xmlrpc' === $hook ) {
361
+ // mask the password
362
$posts = self::truncate_utf8(
363
file_get_contents( 'php://input' ), '!\s*([<>])\s*!', '$1', IP_GEO_BLOCK_MAX_STR_LEN
364
);
365
if ( $mask_pwd &&
366
preg_match_all( '/<string>(\S*?)<\/string>/', $posts, $matches ) >= 2 &&
367
strpos( $matches[1][1], home_url() ) !== 0 ) { // except pingback
474
$sql = $wpdb->prepare(
475
"DELETE FROM `$table` WHERE `hook` = '%s' ORDER BY `No` ASC LIMIT %d",
476
$hook, $count - $rows + 1
477
+ ) and self::add_sql( 'logs', $sql ); // $wpdb->query( $sql ) or self::error( __LINE__ );
478
}
479
480
// insert into DB
492
$agent,
493
$heads,
494
$posts
495
+ ) and self::add_sql( 'logs', $sql ); // $wpdb->query( $sql ) or self::error( __LINE__ );
496
497
// backup logs to text files
498
if ( $dir = apply_filters(
515
global $wpdb;
516
$table = $wpdb->prefix . self::TABLE_LOGS;
517