Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.3KB

  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 <sebastien@slucas.fr>
  7. */
  8. require_once 'config_default.php';
  9. if (file_exists(dirname(__FILE__) . '/config_local.php') && (php_sapi_name() !== 'cli')) {
  10. require_once 'config_local.php';
  11. }
  12. $remote_user = array_key_exists('PHP_AUTH_USER', $_SERVER) ? $_SERVER['PHP_AUTH_USER'] : '';
  13. // Clean username, only allow a-z, A-Z, 0-9, -_ chars
  14. $remote_user = preg_replace( "/[^a-zA-Z0-9_-]/", "", $remote_user);
  15. $user_config_file = 'config_local.' . $remote_user . '.php';
  16. if (file_exists(dirname(__FILE__) . '/' . $user_config_file) && (php_sapi_name() !== 'cli')) {
  17. require_once $user_config_file;
  18. }
  19. if(!is_null($config['cops_basic_authentication']) &&
  20. is_array($config['cops_basic_authentication']))
  21. {
  22. if (!isset($_SERVER['PHP_AUTH_USER']) ||
  23. (isset($_SERVER['PHP_AUTH_USER']) &&
  24. ($_SERVER['PHP_AUTH_USER']!=$config['cops_basic_authentication']['username'] ||
  25. $_SERVER['PHP_AUTH_PW'] != $config['cops_basic_authentication']['password'])))
  26. {
  27. header('WWW-Authenticate: Basic realm="COPS Authentication"');
  28. header('HTTP/1.0 401 Unauthorized');
  29. echo 'This site is password protected';
  30. exit;
  31. }
  32. }