PluginProbe
Easy Basic Authentication – Add basic auth to site or admin area / 2.5
Easy Basic Authentication – Add basic auth to site or admin area v2.5
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 +28 -15 1.52.5 View file →
@@ -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,8 +15,9 @@
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 23 add_action( 'init', array($this,'basic_auth_admin') );
@@ -42,16 +44,9 @@
42 44
43 45 if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) ||
44 46 $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) {
45 47
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;
48 + $this->do_exit(true);
54 49 }
55 50 }
56 51
57 52 public function basic_auth_admin() {
@@ -59,20 +54,38 @@
59 54 $pass = get_option( 'basic_auth_plugin_password' );
60 55
61 56 if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) ||
62 57 $_SERVER['PHP_AUTH_USER'] != $user || !wp_check_password( $_SERVER['PHP_AUTH_PW'], $pass ) ) {
58 +
59 + $this->do_exit(true);
60 + }
61 + }
62 +
63 + public function do_exit($admin_area = false) {
64 +
65 + if (in_array($_SERVER['REMOTE_ADDR'], $this->getWhiteList())) {
66 + return;
67 + }
68 + $this->basic_auth_action_failed_access();
69 + do_action('basic_auth_before_401');
70 +
71 + if($admin_area) {
72 + do_action('basic_auth_before_401_admin_area');
63 73
64 - $this->basic_auth_action_failed_access();
65 -
66 - do_action('basic_auth_before_401');
67 -
74 + header( 'WWW-Authenticate: Basic realm="My Website"' );
75 + header( 'HTTP/1.0 401 Unauthorized' );
76 + exit;
77 + } else {
68 78 header( 'HTTP/1.1 401 Unauthorized' );
69 79 header( 'WWW-Authenticate: Basic realm="Admin Area"' );
70 80 exit;
71 - }
81 + }
72 82 }
73 -
74 -
83 +
84 + public function getWhiteList() {
85 + return get_option( 'basic_auth_plugin_whitelist' )?explode(',',get_option( 'basic_auth_plugin_whitelist' )):[];
86 + }
87 +
75 88 public function basic_auth_plugin_menu() {
76 89 add_menu_page(
77 90 __('Configurations for Easy Basic Authentication', 'easy-basic-authentication'),
78 91 __('Easy Basic A.', 'easy-basic-authentication'),