| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | require_once (dirname(__FILE__).'/easy-basic-authentication-log-class.php'); |
| 4 | 4 | require_once (dirname(__FILE__).'/easy-basic-authentication-emailalert-class.php'); |
| 5 | 5 | require_once (dirname(__FILE__).'/easy-basic-authentication-form-class.php'); |
| 6 | +require_once (dirname(__FILE__).'/easy-basic-authentication-notice-class.php'); | |
| 6 | 7 | |
| 7 | 8 | class easy_basic_authentication_class { |
| 8 | 9 | |
| 9 | 10 | private $log; |
| @@ -14,12 +15,13 @@ | ||
| 14 | 15 | { |
| 15 | 16 | $this->log = new easy_basic_authentication_log_class(); |
| 16 | 17 | $this->email = new easy_basic_authentication_emailalert_class(); |
| 17 | 18 | $this->form = new easy_basic_authentication_form_class(); |
| 19 | + $notice = new easy_basic_authentication_notice_class(); | |
| 18 | 20 | |
| 19 | 21 | if(get_option( 'basic_auth_plugin_admin_enable' )) { |
| 20 | 22 | if (in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) { |
| 21 | - add_action( 'init', array($this,'basic_auth_admin') ); | |
| 23 | + add_action( 'init', array($this,'basic_auth_root') ); | |
| 22 | 24 | } |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | if(get_option( 'basic_auth_plugin_enable' ) && get_option( 'basic_auth_plugin_admin_enable' )){ |
| @@ -39,28 +41,21 @@ | ||
| 39 | 41 | public function basic_auth_root() { |
| 40 | 42 | $user = get_option( 'basic_auth_plugin_username' ); |
| 41 | 43 | $pass = get_option( 'basic_auth_plugin_password' ); |
| 42 | 44 | |
| 43 | - if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) || | |
| 44 | - $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) { | |
| 45 | + if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) || | |
| 46 | + $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( wp_unslash( $_SERVER['PHP_AUTH_PW'] ), $pass ) ) { | |
| 45 | 47 | |
| 46 | 48 | $this->do_exit(true); |
| 47 | 49 | } |
| 48 | 50 | } |
| 49 | - | |
| 50 | - public function basic_auth_admin() { | |
| 51 | - $user = get_option( 'basic_auth_plugin_username' ); | |
| 52 | - $pass = get_option( 'basic_auth_plugin_password' ); | |
| 53 | - | |
| 54 | - if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) || | |
| 55 | - $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) { | |
| 56 | - | |
| 57 | - $this->do_exit(true); | |
| 58 | - } | |
| 59 | - } | |
| 60 | - | |
| 51 | + | |
| 61 | 52 | public function do_exit($admin_area = false) { |
| 62 | 53 | |
| 54 | + if (isset($_SERVER['REMOTE_ADDR']) && in_array($_SERVER['REMOTE_ADDR'], $this->getWhiteList())) { | |
| 55 | + return; | |
| 56 | + } | |
| 57 | + | |
| 63 | 58 | $this->basic_auth_action_failed_access(); |
| 64 | 59 | do_action('basic_auth_before_401'); |
| 65 | 60 | |
| 66 | 61 | if($admin_area) { |
| @@ -73,8 +68,12 @@ | ||
| 73 | 68 | header( 'HTTP/1.1 401 Unauthorized' ); |
| 74 | 69 | header( 'WWW-Authenticate: Basic realm="Admin Area"' ); |
| 75 | 70 | exit; |
| 76 | 71 | } |
| 72 | + } | |
| 73 | + | |
| 74 | + public function getWhiteList() { | |
| 75 | + return get_option( 'basic_auth_plugin_whitelist' )?explode(',',get_option( 'basic_auth_plugin_whitelist' )):[]; | |
| 77 | 76 | } |
| 78 | 77 | |
| 79 | 78 | public function basic_auth_plugin_menu() { |
| 80 | 79 | add_menu_page( |