check_logfiles: 3.7.5.1
[omd.git] / packages / dokuwiki / authmultisite / auth.php
blob58f137444ec85de34b5da9fdcf20f0b45a240fb2
1 <?php
2 if(!defined('DOKU_INC')) die();
4 /**
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 {
14 var $success = true;
15 var $cando = array (
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) {
34 $creds = array();
35 foreach(file($path) AS $line) {
36 if(strpos($line, ':') !== false) {
37 list($username, $secret) = explode(':', $line, 2);
38 $creds[$username] = rtrim($secret);
41 return $creds;
44 function trustExternal($user,$pass,$sticky=false){
45 global $conf;
46 global $USERINFO;
47 foreach(array_keys($_COOKIE) AS $cookieName)
49 if(substr($cookieName, 0, 5) != 'auth_'){
50 continue;
53 if(!isset($_COOKIE[$cookieName]) || $_COOKIE[$cookieName] == ''){
54 continue;
56 list($username, $issueTime, $cookieHash) = explode(':', $_COOKIE[$cookieName], 3);
58 require_once($conf['multisite']['authfile']);
59 if(!isset($mk_users[$username])){
60 continue;
63 if(file_exists($conf['multisite']['auth_serials']))
64 $authFile = 'serial';
65 elseif(file_exists($conf['multisite']['htpasswd']))
66 $authFile = 'htpasswd';
67 else
68 continue;
70 if($authFile == 'htpasswd')
71 $users = $this->loadAuthFile($conf['multisite']['htpasswd']);
72 else
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;
88 return true;
89 }else
91 continue;
94 header('Location:../check_mk/login.py?_origtarget=' . urlencode($_SERVER['REQUEST_URI']));
95 return false;
100 //Setup VIM: ex: et ts=2 :