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