Skip to content

Commit

Permalink
FIX Update BasicAuth call signature, remove deprecated code and updat…
Browse files Browse the repository at this point in the history
…e getenv
  • Loading branch information
robbieaverill committed Dec 13, 2017
1 parent 227b64c commit bf5076f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 6 additions & 0 deletions _config/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 2 additions & 0 deletions src/Controllers/DevCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
5 changes: 0 additions & 5 deletions src/EnvironmentCheckSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
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.
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions src/EnvironmentChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
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.
Expand Down Expand Up @@ -102,12 +101,14 @@ public function __construct($checkSuiteName, $title)
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);
Expand Down Expand Up @@ -143,11 +144,11 @@ public function init($permission = 'ADMIN')
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
Expand Down

0 comments on commit bf5076f

Please sign in to comment.