mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
FIX Update BasicAuth call signature, remove deprecated code and update getenv
This commit is contained in:
parent
227b64cbcc
commit
bf5076f2df
@ -6,3 +6,9 @@ SilverStripe\Control\Director:
|
|||||||
'health/check': 'Silverstripe\EnvironmentCheck\Controllers\DevHealthController'
|
'health/check': 'Silverstripe\EnvironmentCheck\Controllers\DevHealthController'
|
||||||
'dev/check/$Suite': 'Silverstripe\EnvironmentCheck\Controllers\DevCheckController'
|
'dev/check/$Suite': 'Silverstripe\EnvironmentCheck\Controllers\DevCheckController'
|
||||||
|
|
||||||
|
SilverStripe\Dev\DevelopmentAdmin:
|
||||||
|
registered_controllers:
|
||||||
|
check:
|
||||||
|
controller: Silverstripe\EnvironmentCheck\Controllers\DevCheckController
|
||||||
|
links:
|
||||||
|
check: 'Run registered environment checks and display their status'
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace SilverStripe\EnvironmentCheck\Controllers;
|
namespace SilverStripe\EnvironmentCheck\Controllers;
|
||||||
|
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
use SilverStripe\Control\HTTPResponse_Exception;
|
||||||
use SilverStripe\EnvironmentCheck\EnvironmentChecker;
|
use SilverStripe\EnvironmentCheck\EnvironmentChecker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,10 +8,6 @@ use SilverStripe\Core\Config\Configurable;
|
|||||||
use SilverStripe\Core\Extensible;
|
use SilverStripe\Core\Extensible;
|
||||||
use SilverStripe\Core\Injector\Injectable;
|
use SilverStripe\Core\Injector\Injectable;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
|
||||||
use SilverStripe\ORM\ArrayList;
|
|
||||||
use SilverStripe\View\ArrayData;
|
|
||||||
use SilverStripe\View\ViewableData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a suite of environment checks.
|
* Represents a suite of environment checks.
|
||||||
@ -77,7 +73,6 @@ class EnvironmentCheckSuite
|
|||||||
*/
|
*/
|
||||||
public function __construct($suiteName)
|
public function __construct($suiteName)
|
||||||
{
|
{
|
||||||
$this->constructExtensions();
|
|
||||||
if (empty($this->config()->registered_suites[$suiteName])) {
|
if (empty($this->config()->registered_suites[$suiteName])) {
|
||||||
// Not registered via config system, but it still may be configured later via self::register.
|
// Not registered via config system, but it still may be configured later via self::register.
|
||||||
return;
|
return;
|
||||||
|
@ -9,14 +9,13 @@ use SilverStripe\Control\Email\Email;
|
|||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
use SilverStripe\Control\HTTPResponse_Exception;
|
use SilverStripe\Control\HTTPResponse_Exception;
|
||||||
use SilverStripe\Control\RequestHandler;
|
use SilverStripe\Control\RequestHandler;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Environment;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Dev\Deprecation;
|
use SilverStripe\Dev\Deprecation;
|
||||||
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
|
||||||
use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
|
|
||||||
use SilverStripe\Security\BasicAuth;
|
use SilverStripe\Security\BasicAuth;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
use SilverStripe\Security\Permission;
|
use SilverStripe\Security\Permission;
|
||||||
|
use SilverStripe\Security\Security;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an interface for checking the given EnvironmentCheckSuite.
|
* Provides an interface for checking the given EnvironmentCheckSuite.
|
||||||
@ -102,12 +101,14 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public function init($permission = 'ADMIN')
|
public function init($permission = 'ADMIN')
|
||||||
{
|
{
|
||||||
// if the environment supports it, provide a basic auth challenge and see if it matches configured credentials
|
// if the environment supports it, provide a basic auth challenge and see if it matches configured credentials
|
||||||
if (getenv('ENVCHECK_BASICAUTH_USERNAME') && getenv('ENVCHECK_BASICAUTH_PASSWORD')) {
|
if (Environment::getEnv('ENVCHECK_BASICAUTH_USERNAME')
|
||||||
|
&& Environment::getEnv('ENVCHECK_BASICAUTH_PASSWORD')
|
||||||
|
) {
|
||||||
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
|
||||||
// authenticate the input user/pass with the configured credentials
|
// authenticate the input user/pass with the configured credentials
|
||||||
if (!(
|
if (!(
|
||||||
$_SERVER['PHP_AUTH_USER'] == getenv('ENVCHECK_BASICAUTH_USERNAME')
|
$_SERVER['PHP_AUTH_USER'] == Environment::getEnv('ENVCHECK_BASICAUTH_USERNAME')
|
||||||
&& $_SERVER['PHP_AUTH_PW'] == getenv('ENVCHECK_BASICAUTH_PASSWORD')
|
&& $_SERVER['PHP_AUTH_PW'] == Environment::getEnv('ENVCHECK_BASICAUTH_PASSWORD')
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
$response = new HTTPResponse(null, 401);
|
$response = new HTTPResponse(null, 401);
|
||||||
@ -143,11 +144,11 @@ class EnvironmentChecker extends RequestHandler
|
|||||||
public function canAccess($member = null, $permission = 'ADMIN')
|
public function canAccess($member = null, $permission = 'ADMIN')
|
||||||
{
|
{
|
||||||
if (!$member) {
|
if (!$member) {
|
||||||
$member = Member::currentUser();
|
$member = Security::getCurrentUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$member) {
|
if (!$member) {
|
||||||
$member = BasicAuth::requireLogin('Environment Checker', $permission, false);
|
$member = BasicAuth::requireLogin($this->getRequest(), 'Environment Checker', $permission, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We allow access to this controller regardless of live-status or ADMIN permission only
|
// We allow access to this controller regardless of live-status or ADMIN permission only
|
||||||
|
Loading…
Reference in New Issue
Block a user