From 144df0770c65affbc9dc7280cad3cce6d5b449a7 Mon Sep 17 00:00:00 2001 From: Sandy Pleyte Date: Sun, 28 Dec 2014 10:34:17 +0100 Subject: [PATCH] Added support for username based configs --- .gitignore | 1 + config.php | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index d438703..34bb042 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ test/text.atom cops.zip cops.sublime-* config_local.php +config_local.*.php diff --git a/config.php b/config.php index c5f1c21..2990244 100644 --- a/config.php +++ b/config.php @@ -6,9 +6,18 @@ * @author Sébastien Lucas */ - require_once 'config_default.php'; - if (file_exists(dirname(__FILE__). '/config_local.php') && (php_sapi_name() !== 'cli')) - require_once 'config_local.php'; +require_once 'config_default.php'; +if (file_exists(dirname(__FILE__) . '/config_local.php') && (php_sapi_name() !== 'cli')) { + require_once 'config_local.php'; +} + +$remote_user = array_key_exists('PHP_AUTH_USER', $_SERVER) ? $_SERVER['PHP_AUTH_USER'] : ''; +// Clean username, only allow a-z, A-Z, 0-9, -_ chars +$remote_user = preg_replace( "/[^a-zA-Z0-9_-]/", "", $remote_user); +$user_config_file = 'config_local.' . $remote_user . '.php'; +if (file_exists(dirname(__FILE__) . '/' . $user_config_file) && (php_sapi_name() !== 'cli')) { + require_once $user_config_file; +} if(!is_null($config['cops_basic_authentication']) && is_array($config['cops_basic_authentication']))