PluginProbe
Easy Basic Authentication – Add basic auth to site or admin area / 1.3.2
Easy Basic Authentication – Add basic auth to site or admin area v1.3.2
trunk 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.7.1 1.8 1.8.1 1.9 All 50 releases
← All changes | class/easy-basic-authentication-class.php +79 -5 1.11.3.2 View file →
@@ -27,8 +27,11 @@
27 27 $pass = get_option( 'basic_auth_plugin_password' );
28 28
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 +
32 + $this->basic_auth_log_failed_access();
33 +
31 34 header( 'WWW-Authenticate: Basic realm="My Website"' );
32 35 header( 'HTTP/1.0 401 Unauthorized' );
33 36 echo 'Autenticazione richiesta';
34 37 exit;
@@ -40,24 +43,51 @@
40 43 $pass = get_option( 'basic_auth_plugin_password' );
41 44
42 45 if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) ||
43 46 $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) {
47 +
48 + $this->basic_auth_log_failed_access();
49 +
44 50 header( 'HTTP/1.1 401 Unauthorized' );
45 51 header( 'WWW-Authenticate: Basic realm="Admin Area"' );
46 52 exit;
47 - }
53 + }
48 54 }
49 55
50 56
51 57 public function basic_auth_plugin_menu() {
52 - add_options_page(
58 + ini_set('display_errors', 1);
59 +ini_set('display_startup_errors', 1);
60 +error_reporting(E_ALL);
61 + $access_count = $this->basic_auth_count_not_viewed_log_failed_access();
62 + add_menu_page(
53 63 __('Configurations for Easy Basic Authentication', 'easy-basic-authentication'),
54 - __('Easy Basic Authentication', '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>',
55 65 'manage_options',
56 66 'basic-auth-plugin',
57 - array($this,'basic_auth_plugin_settings_page')
67 + array($this, 'basic_auth_plugin_settings_page'),
68 + 'dashicons-lock'
58 69 );
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 + );
59 79 }
80 +
81 + public function basic_auth_login_page() {
82 + if(array_key_exists('clear_mode',$_POST)) {
83 + update_option('basic_auth_failure_logs', array());
84 + }
85 + $user_log_data = array_reverse($this->basic_auth_get_log_failed_access());
86 + include plugin_dir_path( __FILE__ ) . '../template/log_page.php';
87 + $this->update_view();
88 + }
89 +
60 90
61 91 public function basic_auth_plugin_settings_page() {
62 92 include plugin_dir_path( __FILE__ ) . '../template/settings_page.php';
63 93 }
@@ -104,8 +134,9 @@
104 134 array($this,'basic_auth_plugin_password_cb'),
105 135 'basic-auth-plugin-settings',
106 136 'basic-auth-plugin-section'
107 137 );
138 +
108 139 }
109 140
110 141 public function basic_auth_plugin_section_cb() {
111 142 echo __('Configure basic authentication', 'easy-basic-authentication');
@@ -159,6 +190,49 @@
159 190 update_option( 'basic_auth_plugin_password', $hashed_password );
160 191 }
161 192 }
162 193 }
163 -
194 +
195 + public function basic_auth_log_failed_access() {
196 + $logs = get_option('basic_auth_failure_logs', array());
197 +
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 + );
205 +
206 + $logs[] = $log_entry;
207 +
208 + update_option('basic_auth_failure_logs', $logs);
209 + }
210 +
211 + public function basic_auth_get_log_failed_access() {
212 + return get_option('basic_auth_failure_logs', array());
213 + }
214 +
215 + public function basic_auth_count_log_failed_access() {
216 + return count($this->basic_auth_get_log_failed_access());
217 + }
218 +
219 + public function basic_auth_not_viewed_log_failed_access() {
220 + $return_not_viewed = array_filter($this->basic_auth_get_log_failed_access(), function ($entry) {
221 + return isset($entry['viewed']) && $entry['viewed'] === 0;
222 + });
223 + return $return_not_viewed;
224 + }
225 +
226 + public function basic_auth_count_not_viewed_log_failed_access() {
227 + return count($this->basic_auth_not_viewed_log_failed_access());
228 + }
229 +
230 + public function update_view() {
231 + $logs = get_option('basic_auth_failure_logs', array());
232 + foreach ($logs as &$entry) {
233 + $entry['viewed'] = 1;
234 + }
235 + update_option('basic_auth_failure_logs', $logs);
236 + }
237 +
164 238 }