| 1 |
<?php |
| 2 |
|
| 3 |
if(!defined('ABSPATH')){ |
| 4 |
die('Hacking Attempt'); |
| 5 |
} |
| 6 |
|
| 7 |
// The Loginizer Admin Options Page |
| 8 |
function loginizer_page_dashboard(){ |
| 9 |
|
| 10 |
global $loginizer, $lz_error, $lz_env; |
| 11 |
|
| 12 |
if(!current_user_can('manage_options')){ |
| 13 |
wp_die('Sorry, but you do not have permissions to change settings.'); |
| 14 |
} |
| 15 |
|
| 16 |
// Dismiss the announcement |
| 17 |
if(isset($_GET['dismiss_announcement'])){ |
| 18 |
update_option('loginizer_no_announcement', 1); |
| 19 |
} |
| 20 |
|
| 21 |
/* Make sure post was from this page */ |
| 22 |
if(count($_POST) > 0){ |
| 23 |
check_admin_referer('loginizer-options'); |
| 24 |
} |
| 25 |
|
| 26 |
do_action('loginizer_pre_page_dashboard'); |
| 27 |
|
| 28 |
// Is there a IP Method ? |
| 29 |
if(isset($_POST['save_lz_ip_method'])){ |
| 30 |
|
| 31 |
$ip_method = (int) lz_optpost('lz_ip_method'); |
| 32 |
$custom_ip_method = lz_optpost('lz_custom_ip_method'); |
| 33 |
|
| 34 |
if($ip_method >= 0 && $ip_method <= 3){ |
| 35 |
update_option('loginizer_ip_method', $ip_method); |
| 36 |
} |
| 37 |
|
| 38 |
// Custom Method name ? |
| 39 |
if($ip_method == 3){ |
| 40 |
update_option('loginizer_custom_ip_method', $custom_ip_method); |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
loginizer_page_dashboard_T(); |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
// The Loginizer Admin Options Page - THEME |
| 50 |
function loginizer_page_dashboard_T(){ |
| 51 |
|
| 52 |
global $loginizer, $lz_error, $lz_env; |
| 53 |
|
| 54 |
loginizer_page_header('Dashboard'); |
| 55 |
?> |
| 56 |
<style> |
| 57 |
.lz-welcome-panel{ |
| 58 |
border: 1px solid #c3c4c7; |
| 59 |
box-shadow: 0 1px 1px rgba(0,0,0,.04); |
| 60 |
background: #fff; |
| 61 |
padding:10px; |
| 62 |
} |
| 63 |
|
| 64 |
.lz-welcome-panel-content{ |
| 65 |
display:inline; |
| 66 |
vertical-align:middle; |
| 67 |
} |
| 68 |
|
| 69 |
input[type="text"], textarea, select { |
| 70 |
width: 70%; |
| 71 |
} |
| 72 |
|
| 73 |
.form-table label{ |
| 74 |
font-weight:bold; |
| 75 |
} |
| 76 |
|
| 77 |
.exp{ |
| 78 |
font-size:12px; |
| 79 |
} |
| 80 |
</style> |
| 81 |
|
| 82 |
<?php |
| 83 |
$lz_ip = lz_getip(); |
| 84 |
|
| 85 |
if($lz_ip != '127.0.0.1' && @$_SERVER['SERVER_ADDR'] == $lz_ip){ |
| 86 |
echo '<div class="update-message notice error inline notice-error notice-alt"><p style="color:red"> '.__('Your Server IP Address seems to match the Client IP detected by Loginizer. You might want to change the IP detection method to HTTP_X_FORWARDED_FOR under System Information section.', 'loginizer').'</p></div><br>'; |
| 87 |
} |
| 88 |
|
| 89 |
loginizer_newsletter_subscribe(); |
| 90 |
|
| 91 |
if(!empty($loginizer['backuply_promo']) && $loginizer['backuply_promo'] > 0 && $loginizer['backuply_promo'] < (time() - (7*24*3600))){ |
| 92 |
|
| 93 |
loginizer_backuply_promo(); |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
echo ' |
| 99 |
<div class="lz-welcome-panel"> |
| 100 |
<div class="lz-welcome-panel-content">'. __('Thank you for choosing Loginizer! Many more features coming soon... Review Loginizer at WordPress ', 'loginizer').'<a href="https://wordpress.org/support/view/plugin-reviews/loginizer" class="button button-primary" target="_blank">'. __('Add Review', 'loginizer'). '</a></div> |
| 101 |
</div><br />'; |
| 102 |
|
| 103 |
// Saved ? |
| 104 |
if(!empty($GLOBALS['lz_saved'])){ |
| 105 |
echo '<div id="message" class="updated"><p>'. __('The settings were saved successfully', 'loginizer'). '</p></div><br />'; |
| 106 |
} |
| 107 |
|
| 108 |
// Any errors ? |
| 109 |
if(!empty($lz_error)){ |
| 110 |
lz_report_error($lz_error);echo '<br />'; |
| 111 |
} |
| 112 |
|
| 113 |
?> |
| 114 |
<div style="display:flex; justify-content:space-between;" > |
| 115 |
<div class="postbox" style="width:34%"> |
| 116 |
|
| 117 |
<div class="postbox-header"> |
| 118 |
<h2 class="hndle ui-sortable-handle"> |
| 119 |
<span><?php echo __('Getting Started', 'loginizer'); ?></span> |
| 120 |
</h2> |
| 121 |
</div> |
| 122 |
|
| 123 |
<div class="inside"> |
| 124 |
|
| 125 |
<form action="" method="post" enctype="multipart/form-data"> |
| 126 |
<?php wp_nonce_field('loginizer-options'); ?> |
| 127 |
<table class="form-table"> |
| 128 |
<tr> |
| 129 |
<td scope="row" valign="top" colspan="2" style="line-height:1.9"> |
| 130 |
<i><?php echo __('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.', 'loginizer'); ?></i> |
| 131 |
<?php |
| 132 |
if(defined('LOGINIZER_PREMIUM')){ |
| 133 |
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','loginizer').'</i>'; |
| 134 |
}else{ |
| 135 |
echo '<br><i><a href="'.LOGINIZER_PRICING_URL.'" target="_blank" style="text-decoration:none;color:red;">'.__('Upgrade to Pro</a> for more features like <b>reCAPTCHA, Two Factor Auth, Rename wp-admin and wp-login.php pages, Email based PasswordLess</b> login and more. These features will improve your website\'s security.','loginizer').'</i>'; |
| 136 |
} |
| 137 |
?> |
| 138 |
</td> |
| 139 |
</tr> |
| 140 |
</table> |
| 141 |
</form> |
| 142 |
|
| 143 |
</div> |
| 144 |
</div> |
| 145 |
|
| 146 |
<?php |
| 147 |
|
| 148 |
$login_attempt_stats = get_option('loginizer_login_attempt_stats', []); |
| 149 |
$success_logins = 1; |
| 150 |
$failed_logins = 0; |
| 151 |
$stats_dataset = []; |
| 152 |
|
| 153 |
foreach($login_attempt_stats as $attempt_time => $count){ |
| 154 |
|
| 155 |
if($attempt_time < strtotime('-30 days')){ |
| 156 |
unset($login_attempt_stats[$attempt_time]); |
| 157 |
update_option('loginizer_login_attempt_stats', $login_attempt_stats, false); |
| 158 |
continue; |
| 159 |
} |
| 160 |
|
| 161 |
$day_month = date('M j', $attempt_time); |
| 162 |
if(empty($stats_dataset[$day_month])){ |
| 163 |
$stats_dataset[$day_month] = 0; |
| 164 |
} |
| 165 |
|
| 166 |
if(!empty($login_attempt_stats[$attempt_time][0])){ |
| 167 |
$stats_dataset[$day_month] += $login_attempt_stats[$attempt_time][0]; |
| 168 |
} |
| 169 |
|
| 170 |
if($attempt_time > strtotime('-24 hours')){ |
| 171 |
|
| 172 |
if(!empty($login_attempt_stats[$attempt_time][0])){ |
| 173 |
$failed_logins += $login_attempt_stats[$attempt_time][0]; |
| 174 |
} |
| 175 |
|
| 176 |
if(!empty($login_attempt_stats[$attempt_time][1])){ |
| 177 |
$success_logins += $login_attempt_stats[$attempt_time][1]; |
| 178 |
} |
| 179 |
|
| 180 |
continue; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
$failed_login_color = '#f9fa8e'; |
| 185 |
|
| 186 |
if($failed_logins < 40){ |
| 187 |
$failed_login_color = '#f9fa8e'; |
| 188 |
$failed_notice = __('Your Website is safe', 'loginizer'); |
| 189 |
|
| 190 |
} else if($failed_logins < 70){ |
| 191 |
$failed_login_color = '#ffcd56'; |
| 192 |
$failed_notice = __('Risk from Brute-force attacks is low, attacks are under control', 'loginizer'); |
| 193 |
} else if($failed_logins < 150){ |
| 194 |
$failed_login_color = '#f67019'; |
| 195 |
$failed_notice = __('Brute-force attacks on your websites are on rise', 'loginizer'); |
| 196 |
} else { |
| 197 |
$failed_login_color = '#fc1e4d'; |
| 198 |
$failed_notice = __('Your website is under heavy brute-force attacks.<br/> <a href="https://loginizer.com/pricing?utm_source=stats_block" target="_blank">Upgrade to a premium version</a> for added protection if this trend persists. Act fast to secure your site.', 'loginizer'); |
| 199 |
} |
| 200 |
|
| 201 |
if(defined('LOGINIZER_PREMIUM')){ |
| 202 |
$failed_login_color = '#f53794'; |
| 203 |
$failed_notice = __('Your website is being protected by Loginizer Security.', 'loginizer'); |
| 204 |
} |
| 205 |
|
| 206 |
?> |
| 207 |
|
| 208 |
<div class="postbox" style="width:65%;"> |
| 209 |
|
| 210 |
<div class="postbox-header"> |
| 211 |
<h2 class="hndle"> |
| 212 |
<span><?php echo __('Login Attempts', 'loginizer'); ?></span> |
| 213 |
</h2> |
| 214 |
</div> |
| 215 |
<div class="inside" style="display:flex;"> |
| 216 |
<div style="margin-right:50px;"> |
| 217 |
<div style="position:relative; width: 250px; height:auto; margin: 0 auto;"> |
| 218 |
<canvas id="lz-attempts-chart"></canvas> |
| 219 |
<h3 style="position:absolute; bottom:0%; width:100%; text-align:center;"><?php _e('Total Attempts:', 'loginizer'); ?> <?php echo esc_html($failed_logins + $success_logins); ?></h3> |
| 220 |
</div> |
| 221 |
<div><p style="text-align:center;"><?php echo wp_kses_post($failed_notice); ?></p></div> |
| 222 |
<div style="color:#898989; text-align:right;"><?php _e('Data For Last 24 hours', 'loginizer'); ?></div> |
| 223 |
</div> |
| 224 |
<div style="margin:auto; height:100%; min-height:300px; width:80%;"> |
| 225 |
<canvas id="lz-attemt-chart-thirty"></canvas> |
| 226 |
</div> |
| 227 |
</div> |
| 228 |
</div> |
| 229 |
</div> |
| 230 |
|
| 231 |
<div class="postbox"> |
| 232 |
|
| 233 |
<div class="postbox-header"> |
| 234 |
<h2 class="hndle ui-sortable-handle"> |
| 235 |
<span><?php echo __('System Information', 'loginizer'); ?></span> |
| 236 |
</h2> |
| 237 |
</div> |
| 238 |
<div class="inside"> |
| 239 |
|
| 240 |
<form action="" method="post" enctype="multipart/form-data"> |
| 241 |
<?php wp_nonce_field('loginizer-options'); ?> |
| 242 |
<table class="wp-list-table fixed striped users" cellspacing="1" border="0" width="95%" cellpadding="10" align="center"> |
| 243 |
<?php |
| 244 |
echo ' |
| 245 |
<tr> |
| 246 |
<th align="left" width="25%">'.__('Loginizer Version', 'loginizer').'</th> |
| 247 |
<td>'.LOGINIZER_VERSION.(defined('LOGINIZER_PREMIUM') ? ' (<font color="green">'.__('Security PRO Version','loginizer').'</font>)' : '').'</td> |
| 248 |
</tr>'; |
| 249 |
|
| 250 |
do_action('loginizer_system_information'); |
| 251 |
|
| 252 |
echo '<tr> |
| 253 |
<th align="left">'.__('URL', 'loginizer').'</th> |
| 254 |
<td>'.get_site_url().'</td> |
| 255 |
</tr> |
| 256 |
<tr> |
| 257 |
<th align="left">'.__('Path', 'loginizer').'</th> |
| 258 |
<td>'.ABSPATH.'</td> |
| 259 |
</tr> |
| 260 |
<tr> |
| 261 |
<th align="left">'.__('Server\'s IP Address', 'loginizer').'</th> |
| 262 |
<td>'.@$_SERVER['SERVER_ADDR'].'</td> |
| 263 |
</tr> |
| 264 |
<tr> |
| 265 |
<th align="left">'.__('Your IP Address', 'loginizer').'</th> |
| 266 |
<td>'.lz_getip().' |
| 267 |
<div style="float:right"> |
| 268 |
Method : |
| 269 |
<select name="lz_ip_method" id="lz_ip_method" style="font-size:11px; width:150px" onchange="lz_ip_method_handle()"> |
| 270 |
<option value="0" '.lz_POSTselect('lz_ip_method', 0, (@$loginizer['ip_method'] == 0)).'>REMOTE_ADDR'.(!empty($_SERVER['REMOTE_ADDR']) ? '(' . esc_html($_SERVER['REMOTE_ADDR']) .')' : '').'</option> |
| 271 |
<option value="1" '.lz_POSTselect('lz_ip_method', 1, (@$loginizer['ip_method'] == 1)).'>HTTP_X_FORWARDED_FOR'.(!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? '(' . esc_html($_SERVER['HTTP_X_FORWARDED_FOR']) .')' : '').'</option> |
| 272 |
<option value="2" '.lz_POSTselect('lz_ip_method', 2, (@$loginizer['ip_method'] == 2)).'>HTTP_CLIENT_IP'.(!empty($_SERVER['HTTP_CLIENT_IP']) ? '(' . esc_html($_SERVER['HTTP_CLIENT_IP']) .')' : '').'</option> |
| 273 |
<option value="3" '.lz_POSTselect('lz_ip_method', 3, (@$loginizer['ip_method'] == 3)).'>CUSTOM</option> |
| 274 |
</select> |
| 275 |
<input name="lz_custom_ip_method" id="lz_custom_ip_method" type="text" value="'.lz_optpost('lz_custom_ip_method',(empty($loginizer['custom_ip_method']) ? '' : $loginizer['custom_ip_method'])).'" style="font-size:11px; width:100px; display:none" /> |
| 276 |
<input name="save_lz_ip_method" class="button button-primary" value="Save" type="submit" /> |
| 277 |
</div> |
| 278 |
</td> |
| 279 |
</tr> |
| 280 |
<tr> |
| 281 |
<th align="left">'.__('wp-config.php is writable', 'loginizer').'</th> |
| 282 |
<td>'.(is_writable(ABSPATH.'/wp-config.php') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td> |
| 283 |
</tr>'; |
| 284 |
|
| 285 |
if(file_exists(ABSPATH.'/.htaccess')){ |
| 286 |
echo ' |
| 287 |
<tr> |
| 288 |
<th align="left">'.__('.htaccess is writable', 'loginizer').'</th> |
| 289 |
<td>'.(is_writable(ABSPATH.'/.htaccess') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td> |
| 290 |
</tr>'; |
| 291 |
|
| 292 |
} |
| 293 |
|
| 294 |
// Setting up the dataset for the 30 day chart |
| 295 |
$line_dataset[] = array( |
| 296 |
'label' => __( 'Failed', 'loginizer'), |
| 297 |
'data' => array_reverse($stats_dataset), |
| 298 |
'backgroundColor' => 'rgb(54, 162, 235)', |
| 299 |
'borderColor' => 'rgb(54, 162, 235)', |
| 300 |
); |
| 301 |
|
| 302 |
// Enqueues CharJS script and inline the char js |
| 303 |
wp_enqueue_script('chartjs', LOGINIZER_URL.'/assets/js/chart.js', array('jquery'), '3.0.0'); |
| 304 |
wp_add_inline_script('chartjs', 'function lz_attempts_chart(){ |
| 305 |
const ctx = document.getElementById("lz-attempts-chart"); |
| 306 |
|
| 307 |
new Chart(ctx, { |
| 308 |
type: "doughnut", |
| 309 |
data: { |
| 310 |
labels: ["Failed", "Success"], |
| 311 |
datasets: [{ |
| 312 |
label: "Count", |
| 313 |
data: ['.esc_html($failed_logins).', '.esc_html($success_logins).'], |
| 314 |
backgroundColor: [ |
| 315 |
"'.esc_html($failed_login_color).'", |
| 316 |
"rgb(54, 162, 235)", |
| 317 |
], |
| 318 |
hoverOffset: 4, |
| 319 |
borderWidth: [0] |
| 320 |
}], |
| 321 |
}, |
| 322 |
options : { |
| 323 |
circumference : 180, |
| 324 |
rotation:-90, |
| 325 |
responsive: true, |
| 326 |
} |
| 327 |
}); |
| 328 |
|
| 329 |
const thirty_days = document.getElementById("lz-attemt-chart-thirty"); |
| 330 |
|
| 331 |
new Chart(thirty_days, { |
| 332 |
type: "line", |
| 333 |
data: { |
| 334 |
datasets: '.json_encode($line_dataset).' |
| 335 |
}, |
| 336 |
options: { |
| 337 |
responsive: true, |
| 338 |
maintainAspectRatio: false, |
| 339 |
hover: { |
| 340 |
mode: "nearest", |
| 341 |
intersect: true |
| 342 |
}, |
| 343 |
scales: { |
| 344 |
x: { |
| 345 |
display: true, |
| 346 |
scaleLabel: { |
| 347 |
display: false |
| 348 |
} |
| 349 |
|
| 350 |
}, |
| 351 |
y: { |
| 352 |
display: true, |
| 353 |
scaleLabel: { |
| 354 |
display: false |
| 355 |
}, |
| 356 |
beginAtZero: true, |
| 357 |
ticks: { |
| 358 |
callback: function(label, index, labels) { |
| 359 |
if (Math.floor(label) === label) { |
| 360 |
return label; |
| 361 |
} |
| 362 |
}, |
| 363 |
} |
| 364 |
} |
| 365 |
} |
| 366 |
} |
| 367 |
}); |
| 368 |
} |
| 369 |
|
| 370 |
lz_attempts_chart();'); |
| 371 |
|
| 372 |
?> |
| 373 |
</table> |
| 374 |
</form> |
| 375 |
|
| 376 |
</div> |
| 377 |
</div> |
| 378 |
|
| 379 |
<script type="text/javascript"> |
| 380 |
|
| 381 |
function lz_ip_method_handle(){ |
| 382 |
var ele = jQuery('#lz_ip_method'); |
| 383 |
if(ele.val() == 3){ |
| 384 |
jQuery('#lz_custom_ip_method').show(); |
| 385 |
}else{ |
| 386 |
jQuery('#lz_custom_ip_method').hide(); |
| 387 |
} |
| 388 |
}; |
| 389 |
|
| 390 |
lz_ip_method_handle(); |
| 391 |
|
| 392 |
</script> |
| 393 |
|
| 394 |
<div id="" class="postbox"> |
| 395 |
|
| 396 |
<div class="postbox-header"> |
| 397 |
<h2 class="hndle ui-sortable-handle"> |
| 398 |
<span><?php echo __('File Permissions', 'loginizer'); ?></span> |
| 399 |
</h2> |
| 400 |
</div> |
| 401 |
|
| 402 |
<div class="inside"> |
| 403 |
|
| 404 |
<form action="" method="post" enctype="multipart/form-data"> |
| 405 |
<?php wp_nonce_field('loginizer-options'); ?> |
| 406 |
<table class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center"> |
| 407 |
<?php |
| 408 |
|
| 409 |
echo ' |
| 410 |
<tr> |
| 411 |
<th style="background:#EFEFEF;">'.__('Relative Path', 'loginizer').'</th> |
| 412 |
<th style="width:10%; background:#EFEFEF;">'.__('Suggested', 'loginizer').'</th> |
| 413 |
<th style="width:10%; background:#EFEFEF;">'.__('Actual', 'loginizer').'</th> |
| 414 |
</tr>'; |
| 415 |
|
| 416 |
if(version_compare(phpversion(), '7.0') < 0){ |
| 417 |
$wp_content = basename(dirname(dirname(dirname(dirname(dirname(__FILE__)))))); |
| 418 |
}else { |
| 419 |
$wp_content = basename(dirname(__FILE__, 5)); |
| 420 |
} |
| 421 |
|
| 422 |
$files_to_check = array('/' => array('0755', '0750'), |
| 423 |
'/wp-admin' => array('0755'), |
| 424 |
'/wp-includes' => array('0755'), |
| 425 |
'/wp-config.php' => array('0444'), |
| 426 |
'/'.$wp_content => array('0755'), |
| 427 |
'/'.$wp_content.'/themes' => array('0755'), |
| 428 |
'/'.$wp_content.'/plugins' => array('0755')); |
| 429 |
|
| 430 |
if(file_exists(ABSPATH.'/.htaccess')){ |
| 431 |
$files_to_check['.htaccess'] = array('0444'); |
| 432 |
} |
| 433 |
|
| 434 |
$root = ABSPATH; |
| 435 |
|
| 436 |
foreach($files_to_check as $k => $v){ |
| 437 |
|
| 438 |
$path = $root.'/'.$k; |
| 439 |
$stat = @stat($path); |
| 440 |
$suggested = $v; |
| 441 |
$actual = substr(sprintf('%o', $stat['mode']), -4); |
| 442 |
|
| 443 |
echo ' |
| 444 |
<tr> |
| 445 |
<td>'.$k.'</td> |
| 446 |
<td>'.current($suggested).'</td> |
| 447 |
<td><span '.(!in_array($actual, $suggested) ? 'style="color: red;"' : '').'>'.$actual.'</span></td> |
| 448 |
</tr>'; |
| 449 |
|
| 450 |
} |
| 451 |
|
| 452 |
?> |
| 453 |
</table> |
| 454 |
</form> |
| 455 |
|
| 456 |
</div> |
| 457 |
</div> |
| 458 |
|
| 459 |
<?php |
| 460 |
|
| 461 |
loginizer_page_footer(); |
| 462 |
|
| 463 |
} |