| @@ -42,16 +42,9 @@ | ||
| 42 | 42 | |
| 43 | 43 | if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) || |
| 44 | 44 | $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) { |
| 45 | 45 | |
| 46 | - $this->basic_auth_action_failed_access(); | |
| 47 | - | |
| 48 | - do_action('basic_auth_before_401'); | |
| 49 | - | |
| 50 | - header( 'WWW-Authenticate: Basic realm="My Website"' ); | |
| 51 | - header( 'HTTP/1.0 401 Unauthorized' ); | |
| 52 | - echo 'Autenticazione richiesta'; | |
| 53 | - exit; | |
| 46 | + $this->do_exit(true); | |
| 54 | 47 | } |
| 55 | 48 | } |
| 56 | 49 | |
| 57 | 50 | public function basic_auth_admin() { |
| @@ -59,20 +52,38 @@ | ||
| 59 | 52 | $pass = get_option( 'basic_auth_plugin_password' ); |
| 60 | 53 | |
| 61 | 54 | if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) || |
| 62 | 55 | $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) { |
| 56 | + | |
| 57 | + $this->do_exit(true); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + public function do_exit($admin_area = false) { | |
| 62 | + | |
| 63 | + if (in_array($_SERVER['REMOTE_ADDR'], $this->getWhiteList())) { | |
| 64 | + return; | |
| 65 | + } | |
| 66 | + $this->basic_auth_action_failed_access(); | |
| 67 | + do_action('basic_auth_before_401'); | |
| 68 | + | |
| 69 | + if($admin_area) { | |
| 70 | + do_action('basic_auth_before_401_admin_area'); | |
| 63 | 71 | |
| 64 | - $this->basic_auth_action_failed_access(); | |
| 65 | - | |
| 66 | - do_action('basic_auth_before_401'); | |
| 67 | - | |
| 72 | + header( 'WWW-Authenticate: Basic realm="My Website"' ); | |
| 73 | + header( 'HTTP/1.0 401 Unauthorized' ); | |
| 74 | + exit; | |
| 75 | + } else { | |
| 68 | 76 | header( 'HTTP/1.1 401 Unauthorized' ); |
| 69 | 77 | header( 'WWW-Authenticate: Basic realm="Admin Area"' ); |
| 70 | 78 | exit; |
| 71 | - } | |
| 79 | + } | |
| 72 | 80 | } |
| 73 | - | |
| 74 | - | |
| 81 | + | |
| 82 | + public function getWhiteList() { | |
| 83 | + return get_option( 'basic_auth_plugin_whitelist' )?explode(',',get_option( 'basic_auth_plugin_whitelist' )):[]; | |
| 84 | + } | |
| 85 | + | |
| 75 | 86 | public function basic_auth_plugin_menu() { |
| 76 | 87 | add_menu_page( |
| 77 | 88 | __('Configurations for Easy Basic Authentication', 'easy-basic-authentication'), |
| 78 | 89 | __('Easy Basic A.', 'easy-basic-authentication'), |