-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopwarstopputin.php
2923 lines (2415 loc) · 110 KB
/
stopwarstopputin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: Stop War! Stop Putin!
* Plugin URI: https://github.com/stopwarstopputin/swsp-wordpress-plugin
* Description: The Stop War! Stop Putin! WordPress Plugin allows you to block all visitors from Russia & Belarus and display a custom message to stand up against Putin and to stop war.
* Version: 1.0
* Author: stopwarstopputin
* Author URI: https://github.com/stopwarstopputin/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
*
* This plugin is a simplified fork built on the basis of the IP2Location Country Blocker WordPress Plugin developed by by Hexasoft Development Sdn. Bhd.
* https://ip2location.com/resources/wordpress-stop_war_stop_putin
*
* The Stop War! Stop Putin! WordPress is in not authorized, associated with or endorsed by Hexasoft Development Sdn. Bhd.
* This site or product includes IP2Location LITE data available from http://www.ip2location.com.
* The IP2Location LITE database is licensed under CC-BY-SA-4.0
*
*/
$upload_dir = wp_upload_dir();
##xx
$plugin_dir = plugin_dir_path( __FILE__ );
defined('FS_METHOD') or define('FS_METHOD', 'direct');
##xx defined('IP2LOCATION_DIR') or define('IP2LOCATION_DIR', str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $upload_dir['basedir']) . DIRECTORY_SEPARATOR . 'ip2location' . DIRECTORY_SEPARATOR);
define('IP2LOCATION_DIR', str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $plugin_dir . 'assets' . DIRECTORY_SEPARATOR ));
define('IPLCB_ROOT', __DIR__ . DIRECTORY_SEPARATOR);
update_option('stopwarstopputin_blocker_database', 'IP2LOCATION-LITE-DB1.BIN');
unset ($block_nations);
$block_nations[] = 'RU';
$block_nations[] = 'BY';
$block_nations[] = 'DE';
update_option('stopwarstopputin_blocker_frontend_banlist', $block_nations);
##defined('FS_METHOD') or define('FS_METHOD', 'direct');
##defined('IP2LOCATION_DIR') or define('IP2LOCATION_DIR', str_replace(['/', '\\'], DIRECTORY_SEPARATOR, ##$upload_dir['basedir']) . DIRECTORY_SEPARATOR . 'ip2location' . DIRECTORY_SEPARATOR);
##define('IPLCB_ROOT', __DIR__ . DIRECTORY_SEPARATOR);
// For development usage.
if (isset($_SERVER['DEV_MODE'])) {
$_SERVER['REMOTE_ADDR'] = '8.8.8.8';
}
require_once IPLCB_ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// Initial Stop_War_Stop_Putin_Blocker class.
$stop_war_stop_putin = new Stop_War_Stop_Putin_Blocker();
register_activation_hook(__FILE__, [$stop_war_stop_putin, 'set_defaults']);
add_action('init', [$stop_war_stop_putin, 'check_block'], 1);
add_action('admin_enqueue_scripts', [$stop_war_stop_putin, 'plugin_enqueues']);
add_action('admin_notices', [$stop_war_stop_putin, 'show_notice']);
add_action('wp_ajax_ip2location_country_blocker_update_ip2location_database', [$stop_war_stop_putin, 'update_ip2location_database']);
add_action('wp_ajax_ip2location_country_blocker_update_ip2proxy_database', [$stop_war_stop_putin, 'update_ip2proxy_database']);
add_action('wp_ajax_ip2location_country_blocker_validate_token', [$stop_war_stop_putin, 'validate_token']);
add_action('wp_footer', [$stop_war_stop_putin, 'footer']);
add_action('wp_ajax_ip2location_country_blocker_submit_feedback', [$stop_war_stop_putin, 'submit_feedback']);
add_action('admin_footer_text', [$stop_war_stop_putin, 'admin_footer_text']);
add_action('ip2location_country_blocker_hourly_event', [$stop_war_stop_putin, 'hourly_event']);
class Stop_War_Stop_Putin_Blocker
{
private $session = [
'country' => '??',
'is_proxy' => '??',
'proxy_type' => '??',
'lookup_mode' => '??',
'cache' => false,
];
private $countries = ['AF' => 'Afghanistan', 'AX' => 'Aland Islands', 'AL' => 'Albania', 'DZ' => 'Algeria', 'AS' => 'American Samoa', 'AD' => 'Andorra', 'AO' => 'Angola', 'AI' => 'Anguilla', 'AQ' => 'Antarctica', 'AG' => 'Antigua and Barbuda', 'AR' => 'Argentina', 'AM' => 'Armenia', 'AW' => 'Aruba', 'AU' => 'Australia', 'AT' => 'Austria', 'AZ' => 'Azerbaijan', 'BS' => 'Bahamas', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BB' => 'Barbados', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BZ' => 'Belize', 'BJ' => 'Benin', 'BM' => 'Bermuda', 'BT' => 'Bhutan', 'BO' => 'Bolivia, Plurinational State of', 'BQ' => 'Bonaire, Sint Eustatius and Saba', 'BA' => 'Bosnia and Herzegovina', 'BW' => 'Botswana', 'BV' => 'Bouvet Island', 'BR' => 'Brazil', 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei Darussalam', 'BG' => 'Bulgaria', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'CV' => 'Cabo Verde', 'KH' => 'Cambodia', 'CM' => 'Cameroon', 'CA' => 'Canada', 'KY' => 'Cayman Islands', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'CL' => 'Chile', 'CN' => 'China', 'CX' => 'Christmas Island', 'CC' => 'Cocos (Keeling) Islands', 'CO' => 'Colombia', 'KM' => 'Comoros', 'CG' => 'Congo', 'CD' => 'Congo, The Democratic Republic of The', 'CK' => 'Cook Islands', 'CR' => 'Costa Rica', 'CI' => 'Cote D\'ivoire', 'HR' => 'Croatia', 'CU' => 'Cuba', 'CW' => 'Curacao', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'DJ' => 'Djibouti', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'EC' => 'Ecuador', 'EG' => 'Egypt', 'SV' => 'El Salvador', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'EE' => 'Estonia', 'ET' => 'Ethiopia', 'FK' => 'Falkland Islands (Malvinas)', 'FO' => 'Faroe Islands', 'FJ' => 'Fiji', 'FI' => 'Finland', 'FR' => 'France', 'GF' => 'French Guiana', 'PF' => 'French Polynesia', 'TF' => 'French Southern Territories', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GE' => 'Georgia', 'DE' => 'Germany', 'GH' => 'Ghana', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GU' => 'Guam', 'GT' => 'Guatemala', 'GG' => 'Guernsey', 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'GY' => 'Guyana', 'HT' => 'Haiti', 'HM' => 'Heard Island and Mcdonald Islands', 'VA' => 'Holy See', 'HN' => 'Honduras', 'HK' => 'Hong Kong', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran, Islamic Republic of', 'IQ' => 'Iraq', 'IE' => 'Ireland', 'IM' => 'Isle of Man', 'IL' => 'Israel', 'IT' => 'Italy', 'JM' => 'Jamaica', 'JP' => 'Japan', 'JE' => 'Jersey', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KE' => 'Kenya', 'KI' => 'Kiribati', 'KP' => 'Korea, Democratic People\'s Republic of', 'KR' => 'Korea, Republic of', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Lao People\'s Democratic Republic', 'LV' => 'Latvia', 'LB' => 'Lebanon', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libya', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MO' => 'Macao', 'MK' => 'Macedonia, The Former Yugoslav Republic of', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'ML' => 'Mali', 'MT' => 'Malta', 'MH' => 'Marshall Islands', 'MQ' => 'Martinique', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MX' => 'Mexico', 'FM' => 'Micronesia, Federated States of', 'MD' => 'Moldova, Republic of', 'MC' => 'Monaco', 'MN' => 'Mongolia', 'ME' => 'Montenegro', 'MS' => 'Montserrat', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'MM' => 'Myanmar', 'NA' => 'Namibia', 'NR' => 'Nauru', 'NP' => 'Nepal', 'NL' => 'Netherlands', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 'NI' => 'Nicaragua', 'NE' => 'Niger', 'NG' => 'Nigeria', 'NU' => 'Niue', 'NF' => 'Norfolk Island', 'MP' => 'Northern Mariana Islands', 'NO' => 'Norway', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PW' => 'Palau', 'PS' => 'Palestine, State of', 'PA' => 'Panama', 'PG' => 'Papua New Guinea', 'PY' => 'Paraguay', 'PE' => 'Peru', 'PH' => 'Philippines', 'PN' => 'Pitcairn', 'PL' => 'Poland', 'PT' => 'Portugal', 'PR' => 'Puerto Rico', 'QA' => 'Qatar', 'RE' => 'Reunion', 'RO' => 'Romania', 'RU' => 'Russian Federation', 'RW' => 'Rwanda', 'BL' => 'Saint Barthelemy', 'SH' => 'Saint Helena, Ascension and Tristan Da Cunha', 'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint Lucia', 'MF' => 'Saint Martin (French Part)', 'PM' => 'Saint Pierre and Miquelon', 'VC' => 'Saint Vincent and The Grenadines', 'WS' => 'Samoa', 'SM' => 'San Marino', 'ST' => 'Sao Tome and Principe', 'SA' => 'Saudi Arabia', 'SN' => 'Senegal', 'RS' => 'Serbia', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SG' => 'Singapore', 'SX' => 'Sint Maarten (Dutch Part)', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'SB' => 'Solomon Islands', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'GS' => 'South Georgia and The South Sandwich Islands', 'SS' => 'South Sudan', 'ES' => 'Spain', 'LK' => 'Sri Lanka', 'SD' => 'Sudan', 'SR' => 'Suriname', 'SJ' => 'Svalbard and Jan Mayen', 'SZ' => 'Eswatini', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'SY' => 'Syrian Arab Republic', 'TW' => 'Taiwan, Province of China', 'TJ' => 'Tajikistan', 'TZ' => 'Tanzania, United Republic of', 'TH' => 'Thailand', 'TL' => 'Timor-Leste', 'TG' => 'Togo', 'TK' => 'Tokelau', 'TO' => 'Tonga', 'TT' => 'Trinidad and Tobago', 'TN' => 'Tunisia', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'TC' => 'Turks and Caicos Islands', 'TV' => 'Tuvalu', 'UG' => 'Uganda', 'UA' => 'Ukraine', 'AE' => 'United Arab Emirates', 'GB' => 'United Kingdom', 'US' => 'United States', 'UM' => 'United States Minor Outlying Islands', 'UY' => 'Uruguay', 'UZ' => 'Uzbekistan', 'VU' => 'Vanuatu', 'VE' => 'Venezuela, Bolivarian Republic of', 'VN' => 'Viet Nam', 'VG' => 'Virgin Islands, British', 'VI' => 'Virgin Islands, U.S.', 'WF' => 'Wallis and Futuna', 'EH' => 'Western Sahara', 'YE' => 'Yemen', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe'];
private $country_groups = [
'APAC' => ['AS', 'AU', 'BD', 'BN', 'BT', 'CC', 'CK', 'CN', 'CX', 'FJ', 'FM', 'GN', 'GU', 'HK', 'ID', 'IN', 'JP', 'KH', 'KI', 'KP', 'KR', 'LA', 'LK', 'MH', 'MM', 'MN', 'MO', 'MP', 'MV', 'MY', 'NC', 'NF', 'NP', 'NR', 'NU', 'NZ', 'PF', 'PH', 'PK', 'PN', 'PW', 'RU', 'SB', 'SG', 'TH', 'TK', 'TL', 'TO', 'TV', 'TW', 'VN', 'VU', 'WF', 'WS'],
'ASEAN' => ['BN', 'CN', 'ID', 'JP', 'KH', 'KR', 'LA', 'MM', 'MY', 'PH', 'SG', 'TH', 'VN'],
'BRIC' => ['BR', 'CN', 'IN', 'RU'],
'BRICS' => ['BR', 'CN', 'IN', 'RU', 'ZA'],
'EAC' => ['BI', 'KE', 'RW', 'SD', 'TZ', 'UG'],
'EFTA' => ['CH', 'IS', 'LI', 'NO'],
'EMEA' => ['AD', 'AE', 'AL', 'AM', 'AO', 'AT', 'AX', 'AZ', 'BA', 'BE', 'BG', 'BH', 'BI', 'BJ', 'BW', 'BY', 'CF', 'CG', 'CH', 'CI', 'CM', 'CV', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DZ', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FO', 'FR', 'GA', 'GB', 'GE', 'GG', 'GH', 'GI', 'GM', 'GN', 'GR', 'HR', 'HU', 'IE', 'IL', 'IM', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JO', 'KE', 'KM', 'KW', 'KZ', 'LB', 'LI', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MG', 'MK', 'ML', 'MR', 'MT', 'MU', 'MW', 'MZ', 'NA', 'NE', 'NL', 'NO', 'OM', 'PL', 'PT', 'QA', 'RE', 'RS', 'RU', 'RW', 'SA', 'SC', 'SD', 'SE', 'SH', 'SI', 'SK', 'SL', 'SM', 'SN', 'ST', 'SY', 'SZ', 'TD', 'TG', 'TN', 'TR', 'TZ', 'UA', 'UG', 'VA', 'YE', 'YT', 'ZA', 'ZM', 'ZW'],
'EU' => ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'OM', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'],
];
private $robots = [
'baidu' => 'Baidu',
'bingbot' => 'Bing',
'feedburner' => 'FeedBurner',
'google' => 'Google',
'msnbot' => 'MSN',
'slurp' => 'Yahoo',
'yandex' => 'Yandex',
];
private $proxy_types = [
'VPN', 'TOR', 'DCH', 'PUB', 'WEB', 'SES',
];
public function __construct()
{
// Set priority
$this->set_priority();
// Check for IP2Location BIN directory.
if (!file_exists(IP2LOCATION_DIR)) {
wp_mkdir_p(IP2LOCATION_DIR);
}
// Check for cache directory.
if (!file_exists(IP2LOCATION_DIR . 'caches')) {
wp_mkdir_p(IP2LOCATION_DIR . 'caches');
}
add_action('admin_menu', [$this, 'add_admin_menu']);
}
public function frontend_page()
{
if (!$this->is_setup_completed()) {
return $this->settings_page();
}
$frontend_status = '';
$enable_frontend = (isset($_POST['submit']) && isset($_POST['enable_frontend'])) ? 1 : (((isset($_POST['submit']) && !isset($_POST['enable_frontend']))) ? 0 : get_option('stopwarstopputin_blocker_frontend_enabled'));
$frontend_block_mode = (isset($_POST['frontend_block_mode'])) ? sanitize_text_field($_POST['frontend_block_mode']) : get_option('stopwarstopputin_blocker_frontend_block_mode');
$frontend_ban_list = (isset($_POST['frontend_ban_list'])) ? $this->sanitize_array($_POST['frontend_ban_list']) : (!isset($_POST['submit']) ? get_option('stopwarstopputin_blocker_frontend_banlist') : '');
$frontend_ban_list = (!is_array($frontend_ban_list)) ? [$frontend_ban_list] : $frontend_ban_list;
$frontend_option = (isset($_POST['frontend_option'])) ? sanitize_text_field($_POST['frontend_option']) : get_option('stopwarstopputin_blocker_frontend_option');
$frontend_error_page = (isset($_POST['frontend_error_page'])) ? sanitize_text_field($_POST['frontend_error_page']) : get_option('stopwarstopputin_blocker_frontend_error_page');
$frontend_redirect_url = (isset($_POST['frontend_redirect_url'])) ? sanitize_text_field($_POST['frontend_redirect_url']) : get_option('stopwarstopputin_blocker_frontend_redirect_url');
$frontend_ip_blacklist = (isset($_POST['frontend_ip_blacklist'])) ? sanitize_text_field($_POST['frontend_ip_blacklist']) : get_option('stopwarstopputin_blocker_frontend_ip_blacklist');
$frontend_ip_whitelist = (isset($_POST['frontend_ip_whitelist'])) ? sanitize_text_field($_POST['frontend_ip_whitelist']) : get_option('stopwarstopputin_blocker_frontend_ip_whitelist');
$enable_frontend_logged_user_whitelist = (isset($_POST['submit']) && isset($_POST['enable_frontend_logged_user_whitelist'])) ? 1 : (((isset($_POST['submit']) && !isset($_POST['enable_frontend_logged_user_whitelist']))) ? 0 : ((get_option('stopwarstopputin_blocker_frontend_whitelist_logged_user') !== false) ? get_option('stopwarstopputin_blocker_frontend_whitelist_logged_user') : 1));
$frontend_skip_bots = (isset($_POST['submit']) && isset($_POST['frontend_skip_bots'])) ? 1 : (((isset($_POST['submit']) && !isset($_POST['frontend_skip_bots']))) ? 0 : get_option('stopwarstopputin_blocker_frontend_skip_bots'));
$frontend_bots_list = (isset($_POST['frontend_bots_list'])) ? $this->sanitize_array($_POST['frontend_bots_list']) : (!isset($_POST['submit']) ? get_option('stopwarstopputin_blocker_frontend_bots_list') : '');
$frontend_bots_list = (!is_array($frontend_bots_list)) ? [$frontend_bots_list] : $frontend_bots_list;
$frontend_block_proxy = (isset($_POST['submit']) && isset($_POST['frontend_block_proxy'])) ? 1 : (((isset($_POST['submit']) && !isset($_POST['frontend_block_proxy']))) ? 0 : get_option('stopwarstopputin_blocker_frontend_block_proxy'));
$frontend_block_proxy_type = (isset($_POST['frontend_block_proxy_type'])) ? $this->sanitize_array($_POST['frontend_block_proxy_type']) : get_option('stopwarstopputin_blocker_frontend_block_proxy_type');
// Sanitize inputs
if (!empty($frontend_ip_whitelist)) {
if (strpos($frontend_ip_whitelist, ';')) {
$parts = explode(';', $frontend_ip_whitelist);
foreach ($parts as $part) {
if (!filter_var(str_replace('*', '0', $part), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_whitelist = '';
break;
}
}
} else {
if (!filter_var(str_replace('*', '0', $frontend_ip_whitelist), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_whitelist = '';
}
}
}
if (!empty($frontend_ip_blacklist)) {
if (strpos($frontend_ip_blacklist, ';')) {
$parts = explode(';', $frontend_ip_blacklist);
foreach ($parts as $part) {
if (!filter_var(str_replace('*', '0', $part), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_blacklist = '';
break;
}
}
} else {
if (!filter_var(str_replace('*', '0', $frontend_ip_blacklist), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_blacklist = '';
}
}
}
if (isset($_POST['submit'])) {
check_admin_referer('save-frontend');
if (!isset($_POST['frontend_block_proxy_type'])) {
$frontend_block_proxy_type = '';
}
if ($frontend_option == 2 && !filter_var($frontend_error_page, FILTER_VALIDATE_URL)) {
$frontend_status = '
<div class="error">
<p><strong>ERROR</strong>: Please choose a custom error page.</p>
</div>';
} elseif ($frontend_option == 3 && !filter_var($frontend_redirect_url, FILTER_VALIDATE_URL)) {
$frontend_status = '
<div class="error">
<p><strong>ERROR</strong>: Please provide a valid URL for redirection.</p>
</div>';
} else {
// Remove country that existed in group to prevent duplicated lookup.
$removed_list = [];
if (($groups = $this->get_group_from_list($frontend_ban_list)) !== false) {
foreach ($groups as $group) {
foreach ($frontend_ban_list as $country_code) {
if ($this->is_in_array($country_code, $this->country_groups[$group])) {
if (($key = array_search($country_code, $frontend_ban_list)) !== false) {
$removed_list[] = $this->get_country_name($country_code);
unset($frontend_ban_list[$key]);
}
}
}
}
}
update_option('stopwarstopputin_blocker_frontend_enabled', $enable_frontend);
update_option('stopwarstopputin_blocker_frontend_block_mode', $frontend_block_mode);
update_option('stopwarstopputin_blocker_frontend_banlist', $frontend_ban_list);
update_option('stopwarstopputin_blocker_frontend_option', $frontend_option);
update_option('stopwarstopputin_blocker_frontend_redirect_url', $frontend_redirect_url);
update_option('stopwarstopputin_blocker_frontend_error_page', $frontend_error_page);
update_option('stopwarstopputin_blocker_frontend_ip_blacklist', $frontend_ip_blacklist);
update_option('stopwarstopputin_blocker_frontend_ip_whitelist', $frontend_ip_whitelist);
update_option('stopwarstopputin_blocker_frontend_whitelist_logged_user', $enable_frontend_logged_user_whitelist);
update_option('stopwarstopputin_blocker_frontend_skip_bots', $frontend_skip_bots);
update_option('stopwarstopputin_blocker_frontend_bots_list', $frontend_bots_list);
update_option('stopwarstopputin_blocker_frontend_block_proxy', $frontend_block_proxy);
update_option('stopwarstopputin_blocker_frontend_block_proxy_type', $frontend_block_proxy_type);
$frontend_status = '
<div class="updated">
<p>Changes saved.</p>
' . ((!empty($removed_list)) ? ('<p>' . implode(', ', $removed_list) . ' has been removed from your list as part of country group.</p>') : '') . '
</div>';
}
}
if (!is_file(IP2LOCATION_DIR . get_option('stopwarstopputin_blocker_database'))) {
$frontend_status .= '
<div class="error">
<p><strong>ERROR</strong>: '. IP2LOCATION_DIR .' ## '. $tmpfile .' Unable to find the IP2Location BIN database! Please <a href="#bin_download">download the BIN database</a> in Settings page.</p>
</div>';
}
if (false) {
$tmpfile = print_r ( get_option('stopwarstopputin_blocker_frontend_bots_list'),true);
$tmpfile1 = get_option('stopwarstopputin_blocker_frontend_enabled');
$frontend_status .= '
<div class="error">
<p><strong>Status X</strong>: '. $tmpfile .' - '. $tmpfile1 .'</p>
</div>';
}
echo '
<div class="wrap">
<h1>Stop War! Stop Putin! WordPress Plugin</h1>
<p>The Stop War! Stop Putin! WordPress Plugin allows you to block all visitors from Russia & Belarus and display a custom message to stand up against Putin and to stop war.</p>
<p>Important: For the Stop War! Stop Putin! WordPress Plugin to work properly, please make sure that you do not have any WordPress Caching Plugins (like WP Rocket, W3 Total Cache, WP Super Cache etc.) activated.</p>
' . $frontend_status . '
<form method="post" novalidate="novalidate">
' . wp_nonce_field('save-frontend') . '
<div style="margin-top:20px">
<label for="enable_frontend">
<input type="checkbox" name="enable_frontend" id="enable_frontend"' . (($enable_frontend) ? ' checked' : '') . '>
Enable Frontend Blocking
</label>
</div>
<div class="postbox" style="margin-top:20px;padding-left:15px;padding-right:15px;padding-bottom:20px;">
<table class="form-table" style="margin-left:20px;">
<h2 class="title" style="padding-bottom:5px">Block By Country</h2>
<tr>
<th scope="row">
<label>Block by country</label>
</th>
<td>
Russian Federation, Belarus
</td>
</tr>
</table>
</div>
<div class="postbox" style="margin-top:20px;padding-left:15px;padding-right:15px;padding-bottom:20px;">
<table class="form-table" style="margin-left:20px;">
<h2 class="title" style="padding-bottom:5px">Other Settings</h2>
<tr>
<th scope="row">
<label>Block by bot</label>
</th>
<td>
<label for="frontend_skip_bots">
<input type="checkbox" name="frontend_skip_bots" id="frontend_skip_bots"' . (($frontend_skip_bots) ? ' checked' : '') . ' class="input-field">
Do not block the below bots and crawlers.
</label>
<div style="margin-top:10px;">
<select name="frontend_bots_list[]" id="frontend_bots_list" data-placeholder="Choose Robot..." multiple="true" class="chosen input-field">';
foreach ($this->robots as $robot_code => $robot_name) {
echo '
<option value="' . esc_attr($robot_code) . '"' . (($this->is_in_array($robot_code, $frontend_bots_list)) ? ' selected' : '') . '> ' . esc_html($robot_name) . '</option>';
}
echo '
</select>
</div>
</td>
</tr>
<tr>
<th scope="row">
<label>Display page when visitor is blocked</label>
</th>
<td>
<div style="margin-bottom:10px;">
<strong>Show the following page when visitor is blocked.</strong>
</div>
<fieldset>
<legend class="screen-reader-text"><span>Error Option</span></legend>
<label>
<input type="radio" name="frontend_option" id="frontend_option_1" value="1"' . (($frontend_option == 1) ? ' checked' : '') . ' class="input-field">
Default Error 403 Page
</label>
<br />
<label>
<input type="radio" name="frontend_option" id="frontend_option_2" value="2"' . (($frontend_option == 2) ? ' checked' : '') . ' class="input-field">
Custom Error Page :
<select name="frontend_error_page" id="frontend_error_page" class="input-field">';
$pages = get_pages(['post_status' => 'publish,private']);
foreach ($pages as $page) {
echo '
<option value="' . esc_attr($page->guid) . '"' . (($frontend_error_page == $page->guid) ? ' selected' : '') . '>' . esc_html($page->post_title) . '</option>';
}
echo '
</select>
</label>
<br />
<label>
<input type="radio" name="frontend_option" id="frontend_option_3" value="3"' . (($frontend_option == 3) ? ' checked' : '') . ' class="input-field" />
URL :
<input type="text" name="frontend_redirect_url" id="frontend_redirect_url" value="' . esc_attr($frontend_redirect_url) . '" class="regular-text code input-field" />
</label>
</fieldset>
</td>
</tr>
</table>
<label for="enable_frontend_logged_user_whitelist">
<input type="checkbox" name="enable_frontend_logged_user_whitelist" id="enable_frontend_logged_user_whitelist"' . (($enable_frontend_logged_user_whitelist) ? ' checked' : '') . ' class="input-field">
Bypass blocking for logged in user.
</label>
</div>
<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes" />
</p>
</form>
<div class="clear"></div>
<input type="hidden" id="support_proxy" value="' . ((get_option('stopwarstopputin_blocker_px_lookup_mode')) ? 1 : 0) . '">
</div>';
}
public function backend_page()
{
if (!$this->is_setup_completed()) {
return $this->settings_page();
}
$backend_status = '';
$enable_backend = (isset($_POST['submit']) && isset($_POST['enable_backend'])) ? 1 : (((isset($_POST['submit']) && !isset($_POST['enable_backend']))) ? 0 : get_option('stopwarstopputin_blocker_backend_enabled'));
$backend_block_mode = (isset($_POST['backend_block_mode'])) ? sanitize_text_field($_POST['backend_block_mode']) : get_option('stopwarstopputin_blocker_backend_block_mode');
$backend_ban_list = (isset($_POST['backend_ban_list'])) ? $this->sanitize_array($_POST['backend_ban_list']) : (!isset($_POST['submit']) ? get_option('stopwarstopputin_blocker_backend_banlist') : '');
$backend_ban_list = (!is_array($backend_ban_list)) ? [$backend_ban_list] : $backend_ban_list;
$backend_option = (isset($_POST['backend_option'])) ? sanitize_text_field($_POST['backend_option']) : get_option('stopwarstopputin_blocker_backend_option');
$backend_error_page = (isset($_POST['backend_error_page'])) ? sanitize_text_field($_POST['backend_error_page']) : get_option('stopwarstopputin_blocker_backend_error_page');
$backend_redirect_url = (isset($_POST['backend_redirect_url'])) ? sanitize_text_field($_POST['backend_redirect_url']) : get_option('stopwarstopputin_blocker_backend_redirect_url');
$bypass_code = (isset($_POST['bypass_code'])) ? sanitize_text_field($_POST['bypass_code']) : get_option('stopwarstopputin_blocker_bypass_code');
$backend_ip_blacklist = (isset($_POST['backend_ip_blacklist'])) ? sanitize_text_field($_POST['backend_ip_blacklist']) : get_option('stopwarstopputin_blocker_backend_ip_blacklist');
$backend_ip_whitelist = (isset($_POST['backend_ip_whitelist'])) ? sanitize_text_field($_POST['backend_ip_whitelist']) : get_option('stopwarstopputin_blocker_backend_ip_whitelist');
$backend_skip_bots = (isset($_POST['submit']) && isset($_POST['backend_skip_bots'])) ? 1 : (((isset($_POST['submit']) && !isset($_POST['backend_skip_bots']))) ? 0 : get_option('stopwarstopputin_blocker_backend_skip_bots'));
$backend_bots_list = (isset($_POST['backend_bots_list'])) ? $this->sanitize_array($_POST['backend_bots_list']) : (!isset($_POST['submit']) ? get_option('stopwarstopputin_blocker_backend_bots_list') : '');
$backend_bots_list = (!is_array($backend_bots_list)) ? [$backend_bots_list] : $backend_bots_list;
$backend_block_proxy = (isset($_POST['submit']) && isset($_POST['backend_block_proxy'])) ? 1 : (((isset($_POST['submit']) && !isset($_POST['backend_block_proxy']))) ? 0 : get_option('stopwarstopputin_blocker_backend_block_proxy'));
$backend_block_proxy_type = (isset($_POST['backend_block_proxy_type'])) ? $this->sanitize_array($_POST['backend_block_proxy_type']) : get_option('stopwarstopputin_blocker_backend_block_proxy_type');
$email_notification = (isset($_POST['email_notification'])) ? sanitize_text_field($_POST['email_notification']) : get_option('stopwarstopputin_blocker_email_notification');
$access_email_notification = (isset($_POST['access_email_notification'])) ? sanitize_text_field($_POST['access_email_notification']) : get_option('stopwarstopputin_blocker_access_email_notification');
// Sanitize inputs
if (!empty($frontend_ip_whitelist)) {
if (strpos($frontend_ip_whitelist, ';')) {
$parts = explode(';', $frontend_ip_whitelist);
foreach ($parts as $part) {
if (!filter_var(str_replace('*', '0', $part), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_whitelist = '';
break;
}
}
} else {
if (!filter_var(str_replace('*', '0', $frontend_ip_whitelist), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_whitelist = '';
}
}
}
if (!empty($frontend_ip_blacklist)) {
if (strpos($frontend_ip_blacklist, ';')) {
$parts = explode(';', $frontend_ip_blacklist);
foreach ($parts as $part) {
if (!filter_var(str_replace('*', '0', $part), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_blacklist = '';
break;
}
}
} else {
if (!filter_var(str_replace('*', '0', $frontend_ip_blacklist), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$frontend_ip_blacklist = '';
}
}
}
$result = $this->get_location($this->get_ip());
$my_country_code = $result['country_code'];
$my_country_name = $result['country_name'];
if (isset($_POST['submit'])) {
check_admin_referer('save-backend');
if (!isset($_POST['backend_block_proxy_type'])) {
$backend_block_proxy_type = '';
}
if ($backend_option == 2 && !filter_var($backend_error_page, FILTER_VALIDATE_URL)) {
$backend_status = '
<div class="error">
<p><strong>ERROR</strong>: Please choose a custom error page.</p>
</div>';
} elseif ($backend_option == 3 && !filter_var($backend_redirect_url, FILTER_VALIDATE_URL)) {
$backend_status = '
<div class="error">
<p><strong>ERROR</strong>: Please provide a valid URL for redirection.</p>
</div>';
} else {
// Remove country that existed in group to prevent duplicated lookup.
$removed_list = [];
if (($groups = $this->get_group_from_list($backend_ban_list)) !== false) {
foreach ($groups as $group) {
foreach ($backend_ban_list as $country_code) {
if ($this->is_in_array($country_code, $this->country_groups[$group])) {
if (($key = array_search($country_code, $backend_ban_list)) !== false) {
$removed_list[] = $this->get_country_name($country_code);
unset($backend_ban_list[$key]);
}
}
}
}
}
update_option('stopwarstopputin_blocker_backend_enabled', $enable_backend);
update_option('stopwarstopputin_blocker_backend_block_mode', $backend_block_mode);
update_option('stopwarstopputin_blocker_backend_banlist', $backend_ban_list);
update_option('stopwarstopputin_blocker_backend_option', $backend_option);
update_option('stopwarstopputin_blocker_backend_redirect_url', $backend_redirect_url);
update_option('stopwarstopputin_blocker_backend_error_page', $backend_error_page);
update_option('stopwarstopputin_blocker_bypass_code', $bypass_code);
update_option('stopwarstopputin_blocker_backend_ip_blacklist', $backend_ip_blacklist);
update_option('stopwarstopputin_blocker_backend_ip_whitelist', $backend_ip_whitelist);
update_option('stopwarstopputin_blocker_backend_skip_bots', $backend_skip_bots);
update_option('stopwarstopputin_blocker_backend_bots_list', $backend_bots_list);
update_option('stopwarstopputin_blocker_backend_block_proxy', $backend_block_proxy);
update_option('stopwarstopputin_blocker_backend_block_proxy_type', $backend_block_proxy_type);
update_option('stopwarstopputin_blocker_access_email_notification', $access_email_notification);
update_option('stopwarstopputin_blocker_email_notification', $email_notification);
$backend_status = '
<div class="updated">
<p>Changes saved.</p>
' . ((!empty($removed_list)) ? ('<p>' . implode(', ', $removed_list) . ' has been removed from your list as part of country group.</p>') : '') . '
</div>';
}
}
if (!is_file(IP2LOCATION_DIR . get_option('stopwarstopputin_blocker_database'))) {
$backend_status .= '
<div class="error">
<p><strong>ERROR</strong>: Unable to find the IP2Location BIN database! Please download the database at at <a href="http://www.ip2location.com/?r=wordpress" target="_blank">IP2Location commercial database</a> | <a href="http://lite.ip2location.com/?r=wordpress" target="_blank">IP2Location LITE database (free edition)</a>.</p>
</div>';
}
echo '
<div class="wrap">
<h1>Backend Settings</h1>
' . $backend_status . '
<form id="form_backend_settings" method="post" novalidate="novalidate">
' . wp_nonce_field('save-backend') . '
<input type="hidden" name="my_country_code" id="my_country_code" value="' . esc_attr($my_country_code) . '" />
<input type="hidden" name="my_country_name" id="my_country_name" value="' . esc_attr($my_country_name) . '" />
<div style="margin-top:20px;">
<label for="enable_backend">
<input type="checkbox" name="enable_backend" id="enable_backend"' . (($enable_backend) ? ' checked' : '') . '>
Enable Backend Blocking
</label>
</div>
<div class="postbox" style="margin-top:20px;padding-left:15px;padding-right:15px;padding-bottom:20px;">
<table class="form-table" style="margin-left:20px;">
<h2 class="title" style="padding-bottom:5px">Block By Country</h2>
<tr>
<th scope="row">
<label>Block by country</label>
</th>
<td>
<fieldset>
<legend class="screen-reader-text"><span>Blocking Mode</span></legend>
<label><input type="radio" name="backend_block_mode" value="1"' . (($backend_block_mode == 1) ? ' checked' : '') . ' class="input-field" /> Block countries listed below.</label><br />
<label><input type="radio" name="backend_block_mode" value="2"' . (($backend_block_mode == 2) ? ' checked' : '') . ' class="input-field" /> Block all countries <strong>except</strong> countries listed below.</label>
</fieldset>
<select name="backend_ban_list[]" id="backend_ban_list" data-placeholder="Choose Country..." multiple="true" class="chosen input-field">';
foreach ($this->country_groups as $group_name => $countries) {
echo '
<option value="' . esc_attr($group_name) . '"' . (($this->is_in_array($group_name, $backend_ban_list)) ? ' selected' : '') . '> ' . esc_html($group_name) . ' Countries</option>';
}
foreach ($this->countries as $country_code => $country_name) {
echo '
<option value="' . esc_attr($country_code) . '"' . (($this->is_in_array($country_code, $backend_ban_list)) ? ' selected' : '') . '> ' . esc_html($country_name) . '</option>';
}
echo '
</select>
<p><strong>Note: </strong> For EU, APAC and other country groupings, please visit <a href="https://github.com/geodatasource/country-grouping-terminology" target="_blank">GeoDataSource Country Grouping Terminology</a> for details.</p>
</td>
</tr>
</table>
</div>
<div class="postbox" style="margin-top:20px;padding-left:15px;padding-right:15px;padding-bottom:20px;">
<table class="form-table" style="margin-left:20px;">
<h2 class="title" style="padding-bottom:5px">Block By Proxy</h2>
<tr>
<th scope="row">
<label>Block by proxy IP</label>
</th>
<td>
<label for="backend_block_proxy">
<input type="checkbox" name="backend_block_proxy" id="backend_block_proxy"' . (($backend_block_proxy) ? ' checked' : '') . ' class="input-field">
Block proxy IP.
</label>
<p class="description">
IP2Proxy Lookup Mode is required for this option. You can enable/disable the IP2Proxy Lookup Mode at the Settings tab.
</p>
</td>
</tr>
<tr>
<th scope="row">
<label>Block by proxy type</label>
</th>
<td>
<label for="backend_block_proxy_type">
Block following proxy type.
</label>
<div style="margin-top:10px">
<select name="backend_block_proxy_type[]" id="backend_block_proxy_type" data-placeholder="Choose Proxy Type..." multiple="true" class="chosen input-field">';
foreach ($this->proxy_types as $proxy_type) {
echo '
<option value="' . esc_attr($proxy_type) . '"' . (($this->is_in_array($proxy_type, $backend_block_proxy_type)) ? ' selected' : '') . '> ' . esc_html($proxy_type) . '</option>';
}
echo '
</select>
<p class="description">
This feature only works with <a href="https://www.ip2location.com/database/ip2proxy#wordpress-wzdicb" target="_blank">IP2Proxy Commercial</a> database.
</p>
</div>
</td>
</tr>
</table>
</div>
<div class="postbox" style="margin-top:20px;padding-left:15px;padding-right:15px;padding-bottom:20px;">
<table class="form-table" style="margin-left:20px;">
<h2 class="title" style="padding-bottom:5px">Other Settings</h2>
<tr>
<th scope="row">
<label>Block by bot</label>
</th>
<td>
<label for="backend_skip_bots">
<input type="checkbox" name="backend_skip_bots" id="backend_skip_bots"' . (($backend_skip_bots) ? ' checked' : '') . ' class="input-field">
Do not block the below bots and crawlers.
</label>
<div style="margin-top:10px">
<select name="backend_bots_list[]" id="backend_bots_list" data-placeholder="Choose Robot..." multiple="true" class="chosen input-field">';
foreach ($this->robots as $robot_code => $robot_name) {
echo '
<option value="' . esc_attr($robot_code) . '"' . (($this->is_in_array($robot_code, $backend_bots_list)) ? ' selected' : '') . '> ' . esc_html($robot_name) . '</option>';
}
echo '
</select>
</div>
</td>
</tr>
<tr>
<th scope="row">
<label>Display page when visitor is blocked</label>
</th>
<td>
<p>
<strong>Show the following page when a visitor is blocked.</strong>
</p>
<fieldset>
<legend class="screen-reader-text"><span>Error Option</span></legend>
<label>
<input type="radio" name="backend_option" id="backend_option_1" value="1"' . (($backend_option == 1) ? ' checked' : '') . ' class="input-field">
Default Error 403 Page
</label>
<br />
<label>
<input type="radio" name="backend_option" id="backend_option_2" value="2"' . (($backend_option == 2) ? ' checked' : '') . ' class="input-field">
Custom Error Page :
<select name="backend_error_page" id="backend_error_page" class="input-field">';
$pages = get_pages(['post_status' => 'publish,private']);
foreach ($pages as $page) {
echo '
<option value="' . esc_attr($page->guid) . '"' . (($backend_error_page == $page->guid) ? ' selected' : '') . '>' . esc_html($page->post_title) . '</option>';
}
echo '
</select>
</label>
<br />
<label>
<input type="radio" name="backend_option" id="backend_option_3" value="3"' . (($backend_option == 3) ? ' checked' : '') . ' class="input-field">
URL :
<input type="text" name="backend_redirect_url" id="backend_redirect_url" value="' . esc_attr($backend_redirect_url) . '" class="regular-text code input-field" />
</label>
</fieldset>
</td>
</tr>
<tr>
<th scope="row">
<label>Secret code to bypass blocking (Max 20 characters)</label>
</th>
<td>
<input type="text" name="bypass_code" id="bypass_code" maxlength="20" value="' . esc_attr($bypass_code) . '" class="regular-text code input-field" />
<p class="description">
This is the secret code used to bypass all blockings to backend pages. It take precedence over all block settings configured. To bypass, you just need to append the <strong>secret_code</strong> parameter with above value to the wp-login.php page. For example, http://www.example.com/wp-login.php<code>?secret_code=1234567</code>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label>Blacklist IP addresses</label>
</th>
<td>
<fieldset>
<legend class="screen-reader-text"><span>Blacklist</span></legend>
<input type="text" name="backend_ip_blacklist" id="backend_ip_blacklist" value="' . esc_attr($backend_ip_blacklist) . '" class="regular-text ip-address-list" />
<p class="description">Use asterisk (*) for wildcard matching. E.g.: 8.8.8.* will match IP from 8.8.8.0 to 8.8.8.255.</p>
</fieldset>
</td>
</tr>
<tr>
<th scope="row">
<label>Whitelist IP addresses</label>
</th>
<td>
<fieldset>
<legend class="screen-reader-text"><span>Blacklist</span></legend>
<input type="text" name="backend_ip_whitelist" id="backend_ip_whitelist" value="' . esc_attr($backend_ip_whitelist) . '" class="regular-text ip-address-list" />
<p class="description">Use asterisk (*) for wildcard matching. E.g.: 8.8.8.* will match IP from 8.8.8.0 to 8.8.8.255.</p>
</fieldset>
</td>
</tr>
<tr>
<th scope="row">
<label for="email_notification">Email Notification</label>
</th>
<td>
<select name="email_notification">
<option value="none"> None</option>';
$users = get_users(['role' => 'administrator']);
foreach ($users as $user) {
echo '
<option value="' . esc_attr($user->user_email) . '"' . (($user->user_email == $email_notification) ? ' selected' : '') . '>' . esc_html($user->display_name) . '</option>';
}
echo '
</select>
<p class="description">
Send email notification to selected recipient when a visitor is blocked.
</p>
</td>
</tr>
</table>
</div>
<p class="submit">
<input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes" />
</p>
</form>
<div class="clear"></div>
<input type="hidden" id="support_proxy" value="' . ((get_option('stopwarstopputin_blocker_px_lookup_mode')) ? 1 : 0) . '">
</div>';
}
public function statistics_page()
{
if (!$this->is_setup_completed()) {
return $this->settings_page();
}
if (isset($_POST['purge'])) {
check_admin_referer('purge-logs');
$GLOBALS['wpdb']->query('TRUNCATE TABLE ' . $GLOBALS['wpdb']->prefix . 'ip2location_country_blocker_log');
}
// Remove logs older than 30 days.
$GLOBALS['wpdb']->query('DELETE FROM ' . $GLOBALS['wpdb']->prefix . 'ip2location_country_blocker_log WHERE date_created <="' . date('Y-m-d H:i:s', strtotime('-30 days')) . '"');
// Prepare logs for last 30 days.
$results = $GLOBALS['wpdb']->get_results('SELECT DATE_FORMAT(date_created, "%Y-%m-%d") AS date, side, COUNT(*) AS total FROM ' . $GLOBALS['wpdb']->prefix . 'ip2location_country_blocker_log GROUP BY date, side ORDER BY date', OBJECT);
$lines = [];
for ($d = 30; $d > 0; --$d) {
$lines[date('Y-m-d', strtotime('-' . $d . ' days'))][1] = 0;
$lines[date('Y-m-d', strtotime('-' . $d . ' days'))][2] = 0;
}
foreach ($results as $result) {
$lines[$result->date][$result->side] = $result->total;
}
ksort($lines);
$labels = [];
$frontend_access = [];
$backend_access = [];
foreach ($lines as $date => $value) {
$labels[] = $date;
$frontend_access[] = (isset($value[1])) ? $value[1] : 0;
$backend_access[] = (isset($value[2])) ? $value[2] : 0;
}
$frontends = ['countries' => [], 'colors' => [], 'totals' => []];
$backends = ['countries' => [], 'colors' => [], 'totals' => []];
// Prepare blocked countries.
$results = $GLOBALS['wpdb']->get_results('SELECT side,country_code, COUNT(*) AS total FROM ' . $GLOBALS['wpdb']->prefix . 'ip2location_country_blocker_log GROUP BY country_code, side ORDER BY total DESC;', OBJECT);
foreach ($results as $result) {
if ($result->side == 1) {
$frontends['countries'][] = addslashes($this->get_country_name($result->country_code));
$frontends['colors'][] = 'get_color()';
$frontends['totals'][] = $result->total;
} else {
$backends['countries'][] = addslashes($this->get_country_name($result->country_code));
$backends['colors'][] = 'get_color()';
$backends['totals'][] = $result->total;
}
}
// Add index to table id not exist.
$results = $GLOBALS['wpdb']->get_results('SELECT COUNT(*) AS total FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "' . $GLOBALS['wpdb']->prefix . 'ip2location_country_blocker_log" AND INDEX_NAME = "idx_ip_address"', OBJECT);
if ($results[0]->total == 0) {
$GLOBALS['wpdb']->query('ALTER TABLE `' . $GLOBALS['wpdb']->prefix . 'ip2location_country_blocker_log` ADD INDEX `idx_ip_address` (`ip_address`);');
}
echo '
<div class="wrap">
<h1>Statistics (Past 30 Days)</h1>
' . ((get_option('stopwarstopputin_blocker_log_enabled')) ? '' : '<div class="update-message notice inline notice-warning notice-alt">Visitor log is disabled. Please enable it in <a href="' . admin_url('admin.php?page=stop_war_stop_putin-settings') . '">Settings</a> page to collect statistics data.</div>') . '
<p>
<canvas id="line_chart" style="width:100%;height:400px"></canvas>
</p>
<p>
<div style="float:left;width:400px;margin-right:30px">';
if (empty($frontends['countries'])) {
echo '
<div style="border:1px solid #E1E1E1;padding:10px;background-color:#fff">No data available.</div>';
} else {
echo '
<canvas id="pie_chart_frontend" style="width:100%;height:300px"></canvas>
<h4>Top 10 IP Address Blocked</h4>
<table class="wp-list-table widefat striped">
<thead>
<tr>
<th>IP Address</th>
<th><div align="center">Country Code</div></th>
<th><div align="right">Total</div></th>
</tr>
</thead>
<tbody>';
$results = $GLOBALS['wpdb']->get_results('SELECT ip_address, country_code, COUNT(*) AS total FROM ' . $GLOBALS['wpdb']->prefix . 'ip2location_country_blocker_log WHERE side = "1" GROUP BY ip_address ORDER BY total DESC LIMIT 10;', OBJECT);
foreach ($results as $result) {
echo '
<tr>
<td>' . esc_html($result->ip_address) . '</td>
<td align="center">' . esc_html($result->country_code) . '</td>
<td align="right">' . esc_html($result->total) . '</td>
</tr>';
}
echo '
</tbody>
</table>';
}
echo '
</div>
</p>
<div class="clear"></div>
<p>
<form id="form-purge" method="post">
' . wp_nonce_field('purge-logs') . '
<input type="hidden" name="purge" value="true">
<input type="submit" name="submit" id="btn-purge" class="button button-primary" value="Purge All Logs" />
</form>
</p>
</div>
<script>
jQuery(document).ready(function($){
function get_color(){
var r = Math.floor(Math.random() * 200);
var g = Math.floor(Math.random() * 200);
var b = Math.floor(Math.random() * 200);
return \'rgb(\' + r + \', \' + g + \', \' + b + \', 0.4)\';
}
var ctx = document.getElementById(\'line_chart\').getContext(\'2d\');
var line = new Chart(ctx, {
type: \'line\',
data: {
labels: [\'' . implode('\', \'', $labels) . '\'],
datasets: [{
label: \'Page Views Blocked\',
data: [' . implode(', ', $frontend_access) . '],
backgroundColor: get_color()
}]
},
options: {
title: {
display: true,
text: \'Access Blocked\'
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});';
if (!empty($frontends['countries'])) {
echo '
var ctx = document.getElementById(\'pie_chart_frontend\').getContext(\'2d\');
var pie = new Chart(ctx, {
type: \'pie\',
data: {
labels: [\'' . implode('\', \'', $frontends['countries']) . '\'],
datasets: [{
backgroundColor: [' . implode(', ', $frontends['colors']) . '],
data: [' . implode(', ', $frontends['totals']) . ']
}]
},
options: {
title: {
display: true,
text: \'Access Blocked By Country\'
}
}
});';
}
if (!empty($backends['countries'])) {
echo '
var ctx = document.getElementById(\'pie_chart_backend\').getContext(\'2d\');
var pie = new Chart(ctx, {
type: \'pie\',
data: {
labels: [\'' . implode('\', \'', $backends['countries']) . '\'],
datasets: [{
backgroundColor: [' . implode(', ', $backends['colors']) . '],
data: [' . implode(', ', $backends['totals']) . ']
}]
},
options: {
title: {
display: true,
text: \'Access Blocked By Country\'
}
}
});';
}
echo '
});
</script>';
}
public function ip_lookup_page()
{
if (!$this->is_setup_completed()) {
return $this->settings_page();
}
$ip_lookup_status = '';
$ip_address = (isset($_POST['ip_address'])) ? sanitize_text_field($_POST['ip_address']) : $this->get_ip();
if (isset($_POST['submit'])) {
check_admin_referer('ip-lookup');
$this->cache_flush();
if (!filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$ip_lookup_status = '
<div class="error">
<p><strong>ERROR</strong>: Please enter an IP address.</p>
</div>';
} else {
$result = $this->get_location($ip_address);
if (empty($result['country_code'])) {
$ip_lookup_status = '
<div class="error">
<p><strong>ERROR</strong>: Unable to lookup IP address <strong>' . htmlspecialchars($ip_address) . '</strong>.</p>
</div>';
} else {
$ip_lookup_status = '
<div class="updated">
<p>IP address <code>' . htmlspecialchars($ip_address) . '</code> belongs to <strong>' . $result['country_name'] . ' (' . $result['country_code'] . ')</strong>.</p>
</div>';
if ($result['is_proxy'] != '') {
$ip_lookup_status .= '
<div class="updated">
<p>Proxy: ' . ucwords(strtolower($result['is_proxy'])) . '</p>
</div>';
}
}
}
}
echo '
<div class="wrap">
<h1>IP Lookup</h1>