changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth / userdb_systempasswd.php
1 <?php
2
3 /*
4   This plugin provides a user 'database' by using the internal/system
5   page "system/passwd". You first must create that page (to do so, please
6   enter a URL like "?id=edit/system/passwd" manually), and initially
7   create one user at least. Inside of this page you should list one
8   user per line, in the following format (without spaces!):
9
10      username:password:ringlevel
11      user2:password
12
13   Where the ringlevel is optional and the passwords can be in cleartext(),
14   crypt(), md5() or sha1() encoding. The privilege ("ring") levels have
15   following meaning:
16     0 - superuser
17     1 - moderator (delete, ...)
18     2 - ordinary user (edit, ...)
19     3 - browsing only (view, info, ...)
20   The level 1 is the default for everyone you'll notice inside of the
21   "system/passwd" control page. First create a superuser (ring level 0),
22   because only this person can edit _SYSTEM pages (the "system/passwd"
23   will get automatically this flag).
24
25   You'll also need:
26     - EWIKI_PROTECTED_MODE
27     - plugins/auth_perm_ring.php (or _perm_unix.php)
28     - plugins/auth_method_http.php (or another one)
29 */
30
31
32 #-- game
33 define("EWIKI_USERDB_SYSTEMPASSWD", "system/passwd");
34
35
36 #-- glue
37 $ewiki_plugins["auth_userdb"][] = "ewiki_auth_userdb_systempasswd";
38
39
40 #-- code
41 function ewiki_auth_userdb_systempasswd($username, $password) {
42
43    global $ewiki_config;
44
45    #-- bad
46    if (empty($username)) return;
47
48    #-- get pw list
49    $data = ewiki_db::GET(EWIKI_USERDB_SYSTEMPASSWD);
50
51    #-- check page flags
52    if (($data["version"]) && !($data["flags"] & EWIKI_DB_F_SYSTEM)) {
53       $data["flags"] |= EWIKI_DB_F_SYSTEM;
54       $data["version"]++;
55       ewiki_db::WRITE($data);
56    }
57    
58    #-- search user
59    $entry = array();
60    foreach (explode("\n",$data["content"]) as $line) {
61
62       $line = trim($line);
63
64       #-- user found?
65       if (strtok($line, ":") == $username) {
66
67          #-- split entry line
68          $entry = explode(":", strtok("\377"));
69
70          #-- add default ring level
71          if (!isset($entry[1])) {
72             $entry[1] = 1;
73          }
74
75          break;
76       }
77    }
78
79    return($entry);
80 }
81
82
83 ?>