Completed
Push — master ( 2cc4d6...bb97fd )
by Sébastien
03:24
created

config.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * COPS (Calibre OPDS PHP Server) class file
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Sébastien Lucas <[email protected]>
7
 */
8
9
require_once dirname(__FILE__) . '/vendor/autoload.php';
10
require dirname(__FILE__) . '/config_default.php';
11 View Code Duplication
if (file_exists(dirname(__FILE__) . '/config_local.php') && (php_sapi_name() !== 'cli')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
    require dirname(__FILE__) . '/config_local.php';
13
}
14
15
$remote_user = array_key_exists('PHP_AUTH_USER', $_SERVER) ? $_SERVER['PHP_AUTH_USER'] : '';
16
// Clean username, only allow a-z, A-Z, 0-9, -_ chars
17
$remote_user = preg_replace( '/[^a-zA-Z0-9_-]/', '', $remote_user);
18
$user_config_file = 'config_local.' . $remote_user . '.php';
19 View Code Duplication
if (file_exists(dirname(__FILE__) . '/' . $user_config_file) && (php_sapi_name() !== 'cli')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    require_once dirname(__FILE__) . '/' . $user_config_file;
21
}
22
23
if(!is_null($config['cops_basic_authentication']) &&
24
    is_array($config['cops_basic_authentication']))
25
{
26
    if (!isset($_SERVER['PHP_AUTH_USER']) ||
27
        (isset($_SERVER['PHP_AUTH_USER']) &&
28
        ($_SERVER['PHP_AUTH_USER']!=$config['cops_basic_authentication']['username'] ||
29
        $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password'])))
30
    {
31
        header('WWW-Authenticate: Basic realm="COPS Authentication"');
32
        header('HTTP/1.0 401 Unauthorized');
33
        echo 'This site is password protected';
34
        exit;
35
    }
36
}
37