Completed
Push — master ( 221921...32345e )
by Bhanu
58:02
created

functions.inc.php ➔ auth_check()   D

Complexity

Conditions 9
Paths 4

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

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