| @@ -29,10 +29,8 @@ | ||
| 29 | 29 | if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) || |
| 30 | 30 | $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) { |
| 31 | 31 | |
| 32 | 32 | $this->basic_auth_log_failed_access(); |
| 33 | - | |
| 34 | - do_action('basic_auth_before_401'); | |
| 35 | 33 | |
| 36 | 34 | header( 'WWW-Authenticate: Basic realm="My Website"' ); |
| 37 | 35 | header( 'HTTP/1.0 401 Unauthorized' ); |
| 38 | 36 | echo 'Autenticazione richiesta'; |
| @@ -44,14 +42,12 @@ | ||
| 44 | 42 | $user = get_option( 'basic_auth_plugin_username' ); |
| 45 | 43 | $pass = get_option( 'basic_auth_plugin_password' ); |
| 46 | 44 | |
| 47 | 45 | if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) || |
| 48 | - $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) { | |
| 46 | + $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) { | |
| 49 | 47 | |
| 50 | 48 | $this->basic_auth_log_failed_access(); |
| 51 | - | |
| 52 | - do_action('basic_auth_before_401'); | |
| 53 | - | |
| 49 | + | |
| 54 | 50 | header( 'HTTP/1.1 401 Unauthorized' ); |
| 55 | 51 | header( 'WWW-Authenticate: Basic realm="Admin Area"' ); |
| 56 | 52 | exit; |
| 57 | 53 | } |
| @@ -58,28 +54,29 @@ | ||
| 58 | 54 | } |
| 59 | 55 | |
| 60 | 56 | |
| 61 | 57 | public function basic_auth_plugin_menu() { |
| 58 | + ini_set('display_errors', 1); | |
| 59 | +ini_set('display_startup_errors', 1); | |
| 60 | +error_reporting(E_ALL); | |
| 62 | 61 | $access_count = $this->basic_auth_count_not_viewed_log_failed_access(); |
| 63 | 62 | add_menu_page( |
| 64 | 63 | __('Configurations for Easy Basic Authentication', 'easy-basic-authentication'), |
| 65 | - __('Easy Basic A.', 'easy-basic-authentication'), | |
| 64 | + __('Easy Basic A.', 'easy-basic-authentication') . '<span class="update-plugins count-' . $access_count . '"><span class="plugin-count">' . $access_count . '</span></span>', | |
| 66 | 65 | 'manage_options', |
| 67 | 66 | 'basic-auth-plugin', |
| 68 | 67 | array($this, 'basic_auth_plugin_settings_page'), |
| 69 | 68 | 'dashicons-lock' |
| 70 | 69 | ); |
| 71 | - if($this->log_is_enabled()) { | |
| 72 | - add_submenu_page( | |
| 73 | - 'basic-auth-plugin', | |
| 74 | - __('Log Page', 'easy-basic-authentication'), | |
| 75 | - __('Log Page', 'easy-basic-authentication'). '<span class="update-plugins count-' . $access_count . '"><span class="plugin-count">' . $access_count . '</span></span>', | |
| 76 | - 'manage_options', | |
| 77 | - 'basic-auth-login', | |
| 78 | - array($this, 'basic_auth_login_page') | |
| 79 | - ); | |
| 80 | - } | |
| 81 | - | |
| 70 | + | |
| 71 | + add_submenu_page( | |
| 72 | + 'basic-auth-plugin', | |
| 73 | + __('Log Page', 'easy-basic-authentication'), | |
| 74 | + __('Log Page', 'easy-basic-authentication'), | |
| 75 | + 'manage_options', | |
| 76 | + 'basic-auth-login', | |
| 77 | + array($this, 'basic_auth_login_page') | |
| 78 | + ); | |
| 82 | 79 | } |
| 83 | 80 | |
| 84 | 81 | public function basic_auth_login_page() { |
| 85 | 82 | if(array_key_exists('clear_mode',$_POST)) { |
| @@ -98,9 +95,8 @@ | ||
| 98 | 95 | public function basic_auth_plugin_settings_init() { |
| 99 | 96 | register_setting( 'basic-auth-plugin-settings', 'basic_auth_plugin_admin_enable' ); |
| 100 | 97 | register_setting( 'basic-auth-plugin-settings', 'basic_auth_plugin_enable' ); |
| 101 | 98 | register_setting( 'basic-auth-plugin-settings', 'basic_auth_plugin_username' ); |
| 102 | - register_setting( 'basic-auth-plugin-settings', 'basic_auth_plugin_admin_log_enable' ); | |
| 103 | 99 | |
| 104 | 100 | add_settings_section( |
| 105 | 101 | 'basic-auth-plugin-section', |
| 106 | 102 | __('Configurations for Easy Basic Authentication', 'easy-basic-authentication'), |
| @@ -138,16 +134,8 @@ | ||
| 138 | 134 | array($this,'basic_auth_plugin_password_cb'), |
| 139 | 135 | 'basic-auth-plugin-settings', |
| 140 | 136 | 'basic-auth-plugin-section' |
| 141 | 137 | ); |
| 142 | - | |
| 143 | - add_settings_field( | |
| 144 | - 'basic-auth-plugin-admin-log-enable', | |
| 145 | - __('Enable access logs', 'easy-basic-authentication'), | |
| 146 | - array($this,'basic_auth_plugin_admin_log_enable_cb'), | |
| 147 | - 'basic-auth-plugin-settings', | |
| 148 | - 'basic-auth-plugin-section' | |
| 149 | - ); | |
| 150 | 138 | |
| 151 | 139 | } |
| 152 | 140 | |
| 153 | 141 | public function basic_auth_plugin_section_cb() { |
| @@ -184,16 +172,9 @@ | ||
| 184 | 172 | <input type="password" name="basic_auth_plugin_password" value="" placeholder="<?php echo $password; ?>"> |
| 185 | 173 | <?php |
| 186 | 174 | } |
| 187 | 175 | |
| 188 | - public function basic_auth_plugin_admin_log_enable_cb() { | |
| 189 | - $enable = get_option( 'basic_auth_plugin_admin_log_enable' ); | |
| 190 | - ?> | |
| 191 | - <input type="checkbox" name="basic_auth_plugin_admin_log_enable" value="1" <?php checked( $enable, 1 ); ?>> | |
| 192 | - <?php | |
| 193 | - } | |
| 194 | 176 | |
| 195 | - | |
| 196 | 177 | public function basic_auth_plugin_save_settings() { |
| 197 | 178 | if ( isset( $_POST['eba_submit'] ) ) { |
| 198 | 179 | $admin_enable = isset( $_POST['basic_auth_plugin_admin_enable'] ) ? 1 : 0; |
| 199 | 180 | $enable = isset( $_POST['basic_auth_plugin_enable'] ) ? 1 : 0; |
| @@ -198,14 +179,12 @@ | ||
| 198 | 179 | $admin_enable = isset( $_POST['basic_auth_plugin_admin_enable'] ) ? 1 : 0; |
| 199 | 180 | $enable = isset( $_POST['basic_auth_plugin_enable'] ) ? 1 : 0; |
| 200 | 181 | $username = sanitize_text_field( $_POST['basic_auth_plugin_username'] ); |
| 201 | 182 | $password = sanitize_text_field( $_POST['basic_auth_plugin_password'] ); |
| 202 | - $log_enable = isset( $_POST['basic_auth_plugin_admin_log_enable'] ) ? 1 : 0; | |
| 203 | 183 | |
| 204 | 184 | update_option( 'basic_auth_plugin_admin_enable', $admin_enable ); |
| 205 | 185 | update_option( 'basic_auth_plugin_enable', $enable ); |
| 206 | 186 | update_option( 'basic_auth_plugin_username', $username ); |
| 207 | - update_option( 'basic_auth_plugin_admin_log_enable', $log_enable ); | |
| 208 | 187 | |
| 209 | 188 | if ( ! empty( $password ) ) { |
| 210 | 189 | $hashed_password = wp_hash_password( $password ); |
| 211 | 190 | update_option( 'basic_auth_plugin_password', $hashed_password ); |
| @@ -213,27 +192,21 @@ | ||
| 213 | 192 | } |
| 214 | 193 | } |
| 215 | 194 | |
| 216 | 195 | public function basic_auth_log_failed_access() { |
| 217 | - if($this->log_is_enabled()) { | |
| 218 | - $logs = get_option('basic_auth_failure_logs', array()); | |
| 196 | + $logs = get_option('basic_auth_failure_logs', array()); | |
| 219 | 197 | |
| 220 | - $log_entry = array( | |
| 221 | - 'id' => uniqid(), | |
| 222 | - 'ip' => $_SERVER['REMOTE_ADDR'], | |
| 223 | - 'data' => current_time('mysql'), | |
| 224 | - 'browser' => $_SERVER['HTTP_USER_AGENT'], | |
| 225 | - 'viewed' => 0 | |
| 226 | - ); | |
| 198 | + $log_entry = array( | |
| 199 | + 'id' => uniqid(), | |
| 200 | + 'ip' => $_SERVER['REMOTE_ADDR'], | |
| 201 | + 'data' => current_time('mysql'), | |
| 202 | + 'browser' => $_SERVER['HTTP_USER_AGENT'], | |
| 203 | + 'viewed' => 0 | |
| 204 | + ); | |
| 227 | 205 | |
| 228 | - $log_entry = apply_filters('basic_auth_single_log_entry', $log_entry); | |
| 206 | + $logs[] = $log_entry; | |
| 229 | 207 | |
| 230 | - $logs[] = $log_entry; | |
| 231 | - | |
| 232 | - $logs = apply_filters('basic_auth_logs_entry', $logs); | |
| 233 | - | |
| 234 | - update_option('basic_auth_failure_logs', $logs); | |
| 235 | - } | |
| 208 | + update_option('basic_auth_failure_logs', $logs); | |
| 236 | 209 | } |
| 237 | 210 | |
| 238 | 211 | public function basic_auth_get_log_failed_access() { |
| 239 | 212 | return get_option('basic_auth_failure_logs', array()); |
| @@ -260,10 +233,6 @@ | ||
| 260 | 233 | $entry['viewed'] = 1; |
| 261 | 234 | } |
| 262 | 235 | update_option('basic_auth_failure_logs', $logs); |
| 263 | 236 | } |
| 264 | - | |
| 265 | - public function log_is_enabled() { | |
| 266 | - return get_option( 'basic_auth_plugin_admin_log_enable' ); | |
| 267 | - } | |
| 268 | - | |
| 237 | + | |
| 269 | 238 | } |