functions.inc.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. function auth_ok(){
  3. return isset($_SESSION["authenticated"]) && $_SESSION["authenticated"] === true;
  4. }
  5. function auth_get_link(){
  6. return '<a href="'.get_php_self().'?login=1">Authenticate to access this section</a>';
  7. }
  8. function get_php_self(){
  9. return isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'],''), ENT_QUOTES, 'UTF-8') : '';
  10. }
  11. // From apc.php
  12. function auth_check() {
  13. if ( isset($_GET["login"]) && DOMPDF_ADMIN_PASSWORD == "password" ) {
  14. $_SESSION["auth_message"] = "The password must be changed in 'dompdf_config.custom.inc.php'";
  15. return false;
  16. }
  17. else {
  18. $_SESSION["auth_message"] = null;
  19. }
  20. if ( isset($_GET["login"]) || isset($_SERVER["PHP_AUTH_USER"]) ) {
  21. if (!isset($_SERVER["PHP_AUTH_USER"]) ||
  22. !isset($_SERVER["PHP_AUTH_PW"]) ||
  23. $_SERVER["PHP_AUTH_USER"] != DOMPDF_ADMIN_USERNAME ||
  24. $_SERVER["PHP_AUTH_PW"] != DOMPDF_ADMIN_PASSWORD) {
  25. $PHP_SELF = get_php_self();
  26. header('WWW-Authenticate: Basic realm="DOMPDF Login"');
  27. header('HTTP/1.0 401 Unauthorized');
  28. echo <<<EOB
  29. <html><body>
  30. <h1>Rejected!</h1>
  31. <big>Wrong Username or Password!</big><br/>&nbsp;<br/>&nbsp;
  32. <big><a href='$PHP_SELF'>Continue...</a></big>
  33. </body></html>
  34. EOB;
  35. exit;
  36. }
  37. else {
  38. $_SESSION["auth_message"] = null;
  39. $_SESSION["authenticated"] = true;
  40. return true;
  41. }
  42. }
  43. }