| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | echo 'You are not allowed to access this page directly.'; |
| 5 | 5 | exit; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | -define('LOGINIZER_VERSION', '2.1.0'); | |
| 8 | +define('LOGINIZER_VERSION', '1.8.3'); | |
| 9 | 9 | define('LOGINIZER_DIR', dirname(LOGINIZER_FILE)); |
| 10 | 10 | define('LOGINIZER_URL', plugins_url('', LOGINIZER_FILE)); |
| 11 | 11 | define('LOGINIZER_PRO_URL', 'https://loginizer.com/features#compare'); |
| 12 | 12 | define('LOGINIZER_PRICING_URL', 'https://loginizer.com/pricing'); |
| @@ -24,9 +24,9 @@ | ||
| 24 | 24 | |
| 25 | 25 | $sql = array(); |
| 26 | 26 | |
| 27 | 27 | $sql[] = "DROP TABLE IF EXISTS `".$wpdb->prefix."loginizer_logs`"; |
| 28 | - | |
| 28 | + | |
| 29 | 29 | $sql[] = "CREATE TABLE `".$wpdb->prefix."loginizer_logs` ( |
| 30 | 30 | `username` varchar(255) NOT NULL DEFAULT '', |
| 31 | 31 | `time` int(10) NOT NULL DEFAULT '0', |
| 32 | 32 | `count` int(10) NOT NULL DEFAULT '0', |
| @@ -45,14 +45,9 @@ | ||
| 45 | 45 | add_option('loginizer_last_reset', 0); |
| 46 | 46 | add_option('loginizer_whitelist', array()); |
| 47 | 47 | add_option('loginizer_blacklist', array()); |
| 48 | 48 | add_option('loginizer_2fa_whitelist', array()); |
| 49 | - | |
| 50 | - // TODO:: REMOVE THIS AFTER MARCH 2025 | |
| 51 | - $softwp_upgrade = get_option('loginizer_softwp_upgrade', 0); | |
| 52 | - if(!defined('SITEPAD') && empty($softwp_upgrade)){ | |
| 53 | - loginizer_check_softaculous(); | |
| 54 | - } | |
| 49 | + | |
| 55 | 50 | } |
| 56 | 51 | |
| 57 | 52 | /** |
| 58 | 53 | * Updates the database structure for Loginizer |
| @@ -89,9 +84,9 @@ | ||
| 89 | 84 | // Trick the following if conditions to not run |
| 90 | 85 | $version = (int) str_replace('.', '', LOGINIZER_VERSION); |
| 91 | 86 | |
| 92 | 87 | } |
| 93 | - | |
| 88 | + | |
| 94 | 89 | // Is it less than 1.0.1 ? |
| 95 | 90 | if($version < 101){ |
| 96 | 91 | |
| 97 | 92 | // TODO : GET the existing settings |
| @@ -187,38 +182,11 @@ | ||
| 187 | 182 | $wpdb->query("ALTER TABLE ".$wpdb->prefix."loginizer_logs ADD `url` VARCHAR(255) NOT NULL DEFAULT '' AFTER `ip`;"); |
| 188 | 183 | |
| 189 | 184 | } |
| 190 | 185 | |
| 191 | - // Setting alignment to left in social login ? | |
| 192 | - if($version < 201){ | |
| 193 | - $social_settings = get_option('loginizer_social_settings', []); | |
| 194 | - | |
| 195 | - if(!empty($social_settings)){ | |
| 196 | - if(!empty($social_settings['login']) && (!empty($social_settings['login']['login_form']) || !empty($social_settings['login']['registration_form']))){ | |
| 197 | - $social_settings['login']['button_alignment'] = 'left'; | |
| 198 | - } | |
| 199 | - | |
| 200 | - if(!empty($social_settings['woocommerce']) && (!empty($social_settings['woocommmerce']['login_form']) || !empty($social_settings['woocommerce']['registration_form']))){ | |
| 201 | - $social_settings['woocommerce']['button_alignment'] = 'left'; | |
| 202 | - } | |
| 203 | - | |
| 204 | - if(!empty($social_settings['comment']) && !empty($social_settings['comment']['enable_buttons'])){ | |
| 205 | - $social_settings['comment']['button_alignment'] = 'left'; | |
| 206 | - } | |
| 207 | - | |
| 208 | - update_option('loginizer_social_settings', $social_settings); | |
| 209 | - } | |
| 210 | - } | |
| 211 | - | |
| 212 | 186 | // Save the new Version |
| 213 | 187 | update_option('loginizer_version', LOGINIZER_VERSION); |
| 214 | 188 | |
| 215 | - // TODO:: REMOVE THIS AFTER MARCH 2025 | |
| 216 | - $softwp_upgrade = get_option('loginizer_softwp_upgrade', 0); | |
| 217 | - if(!defined('SITEPAD') && empty($softwp_upgrade)){ | |
| 218 | - loginizer_check_softaculous(); | |
| 219 | - } | |
| 220 | - | |
| 221 | 189 | // In Sitepad Math Captcha is enabled by default |
| 222 | 190 | if(defined('SITEPAD') && get_option('loginizer_captcha') === false){ |
| 223 | 191 | $option['captcha_no_google'] = 1; |
| 224 | 192 | add_option('loginizer_captcha', $option); |
| @@ -235,13 +203,11 @@ | ||
| 235 | 203 | global $loginizer; |
| 236 | 204 | |
| 237 | 205 | // Check if the installed version is outdated |
| 238 | 206 | loginizer_update_check(); |
| 239 | - | |
| 207 | + | |
| 240 | 208 | // Set the array |
| 241 | - if(empty($loginizer)){ | |
| 242 | - $loginizer = array(); | |
| 243 | - } | |
| 209 | + $loginizer = array(); | |
| 244 | 210 | |
| 245 | 211 | $loginizer['prefix'] = !defined('SITEPAD') ? 'Loginizer ' : 'SitePad '; |
| 246 | 212 | $loginizer['app'] = !defined('SITEPAD') ? 'WordPress' : 'SitePad'; |
| 247 | 213 | $loginizer['login_basename'] = !defined('SITEPAD') ? 'wp-login.php' : 'login.php'; |
| @@ -262,10 +228,8 @@ | ||
| 262 | 228 | $loginizer['reset_retries'] = empty($options['reset_retries']) ? 86400 : $options['reset_retries']; // 24 hours |
| 263 | 229 | $loginizer['notify_email'] = empty($options['notify_email']) ? 0 : $options['notify_email']; |
| 264 | 230 | $loginizer['notify_email_address'] = lz_is_multisite() ? get_site_option('admin_email') : get_option('admin_email'); |
| 265 | 231 | $loginizer['trusted_ips'] = empty($options['trusted_ips']) ? false : true; |
| 266 | - $loginizer['blocked_screen'] = empty($options['blocked_screen']) ? false : true; | |
| 267 | - $loginizer['social_settings'] = get_option('loginizer_social_settings', []); | |
| 268 | 232 | |
| 269 | 233 | if(!empty($options['notify_email_address'])){ |
| 270 | 234 | $loginizer['notify_email_address'] = $options['notify_email_address']; |
| 271 | 235 | $loginizer['custom_notify_email'] = 1; |
| @@ -270,18 +234,43 @@ | ||
| 270 | 234 | $loginizer['notify_email_address'] = $options['notify_email_address']; |
| 271 | 235 | $loginizer['custom_notify_email'] = 1; |
| 272 | 236 | } |
| 273 | 237 | |
| 274 | - // Login Success Email Notification. | |
| 275 | - $loginizer['login_mail'] = get_option('loginizer_login_mail', []); | |
| 276 | - add_action('init', 'loginizer_load_translation_vars', 0); | |
| 277 | - | |
| 278 | - $loginizer['login_mail_subject'] = empty($loginizer['login_mail']['subject']) ? '' : $loginizer['login_mail']['subject']; | |
| 279 | - $loginizer['login_mail_body'] = empty($loginizer['login_mail']['body']) ? '' : $loginizer['login_mail']['body']; | |
| 280 | - | |
| 238 | + // Default messages | |
| 239 | + $loginizer['d_msg']['inv_userpass'] = __('Incorrect Username or Password', 'loginizer'); | |
| 240 | + $loginizer['d_msg']['ip_blacklisted'] = __('Your IP has been blacklisted', 'loginizer'); | |
| 241 | + $loginizer['d_msg']['attempts_left'] = __('attempt(s) left', 'loginizer'); | |
| 242 | + $loginizer['d_msg']['lockout_err'] = __('You have exceeded maximum login retries<br /> Please try after', 'loginizer'); | |
| 243 | + $loginizer['d_msg']['minutes_err'] = __('minute(s)', 'loginizer'); | |
| 244 | + $loginizer['d_msg']['hours_err'] = __('hour(s)', 'loginizer'); | |
| 245 | + | |
| 246 | + // Message Strings | |
| 247 | + $loginizer['msg'] = get_option('loginizer_msg', []); | |
| 248 | + | |
| 249 | + foreach($loginizer['d_msg'] as $lk => $lv){ | |
| 250 | + if(empty($loginizer['msg'][$lk])){ | |
| 251 | + $loginizer['msg'][$lk] = $loginizer['d_msg'][$lk]; | |
| 252 | + } | |
| 253 | + } | |
| 254 | + | |
| 255 | + $loginizer['2fa_d_msg']['otp_app'] = __('Please enter the OTP as seen in your App', 'loginizer'); | |
| 256 | + $loginizer['2fa_d_msg']['otp_email'] = __('Please enter the OTP emailed to you', 'loginizer'); | |
| 257 | + $loginizer['2fa_d_msg']['otp_field'] = __('One Time Password', 'loginizer'); | |
| 258 | + $loginizer['2fa_d_msg']['otp_question'] = __('Please answer your security question', 'loginizer'); | |
| 259 | + $loginizer['2fa_d_msg']['otp_answer'] = __('Your Answer', 'loginizer'); | |
| 260 | + | |
| 261 | + // Message Strings | |
| 262 | + $loginizer['2fa_msg'] = get_option('loginizer_2fa_msg', []); | |
| 263 | + | |
| 264 | + foreach($loginizer['2fa_d_msg'] as $lk => $lv){ | |
| 265 | + if(empty($loginizer['2fa_msg'][$lk])){ | |
| 266 | + $loginizer['2fa_msg'][$lk] = $loginizer['2fa_d_msg'][$lk]; | |
| 267 | + } | |
| 268 | + } | |
| 269 | + | |
| 281 | 270 | // Load the blacklist and whitelist |
| 282 | - $loginizer['blacklist'] = get_option('loginizer_blacklist', []); | |
| 283 | - $loginizer['whitelist'] = get_option('loginizer_whitelist', []); | |
| 271 | + $loginizer['blacklist'] = get_option('loginizer_blacklist'); | |
| 272 | + $loginizer['whitelist'] = get_option('loginizer_whitelist'); | |
| 284 | 273 | $loginizer['2fa_whitelist'] = get_option('loginizer_2fa_whitelist'); |
| 285 | 274 | |
| 286 | 275 | // It should not be false |
| 287 | 276 | if(empty($loginizer['2fa_whitelist'])){ |
| @@ -289,14 +278,8 @@ | ||
| 289 | 278 | } |
| 290 | 279 | |
| 291 | 280 | // When was the database cleared last time |
| 292 | 281 | $loginizer['last_reset'] = get_option('loginizer_last_reset'); |
| 293 | - | |
| 294 | - if(!isset($loginizer['ultimate-member-active'])){ | |
| 295 | - $um_is_active = in_array('ultimate-member/ultimate-member.php', apply_filters('active_plugins', get_option('active_plugins', []))); | |
| 296 | - | |
| 297 | - $loginizer['ultimate-member-active'] = !empty($um_is_active) ? true : false; | |
| 298 | - } | |
| 299 | 282 | |
| 300 | 283 | //print_r($loginizer); |
| 301 | 284 | |
| 302 | 285 | // Clear retries |
| @@ -332,26 +315,137 @@ | ||
| 332 | 315 | // Is called before displaying the error message so that we dont show that the username is wrong or the password |
| 333 | 316 | // Update Error message |
| 334 | 317 | add_action('wp_login_errors', 'loginizer_error_handler', 10001, 2); |
| 335 | 318 | add_action('woocommerce_login_failed', 'loginizer_woocommerce_error_handler', 10001); |
| 336 | - add_action('wp_login', 'loginizer_login_success', 11, 2); | |
| 337 | - add_action('rsssl_two_factor_user_authenticated', 'loginizer_rsssl_2fa_success'); | |
| 338 | - | |
| 339 | - if(!empty($loginizer['ultimate-member-active'])){ | |
| 340 | - add_action('wp_login_failed', 'loginizer_ultimatemember_error_handler', 10001); | |
| 341 | - } | |
| 319 | + add_action('wp_login', 'loginizer_login_success', 10, 2); | |
| 320 | + | |
| 321 | + } | |
| 322 | + | |
| 323 | + // ---------------- | |
| 324 | + // PRO INIT | |
| 325 | + // ---------------- | |
| 326 | + | |
| 327 | + // Email to Login | |
| 328 | + $options = get_option('loginizer_epl'); | |
| 329 | + $loginizer['pl_d_sub'] = __('Login at $site_name','loginizer'); | |
| 330 | + $loginizer['pl_d_msg'] = __('Hi, | |
| 342 | 331 | |
| 343 | - if(!empty($_COOKIE['lz_social_error']) && !empty($loginizer['social_settings'])){ | |
| 344 | - add_filter('wp_login_errors', 'loginizer_social_login_error_handler', 10000, 2); | |
| 345 | - } | |
| 332 | +A login request was submitted for your account $email at : | |
| 333 | +$site_name - $site_url | |
| 334 | + | |
| 335 | +Login at $site_name by visiting this url : | |
| 336 | +$login_url | |
| 337 | + | |
| 338 | +If you have not requested for the Login URL, please ignore this email. | |
| 339 | + | |
| 340 | +Regards, | |
| 341 | +$site_name','loginizer'); | |
| 342 | + $loginizer['email_pass_less'] = empty($options['email_pass_less']) ? 0 : $options['email_pass_less']; | |
| 343 | + $loginizer['passwordless_sub'] = empty($options['passwordless_sub']) ? $loginizer['pl_d_sub'] : $options['passwordless_sub']; | |
| 344 | + $loginizer['passwordless_msg'] = empty($options['passwordless_msg']) ? $loginizer['pl_d_msg'] : $options['passwordless_msg']; | |
| 345 | + $loginizer['passwordless_msg_is_custom'] = empty($options['passwordless_msg']) ? 0 : 1; | |
| 346 | + $loginizer['passwordless_html'] = empty($options['passwordless_html']) ? 0 : $options['passwordless_html']; | |
| 347 | + $loginizer['passwordless_redirect'] = empty($options['passwordless_redirect']) ? 0 : $options['passwordless_redirect']; | |
| 348 | + $loginizer['passwordless_redirect_for'] = empty($options['passwordless_redirect_for']) ? 0 : $options['passwordless_redirect_for']; | |
| 349 | + | |
| 350 | + // 2FA OTP Email to Login | |
| 351 | + $options = get_option('loginizer_2fa_email_template'); | |
| 352 | + $loginizer['2fa_email_d_sub'] = 'OTP : Login at $site_name'; | |
| 353 | + $loginizer['2fa_email_d_msg'] = 'Hi, | |
| 354 | + | |
| 355 | +A login request was submitted for your account $email at : | |
| 356 | +$site_name - $site_url | |
| 357 | + | |
| 358 | +Please use the following One Time password (OTP) to login : | |
| 359 | +$otp | |
| 360 | + | |
| 361 | +Note : The OTP expires after 10 minutes. | |
| 362 | + | |
| 363 | +If you haven\'t requested for the OTP, please ignore this email. | |
| 364 | + | |
| 365 | +Regards, | |
| 366 | +$site_name'; | |
| 367 | + | |
| 368 | + $loginizer['2fa_email_sub'] = empty($options['2fa_email_sub']) ? $loginizer['2fa_email_d_sub'] : $options['2fa_email_sub']; | |
| 369 | + $loginizer['2fa_email_msg'] = empty($options['2fa_email_msg']) ? $loginizer['2fa_email_d_msg'] : $options['2fa_email_msg']; | |
| 370 | + | |
| 371 | + // For SitePad its always on | |
| 372 | + if(defined('SITEPAD')){ | |
| 373 | + $loginizer['email_pass_less'] = 1; | |
| 346 | 374 | } |
| 347 | 375 | |
| 348 | - // Social Login Form Actions | |
| 349 | - if(!empty($loginizer['social_settings'])){ | |
| 350 | - if(!empty($loginizer['social_settings']['login']['login_form'])){ | |
| 351 | - add_action('login_form', 'loginizer_social_btn_login'); | |
| 352 | - } | |
| 353 | - } | |
| 376 | + // Captcha | |
| 377 | + $options = get_option('loginizer_captcha'); | |
| 378 | + $loginizer['captcha_type'] = empty($options['captcha_type']) ? '' : $options['captcha_type']; | |
| 379 | + $loginizer['captcha_key'] = empty($options['captcha_key']) ? '' : $options['captcha_key']; | |
| 380 | + $loginizer['captcha_secret'] = empty($options['captcha_secret']) ? '' : $options['captcha_secret']; | |
| 381 | + $loginizer['captcha_theme'] = empty($options['captcha_theme']) ? 'light' : $options['captcha_theme']; | |
| 382 | + $loginizer['captcha_size'] = empty($options['captcha_size']) ? 'normal' : $options['captcha_size']; | |
| 383 | + $loginizer['captcha_lang'] = empty($options['captcha_lang']) ? '' : $options['captcha_lang']; | |
| 384 | + $loginizer['captcha_user_hide'] = !isset($options['captcha_user_hide']) ? 0 : $options['captcha_user_hide']; | |
| 385 | + $loginizer['captcha_no_css_login'] = !isset($options['captcha_no_css_login']) ? 0 : $options['captcha_no_css_login']; | |
| 386 | + $loginizer['captcha_no_js'] = 1; | |
| 387 | + $loginizer['captcha_login'] = !isset($options['captcha_login']) ? 1 : $options['captcha_login']; | |
| 388 | + $loginizer['captcha_lostpass'] = !isset($options['captcha_lostpass']) ? 1 : $options['captcha_lostpass']; | |
| 389 | + $loginizer['captcha_resetpass'] = !isset($options['captcha_resetpass']) ? 1 : $options['captcha_resetpass']; | |
| 390 | + $loginizer['captcha_register'] = !isset($options['captcha_register']) ? 1 : $options['captcha_register']; | |
| 391 | + $loginizer['captcha_comment'] = !isset($options['captcha_comment']) ? 1 : $options['captcha_comment']; | |
| 392 | + $loginizer['captcha_wc_checkout'] = !isset($options['captcha_wc_checkout']) ? 1 : $options['captcha_wc_checkout']; | |
| 393 | + | |
| 394 | + $loginizer['captcha_no_google'] = !isset($options['captcha_no_google']) ? 0 : $options['captcha_no_google']; | |
| 395 | + $loginizer['captcha_domain'] = empty($options['captcha_domain']) ? 'www.google.com' : $options['captcha_domain']; | |
| 396 | + | |
| 397 | + $loginizer['captcha_text'] = empty($options['captcha_text']) ? __('Math Captcha', 'loginizer') : $options['captcha_text']; | |
| 398 | + $loginizer['captcha_time'] = empty($options['captcha_time']) ? 300 : $options['captcha_time']; | |
| 399 | + $loginizer['captcha_words'] = !isset($options['captcha_words']) ? 0 : $options['captcha_words']; | |
| 400 | + $loginizer['captcha_add'] = !isset($options['captcha_add']) ? 1 : $options['captcha_add']; | |
| 401 | + $loginizer['captcha_subtract'] = !isset($options['captcha_subtract']) ? 1 : $options['captcha_subtract']; | |
| 402 | + $loginizer['captcha_multiply'] = !isset($options['captcha_multiply']) ? 0 : $options['captcha_multiply']; | |
| 403 | + $loginizer['captcha_divide'] = !isset($options['captcha_divide']) ? 0 : $options['captcha_divide']; | |
| 404 | + | |
| 405 | + // 2fa/question | |
| 406 | + $options = get_option('loginizer_2fa'); | |
| 407 | + $loginizer['2fa_app'] = !isset($options['2fa_app']) ? 0 : $options['2fa_app']; | |
| 408 | + $loginizer['2fa_email'] = !isset($options['2fa_email']) ? 0 : $options['2fa_email']; | |
| 409 | + $loginizer['2fa_email_force'] = !isset($options['2fa_email_force']) ? 0 : $options['2fa_email_force']; | |
| 410 | + $loginizer['2fa_sms'] = !isset($options['2fa_sms']) ? 0 : $options['2fa_sms']; | |
| 411 | + $loginizer['question'] = !isset($options['question']) ? 0 : $options['question']; | |
| 412 | + $loginizer['2fa_default'] = empty($options['2fa_default']) ? 'question' : $options['2fa_default']; | |
| 413 | + $loginizer['2fa_roles'] = empty($options['2fa_roles']) ? array() : $options['2fa_roles']; | |
| 414 | + | |
| 415 | + // Security Settings | |
| 416 | + $options = get_option('loginizer_security'); | |
| 417 | + $loginizer['login_slug'] = empty($options['login_slug']) ? '' : $options['login_slug']; | |
| 418 | + $loginizer['rename_login_secret'] = empty($options['rename_login_secret']) ? '' : $options['rename_login_secret']; | |
| 419 | + $loginizer['xmlrpc_slug'] = empty($options['xmlrpc_slug']) ? '' : $options['xmlrpc_slug']; | |
| 420 | + $loginizer['xmlrpc_disable'] = empty($options['xmlrpc_disable']) ? '' : $options['xmlrpc_disable'];// Disable XML-RPC | |
| 421 | + $loginizer['pingbacks_disable'] = empty($options['pingbacks_disable']) ? '' : $options['pingbacks_disable'];// Disable Pingbacks | |
| 422 | + | |
| 423 | + // Admin Slug Settings | |
| 424 | + $options = get_option('loginizer_wp_admin'); | |
| 425 | + $loginizer['admin_slug'] = empty($options['admin_slug']) ? '' : $options['admin_slug']; | |
| 426 | + $loginizer['restrict_wp_admin'] = empty($options['restrict_wp_admin']) ? '' : $options['restrict_wp_admin']; | |
| 427 | + $loginizer['wp_admin_msg'] = empty($options['wp_admin_msg']) ? '' : $options['wp_admin_msg']; | |
| 428 | + | |
| 429 | + // Checksum Settings | |
| 430 | + $options = get_option('loginizer_checksums'); | |
| 431 | + $loginizer['disable_checksum'] = empty($options['disable_checksum']) ? '' : $options['disable_checksum']; | |
| 432 | + $loginizer['checksum_time'] = empty($options['checksum_time']) ? '' : $options['checksum_time']; | |
| 433 | + $loginizer['checksum_frequency'] = empty($options['checksum_frequency']) ? 7 : $options['checksum_frequency']; | |
| 434 | + $loginizer['no_checksum_email'] = empty($options['no_checksum_email']) ? '' : $options['no_checksum_email']; | |
| 435 | + $loginizer['checksums_last_run'] = get_option('loginizer_checksums_last_run'); | |
| 436 | + | |
| 437 | + // Auto Blacklist Usernames | |
| 438 | + $loginizer['username_blacklist'] = get_option('loginizer_username_blacklist'); | |
| 439 | + | |
| 440 | + $loginizer['domains_blacklist'] = get_option('loginizer_domains_blacklist'); | |
| 441 | + | |
| 442 | + $loginizer['wp_admin_d_msg'] = __('LZ : Not allowed via WP-ADMIN. Please access over the new Admin URL', 'loginizer'); | |
| 443 | + | |
| 444 | + // CSRF Protection | |
| 445 | + $loginizer['enable_csrf_protection'] = get_option('loginizer_csrf_protection'); | |
| 446 | + $loginizer['2fa_custom_login_redirect'] = get_option('loginizer_2fa_custom_redirect'); | |
| 447 | + $loginizer['limit_session'] = get_option('loginizer_limit_session'); | |
| 354 | 448 | |
| 355 | 449 | if((function_exists('wp_doing_ajax') && wp_doing_ajax()) || (defined( 'DOING_AJAX' ) && DOING_AJAX)){ |
| 356 | 450 | include_once LOGINIZER_DIR . '/main/ajax.php'; |
| 357 | 451 | } |
| @@ -358,18 +452,68 @@ | ||
| 358 | 452 | |
| 359 | 453 | if(is_admin()){ |
| 360 | 454 | include_once LOGINIZER_DIR . '/main/admin.php'; |
| 361 | 455 | } |
| 362 | - | |
| 456 | + | |
| 363 | 457 | // ---------------- |
| 364 | 458 | // PRO INIT END |
| 365 | 459 | // ---------------- |
| 366 | 460 | |
| 367 | - // Secuity checks for social login. | |
| 368 | - if(!empty($_GET['lz_social_provider']) && loginizer_can_login() && empty($_GET['lz_api'])){ | |
| 369 | - add_action('init', 'loginizer_social_login_load'); | |
| 370 | - return; | |
| 461 | + // Is the premium features there ? | |
| 462 | + if(file_exists(LOGINIZER_DIR.'/premium.php')){ | |
| 463 | + | |
| 464 | + // Include the file | |
| 465 | + include_once(LOGINIZER_DIR.'/premium.php'); | |
| 466 | + | |
| 467 | + loginizer_security_init(); | |
| 468 | + | |
| 469 | + // Its the free version | |
| 470 | + }else{ | |
| 471 | + | |
| 472 | + if(current_user_can('activate_plugins')){ | |
| 473 | + // The promo time | |
| 474 | + $loginizer['promo_time'] = get_option('loginizer_promo_time'); | |
| 475 | + if(empty($loginizer['promo_time'])){ | |
| 476 | + $loginizer['promo_time'] = time(); | |
| 477 | + update_option('loginizer_promo_time', $loginizer['promo_time']); | |
| 478 | + } | |
| 479 | + | |
| 480 | + // Are we to show the loginizer promo | |
| 481 | + if(!empty($loginizer['promo_time']) && $loginizer['promo_time'] > 0 && $loginizer['promo_time'] < (time() - (30*24*3600))){ | |
| 482 | + | |
| 483 | + add_action('admin_notices', 'loginizer_promo'); | |
| 484 | + | |
| 485 | + } | |
| 486 | + | |
| 487 | + if(!file_exists(LOGINIZER_DIR.'/premium.php') && current_user_can('activate_plugins') && !empty($loginizer['csrf_promo']) && $loginizer['csrf_promo'] > 0 && $loginizer['csrf_promo'] < (time() - 86400)){ | |
| 488 | + | |
| 489 | + add_action('admin_notices', 'loginizer_csrf_promo'); | |
| 490 | + | |
| 491 | + } | |
| 492 | + | |
| 493 | + // Are we to disable the promo | |
| 494 | + if(isset($_GET['loginizer_promo']) && (int)$_GET['loginizer_promo'] == 0){ | |
| 495 | + update_option('loginizer_promo_time', (0 - time()) ); | |
| 496 | + die('DONE'); | |
| 497 | + } | |
| 498 | + | |
| 499 | + $loginizer['backuply_promo'] = get_option('loginizer_backuply_promo_time'); | |
| 500 | + | |
| 501 | + if(empty($loginizer['backuply_promo'])){ | |
| 502 | + $loginizer['backuply_promo'] = abs($loginizer['promo_time']); | |
| 503 | + update_option('loginizer_backuply_promo_time', $loginizer['backuply_promo']); | |
| 504 | + } | |
| 505 | + | |
| 506 | + // Setting CSRF Promo time | |
| 507 | + $loginizer['csrf_promo'] = get_option('loginizer_csrf_promo_time'); | |
| 508 | + | |
| 509 | + if(empty($loginizer['csrf_promo'])){ | |
| 510 | + $loginizer['csrf_promo'] = abs($loginizer['promo_time']); | |
| 511 | + update_option('loginizer_csrf_promo_time', $loginizer['csrf_promo']); | |
| 512 | + } | |
| 513 | + } | |
| 371 | 514 | } |
| 515 | + | |
| 372 | 516 | } |
| 373 | 517 | |
| 374 | 518 | // Should return NULL if everything is fine |
| 375 | 519 | function loginizer_wp_authenticate($user, $username, $password){ |
| @@ -390,15 +534,9 @@ | ||
| 390 | 534 | |
| 391 | 535 | // This is used by WP Activity Log |
| 392 | 536 | apply_filters( 'wp_login_blocked', $username ); |
| 393 | 537 | |
| 394 | - // Shows a blocked screen | |
| 395 | - if(!empty($loginizer['blocked_screen'])){ | |
| 396 | - $lz_error['trusted_ip'] = __('You are restricted from logging in as your IP is not whitelisted.', 'loginizer'); | |
| 397 | - loginizer_blocked_page($lz_error); | |
| 398 | - } | |
| 399 | - | |
| 400 | - return new WP_Error('ip_blacklisted', __('You are restricted from logging in as your IP is not whitelisted.', 'loginizer')); | |
| 538 | + return new WP_Error('ip_blacklisted', __('Your IP is not whitelisted, so you can not log in', 'loginizer')); | |
| 401 | 539 | } |
| 402 | 540 | |
| 403 | 541 | // Are you blacklisted ? |
| 404 | 542 | if(loginizer_is_blacklisted()){ |
| @@ -406,13 +544,8 @@ | ||
| 406 | 544 | |
| 407 | 545 | // This is used by WP Activity Log |
| 408 | 546 | apply_filters( 'wp_login_blocked', $username ); |
| 409 | 547 | |
| 410 | - // Shows a blocked screen | |
| 411 | - if(!empty($loginizer['blocked_screen'])){ | |
| 412 | - loginizer_blocked_page($lz_error); | |
| 413 | - } | |
| 414 | - | |
| 415 | 548 | return new WP_Error('ip_blacklisted', implode('', $lz_error), 'loginizer'); |
| 416 | 549 | } |
| 417 | 550 | |
| 418 | 551 | // Is the username blacklisted ? |
| @@ -435,13 +568,8 @@ | ||
| 435 | 568 | |
| 436 | 569 | // This is used by WP Activity Log |
| 437 | 570 | apply_filters( 'wp_login_blocked', $username ); |
| 438 | 571 | |
| 439 | - // Shows a blocked screen | |
| 440 | - if(!empty($loginizer['blocked_screen'])){ | |
| 441 | - loginizer_blocked_page($lz_error); | |
| 442 | - } | |
| 443 | - | |
| 444 | 572 | return new WP_Error('ip_blocked', implode('', $lz_error), 'loginizer'); |
| 445 | 573 | |
| 446 | 574 | } |
| 447 | 575 | |
| @@ -476,11 +604,8 @@ | ||
| 476 | 604 | } |
| 477 | 605 | |
| 478 | 606 | $lz_error['ip_blocked'] = $loginizer['msg']['lockout_err'].' '.$_time; |
| 479 | 607 | |
| 480 | - if(!empty($loginizer['ultimate-member-active']) && class_exists('UM')){ | |
| 481 | - \UM()->form()->add_error('blocked_msg', $lz_error['ip_blocked']); | |
| 482 | - } | |
| 483 | 608 | return false; |
| 484 | 609 | } |
| 485 | 610 | } |
| 486 | 611 | |
| @@ -490,36 +615,31 @@ | ||
| 490 | 615 | function loginizer_is_blacklisted(){ |
| 491 | 616 | |
| 492 | 617 | global $wpdb, $loginizer, $lz_error; |
| 493 | 618 | |
| 494 | - $blacklist = isset($loginizer['blacklist']) ? $loginizer['blacklist'] : []; | |
| 619 | + $blacklist = $loginizer['blacklist']; | |
| 495 | 620 | |
| 496 | 621 | if(empty($blacklist)){ |
| 497 | 622 | return false; |
| 498 | 623 | } |
| 499 | - | |
| 500 | - $current_ip_inet = inet_ptoi($loginizer['current_ip']); | |
| 501 | - | |
| 624 | + | |
| 502 | 625 | foreach($blacklist as $k => $v){ |
| 503 | - | |
| 504 | - $start_inet = inet_ptoi($v['start']); | |
| 505 | - $end_inet = inet_ptoi($v['end']); | |
| 506 | - | |
| 626 | + | |
| 507 | 627 | // Is the IP in the blacklist ? |
| 508 | - if($start_inet <= $current_ip_inet && $current_ip_inet <= $end_inet){ | |
| 628 | + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){ | |
| 509 | 629 | $result = 1; |
| 510 | 630 | break; |
| 511 | 631 | } |
| 512 | - | |
| 632 | + | |
| 513 | 633 | // Is it in a wider range ? |
| 514 | - if($start_inet >= 0 && $end_inet < 0){ | |
| 634 | + if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){ | |
| 515 | 635 | |
| 516 | 636 | // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi, |
| 517 | 637 | // if the current IP is <= than the start of the range, it is within the range |
| 518 | 638 | // OR |
| 519 | 639 | // if the current IP is <= than the end of the range, it is within the range |
| 520 | - if($start_inet <= $current_ip_inet | |
| 521 | - || $current_ip_inet <= $end_inet){ | |
| 640 | + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) | |
| 641 | + || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){ | |
| 522 | 642 | $result = 1; |
| 523 | 643 | break; |
| 524 | 644 | } |
| 525 | 645 | |
| @@ -525,9 +645,9 @@ | ||
| 525 | 645 | |
| 526 | 646 | } |
| 527 | 647 | |
| 528 | 648 | } |
| 529 | - | |
| 649 | + | |
| 530 | 650 | // You are blacklisted |
| 531 | 651 | if(!empty($result)){ |
| 532 | 652 | $lz_error['ip_blacklisted'] = $loginizer['msg']['ip_blacklisted']; |
| 533 | 653 | return true; |
| @@ -536,8 +656,53 @@ | ||
| 536 | 656 | return false; |
| 537 | 657 | |
| 538 | 658 | } |
| 539 | 659 | |
| 660 | +function loginizer_is_whitelisted(){ | |
| 661 | + | |
| 662 | + global $wpdb, $loginizer, $lz_error; | |
| 663 | + | |
| 664 | + $whitelist = $loginizer['whitelist']; | |
| 665 | + | |
| 666 | + if(empty($whitelist)){ | |
| 667 | + return false; | |
| 668 | + } | |
| 669 | + | |
| 670 | + foreach($whitelist as $k => $v){ | |
| 671 | + | |
| 672 | + // Is the IP in the blacklist ? | |
| 673 | + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){ | |
| 674 | + $result = 1; | |
| 675 | + break; | |
| 676 | + } | |
| 677 | + | |
| 678 | + // Is it in a wider range ? | |
| 679 | + if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){ | |
| 680 | + | |
| 681 | + // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi, | |
| 682 | + // if the current IP is <= than the start of the range, it is within the range | |
| 683 | + // OR | |
| 684 | + // if the current IP is <= than the end of the range, it is within the range | |
| 685 | + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) | |
| 686 | + || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){ | |
| 687 | + $result = 1; | |
| 688 | + break; | |
| 689 | + } | |
| 690 | + | |
| 691 | + } | |
| 692 | + | |
| 693 | + } | |
| 694 | + | |
| 695 | + // You are whitelisted | |
| 696 | + if(!empty($result)){ | |
| 697 | + return true; | |
| 698 | + } | |
| 699 | + | |
| 700 | + return false; | |
| 701 | + | |
| 702 | +} | |
| 703 | + | |
| 704 | + | |
| 540 | 705 | // When the login fails, then this is called |
| 541 | 706 | // We need to update the database |
| 542 | 707 | function loginizer_login_failed($username, $is_2fa = ''){ |
| 543 | 708 | |
| @@ -555,79 +720,47 @@ | ||
| 555 | 720 | } |
| 556 | 721 | |
| 557 | 722 | if(empty($lz_cannot_login) && empty($loginizer['ip_is_whitelisted']) && empty($loginizer['no_loginizer_logs'])){ |
| 558 | 723 | |
| 559 | - // The params which comes when social login returns an error, have some characters, which WordPress could not save. | |
| 560 | - // REQUEST_URI / HTTP_HOST are not always set (WP-CLI, some CGI and XML-RPC setups) | |
| 561 | - $server_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; | |
| 562 | - $http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; | |
| 724 | + $url = @addslashes((!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); | |
| 725 | + $url = esc_url($url); | |
| 563 | 726 | |
| 564 | - if(!empty($server_uri) && strpos($server_uri, 'lz_social_provider') !== FALSE){ | |
| 565 | - $request_uri = explode('=', $server_uri); | |
| 566 | - $server_uri = $request_uri[0]; | |
| 567 | - } | |
| 568 | - | |
| 569 | - // No addslashes() here, $wpdb->prepare() below does the escaping | |
| 570 | - $url = esc_url((!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$http_host.$server_uri); | |
| 571 | - | |
| 572 | - // Must never be 0, we divide by it below | |
| 573 | - $max_retries = (int) $loginizer['max_retries'] < 1 ? 1 : (int) $loginizer['max_retries']; | |
| 574 | - | |
| 575 | - // This way is atomic now, the earlier one were causing race condition. | |
| 576 | - // NOTE : In the UPDATE part `count` is already the new value, as MySQL / MariaDB | |
| 577 | - // evaluate the assignments from left to right, so lockout must NOT add 1 again | |
| 578 | - $upsert = $wpdb->prepare( | |
| 579 | - "INSERT INTO `".$wpdb->prefix."loginizer_logs` | |
| 580 | - (username, time, count, ip, lockout, url) | |
| 581 | - VALUES | |
| 582 | - (%s, %d, 1, %s, FLOOR(1 / %d), %s) | |
| 583 | - ON DUPLICATE KEY UPDATE | |
| 584 | - username = VALUES(username), | |
| 585 | - time = VALUES(time), | |
| 586 | - count = count + 1, | |
| 587 | - lockout = FLOOR(count / %d), | |
| 588 | - url = VALUES(url)", | |
| 589 | - $username, | |
| 590 | - time(), | |
| 591 | - $loginizer['current_ip'], | |
| 592 | - $max_retries, | |
| 593 | - $url, | |
| 594 | - $max_retries | |
| 595 | - ); | |
| 596 | - $wpdb->query($upsert); | |
| 597 | - | |
| 598 | - // Re-read the persisted row so email/retries-left reflect the actual count | |
| 599 | 727 | $sel_query = $wpdb->prepare("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = %s", $loginizer['current_ip']); |
| 600 | 728 | $result = lz_selectquery($sel_query); |
| 729 | + | |
| 730 | + if(!empty($result)){ | |
| 731 | + $lockout = floor((($result['count']+1) / $loginizer['max_retries'])); | |
| 732 | + | |
| 733 | + $update_data = array('username' => $username, | |
| 734 | + 'time' => time(), | |
| 735 | + 'count' => $result['count']+1, | |
| 736 | + 'lockout' => $lockout, | |
| 737 | + 'url' => $url); | |
| 738 | + | |
| 739 | + $where_data = array('ip' => $loginizer['current_ip']); | |
| 740 | + | |
| 741 | + $format = array('%s','%d','%d','%d','%s'); | |
| 742 | + $where_format = array('%s'); | |
| 743 | + | |
| 744 | + $wpdb->update($wpdb->prefix.'loginizer_logs', $update_data, $where_data, $format, $where_format); | |
| 745 | + | |
| 746 | + // Do we need to email admin ? | |
| 747 | + if(!empty($loginizer['notify_email']) && $lockout >= $loginizer['notify_email']){ | |
| 748 | + | |
| 749 | + $lockout_time = $loginizer['lockout_time']; | |
| 750 | + | |
| 751 | + if($lockout >= $loginizer['max_lockouts']){ | |
| 752 | + // extended lockout is in hours so we have to convert to minute | |
| 753 | + $lockout_time = $loginizer['lockouts_extend']; | |
| 754 | + } | |
| 755 | + | |
| 756 | + $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname'); | |
| 757 | + $mail = array(); | |
| 758 | + $mail['to'] = $loginizer['notify_email_address']; | |
| 759 | + $mail['subject'] = 'Failed '.$fail_type.' Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')'; | |
| 760 | + $mail['message'] = 'Hi, | |
| 601 | 761 | |
| 602 | - if(empty($result)){ | |
| 603 | - $result = array('count' => 0); | |
| 604 | - } | |
| 605 | - | |
| 606 | - $count = (int) $result['count']; | |
| 607 | - $lockout = !empty($result['lockout']) ? (int) $result['lockout'] : 0; | |
| 608 | - | |
| 609 | - // The lockout goes up only on every max_retries'th failure, which is the | |
| 610 | - // attempt that actually locks the IP out. On the failures in between there | |
| 611 | - // is nothing new to report, so we must not email on each one of them | |
| 612 | - $is_new_lockout = !empty($count) && ($count % $max_retries) == 0; | |
| 613 | - | |
| 614 | - // Do we need to email admin ? | |
| 615 | - if(!empty($loginizer['notify_email']) && !empty($is_new_lockout) && $lockout >= $loginizer['notify_email']){ | |
| 616 | - | |
| 617 | - $lockout_time = $loginizer['lockout_time']; | |
| 618 | - | |
| 619 | - if($lockout >= $loginizer['max_lockouts']){ | |
| 620 | - $lockout_time = $loginizer['lockouts_extend']; | |
| 621 | - } | |
| 622 | - | |
| 623 | - $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname'); | |
| 624 | - $mail = array(); | |
| 625 | - $mail['to'] = $loginizer['notify_email_address']; | |
| 626 | - $mail['subject'] = 'Failed '.$fail_type.' Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')'; | |
| 627 | - $mail['message'] = 'Hi, | |
| 628 | - | |
| 629 | -'.(int) $result['count'].' failed '.strtolower($fail_type).' attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].' on your site : | |
| 762 | +'.($result['count']+1).' failed '.strtolower($fail_type).' attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].' on your site : | |
| 630 | 763 | '.home_url().' |
| 631 | 764 | |
| 632 | 765 | Last '.$fail_type.' Attempt : '.date('d/M/Y H:i:s P', time()).' |
| 633 | 766 | Last User Attempt : '.$username.' |
| @@ -635,111 +768,37 @@ | ||
| 635 | 768 | |
| 636 | 769 | Regards, |
| 637 | 770 | Loginizer'; |
| 638 | 771 | |
| 639 | - @wp_mail($mail['to'], $mail['subject'], $mail['message']); | |
| 772 | + @wp_mail($mail['to'], $mail['subject'], $mail['message']); | |
| 773 | + } | |
| 774 | + }else{ | |
| 775 | + $result = array(); | |
| 776 | + $result['count'] = 0; | |
| 777 | + | |
| 778 | + $insert_data = array('username' => $username, | |
| 779 | + 'time' => time(), | |
| 780 | + 'count' => 1, | |
| 781 | + 'ip' => $loginizer['current_ip'], | |
| 782 | + 'lockout' => 0, | |
| 783 | + 'url' => $url); | |
| 784 | + | |
| 785 | + $format = array('%s','%d','%d','%s','%d','%s'); | |
| 786 | + | |
| 787 | + $wpdb->insert($wpdb->prefix.'loginizer_logs', $insert_data, $format); | |
| 640 | 788 | } |
| 641 | - | |
| 789 | + | |
| 790 | + // We need to add one as this is a failed attempt as well | |
| 791 | + $result['count'] = $result['count'] + 1; | |
| 642 | 792 | loginizer_update_attempt_stats(0); |
| 643 | - $loginizer['retries_left'] = $max_retries - ($count % $max_retries); | |
| 644 | - $loginizer['retries_left'] = $loginizer['retries_left'] == $max_retries ? 0 : $loginizer['retries_left']; | |
| 793 | + $loginizer['retries_left'] = ($loginizer['max_retries'] - ($result['count'] % $loginizer['max_retries'])); | |
| 794 | + $loginizer['retries_left'] = $loginizer['retries_left'] == $loginizer['max_retries'] ? 0 : $loginizer['retries_left']; | |
| 645 | 795 | |
| 646 | 796 | } |
| 647 | 797 | } |
| 648 | 798 | |
| 649 | -function loginizer_rsssl_2fa_success($user){ | |
| 650 | - loginizer_login_success('', $user); | |
| 651 | -} | |
| 652 | - | |
| 653 | -function loginizer_login_success($user_login, $user) { | |
| 654 | - global $wp_version, $loginizer; | |
| 655 | - | |
| 799 | +function loginizer_login_success($user_login, $user){ | |
| 656 | 800 | loginizer_update_attempt_stats(1); |
| 657 | - | |
| 658 | - if(empty($loginizer['login_mail'])){ | |
| 659 | - return; | |
| 660 | - } | |
| 661 | - | |
| 662 | - if(empty($loginizer['login_mail']['enable'])){ | |
| 663 | - return; | |
| 664 | - } | |
| 665 | - | |
| 666 | - if(!empty($loginizer['login_mail']['disable_whitelist'])){ | |
| 667 | - // Check its whitelist ip | |
| 668 | - if(loginizer_is_whitelisted()){ | |
| 669 | - return; | |
| 670 | - } | |
| 671 | - } | |
| 672 | - | |
| 673 | - if(empty($user_login) && empty($user)){ | |
| 674 | - error_log('Loginizer: No user information to send email'); | |
| 675 | - return; | |
| 676 | - } | |
| 677 | - | |
| 678 | - if(empty($user)){ | |
| 679 | - $user = get_user_by('login', $user_login); | |
| 680 | - } | |
| 681 | - | |
| 682 | - if(empty($user)){ | |
| 683 | - error_log('Loginizer: Unable to get the user'); | |
| 684 | - return; | |
| 685 | - } | |
| 686 | - | |
| 687 | - if(empty($loginizer['login_mail']['roles']) || !is_array($loginizer['login_mail']['roles'])){ | |
| 688 | - return; | |
| 689 | - } | |
| 690 | - | |
| 691 | - // Check if the user role is enabled for email notification. | |
| 692 | - if(!array_intersect($user->roles, $loginizer['login_mail']['roles'])){ | |
| 693 | - return; | |
| 694 | - } | |
| 695 | - | |
| 696 | - // current_datetime & wp_timezone_string were introduced in WordPress 5.3 | |
| 697 | - if(!empty($wp_version) && version_compare($wp_version, '5.3', '>') && function_exists('current_datetime')){ | |
| 698 | - $time_zone = wp_timezone_string(); | |
| 699 | - | |
| 700 | - if(!empty($time_zone) && isset($time_zone[1]) && is_numeric($time_zone[1])){ | |
| 701 | - $time_zone = 'UTC'.$time_zone; | |
| 702 | - } | |
| 703 | - | |
| 704 | - // Setting up data variables. | |
| 705 | - $date = current_datetime()->format('Y-m-d H:i:s') .' '. $time_zone; | |
| 706 | - } else { | |
| 707 | - $date = date("Y-m-d H:i:s", time()) . ' ' . date_default_timezone_get(); | |
| 708 | - } | |
| 709 | - | |
| 710 | - $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname'); | |
| 711 | - $email = $user->data->user_email; | |
| 712 | - | |
| 713 | - $vars = array( | |
| 714 | - 'date' => $date, | |
| 715 | - 'ip' => esc_html($loginizer['current_ip']), | |
| 716 | - 'sitename' => $sitename, | |
| 717 | - 'user_login' => $user_login | |
| 718 | - ); | |
| 719 | - | |
| 720 | - $message = lz_lang_vars_name($loginizer['login_mail_body'], $vars); | |
| 721 | - $subject = lz_lang_vars_name($loginizer['login_mail_subject'], $vars); | |
| 722 | - | |
| 723 | - $headers = []; | |
| 724 | - | |
| 725 | - // Do we need to send the email as HTML ? | |
| 726 | - if(!empty($loginizer['login_mail']['html_mail'])){ | |
| 727 | - $headers[] = 'Content-Type: text/html; charset=UTF-8'; | |
| 728 | - | |
| 729 | - if(!empty($loginizer['login_mail']['body'])){ | |
| 730 | - $message = html_entity_decode($message); | |
| 731 | - }else{ | |
| 732 | - $message = preg_replace("/\<br\s*\/\>/i", "<br/>", $message); | |
| 733 | - $message = preg_replace('/(?<!<br\/>)\n/i', "<br/>\n", $message); | |
| 734 | - } | |
| 735 | - } | |
| 736 | - | |
| 737 | - // Sending notification | |
| 738 | - if(empty(wp_mail($email, $subject, $message, $headers))){ | |
| 739 | - error_log(__('There was a problem sending your email.', 'loginizer')); | |
| 740 | - return; | |
| 741 | - } | |
| 742 | 801 | } |
| 743 | 802 | |
| 744 | 803 | function loginizer_update_attempt_stats($type){ |
| 745 | 804 | |
| @@ -758,9 +817,9 @@ | ||
| 758 | 817 | // Handles the error of the password not being there |
| 759 | 818 | function loginizer_error_handler($errors, $redirect_to){ |
| 760 | 819 | |
| 761 | 820 | global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login; |
| 762 | - | |
| 821 | + | |
| 763 | 822 | //echo 'loginizer_error_handler :';print_r($errors->errors);echo '<br>'; |
| 764 | 823 | if(is_null($errors) || empty($errors)){ |
| 765 | 824 | return true; |
| 766 | 825 | } |
| @@ -796,48 +855,17 @@ | ||
| 796 | 855 | } |
| 797 | 856 | |
| 798 | 857 | // Handles the error of the password not being there |
| 799 | 858 | function loginizer_woocommerce_error_handler(){ |
| 800 | - | |
| 859 | + | |
| 801 | 860 | global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login; |
| 802 | 861 | |
| 803 | 862 | if(function_exists('wc_add_notice')){ |
| 804 | 863 | wc_add_notice( loginizer_retries_left(), 'error' ); |
| 805 | 864 | } |
| 806 | -} | |
| 807 | - | |
| 808 | -function loginizer_ultimatemember_error_handler(){ | |
| 809 | 865 | |
| 810 | - if(class_exists('UM')){ | |
| 811 | - \UM()->form()->add_error('remaining_tries', loginizer_retries_left()); | |
| 812 | - } | |
| 813 | 866 | } |
| 814 | 867 | |
| 815 | -// Handles social login URL | |
| 816 | -function loginizer_social_login_error_handler($errors = '', $redirect_to = ''){ | |
| 817 | - global $loginizer; | |
| 818 | - | |
| 819 | - if(loginizer_is_blacklisted()){ | |
| 820 | - return $errors; | |
| 821 | - } | |
| 822 | - | |
| 823 | - loginizer_get_social_error(); | |
| 824 | - | |
| 825 | - if(empty($loginizer['social_errors'])){ | |
| 826 | - return $errors; | |
| 827 | - } | |
| 828 | - | |
| 829 | - if(is_null($errors) || empty($errors) || !is_wp_error($errors)){ | |
| 830 | - $errors = new WP_Error(); | |
| 831 | - } | |
| 832 | - | |
| 833 | - foreach($loginizer['social_errors'] as $key => $text){ | |
| 834 | - $errors->add($key, $text); | |
| 835 | - } | |
| 836 | - | |
| 837 | - return $errors; | |
| 838 | -} | |
| 839 | - | |
| 840 | 868 | // Returns a string with the number of retries left |
| 841 | 869 | function loginizer_retries_left(){ |
| 842 | 870 | |
| 843 | 871 | global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login; |
| @@ -851,125 +879,18 @@ | ||
| 851 | 879 | |
| 852 | 880 | } |
| 853 | 881 | |
| 854 | 882 | function loginizer_reset_retries(){ |
| 855 | - | |
| 883 | + | |
| 856 | 884 | global $wpdb, $loginizer; |
| 857 | - | |
| 885 | + | |
| 858 | 886 | $deltime = time() - $loginizer['reset_retries']; |
| 859 | - | |
| 887 | + | |
| 860 | 888 | $del_query = $wpdb->prepare("DELETE FROM `".$wpdb->prefix."loginizer_logs` WHERE `time` <= %d", $deltime); |
| 861 | 889 | $result = $wpdb->query($del_query); |
| 862 | - | |
| 890 | + | |
| 863 | 891 | update_option('loginizer_last_reset', time()); |
| 864 | - | |
| 865 | -} | |
| 866 | - | |
| 867 | -function loginizer_load_translation_vars(){ | |
| 868 | - global $loginizer; | |
| 869 | 892 | |
| 870 | - $loginizer['login_mail_default_sub'] = __('Login Successful at $sitename', 'loginizer'); | |
| 871 | - $loginizer['login_mail_default_msg'] = __('Hello $user_login, | |
| 872 | - | |
| 873 | -Your account was recently logged in from the IP : $ip | |
| 874 | -Time : $date | |
| 875 | -If it was not you who logged in then please report this to us immediately. | |
| 876 | - | |
| 877 | -Regards, | |
| 878 | -$sitename','loginizer'); | |
| 879 | - | |
| 880 | - if(empty($loginizer['login_mail_subject'])){ | |
| 881 | - $loginizer['login_mail_subject'] = $loginizer['login_mail_default_sub']; | |
| 882 | - } | |
| 883 | - | |
| 884 | - if(empty($loginizer['login_mail_body'])){ | |
| 885 | - $loginizer['login_mail_body'] = $loginizer['login_mail_default_msg']; | |
| 886 | - } | |
| 887 | - | |
| 888 | - // Default messages | |
| 889 | - $loginizer['d_msg']['inv_userpass'] = __('Incorrect Username or Password', 'loginizer'); | |
| 890 | - $loginizer['d_msg']['ip_blacklisted'] = __('Your IP has been blacklisted', 'loginizer'); | |
| 891 | - $loginizer['d_msg']['attempts_left'] = __('attempt(s) left', 'loginizer'); | |
| 892 | - $loginizer['d_msg']['lockout_err'] = __('You have exceeded maximum login retries<br /> Please try after', 'loginizer'); | |
| 893 | - $loginizer['d_msg']['minutes_err'] = __('minute(s)', 'loginizer'); | |
| 894 | - $loginizer['d_msg']['hours_err'] = __('hour(s)', 'loginizer'); | |
| 895 | - | |
| 896 | - // Message Strings | |
| 897 | - $loginizer['msg'] = get_option('loginizer_msg', []); | |
| 898 | - | |
| 899 | - foreach($loginizer['d_msg'] as $lk => $lv){ | |
| 900 | - if(empty($loginizer['msg'][$lk])){ | |
| 901 | - $loginizer['msg'][$lk] = $loginizer['d_msg'][$lk]; | |
| 902 | - } | |
| 903 | - } | |
| 904 | - | |
| 905 | - $loginizer['2fa_d_msg']['otp_app'] = __('Please enter the OTP as seen in your App', 'loginizer'); | |
| 906 | - $loginizer['2fa_d_msg']['otp_email'] = __('Please enter the OTP emailed to you', 'loginizer'); | |
| 907 | - $loginizer['2fa_d_msg']['otp_field'] = __('One Time Password', 'loginizer'); | |
| 908 | - $loginizer['2fa_d_msg']['otp_question'] = __('Please answer your security question', 'loginizer'); | |
| 909 | - $loginizer['2fa_d_msg']['otp_answer'] = __('Your Answer', 'loginizer'); | |
| 910 | - | |
| 911 | - // Message Strings | |
| 912 | - $loginizer['2fa_msg'] = get_option('loginizer_2fa_msg', []); | |
| 913 | - | |
| 914 | - foreach($loginizer['2fa_d_msg'] as $lk => $lv){ | |
| 915 | - if(empty($loginizer['2fa_msg'][$lk])){ | |
| 916 | - $loginizer['2fa_msg'][$lk] = $loginizer['2fa_d_msg'][$lk]; | |
| 917 | - } | |
| 918 | - } | |
| 919 | - | |
| 920 | -} | |
| 921 | - | |
| 922 | -function loginizer_social_login_load(){ | |
| 923 | - include_once LOGINIZER_DIR . '/main/social-login.php'; | |
| 924 | -} | |
| 925 | - | |
| 926 | -// Checks if softaculous is installed on the server. | |
| 927 | -function loginizer_check_softaculous(){ | |
| 928 | - | |
| 929 | - // Checking if we have Softaculous installed? | |
| 930 | - if(!preg_match('/^\/home(?:\d+)?\/.*\//U', ABSPATH, $matches)){ | |
| 931 | - return false; | |
| 932 | - } | |
| 933 | - | |
| 934 | - if(empty($matches) || empty($matches[0])){ | |
| 935 | - return false; | |
| 936 | - } | |
| 937 | - | |
| 938 | - $softaculous_path = $matches[0] . '.softaculous/installations.php'; | |
| 939 | - if(!file_exists($softaculous_path)){ | |
| 940 | - return false; | |
| 941 | - } | |
| 942 | - | |
| 943 | - // Checking if users has changed the branding of Softaculous. | |
| 944 | - $universal_file = ''; | |
| 945 | - // Plesk, ISPManager, ISPConfig, InterWorx, H-Sphere, CentOS Web Panel, Softaculous Remote and Softaculous Enterprise | |
| 946 | - if(file_exists('/usr/local/softaculous/enduser/universal.php')){ | |
| 947 | - $universal_file = '/usr/local/softaculous/enduser/universal.php'; | |
| 948 | - }else if(file_exists('/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/enduser/universal.php')){ | |
| 949 | - $universal_file = '/usr/local/cpanel/whostmgr/docroot/cgi/softaculous/enduser/universal.php'; | |
| 950 | - }else if(file_exists('/usr/local/directadmin/plugins/softaculous/enduser/universal.php')){ | |
| 951 | - $universal_file = '/usr/local/directadmin/plugins/softaculous/enduser/universal.php'; | |
| 952 | - }else if(file_exists('/usr/local/vesta/softaculous/enduser/universal.php')){ | |
| 953 | - $universal_file = '/usr/local/vesta/softaculous/enduser/universal.php'; | |
| 954 | - } | |
| 955 | - | |
| 956 | - if(empty($universal_file)){ | |
| 957 | - return false; | |
| 958 | - } | |
| 959 | - | |
| 960 | - $universal = file_get_contents($universal_file); | |
| 961 | - | |
| 962 | - if(empty($universal)){ | |
| 963 | - return false; | |
| 964 | - } | |
| 965 | - | |
| 966 | - // Checking if Softaculous is being whitelabeled | |
| 967 | - if(preg_match('/\$globals\[["\']sn["\']\]\s.?=\s.?["\']Softaculous["\']/', $universal)){ | |
| 968 | - update_option('loginizer_softwp_upgrade', time()); | |
| 969 | - } | |
| 970 | - | |
| 971 | - return false; | |
| 972 | 893 | } |
| 973 | 894 | |
| 974 | 895 | // Sorry to see you going |
| 975 | 896 | register_uninstall_hook(LOGINIZER_FILE, 'loginizer_deactivation'); |