Added HTTP authentication
This commit is contained in:
parent
2fd6922c9e
commit
d124f6fc95
29
index.php
29
index.php
|
@ -12,7 +12,32 @@ namespace OpcacheGui;
|
|||
* @link https://github.com/amnuts/opcache-gui
|
||||
* @license MIT, http://acollington.mit-license.org/
|
||||
*/
|
||||
define('USE_AUTHENTICATION', 1);
|
||||
define('USERNAME', 'opcache');
|
||||
define('PASSWORD', 'opcache');
|
||||
|
||||
if ( USE_AUTHENTICATION == 1 ) {
|
||||
if (!empty($_SERVER['AUTH_TYPE']) && !empty($_SERVER['REMOTE_USER']) && strcasecmp($_SERVER['REMOTE_USER'], 'anonymous'))
|
||||
{
|
||||
if (!in_array(strtolower($_SERVER['REMOTE_USER']), array_map('strtolower', $user_allowed))
|
||||
&& !in_array('all', array_map('strtolower', $user_allowed)))
|
||||
{
|
||||
echo 'You are not authorised to view this page. Please contact server admin to get permission. Exiting.';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
else if ( !isset($_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ) ||
|
||||
$_SERVER['PHP_AUTH_USER'] != USERNAME || $_SERVER['PHP_AUTH_PW'] != PASSWORD ) {
|
||||
header( 'WWW-Authenticate: Basic realm="OPCACHE Log In!"' );
|
||||
header( 'HTTP/1.0 401 Unauthorized' );
|
||||
exit;
|
||||
}
|
||||
else if ( $_SERVER['PHP_AUTH_PW'] == 'opcache' )
|
||||
{
|
||||
echo "Please change the default password to get this page working. Exiting.";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* User configuration
|
||||
|
@ -200,7 +225,7 @@ class OpCacheService
|
|||
]
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
if (!empty($status['interned_strings_usage'])) {
|
||||
$overview['readable']['interned'] = [
|
||||
'buffer_size' => $this->size($status['interned_strings_usage']['buffer_size']),
|
||||
|
@ -220,7 +245,7 @@ class OpCacheService
|
|||
$config['version'],
|
||||
[
|
||||
'php' => phpversion(),
|
||||
'server' => empty($_SERVER['SERVER_SOFTWARE']) ? '' : $_SERVER['SERVER_SOFTWARE'],
|
||||
'server' => $_SERVER['SERVER_SOFTWARE'],
|
||||
'host' => (function_exists('gethostname')
|
||||
? gethostname()
|
||||
: (php_uname('n')
|
||||
|
|
Loading…
Reference in a new issue