From d124f6fc95bcb4d6dfbfbb2aa9d4a343f3691502 Mon Sep 17 00:00:00 2001 From: Matthew Sigley Date: Tue, 3 Apr 2018 16:36:47 -0400 Subject: [PATCH] Added HTTP authentication --- index.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 28239c5..1edd867 100644 --- a/index.php +++ b/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')