changed git call from https to git readonly
[atutor.git] / mods / wiki / fragments / funcs / auth.php
1 <?php
2
3 /*
4    http user space authentication
5    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
6    can be used with the tools/, if you don't want to fiddle
7    with the .htaccess and .htpasswd files for your webserver
8 */
9
10
11  #-- (pw array - I have such one in an external config file)
12  $passwords = (array)$passwords + array(
13 //   "user" => "password",
14 //   "u2" => "password",
15  );
16  if (defined("EWIKI_ADMIN_PW")) {
17     $passwords["admin"] = EWIKI_ADMIN_PW;
18  }
19  if (empty($passwords)) {
20     die("<h1>Restricted Access</h1>\nPlease first create an admin account in '<tt>.../fragments/funcs/auth.php</tt>' or define() the '<tt>EWIKI_ADMIN_PW</tt>' constant.");
21  }
22
23
24  #-- fetch user:password
25  if ($uu = $_SERVER["HTTP_AUTHORIZATION"]) {
26     foreach (explode(",", $uu) as $uu) {
27        $uu = trim($uu);
28        if (strtoupper(strtok($uu, " ")) == "BASIC") {
29           $uu = strtok(" ");
30           $uu = base64_decode($uu);
31           list($_a_user, $_a_password) = explode(":", $uu, 2);
32        }
33     }
34  }
35  elseif (strlen($_a_user = trim($_SERVER["PHP_AUTH_USER"]))) {
36     $_a_password = trim($_SERVER["PHP_AUTH_PW"]);
37  }
38
39  #-- check password
40  $_success = false;
41  if ($_a_user && $_a_password && ($_a_password==@$passwords[$_a_user])) {
42     $_success = $_a_user; 
43  }
44
45  #-- request HTTP Basic authentication otherwise
46  if (!$_success) {
47     header('HTTP/1.1 401 Authentication Required');
48     header('Status: 401 Authentication Required');
49     header('WWW-Authenticate: Basic realm="restricted access"');
50     die();
51  }
52
53 ?>