diff --git a/_config/routes.yml b/_config/routes.yml index c7f53fb..e2c2bed 100644 --- a/_config/routes.yml +++ b/_config/routes.yml @@ -6,3 +6,9 @@ SilverStripe\Control\Director: 'health/check': 'Silverstripe\EnvironmentCheck\Controllers\DevHealthController' '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' diff --git a/src/Controllers/DevCheckController.php b/src/Controllers/DevCheckController.php index 6b53384..4e0d346 100644 --- a/src/Controllers/DevCheckController.php +++ b/src/Controllers/DevCheckController.php @@ -3,6 +3,8 @@ namespace SilverStripe\EnvironmentCheck\Controllers; use SilverStripe\Control\Controller; +use SilverStripe\Control\HTTPRequest; +use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\EnvironmentCheck\EnvironmentChecker; /** diff --git a/src/EnvironmentCheckSuite.php b/src/EnvironmentCheckSuite.php index 4807ef4..0fe8dea 100644 --- a/src/EnvironmentCheckSuite.php +++ b/src/EnvironmentCheckSuite.php @@ -8,10 +8,6 @@ use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injectable; 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. @@ -77,7 +73,6 @@ class EnvironmentCheckSuite */ public function __construct($suiteName) { - $this->constructExtensions(); if (empty($this->config()->registered_suites[$suiteName])) { // Not registered via config system, but it still may be configured later via self::register. return; diff --git a/src/EnvironmentChecker.php b/src/EnvironmentChecker.php index 96177c3..63617aa 100644 --- a/src/EnvironmentChecker.php +++ b/src/EnvironmentChecker.php @@ -9,14 +9,13 @@ use SilverStripe\Control\Email\Email; use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\RequestHandler; -use SilverStripe\Core\Config\Config; +use SilverStripe\Core\Environment; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\Deprecation; -use SilverStripe\EnvironmentCheck\EnvironmentCheck; -use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite; use SilverStripe\Security\BasicAuth; use SilverStripe\Security\Member; use SilverStripe\Security\Permission; +use SilverStripe\Security\Security; /** * Provides an interface for checking the given EnvironmentCheckSuite. @@ -102,12 +101,14 @@ class EnvironmentChecker extends RequestHandler public function init($permission = 'ADMIN') { // 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'])) { // authenticate the input user/pass with the configured credentials if (!( - $_SERVER['PHP_AUTH_USER'] == getenv('ENVCHECK_BASICAUTH_USERNAME') - && $_SERVER['PHP_AUTH_PW'] == getenv('ENVCHECK_BASICAUTH_PASSWORD') + $_SERVER['PHP_AUTH_USER'] == Environment::getEnv('ENVCHECK_BASICAUTH_USERNAME') + && $_SERVER['PHP_AUTH_PW'] == Environment::getEnv('ENVCHECK_BASICAUTH_PASSWORD') ) ) { $response = new HTTPResponse(null, 401); @@ -143,11 +144,11 @@ class EnvironmentChecker extends RequestHandler public function canAccess($member = null, $permission = 'ADMIN') { if (!$member) { - $member = Member::currentUser(); + $member = Security::getCurrentUser(); } 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