PluginProbe
Loginizer / 1.3.4
Loginizer v1.3.4
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.3.4, at init.php

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