mirror of
https://github.com/silverstripe/silverstripe-environmentcheck
synced 2024-10-22 17:05:40 +02:00
Merge pull request #53 from creative-commoners/pulls/2.0/fix-basic-auth
FIX Update BasicAuth call signature, remove deprecated code and update getenv
This commit is contained in:
commit
1ce832f859
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1,6 +1,7 @@
|
||||
/tests export-ignore
|
||||
/docs export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/codecov.yml export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
|
@ -12,6 +12,8 @@ matrix:
|
||||
env: DB=PGSQL PHPUNIT_TEST=1
|
||||
- php: 7.1
|
||||
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
|
||||
- php: 7.2
|
||||
env: DB=MYSQL PHPUNIT_TEST=1
|
||||
|
||||
before_script:
|
||||
- phpenv rehash
|
||||
@ -25,7 +27,7 @@ before_script:
|
||||
script:
|
||||
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
|
||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
|
||||
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src/ tests/ ; fi
|
||||
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi
|
||||
|
||||
after_success:
|
||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
||||
|
91
_config.php
91
_config.php
@ -1,23 +1,70 @@
|
||||
<?php
|
||||
|
||||
// use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
|
||||
|
||||
// // These power dev/health, which can be used by load balancers and other such systems
|
||||
// EnvironmentCheckSuite::register('health', 'DatabaseCheck');
|
||||
|
||||
// // These power dev/check, which is used for diagnostics and for deployment
|
||||
// EnvironmentCheckSuite::register('check', 'DatabaseCheck("Member")', "Is the database accessible?");
|
||||
// EnvironmentCheckSuite::register('check', 'URLCheck("")', "Is the homepage accessible?");
|
||||
|
||||
// EnvironmentCheckSuite::register('check', 'HasFunctionCheck("curl_init")', "Does PHP have CURL support?");
|
||||
// EnvironmentCheckSuite::register('check', 'HasFunctionCheck("imagecreatetruecolor")', "Does PHP have GD2 support?");
|
||||
// EnvironmentCheckSuite::register('check', 'HasFunctionCheck("xml_set_object")', "Does PHP have XML support?");
|
||||
// EnvironmentCheckSuite::register('check', 'HasFunctionCheck("token_get_all")', "Does PHP have tokenizer support?");
|
||||
// EnvironmentCheckSuite::register('check', 'HasFunctionCheck("iconv")', "Does PHP have iconv support?");
|
||||
// EnvironmentCheckSuite::register('check', 'HasFunctionCheck("hash")', "Does PHP have hash support?");
|
||||
// EnvironmentCheckSuite::register('check', 'HasFunctionCheck("session_start")', "Does PHP have session support?");
|
||||
// EnvironmentCheckSuite::register('check', 'HasClassCheck("DOMDocument")', "Does PHP have DOMDocument support?");
|
||||
|
||||
// EnvironmentCheckSuite::register('check', 'FileWriteableCheck("assets")', "Is assets/ writeable?");
|
||||
// EnvironmentCheckSuite::register('check', 'FileWriteableCheck("' . TEMP_FOLDER . '")', "Is the temp folder writeable?");
|
||||
|
||||
//
|
||||
//use SilverStripe\EnvironmentCheck\EnvironmentCheckSuite;
|
||||
//
|
||||
//// These power dev/health, which can be used by load balancers and other such systems
|
||||
//EnvironmentCheckSuite::register('health', 'DatabaseCheck');
|
||||
//
|
||||
//// These power dev/check, which is used for diagnostics and for deployment
|
||||
//EnvironmentCheckSuite::register('check', 'DatabaseCheck("Member")', "Is the database accessible?");
|
||||
//EnvironmentCheckSuite::register('check', 'URLCheck("")', "Is the homepage accessible?");
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasFunctionCheck("curl_init")',
|
||||
// "Does PHP have CURL support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasFunctionCheck("imagecreatetruecolor")',
|
||||
// "Does PHP have GD2 support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasFunctionCheck("xml_set_object")',
|
||||
// "Does PHP have XML support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasFunctionCheck("token_get_all")',
|
||||
// "Does PHP have tokenizer support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasFunctionCheck("iconv")',
|
||||
// "Does PHP have iconv support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasFunctionCheck("hash")',
|
||||
// "Does PHP have hash support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasFunctionCheck("session_start")',
|
||||
// "Does PHP have session support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'HasClassCheck("DOMDocument")',
|
||||
// "Does PHP have DOMDocument support?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'FileWriteableCheck("assets")',
|
||||
// "Is assets/ writeable?"
|
||||
//);
|
||||
//
|
||||
//EnvironmentCheckSuite::register(
|
||||
// 'check',
|
||||
// 'FileWriteableCheck("' . TEMP_FOLDER . '")',
|
||||
// "Is the temp folder writeable?"
|
||||
//);
|
||||
|
@ -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'
|
||||
|
@ -15,10 +15,10 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "^4.0"
|
||||
"silverstripe/framework": "^4.0",
|
||||
"silverstripe/versioned": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"silverstripe/versioned": "^1.0",
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
|
9
phpcs.xml.dist
Normal file
9
phpcs.xml.dist
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset name="SilverStripe">
|
||||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
||||
|
||||
<rule ref="PSR2" >
|
||||
<!-- Current exclusions -->
|
||||
<exclude name="PSR1.Methods.CamelCapsMethodName" />
|
||||
</rule>
|
||||
</ruleset>
|
@ -10,9 +10,13 @@ use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
||||
* it can still fail if the URL in question is requested by the client, e.g. through an iframe.
|
||||
*
|
||||
* Requires curl to present, so ensure to check it before with the following:
|
||||
* <code>EnvironmentCheckSuite::register('check', 'HasFunctionCheck("curl_init")', "Does PHP have CURL support?");</code>
|
||||
*
|
||||
* @package environmentcheck
|
||||
* <code>
|
||||
* EnvironmentCheckSuite::register(
|
||||
* 'check',
|
||||
* 'HasFunctionCheck("curl_init")',
|
||||
* "Does PHP have CURL support?"
|
||||
* );
|
||||
* </code>
|
||||
*/
|
||||
class ExternalURLCheck implements EnvironmentCheck
|
||||
{
|
||||
|
@ -3,28 +3,40 @@
|
||||
namespace SilverStripe\EnvironmentCheck\Checks;
|
||||
|
||||
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
|
||||
use SilverStripe\ORM\Versioning\Versioned;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
* Checks for the accessibility and file type validation of one or more files or folders.
|
||||
*
|
||||
* Examples:
|
||||
* // Checks /assets/calculator_files has .json files and all files are valid json files.
|
||||
* EnvironmentCheckSuite::register('check', 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/*.json",
|
||||
* "jsonValidate", '.FileAccessibilityAndValidationCheck::CHECK_ALL.')', 'Check a json file exist and are all valid json files'
|
||||
* EnvironmentCheckSuite::register(
|
||||
* 'check',
|
||||
* 'FileAccessibilityAndValidationCheck(
|
||||
* "' . BASE_PATH . '/assets/calculator_files/*.json",
|
||||
* "jsonValidate",
|
||||
* '.FileAccessibilityAndValidationCheck::CHECK_ALL.'
|
||||
* )',
|
||||
* 'Check a json file exist and are all valid json files'
|
||||
* );
|
||||
*
|
||||
* // Checks /assets/calculator_files/calculator.json exists and is valid json file.
|
||||
* EnvironmentCheckSuite::register('check', 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/calculator.json",
|
||||
* "jsonValidate", '.FileAccessibilityAndValidationCheck::CHECK_SINGLE.')', 'Check a calculator.json exists and is valid json file'
|
||||
* EnvironmentCheckSuite::register(
|
||||
* 'check',
|
||||
* 'FileAccessibilityAndValidationCheck(
|
||||
* "' . BASE_PATH . '/assets/calculator_files/calculator.json",
|
||||
* "jsonValidate",
|
||||
* '.FileAccessibilityAndValidationCheck::CHECK_SINGLE.'
|
||||
* )',
|
||||
* 'Check a calculator.json exists and is valid json file'
|
||||
* );
|
||||
*
|
||||
* // Check only existence
|
||||
* EnvironmentCheckSuite::register('check', 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/calculator.json")',
|
||||
* 'Check a calculator.json exists only'
|
||||
* EnvironmentCheckSuite::register(
|
||||
* 'check',
|
||||
* 'FileAccessibilityAndValidationCheck("' . BASE_PATH . '/assets/calculator_files/calculator.json")',
|
||||
* 'Check a calculator.json exists only'
|
||||
* );
|
||||
*
|
||||
* @package environmentcheck
|
||||
*/
|
||||
class FileAccessibilityAndValidationCheck implements EnvironmentCheck
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user