2 if(!defined('DOKU_INC')) die();
5 * auth/multisite.class.php
7 * Login against the Check_MK Multisite API
9 * @author Bastian Kuhn <bk@mathias-kettner.de>
12 class auth_plugin_authmultisite
extends DokuWiki_Auth_Plugin
{
16 'addUser' => false, // can Users be created?
17 'delUser' => false, // can Users be deleted?
18 'modLogin' => false, // can login names be changed?
19 'modPass' => false, // can passwords be changed?
20 'modName' => false, // can real names be changed?
21 'modMail' => false, // can emails be changed?
22 'modGroups' => false, // can groups be changed?
23 'getUsers' => false, // can a (filtered) list of users be retrieved?
24 'getUserCount'=> false, // can the number of users be retrieved?
25 'getGroups' => false, // can a list of available groups be retrieved?
26 'external' => true, // does the module do external auth checking?
27 'logout' => false, // can the user logout again? (eg. not possible with HTTP auth)
30 function auth_basic() {
33 private function loadAuthFile($path) {
35 foreach(file($path) AS $line) {
36 if(strpos($line, ':') !== false) {
37 list($username, $secret) = explode(':', $line, 2);
38 $creds[$username] = rtrim($secret);
44 function trustExternal($user,$pass,$sticky=false){
47 foreach(array_keys($_COOKIE) AS $cookieName)
49 if(substr($cookieName, 0, 5) != 'auth_'){
53 if(!isset($_COOKIE[$cookieName]) ||
$_COOKIE[$cookieName] == ''){
56 list($username, $issueTime, $cookieHash) = explode(':', $_COOKIE[$cookieName], 3);
58 require_once($conf['multisite']['authfile']);
59 if(!isset($mk_users[$username])){
63 if(file_exists($conf['multisite']['auth_serials']))
65 elseif(file_exists($conf['multisite']['htpasswd']))
66 $authFile = 'htpasswd';
70 if($authFile == 'htpasswd')
71 $users = $this->loadAuthFile($conf['multisite']['htpasswd']);
73 $users = $this->loadAuthFile($conf['multisite']['auth_serials']);
75 if(!isset($users[$username])) {
76 throw new Exception();
78 $user_secret = $users[$username];
80 $secret = trim(file_get_contents($conf['multisite']['auth_secret']));
81 if(md5($username . $issueTime . $user_secret . $secret) == $cookieHash)
83 $USERINFO['name'] = $username;
84 $USERINFO['grps'] = $mk_users[$username]['roles'];
85 $_SERVER['REMOTE_USER'] = $username;
86 $_SESSION[DOKU_COOKIE
]['auth']['user'] = $username;
87 $_SESSION[DOKU_COOKIE
]['auth']['info'] = $USERINFO;
94 header('Location:../check_mk/login.py?_origtarget=' . urlencode($_SERVER['REQUEST_URI']));
100 //Setup VIM: ex: et ts=2 :