PluginProbe
Loginizer / 1.4.7
Loginizer v1.4.7
2.1.0 2.0.9 2.0.8 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 74 releases
loginizer / init.php

init.php in Loginizer 1.4.7, at init.php

2,173 lines 67.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!function_exists('add_action')){
4 echo 'You are not allowed to access this page directly.';
5 exit;
6 }
7
8 define('LOGINIZER_VERSION', '1.4.7');
9 define('LOGINIZER_DIR', dirname(LOGINIZER_FILE));
10 define('LOGINIZER_URL', plugins_url('', LOGINIZER_FILE));
11 define('LOGINIZER_PRO_URL', 'https://loginizer.com/features#compare');
12 define('LOGINIZER_DOCS', 'https://loginizer.com/docs/');
13
14 include_once(LOGINIZER_DIR.'/functions.php');
15
16 // Ok so we are now ready to go
17 register_activation_hook(LOGINIZER_FILE, 'loginizer_activation');
18
19 // Is called when the ADMIN enables the plugin
20 function loginizer_activation(){
21
22 global $wpdb;
23
24 $sql = array();
25
26 $sql[] = "DROP TABLE IF EXISTS `".$wpdb->prefix."loginizer_logs`";
27
28 $sql[] = "CREATE TABLE `".$wpdb->prefix."loginizer_logs` (
29 `username` varchar(255) NOT NULL DEFAULT '',
30 `time` int(10) NOT NULL DEFAULT '0',
31 `count` int(10) NOT NULL DEFAULT '0',
32 `lockout` int(10) NOT NULL DEFAULT '0',
33 `ip` varchar(255) NOT NULL DEFAULT '',
34 `url` varchar(255) NOT NULL DEFAULT '',
35 UNIQUE KEY `ip` (`ip`)
36 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
37
38 foreach($sql as $sk => $sv){
39 $wpdb->query($sv);
40 }
41
42 add_option('loginizer_version', LOGINIZER_VERSION);
43 add_option('loginizer_options', array());
44 add_option('loginizer_last_reset', 0);
45 add_option('loginizer_whitelist', array());
46 add_option('loginizer_blacklist', array());
47
48 }
49
50 // Checks if we are to update ?
51 function loginizer_update_check(){
52
53 global $wpdb;
54
55 $sql = array();
56 $current_version = get_option('loginizer_version');
57
58 // It must be the 1.0 pre stuff
59 if(empty($current_version)){
60 $current_version = get_option('lz_version');
61 }
62
63 $version = (int) str_replace('.', '', $current_version);
64
65 // No update required
66 if($current_version == LOGINIZER_VERSION){
67 return true;
68 }
69
70 // Is it first run ?
71 if(empty($current_version)){
72
73 // Reinstall
74 loginizer_activation();
75
76 // Trick the following if conditions to not run
77 $version = (int) str_replace('.', '', LOGINIZER_VERSION);
78
79 }
80
81 // Is it less than 1.0.1 ?
82 if($version < 101){
83
84 // TODO : GET the existing settings
85
86 // Get the existing settings
87 $lz_failed_logs = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_failed_logs`;", 1);
88 $lz_options = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_options`;", 1);
89 $lz_iprange = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_iprange`;", 1);
90
91 // Delete the three tables
92 $sql = array();
93 $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_failed_logs;";
94 $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_options;";
95 $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_iprange;";
96
97 foreach($sql as $sk => $sv){
98 $wpdb->query($sv);
99 }
100
101 // Delete option
102 delete_option('lz_version');
103
104 // Reinstall
105 loginizer_activation();
106
107 // TODO : Save the existing settings
108
109 // Update the existing failed logs to new table
110 if(is_array($lz_failed_logs)){
111 foreach($lz_failed_logs as $fk => $fv){
112 $wpdb->query("INSERT INTO ".$wpdb->prefix."loginizer_logs SET `username` = '".$fv['username']."', `time` = '".$fv['time']."', `count` = '".$fv['count']."', `lockout` = '".$fv['lockout']."', `ip` = '".$fv['ip']."';");
113 }
114 }
115
116 // Update the existing options to new structure
117 if(is_array($lz_options)){
118 foreach($lz_options as $ok => $ov){
119
120 if($ov['option_name'] == 'lz_last_reset'){
121 update_option('loginizer_last_reset', $ov['option_value']);
122 continue;
123 }
124
125 $old_option[str_replace('lz_', '', $ov['option_name'])] = $ov['option_value'];
126 }
127 // Save the options
128 update_option('loginizer_options', $old_option);
129 }
130
131 // Update the existing iprange to new structure
132 if(is_array($lz_iprange)){
133
134 $old_blacklist = array();
135 $old_whitelist = array();
136 $bid = 1;
137 $wid = 1;
138 foreach($lz_iprange as $ik => $iv){
139
140 if(!empty($iv['blacklist'])){
141 $old_blacklist[$bid] = array();
142 $old_blacklist[$bid]['start'] = long2ip($iv['start']);
143 $old_blacklist[$bid]['end'] = long2ip($iv['end']);
144 $old_blacklist[$bid]['time'] = strtotime($iv['date']);
145 $bid = $bid + 1;
146 }
147
148 if(!empty($iv['whitelist'])){
149 $old_whitelist[$wid] = array();
150 $old_whitelist[$wid]['start'] = long2ip($iv['start']);
151 $old_whitelist[$wid]['end'] = long2ip($iv['end']);
152 $old_whitelist[$wid]['time'] = strtotime($iv['date']);
153 $wid = $wid + 1;
154 }
155 }
156
157 if(!empty($old_blacklist)) update_option('loginizer_blacklist', $old_blacklist);
158 if(!empty($old_whitelist)) update_option('loginizer_whitelist', $old_whitelist);
159 }
160
161 }
162
163 // Is it less than 1.3.9 ?
164 if($version < 139){
165
166 $wpdb->query("ALTER TABLE ".$wpdb->prefix."loginizer_logs ADD `url` VARCHAR(255) NOT NULL DEFAULT '' AFTER `ip`;");
167
168 }
169
170 // Save the new Version
171 update_option('loginizer_version', LOGINIZER_VERSION);
172
173 // In Sitepad Math Captcha is enabled by default
174 if(defined('SITEPAD') && get_option('loginizer_captcha') === false){
175 $option['captcha_no_google'] = 1;
176 add_option('loginizer_captcha', $option);
177 }
178
179 }
180
181 // Add the action to load the plugin
182 add_action('plugins_loaded', 'loginizer_load_plugin');
183
184 // The function that will be called when the plugin is loaded
185 function loginizer_load_plugin(){
186
187 global $loginizer;
188
189 // Check if the installed version is outdated
190 loginizer_update_check();
191
192 // Set the array
193 $loginizer = array();
194
195 $loginizer['prefix'] = !defined('SITEPAD') ? 'Loginizer ' : 'SitePad ';
196 $loginizer['app'] = !defined('SITEPAD') ? 'WordPress' : 'SitePad';
197 $loginizer['login_basename'] = !defined('SITEPAD') ? 'wp-login.php' : 'login.php';
198 $loginizer['wp-includes'] = !defined('SITEPAD') ? 'wp-includes' : 'site-inc';
199
200 // The IP Method to use
201 $loginizer['ip_method'] = get_option('loginizer_ip_method');
202 if($loginizer['ip_method'] == 3){
203 $loginizer['custom_ip_method'] = get_option('loginizer_custom_ip_method');
204 }
205
206 // Load settings
207 $options = get_option('loginizer_options');
208 $loginizer['max_retries'] = empty($options['max_retries']) ? 3 : $options['max_retries'];
209 $loginizer['lockout_time'] = empty($options['lockout_time']) ? 900 : $options['lockout_time']; // 15 minutes
210 $loginizer['max_lockouts'] = empty($options['max_lockouts']) ? 5 : $options['max_lockouts'];
211 $loginizer['lockouts_extend'] = empty($options['lockouts_extend']) ? 86400 : $options['lockouts_extend']; // 24 hours
212 $loginizer['reset_retries'] = empty($options['reset_retries']) ? 86400 : $options['reset_retries']; // 24 hours
213 $loginizer['notify_email'] = empty($options['notify_email']) ? 0 : $options['notify_email'];
214
215 // Default messages
216 $loginizer['d_msg']['inv_userpass'] = 'Incorrect Username or Password';
217 $loginizer['d_msg']['ip_blacklisted'] = 'Your IP has been blacklisted';
218
219 // Message Strings
220 $loginizer['msg'] = get_option('loginizer_msg');
221
222 foreach($loginizer['d_msg'] as $lk => $lv){
223 if(empty($loginizer['msg'][$lk])){
224 $loginizer['msg'][$lk] = $loginizer['d_msg'][$lk];
225 }
226 }
227
228 // Load the blacklist and whitelist
229 $loginizer['blacklist'] = get_option('loginizer_blacklist');
230 $loginizer['whitelist'] = get_option('loginizer_whitelist');
231
232 // When was the database cleared last time
233 $loginizer['last_reset'] = get_option('loginizer_last_reset');
234
235 //print_r($loginizer);
236
237 // Clear retries
238 if((time() - $loginizer['last_reset']) >= $loginizer['reset_retries']){
239 loginizer_reset_retries();
240 }
241
242 $ins_time = get_option('loginizer_ins_time');
243 if(empty($ins_time)){
244 $ins_time = time();
245 update_option('loginizer_ins_time', $ins_time);
246 }
247 $loginizer['ins_time'] = $ins_time;
248
249 // Set the current IP
250 $loginizer['current_ip'] = lz_getip();
251
252 // Is Brute Force Disabled ?
253 $loginizer['disable_brute'] = get_option('loginizer_disable_brute');
254
255 // Filters and actions
256 if(empty($loginizer['disable_brute'])){
257
258 // Use this to verify before WP tries to login
259 // Is always called and is the first function to be called
260 //add_action('wp_authenticate', 'loginizer_wp_authenticate', 10, 2);// Not called by XML-RPC
261 add_filter('authenticate', 'loginizer_wp_authenticate', 10001, 3);// This one is called by xmlrpc as well as GUI
262
263 // Is called when a login attempt fails
264 // Hence Update our records that the login failed
265 add_action('wp_login_failed', 'loginizer_login_failed');
266
267 // Is called before displaying the error message so that we dont show that the username is wrong or the password
268 // Update Error message
269 add_action('wp_login_errors', 'loginizer_error_handler', 10001, 2);
270 add_action('woocommerce_login_failed', 'loginizer_woocommerce_error_handler', 10001);
271
272 }
273
274 // Is the premium features there ?
275 if(file_exists(LOGINIZER_DIR.'/premium.php')){
276
277 // Include the file
278 include_once(LOGINIZER_DIR.'/premium.php');
279
280 loginizer_security_init();
281
282 // Its the free version
283 }else{
284
285 // The promo time
286 $loginizer['promo_time'] = get_option('loginizer_promo_time');
287 if(empty($loginizer['promo_time'])){
288 $loginizer['promo_time'] = time();
289 update_option('loginizer_promo_time', $loginizer['promo_time']);
290 }
291
292 // Are we to show the loginizer promo
293 if(!empty($loginizer['promo_time']) && $loginizer['promo_time'] > 0 && $loginizer['promo_time'] < (time() - (30*24*3600))){
294
295 add_action('admin_notices', 'loginizer_promo');
296
297 }
298
299 // Are we to disable the promo
300 if(isset($_GET['loginizer_promo']) && (int)$_GET['loginizer_promo'] == 0){
301 update_option('loginizer_promo_time', (0 - time()) );
302 die('DONE');
303 }
304
305 }
306
307 }
308
309 // Show the promo
310 function loginizer_promo(){
311
312 echo '
313 <style>
314 .lz_button {
315 background-color: #4CAF50; /* Green */
316 border: none;
317 color: white;
318 padding: 8px 16px;
319 text-align: center;
320 text-decoration: none;
321 display: inline-block;
322 font-size: 16px;
323 margin: 4px 2px;
324 -webkit-transition-duration: 0.4s; /* Safari */
325 transition-duration: 0.4s;
326 cursor: pointer;
327 }
328
329 .lz_button:focus{
330 border: none;
331 color: white;
332 }
333
334 .lz_button1 {
335 color: white;
336 background-color: #4CAF50;
337 border:3px solid #4CAF50;
338 }
339
340 .lz_button1:hover {
341 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
342 color: white;
343 border:3px solid #4CAF50;
344 }
345
346 .lz_button2 {
347 color: white;
348 background-color: #0085ba;
349 }
350
351 .lz_button2:hover {
352 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
353 color: white;
354 }
355
356 .lz_button3 {
357 color: white;
358 background-color: #365899;
359 }
360
361 .lz_button3:hover {
362 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
363 color: white;
364 }
365
366 .lz_button4 {
367 color: white;
368 background-color: rgb(66, 184, 221);
369 }
370
371 .lz_button4:hover {
372 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
373 color: white;
374 }
375
376 .loginizer_promo-close{
377 float:right;
378 text-decoration:none;
379 margin: 5px 10px 0px 0px;
380 }
381
382 .loginizer_promo-close:hover{
383 color: red;
384 }
385 </style>
386
387 <script>
388 jQuery(document).ready( function() {
389 (function($) {
390 $("#loginizer_promo .loginizer_promo-close").click(function(){
391 var data;
392
393 // Hide it
394 $("#loginizer_promo").hide();
395
396 // Save this preference
397 $.post("'.admin_url('?loginizer_promo=0').'", data, function(response) {
398 //alert(response);
399 });
400 });
401 })(jQuery);
402 });
403 </script>
404
405 <div class="notice notice-success" id="loginizer_promo" style="min-height:120px">
406 <a class="loginizer_promo-close" href="javascript:" aria-label="Dismiss this Notice">
407 <span class="dashicons dashicons-dismiss"></span> Dismiss
408 </a>
409 <img src="'.LOGINIZER_URL.'/loginizer-200.png" style="float:left; margin:10px 20px 10px 10px" width="100" />
410 <p style="font-size:16px">We are glad you like Loginizer and have been using it since the past few days. It is time to take the next step </p>
411 <p>
412 <a class="lz_button lz_button1" target="_blank" href="https://loginizer.com/features">Upgrade to Pro</a>
413 <a class="lz_button lz_button2" target="_blank" href="https://wordpress.org/support/view/plugin-reviews/loginizer">Rate it 5�
414 \'s</a>
415 <a class="lz_button lz_button3" target="_blank" href="https://www.facebook.com/Loginizer-815504798591884/">Like Us on Facebook</a>
416 <a class="lz_button lz_button4" target="_blank" href="https://twitter.com/home?status='.rawurlencode('I use @loginizer to secure my #WordPress site - https://loginizer.com').'">Tweet about Loginizer</a>
417 </p>
418 </div>';
419
420 }
421
422 // Should return NULL if everything is fine
423 function loginizer_wp_authenticate($user, $username, $password){
424
425 global $loginizer, $lz_error, $lz_cannot_login, $lz_user_pass;
426
427 if(!empty($username) && !empty($password)){
428 $lz_user_pass = 1;
429 }
430
431 // Are you whitelisted ?
432 if(loginizer_is_whitelisted()){
433 $loginizer['ip_is_whitelisted'] = 1;
434 return $user;
435 }
436
437 // Are you blacklisted ?
438 if(loginizer_is_blacklisted()){
439 $lz_cannot_login = 1;
440 return new WP_Error('ip_blacklisted', implode('', $lz_error), 'loginizer');
441 }
442
443 // Is the username blacklisted ?
444 if(function_exists('loginizer_user_blacklisted')){
445 if(loginizer_user_blacklisted($username)){
446 $lz_cannot_login = 1;
447 return new WP_Error('user_blacklisted', implode('', $lz_error), 'loginizer');
448 }
449 }
450
451 if(loginizer_can_login()){
452 return $user;
453 }
454
455 $lz_cannot_login = 1;
456
457 return new WP_Error('ip_blocked', implode('', $lz_error), 'loginizer');
458
459 }
460
461 function loginizer_can_login(){
462
463 global $wpdb, $loginizer, $lz_error;
464
465 // Get the logs
466 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = '".$loginizer['current_ip']."';");
467
468 if(!empty($result['count']) && ($result['count'] % $loginizer['max_retries']) == 0){
469
470 // Has he reached max lockouts ?
471 if($result['lockout'] >= $loginizer['max_lockouts']){
472 $loginizer['lockout_time'] = $loginizer['lockouts_extend'];
473 }
474
475 // Is he in the lockout time ?
476 if($result['time'] >= (time() - $loginizer['lockout_time'])){
477 $banlift = ceil((($result['time'] + $loginizer['lockout_time']) - time()) / 60);
478
479 //echo 'Current Time '.date('d/M/Y H:i:s P', time()).'<br />';
480 //echo 'Last attempt '.date('d/M/Y H:i:s P', $result['time']).'<br />';
481 //echo 'Unlock Time '.date('d/M/Y H:i:s P', $result['time'] + $loginizer['lockout_time']).'<br />';
482
483 $_time = $banlift.' minute(s)';
484
485 if($banlift > 60){
486 $banlift = ceil($banlift / 60);
487 $_time = $banlift.' hour(s)';
488 }
489
490 $lz_error['ip_blocked'] = 'You have exceeded maximum login retries<br /> Please try after '.$_time;
491
492 return false;
493 }
494 }
495
496 return true;
497 }
498
499 function loginizer_is_blacklisted(){
500
501 global $wpdb, $loginizer, $lz_error;
502
503 $blacklist = $loginizer['blacklist'];
504
505 foreach($blacklist as $k => $v){
506
507 // Is the IP in the blacklist ?
508 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
509 $result = 1;
510 break;
511 }
512
513 // Is it in a wider range ?
514 if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){
515
516 // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi,
517 // if the current IP is <= than the start of the range, it is within the range
518 // OR
519 // if the current IP is <= than the end of the range, it is within the range
520 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip'])
521 || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
522 $result = 1;
523 break;
524 }
525
526 }
527
528 }
529
530 // You are blacklisted
531 if(!empty($result)){
532 $lz_error['ip_blacklisted'] = $loginizer['msg']['ip_blacklisted'];
533 return true;
534 }
535
536 return false;
537
538 }
539
540 function loginizer_is_whitelisted(){
541
542 global $wpdb, $loginizer, $lz_error;
543
544 $whitelist = $loginizer['whitelist'];
545
546 foreach($whitelist as $k => $v){
547
548 // Is the IP in the blacklist ?
549 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
550 $result = 1;
551 break;
552 }
553
554 // Is it in a wider range ?
555 if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){
556
557 // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi,
558 // if the current IP is <= than the start of the range, it is within the range
559 // OR
560 // if the current IP is <= than the end of the range, it is within the range
561 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip'])
562 || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
563 $result = 1;
564 break;
565 }
566
567 }
568
569 }
570
571 // You are whitelisted
572 if(!empty($result)){
573 return true;
574 }
575
576 return false;
577
578 }
579
580
581 // When the login fails, then this is called
582 // We need to update the database
583 function loginizer_login_failed($username){
584
585 global $wpdb, $loginizer, $lz_cannot_login;
586
587 if(empty($lz_cannot_login) && empty($loginizer['ip_is_whitelisted']) && empty($loginizer['no_loginizer_logs'])){
588
589 $url = @addslashes((!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
590 $url = esc_url($url);
591
592 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = '".$loginizer['current_ip']."';");
593
594 if(!empty($result)){
595 $lockout = floor((($result['count']+1) / $loginizer['max_retries']));
596 $sresult = $wpdb->query("UPDATE `".$wpdb->prefix."loginizer_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = `count`+1, `lockout` = '".$lockout."', `url` = '".$url."' WHERE `ip` = '".$loginizer['current_ip']."';");
597
598 // Do we need to email admin ?
599 if(!empty($loginizer['notify_email']) && $lockout >= $loginizer['notify_email']){
600
601 $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname');
602 $mail = array();
603 $mail['to'] = lz_is_multisite() ? get_site_option('admin_email') : get_option('admin_email');
604 $mail['subject'] = 'Failed Login Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')';
605 $mail['message'] = 'Hi,
606
607 '.($result['count']+1).' failed login attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].'
608
609 Last Login Attempt : '.date('d/M/Y H:i:s P', time()).'
610 Last User Attempt : '.$username.'
611 IP has been blocked until : '.date('d/M/Y H:i:s P', time() + $loginizer['lockout_time']).'
612
613 Regards,
614 Loginizer';
615
616 @wp_mail($mail['to'], $mail['subject'], $mail['message']);
617 }
618 }else{
619 $insert = $wpdb->query("INSERT INTO `".$wpdb->prefix."loginizer_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = '1', `ip` = '".$loginizer['current_ip']."', `lockout` = '0', `url` = '".$url."';");
620 }
621
622 // We need to add one as this is a failed attempt as well
623 $result['count'] = $result['count'] + 1;
624 $loginizer['retries_left'] = ($loginizer['max_retries'] - ($result['count'] % $loginizer['max_retries']));
625 $loginizer['retries_left'] = $loginizer['retries_left'] == $loginizer['max_retries'] ? 0 : $loginizer['retries_left'];
626
627 }
628 }
629
630 // Handles the error of the password not being there
631 function loginizer_error_handler($errors, $redirect_to){
632
633 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
634
635 //echo 'loginizer_error_handler :';print_r($errors->errors);echo '<br>';
636
637 // Remove the empty password error
638 if(is_wp_error($errors)){
639
640 $codes = $errors->get_error_codes();
641
642 foreach($codes as $k => $v){
643 if($v == 'invalid_username' || $v == 'incorrect_password'){
644 $show_error = 1;
645 }
646 }
647
648 $errors->remove('invalid_username');
649 $errors->remove('incorrect_password');
650
651 }
652
653 // Add the error
654 if(!empty($lz_user_pass) && !empty($show_error) && empty($lz_cannot_login)){
655 $errors->add('invalid_userpass', '<b>ERROR:</b> ' . $loginizer['msg']['inv_userpass']);
656 }
657
658 // Add the number of retires left as well
659 if(count($errors->get_error_codes()) > 0 && isset($loginizer['retries_left'])){
660 $errors->add('retries_left', loginizer_retries_left());
661 }
662
663 return $errors;
664
665 }
666
667
668
669 // Handles the error of the password not being there
670 function loginizer_woocommerce_error_handler(){
671
672 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
673
674 if(function_exists('wc_add_notice')){
675 wc_add_notice( loginizer_retries_left(), 'error' );
676 }
677
678 }
679
680 // Returns a string with the number of retries left
681 function loginizer_retries_left(){
682
683 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
684
685 // If we are to show the number of retries left
686 if(isset($loginizer['retries_left'])){
687 return '<b>'.$loginizer['retries_left'].'</b> attempt(s) left';
688 }
689
690 }
691
692 function loginizer_reset_retries(){
693
694 global $wpdb, $loginizer;
695
696 $deltime = time() - $loginizer['reset_retries'];
697 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs` WHERE `time` <= '".$deltime."';");
698
699 update_option('loginizer_last_reset', time());
700
701 }
702
703 add_filter("plugin_action_links_$plugin_loginizer", 'loginizer_plugin_action_links');
704
705 // Add settings link on plugin page
706 function loginizer_plugin_action_links($links) {
707
708 if(!defined('LOGINIZER_PREMIUM')){
709 $links[] = '<a href="'.LOGINIZER_PRO_URL.'" style="color:#3db634;" target="_blank">'._x('Upgrade', 'Plugin action link label.', 'loginizer').'</a>';
710 }
711
712 $settings_link = '<a href="admin.php?page=loginizer">Settings</a>';
713 array_unshift($links, $settings_link);
714
715 return $links;
716 }
717
718 add_action('admin_menu', 'loginizer_admin_menu');
719
720 // Shows the admin menu of Loginizer
721 function loginizer_admin_menu() {
722
723 global $wp_version, $loginizer;
724
725 if(!defined('SITEPAD')){
726
727 // Add the menu page
728 add_menu_page(__('Loginizer Dashboard'), __('Loginizer Security'), 'activate_plugins', 'loginizer', 'loginizer_page_dashboard');
729
730 // Dashboard
731 add_submenu_page('loginizer', __('Loginizer Dashboard'), __('Dashboard'), 'activate_plugins', 'loginizer', 'loginizer_page_dashboard');
732
733 }else{
734
735 // Add the menu page
736 add_menu_page(__('Security'), __('Security'), 'activate_plugins', 'loginizer', 'loginizer_page_security', 'dashicons-shield', 85);
737
738 // Rename Login
739 add_submenu_page('loginizer', __('Security Settings'), __('Rename Login'), 'activate_plugins', 'loginizer', 'loginizer_page_security');
740
741 }
742
743 // Brute Force
744 add_submenu_page('loginizer', __('Brute Force Settings'), __('Brute Force'), 'activate_plugins', 'loginizer_brute_force', 'loginizer_page_brute_force');
745
746 if(defined('LOGINIZER_PREMIUM')){
747
748 // PasswordLess
749 add_submenu_page('loginizer', __($loginizer['prefix'].'PasswordLess Settings'), __('PasswordLess'), 'activate_plugins', 'loginizer_passwordless', 'loginizer_page_passwordless');
750
751 // Security Settings
752 if(!defined('SITEPAD')){
753
754 // Two Factor Auth
755 add_submenu_page('loginizer', __($loginizer['prefix'].' Two Factor Authentication'), __('Two Factor Auth'), 'activate_plugins', 'loginizer_2fa', 'loginizer_page_2fa');
756
757 }
758
759 // reCaptcha
760 add_submenu_page('loginizer', __($loginizer['prefix'].'reCAPTCHA Settings'), __('reCAPTCHA'), 'activate_plugins', 'loginizer_recaptcha', 'loginizer_page_recaptcha');
761
762 // Security Settings
763 if(!defined('SITEPAD')){
764
765 // Security Settings
766 add_submenu_page('loginizer', __($loginizer['prefix'].'Security Settings'), __('Security Settings'), 'activate_plugins', 'loginizer_security', 'loginizer_page_security');
767
768 // File Checksums
769 add_submenu_page('loginizer', __('Loginizer File Checksums'), __('File Checksums'), 'activate_plugins', 'loginizer_checksums', 'loginizer_page_checksums');
770
771 }
772
773 }elseif(!defined('LOGINIZER_PREMIUM') && !empty($loginizer['ins_time']) && $loginizer['ins_time'] < (time() - (30*24*3600))){
774
775 // Go Pro link
776 add_submenu_page('loginizer', __('Loginizer Go Pro'), __('Go Pro'), 'activate_plugins', LOGINIZER_PRO_URL);
777
778 }
779
780 }
781
782 // The Loginizer Admin Options Page
783 function loginizer_page_header($title = 'Loginizer'){
784
785 global $loginizer;
786
787 ?>
788 <style>
789 .lz-right-ul{
790 padding-left: 10px !important;
791 }
792
793 .lz-right-ul li{
794 list-style: circle !important;
795 }
796 </style>
797 <?php
798
799 echo '<div style="margin: 10px 20px 0 2px;">
800 <div class="metabox-holder columns-2">
801 <div class="postbox-container">
802 <div id="top-sortables" class="meta-box-sortables ui-sortable">
803
804 <table cellpadding="2" cellspacing="1" width="100%" class="fixed" border="0">
805 <tr>
806 <td valign="top"><h3>'.$loginizer['prefix'].$title.'</h3></td>';
807
808 if(!defined('SITEPAD')){
809
810 echo '<td align="right"><a target="_blank" class="button button-primary" href="https://wordpress.org/support/view/plugin-reviews/loginizer">Review Loginizer</a></td>
811 <td align="right" width="40"><a target="_blank" href="https://twitter.com/loginizer"><img src="'.LOGINIZER_URL.'/twitter.png" /></a></td>
812 <td align="right" width="40"><a target="_blank" href="https://www.facebook.com/Loginizer-815504798591884"><img src="'.LOGINIZER_URL.'/facebook.png" /></a></td>';
813
814 }
815
816 echo '
817 </tr>
818 </table>
819 <hr />
820
821 <!--Main Table-->
822 <table cellpadding="8" cellspacing="1" width="100%" class="fixed">
823 <tr>
824 <td valign="top">';
825
826 }
827
828 // The Loginizer Theme footer
829 function loginizer_page_footer(){
830
831 echo '</td>
832 <td width="200" valign="top" id="loginizer-right-bar">';
833
834 if(!defined('SITEPAD')){
835
836 if(!defined('LOGINIZER_PREMIUM')){
837
838 echo '
839 <div class="postbox" style="min-width:0px !important;">
840 <h2 class="hndle ui-sortable-handle">
841 <span>Premium Version</span>
842 </h2>
843 <div class="inside">
844 <i>Upgrade to the premium version and get the following features </i>:<br>
845 <ul class="lz-right-ul">
846 <li>PasswordLess Login</li>
847 <li>Two Factor Auth - Email</li>
848 <li>Two Factor Auth - App</li>
849 <li>Login Challenge Question</li>
850 <li>reCAPTCHA</li>
851 <li>Rename Login Page</li>
852 <li>Disable XML-RPC</li>
853 <li>And many more ...</li>
854 </ul>
855 <center><a class="button button-primary" href="https://loginizer.com/pricing">Upgrade</a></center>
856 </div>
857 </div>';
858
859 }else{
860
861 echo '
862 <div class="postbox" style="min-width:0px !important;">
863 <h2 class="hndle ui-sortable-handle">
864 <span>Recommendations</span>
865 </h2>
866 <div class="inside">
867 <i>We recommed that you enable atleast one of the following security features</i>:<br>
868 <ul class="lz-right-ul">
869 <li>Rename Login Page</li>
870 <li>Login Challenge Question</li>
871 <li>reCAPTCHA</li>
872 <li>Two Factor Auth - Email</li>
873 <li>Two Factor Auth - App</li>
874 <li>Change \'admin\' Username</li>
875 </ul>
876 </div>
877 </div>';
878 }
879
880 echo '
881 <div class="postbox" style="min-width:0px !important;">
882 <h2 class="hndle ui-sortable-handle">
883 <span><a target="_blank" href="https://pagelayer.com/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/pagelayer_product.png" width="100%" /></a></span>
884 </h2>
885 <div class="inside">
886 <i>Easily manage and make professional pages and content with our Pagelayer builder </i>:<br>
887 <ul class="lz-right-ul">
888 <li>30+ Free Widgets</li>
889 <li>60+ Premium Widgets</li>
890 <li>400+ Premium Sections</li>
891 <li>Theme Builder</li>
892 <li>WooCommerce Builder</li>
893 <li>Theme Creator and Exporter</li>
894 <li>Form Builder</li>
895 <li>Popup Builder</li>
896 <li>And many more ...</li>
897 </ul>
898 <center><a class="button button-primary" target="_blank" href="https://wordpress.org/plugins/pagelayer/">Visit Pagelayer</a></center>
899 </div>
900 </div>';
901
902 echo '
903 <div class="postbox" style="min-width:0px !important;">
904 <h2 class="hndle ui-sortable-handle">
905 <span><a target="_blank" href="https://wpcentral.co/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/wpcentral_product.png" width="100%" /></a></span>
906 </h2>
907 <div class="inside">
908 <i>Manage all your WordPress sites from <b>1 dashboard</b> </i>:<br>
909 <ul class="lz-right-ul">
910 <li>1-click Admin Access</li>
911 <li>Update WordPress</li>
912 <li>Update Themes</li>
913 <li>Update Plugins</li>
914 <li>Backup your WordPress Site</li>
915 <li>Plugins & Theme Management</li>
916 <li>Post Management</li>
917 <li>And many more ...</li>
918 </ul>
919 <center><a class="button button-primary" target="_blank" href="https://wpcentral.co/?from=loginizer-plugin">Visit wpCentral</a></center>
920 </div>
921 </div>';
922
923 }
924
925 echo '</td>
926 </tr>
927 </table>';
928
929 if(!defined('SITEPAD')){
930
931 echo '<br />
932 <div style="width:45%;background:#FFF;padding:15px; margin:auto">
933 <b>Let your friends know that you have secured your website :</b>
934 <form method="get" action="https://twitter.com/intent/tweet" id="tweet" onsubmit="return dotweet(this);">
935 <textarea name="text" cols="45" row="3" style="resize:none;">I just secured my @WordPress site against #bruteforce using @loginizer</textarea>
936 &nbsp; &nbsp; <input type="submit" value="Tweet!" class="button button-primary" onsubmit="return false;" id="twitter-btn" style="margin-top:20px;"/>
937 </form>
938
939 </div>
940 <br />
941
942 <script>
943 function dotweet(ele){
944 window.open(jQuery("#"+ele.id).attr("action")+"?"+jQuery("#"+ele.id).serialize(), "_blank", "scrollbars=no, menubar=no, height=400, width=500, resizable=yes, toolbar=no, status=no");
945 return false;
946 }
947 </script>
948
949 <hr />
950 <a href="http://loginizer.com" target="_blank">Loginizer</a> v'.LOGINIZER_VERSION.'. You can report any bugs <a href="http://wordpress.org/support/plugin/loginizer" target="_blank">here</a>.';
951
952 }
953
954 echo '
955 </div>
956 </div>
957 </div>
958 </div>';
959
960 }
961
962 // The Loginizer Admin Options Page
963 function loginizer_page_dashboard(){
964
965 global $loginizer, $lz_error, $lz_env;
966
967 if(!current_user_can('manage_options')){
968 wp_die('Sorry, but you do not have permissions to change settings.');
969 }
970
971 // Dismiss the announcement
972 if(isset($_GET['dismiss_announcement'])){
973 update_option('loginizer_no_announcement', 1);
974 }
975
976 /* Make sure post was from this page */
977 if(count($_POST) > 0){
978 check_admin_referer('loginizer-options');
979 }
980
981 // Is there a license key ?
982 if(isset($_POST['save_lz'])){
983
984 $license = lz_optpost('lz_license');
985
986 // Check if its a valid license
987 if(empty($license)){
988 $lz_error['lic_invalid'] = __('The license key was not submitted', 'loginizer');
989 return loginizer_page_dashboard_T();
990 }
991
992 $resp = wp_remote_get(LOGINIZER_API.'license.php?license='.$license, array('timeout' => 30));
993
994 if(is_array($resp)){
995 $json = json_decode($resp['body'], true);
996 //print_r($json);
997 }else{
998
999 $lz_error['resp_invalid'] = __('The response was malformed<br>'.var_export($resp, true), 'loginizer');
1000 return loginizer_page_dashboard_T();
1001
1002 }
1003
1004 // Save the License
1005 if(empty($json['license'])){
1006
1007 $lz_error['lic_invalid'] = __('The license key is invalid', 'loginizer');
1008 return loginizer_page_dashboard_T();
1009
1010 }else{
1011
1012 update_option('loginizer_license', $json);
1013
1014 // Mark as saved
1015 $GLOBALS['lz_saved'] = true;
1016 }
1017
1018 }
1019
1020
1021 // Is there a IP Method ?
1022 if(isset($_POST['save_lz_ip_method'])){
1023
1024 $ip_method = (int) lz_optpost('lz_ip_method');
1025 $custom_ip_method = lz_optpost('lz_custom_ip_method');
1026
1027 if($ip_method >= 0 && $ip_method <= 3){
1028 update_option('loginizer_ip_method', $ip_method);
1029 }
1030
1031 // Custom Method name ?
1032 if($ip_method == 3){
1033 update_option('loginizer_custom_ip_method', $custom_ip_method);
1034 }
1035
1036 }
1037
1038 loginizer_page_dashboard_T();
1039
1040 }
1041
1042 // The Loginizer Admin Options Page - THEME
1043 function loginizer_page_dashboard_T(){
1044
1045 global $loginizer, $lz_error, $lz_env;
1046
1047 loginizer_page_header('Dashboard');
1048 ?>
1049 <style>
1050 .welcome-panel{
1051 margin: 0px;
1052 padding: 10px;
1053 }
1054
1055 input[type="text"], textarea, select {
1056 width: 70%;
1057 }
1058
1059 .form-table label{
1060 font-weight:bold;
1061 }
1062
1063 .exp{
1064 font-size:12px;
1065 }
1066 </style>
1067
1068 <?php
1069
1070 $hide_announcement = get_option('loginizer_no_announcement');
1071 if(empty($hide_announcement)){
1072 echo '<div id="message" class="welcome-panel">'. __('<a href="https://loginizer.com/blog/loginizer-has-been-acquired-by-softaculous/" target="_blank" style="text-decoration:none;">We are excited to announce that we have joined forces with Softaculous and have been acquired by them 😊. Read full announcement here.</a>', 'loginizer'). '<a class="welcome-panel-close" style="top:3px;right:2px;" href="'.menu_page_url('loginizer', false).'&dismiss_announcement=1" aria-label="Dismiss announcement"></a></div><br />';
1073 }
1074
1075 echo '<script src="https://api.loginizer.com/'.(defined('LOGINIZER_PREMIUM') ? 'news_security.js' : 'news.js').'"></script><br>';
1076
1077 // Saved ?
1078 if(!empty($GLOBALS['lz_saved'])){
1079 echo '<div id="message" class="updated"><p>'. __('The settings were saved successfully', 'loginizer'). '</p></div><br />';
1080 }
1081
1082 // Any errors ?
1083 if(!empty($lz_error)){
1084 lz_report_error($lz_error);echo '<br />';
1085 }
1086
1087 ?>
1088
1089 <div class="postbox">
1090
1091 <button class="handlediv button-link" aria-expanded="true" type="button">
1092 <span class="screen-reader-text">Toggle panel: Getting Started</span>
1093 <span class="toggle-indicator" aria-hidden="true"></span>
1094 </button>
1095
1096 <h2 class="hndle ui-sortable-handle">
1097 <span><?php echo __('Getting Started', 'loginizer'); ?></span>
1098 </h2>
1099
1100 <div class="inside">
1101
1102 <form action="" method="post" enctype="multipart/form-data">
1103 <?php wp_nonce_field('loginizer-options'); ?>
1104 <table class="form-table">
1105 <tr>
1106 <td scope="row" valign="top" colspan="2" style="line-height:150%">
1107 <i>Welcome to Loginizer Security. By default the <b>Brute Force Protection</b> is immediately enabled. You should start by going over the default settings and tweaking them as per your needs.</i>
1108 <?php
1109 if(defined('LOGINIZER_PREMIUM')){
1110 echo '<br><i>In the Premium version of Loginizer you have many more features. We recommend you enable features like <b>reCAPTCHA, Two Factor Auth or Email based PasswordLess</b> login. These features will improve your websites security.</i>';
1111 }
1112 ?>
1113 </td>
1114 </tr>
1115 </table>
1116 </form>
1117
1118 </div>
1119 </div>
1120
1121 <div class="postbox">
1122
1123 <button class="handlediv button-link" aria-expanded="true" type="button">
1124 <span class="screen-reader-text">Toggle panel: System Information</span>
1125 <span class="toggle-indicator" aria-hidden="true"></span>
1126 </button>
1127
1128 <h2 class="hndle ui-sortable-handle">
1129 <span><?php echo __('System Information', 'loginizer'); ?></span>
1130 </h2>
1131
1132 <div class="inside">
1133
1134 <form action="" method="post" enctype="multipart/form-data">
1135 <?php wp_nonce_field('loginizer-options'); ?>
1136 <table class="wp-list-table fixed striped users" cellspacing="1" border="0" width="95%" cellpadding="10" align="center">
1137 <?php
1138 echo '
1139 <tr>
1140 <th align="left" width="25%">'.__('Loginizer Version', 'loginizer').'</th>
1141 <td>'.LOGINIZER_VERSION.(defined('LOGINIZER_PREMIUM') ? ' (Security PRO Version)' : '').'</td>
1142 </tr>';
1143
1144 if(defined('LOGINIZER_PREMIUM')){
1145 echo '
1146 <tr>
1147 <th align="left" valign="top">'.__('Loginizer License', 'loginizer').'</th>
1148 <td align="left">
1149 '.(empty($loginizer['license']) ? '<span style="color:red">Unlicensed</span> &nbsp; &nbsp;' : '').'
1150 <input type="text" name="lz_license" value="'.(empty($loginizer['license']) ? '' : $loginizer['license']['license']).'" size="30" placeholder="e.g. WXCSE-SFJJX-XXXXX-AAAAA-BBBBB" style="width:300px;" /> &nbsp;
1151 <input name="save_lz" class="button button-primary" value="Update License" type="submit" />';
1152
1153 if(!empty($loginizer['license'])){
1154
1155 $expires = $loginizer['license']['expires'];
1156 $expires = substr($expires, 0, 4).'/'.substr($expires, 4, 2).'/'.substr($expires, 6);
1157
1158 echo '<div style="margin-top:10px;">License Active : '.(empty($loginizer['license']['active']) ? '<span style="color:red">No</span>' : 'Yes').' &nbsp; &nbsp; &nbsp;
1159 License Expires : '.($loginizer['license']['expires'] <= date('Ymd') ? '<span style="color:red">'.$expires.'</span>' : $expires).'
1160 </div>';
1161 }
1162
1163
1164 echo
1165 '</td>
1166 </tr>';
1167 }
1168
1169 echo '<tr>
1170 <th align="left">'.__('URL', 'loginizer').'</th>
1171 <td>'.get_site_url().'</td>
1172 </tr>
1173 <tr>
1174 <th align="left">'.__('Path', 'loginizer').'</th>
1175 <td>'.ABSPATH.'</td>
1176 </tr>
1177 <tr>
1178 <th align="left">'.__('Server\'s IP Address', 'loginizer').'</th>
1179 <td>'.@$_SERVER['SERVER_ADDR'].'</td>
1180 </tr>
1181 <tr>
1182 <th align="left">'.__('Your IP Address', 'loginizer').'</th>
1183 <td>'.lz_getip().'
1184 <div style="float:right">
1185 Method :
1186 <select name="lz_ip_method" id="lz_ip_method" style="font-size:11px; width:150px" onchange="lz_ip_method_handle()">
1187 <option value="0" '.lz_POSTselect('lz_ip_method', 0, (@$loginizer['ip_method'] == 0)).'>REMOTE_ADDR</option>
1188 <option value="1" '.lz_POSTselect('lz_ip_method', 1, (@$loginizer['ip_method'] == 1)).'>HTTP_X_FORWARDED_FOR</option>
1189 <option value="2" '.lz_POSTselect('lz_ip_method', 2, (@$loginizer['ip_method'] == 2)).'>HTTP_CLIENT_IP</option>
1190 <option value="3" '.lz_POSTselect('lz_ip_method', 3, (@$loginizer['ip_method'] == 3)).'>CUSTOM</option>
1191 </select>
1192 <input name="lz_custom_ip_method" id="lz_custom_ip_method" type="text" value="'.lz_optpost('lz_custom_ip_method', @$loginizer['custom_ip_method']).'" style="font-size:11px; width:100px; display:none" />
1193 <input name="save_lz_ip_method" class="button button-primary" value="Save" type="submit" />
1194 </div>
1195 </td>
1196 </tr>
1197 <tr>
1198 <th align="left">'.__('wp-config.php is writable', 'loginizer').'</th>
1199 <td>'.(is_writable(ABSPATH.'/wp-config.php') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1200 </tr>';
1201
1202 if(file_exists(ABSPATH.'/.htaccess')){
1203 echo '
1204 <tr>
1205 <th align="left">'.__('.htaccess is writable', 'loginizer').'</th>
1206 <td>'.(is_writable(ABSPATH.'/.htaccess') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1207 </tr>';
1208
1209 }
1210
1211 ?>
1212 </table>
1213 </form>
1214
1215 </div>
1216 </div>
1217
1218 <script type="text/javascript">
1219
1220 function lz_ip_method_handle(){
1221 var ele = jQuery('#lz_ip_method');
1222 if(ele.val() == 3){
1223 jQuery('#lz_custom_ip_method').show();
1224 }else{
1225 jQuery('#lz_custom_ip_method').hide();
1226 }
1227 };
1228
1229 lz_ip_method_handle();
1230
1231 </script>
1232
1233 <div id="" class="postbox">
1234
1235 <button class="handlediv button-link" aria-expanded="true" type="button">
1236 <span class="screen-reader-text">Toggle panel: File Permissions</span>
1237 <span class="toggle-indicator" aria-hidden="true"></span>
1238 </button>
1239
1240 <h2 class="hndle ui-sortable-handle">
1241 <span><?php echo __('File Permissions', 'loginizer'); ?></span>
1242 </h2>
1243
1244 <div class="inside">
1245
1246 <form action="" method="post" enctype="multipart/form-data">
1247 <?php wp_nonce_field('loginizer-options'); ?>
1248 <table class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1249 <?php
1250
1251 echo '
1252 <tr>
1253 <th style="background:#EFEFEF;">'.__('Relative Path', 'loginizer').'</th>
1254 <th style="width:10%; background:#EFEFEF;">'.__('Suggested', 'loginizer').'</th>
1255 <th style="width:10%; background:#EFEFEF;">'.__('Actual', 'loginizer').'</th>
1256 </tr>';
1257
1258 $wp_content = basename(dirname(dirname(dirname(__FILE__))));
1259
1260 $files_to_check = array('/' => '0755',
1261 '/wp-admin' => '0755',
1262 '/wp-includes' => '0755',
1263 '/wp-config.php' => '0444',
1264 '/'.$wp_content => '0755',
1265 '/'.$wp_content.'/themes' => '0755',
1266 '/'.$wp_content.'/plugins' => '0755',
1267 '.htaccess' => '0444');
1268
1269 $root = ABSPATH;
1270
1271 foreach($files_to_check as $k => $v){
1272
1273 $path = $root.'/'.$k;
1274 $stat = @stat($path);
1275 $suggested = $v;
1276 $actual = substr(sprintf('%o', $stat['mode']), -4);
1277
1278 echo '
1279 <tr>
1280 <td>'.$k.'</td>
1281 <td>'.$suggested.'</td>
1282 <td><span '.($suggested != $actual ? 'style="color: red;"' : '').'>'.$actual.'</span></td>
1283 </tr>';
1284
1285 }
1286
1287 ?>
1288 </table>
1289 </form>
1290
1291 </div>
1292 </div>
1293
1294 <?php
1295
1296 loginizer_page_footer();
1297
1298 }
1299
1300 // The Loginizer Admin Options Page
1301 function loginizer_page_brute_force(){
1302
1303 global $wpdb, $wp_roles, $loginizer;
1304
1305 if(!current_user_can('manage_options')){
1306 wp_die('Sorry, but you do not have permissions to change settings.');
1307 }
1308
1309 /* Make sure post was from this page */
1310 if(count($_POST) > 0){
1311 check_admin_referer('loginizer-options');
1312 }
1313
1314 // BEGIN THEME
1315 loginizer_page_header('Brute Force Settings');
1316
1317 // Load the blacklist and whitelist
1318 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1319 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1320
1321 // Disable Brute Force
1322 if(isset($_POST['disable_brute_lz'])){
1323
1324 // Save the options
1325 update_option('loginizer_disable_brute', 1);
1326
1327 $loginizer['disable_brute'] = 1;
1328
1329 echo '<div id="message" class="updated"><p>'
1330 . __('The Brute Force Protection feature is now disabled', 'loginizer')
1331 . '</p></div><br />';
1332
1333 }
1334
1335 // Enable brute force
1336 if(isset($_POST['enable_brute_lz'])){
1337
1338 // Save the options
1339 update_option('loginizer_disable_brute', 0);
1340
1341 $loginizer['disable_brute'] = 0;
1342
1343 echo '<div id="message" class="updated"><p>'
1344 . __('The Brute Force Protection feature is now enabled', 'loginizer')
1345 . '</p></div><br />';
1346
1347 }
1348
1349 // The Brute Force Settings
1350 if(isset($_POST['save_lz'])){
1351
1352 $max_retries = (int) lz_optpost('max_retries');
1353 $lockout_time = (int) lz_optpost('lockout_time');
1354 $max_lockouts = (int) lz_optpost('max_lockouts');
1355 $lockouts_extend = (int) lz_optpost('lockouts_extend');
1356 $reset_retries = (int) lz_optpost('reset_retries');
1357 $notify_email = (int) lz_optpost('notify_email');
1358
1359 $lockout_time = $lockout_time * 60;
1360 $lockouts_extend = $lockouts_extend * 60 * 60;
1361 $reset_retries = $reset_retries * 60 * 60;
1362
1363 if(empty($error)){
1364
1365 $option['max_retries'] = $max_retries;
1366 $option['lockout_time'] = $lockout_time;
1367 $option['max_lockouts'] = $max_lockouts;
1368 $option['lockouts_extend'] = $lockouts_extend;
1369 $option['reset_retries'] = $reset_retries;
1370 $option['notify_email'] = $notify_email;
1371
1372 // Save the options
1373 update_option('loginizer_options', $option);
1374
1375 $saved = true;
1376
1377 }else{
1378 lz_report_error($error);
1379 }
1380
1381 if(!empty($notice)){
1382 lz_report_notice($notice);
1383 }
1384
1385 if(!empty($saved)){
1386 echo '<div id="message" class="updated"><p>'
1387 . __('The settings were saved successfully', 'loginizer')
1388 . '</p></div><br />';
1389 }
1390
1391 }
1392
1393 // Delete a Blackist IP range
1394 if(isset($_POST['bdelid'])){
1395
1396 $delid = (int) lz_optreq('bdelid');
1397
1398 // Unset and save
1399 $blacklist = $loginizer['blacklist'];
1400 unset($blacklist[$delid]);
1401 update_option('loginizer_blacklist', $blacklist);
1402
1403 echo '<div id="message" class="updated fade"><p>'
1404 . __('The Blacklist IP range has been deleted successfully', 'loginizer')
1405 . '</p></div><br />';
1406
1407 }
1408
1409 // Delete all Blackist IP ranges
1410 if(isset($_POST['del_all_blacklist'])){
1411
1412 // Unset and save
1413 update_option('loginizer_blacklist', array());
1414
1415 echo '<div id="message" class="updated fade"><p>'
1416 . __('The Blacklist IP range(s) have been cleared successfully', 'loginizer')
1417 . '</p></div><br />';
1418
1419 }
1420
1421 // Delete a Whitelist IP range
1422 if(isset($_POST['delid'])){
1423
1424 $delid = (int) lz_optreq('delid');
1425
1426 // Unset and save
1427 $whitelist = $loginizer['whitelist'];
1428 unset($whitelist[$delid]);
1429 update_option('loginizer_whitelist', $whitelist);
1430
1431 echo '<div id="message" class="updated fade"><p>'
1432 . __('The Whitelist IP range has been deleted successfully', 'loginizer')
1433 . '</p></div><br />';
1434
1435 }
1436
1437 // Delete all Blackist IP ranges
1438 if(isset($_POST['del_all_whitelist'])){
1439
1440 // Unset and save
1441 update_option('loginizer_whitelist', array());
1442
1443 echo '<div id="message" class="updated fade"><p>'
1444 . __('The Whitelist IP range(s) have been cleared successfully', 'loginizer')
1445 . '</p></div><br />';
1446
1447 }
1448
1449 // Reset All Logs
1450 if(isset($_POST['lz_reset_all_ip'])){
1451
1452 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1453 WHERE `time` > 0");
1454
1455 echo '<div id="message" class="updated fade"><p>'
1456 . __('All the IP Logs have been cleared', 'loginizer')
1457 . '</p></div><br />';
1458 }
1459
1460 // Reset Logs
1461 if(isset($_POST['lz_reset_ips']) && is_array($_POST['lz_reset_ips'])){
1462
1463 $ips = $_POST['lz_reset_ips'];
1464
1465 foreach($ips as $ip){
1466 if(!lz_valid_ip($ip)){
1467 $error[] = 'The IP - '.$ip.' is invalid !';
1468 }
1469 }
1470
1471 if(count($ips) < 1){
1472 $error[] = 'There are no IPs submitted';
1473 }
1474
1475 // Should we start deleting logs
1476 if(empty($error)){
1477
1478 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1479 WHERE `ip` IN ('".implode("', '", $ips)."')");
1480
1481 if(empty($error)){
1482
1483 echo '<div id="message" class="updated fade"><p>'
1484 . __('The selected IP Logs have been reset', 'loginizer')
1485 . '</p></div><br />';
1486
1487 }
1488
1489 }
1490
1491 if(!empty($error)){
1492 lz_report_error($error);echo '<br />';
1493 }
1494
1495 }
1496
1497 if(isset($_POST['blacklist_iprange'])){
1498
1499 $start_ip = lz_optpost('start_ip');
1500 $end_ip = lz_optpost('end_ip');
1501
1502 if(empty($start_ip)){
1503 $error[] = 'Please enter the Start IP';
1504 }
1505
1506 // If no end IP we consider only 1 IP
1507 if(empty($end_ip)){
1508 $end_ip = $start_ip;
1509 }
1510
1511 if(!lz_valid_ip($start_ip)){
1512 $error[] = 'Please provide a valid start IP';
1513 }
1514
1515 if(!lz_valid_ip($end_ip)){
1516 $error[] = 'Please provide a valid end IP';
1517 }
1518
1519 // Regular ranges will work
1520 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1521
1522 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1523 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1524 // This is right
1525 }else{
1526 $error[] = 'The End IP cannot be smaller than the Start IP';
1527 }
1528
1529 }
1530
1531 if(empty($error)){
1532
1533 $blacklist = $loginizer['blacklist'];
1534
1535 foreach($blacklist as $k => $v){
1536
1537 // This is to check if there is any other range exists with the same Start or End IP
1538 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1539 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1540 ){
1541 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1542 break;
1543 }
1544
1545 // This is to check if there is any other range exists with the same Start IP
1546 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1547 $error[] = 'The Start IP is present in an existing range !';
1548 break;
1549 }
1550
1551 // This is to check if there is any other range exists with the same End IP
1552 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1553 $error[] = 'The End IP is present in an existing range!';
1554 break;
1555 }
1556
1557 }
1558
1559 $newid = ( empty($blacklist) ? 0 : max(array_keys($blacklist)) ) + 1;
1560
1561 if(empty($error)){
1562
1563 $blacklist[$newid] = array();
1564 $blacklist[$newid]['start'] = $start_ip;
1565 $blacklist[$newid]['end'] = $end_ip;
1566 $blacklist[$newid]['time'] = time();
1567
1568 update_option('loginizer_blacklist', $blacklist);
1569
1570 echo '<div id="message" class="updated fade"><p>'
1571 . __('Blacklist IP range added successfully', 'loginizer')
1572 . '</p></div><br />';
1573
1574 }
1575
1576 }
1577
1578 if(!empty($error)){
1579 lz_report_error($error);echo '<br />';
1580 }
1581
1582 }
1583
1584 if(isset($_POST['whitelist_iprange'])){
1585
1586 $start_ip = lz_optpost('start_ip_w');
1587 $end_ip = lz_optpost('end_ip_w');
1588
1589 if(empty($start_ip)){
1590 $error[] = 'Please enter the Start IP';
1591 }
1592
1593 // If no end IP we consider only 1 IP
1594 if(empty($end_ip)){
1595 $end_ip = $start_ip;
1596 }
1597
1598 if(!lz_valid_ip($start_ip)){
1599 $error[] = 'Please provide a valid start IP';
1600 }
1601
1602 if(!lz_valid_ip($end_ip)){
1603 $error[] = 'Please provide a valid end IP';
1604 }
1605
1606 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1607
1608 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1609 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1610 // This is right
1611 }else{
1612 $error[] = 'The End IP cannot be smaller than the Start IP';
1613 }
1614
1615 }
1616
1617 if(empty($error)){
1618
1619 $whitelist = $loginizer['whitelist'];
1620
1621 foreach($whitelist as $k => $v){
1622
1623 // This is to check if there is any other range exists with the same Start or End IP
1624 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1625 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1626 ){
1627 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1628 break;
1629 }
1630
1631 // This is to check if there is any other range exists with the same Start IP
1632 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1633 $error[] = 'The Start IP is present in an existing range !';
1634 break;
1635 }
1636
1637 // This is to check if there is any other range exists with the same End IP
1638 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1639 $error[] = 'The End IP is present in an existing range!';
1640 break;
1641 }
1642
1643 }
1644
1645 $newid = ( empty($whitelist) ? 0 : max(array_keys($whitelist)) ) + 1;
1646
1647 if(empty($error)){
1648
1649 $whitelist[$newid] = array();
1650 $whitelist[$newid]['start'] = $start_ip;
1651 $whitelist[$newid]['end'] = $end_ip;
1652 $whitelist[$newid]['time'] = time();
1653
1654 update_option('loginizer_whitelist', $whitelist);
1655
1656 echo '<div id="message" class="updated fade"><p>'
1657 . __('Whitelist IP range added successfully', 'loginizer')
1658 . '</p></div><br />';
1659
1660 }
1661
1662 }
1663
1664 if(!empty($error)){
1665 lz_report_error($error);echo '<br />';
1666 }
1667 }
1668
1669 // Save the messages
1670 if(isset($_POST['save_err_msgs_lz'])){
1671
1672 $msgs['inv_userpass'] = lz_optpost('msg_inv_userpass');
1673 $msgs['ip_blacklisted'] = lz_optpost('msg_ip_blacklisted');
1674
1675 // Update them
1676 update_option('loginizer_msg', $msgs);
1677
1678 echo '<div id="message" class="updated fade"><p>'
1679 . __('Error messages were saved successfully', 'loginizer')
1680 . '</p></div><br />';
1681
1682 }
1683
1684 // Count the Results
1685 $tmp = lz_selectquery("SELECT COUNT(*) AS num FROM `".$wpdb->prefix."loginizer_logs`");
1686 //print_r($tmp);
1687
1688 // Which Page is it
1689 $lz_env['res_len'] = 10;
1690 $lz_env['cur_page'] = lz_get_page('lzpage', $lz_env['res_len']);
1691 $lz_env['num_res'] = $tmp['num'];
1692 $lz_env['max_page'] = ceil($lz_env['num_res'] / $lz_env['res_len']);
1693
1694 // Get the logs
1695 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs`
1696 ORDER BY `time` DESC
1697 LIMIT ".$lz_env['cur_page'].", ".$lz_env['res_len']."", 1);
1698 //print_r($result);
1699
1700 $lz_env['cur_page'] = ($lz_env['cur_page'] / $lz_env['res_len']) + 1;
1701 $lz_env['cur_page'] = $lz_env['cur_page'] < 1 ? 1 : $lz_env['cur_page'];
1702 $lz_env['next_page'] = ($lz_env['cur_page'] + 1) > $lz_env['max_page'] ? $lz_env['max_page'] : ($lz_env['cur_page'] + 1);
1703 $lz_env['prev_page'] = ($lz_env['cur_page'] - 1) < 1 ? 1 : ($lz_env['cur_page'] - 1);
1704
1705 // Reload the settings
1706 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1707 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1708
1709 $saved_msgs = get_option('loginizer_msg');
1710
1711 ?>
1712
1713 <div id="" class="postbox">
1714
1715 <button class="handlediv button-link" aria-expanded="true" type="button">
1716 <span class="screen-reader-text">Toggle panel: Failed Login Attempts Logs</span>
1717 <span class="toggle-indicator" aria-hidden="true"></span>
1718 </button>
1719
1720 <h2 class="hndle ui-sortable-handle">
1721 <?php echo __('<span>Failed Login Attempts Logs</span> &nbsp; (Past '.($loginizer['reset_retries']/60/60).' hours)','loginizer'); ?>
1722 </h2>
1723
1724 <script>
1725 function yesdsd(){
1726 window.location = '<?php echo menu_page_url('loginizer_brute_force', false);?>&lzpage='+jQuery("#current-page-selector").val();
1727 return false;
1728 }
1729 </script>
1730
1731 <form method="get" onsubmit="return yesdsd();">
1732 <div class="tablenav">
1733 <p class="tablenav-pages" style="margin: 5px 10px" align="right">
1734 <span class="displaying-num"><?php echo $lz_env['num_res'];?> items</span>
1735 <span class="pagination-links">
1736 <a class="first-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage=1';?>"><span class="screen-reader-text">First page</span><span aria-hidden="true">«</span></a>
1737 <a class="prev-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage='.$lz_env['prev_page'];?>"><span class="screen-reader-text">Previous page</span><span aria-hidden="true">‹</span></a>
1738 <span class="paging-input">
1739 <label for="current-page-selector" class="screen-reader-text">Current Page</label>
1740 <input class="current-page" id="current-page-selector" name="lzpage" value="<?php echo $lz_env['cur_page'];?>" size="3" aria-describedby="table-paging" type="text"><span class="tablenav-paging-text"> of <span class="total-pages"><?php echo $lz_env['max_page'];?></span></span>
1741 </span>
1742 <a class="next-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage='.$lz_env['next_page'];?>"><span class="screen-reader-text">Next page</span><span aria-hidden="true">›</span></a>
1743 <a class="last-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage='.$lz_env['max_page'];?>"><span class="screen-reader-text">Last page</span><span aria-hidden="true">»</span></a>
1744 </span>
1745 </p>
1746 </div>
1747 </form>
1748
1749 <form action="" method="post" enctype="multipart/form-data">
1750 <?php wp_nonce_field('loginizer-options'); ?>
1751 <div class="inside">
1752 <table class="wp-list-table widefat fixed users" border="0">
1753 <tr>
1754 <th scope="row" valign="top" style="background:#EFEFEF;" width="20">#</th>
1755 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('IP','loginizer'); ?></th>
1756 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Attempted Username','loginizer'); ?></th>
1757 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Last Failed Attempt (DD/MM/YYYY)','loginizer'); ?></th>
1758 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Failed Attempts Count','loginizer'); ?></th>
1759 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Lockouts Count','loginizer'); ?></th>
1760 <th scope="row" valign="top" style="background:#EFEFEF;" width="150"><?php echo __('URL Attacked','loginizer'); ?></th>
1761 </tr>
1762 <?php
1763
1764 if(empty($result)){
1765 echo '
1766 <tr>
1767 <td colspan="4">
1768 No Logs. You will see logs about failed login attempts here.
1769 </td>
1770 </tr>';
1771 }else{
1772 foreach($result as $ik => $iv){
1773 $status_button = (!empty($iv['status']) ? 'disable' : 'enable');
1774 echo '
1775 <tr>
1776 <td>
1777 <input type="checkbox" value="'.$iv['ip'].'" name="lz_reset_ips[]" />
1778 </td>
1779 <td>
1780 '.$iv['ip'].'
1781 </td>
1782 <td>
1783 '.$iv['username'].'
1784 </td>
1785 <td>
1786 '.date('d/M/Y H:i:s P', $iv['time']).'
1787 </td>
1788 <td>
1789 '.$iv['count'].'
1790 </td>
1791 <td>
1792 '.$iv['lockout'].'
1793 </td>
1794 <td>
1795 '.$iv['url'].'
1796 </td>
1797 </tr>';
1798 }
1799 }
1800
1801 ?>
1802 </table>
1803
1804 <br>
1805 <input name="lz_reset_ip" class="button button-primary action" value="<?php echo __('Remove From Logs', 'loginizer'); ?>" type="submit" />
1806 &nbsp; &nbsp;
1807 <input name="lz_reset_all_ip" class="button button-primary action" value="<?php echo __('Clear All Logs', 'loginizer'); ?>" type="submit" />
1808 </div>
1809 </div>
1810 </form>
1811 <br />
1812
1813 <div id="" class="postbox">
1814
1815 <button class="handlediv button-link" aria-expanded="true" type="button">
1816 <span class="screen-reader-text">Toggle panel: Brute Force Settings</span>
1817 <span class="toggle-indicator" aria-hidden="true"></span>
1818 </button>
1819
1820 <h2 class="hndle ui-sortable-handle">
1821 <span><?php echo __('Brute Force Settings', 'loginizer'); ?></span>
1822 </h2>
1823
1824 <div class="inside">
1825
1826 <form action="" method="post" enctype="multipart/form-data">
1827 <?php wp_nonce_field('loginizer-options'); ?>
1828 <table class="form-table">
1829 <tr>
1830 <th scope="row" valign="top"><label for="max_retries"><?php echo __('Max Retries','loginizer'); ?></label></th>
1831 <td>
1832 <input type="text" size="3" value="<?php echo lz_optpost('max_retries', $loginizer['max_retries']); ?>" name="max_retries" id="max_retries" /> <?php echo __('Maximum failed attempts allowed before lockout','loginizer'); ?> <br />
1833 </td>
1834 </tr>
1835 <tr>
1836 <th scope="row" valign="top"><label for="lockout_time"><?php echo __('Lockout Time','loginizer'); ?></label></th>
1837 <td>
1838 <input type="text" size="3" value="<?php echo (!empty($lockout_time) ? $lockout_time : $loginizer['lockout_time']) / 60; ?>" name="lockout_time" id="lockout_time" /> <?php echo __('minutes','loginizer'); ?> <br />
1839 </td>
1840 </tr>
1841 <tr>
1842 <th scope="row" valign="top"><label for="max_lockouts"><?php echo __('Max Lockouts','loginizer'); ?></label></th>
1843 <td>
1844 <input type="text" size="3" value="<?php echo lz_optpost('max_lockouts', $loginizer['max_lockouts']); ?>" name="max_lockouts" id="max_lockouts" /> <?php echo __('','loginizer'); ?> <br />
1845 </td>
1846 </tr>
1847 <tr>
1848 <th scope="row" valign="top"><label for="lockouts_extend"><?php echo __('Extend Lockout','loginizer'); ?></label></th>
1849 <td>
1850 <input type="text" size="3" value="<?php echo (!empty($lockouts_extend) ? $lockouts_extend : $loginizer['lockouts_extend']) / 60 / 60; ?>" name="lockouts_extend" id="lockouts_extend" /> <?php echo __('hours. Extend Lockout time after Max Lockouts','loginizer'); ?> <br />
1851 </td>
1852 </tr>
1853 <tr>
1854 <th scope="row" valign="top"><label for="reset_retries"><?php echo __('Reset Retries','loginizer'); ?></label></th>
1855 <td>
1856 <input type="text" size="3" value="<?php echo (!empty($reset_retries) ? $reset_retries : $loginizer['reset_retries']) / 60 / 60; ?>" name="reset_retries" id="reset_retries" /> <?php echo __('hours','loginizer'); ?> <br />
1857 </td>
1858 </tr>
1859 <tr>
1860 <th scope="row" valign="top"><label for="notify_email"><?php echo __('Email Notification','loginizer'); ?></label></th>
1861 <td>
1862 <?php echo __('after ','loginizer'); ?>
1863 <input type="text" size="3" value="<?php echo (!empty($notify_email) ? $notify_email : $loginizer['notify_email']); ?>" name="notify_email" id="notify_email" /> <?php echo __('lockouts <br />0 to disable email notifications','loginizer'); ?>
1864 </td>
1865 </tr>
1866 </table><br />
1867 <input name="save_lz" class="button button-primary action" value="<?php echo __('Save Settings','loginizer'); ?>" type="submit" />
1868 <?php
1869
1870 if(empty($loginizer['disable_brute'])){
1871
1872 echo '<input name="disable_brute_lz" class="button action" value="'.__('Disable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1873
1874 }else{
1875
1876 echo '<input name="enable_brute_lz" class="button button-primary action" value="'.__('Enable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1877
1878 }
1879
1880 ?>
1881 </form>
1882
1883 </div>
1884 </div>
1885 <br />
1886
1887 <?php
1888
1889 wp_enqueue_script('jquery-paginate', LOGINIZER_URL.'/jquery-paginate.js', array('jquery'), '1.10.15');
1890
1891 ?>
1892
1893 <style>
1894 .page-navigation a {
1895 margin: 5px 2px;
1896 display: inline-block;
1897 padding: 5px 8px;
1898 color: #0073aa;
1899 background: #e5e5e5 none repeat scroll 0 0;
1900 border: 1px solid #ccc;
1901 text-decoration: none;
1902 transition-duration: 0.05s;
1903 transition-property: border, background, color;
1904 transition-timing-function: ease-in-out;
1905 }
1906
1907 .page-navigation a[data-selected] {
1908 background-color: #00a0d2;
1909 color: #fff;
1910 }
1911 </style>
1912
1913 <script>
1914
1915 jQuery(document).ready(function(){
1916 jQuery('#lz_bl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_bl_nav')});
1917 jQuery('#lz_wl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_wl_nav')});
1918 });
1919
1920 // Delete a Blacklist / Whitelist IP Range
1921 function del_confirm(field, todo_id, msg){
1922 var ret = confirm(msg);
1923
1924 if(ret){
1925 jQuery('#lz_bl_wl_todo').attr('name', field);
1926 jQuery('#lz_bl_wl_todo').val(todo_id);
1927 jQuery('#lz_bl_wl_form').submit();
1928 }
1929
1930 return false;
1931
1932 }
1933
1934 // Delete all Blacklist / Whitelist IP Ranges
1935 function del_confirm_all(msg){
1936 var ret = confirm(msg);
1937
1938 if(ret){
1939 return true;
1940 }
1941
1942 return false;
1943
1944 }
1945
1946 </script>
1947
1948 <div id="" class="postbox">
1949
1950 <button class="handlediv button-link" aria-expanded="true" type="button">
1951 <span class="screen-reader-text">Toggle panel: Blacklist IP</span>
1952 <span class="toggle-indicator" aria-hidden="true"></span>
1953 </button>
1954
1955 <h2 class="hndle ui-sortable-handle">
1956 <span><?php echo __('Blacklist IP','loginizer'); ?></span>
1957 </h2>
1958
1959 <div class="inside">
1960
1961 <?php echo __('Enter the IP you want to blacklist from login','loginizer'); ?>
1962
1963 <form action="" method="post">
1964 <?php wp_nonce_field('loginizer-options'); ?>
1965 <table class="form-table">
1966 <tr>
1967 <th scope="row" valign="top"><label for="start_ip"><?php echo __('Start IP','loginizer'); ?></label></th>
1968 <td>
1969 <input type="text" size="25" value="<?php echo(lz_optpost('start_ip')); ?>" name="start_ip" id="start_ip"/> <?php echo __('Start IP of the range','loginizer'); ?> <br />
1970 </td>
1971 </tr>
1972 <tr>
1973 <th scope="row" valign="top"><label for="end_ip"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
1974 <td>
1975 <input type="text" size="25" value="<?php echo(lz_optpost('end_ip')); ?>" name="end_ip" id="end_ip"/> <?php echo __('End IP of the range. <br />If you want to blacklist single IP leave this field blank.','loginizer'); ?> <br />
1976 </td>
1977 </tr>
1978 </table><br />
1979 <input name="blacklist_iprange" class="button button-primary action" value="<?php echo __('Add Blacklist IP Range','loginizer'); ?>" type="submit" />
1980 <input style="float:right" name="del_all_blacklist" onclick="return del_confirm_all('<?php echo __('Are you sure you want to delete all Blacklist IP Range(s) ?','loginizer'); ?>')" class="button action" value="<?php echo __('Delete All Blacklist IP Range(s)','loginizer'); ?>" type="submit" />
1981 </form>
1982 </div>
1983
1984 <div id="lz_bl_nav" style="margin: 5px 10px; text-align:right"></div>
1985 <table id="lz_bl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1986 <tr>
1987 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
1988 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
1989 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
1990 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
1991 </tr>
1992 <?php
1993 if(empty($loginizer['blacklist'])){
1994 echo '
1995 <tr>
1996 <td colspan="4">
1997 No Blacklist IPs. You will see blacklisted IP ranges here.
1998 </td>
1999 </tr>';
2000 }else{
2001 foreach($loginizer['blacklist'] as $ik => $iv){
2002 echo '
2003 <tr>
2004 <td>
2005 '.$iv['start'].'
2006 </td>
2007 <td>
2008 '.$iv['end'].'
2009 </td>
2010 <td>
2011 '.date('d/m/Y', $iv['time']).'
2012 </td>
2013 <td>
2014 <a class="submitdelete" href="javascript:void(0)" onclick="return del_confirm(\'bdelid\', '.$ik.', \'Are you sure you want to delete this IP range ?\')">Delete</a>
2015 </td>
2016 </tr>';
2017 }
2018 }
2019 ?>
2020 </table>
2021 <br />
2022 <form action="" method="post" id="lz_bl_wl_form">
2023 <?php wp_nonce_field('loginizer-options'); ?>
2024 <input type="hidden" value="" name="" id="lz_bl_wl_todo"/>
2025 </form>
2026 </div>
2027
2028 <br />
2029
2030 <div id="" class="postbox">
2031
2032 <button class="handlediv button-link" aria-expanded="true" type="button">
2033 <span class="screen-reader-text">Toggle panel: Whitelist IP</span>
2034 <span class="toggle-indicator" aria-hidden="true"></span>
2035 </button>
2036
2037 <h2 class="hndle ui-sortable-handle">
2038 <span><?php echo __('Whitelist IP', 'loginizer'); ?></span>
2039 </h2>
2040
2041 <div class="inside">
2042
2043 <?php echo __('Enter the IP you want to whitelist for login','loginizer'); ?>
2044 <form action="" method="post">
2045 <?php wp_nonce_field('loginizer-options'); ?>
2046 <table class="form-table">
2047 <tr>
2048 <th scope="row" valign="top"><label for="start_ip_w"><?php echo __('Start IP','loginizer'); ?></label></th>
2049 <td>
2050 <input type="text" size="25" value="<?php echo(lz_optpost('start_ip_w')); ?>" name="start_ip_w" id="start_ip_w"/> <?php echo __('Start IP of the range','loginizer'); ?> <br />
2051 </td>
2052 </tr>
2053 <tr>
2054 <th scope="row" valign="top"><label for="end_ip_w"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
2055 <td>
2056 <input type="text" size="25" value="<?php echo(lz_optpost('end_ip_w')); ?>" name="end_ip_w" id="end_ip_w"/> <?php echo __('End IP of the range. <br />If you want to whitelist single IP leave this field blank.','loginizer'); ?> <br />
2057 </td>
2058 </tr>
2059 </table><br />
2060 <input name="whitelist_iprange" class="button button-primary action" value="<?php echo __('Add Whitelist IP Range','loginizer'); ?>" type="submit" />
2061 <input style="float:right" name="del_all_whitelist" onclick="return del_confirm_all('<?php echo __('Are you sure you want to delete all Whitelist IP Range(s) ?','loginizer'); ?>')" class="button action" value="<?php echo __('Delete All Whitelist IP Range(s)','loginizer'); ?>" type="submit" />
2062 </form>
2063 </div>
2064
2065 <div id="lz_wl_nav" style="margin: 5px 10px; text-align:right"></div>
2066 <table id="lz_wl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
2067 <tr>
2068 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
2069 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
2070 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
2071 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
2072 </tr>
2073 <?php
2074 if(empty($loginizer['whitelist'])){
2075 echo '
2076 <tr>
2077 <td colspan="4">
2078 No Whitelist IPs. You will see whitelisted IP ranges here.
2079 </td>
2080 </tr>';
2081 }else{
2082 foreach($loginizer['whitelist'] as $ik => $iv){
2083 echo '
2084 <tr>
2085 <td>
2086 '.$iv['start'].'
2087 </td>
2088 <td>
2089 '.$iv['end'].'
2090 </td>
2091 <td>
2092 '.date('d/m/Y', $iv['time']).'
2093 </td>
2094 <td>
2095 <a class="submitdelete" href="javascript:void(0)" onclick="return del_confirm(\'delid\', '.$ik.', \'Are you sure you want to delete this IP range ?\')">Delete</a>
2096 </td>
2097 </tr>';
2098 }
2099 }
2100 ?>
2101 </table>
2102 <br />
2103
2104 </div>
2105
2106 <div id="" class="postbox">
2107
2108 <button class="handlediv button-link" aria-expanded="true" type="button">
2109 <span class="screen-reader-text">Toggle panel: Error Messages</span>
2110 <span class="toggle-indicator" aria-hidden="true"></span>
2111 </button>
2112
2113 <h2 class="hndle ui-sortable-handle">
2114 <span><?php echo __('Error Messages', 'loginizer'); ?></span>
2115 </h2>
2116
2117 <div class="inside">
2118
2119 <form action="" method="post" enctype="multipart/form-data">
2120 <?php wp_nonce_field('loginizer-options'); ?>
2121 <table class="form-table">
2122 <tr>
2123 <th scope="row" valign="top"><label for="msg_inv_userpass"><?php echo __('Failed Login Attempt','loginizer'); ?></label></th>
2124 <td>
2125 <input type="text" size="25" value="<?php echo esc_attr($saved_msgs['inv_userpass']); ?>" name="msg_inv_userpass" id="msg_inv_userpass" />
2126 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['inv_userpass']. '&quot;</em>', 'loginizer'); ?><br />
2127 </td>
2128 </tr>
2129 <tr>
2130 <th scope="row" valign="top"><label for="msg_ip_blacklisted"><?php echo __('Blacklisted IP','loginizer'); ?></label></th>
2131 <td>
2132 <input type="text" size="25" value="<?php echo esc_attr($saved_msgs['ip_blacklisted']); ?>" name="msg_ip_blacklisted" id="msg_ip_blacklisted" />
2133 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['ip_blacklisted']. '&quot;</em>', 'loginizer'); ?><br />
2134 </td>
2135 </tr>
2136 </table><br />
2137 <input name="save_err_msgs_lz" class="button button-primary action" value="<?php echo __('Save Error Messages','loginizer'); ?>" type="submit" />
2138 </form>
2139 </div>
2140 </div>
2141 <?php
2142
2143 loginizer_page_footer();
2144
2145 }
2146
2147
2148 // Sorry to see you going
2149 register_uninstall_hook(LOGINIZER_FILE, 'loginizer_deactivation');
2150
2151 function loginizer_deactivation(){
2152
2153 global $wpdb;
2154
2155 $sql = array();
2156 $sql[] = "DROP TABLE ".$wpdb->prefix."loginizer_logs;";
2157
2158 foreach($sql as $sk => $sv){
2159 $wpdb->query($sv);
2160 }
2161
2162 delete_option('loginizer_version');
2163 delete_option('loginizer_options');
2164 delete_option('loginizer_last_reset');
2165 delete_option('loginizer_whitelist');
2166 delete_option('loginizer_blacklist');
2167 delete_option('loginizer_msg');
2168 delete_option('loginizer_security');
2169 delete_option('loginizer_wp_admin');
2170
2171 }
2172
2173