changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth / userdb_anonymous.php
1 <?php
2
3 /*
4    "Anonymous" login (like in FTP). Users can login using their email
5    address as password. In this implementation we do not depend upon
6    the username being "anonymous" (any string will do).
7
8    This plugin itself implements a partial ["auth_query"] plugin, which
9    evaluates the HTTP From: request header (see RFC2616 section 14.22),
10    which however isn't supported by the mainstream browsers. The value
11    of this header is already evealuated by the ewiki core script and
12    stored into the {author} field - if you use this plugin or not. The
13    only difference is, that the From: header now grants edit/ permission
14    in EWIKI_PROTECTED_MODE.
15 */
16
17 $ewiki_config["login_notice"] = "Anonymous login (use your email address as password).";
18 $ewiki_config["http_auth_add"] = "ANONYMOUS";
19
20
21 define("EWIKI_AUTH_ANONYMOUS_RING", 2);     // permission ring level
22 define("EWIKI_AUTH_ANONYMOUS_VERIFY", 0);   // verify given email address
23
24
25 $ewiki_plugins["auth_userdb"][] = "ewiki_auth_userdb_anonymous";
26
27
28
29 function ewiki_auth_userdb_anonymous($username, $password) {
30
31    global $ewiki_author;
32
33    #-- get params
34    if (!$name = $username) {
35       $name = "anonymous";
36    }
37    if (strpos($password, "@")) {
38       $email = trim($password);
39    }
40    elseif (strpos($username, "@")) {
41       $email = trim($username);
42       $name = "anonymous";
43    }
44    else {
45       $email = "";
46    }
47
48    #-- HTTP header field "From: joe@example.com"
49    if (empty($email)) {
50       $email = trim($_SERVER["HTTP_FROM"]);
51    }
52
53    #-- check for valid address (the-non-4000-chars-regex-check)
54    $c = EWIKI_CHARS;
55    if ($email && preg_match("/^[-!%&~+.$c]+@([-$c]{2,}\.)+[-$c]{2,9}$/i", $email)) {
56
57       return(array($password, EWIKI_AUTH_ANONYMOUS_RING, $ewiki_author="anonymous|$email"));
58    }
59
60    return(false);   
61 }
62
63
64 ?>