PluginProbe
Loginizer / 1.8.2
Loginizer v1.8.2
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 / main / settings / brute-force.php

brute-force.php in Loginizer 1.8.2, at main/settings/brute-force.php

1,174 lines 40.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!defined('ABSPATH')){
4 die('Hacking Attempt!');
5 }
6
7 // The Loginizer Admin Options Page
8 function loginizer_page_brute_force(){
9
10 global $wpdb, $wp_roles, $loginizer;
11
12 if(!current_user_can('manage_options')){
13 wp_die('Sorry, but you do not have permissions to change settings.');
14 }
15
16 /* Make sure post was from this page */
17 if(count($_POST) > 0){
18 check_admin_referer('loginizer-options');
19 }
20
21 // BEGIN THEME
22 loginizer_page_header('Brute Force Settings');
23
24 // Load the blacklist and whitelist
25 $loginizer['blacklist'] = get_option('loginizer_blacklist');
26 $loginizer['whitelist'] = get_option('loginizer_whitelist');
27
28 // Disable Brute Force
29 if(isset($_POST['disable_brute_lz'])){
30
31 // Save the options
32 update_option('loginizer_disable_brute', 1);
33
34 $loginizer['disable_brute'] = 1;
35
36 echo '<div id="message" class="updated"><p>'
37 . __('The Brute Force Protection feature is now disabled', 'loginizer')
38 . '</p></div><br />';
39
40 }
41
42 // Enable brute force
43 if(isset($_POST['enable_brute_lz'])){
44
45 // Save the options
46 update_option('loginizer_disable_brute', 0);
47
48 $loginizer['disable_brute'] = 0;
49
50 echo '<div id="message" class="updated"><p>'
51 . __('The Brute Force Protection feature is now enabled', 'loginizer')
52 . '</p></div><br />';
53
54 }
55
56 // The Brute Force Settings
57 if(isset($_POST['save_lz'])){
58
59 $max_retries = (int) lz_optpost('max_retries');
60 $lockout_time = (int) lz_optpost('lockout_time');
61 $max_lockouts = (int) lz_optpost('max_lockouts');
62 $lockouts_extend = (int) lz_optpost('lockouts_extend');
63 $reset_retries = (int) lz_optpost('reset_retries');
64 $notify_email = (int) lz_optpost('notify_email');
65 $notify_email_address = lz_optpost('notify_email_address');
66 $trusted_ips = lz_optpost('trusted_ips');
67
68 if(!empty($notify_email_address) && !lz_valid_email($notify_email_address)){
69 $error[] = __('Email address is invalid', 'loginizer');
70 }
71
72 if(empty(loginizer_is_whitelisted()) && isset($_POST['trusted_ips'])){
73 $error[] = __('Add your IP to whitelist to enable Trusted IP\'s', 'loginizer');
74 }
75
76 if(!empty($max_retries) && $max_retries < 0){
77 $error[] = __('Max Retries value is invalid', 'loginizer');
78 }
79
80 if(!empty($lockout_time) && $lockout_time < 0){
81 $error[] = __('Lockout Time value is invalid', 'loginizer');
82 }
83
84 if(!empty($max_lockouts) && $max_lockouts < 0){
85 $error[] = __('Max Lockouts value is invalid', 'loginizer');
86 }
87
88 if(!empty($lockouts_extend) && $lockouts_extend < 0){
89 $error[] = __('Extended Lockout value is invalid', 'loginizer');
90 }
91
92 if(!empty($reset_retries) && $reset_retries < 0){
93 $error[] = __('Reset Retries value is invalid', 'loginizer');
94 }
95
96 if(!empty($notify_email) && $notify_email < 0){
97 $error[] = __('Email Notification value is invalid', 'loginizer');
98 }
99
100 $lockout_time = $lockout_time * 60;
101 $lockouts_extend = $lockouts_extend * 60 * 60;
102 $reset_retries = $reset_retries * 60 * 60;
103
104 if(empty($error)){
105
106 $option['max_retries'] = $max_retries;
107 $option['lockout_time'] = $lockout_time;
108 $option['max_lockouts'] = $max_lockouts;
109 $option['lockouts_extend'] = $lockouts_extend;
110 $option['reset_retries'] = $reset_retries;
111 $option['notify_email'] = $notify_email;
112 $option['notify_email_address'] = $notify_email_address;
113 $option['trusted_ips'] = $trusted_ips;
114
115 // Save the options
116 update_option('loginizer_options', $option);
117
118 $saved = true;
119
120 }else{
121 lz_report_error($error);
122 }
123
124 if(!empty($notice)){
125 lz_report_notice($notice);
126 }
127
128 if(!empty($saved)){
129 echo '<div id="message" class="updated"><p>'
130 . __('The settings were saved successfully', 'loginizer')
131 . '</p></div><br />';
132 }
133
134 }
135
136 // Delete a Blackist IP range
137 if(isset($_POST['bdelid'])){
138
139 $delid = (int) lz_optreq('bdelid');
140
141 // Unset and save
142 $blacklist = $loginizer['blacklist'];
143 unset($blacklist[$delid]);
144 update_option('loginizer_blacklist', $blacklist);
145
146 echo '<div id="message" class="updated fade"><p>'
147 . __('The Blacklist IP range has been deleted successfully', 'loginizer')
148 . '</p></div><br />';
149
150 }
151
152 // Delete all Blackist IP ranges
153 if(isset($_POST['del_all_blacklist'])){
154
155 // Unset and save
156 update_option('loginizer_blacklist', array());
157
158 echo '<div id="message" class="updated fade"><p>'
159 . __('The Blacklist IP range(s) have been cleared successfully', 'loginizer')
160 . '</p></div><br />';
161
162 }
163
164 // Delete a Whitelist IP range
165 if(isset($_POST['delid'])){
166
167 $delid = (int) lz_optreq('delid');
168
169 // Unset and save
170 $whitelist = $loginizer['whitelist'];
171 unset($whitelist[$delid]);
172 update_option('loginizer_whitelist', $whitelist);
173
174 echo '<div id="message" class="updated fade"><p>'
175 . __('The Whitelist IP range has been deleted successfully', 'loginizer')
176 . '</p></div><br />';
177
178 }
179
180 // Delete all Blackist IP ranges
181 if(isset($_POST['del_all_whitelist'])){
182
183 // Unset and save
184 update_option('loginizer_whitelist', array());
185
186 echo '<div id="message" class="updated fade"><p>'
187 . __('The Whitelist IP range(s) have been cleared successfully', 'loginizer')
188 . '</p></div><br />';
189
190 }
191
192 // Reset All Logs
193 if(isset($_POST['lz_reset_all_ip'])){
194
195 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs` WHERE `time` > 0");
196
197 echo '<div id="message" class="updated fade"><p>'
198 . __('All the IP Logs have been cleared', 'loginizer')
199 . '</p></div><br />';
200 }
201
202 // Reset Logs
203 if(isset($_POST['lz_reset_ip']) && isset($_POST['lz_reset_ips']) && is_array($_POST['lz_reset_ips'])){
204
205 $ips = $_POST['lz_reset_ips'];
206
207 foreach($ips as $ip){
208 if(!lz_valid_ip($ip)){
209 $error[] = 'The IP - '.esc_html($ip).' is invalid !';
210 }
211 }
212
213 if(count($ips) < 1){
214 $error[] = __('There are no IPs submitted', 'loginizer');
215 }
216
217 // Should we start deleting logs
218 if(empty($error)){
219
220 foreach($ips as $ip){
221 $result = $wpdb->query($wpdb->prepare("DELETE FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = %s", $ip));
222 }
223
224 if(empty($error)){
225
226 echo '<div id="message" class="updated fade"><p>'
227 . __('The selected IP Logs have been reset', 'loginizer')
228 . '</p></div><br />';
229
230 }
231
232 }
233
234 if(!empty($error)){
235 lz_report_error($error);echo '<br />';
236 }
237
238 }
239
240 if(isset($_POST['blacklist_iprange'])){
241
242 $start_ip = lz_optpost('start_ip');
243 $end_ip = lz_optpost('end_ip');
244
245 // If no end IP we consider only 1 IP
246 if(empty($end_ip)){
247 $end_ip = $start_ip;
248 }
249
250 // Validate the IP against all checks
251 loginizer_iprange_validate($start_ip, $end_ip, $loginizer['blacklist'], $error);
252
253 if(empty($error)){
254
255 $blacklist = $loginizer['blacklist'];
256
257 $newid = ( empty($blacklist) ? 0 : max(array_keys($blacklist)) ) + 1;
258
259 $blacklist[$newid] = array();
260 $blacklist[$newid]['start'] = $start_ip;
261 $blacklist[$newid]['end'] = $end_ip;
262 $blacklist[$newid]['time'] = time();
263
264 update_option('loginizer_blacklist', $blacklist);
265
266 echo '<div id="message" class="updated fade"><p>'
267 . __('Blacklist IP range added successfully', 'loginizer')
268 . '</p></div><br />';
269
270 }
271
272 if(!empty($error)){
273 lz_report_error($error);echo '<br />';
274 }
275
276 }
277
278 if(isset($_POST['whitelist_iprange'])){
279
280 $start_ip = lz_optpost('start_ip_w');
281 $end_ip = lz_optpost('end_ip_w');
282
283 // If no end IP we consider only 1 IP
284 if(empty($end_ip)){
285 $end_ip = $start_ip;
286 }
287
288 // Validate the IP against all checks
289 loginizer_iprange_validate($start_ip, $end_ip, $loginizer['whitelist'], $error);
290
291 if(empty($error)){
292
293 $whitelist = $loginizer['whitelist'];
294
295 $newid = ( empty($whitelist) ? 0 : max(array_keys($whitelist)) ) + 1;
296
297 $whitelist[$newid] = array();
298 $whitelist[$newid]['start'] = $start_ip;
299 $whitelist[$newid]['end'] = $end_ip;
300 $whitelist[$newid]['time'] = time();
301
302 update_option('loginizer_whitelist', $whitelist);
303
304 echo '<div id="message" class="updated fade"><p>'
305 . __('Whitelist IP range added successfully', 'loginizer')
306 . '</p></div><br />';
307
308 }
309
310 if(!empty($error)){
311 lz_report_error($error);echo '<br />';
312 }
313 }
314
315 if(isset($_POST['lz_import_csv'])){
316
317 if(!empty($_FILES['lz_import_file_csv']['name'])){
318
319 $lz_csv_type = lz_optpost('lz_csv_type');
320
321 // Is the submitted type in the allowed list ?
322 if(!in_array($lz_csv_type, array('blacklist', 'whitelist'))){
323 $error[] = __('Invalid import type', 'loginizer');
324 }
325
326 if(empty($error)){
327
328 //Get the extension of the file
329 $csv_file_name = basename($_FILES['lz_import_file_csv']['name']);
330 $csv_ext_name = strtolower(pathinfo($csv_file_name, PATHINFO_EXTENSION));
331
332 //Check if it's a csv file
333 if($csv_ext_name == 'csv'){
334
335 $file = fopen($_FILES['lz_import_file_csv']['tmp_name'], "r");
336
337 $line_count = 0;
338 $update_record = 0;
339
340 while($content = fgetcsv($file)){
341
342 //Increment the $line_count
343 $line_count++;
344
345 //Skip the first line
346 if($line_count <= 1){
347 continue;
348 }
349
350 if(loginizer_iprange_validate($content[0], $content[1], $loginizer[$lz_csv_type], $error, $line_count)){
351
352 $newid = ( empty($loginizer[$lz_csv_type]) ? 0 : max(array_keys($loginizer[$lz_csv_type])) ) + 1;
353
354 $loginizer[$lz_csv_type][$newid] = array();
355 $loginizer[$lz_csv_type][$newid]['start'] = $content[0];
356 $loginizer[$lz_csv_type][$newid]['end'] = $content[1];
357 $loginizer[$lz_csv_type][$newid]['time'] = time();
358
359 $update_record = 1;
360
361 }
362 }
363
364 fclose($file);
365
366 if(!empty($update_record)){
367
368 update_option('loginizer_'.$lz_csv_type, $loginizer[$lz_csv_type]);
369
370 echo '<div id="message" class="updated fade"><p>'
371 . __('Imported '.ucfirst($lz_csv_type).' IP range(s) successfully', 'loginizer')
372 . '</p></div><br />';
373
374 }
375
376 if(!empty($error)){
377 lz_report_error($error);echo '<br />';
378 }
379 }
380
381 }
382 }
383 }
384
385 //Brute Force Bulk Blacklist/ Whitelist Ip
386 if(isset($_POST['lz_blacklist_selected_ip'])){
387 if(isset($_POST['lz_reset_ips']) && is_array($_POST['lz_reset_ips'])){
388
389 $ips = $_POST['lz_reset_ips'];
390
391 foreach($ips as $ip){
392 if(!lz_valid_ip($ip)){
393 $error[] = 'The IP - '.esc_html($ip).' is invalid !';
394 }
395 }
396
397 if(count($ips) < 1){
398 $error[] = __('There are no IPs submitted', 'loginizer');
399 }
400
401 // Should we start deleting logs
402 if(empty($error)){
403
404 $update_record = 0;
405
406 foreach($ips as $ip){
407
408 if(loginizer_iprange_validate($ip, '', $loginizer['blacklist'], $error)){
409
410 $newid = ( empty($loginizer['blacklist']) ? 0 : max(array_keys($loginizer['blacklist'])) ) + 1;
411
412 $loginizer['blacklist'][$newid] = array();
413 $loginizer['blacklist'][$newid]['start'] = $ip;
414 $loginizer['blacklist'][$newid]['end'] = $ip;
415 $loginizer['blacklist'][$newid]['time'] = time();
416
417 $update_record = 1;
418 }
419 }
420
421 if(!empty($update_record)){
422
423 update_option('loginizer_blacklist', $loginizer['blacklist']);
424
425 echo '<div id="message" class="updated fade"><p>'
426 . __('The selected IP(s) have been blacklisted', 'loginizer')
427 . '</p></div><br />';
428
429 }
430
431 }
432 }else{
433 $error[] = __('No IP(s) selected', 'loginizer');
434 }
435
436 if(!empty($error)){
437 lz_report_error($error);echo '<br />';
438 }
439 }
440
441 // Save the messages
442 if(isset($_POST['save_err_msgs_lz'])){
443
444 $msgs['inv_userpass'] = lz_optpost('msg_inv_userpass');
445 $msgs['ip_blacklisted'] = lz_optpost('msg_ip_blacklisted');
446 $msgs['attempts_left'] = lz_optpost('msg_attempts_left');
447 $msgs['lockout_err'] = lz_optpost('msg_lockout_err');
448 $msgs['minutes_err'] = lz_optpost('msg_minutes_err');
449 $msgs['hours_err'] = lz_optpost('msg_hours_err');
450
451 // Update them
452 update_option('loginizer_msg', $msgs);
453
454 echo '<div id="message" class="updated fade"><p>'
455 . __('Error messages were saved successfully', 'loginizer')
456 . '</p></div><br />';
457
458 }
459
460 // Count the Results
461 $tmp = lz_selectquery("SELECT COUNT(*) AS num FROM `".$wpdb->prefix."loginizer_logs`");
462 //print_r($tmp);
463
464 // Which Page is it
465 $lz_env['res_len'] = 10;
466 $lz_env['cur_page'] = lz_get_page('lzpage', $lz_env['res_len']);
467 $lz_env['num_res'] = $tmp['num'];
468 $lz_env['max_page'] = ceil($lz_env['num_res'] / $lz_env['res_len']);
469
470 // Get the logs
471 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs`
472 ORDER BY `time` DESC
473 LIMIT ".$lz_env['cur_page'].", ".$lz_env['res_len']."", 1);
474 //print_r($result);
475
476 $lz_env['cur_page'] = ($lz_env['cur_page'] / $lz_env['res_len']) + 1;
477 $lz_env['cur_page'] = $lz_env['cur_page'] < 1 ? 1 : $lz_env['cur_page'];
478 $lz_env['next_page'] = ($lz_env['cur_page'] + 1) > $lz_env['max_page'] ? $lz_env['max_page'] : ($lz_env['cur_page'] + 1);
479 $lz_env['prev_page'] = ($lz_env['cur_page'] - 1) < 1 ? 1 : ($lz_env['cur_page'] - 1);
480
481 // Reload the settings
482 $loginizer['blacklist'] = get_option('loginizer_blacklist');
483 $loginizer['whitelist'] = get_option('loginizer_whitelist');
484
485 $saved_msgs = get_option('loginizer_msg');
486
487 ?>
488
489 <div id="" class="postbox">
490
491 <div class="postbox-header">
492 <h2 class="hndle ui-sortable-handle">
493 <?php echo '<span>'.__('Failed Login Attempts Logs', 'loginizer').'</span> &nbsp; ('.__('Past', 'loginizer').' '.($loginizer['reset_retries']/60/60).' '.__('hours', 'loginizer').')'; ?>
494 </h2>
495 </div>
496
497 <script>
498 function yesdsd(){
499 window.location = '<?php echo menu_page_url('loginizer_brute_force', false);?>&lzpage='+jQuery("#current-page-selector").val();
500 return false;
501 }
502
503 function lz_export_ajax(lz_csv_type){
504
505 var data = new Object();
506 data["action"] = lz_csv_type != "failed_login" ? "loginizer_export" : "loginizer_failed_login_export";
507 data["lz_csv_type"] = lz_csv_type;
508 data["nonce"] = "<?php echo wp_create_nonce('loginizer_admin_ajax'); ?>";
509
510 var admin_url = "<?php admin_url(); ?>"+"admin-ajax.php";
511
512 jQuery.post(admin_url, data, function(response){
513
514 // Was the ajax call successful ?
515 if(response.substring(0,2) == "-1"){
516
517 var err_message = response.substring(2);
518
519 if(err_message){
520 alert(err_message);
521 }else{
522 alert("Failed to export data");
523 }
524
525 return false;
526 }
527
528 /*
529 * Make CSV downloadable
530 */
531 var downloadLink = document.createElement("a");
532 var fileData = ['\ufeff'+response];
533
534 var blobObject = new Blob(fileData,{
535 type: "text/csv;charset=utf-8;"
536 });
537
538 var url = URL.createObjectURL(blobObject);
539 downloadLink.href = url;
540 downloadLink.download = "loginizer-"+lz_csv_type+".csv";
541
542 /*
543 * Actually download CSV
544 */
545 document.body.appendChild(downloadLink);
546 downloadLink.click();
547 document.body.removeChild(downloadLink);
548
549 });
550
551 }
552
553 </script>
554
555 <form method="get" onsubmit="return yesdsd();">
556 <div class="tablenav">
557 <p class="tablenav-pages" style="margin: 5px 10px" align="right">
558 <span class="displaying-num"><?php echo $lz_env['num_res'];?> items</span>
559 <span class="pagination-links">
560 <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>
561 <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>
562 <span class="paging-input">
563 <label for="current-page-selector" class="screen-reader-text">Current Page</label>
564 <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>
565 </span>
566 <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>
567 <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>
568 </span>
569 </p>
570 </div>
571 </form>
572
573 <form action="" method="post" enctype="multipart/form-data">
574 <?php wp_nonce_field('loginizer-options'); ?>
575 <div class="inside">
576 <table class="wp-list-table widefat fixed users" border="0">
577 <tr>
578 <th scope="row" valign="top" style="background:#EFEFEF;" width="20"><input type="checkbox" id="lz_check_all_logs" onchange="lz_multiple_check()" style="margin-left:-1px;"/></th>
579 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('IP','loginizer'); ?></th>
580 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Attempted Username','loginizer'); ?></th>
581 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Last Failed Attempt (DD/MM/YYYY)','loginizer'); ?></th>
582 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Failed Attempts Count','loginizer'); ?></th>
583 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Lockouts Count','loginizer'); ?></th>
584 <th scope="row" valign="top" style="background:#EFEFEF;" width="150"><?php echo __('URL Attacked','loginizer'); ?></th>
585 </tr>
586 <?php
587
588 if(empty($result)){
589 echo '
590 <tr>
591 <td colspan="4">
592 '.__('No Logs. You will see logs about failed login attempts here.', 'loginizer').'
593 </td>
594 </tr>';
595 }else{
596 foreach($result as $ik => $iv){
597 $status_button = (!empty($iv['status']) ? 'disable' : 'enable');
598 echo '
599 <tr>
600 <td>
601 <input type="checkbox" value="'.esc_attr($iv['ip']).'" name="lz_reset_ips[]" class="lz_shift_select_logs lz_check_all_logs" />
602 </td>
603 <td>
604 <a href="https://ipinfo.io/'.esc_html($iv['ip']).'" target="_blank">'.esc_html($iv['ip']).'&nbsp;<span class="dashicons dashicons-external"></span></a>
605 </td>
606 <td>
607 '.esc_html($iv['username']).'
608 </td>
609 <td>
610 '.date('d/M/Y H:i:s P', $iv['time']).'
611 </td>
612 <td>
613 '.esc_html($iv['count']).'
614 </td>
615 <td>
616 '.esc_html($iv['lockout']).'
617 </td>
618 <td>
619 '.esc_html($iv['url']).'
620 </td>
621 </tr>';
622 }
623 }
624
625 ?>
626 </table>
627
628 <br>
629 <input name="lz_reset_ip" class="button button-primary action" value="<?php echo __('Remove From Logs', 'loginizer'); ?>" type="submit" />
630 &nbsp; &nbsp;
631 <input name="lz_reset_all_ip" class="button button-primary action" value="<?php echo __('Clear All Logs', 'loginizer'); ?>" type="submit" />
632 &nbsp; &nbsp;
633 <input name="lz_blacklist_selected_ip" class="button button-primary action" value="<?php echo __('Blacklist Selected IPs', 'loginizer'); ?>" type="submit" />
634 &nbsp; &nbsp;
635 <input name="lz_export_csv" onclick="lz_export_ajax('failed_login'); return false;" class="button button-primary action" value="<?php echo __('Export CSV', 'loginizer'); ?>" type="submit" />
636 </div>
637 </div>
638 </form>
639 <br />
640
641 <div id="" class="postbox">
642
643 <div class="postbox-header">
644 <h2 class="hndle ui-sortable-handle">
645 <span><?php echo __('Brute Force Settings', 'loginizer'); ?></span>
646 </h2>
647 </div>
648
649 <div class="inside">
650
651 <form action="" method="post" enctype="multipart/form-data">
652 <?php wp_nonce_field('loginizer-options'); ?>
653 <table class="form-table">
654 <tr>
655 <th scope="row" valign="top"><label for="max_retries"><?php echo __('Max Retries','loginizer'); ?></label></th>
656 <td>
657 <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 />
658 </td>
659 </tr>
660 <tr>
661 <th scope="row" valign="top"><label for="lockout_time"><?php echo __('Lockout Time','loginizer'); ?></label></th>
662 <td>
663 <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 />
664 </td>
665 </tr>
666 <tr>
667 <th scope="row" valign="top"><label for="max_lockouts"><?php echo __('Max Lockouts','loginizer'); ?></label></th>
668 <td>
669 <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 />
670 </td>
671 </tr>
672 <tr>
673 <th scope="row" valign="top"><label for="lockouts_extend"><?php echo __('Extend Lockout','loginizer'); ?></label></th>
674 <td>
675 <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 />
676 </td>
677 </tr>
678 <tr>
679 <th scope="row" valign="top"><label for="reset_retries"><?php echo __('Reset Retries','loginizer'); ?></label></th>
680 <td>
681 <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 />
682 </td>
683 </tr>
684 <tr>
685 <th scope="row" valign="top"><label for="notify_email"><?php echo __('Email Notification','loginizer'); ?></label></th>
686 <td>
687 <?php echo __('after ','loginizer'); ?>
688 <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'); ?>
689 </td>
690 </tr>
691 <tr>
692 <th scope="row" valign="top"><label for="notify_email_address"><?php echo __('Email Address','loginizer'); ?></label></th>
693 <td>
694 <input type="text" value="<?php echo (!empty($notify_email_address) ? $notify_email_address : (!empty($loginizer['custom_notify_email']) ? $loginizer['notify_email_address'] : '')); ?>" name="notify_email_address" id="notify_email_address" size="30" /> <br /><?php echo __('failed login attempts notifications will be sent to this email','loginizer'); ?>
695 </td>
696 </tr>
697 <tr>
698 <th scope="row" valign="top"><label for="trusted_ips"><?php echo __('Trusted IP\'s','loginizer'); ?></label></th>
699 <td>
700 <input type="checkbox" <?php echo lz_POSTchecked('trusted_ips', (empty($loginizer['trusted_ips']) ? false : true)); ?> name="trusted_ips" id="trusted_ips"/>
701 <?php _e('If enabled Loginizer will only allow whitlisted IP\'s to Login.', 'loginizer'); ?>
702 </td>
703 </tr>
704 </table><br />
705 <input name="save_lz" class="button button-primary action" value="<?php echo __('Save Settings','loginizer'); ?>" type="submit" />
706 <?php
707
708 if(empty($loginizer['disable_brute'])){
709
710 echo '<input name="disable_brute_lz" class="button action" value="'.__('Disable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
711
712 }else{
713
714 echo '<input name="enable_brute_lz" class="button button-primary action" value="'.__('Enable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
715
716 }
717
718 ?>
719 </form>
720
721 </div>
722 </div>
723 <br />
724
725 <?php
726
727 wp_enqueue_script('jquery-paginate', LOGINIZER_URL.'/assets/js/jquery-paginate.js', array('jquery'), '1.10.15');
728
729 ?>
730
731 <style>
732 .page-navigation a {
733 margin: 5px 2px;
734 display: inline-block;
735 padding: 5px 8px;
736 color: #0073aa;
737 background: #e5e5e5 none repeat scroll 0 0;
738 border: 1px solid #ccc;
739 text-decoration: none;
740 transition-duration: 0.05s;
741 transition-property: border, background, color;
742 transition-timing-function: ease-in-out;
743 }
744
745 .page-navigation a[data-selected] {
746 background-color: #00a0d2;
747 color: #fff;
748 }
749 </style>
750
751 <script>
752
753 jQuery(document).ready(function(){
754 jQuery('#lz_bl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_bl_nav')});
755 jQuery('#lz_wl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_wl_nav')});
756 lz_multiple_check();
757 lz_shift_check_all('lz_shift_select_logs');
758 });
759
760 // Delete a Blacklist / Whitelist IP Range
761 function del_confirm(field, todo_id, msg){
762 var ret = confirm(msg);
763
764 if(ret){
765 jQuery('#lz_bl_wl_todo').attr('name', field);
766 jQuery('#lz_bl_wl_todo').val(todo_id);
767 jQuery('#lz_bl_wl_form').submit();
768 }
769
770 return false;
771
772 }
773
774 // Delete all Blacklist / Whitelist IP Ranges
775 function del_confirm_all(msg){
776 var ret = confirm(msg);
777
778 if(ret){
779 return true;
780 }
781
782 return false;
783
784 }
785
786 //Check all the failed log attempts
787 function lz_multiple_check(){
788 jQuery("#lz_check_all_logs").on("click", function(event){
789 if(this.checked == true){
790 jQuery(".lz_check_all_logs").prop("checked", true);
791 }else{
792 jQuery(".lz_check_all_logs").prop("checked", false);
793 }
794 });
795 }
796
797 //To select the installations/backups using shift key
798 function lz_shift_check_all(check_class){
799
800 var checkboxes = jQuery("."+check_class);
801 var lastChecked = null;
802
803 checkboxes.click(function(event){
804 if(!lastChecked){
805 lastChecked = this;
806 return;
807 }
808
809 if(event.shiftKey){
810 var start = checkboxes.index(this);
811 var end = checkboxes.index(lastChecked);
812
813 checkboxes.slice(Math.min(start,end), Math.max(start,end)+ 1).prop("checked", this.checked);
814 }
815
816 lastChecked = this;
817 });
818 };
819
820 </script>
821
822 <div id="" class="postbox">
823
824 <div class="postbox-header">
825 <h2 class="hndle ui-sortable-handle">
826 <span><?php echo __('Blacklist IP','loginizer'); ?></span>
827 </h2>
828 </div>
829
830 <div class="inside">
831
832 <?php echo __('Enter the IP you want to blacklist from login','loginizer'); ?>
833
834 <form action="" method="post">
835 <?php wp_nonce_field('loginizer-options'); ?>
836 <table class="form-table">
837 <tr>
838 <th scope="row" valign="top"><label for="start_ip"><?php echo __('Start IP','loginizer'); ?></label></th>
839 <td>
840 <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 />
841 </td>
842 </tr>
843 <tr>
844 <th scope="row" valign="top"><label for="end_ip"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
845 <td>
846 <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 />
847 </td>
848 </tr>
849 </table><br />
850 <input name="blacklist_iprange" class="button button-primary action" value="<?php echo __('Add Blacklist IP Range','loginizer'); ?>" type="submit" />
851 <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" />
852 </form>
853 </div>
854
855 <div id="lz_bl_nav" style="margin: 5px 10px; text-align:right"></div>
856
857 <!--Brute Force Blacklist Import CSV Form-->
858 <div class="inside" id="blacklist_csv" style="display:none;">
859 <form action="" method="post" enctype="multipart/form-data">
860 <?php wp_nonce_field('loginizer-options'); ?>
861 <input type="hidden" value="blacklist" name="lz_csv_type" />
862 <h3><?php echo __('Import Blacklist IPs (CSV)', 'loginizer'); ?>:</h3>
863 <input type="file" name="lz_import_file_csv" value="Import CSV" />
864 <br><br>
865 <input name="lz_import_csv" class="button button-primary action" value="<?php echo __('Submit', 'loginizer'); ?>" type="submit" />
866 </form>
867 </div>
868 <!---->
869
870 <!--Brute Force Blacklist Export CSV Form-->
871 <div class="inside" style="float:right;">
872 <form action="" method="post">
873 <?php wp_nonce_field('loginizer-options'); ?>
874 <input type="hidden" value="blacklist" name="lz_csv_type" />
875 <input class="button button-primary action" value="<?php echo __('Import CSV', 'loginizer'); ?>" type="button" onclick="jQuery('#blacklist_csv').toggle();"/>
876 <input name="lz_export_csv" onclick="lz_export_ajax('blacklist'); return false;" class="button button-primary action" value="<?php echo __('Export CSV', 'loginizer'); ?>" type="submit" />
877 </form>
878
879 </div>
880 <!---->
881
882 <table id="lz_bl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
883 <tr>
884 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
885 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
886 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
887 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
888 </tr>
889 <?php
890 if(empty($loginizer['blacklist'])){
891 echo '
892 <tr>
893 <td colspan="4">
894 '.__('No Blacklist IPs. You will see blacklisted IP ranges here.', 'loginizer').'
895 </td>
896 </tr>';
897 }else{
898 foreach($loginizer['blacklist'] as $ik => $iv){
899 echo '
900 <tr>
901 <td>
902 '.$iv['start'].'
903 </td>
904 <td>
905 '.$iv['end'].'
906 </td>
907 <td>
908 '.date('d/m/Y', $iv['time']).'
909 </td>
910 <td>
911 <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>
912 </td>
913 </tr>';
914 }
915 }
916 ?>
917 </table>
918 <br />
919 <form action="" method="post" id="lz_bl_wl_form">
920 <?php wp_nonce_field('loginizer-options'); ?>
921 <input type="hidden" value="" name="" id="lz_bl_wl_todo"/>
922 </form>
923 </div>
924
925 <br />
926
927 <div id="" class="postbox">
928
929 <div class="postbox-header">
930 <h2 class="hndle ui-sortable-handle">
931 <span><?php echo __('Whitelist IP', 'loginizer'); ?></span>
932 </h2>
933 </div>
934
935 <div class="inside">
936
937 <?php echo __('Enter the IP you want to whitelist for login','loginizer'); ?>
938 <form action="" method="post">
939 <?php wp_nonce_field('loginizer-options'); ?>
940 <table class="form-table">
941 <tr>
942 <th scope="row" valign="top"><label for="start_ip_w"><?php echo __('Start IP','loginizer'); ?></label></th>
943 <td>
944 <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 />
945 </td>
946 </tr>
947 <tr>
948 <th scope="row" valign="top"><label for="end_ip_w"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
949 <td>
950 <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 />
951 </td>
952 </tr>
953 </table><br />
954 <input name="whitelist_iprange" class="button button-primary action" value="<?php echo __('Add Whitelist IP Range','loginizer'); ?>" type="submit" />
955 <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" />
956 </form>
957 </div>
958
959 <div id="lz_wl_nav" style="margin: 5px 10px; text-align:right"></div>
960
961 <!--Brute Force Whitelist Import CSV Form-->
962 <div class="inside" id="lz_whitelist_csv_div" style="display:none;">
963 <form action="" method="post" enctype="multipart/form-data">
964 <?php wp_nonce_field('loginizer-options'); ?>
965 <input type="hidden" value="whitelist" name="lz_csv_type" />
966 <h3><?php echo __('Import Whitelist IPs (CSV)', 'loginizer'); ?>:</h3>
967 <input type="file" name="lz_import_file_csv" value="Import CSV" />
968 <br><br>
969 <input name="lz_import_csv" class="button button-primary action" value="<?php echo __('Submit', 'loginizer'); ?>" type="submit" />
970 </form>
971 </div>
972 <!---->
973
974 <!--Brute Force Whitelist Export CSV Form-->
975 <div class="inside" style="float:right;">
976 <form action="" method="post">
977 <?php wp_nonce_field('loginizer-options'); ?>
978 <input type="hidden" value="whitelist" name="lz_csv_type" />
979 <input class="button button-primary action" value="<?php echo __('Import CSV', 'loginizer'); ?>" type="button" onclick="jQuery('#lz_whitelist_csv_div').toggle();"/>
980 <input name="lz_export_csv" onclick="lz_export_ajax('whitelist'); return false;" class="button button-primary action" value="<?php echo __('Export CSV', 'loginizer'); ?>" type="submit" />
981 </form>
982 </div>
983 <!---->
984
985 <table id="lz_wl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
986 <tr>
987 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
988 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
989 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
990 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
991 </tr>
992 <?php
993 if(empty($loginizer['whitelist'])){
994 echo '
995 <tr>
996 <td colspan="4">
997 '.__('No Whitelist IPs. You will see whitelisted IP ranges here.', 'loginizer').'
998 </td>
999 </tr>';
1000 }else{
1001 foreach($loginizer['whitelist'] as $ik => $iv){
1002 echo '
1003 <tr>
1004 <td>
1005 '.$iv['start'].'
1006 </td>
1007 <td>
1008 '.$iv['end'].'
1009 </td>
1010 <td>
1011 '.date('d/m/Y', $iv['time']).'
1012 </td>
1013 <td>
1014 <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>
1015 </td>
1016 </tr>';
1017 }
1018 }
1019 ?>
1020 </table>
1021 <br />
1022
1023 </div>
1024
1025 <div id="" class="postbox">
1026
1027 <div class="postbox-header">
1028 <h2 class="hndle ui-sortable-handle">
1029 <span><?php echo __('Error Messages', 'loginizer'); ?></span>
1030 </h2>
1031 </div>
1032
1033 <div class="inside">
1034
1035 <form action="" method="post" enctype="multipart/form-data">
1036 <?php wp_nonce_field('loginizer-options'); ?>
1037 <table class="form-table">
1038 <tr>
1039 <th scope="row" valign="top"><label for="msg_inv_userpass"><?php echo __('Failed Login Attempt','loginizer'); ?></label></th>
1040 <td>
1041 <input type="text" size="25" value="<?php echo (empty($saved_msgs['inv_userpass']) ? '' : esc_attr($saved_msgs['inv_userpass'])); ?>" name="msg_inv_userpass" id="msg_inv_userpass" />
1042 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['inv_userpass']. '&quot;</em>', 'loginizer'); ?><br />
1043 </td>
1044 </tr>
1045 <tr>
1046 <th scope="row" valign="top"><label for="msg_ip_blacklisted"><?php echo __('Blacklisted IP','loginizer'); ?></label></th>
1047 <td>
1048 <input type="text" size="25" value="<?php echo (empty($saved_msgs['ip_blacklisted']) ? '' : esc_attr($saved_msgs['ip_blacklisted'])); ?>" name="msg_ip_blacklisted" id="msg_ip_blacklisted" />
1049 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['ip_blacklisted']. '&quot;</em>', 'loginizer'); ?><br />
1050 </td>
1051 </tr>
1052 <tr>
1053 <th scope="row" valign="top"><label for="msg_attempts_left"><?php echo __('Attempts Left','loginizer'); ?></label></th>
1054 <td>
1055 <input type="text" size="25" value="<?php echo (empty($saved_msgs['attempts_left']) ? '' : esc_attr($saved_msgs['attempts_left'])); ?>" name="msg_attempts_left" id="msg_attempts_left" />
1056 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['attempts_left']. '&quot;</em>', 'loginizer'); ?><br />
1057 </td>
1058 </tr>
1059 <tr>
1060 <th scope="row" valign="top"><label for="msg_lockout_err"><?php echo __('Lockout Error','loginizer'); ?></label></th>
1061 <td>
1062 <input type="text" size="25" value="<?php echo (empty($saved_msgs['lockout_err']) ? '' : esc_attr($saved_msgs['lockout_err'])); ?>" name="msg_lockout_err" id="msg_lockout_err" />
1063 <?php echo __('Default: <em>&quot;' . strip_tags($loginizer['d_msg']['lockout_err']). '&quot;</em>', 'loginizer'); ?><br />
1064 </td>
1065 </tr>
1066 <tr>
1067 <th scope="row" valign="top"><label for="msg_minutes_err"><?php echo __('Minutes','loginizer'); ?></label></th>
1068 <td>
1069 <input type="text" size="25" value="<?php echo (empty($saved_msgs['minutes_err']) ? '' : esc_attr($saved_msgs['minutes_err'])); ?>" name="msg_minutes_err" id="msg_minutes_err" />
1070 <?php echo __('Default: <em>&quot;' . strip_tags($loginizer['d_msg']['minutes_err']). '&quot;</em>', 'loginizer'); ?><br />
1071 </td>
1072 </tr>
1073 <tr>
1074 <th scope="row" valign="top"><label for="msg_hours_err"><?php echo __('Hours','loginizer'); ?></label></th>
1075 <td>
1076 <input type="text" size="25" value="<?php echo (empty($saved_msgs['hours_err']) ? '' : esc_attr($saved_msgs['hours_err'])); ?>" name="msg_hours_err" id="msg_hours_err" />
1077 <?php echo __('Default: <em>&quot;' . strip_tags($loginizer['d_msg']['hours_err']). '&quot;</em>', 'loginizer'); ?><br />
1078 </td>
1079 </tr>
1080 </table><br />
1081 <input name="save_err_msgs_lz" class="button button-primary action" value="<?php echo __('Save Error Messages','loginizer'); ?>" type="submit" />
1082 </form>
1083 </div>
1084 </div>
1085 <?php
1086
1087 loginizer_page_footer();
1088
1089 }
1090
1091 // IP range validations
1092 function loginizer_iprange_validate($start_ip, $end_ip, $cur_list, &$error = array(), $line_count = ''){
1093
1094 $line_error = '';
1095 if(!empty($line_count)){
1096 $line_error = ' '.__('Line no.', 'loginizer').' '.$line_count;
1097 }
1098
1099 if(empty($start_ip)){
1100 $cur_error[] = __('Please enter the Start IP', 'loginizer').$line_error;
1101 }
1102
1103 // If no end IP we consider only 1 IP
1104 if(empty($end_ip)){
1105 $end_ip = $start_ip;
1106 }
1107
1108 if(!lz_valid_ip($start_ip)){
1109 $cur_error[] = __('Please provide a valid start IP', 'loginizer').$line_error;
1110 }
1111
1112 if(!lz_valid_ip($end_ip)){
1113 $cur_error[] = __('Please provide a valid end IP', 'loginizer').$line_error;
1114 }
1115
1116 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1117
1118 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1119 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1120 // This is right
1121 }else{
1122 $cur_error[] = __('The End IP cannot be smaller than the Start IP', 'loginizer').$line_error;
1123 }
1124
1125 }
1126
1127 if(!empty($cur_error)){
1128
1129 foreach($cur_error as $rk => $rv){
1130 $error[] = $rv;
1131 }
1132
1133 return false;
1134 }
1135
1136 if(!empty($cur_list)){
1137
1138 foreach($cur_list as $k => $v){
1139
1140 // This is to check if there is any other range exists with the same Start or End IP
1141 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1142 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1143 ){
1144 $cur_error[] = __('The Start IP or End IP submitted conflicts with an existing IP range !', 'loginizer').$line_error;
1145 break;
1146 }
1147
1148 // This is to check if there is any other range exists with the same Start IP
1149 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1150 $cur_error[] = __('The Start IP is present in an existing range !', 'loginizer').$line_error;
1151 break;
1152 }
1153
1154 // This is to check if there is any other range exists with the same End IP
1155 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1156 $cur_error[] = __('The End IP is present in an existing range!', 'loginizer').$line_error;
1157 break;
1158 }
1159
1160 }
1161
1162 }
1163
1164 if(!empty($cur_error)){
1165
1166 foreach($cur_error as $rk => $rv){
1167 $error[] = $rv;
1168 }
1169
1170 return false;
1171 }
1172
1173 return true;
1174 }