changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth / userdb_sql.php
1 <?php
2 /*
3    This plugin allows to use an existing SQL database table with usernames
4    and passwords for authentication purposes. Works with MySQL or the
5    anydb backend.
6
7    Prior usage you must configure, which database table and field names
8    to retrieve the user information from. Additionally it is possible to
9    substitute the "$ewiki_ring" level (= admin or moderator privileges)
10    from there, if a column exists with that purpose.
11
12    You also need:
13    + EWIKI_PROTECTED_MODE=1
14    + one auth_perm_* plugin
15    + one auth_method_* plugin
16 */
17
18
19
20 $ewiki_plugins["auth_userdb"] = "ewiki_auth_userdb_sql";
21
22
23 function ewiki_auth_userdb_sql($username) {
24
25    #-- function names (don't change)
26    $sql_query = "mysql_query";
27    $sql_fetch = "mysql_fetch_array";
28 #   $sql_query = "anydb_query";
29 #   $sql_fetch = "anydb_fetch_array";
30
31    #-- set your CMS' user table and column names here
32    $TABLE = "users";
33    $COL_USER = "name";
34    $COL_PW = "password";
35    #-- you can OPTIONALLY map privilege level strings to ewiki ring level ints:
36    $COL_PRIV = "privilege";
37    $MAP_PRIV = array("guest"=>3, "user"=>2, "moderator"=>1, "admin"=>0);
38
39    #-- examples for some common CMS and dynamic web site systems
40    # PostNuke
41   //$TABLE="nuke_users";  $COL_USER="pn_name";  $COL_PW="pn_pass";
42   //$COL_PRIV="";
43    # pSlash
44   //$TABLE="ps_users";  $COL_USER="uname";  $COL_PW="pass";
45   //$COL_PRIV="status";  $MAP_PRIV("member"=>2, "Admin"=>0);
46    # coWiki
47   //$TABLE="cowiki_user";  $COL_USER="name";  $COL_PW="passwd";
48   //$COL_PRIV="";
49    # e107
50   //$TABLE="user";  $COL_USER="user_name";  $COL_PW="user_password";
51   //$COL_PRIV="user_admin";  $MAP_PRIV(0=>2, 1=>0);
52    # Geeklog
53   //$TABLE="gl_user";  $COL_USER="username";  $COL_PW="passwd";
54   //$COL_PRIV="";
55
56
57    #-- proceed
58    $ret = array();
59    $username = addslashes($username);  # (not really necessary here anymore)
60    
61    #-- search username and password
62    if (($result = $sql_query("select $COL_PW from $TABLE where $COL_USER='$username'")) && ($row = $sql_fetch($result))) {
63
64       #-- return values
65       $ret[0] = $row[$COL_PW];
66       $ret[1] = 2;  // default ring level
67
68       #-- fetch privilege level, if there is a table row for it
69       if ($COL_PRIV && ($result = $sql_query("select $COL_PRIV from $TABLE where $COL_USER='$username'")) && ($row = $sql_fetch($result))) {
70          $i = $row[$COL_PRIV];
71          #-- map priviliege names/values to ewikis' ring level integers
72          if (isset($i) && isset($MAP_PRIV[$i])) {
73             $ret[1] = $MAP_PRIV[$i];
74          }
75       }
76    }
77
78    #-- done
79    return($ret);
80 }
81
82
83 ?>