-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth.php
125 lines (103 loc) · 3.36 KB
/
auth.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* DokuWiki envvars plugin
* https://www.dokuwiki.org/plugin:authenvvars
*
* @license GPL 3 http://www.gnu.org/licenses/gpl-3.0.html
* @author Christian Hoffmann <christian@lehrer-hoffmann.de>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class auth_plugin_authenvvars extends DokuWiki_Auth_Plugin {
/**
* Constructor.
*/
public function __construct() {
# global $conf;
parent::__construct();
/* No support for logout in this auth plugin. */
$this->cando['logout'] = false;
/* This plugins uses it's own authentication. */
$this->cando['external'] = true;
$this->success = false;
/* Load the config */
$this->loadConfig();
try {
$this->userinfo = array();
$this->userinfo['userid'] = $_SERVER[$this->getConf('useridvar')];
if( empty($this->userinfo['userid']) ) {
throw new Exception( "userid empty. Please give correct envvar in useridvar." );
}
$this->userinfo['name'] = $_SERVER[$this->getConf('usernamevar')];
$this->userinfo['mail'] = $_SERVER[$this->getConf('emailvar')];
$this->userinfo['grps'] = $this->createGrouparray();
}
catch( Exception $e ) {
msg( $e->getMessage() );
return;
}
$this->success = true;
}
public function trustExternal($user, $pass, $sticky=false) {
global $USERINFO;
/* $user ignored */
$myuser = $this->userinfo['userid'];
$USERINFO['name'] = $this->userinfo['name'];
$USERINFO['mail'] = $this->userinfo['mail'];
$USERINFO['grps'] = $this->userinfo['grps'];
$_SERVER['REMOTE_USER'] = $myuser;
$_SESSION[DOKU_COOKIE]['auth']['user'] = $myuser;
$_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
return true;
}
private function createGrouparray() {
$groupformat = $this->getConf('groupformat');
if( $groupformat == 'csv' ) {
return $this->createGrouparrayCsv();
}
return $this->createGrouparrayJson();
}
private function createGrouparrayCsv() {
$groupsvar = $this->getConf('groupsvar');
$groupsep = $this->getConf('groupsep');
$grouparr = array();
$grouparr[] = 'user';
if( empty($groupsvar) ) {
return $grouparr;
}
foreach( explode( $groupsep, $_SERVER[$groupsvar]) as $value ) {
$grouparr[]=$value;
}
/* error_log( $this->userinfo['name'].': '.json_encode($grouparr) ); */
return $grouparr;
}
private function createGrouparrayJson() {
$groupsvar = $this->getConf('groupsvar');
$groupattr = $this->getConf('groupattr');
$grouparr = array();
$grouparr[] = 'user';
if( empty($groupsvar) ) {
return $grouparr;
}
foreach( json_decode($_SERVER[$groupsvar],true) as $key=>$value ) {
if( is_array( $value) ) {
if( ! array_key_exists( $groupattr, $value ) ) {
throw new Exception( $groupattr." is not an attribute." );
}
$grpvalue = $value[$groupattr];
}
else {
$grpvalue = $value;
}
if( ! is_string( $grpvalue) ) {
throw new Exception( "Groupvalue is not a string." );
}
$grouparr[] = $grpvalue;
}
/* error_log( $this->userinfo['name'].': '.json_encode($grouparr) ); */
return $grouparr;
}
public function getUserData($user, $requireGroups = true){
return true;
}
}