PluginProbe
Easy Basic Authentication – Add basic auth to site or admin area / 3.4
Easy Basic Authentication – Add basic auth to site or admin area v3.4
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 +34 -30 1.83.4 View file →
@@ -1,9 +1,10 @@
1 -<?php
1 +<?php
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' )){
@@ -24,9 +26,9 @@
24 26
25 27 if(get_option( 'basic_auth_plugin_enable' ) && get_option( 'basic_auth_plugin_admin_enable' )){
26 28 add_action( 'init', array($this,'basic_auth_root') );
27 29 }
28 -
30 +
29 31 add_action( 'admin_menu', array($this,'basic_auth_plugin_menu' ));
30 32 add_action( 'admin_init', array($this->form,'basic_auth_plugin_settings_init' ));
31 33
32 34 add_action('admin_init', function () {
@@ -32,44 +34,46 @@
32 34 add_action('admin_init', function () {
33 35 $post_data = $_POST;
34 36 $this->form->basic_auth_plugin_save_settings($post_data);
35 37 });
36 -
38 +
37 39 }
38 40
39 - public function basic_auth_root() {
40 - $user = get_option( 'basic_auth_plugin_username' );
41 - $pass = get_option( 'basic_auth_plugin_password' );
42 -
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 -
41 + public function basic_auth_root()
42 + {
43 + $user = get_option('basic_auth_plugin_username');
44 + $pass = get_option('basic_auth_plugin_password');
45 +
46 + if ($this->whiteListChecker()) {
47 + return;
48 + }
49 +
50 + if (!isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['HTTP_AUTHORIZATION'])) {
51 + if (stripos($_SERVER['HTTP_AUTHORIZATION'], 'basic') === 0) {
52 + list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
53 + }
54 + }
55 +
56 + if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
57 + $_SERVER['PHP_AUTH_USER'] !== $user ||
58 + !wp_check_password(wp_unslash($_SERVER['PHP_AUTH_PW']), $pass)) {
46 59 $this->do_exit(true);
47 60 }
48 61 }
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 - }
62 +
63 + public function whiteListChecker() {
64 + if (isset($_SERVER['REMOTE_ADDR']) && in_array($_SERVER['REMOTE_ADDR'], $this->getWhiteList())) {
65 + return true;
66 + }
59 67 }
60 -
68 +
61 69 public function do_exit($admin_area = false) {
62 70
63 - if (in_array($_SERVER['REMOTE_ADDR'], $this->getWhiteList())) {
64 - return;
65 - }
66 71 $this->basic_auth_action_failed_access();
67 72 do_action('basic_auth_before_401');
68 73
69 74 if($admin_area) {
70 75 do_action('basic_auth_before_401_admin_area');
71 -
72 76 header( 'WWW-Authenticate: Basic realm="My Website"' );
73 77 header( 'HTTP/1.0 401 Unauthorized' );
74 78 exit;
75 79 } else {
@@ -84,10 +88,10 @@
84 88 }
85 89
86 90 public function basic_auth_plugin_menu() {
87 91 add_menu_page(
88 - __('Configurations for Easy Basic Authentication', 'easy-basic-authentication'),
89 - __('Easy Basic A.', 'easy-basic-authentication'),
92 + __('Configurations for Easy Basic Authentication', 'easy-basic-authentication'),
93 + __('Easy Basic A.', 'easy-basic-authentication'),
90 94 'manage_options',
91 95 'basic-auth-plugin',
92 96 array($this->form, 'basic_auth_plugin_settings_page'),
93 97 'dashicons-lock'
@@ -94,10 +98,10 @@
94 98 );
95 99 if($this->log->is_enabled()) {
96 100 $this->log->getMenu();
97 101 }
98 - }
99 -
102 + }
103 +
100 104 public function basic_auth_action_failed_access() {
101 105 if($this->log->is_enabled()) {
102 106 $this->log->update_status($_SERVER);
103 107 }