PluginProbe
Loginizer / 1.4.9
Loginizer v1.4.9
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.9, at init.php

2,179 lines 67.2 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.9');
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, $is_2fa = ''){
584
585 global $wpdb, $loginizer, $lz_cannot_login;
586
587 $fail_type = 'Login';
588
589 if(!empty($is_2fa)){
590 $fail_type = '2FA';
591 }
592
593 if(empty($lz_cannot_login) && empty($loginizer['ip_is_whitelisted']) && empty($loginizer['no_loginizer_logs'])){
594
595 $url = @addslashes((!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
596 $url = esc_url($url);
597
598 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = '".$loginizer['current_ip']."';");
599
600 if(!empty($result)){
601 $lockout = floor((($result['count']+1) / $loginizer['max_retries']));
602 $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']."';");
603
604 // Do we need to email admin ?
605 if(!empty($loginizer['notify_email']) && $lockout >= $loginizer['notify_email']){
606
607 $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname');
608 $mail = array();
609 $mail['to'] = lz_is_multisite() ? get_site_option('admin_email') : get_option('admin_email');
610 $mail['subject'] = 'Failed '.$fail_type.' Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')';
611 $mail['message'] = 'Hi,
612
613 '.($result['count']+1).' failed '.strtolower($fail_type).' attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].'
614
615 Last '.$fail_type.' Attempt : '.date('d/M/Y H:i:s P', time()).'
616 Last User Attempt : '.$username.'
617 IP has been blocked until : '.date('d/M/Y H:i:s P', time() + $loginizer['lockout_time']).'
618
619 Regards,
620 Loginizer';
621
622 @wp_mail($mail['to'], $mail['subject'], $mail['message']);
623 }
624 }else{
625 $insert = $wpdb->query("INSERT INTO `".$wpdb->prefix."loginizer_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = '1', `ip` = '".$loginizer['current_ip']."', `lockout` = '0', `url` = '".$url."';");
626 }
627
628 // We need to add one as this is a failed attempt as well
629 $result['count'] = $result['count'] + 1;
630 $loginizer['retries_left'] = ($loginizer['max_retries'] - ($result['count'] % $loginizer['max_retries']));
631 $loginizer['retries_left'] = $loginizer['retries_left'] == $loginizer['max_retries'] ? 0 : $loginizer['retries_left'];
632
633 }
634 }
635
636 // Handles the error of the password not being there
637 function loginizer_error_handler($errors, $redirect_to){
638
639 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
640
641 //echo 'loginizer_error_handler :';print_r($errors->errors);echo '<br>';
642
643 // Remove the empty password error
644 if(is_wp_error($errors)){
645
646 $codes = $errors->get_error_codes();
647
648 foreach($codes as $k => $v){
649 if($v == 'invalid_username' || $v == 'incorrect_password'){
650 $show_error = 1;
651 }
652 }
653
654 $errors->remove('invalid_username');
655 $errors->remove('incorrect_password');
656
657 }
658
659 // Add the error
660 if(!empty($lz_user_pass) && !empty($show_error) && empty($lz_cannot_login)){
661 $errors->add('invalid_userpass', '<b>ERROR:</b> ' . $loginizer['msg']['inv_userpass']);
662 }
663
664 // Add the number of retires left as well
665 if(count($errors->get_error_codes()) > 0 && isset($loginizer['retries_left'])){
666 $errors->add('retries_left', loginizer_retries_left());
667 }
668
669 return $errors;
670
671 }
672
673
674
675 // Handles the error of the password not being there
676 function loginizer_woocommerce_error_handler(){
677
678 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
679
680 if(function_exists('wc_add_notice')){
681 wc_add_notice( loginizer_retries_left(), 'error' );
682 }
683
684 }
685
686 // Returns a string with the number of retries left
687 function loginizer_retries_left(){
688
689 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
690
691 // If we are to show the number of retries left
692 if(isset($loginizer['retries_left'])){
693 return '<b>'.$loginizer['retries_left'].'</b> attempt(s) left';
694 }
695
696 }
697
698 function loginizer_reset_retries(){
699
700 global $wpdb, $loginizer;
701
702 $deltime = time() - $loginizer['reset_retries'];
703 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs` WHERE `time` <= '".$deltime."';");
704
705 update_option('loginizer_last_reset', time());
706
707 }
708
709 add_filter("plugin_action_links_$plugin_loginizer", 'loginizer_plugin_action_links');
710
711 // Add settings link on plugin page
712 function loginizer_plugin_action_links($links) {
713
714 if(!defined('LOGINIZER_PREMIUM')){
715 $links[] = '<a href="'.LOGINIZER_PRO_URL.'" style="color:#3db634;" target="_blank">'._x('Upgrade', 'Plugin action link label.', 'loginizer').'</a>';
716 }
717
718 $settings_link = '<a href="admin.php?page=loginizer">Settings</a>';
719 array_unshift($links, $settings_link);
720
721 return $links;
722 }
723
724 add_action('admin_menu', 'loginizer_admin_menu');
725
726 // Shows the admin menu of Loginizer
727 function loginizer_admin_menu() {
728
729 global $wp_version, $loginizer;
730
731 if(!defined('SITEPAD')){
732
733 // Add the menu page
734 add_menu_page(__('Loginizer Dashboard'), __('Loginizer Security'), 'activate_plugins', 'loginizer', 'loginizer_page_dashboard');
735
736 // Dashboard
737 add_submenu_page('loginizer', __('Loginizer Dashboard'), __('Dashboard'), 'activate_plugins', 'loginizer', 'loginizer_page_dashboard');
738
739 }else{
740
741 // Add the menu page
742 add_menu_page(__('Security'), __('Security'), 'activate_plugins', 'loginizer', 'loginizer_page_security', 'dashicons-shield', 85);
743
744 // Rename Login
745 add_submenu_page('loginizer', __('Security Settings'), __('Rename Login'), 'activate_plugins', 'loginizer', 'loginizer_page_security');
746
747 }
748
749 // Brute Force
750 add_submenu_page('loginizer', __('Brute Force Settings'), __('Brute Force'), 'activate_plugins', 'loginizer_brute_force', 'loginizer_page_brute_force');
751
752 if(defined('LOGINIZER_PREMIUM')){
753
754 // PasswordLess
755 add_submenu_page('loginizer', __($loginizer['prefix'].'PasswordLess Settings'), __('PasswordLess'), 'activate_plugins', 'loginizer_passwordless', 'loginizer_page_passwordless');
756
757 // Security Settings
758 if(!defined('SITEPAD')){
759
760 // Two Factor Auth
761 add_submenu_page('loginizer', __($loginizer['prefix'].' Two Factor Authentication'), __('Two Factor Auth'), 'activate_plugins', 'loginizer_2fa', 'loginizer_page_2fa');
762
763 }
764
765 // reCaptcha
766 add_submenu_page('loginizer', __($loginizer['prefix'].'reCAPTCHA Settings'), __('reCAPTCHA'), 'activate_plugins', 'loginizer_recaptcha', 'loginizer_page_recaptcha');
767
768 // Security Settings
769 if(!defined('SITEPAD')){
770
771 // Security Settings
772 add_submenu_page('loginizer', __($loginizer['prefix'].'Security Settings'), __('Security Settings'), 'activate_plugins', 'loginizer_security', 'loginizer_page_security');
773
774 // File Checksums
775 add_submenu_page('loginizer', __('Loginizer File Checksums'), __('File Checksums'), 'activate_plugins', 'loginizer_checksums', 'loginizer_page_checksums');
776
777 }
778
779 }elseif(!defined('LOGINIZER_PREMIUM') && !empty($loginizer['ins_time']) && $loginizer['ins_time'] < (time() - (30*24*3600))){
780
781 // Go Pro link
782 add_submenu_page('loginizer', __('Loginizer Go Pro'), __('Go Pro'), 'activate_plugins', LOGINIZER_PRO_URL);
783
784 }
785
786 }
787
788 // The Loginizer Admin Options Page
789 function loginizer_page_header($title = 'Loginizer'){
790
791 global $loginizer;
792
793 ?>
794 <style>
795 .lz-right-ul{
796 padding-left: 10px !important;
797 }
798
799 .lz-right-ul li{
800 list-style: circle !important;
801 }
802 </style>
803 <?php
804
805 echo '<div style="margin: 10px 20px 0 2px;">
806 <div class="metabox-holder columns-2">
807 <div class="postbox-container">
808 <div id="top-sortables" class="meta-box-sortables ui-sortable">
809
810 <table cellpadding="2" cellspacing="1" width="100%" class="fixed" border="0">
811 <tr>
812 <td valign="top"><h3>'.$loginizer['prefix'].$title.'</h3></td>';
813
814 if(!defined('SITEPAD')){
815
816 echo '<td align="right"><a target="_blank" class="button button-primary" href="https://wordpress.org/support/view/plugin-reviews/loginizer">Review Loginizer</a></td>
817 <td align="right" width="40"><a target="_blank" href="https://twitter.com/loginizer"><img src="'.LOGINIZER_URL.'/twitter.png" /></a></td>
818 <td align="right" width="40"><a target="_blank" href="https://www.facebook.com/Loginizer-815504798591884"><img src="'.LOGINIZER_URL.'/facebook.png" /></a></td>';
819
820 }
821
822 echo '
823 </tr>
824 </table>
825 <hr />
826
827 <!--Main Table-->
828 <table cellpadding="8" cellspacing="1" width="100%" class="fixed">
829 <tr>
830 <td valign="top">';
831
832 }
833
834 // The Loginizer Theme footer
835 function loginizer_page_footer(){
836
837 echo '</td>
838 <td width="200" valign="top" id="loginizer-right-bar">';
839
840 if(!defined('SITEPAD')){
841
842 if(!defined('LOGINIZER_PREMIUM')){
843
844 echo '
845 <div class="postbox" style="min-width:0px !important;">
846 <h2 class="hndle ui-sortable-handle">
847 <span>Premium Version</span>
848 </h2>
849 <div class="inside">
850 <i>Upgrade to the premium version and get the following features </i>:<br>
851 <ul class="lz-right-ul">
852 <li>PasswordLess Login</li>
853 <li>Two Factor Auth - Email</li>
854 <li>Two Factor Auth - App</li>
855 <li>Login Challenge Question</li>
856 <li>reCAPTCHA</li>
857 <li>Rename Login Page</li>
858 <li>Disable XML-RPC</li>
859 <li>And many more ...</li>
860 </ul>
861 <center><a class="button button-primary" href="https://loginizer.com/pricing">Upgrade</a></center>
862 </div>
863 </div>';
864
865 }else{
866
867 echo '
868 <div class="postbox" style="min-width:0px !important;">
869 <h2 class="hndle ui-sortable-handle">
870 <span>Recommendations</span>
871 </h2>
872 <div class="inside">
873 <i>We recommed that you enable atleast one of the following security features</i>:<br>
874 <ul class="lz-right-ul">
875 <li>Rename Login Page</li>
876 <li>Login Challenge Question</li>
877 <li>reCAPTCHA</li>
878 <li>Two Factor Auth - Email</li>
879 <li>Two Factor Auth - App</li>
880 <li>Change \'admin\' Username</li>
881 </ul>
882 </div>
883 </div>';
884 }
885
886 echo '
887 <div class="postbox" style="min-width:0px !important;">
888 <h2 class="hndle ui-sortable-handle">
889 <span><a target="_blank" href="https://pagelayer.com/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/pagelayer_product.png" width="100%" /></a></span>
890 </h2>
891 <div class="inside">
892 <i>Easily manage and make professional pages and content with our Pagelayer builder </i>:<br>
893 <ul class="lz-right-ul">
894 <li>30+ Free Widgets</li>
895 <li>60+ Premium Widgets</li>
896 <li>400+ Premium Sections</li>
897 <li>Theme Builder</li>
898 <li>WooCommerce Builder</li>
899 <li>Theme Creator and Exporter</li>
900 <li>Form Builder</li>
901 <li>Popup Builder</li>
902 <li>And many more ...</li>
903 </ul>
904 <center><a class="button button-primary" target="_blank" href="https://wordpress.org/plugins/pagelayer/">Visit Pagelayer</a></center>
905 </div>
906 </div>';
907
908 echo '
909 <div class="postbox" style="min-width:0px !important;">
910 <h2 class="hndle ui-sortable-handle">
911 <span><a target="_blank" href="https://wpcentral.co/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/wpcentral_product.png" width="100%" /></a></span>
912 </h2>
913 <div class="inside">
914 <i>Manage all your WordPress sites from <b>1 dashboard</b> </i>:<br>
915 <ul class="lz-right-ul">
916 <li>1-click Admin Access</li>
917 <li>Update WordPress</li>
918 <li>Update Themes</li>
919 <li>Update Plugins</li>
920 <li>Backup your WordPress Site</li>
921 <li>Plugins & Theme Management</li>
922 <li>Post Management</li>
923 <li>And many more ...</li>
924 </ul>
925 <center><a class="button button-primary" target="_blank" href="https://wpcentral.co/?from=loginizer-plugin">Visit wpCentral</a></center>
926 </div>
927 </div>';
928
929 }
930
931 echo '</td>
932 </tr>
933 </table>';
934
935 if(!defined('SITEPAD')){
936
937 echo '<br />
938 <div style="width:45%;background:#FFF;padding:15px; margin:auto">
939 <b>Let your friends know that you have secured your website :</b>
940 <form method="get" action="https://twitter.com/intent/tweet" id="tweet" onsubmit="return dotweet(this);">
941 <textarea name="text" cols="45" row="3" style="resize:none;">I just secured my @WordPress site against #bruteforce using @loginizer</textarea>
942 &nbsp; &nbsp; <input type="submit" value="Tweet!" class="button button-primary" onsubmit="return false;" id="twitter-btn" style="margin-top:20px;"/>
943 </form>
944
945 </div>
946 <br />
947
948 <script>
949 function dotweet(ele){
950 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");
951 return false;
952 }
953 </script>
954
955 <hr />
956 <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>.';
957
958 }
959
960 echo '
961 </div>
962 </div>
963 </div>
964 </div>';
965
966 }
967
968 // The Loginizer Admin Options Page
969 function loginizer_page_dashboard(){
970
971 global $loginizer, $lz_error, $lz_env;
972
973 if(!current_user_can('manage_options')){
974 wp_die('Sorry, but you do not have permissions to change settings.');
975 }
976
977 // Dismiss the announcement
978 if(isset($_GET['dismiss_announcement'])){
979 update_option('loginizer_no_announcement', 1);
980 }
981
982 /* Make sure post was from this page */
983 if(count($_POST) > 0){
984 check_admin_referer('loginizer-options');
985 }
986
987 // Is there a license key ?
988 if(isset($_POST['save_lz'])){
989
990 $license = lz_optpost('lz_license');
991
992 // Check if its a valid license
993 if(empty($license)){
994 $lz_error['lic_invalid'] = __('The license key was not submitted', 'loginizer');
995 return loginizer_page_dashboard_T();
996 }
997
998 $resp = wp_remote_get(LOGINIZER_API.'license.php?license='.$license, array('timeout' => 30));
999
1000 if(is_array($resp)){
1001 $json = json_decode($resp['body'], true);
1002 //print_r($json);
1003 }else{
1004
1005 $lz_error['resp_invalid'] = __('The response was malformed<br>'.var_export($resp, true), 'loginizer');
1006 return loginizer_page_dashboard_T();
1007
1008 }
1009
1010 // Save the License
1011 if(empty($json['license'])){
1012
1013 $lz_error['lic_invalid'] = __('The license key is invalid', 'loginizer');
1014 return loginizer_page_dashboard_T();
1015
1016 }else{
1017
1018 update_option('loginizer_license', $json);
1019
1020 // Mark as saved
1021 $GLOBALS['lz_saved'] = true;
1022 }
1023
1024 }
1025
1026
1027 // Is there a IP Method ?
1028 if(isset($_POST['save_lz_ip_method'])){
1029
1030 $ip_method = (int) lz_optpost('lz_ip_method');
1031 $custom_ip_method = lz_optpost('lz_custom_ip_method');
1032
1033 if($ip_method >= 0 && $ip_method <= 3){
1034 update_option('loginizer_ip_method', $ip_method);
1035 }
1036
1037 // Custom Method name ?
1038 if($ip_method == 3){
1039 update_option('loginizer_custom_ip_method', $custom_ip_method);
1040 }
1041
1042 }
1043
1044 loginizer_page_dashboard_T();
1045
1046 }
1047
1048 // The Loginizer Admin Options Page - THEME
1049 function loginizer_page_dashboard_T(){
1050
1051 global $loginizer, $lz_error, $lz_env;
1052
1053 loginizer_page_header('Dashboard');
1054 ?>
1055 <style>
1056 .welcome-panel{
1057 margin: 0px;
1058 padding: 10px;
1059 }
1060
1061 input[type="text"], textarea, select {
1062 width: 70%;
1063 }
1064
1065 .form-table label{
1066 font-weight:bold;
1067 }
1068
1069 .exp{
1070 font-size:12px;
1071 }
1072 </style>
1073
1074 <?php
1075
1076 $hide_announcement = get_option('loginizer_no_announcement');
1077 if(empty($hide_announcement)){
1078 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 />';
1079 }
1080
1081 echo '<script src="https://api.loginizer.com/'.(defined('LOGINIZER_PREMIUM') ? 'news_security.js' : 'news.js').'"></script><br>';
1082
1083 // Saved ?
1084 if(!empty($GLOBALS['lz_saved'])){
1085 echo '<div id="message" class="updated"><p>'. __('The settings were saved successfully', 'loginizer'). '</p></div><br />';
1086 }
1087
1088 // Any errors ?
1089 if(!empty($lz_error)){
1090 lz_report_error($lz_error);echo '<br />';
1091 }
1092
1093 ?>
1094
1095 <div class="postbox">
1096
1097 <button class="handlediv button-link" aria-expanded="true" type="button">
1098 <span class="screen-reader-text">Toggle panel: Getting Started</span>
1099 <span class="toggle-indicator" aria-hidden="true"></span>
1100 </button>
1101
1102 <h2 class="hndle ui-sortable-handle">
1103 <span><?php echo __('Getting Started', 'loginizer'); ?></span>
1104 </h2>
1105
1106 <div class="inside">
1107
1108 <form action="" method="post" enctype="multipart/form-data">
1109 <?php wp_nonce_field('loginizer-options'); ?>
1110 <table class="form-table">
1111 <tr>
1112 <td scope="row" valign="top" colspan="2" style="line-height:150%">
1113 <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>
1114 <?php
1115 if(defined('LOGINIZER_PREMIUM')){
1116 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>';
1117 }
1118 ?>
1119 </td>
1120 </tr>
1121 </table>
1122 </form>
1123
1124 </div>
1125 </div>
1126
1127 <div class="postbox">
1128
1129 <button class="handlediv button-link" aria-expanded="true" type="button">
1130 <span class="screen-reader-text">Toggle panel: System Information</span>
1131 <span class="toggle-indicator" aria-hidden="true"></span>
1132 </button>
1133
1134 <h2 class="hndle ui-sortable-handle">
1135 <span><?php echo __('System Information', 'loginizer'); ?></span>
1136 </h2>
1137
1138 <div class="inside">
1139
1140 <form action="" method="post" enctype="multipart/form-data">
1141 <?php wp_nonce_field('loginizer-options'); ?>
1142 <table class="wp-list-table fixed striped users" cellspacing="1" border="0" width="95%" cellpadding="10" align="center">
1143 <?php
1144 echo '
1145 <tr>
1146 <th align="left" width="25%">'.__('Loginizer Version', 'loginizer').'</th>
1147 <td>'.LOGINIZER_VERSION.(defined('LOGINIZER_PREMIUM') ? ' (Security PRO Version)' : '').'</td>
1148 </tr>';
1149
1150 if(defined('LOGINIZER_PREMIUM')){
1151 echo '
1152 <tr>
1153 <th align="left" valign="top">'.__('Loginizer License', 'loginizer').'</th>
1154 <td align="left">
1155 '.(empty($loginizer['license']) ? '<span style="color:red">Unlicensed</span> &nbsp; &nbsp;' : '').'
1156 <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;
1157 <input name="save_lz" class="button button-primary" value="Update License" type="submit" />';
1158
1159 if(!empty($loginizer['license'])){
1160
1161 $expires = $loginizer['license']['expires'];
1162 $expires = substr($expires, 0, 4).'/'.substr($expires, 4, 2).'/'.substr($expires, 6);
1163
1164 echo '<div style="margin-top:10px;">License Active : '.(empty($loginizer['license']['active']) ? '<span style="color:red">No</span>' : 'Yes').' &nbsp; &nbsp; &nbsp;
1165 License Expires : '.($loginizer['license']['expires'] <= date('Ymd') ? '<span style="color:red">'.$expires.'</span>' : $expires).'
1166 </div>';
1167 }
1168
1169
1170 echo
1171 '</td>
1172 </tr>';
1173 }
1174
1175 echo '<tr>
1176 <th align="left">'.__('URL', 'loginizer').'</th>
1177 <td>'.get_site_url().'</td>
1178 </tr>
1179 <tr>
1180 <th align="left">'.__('Path', 'loginizer').'</th>
1181 <td>'.ABSPATH.'</td>
1182 </tr>
1183 <tr>
1184 <th align="left">'.__('Server\'s IP Address', 'loginizer').'</th>
1185 <td>'.@$_SERVER['SERVER_ADDR'].'</td>
1186 </tr>
1187 <tr>
1188 <th align="left">'.__('Your IP Address', 'loginizer').'</th>
1189 <td>'.lz_getip().'
1190 <div style="float:right">
1191 Method :
1192 <select name="lz_ip_method" id="lz_ip_method" style="font-size:11px; width:150px" onchange="lz_ip_method_handle()">
1193 <option value="0" '.lz_POSTselect('lz_ip_method', 0, (@$loginizer['ip_method'] == 0)).'>REMOTE_ADDR</option>
1194 <option value="1" '.lz_POSTselect('lz_ip_method', 1, (@$loginizer['ip_method'] == 1)).'>HTTP_X_FORWARDED_FOR</option>
1195 <option value="2" '.lz_POSTselect('lz_ip_method', 2, (@$loginizer['ip_method'] == 2)).'>HTTP_CLIENT_IP</option>
1196 <option value="3" '.lz_POSTselect('lz_ip_method', 3, (@$loginizer['ip_method'] == 3)).'>CUSTOM</option>
1197 </select>
1198 <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" />
1199 <input name="save_lz_ip_method" class="button button-primary" value="Save" type="submit" />
1200 </div>
1201 </td>
1202 </tr>
1203 <tr>
1204 <th align="left">'.__('wp-config.php is writable', 'loginizer').'</th>
1205 <td>'.(is_writable(ABSPATH.'/wp-config.php') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1206 </tr>';
1207
1208 if(file_exists(ABSPATH.'/.htaccess')){
1209 echo '
1210 <tr>
1211 <th align="left">'.__('.htaccess is writable', 'loginizer').'</th>
1212 <td>'.(is_writable(ABSPATH.'/.htaccess') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1213 </tr>';
1214
1215 }
1216
1217 ?>
1218 </table>
1219 </form>
1220
1221 </div>
1222 </div>
1223
1224 <script type="text/javascript">
1225
1226 function lz_ip_method_handle(){
1227 var ele = jQuery('#lz_ip_method');
1228 if(ele.val() == 3){
1229 jQuery('#lz_custom_ip_method').show();
1230 }else{
1231 jQuery('#lz_custom_ip_method').hide();
1232 }
1233 };
1234
1235 lz_ip_method_handle();
1236
1237 </script>
1238
1239 <div id="" class="postbox">
1240
1241 <button class="handlediv button-link" aria-expanded="true" type="button">
1242 <span class="screen-reader-text">Toggle panel: File Permissions</span>
1243 <span class="toggle-indicator" aria-hidden="true"></span>
1244 </button>
1245
1246 <h2 class="hndle ui-sortable-handle">
1247 <span><?php echo __('File Permissions', 'loginizer'); ?></span>
1248 </h2>
1249
1250 <div class="inside">
1251
1252 <form action="" method="post" enctype="multipart/form-data">
1253 <?php wp_nonce_field('loginizer-options'); ?>
1254 <table class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1255 <?php
1256
1257 echo '
1258 <tr>
1259 <th style="background:#EFEFEF;">'.__('Relative Path', 'loginizer').'</th>
1260 <th style="width:10%; background:#EFEFEF;">'.__('Suggested', 'loginizer').'</th>
1261 <th style="width:10%; background:#EFEFEF;">'.__('Actual', 'loginizer').'</th>
1262 </tr>';
1263
1264 $wp_content = basename(dirname(dirname(dirname(__FILE__))));
1265
1266 $files_to_check = array('/' => '0755',
1267 '/wp-admin' => '0755',
1268 '/wp-includes' => '0755',
1269 '/wp-config.php' => '0444',
1270 '/'.$wp_content => '0755',
1271 '/'.$wp_content.'/themes' => '0755',
1272 '/'.$wp_content.'/plugins' => '0755',
1273 '.htaccess' => '0444');
1274
1275 $root = ABSPATH;
1276
1277 foreach($files_to_check as $k => $v){
1278
1279 $path = $root.'/'.$k;
1280 $stat = @stat($path);
1281 $suggested = $v;
1282 $actual = substr(sprintf('%o', $stat['mode']), -4);
1283
1284 echo '
1285 <tr>
1286 <td>'.$k.'</td>
1287 <td>'.$suggested.'</td>
1288 <td><span '.($suggested != $actual ? 'style="color: red;"' : '').'>'.$actual.'</span></td>
1289 </tr>';
1290
1291 }
1292
1293 ?>
1294 </table>
1295 </form>
1296
1297 </div>
1298 </div>
1299
1300 <?php
1301
1302 loginizer_page_footer();
1303
1304 }
1305
1306 // The Loginizer Admin Options Page
1307 function loginizer_page_brute_force(){
1308
1309 global $wpdb, $wp_roles, $loginizer;
1310
1311 if(!current_user_can('manage_options')){
1312 wp_die('Sorry, but you do not have permissions to change settings.');
1313 }
1314
1315 /* Make sure post was from this page */
1316 if(count($_POST) > 0){
1317 check_admin_referer('loginizer-options');
1318 }
1319
1320 // BEGIN THEME
1321 loginizer_page_header('Brute Force Settings');
1322
1323 // Load the blacklist and whitelist
1324 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1325 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1326
1327 // Disable Brute Force
1328 if(isset($_POST['disable_brute_lz'])){
1329
1330 // Save the options
1331 update_option('loginizer_disable_brute', 1);
1332
1333 $loginizer['disable_brute'] = 1;
1334
1335 echo '<div id="message" class="updated"><p>'
1336 . __('The Brute Force Protection feature is now disabled', 'loginizer')
1337 . '</p></div><br />';
1338
1339 }
1340
1341 // Enable brute force
1342 if(isset($_POST['enable_brute_lz'])){
1343
1344 // Save the options
1345 update_option('loginizer_disable_brute', 0);
1346
1347 $loginizer['disable_brute'] = 0;
1348
1349 echo '<div id="message" class="updated"><p>'
1350 . __('The Brute Force Protection feature is now enabled', 'loginizer')
1351 . '</p></div><br />';
1352
1353 }
1354
1355 // The Brute Force Settings
1356 if(isset($_POST['save_lz'])){
1357
1358 $max_retries = (int) lz_optpost('max_retries');
1359 $lockout_time = (int) lz_optpost('lockout_time');
1360 $max_lockouts = (int) lz_optpost('max_lockouts');
1361 $lockouts_extend = (int) lz_optpost('lockouts_extend');
1362 $reset_retries = (int) lz_optpost('reset_retries');
1363 $notify_email = (int) lz_optpost('notify_email');
1364
1365 $lockout_time = $lockout_time * 60;
1366 $lockouts_extend = $lockouts_extend * 60 * 60;
1367 $reset_retries = $reset_retries * 60 * 60;
1368
1369 if(empty($error)){
1370
1371 $option['max_retries'] = $max_retries;
1372 $option['lockout_time'] = $lockout_time;
1373 $option['max_lockouts'] = $max_lockouts;
1374 $option['lockouts_extend'] = $lockouts_extend;
1375 $option['reset_retries'] = $reset_retries;
1376 $option['notify_email'] = $notify_email;
1377
1378 // Save the options
1379 update_option('loginizer_options', $option);
1380
1381 $saved = true;
1382
1383 }else{
1384 lz_report_error($error);
1385 }
1386
1387 if(!empty($notice)){
1388 lz_report_notice($notice);
1389 }
1390
1391 if(!empty($saved)){
1392 echo '<div id="message" class="updated"><p>'
1393 . __('The settings were saved successfully', 'loginizer')
1394 . '</p></div><br />';
1395 }
1396
1397 }
1398
1399 // Delete a Blackist IP range
1400 if(isset($_POST['bdelid'])){
1401
1402 $delid = (int) lz_optreq('bdelid');
1403
1404 // Unset and save
1405 $blacklist = $loginizer['blacklist'];
1406 unset($blacklist[$delid]);
1407 update_option('loginizer_blacklist', $blacklist);
1408
1409 echo '<div id="message" class="updated fade"><p>'
1410 . __('The Blacklist IP range has been deleted successfully', 'loginizer')
1411 . '</p></div><br />';
1412
1413 }
1414
1415 // Delete all Blackist IP ranges
1416 if(isset($_POST['del_all_blacklist'])){
1417
1418 // Unset and save
1419 update_option('loginizer_blacklist', array());
1420
1421 echo '<div id="message" class="updated fade"><p>'
1422 . __('The Blacklist IP range(s) have been cleared successfully', 'loginizer')
1423 . '</p></div><br />';
1424
1425 }
1426
1427 // Delete a Whitelist IP range
1428 if(isset($_POST['delid'])){
1429
1430 $delid = (int) lz_optreq('delid');
1431
1432 // Unset and save
1433 $whitelist = $loginizer['whitelist'];
1434 unset($whitelist[$delid]);
1435 update_option('loginizer_whitelist', $whitelist);
1436
1437 echo '<div id="message" class="updated fade"><p>'
1438 . __('The Whitelist IP range has been deleted successfully', 'loginizer')
1439 . '</p></div><br />';
1440
1441 }
1442
1443 // Delete all Blackist IP ranges
1444 if(isset($_POST['del_all_whitelist'])){
1445
1446 // Unset and save
1447 update_option('loginizer_whitelist', array());
1448
1449 echo '<div id="message" class="updated fade"><p>'
1450 . __('The Whitelist IP range(s) have been cleared successfully', 'loginizer')
1451 . '</p></div><br />';
1452
1453 }
1454
1455 // Reset All Logs
1456 if(isset($_POST['lz_reset_all_ip'])){
1457
1458 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1459 WHERE `time` > 0");
1460
1461 echo '<div id="message" class="updated fade"><p>'
1462 . __('All the IP Logs have been cleared', 'loginizer')
1463 . '</p></div><br />';
1464 }
1465
1466 // Reset Logs
1467 if(isset($_POST['lz_reset_ips']) && is_array($_POST['lz_reset_ips'])){
1468
1469 $ips = $_POST['lz_reset_ips'];
1470
1471 foreach($ips as $ip){
1472 if(!lz_valid_ip($ip)){
1473 $error[] = 'The IP - '.$ip.' is invalid !';
1474 }
1475 }
1476
1477 if(count($ips) < 1){
1478 $error[] = 'There are no IPs submitted';
1479 }
1480
1481 // Should we start deleting logs
1482 if(empty($error)){
1483
1484 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1485 WHERE `ip` IN ('".implode("', '", $ips)."')");
1486
1487 if(empty($error)){
1488
1489 echo '<div id="message" class="updated fade"><p>'
1490 . __('The selected IP Logs have been reset', 'loginizer')
1491 . '</p></div><br />';
1492
1493 }
1494
1495 }
1496
1497 if(!empty($error)){
1498 lz_report_error($error);echo '<br />';
1499 }
1500
1501 }
1502
1503 if(isset($_POST['blacklist_iprange'])){
1504
1505 $start_ip = lz_optpost('start_ip');
1506 $end_ip = lz_optpost('end_ip');
1507
1508 if(empty($start_ip)){
1509 $error[] = 'Please enter the Start IP';
1510 }
1511
1512 // If no end IP we consider only 1 IP
1513 if(empty($end_ip)){
1514 $end_ip = $start_ip;
1515 }
1516
1517 if(!lz_valid_ip($start_ip)){
1518 $error[] = 'Please provide a valid start IP';
1519 }
1520
1521 if(!lz_valid_ip($end_ip)){
1522 $error[] = 'Please provide a valid end IP';
1523 }
1524
1525 // Regular ranges will work
1526 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1527
1528 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1529 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1530 // This is right
1531 }else{
1532 $error[] = 'The End IP cannot be smaller than the Start IP';
1533 }
1534
1535 }
1536
1537 if(empty($error)){
1538
1539 $blacklist = $loginizer['blacklist'];
1540
1541 foreach($blacklist as $k => $v){
1542
1543 // This is to check if there is any other range exists with the same Start or End IP
1544 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1545 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1546 ){
1547 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1548 break;
1549 }
1550
1551 // This is to check if there is any other range exists with the same Start IP
1552 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1553 $error[] = 'The Start IP is present in an existing range !';
1554 break;
1555 }
1556
1557 // This is to check if there is any other range exists with the same End IP
1558 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1559 $error[] = 'The End IP is present in an existing range!';
1560 break;
1561 }
1562
1563 }
1564
1565 $newid = ( empty($blacklist) ? 0 : max(array_keys($blacklist)) ) + 1;
1566
1567 if(empty($error)){
1568
1569 $blacklist[$newid] = array();
1570 $blacklist[$newid]['start'] = $start_ip;
1571 $blacklist[$newid]['end'] = $end_ip;
1572 $blacklist[$newid]['time'] = time();
1573
1574 update_option('loginizer_blacklist', $blacklist);
1575
1576 echo '<div id="message" class="updated fade"><p>'
1577 . __('Blacklist IP range added successfully', 'loginizer')
1578 . '</p></div><br />';
1579
1580 }
1581
1582 }
1583
1584 if(!empty($error)){
1585 lz_report_error($error);echo '<br />';
1586 }
1587
1588 }
1589
1590 if(isset($_POST['whitelist_iprange'])){
1591
1592 $start_ip = lz_optpost('start_ip_w');
1593 $end_ip = lz_optpost('end_ip_w');
1594
1595 if(empty($start_ip)){
1596 $error[] = 'Please enter the Start IP';
1597 }
1598
1599 // If no end IP we consider only 1 IP
1600 if(empty($end_ip)){
1601 $end_ip = $start_ip;
1602 }
1603
1604 if(!lz_valid_ip($start_ip)){
1605 $error[] = 'Please provide a valid start IP';
1606 }
1607
1608 if(!lz_valid_ip($end_ip)){
1609 $error[] = 'Please provide a valid end IP';
1610 }
1611
1612 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1613
1614 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1615 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1616 // This is right
1617 }else{
1618 $error[] = 'The End IP cannot be smaller than the Start IP';
1619 }
1620
1621 }
1622
1623 if(empty($error)){
1624
1625 $whitelist = $loginizer['whitelist'];
1626
1627 foreach($whitelist as $k => $v){
1628
1629 // This is to check if there is any other range exists with the same Start or End IP
1630 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1631 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1632 ){
1633 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1634 break;
1635 }
1636
1637 // This is to check if there is any other range exists with the same Start IP
1638 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1639 $error[] = 'The Start IP is present in an existing range !';
1640 break;
1641 }
1642
1643 // This is to check if there is any other range exists with the same End IP
1644 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1645 $error[] = 'The End IP is present in an existing range!';
1646 break;
1647 }
1648
1649 }
1650
1651 $newid = ( empty($whitelist) ? 0 : max(array_keys($whitelist)) ) + 1;
1652
1653 if(empty($error)){
1654
1655 $whitelist[$newid] = array();
1656 $whitelist[$newid]['start'] = $start_ip;
1657 $whitelist[$newid]['end'] = $end_ip;
1658 $whitelist[$newid]['time'] = time();
1659
1660 update_option('loginizer_whitelist', $whitelist);
1661
1662 echo '<div id="message" class="updated fade"><p>'
1663 . __('Whitelist IP range added successfully', 'loginizer')
1664 . '</p></div><br />';
1665
1666 }
1667
1668 }
1669
1670 if(!empty($error)){
1671 lz_report_error($error);echo '<br />';
1672 }
1673 }
1674
1675 // Save the messages
1676 if(isset($_POST['save_err_msgs_lz'])){
1677
1678 $msgs['inv_userpass'] = lz_optpost('msg_inv_userpass');
1679 $msgs['ip_blacklisted'] = lz_optpost('msg_ip_blacklisted');
1680
1681 // Update them
1682 update_option('loginizer_msg', $msgs);
1683
1684 echo '<div id="message" class="updated fade"><p>'
1685 . __('Error messages were saved successfully', 'loginizer')
1686 . '</p></div><br />';
1687
1688 }
1689
1690 // Count the Results
1691 $tmp = lz_selectquery("SELECT COUNT(*) AS num FROM `".$wpdb->prefix."loginizer_logs`");
1692 //print_r($tmp);
1693
1694 // Which Page is it
1695 $lz_env['res_len'] = 10;
1696 $lz_env['cur_page'] = lz_get_page('lzpage', $lz_env['res_len']);
1697 $lz_env['num_res'] = $tmp['num'];
1698 $lz_env['max_page'] = ceil($lz_env['num_res'] / $lz_env['res_len']);
1699
1700 // Get the logs
1701 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs`
1702 ORDER BY `time` DESC
1703 LIMIT ".$lz_env['cur_page'].", ".$lz_env['res_len']."", 1);
1704 //print_r($result);
1705
1706 $lz_env['cur_page'] = ($lz_env['cur_page'] / $lz_env['res_len']) + 1;
1707 $lz_env['cur_page'] = $lz_env['cur_page'] < 1 ? 1 : $lz_env['cur_page'];
1708 $lz_env['next_page'] = ($lz_env['cur_page'] + 1) > $lz_env['max_page'] ? $lz_env['max_page'] : ($lz_env['cur_page'] + 1);
1709 $lz_env['prev_page'] = ($lz_env['cur_page'] - 1) < 1 ? 1 : ($lz_env['cur_page'] - 1);
1710
1711 // Reload the settings
1712 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1713 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1714
1715 $saved_msgs = get_option('loginizer_msg');
1716
1717 ?>
1718
1719 <div id="" class="postbox">
1720
1721 <button class="handlediv button-link" aria-expanded="true" type="button">
1722 <span class="screen-reader-text">Toggle panel: Failed Login Attempts Logs</span>
1723 <span class="toggle-indicator" aria-hidden="true"></span>
1724 </button>
1725
1726 <h2 class="hndle ui-sortable-handle">
1727 <?php echo __('<span>Failed Login Attempts Logs</span> &nbsp; (Past '.($loginizer['reset_retries']/60/60).' hours)','loginizer'); ?>
1728 </h2>
1729
1730 <script>
1731 function yesdsd(){
1732 window.location = '<?php echo menu_page_url('loginizer_brute_force', false);?>&lzpage='+jQuery("#current-page-selector").val();
1733 return false;
1734 }
1735 </script>
1736
1737 <form method="get" onsubmit="return yesdsd();">
1738 <div class="tablenav">
1739 <p class="tablenav-pages" style="margin: 5px 10px" align="right">
1740 <span class="displaying-num"><?php echo $lz_env['num_res'];?> items</span>
1741 <span class="pagination-links">
1742 <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>
1743 <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>
1744 <span class="paging-input">
1745 <label for="current-page-selector" class="screen-reader-text">Current Page</label>
1746 <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>
1747 </span>
1748 <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>
1749 <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>
1750 </span>
1751 </p>
1752 </div>
1753 </form>
1754
1755 <form action="" method="post" enctype="multipart/form-data">
1756 <?php wp_nonce_field('loginizer-options'); ?>
1757 <div class="inside">
1758 <table class="wp-list-table widefat fixed users" border="0">
1759 <tr>
1760 <th scope="row" valign="top" style="background:#EFEFEF;" width="20">#</th>
1761 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('IP','loginizer'); ?></th>
1762 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Attempted Username','loginizer'); ?></th>
1763 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Last Failed Attempt (DD/MM/YYYY)','loginizer'); ?></th>
1764 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Failed Attempts Count','loginizer'); ?></th>
1765 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Lockouts Count','loginizer'); ?></th>
1766 <th scope="row" valign="top" style="background:#EFEFEF;" width="150"><?php echo __('URL Attacked','loginizer'); ?></th>
1767 </tr>
1768 <?php
1769
1770 if(empty($result)){
1771 echo '
1772 <tr>
1773 <td colspan="4">
1774 No Logs. You will see logs about failed login attempts here.
1775 </td>
1776 </tr>';
1777 }else{
1778 foreach($result as $ik => $iv){
1779 $status_button = (!empty($iv['status']) ? 'disable' : 'enable');
1780 echo '
1781 <tr>
1782 <td>
1783 <input type="checkbox" value="'.$iv['ip'].'" name="lz_reset_ips[]" />
1784 </td>
1785 <td>
1786 '.$iv['ip'].'
1787 </td>
1788 <td>
1789 '.$iv['username'].'
1790 </td>
1791 <td>
1792 '.date('d/M/Y H:i:s P', $iv['time']).'
1793 </td>
1794 <td>
1795 '.$iv['count'].'
1796 </td>
1797 <td>
1798 '.$iv['lockout'].'
1799 </td>
1800 <td>
1801 '.$iv['url'].'
1802 </td>
1803 </tr>';
1804 }
1805 }
1806
1807 ?>
1808 </table>
1809
1810 <br>
1811 <input name="lz_reset_ip" class="button button-primary action" value="<?php echo __('Remove From Logs', 'loginizer'); ?>" type="submit" />
1812 &nbsp; &nbsp;
1813 <input name="lz_reset_all_ip" class="button button-primary action" value="<?php echo __('Clear All Logs', 'loginizer'); ?>" type="submit" />
1814 </div>
1815 </div>
1816 </form>
1817 <br />
1818
1819 <div id="" class="postbox">
1820
1821 <button class="handlediv button-link" aria-expanded="true" type="button">
1822 <span class="screen-reader-text">Toggle panel: Brute Force Settings</span>
1823 <span class="toggle-indicator" aria-hidden="true"></span>
1824 </button>
1825
1826 <h2 class="hndle ui-sortable-handle">
1827 <span><?php echo __('Brute Force Settings', 'loginizer'); ?></span>
1828 </h2>
1829
1830 <div class="inside">
1831
1832 <form action="" method="post" enctype="multipart/form-data">
1833 <?php wp_nonce_field('loginizer-options'); ?>
1834 <table class="form-table">
1835 <tr>
1836 <th scope="row" valign="top"><label for="max_retries"><?php echo __('Max Retries','loginizer'); ?></label></th>
1837 <td>
1838 <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 />
1839 </td>
1840 </tr>
1841 <tr>
1842 <th scope="row" valign="top"><label for="lockout_time"><?php echo __('Lockout Time','loginizer'); ?></label></th>
1843 <td>
1844 <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 />
1845 </td>
1846 </tr>
1847 <tr>
1848 <th scope="row" valign="top"><label for="max_lockouts"><?php echo __('Max Lockouts','loginizer'); ?></label></th>
1849 <td>
1850 <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 />
1851 </td>
1852 </tr>
1853 <tr>
1854 <th scope="row" valign="top"><label for="lockouts_extend"><?php echo __('Extend Lockout','loginizer'); ?></label></th>
1855 <td>
1856 <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 />
1857 </td>
1858 </tr>
1859 <tr>
1860 <th scope="row" valign="top"><label for="reset_retries"><?php echo __('Reset Retries','loginizer'); ?></label></th>
1861 <td>
1862 <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 />
1863 </td>
1864 </tr>
1865 <tr>
1866 <th scope="row" valign="top"><label for="notify_email"><?php echo __('Email Notification','loginizer'); ?></label></th>
1867 <td>
1868 <?php echo __('after ','loginizer'); ?>
1869 <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'); ?>
1870 </td>
1871 </tr>
1872 </table><br />
1873 <input name="save_lz" class="button button-primary action" value="<?php echo __('Save Settings','loginizer'); ?>" type="submit" />
1874 <?php
1875
1876 if(empty($loginizer['disable_brute'])){
1877
1878 echo '<input name="disable_brute_lz" class="button action" value="'.__('Disable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1879
1880 }else{
1881
1882 echo '<input name="enable_brute_lz" class="button button-primary action" value="'.__('Enable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1883
1884 }
1885
1886 ?>
1887 </form>
1888
1889 </div>
1890 </div>
1891 <br />
1892
1893 <?php
1894
1895 wp_enqueue_script('jquery-paginate', LOGINIZER_URL.'/jquery-paginate.js', array('jquery'), '1.10.15');
1896
1897 ?>
1898
1899 <style>
1900 .page-navigation a {
1901 margin: 5px 2px;
1902 display: inline-block;
1903 padding: 5px 8px;
1904 color: #0073aa;
1905 background: #e5e5e5 none repeat scroll 0 0;
1906 border: 1px solid #ccc;
1907 text-decoration: none;
1908 transition-duration: 0.05s;
1909 transition-property: border, background, color;
1910 transition-timing-function: ease-in-out;
1911 }
1912
1913 .page-navigation a[data-selected] {
1914 background-color: #00a0d2;
1915 color: #fff;
1916 }
1917 </style>
1918
1919 <script>
1920
1921 jQuery(document).ready(function(){
1922 jQuery('#lz_bl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_bl_nav')});
1923 jQuery('#lz_wl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_wl_nav')});
1924 });
1925
1926 // Delete a Blacklist / Whitelist IP Range
1927 function del_confirm(field, todo_id, msg){
1928 var ret = confirm(msg);
1929
1930 if(ret){
1931 jQuery('#lz_bl_wl_todo').attr('name', field);
1932 jQuery('#lz_bl_wl_todo').val(todo_id);
1933 jQuery('#lz_bl_wl_form').submit();
1934 }
1935
1936 return false;
1937
1938 }
1939
1940 // Delete all Blacklist / Whitelist IP Ranges
1941 function del_confirm_all(msg){
1942 var ret = confirm(msg);
1943
1944 if(ret){
1945 return true;
1946 }
1947
1948 return false;
1949
1950 }
1951
1952 </script>
1953
1954 <div id="" class="postbox">
1955
1956 <button class="handlediv button-link" aria-expanded="true" type="button">
1957 <span class="screen-reader-text">Toggle panel: Blacklist IP</span>
1958 <span class="toggle-indicator" aria-hidden="true"></span>
1959 </button>
1960
1961 <h2 class="hndle ui-sortable-handle">
1962 <span><?php echo __('Blacklist IP','loginizer'); ?></span>
1963 </h2>
1964
1965 <div class="inside">
1966
1967 <?php echo __('Enter the IP you want to blacklist from login','loginizer'); ?>
1968
1969 <form action="" method="post">
1970 <?php wp_nonce_field('loginizer-options'); ?>
1971 <table class="form-table">
1972 <tr>
1973 <th scope="row" valign="top"><label for="start_ip"><?php echo __('Start IP','loginizer'); ?></label></th>
1974 <td>
1975 <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 />
1976 </td>
1977 </tr>
1978 <tr>
1979 <th scope="row" valign="top"><label for="end_ip"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
1980 <td>
1981 <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 />
1982 </td>
1983 </tr>
1984 </table><br />
1985 <input name="blacklist_iprange" class="button button-primary action" value="<?php echo __('Add Blacklist IP Range','loginizer'); ?>" type="submit" />
1986 <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" />
1987 </form>
1988 </div>
1989
1990 <div id="lz_bl_nav" style="margin: 5px 10px; text-align:right"></div>
1991 <table id="lz_bl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1992 <tr>
1993 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
1994 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
1995 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
1996 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
1997 </tr>
1998 <?php
1999 if(empty($loginizer['blacklist'])){
2000 echo '
2001 <tr>
2002 <td colspan="4">
2003 No Blacklist IPs. You will see blacklisted IP ranges here.
2004 </td>
2005 </tr>';
2006 }else{
2007 foreach($loginizer['blacklist'] as $ik => $iv){
2008 echo '
2009 <tr>
2010 <td>
2011 '.$iv['start'].'
2012 </td>
2013 <td>
2014 '.$iv['end'].'
2015 </td>
2016 <td>
2017 '.date('d/m/Y', $iv['time']).'
2018 </td>
2019 <td>
2020 <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>
2021 </td>
2022 </tr>';
2023 }
2024 }
2025 ?>
2026 </table>
2027 <br />
2028 <form action="" method="post" id="lz_bl_wl_form">
2029 <?php wp_nonce_field('loginizer-options'); ?>
2030 <input type="hidden" value="" name="" id="lz_bl_wl_todo"/>
2031 </form>
2032 </div>
2033
2034 <br />
2035
2036 <div id="" class="postbox">
2037
2038 <button class="handlediv button-link" aria-expanded="true" type="button">
2039 <span class="screen-reader-text">Toggle panel: Whitelist IP</span>
2040 <span class="toggle-indicator" aria-hidden="true"></span>
2041 </button>
2042
2043 <h2 class="hndle ui-sortable-handle">
2044 <span><?php echo __('Whitelist IP', 'loginizer'); ?></span>
2045 </h2>
2046
2047 <div class="inside">
2048
2049 <?php echo __('Enter the IP you want to whitelist for login','loginizer'); ?>
2050 <form action="" method="post">
2051 <?php wp_nonce_field('loginizer-options'); ?>
2052 <table class="form-table">
2053 <tr>
2054 <th scope="row" valign="top"><label for="start_ip_w"><?php echo __('Start IP','loginizer'); ?></label></th>
2055 <td>
2056 <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 />
2057 </td>
2058 </tr>
2059 <tr>
2060 <th scope="row" valign="top"><label for="end_ip_w"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
2061 <td>
2062 <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 />
2063 </td>
2064 </tr>
2065 </table><br />
2066 <input name="whitelist_iprange" class="button button-primary action" value="<?php echo __('Add Whitelist IP Range','loginizer'); ?>" type="submit" />
2067 <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" />
2068 </form>
2069 </div>
2070
2071 <div id="lz_wl_nav" style="margin: 5px 10px; text-align:right"></div>
2072 <table id="lz_wl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
2073 <tr>
2074 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
2075 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
2076 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
2077 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
2078 </tr>
2079 <?php
2080 if(empty($loginizer['whitelist'])){
2081 echo '
2082 <tr>
2083 <td colspan="4">
2084 No Whitelist IPs. You will see whitelisted IP ranges here.
2085 </td>
2086 </tr>';
2087 }else{
2088 foreach($loginizer['whitelist'] as $ik => $iv){
2089 echo '
2090 <tr>
2091 <td>
2092 '.$iv['start'].'
2093 </td>
2094 <td>
2095 '.$iv['end'].'
2096 </td>
2097 <td>
2098 '.date('d/m/Y', $iv['time']).'
2099 </td>
2100 <td>
2101 <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>
2102 </td>
2103 </tr>';
2104 }
2105 }
2106 ?>
2107 </table>
2108 <br />
2109
2110 </div>
2111
2112 <div id="" class="postbox">
2113
2114 <button class="handlediv button-link" aria-expanded="true" type="button">
2115 <span class="screen-reader-text">Toggle panel: Error Messages</span>
2116 <span class="toggle-indicator" aria-hidden="true"></span>
2117 </button>
2118
2119 <h2 class="hndle ui-sortable-handle">
2120 <span><?php echo __('Error Messages', 'loginizer'); ?></span>
2121 </h2>
2122
2123 <div class="inside">
2124
2125 <form action="" method="post" enctype="multipart/form-data">
2126 <?php wp_nonce_field('loginizer-options'); ?>
2127 <table class="form-table">
2128 <tr>
2129 <th scope="row" valign="top"><label for="msg_inv_userpass"><?php echo __('Failed Login Attempt','loginizer'); ?></label></th>
2130 <td>
2131 <input type="text" size="25" value="<?php echo esc_attr(@$saved_msgs['inv_userpass']); ?>" name="msg_inv_userpass" id="msg_inv_userpass" />
2132 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['inv_userpass']. '&quot;</em>', 'loginizer'); ?><br />
2133 </td>
2134 </tr>
2135 <tr>
2136 <th scope="row" valign="top"><label for="msg_ip_blacklisted"><?php echo __('Blacklisted IP','loginizer'); ?></label></th>
2137 <td>
2138 <input type="text" size="25" value="<?php echo esc_attr(@$saved_msgs['ip_blacklisted']); ?>" name="msg_ip_blacklisted" id="msg_ip_blacklisted" />
2139 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['ip_blacklisted']. '&quot;</em>', 'loginizer'); ?><br />
2140 </td>
2141 </tr>
2142 </table><br />
2143 <input name="save_err_msgs_lz" class="button button-primary action" value="<?php echo __('Save Error Messages','loginizer'); ?>" type="submit" />
2144 </form>
2145 </div>
2146 </div>
2147 <?php
2148
2149 loginizer_page_footer();
2150
2151 }
2152
2153
2154 // Sorry to see you going
2155 register_uninstall_hook(LOGINIZER_FILE, 'loginizer_deactivation');
2156
2157 function loginizer_deactivation(){
2158
2159 global $wpdb;
2160
2161 $sql = array();
2162 $sql[] = "DROP TABLE ".$wpdb->prefix."loginizer_logs;";
2163
2164 foreach($sql as $sk => $sv){
2165 $wpdb->query($sv);
2166 }
2167
2168 delete_option('loginizer_version');
2169 delete_option('loginizer_options');
2170 delete_option('loginizer_last_reset');
2171 delete_option('loginizer_whitelist');
2172 delete_option('loginizer_blacklist');
2173 delete_option('loginizer_msg');
2174 delete_option('loginizer_security');
2175 delete_option('loginizer_wp_admin');
2176
2177 }
2178
2179