1f4476bd9SJan Schumann<?php 28553d24dSAndreas Gohruse dokuwiki\Extension\AuthPlugin; 3ab9790caSAndreas Gohruse dokuwiki\Utf8\Clean; 4ab9790caSAndreas Gohruse dokuwiki\Utf8\PhpString; 50489c64bSMoisés Braga Ribeirouse dokuwiki\Utf8\Sort; 631667ec6SAndreas Gohruse dokuwiki\Logger; 731667ec6SAndreas Gohr 8f4476bd9SJan Schumann/** 9f4476bd9SJan Schumann * Active Directory authentication backend for DokuWiki 10f4476bd9SJan Schumann * 11f4476bd9SJan Schumann * This makes authentication with a Active Directory server much easier 12f4476bd9SJan Schumann * than when using the normal LDAP backend by utilizing the adLDAP library 13f4476bd9SJan Schumann * 14f4476bd9SJan Schumann * Usage: 15f4476bd9SJan Schumann * Set DokuWiki's local.protected.php auth setting to read 16f4476bd9SJan Schumann * 17f4476bd9SJan Schumann * $conf['authtype'] = 'authad'; 18f4476bd9SJan Schumann * 1932fd494aSAndreas Gohr * $conf['plugin']['authad']['account_suffix'] = '@my.domain.org'; 2032fd494aSAndreas Gohr * $conf['plugin']['authad']['base_dn'] = 'DC=my,DC=domain,DC=org'; 2132fd494aSAndreas Gohr * $conf['plugin']['authad']['domain_controllers'] = 'srv1.domain.org,srv2.domain.org'; 22f4476bd9SJan Schumann * 23f4476bd9SJan Schumann * //optional: 2432fd494aSAndreas Gohr * $conf['plugin']['authad']['sso'] = 1; 253002d731SAndreas Gohr * $conf['plugin']['authad']['admin_username'] = 'root'; 263002d731SAndreas Gohr * $conf['plugin']['authad']['admin_password'] = 'pass'; 2732fd494aSAndreas Gohr * $conf['plugin']['authad']['real_primarygroup'] = 1; 2832fd494aSAndreas Gohr * $conf['plugin']['authad']['use_ssl'] = 1; 2932fd494aSAndreas Gohr * $conf['plugin']['authad']['use_tls'] = 1; 3032fd494aSAndreas Gohr * $conf['plugin']['authad']['debug'] = 1; 3193a7873eSAndreas Gohr * // warn user about expiring password this many days in advance: 3232fd494aSAndreas Gohr * $conf['plugin']['authad']['expirywarn'] = 5; 33f4476bd9SJan Schumann * 34f4476bd9SJan Schumann * // get additional information to the userinfo array 35f4476bd9SJan Schumann * // add a list of comma separated ldap contact fields. 36f4476bd9SJan Schumann * $conf['plugin']['authad']['additional'] = 'field1,field2'; 37f4476bd9SJan Schumann * 38f4476bd9SJan Schumann * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 39f4476bd9SJan Schumann * @author James Van Lommel <jamesvl@gmail.com> 40f4476bd9SJan Schumann * @link http://www.nosq.com/blog/2005/08/ldap-activedirectory-and-dokuwiki/ 41f4476bd9SJan Schumann * @author Andreas Gohr <andi@splitbrain.org> 42f4476bd9SJan Schumann * @author Jan Schumann <js@schumann-it.com> 43f4476bd9SJan Schumann */ 448553d24dSAndreas Gohrclass auth_plugin_authad extends AuthPlugin 45a4337320SAndreas Gohr{ 4632fd494aSAndreas Gohr 4793a7873eSAndreas Gohr /** 4893a7873eSAndreas Gohr * @var array hold connection data for a specific AD domain 4993a7873eSAndreas Gohr */ 50ab9790caSAndreas Gohr protected $opts = []; 5132fd494aSAndreas Gohr 5293a7873eSAndreas Gohr /** 5393a7873eSAndreas Gohr * @var array open connections for each AD domain, as adLDAP objects 5493a7873eSAndreas Gohr */ 55ab9790caSAndreas Gohr protected $adldap = []; 5693a7873eSAndreas Gohr 5793a7873eSAndreas Gohr /** 5893a7873eSAndreas Gohr * @var bool message state 5993a7873eSAndreas Gohr */ 6093a7873eSAndreas Gohr protected $msgshown = false; 6193a7873eSAndreas Gohr 6293a7873eSAndreas Gohr /** 6393a7873eSAndreas Gohr * @var array user listing cache 6493a7873eSAndreas Gohr */ 65ab9790caSAndreas Gohr protected $users = []; 6693a7873eSAndreas Gohr 6793a7873eSAndreas Gohr /** 6893a7873eSAndreas Gohr * @var array filter patterns for listing users 6993a7873eSAndreas Gohr */ 70ab9790caSAndreas Gohr protected $pattern = []; 71f4476bd9SJan Schumann 72ab9790caSAndreas Gohr protected $grpsusers = []; 73c52f6cd2SMichael Große 74f4476bd9SJan Schumann /** 75f4476bd9SJan Schumann * Constructor 76f4476bd9SJan Schumann */ 77a4337320SAndreas Gohr public function __construct() 78a4337320SAndreas Gohr { 7900d58927SMichael Hamann global $INPUT; 80454d868bSAndreas Gohr parent::__construct(); 81454d868bSAndreas Gohr 82a4337320SAndreas Gohr require_once(DOKU_PLUGIN.'authad/adLDAP/adLDAP.php'); 83a4337320SAndreas Gohr require_once(DOKU_PLUGIN.'authad/adLDAP/classes/adLDAPUtils.php'); 84a4337320SAndreas Gohr 8532fd494aSAndreas Gohr // we load the config early to modify it a bit here 8632fd494aSAndreas Gohr $this->loadConfig(); 87f4476bd9SJan Schumann 88f4476bd9SJan Schumann // additional information fields 8932fd494aSAndreas Gohr if (isset($this->conf['additional'])) { 9032fd494aSAndreas Gohr $this->conf['additional'] = str_replace(' ', '', $this->conf['additional']); 9132fd494aSAndreas Gohr $this->conf['additional'] = explode(',', $this->conf['additional']); 92ab9790caSAndreas Gohr } else $this->conf['additional'] = []; 93f4476bd9SJan Schumann 94f4476bd9SJan Schumann // ldap extension is needed 95f4476bd9SJan Schumann if (!function_exists('ldap_connect')) { 9632fd494aSAndreas Gohr if ($this->conf['debug']) 97f4476bd9SJan Schumann msg("AD Auth: PHP LDAP extension not found.", -1); 98f4476bd9SJan Schumann $this->success = false; 99f4476bd9SJan Schumann return; 100f4476bd9SJan Schumann } 101f4476bd9SJan Schumann 102f4476bd9SJan Schumann // Prepare SSO 1031d5848a6Sfiwswe if (!empty($INPUT->server->str('REMOTE_USER'))) { 104d34a2a38SAndreas Gohr // make sure the right encoding is used 105d34a2a38SAndreas Gohr if ($this->getConf('sso_charset')) { 106*dccd6b2bSAndreas Gohr $INPUT->server->set( 107*dccd6b2bSAndreas Gohr 'REMOTE_USER', 108*dccd6b2bSAndreas Gohr iconv($this->getConf('sso_charset'), 'UTF-8', $INPUT->server->str('REMOTE_USER')) 109*dccd6b2bSAndreas Gohr ); 110ab9790caSAndreas Gohr } elseif (!Clean::isUtf8($INPUT->server->str('REMOTE_USER'))) { 1111d5848a6Sfiwswe $INPUT->server->set('REMOTE_USER', utf8_encode($INPUT->server->str('REMOTE_USER'))); 11293a7873eSAndreas Gohr } 113d34a2a38SAndreas Gohr 114d34a2a38SAndreas Gohr // trust the incoming user 115d34a2a38SAndreas Gohr if ($this->conf['sso']) { 1161d5848a6Sfiwswe $INPUT->server->set('REMOTE_USER', $this->cleanUser($INPUT->server->str('REMOTE_USER'))); 117f4476bd9SJan Schumann 118f4476bd9SJan Schumann // we need to simulate a login 119f4476bd9SJan Schumann if (empty($_COOKIE[DOKU_COOKIE])) { 1201d5848a6Sfiwswe $INPUT->set('u', $INPUT->server->str('REMOTE_USER')); 12100d58927SMichael Hamann $INPUT->set('p', 'sso_only'); 122f4476bd9SJan Schumann } 123f4476bd9SJan Schumann } 124d34a2a38SAndreas Gohr } 125f4476bd9SJan Schumann 12693a7873eSAndreas Gohr // other can do's are changed in $this->_loadServerConfig() base on domain setup 127bb30445dSMichael Wilmes $this->cando['modName'] = (bool)$this->conf['update_name']; 128bb30445dSMichael Wilmes $this->cando['modMail'] = (bool)$this->conf['update_mail']; 12925f80763SMichael Große $this->cando['getUserCount'] = true; 130f4476bd9SJan Schumann } 131f4476bd9SJan Schumann 132f4476bd9SJan Schumann /** 133a154806fSAndreas Gohr * Load domain config on capability check 134a154806fSAndreas Gohr * 135a154806fSAndreas Gohr * @param string $cap 136a154806fSAndreas Gohr * @return bool 137a154806fSAndreas Gohr */ 138a4337320SAndreas Gohr public function canDo($cap) 139a4337320SAndreas Gohr { 1401d5848a6Sfiwswe global $INPUT; 141a154806fSAndreas Gohr //capabilities depend on config, which may change depending on domain 1421d5848a6Sfiwswe $domain = $this->getUserDomain($INPUT->server->str('REMOTE_USER')); 143a4337320SAndreas Gohr $this->loadServerConfig($domain); 144a154806fSAndreas Gohr return parent::canDo($cap); 145a154806fSAndreas Gohr } 146a154806fSAndreas Gohr 147a154806fSAndreas Gohr /** 148f4476bd9SJan Schumann * Check user+password [required auth function] 149f4476bd9SJan Schumann * 150f4476bd9SJan Schumann * Checks if the given user exists and the given 151f4476bd9SJan Schumann * plaintext password is correct by trying to bind 152f4476bd9SJan Schumann * to the LDAP server 153f4476bd9SJan Schumann * 154f4476bd9SJan Schumann * @author James Van Lommel <james@nosq.com> 15593a7873eSAndreas Gohr * @param string $user 15693a7873eSAndreas Gohr * @param string $pass 157f4476bd9SJan Schumann * @return bool 158f4476bd9SJan Schumann */ 159a4337320SAndreas Gohr public function checkPass($user, $pass) 160a4337320SAndreas Gohr { 1611d5848a6Sfiwswe global $INPUT; 1621d5848a6Sfiwswe if ($INPUT->server->str('REMOTE_USER') == $user && 16332fd494aSAndreas Gohr $this->conf['sso'] 16493a7873eSAndreas Gohr ) return true; 165f4476bd9SJan Schumann 166a4337320SAndreas Gohr $adldap = $this->initAdLdap($this->getUserDomain($user)); 16793a7873eSAndreas Gohr if (!$adldap) return false; 16893a7873eSAndreas Gohr 169a4337320SAndreas Gohr try { 170a4337320SAndreas Gohr return $adldap->authenticate($this->getUserName($user), $pass); 171a4337320SAndreas Gohr } catch (adLDAPException $e) { 172a4337320SAndreas Gohr // shouldn't really happen 173a4337320SAndreas Gohr return false; 174a4337320SAndreas Gohr } 175f4476bd9SJan Schumann } 176f4476bd9SJan Schumann 177f4476bd9SJan Schumann /** 178f4476bd9SJan Schumann * Return user info [required auth function] 179f4476bd9SJan Schumann * 180f4476bd9SJan Schumann * Returns info about the given user needs to contain 181f4476bd9SJan Schumann * at least these fields: 182f4476bd9SJan Schumann * 183f4476bd9SJan Schumann * name string full name of the user 184f4476bd9SJan Schumann * mail string email address of the user 185f4476bd9SJan Schumann * grps array list of groups the user is in 186f4476bd9SJan Schumann * 18793a7873eSAndreas Gohr * This AD specific function returns the following 188f4476bd9SJan Schumann * addional fields: 189f4476bd9SJan Schumann * 190f4476bd9SJan Schumann * dn string distinguished name (DN) 19193a7873eSAndreas Gohr * uid string samaccountname 19293a7873eSAndreas Gohr * lastpwd int timestamp of the date when the password was set 19393a7873eSAndreas Gohr * expires true if the password expires 19493a7873eSAndreas Gohr * expiresin int seconds until the password expires 19593a7873eSAndreas Gohr * any fields specified in the 'additional' config option 196f4476bd9SJan Schumann * 197f4476bd9SJan Schumann * @author James Van Lommel <james@nosq.com> 19893a7873eSAndreas Gohr * @param string $user 1992046a654SChristopher Smith * @param bool $requireGroups (optional) - ignored, groups are always supplied by this plugin 20093a7873eSAndreas Gohr * @return array 201f4476bd9SJan Schumann */ 202a4337320SAndreas Gohr public function getUserData($user, $requireGroups = true) 203a4337320SAndreas Gohr { 204f4476bd9SJan Schumann global $conf; 20593a7873eSAndreas Gohr global $lang; 20693a7873eSAndreas Gohr global $ID; 2071d5848a6Sfiwswe global $INPUT; 208a4337320SAndreas Gohr $adldap = $this->initAdLdap($this->getUserDomain($user)); 209ab9790caSAndreas Gohr if (!$adldap) return []; 210f4476bd9SJan Schumann 211ab9790caSAndreas Gohr if ($user == '') return []; 21293a7873eSAndreas Gohr 213ab9790caSAndreas Gohr $fields = ['mail', 'displayname', 'samaccountname', 'lastpwd', 'pwdlastset', 'useraccountcontrol']; 214f4476bd9SJan Schumann 215f4476bd9SJan Schumann // add additional fields to read 21632fd494aSAndreas Gohr $fields = array_merge($fields, $this->conf['additional']); 217f4476bd9SJan Schumann $fields = array_unique($fields); 21814642325SAndreas Gohr $fields = array_filter($fields); 219f4476bd9SJan Schumann 220f4476bd9SJan Schumann //get info for given user 221a4337320SAndreas Gohr $result = $adldap->user()->info($this->getUserName($user), $fields); 22293a7873eSAndreas Gohr if ($result == false) { 223ab9790caSAndreas Gohr return []; 22493a7873eSAndreas Gohr } 22593a7873eSAndreas Gohr 226f4476bd9SJan Schumann //general user info 227ab9790caSAndreas Gohr $info = []; 228f4476bd9SJan Schumann $info['name'] = $result[0]['displayname'][0]; 229f4476bd9SJan Schumann $info['mail'] = $result[0]['mail'][0]; 230f4476bd9SJan Schumann $info['uid'] = $result[0]['samaccountname'][0]; 231f4476bd9SJan Schumann $info['dn'] = $result[0]['dn']; 23293a7873eSAndreas Gohr //last password set (Windows counts from January 1st 1601) 233ab9790caSAndreas Gohr $info['lastpwd'] = $result[0]['pwdlastset'][0] / 10_000_000 - 11_644_473_600; 23493a7873eSAndreas Gohr //will it expire? 23593a7873eSAndreas Gohr $info['expires'] = !($result[0]['useraccountcontrol'][0] & 0x10000); //ADS_UF_DONT_EXPIRE_PASSWD 236f4476bd9SJan Schumann 237f4476bd9SJan Schumann // additional information 23832fd494aSAndreas Gohr foreach ($this->conf['additional'] as $field) { 239f4476bd9SJan Schumann if (isset($result[0][strtolower($field)])) { 240f4476bd9SJan Schumann $info[$field] = $result[0][strtolower($field)][0]; 241f4476bd9SJan Schumann } 242f4476bd9SJan Schumann } 243f4476bd9SJan Schumann 244f4476bd9SJan Schumann // handle ActiveDirectory memberOf 245a4337320SAndreas Gohr $info['grps'] = $adldap->user()->groups($this->getUserName($user), (bool) $this->opts['recursive_groups']); 246f4476bd9SJan Schumann 247f4476bd9SJan Schumann if (is_array($info['grps'])) { 248f4476bd9SJan Schumann foreach ($info['grps'] as $ndx => $group) { 249f4476bd9SJan Schumann $info['grps'][$ndx] = $this->cleanGroup($group); 250f4476bd9SJan Schumann } 251f4476bd9SJan Schumann } 252f4476bd9SJan Schumann 253f4476bd9SJan Schumann // always add the default group to the list of groups 254f4476bd9SJan Schumann if (!is_array($info['grps']) || !in_array($conf['defaultgroup'], $info['grps'])) { 255f4476bd9SJan Schumann $info['grps'][] = $conf['defaultgroup']; 256f4476bd9SJan Schumann } 257f4476bd9SJan Schumann 25893a7873eSAndreas Gohr // add the user's domain to the groups 259a4337320SAndreas Gohr $domain = $this->getUserDomain($user); 260bf9be0e3SAndreas Gohr if ($domain && !in_array("domain-$domain", $info['grps'])) { 26193a7873eSAndreas Gohr $info['grps'][] = $this->cleanGroup("domain-$domain"); 26293a7873eSAndreas Gohr } 26393a7873eSAndreas Gohr 26493a7873eSAndreas Gohr // check expiry time 26532fd494aSAndreas Gohr if ($info['expires'] && $this->conf['expirywarn']) { 266a4337320SAndreas Gohr try { 2671e52e72aSAndreas Gohr $expiry = $adldap->user()->passwordExpiry($user); 2681e52e72aSAndreas Gohr if (is_array($expiry)) { 2691e52e72aSAndreas Gohr $info['expiresat'] = $expiry['expiryts']; 2701e52e72aSAndreas Gohr $info['expiresin'] = round(($info['expiresat'] - time())/(24*60*60)); 27193a7873eSAndreas Gohr 27293a7873eSAndreas Gohr // if this is the current user, warn him (once per request only) 2731d5848a6Sfiwswe if (($INPUT->server->str('REMOTE_USER') == $user) && 2741e52e72aSAndreas Gohr ($info['expiresin'] <= $this->conf['expirywarn']) && 27593a7873eSAndreas Gohr !$this->msgshown 27693a7873eSAndreas Gohr ) { 2775b795a65SPatrick Brown $msg = sprintf($this->getLang('authpwdexpire'), $info['expiresin']); 27893a7873eSAndreas Gohr if ($this->canDo('modPass')) { 279ab9790caSAndreas Gohr $url = wl($ID, ['do'=> 'profile']); 28093a7873eSAndreas Gohr $msg .= ' <a href="'.$url.'">'.$lang['btn_profile'].'</a>'; 28193a7873eSAndreas Gohr } 28293a7873eSAndreas Gohr msg($msg); 28393a7873eSAndreas Gohr $this->msgshown = true; 28493a7873eSAndreas Gohr } 28593a7873eSAndreas Gohr } 286a4337320SAndreas Gohr } catch (adLDAPException $e) { 287a4337320SAndreas Gohr // ignore. should usually not happen 288a4337320SAndreas Gohr } 2891e52e72aSAndreas Gohr } 29093a7873eSAndreas Gohr 291f4476bd9SJan Schumann return $info; 292f4476bd9SJan Schumann } 293f4476bd9SJan Schumann 294f4476bd9SJan Schumann /** 295f4476bd9SJan Schumann * Make AD group names usable by DokuWiki. 296f4476bd9SJan Schumann * 297f4476bd9SJan Schumann * Removes backslashes ('\'), pound signs ('#'), and converts spaces to underscores. 298f4476bd9SJan Schumann * 299f4476bd9SJan Schumann * @author James Van Lommel (jamesvl@gmail.com) 30093a7873eSAndreas Gohr * @param string $group 30193a7873eSAndreas Gohr * @return string 302f4476bd9SJan Schumann */ 303a4337320SAndreas Gohr public function cleanGroup($group) 304a4337320SAndreas Gohr { 30593a7873eSAndreas Gohr $group = str_replace('\\', '', $group); 30693a7873eSAndreas Gohr $group = str_replace('#', '', $group); 30793a7873eSAndreas Gohr $group = preg_replace('[\s]', '_', $group); 308ab9790caSAndreas Gohr $group = PhpString::strtolower(trim($group)); 30993a7873eSAndreas Gohr return $group; 310f4476bd9SJan Schumann } 311f4476bd9SJan Schumann 312f4476bd9SJan Schumann /** 313f4476bd9SJan Schumann * Sanitize user names 31493a7873eSAndreas Gohr * 31593a7873eSAndreas Gohr * Normalizes domain parts, does not modify the user name itself (unlike cleanGroup) 31693a7873eSAndreas Gohr * 31793a7873eSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 31893a7873eSAndreas Gohr * @param string $user 31993a7873eSAndreas Gohr * @return string 320f4476bd9SJan Schumann */ 321a4337320SAndreas Gohr public function cleanUser($user) 322a4337320SAndreas Gohr { 32393a7873eSAndreas Gohr $domain = ''; 32493a7873eSAndreas Gohr 32593a7873eSAndreas Gohr // get NTLM or Kerberos domain part 326ab9790caSAndreas Gohr [$dom, $user] = sexplode('\\', $user, 2, ''); 32793a7873eSAndreas Gohr if (!$user) $user = $dom; 32893a7873eSAndreas Gohr if ($dom) $domain = $dom; 329ab9790caSAndreas Gohr [$user, $dom] = sexplode('@', $user, 2, ''); 33093a7873eSAndreas Gohr if ($dom) $domain = $dom; 33193a7873eSAndreas Gohr 33293a7873eSAndreas Gohr // clean up both 333ab9790caSAndreas Gohr $domain = PhpString::strtolower(trim($domain)); 334ab9790caSAndreas Gohr $user = PhpString::strtolower(trim($user)); 33593a7873eSAndreas Gohr 336916ef7cfSAndreas Gohr // is this a known, valid domain or do we work without account suffix? if not discard 3373e2e2c4fSAndreas Gohr if ((!isset($this->conf[$domain]) || !is_array($this->conf[$domain])) && 3383e2e2c4fSAndreas Gohr $this->conf['account_suffix'] !== '') { 33993a7873eSAndreas Gohr $domain = ''; 34093a7873eSAndreas Gohr } 34193a7873eSAndreas Gohr 34293a7873eSAndreas Gohr // reattach domain 34393a7873eSAndreas Gohr if ($domain) $user = "$user@$domain"; 34493a7873eSAndreas Gohr return $user; 345f4476bd9SJan Schumann } 346f4476bd9SJan Schumann 347f4476bd9SJan Schumann /** 348f4476bd9SJan Schumann * Most values in LDAP are case-insensitive 34993a7873eSAndreas Gohr * 35093a7873eSAndreas Gohr * @return bool 351f4476bd9SJan Schumann */ 352a4337320SAndreas Gohr public function isCaseSensitive() 353a4337320SAndreas Gohr { 354f4476bd9SJan Schumann return false; 355f4476bd9SJan Schumann } 356f4476bd9SJan Schumann 3576fcf992cSMichael Große /** 3587910cbbbSMichael Große * Create a Search-String useable by adLDAPUsers::all($includeDescription = false, $search = "*", $sorted = true) 3597910cbbbSMichael Große * 3606fcf992cSMichael Große * @param array $filter 3616fcf992cSMichael Große * @return string 3626fcf992cSMichael Große */ 363a4337320SAndreas Gohr protected function constructSearchString($filter) 364a4337320SAndreas Gohr { 36567a31a83SMichael Große if (!$filter) { 36667a31a83SMichael Große return '*'; 36767a31a83SMichael Große } 368a4337320SAndreas Gohr $adldapUtils = new adLDAPUtils($this->initAdLdap(null)); 36967a31a83SMichael Große $result = '*'; 37067a31a83SMichael Große if (isset($filter['name'])) { 37107aec029SMichael Große $result .= ')(displayname=*' . $adldapUtils->ldapSlashes($filter['name']) . '*'; 37267a31a83SMichael Große unset($filter['name']); 37367a31a83SMichael Große } 3747910cbbbSMichael Große 37567a31a83SMichael Große if (isset($filter['user'])) { 37607aec029SMichael Große $result .= ')(samAccountName=*' . $adldapUtils->ldapSlashes($filter['user']) . '*'; 37767a31a83SMichael Große unset($filter['user']); 37867a31a83SMichael Große } 37967a31a83SMichael Große 38067a31a83SMichael Große if (isset($filter['mail'])) { 38107aec029SMichael Große $result .= ')(mail=*' . $adldapUtils->ldapSlashes($filter['mail']) . '*'; 38267a31a83SMichael Große unset($filter['mail']); 38367a31a83SMichael Große } 38467a31a83SMichael Große return $result; 38567a31a83SMichael Große } 38667a31a83SMichael Große 387f4476bd9SJan Schumann /** 3887910cbbbSMichael Große * Return a count of the number of user which meet $filter criteria 3897910cbbbSMichael Große * 3907910cbbbSMichael Große * @param array $filter $filter array of field/pattern pairs, empty array for no filter 3917910cbbbSMichael Große * @return int number of users 39225f80763SMichael Große */ 393ab9790caSAndreas Gohr public function getUserCount($filter = []) 394a4337320SAndreas Gohr { 395a4337320SAndreas Gohr $adldap = $this->initAdLdap(null); 3966fcf992cSMichael Große if (!$adldap) { 39731667ec6SAndreas Gohr Logger::debug("authad/auth.php getUserCount(): _adldap not set."); 3986fcf992cSMichael Große return -1; 3996fcf992cSMichael Große } 400ab9790caSAndreas Gohr if ($filter == []) { 40125f80763SMichael Große $result = $adldap->user()->all(); 40267a31a83SMichael Große } else { 403a4337320SAndreas Gohr $searchString = $this->constructSearchString($filter); 40467a31a83SMichael Große $result = $adldap->user()->all(false, $searchString); 405c52f6cd2SMichael Große if (isset($filter['grps'])) { 406c52f6cd2SMichael Große $this->users = array_fill_keys($result, false); 407a4337320SAndreas Gohr /** @var admin_plugin_usermanager $usermanager */ 408c52f6cd2SMichael Große $usermanager = plugin_load("admin", "usermanager", false); 409462e9e37SMichael Große $usermanager->setLastdisabled(true); 410a4337320SAndreas Gohr if (!isset($this->grpsusers[$this->filterToString($filter)])) { 411a4337320SAndreas Gohr $this->fillGroupUserArray($filter, $usermanager->getStart() + 3*$usermanager->getPagesize()); 412a4337320SAndreas Gohr } elseif (count($this->grpsusers[$this->filterToString($filter)]) < 41364159a61SAndreas Gohr $usermanager->getStart() + 3*$usermanager->getPagesize() 41464159a61SAndreas Gohr ) { 415a4337320SAndreas Gohr $this->fillGroupUserArray( 41664159a61SAndreas Gohr $filter, 41764159a61SAndreas Gohr $usermanager->getStart() + 41864159a61SAndreas Gohr 3*$usermanager->getPagesize() - 419a4337320SAndreas Gohr count($this->grpsusers[$this->filterToString($filter)]) 42064159a61SAndreas Gohr ); 421c52f6cd2SMichael Große } 422a4337320SAndreas Gohr $result = $this->grpsusers[$this->filterToString($filter)]; 423462e9e37SMichael Große } else { 424a4337320SAndreas Gohr /** @var admin_plugin_usermanager $usermanager */ 425462e9e37SMichael Große $usermanager = plugin_load("admin", "usermanager", false); 426462e9e37SMichael Große $usermanager->setLastdisabled(false); 427c52f6cd2SMichael Große } 42867a31a83SMichael Große } 42967a31a83SMichael Große 43025f80763SMichael Große if (!$result) { 4316fcf992cSMichael Große return 0; 43225f80763SMichael Große } 43325f80763SMichael Große return count($result); 43425f80763SMichael Große } 43525f80763SMichael Große 4366fcf992cSMichael Große /** 4376fcf992cSMichael Große * 4386fcf992cSMichael Große * create a unique string for each filter used with a group 4396fcf992cSMichael Große * 4406fcf992cSMichael Große * @param array $filter 4416fcf992cSMichael Große * @return string 4426fcf992cSMichael Große */ 443a4337320SAndreas Gohr protected function filterToString($filter) 444a4337320SAndreas Gohr { 445c52f6cd2SMichael Große $result = ''; 446c52f6cd2SMichael Große if (isset($filter['user'])) { 447c52f6cd2SMichael Große $result .= 'user-' . $filter['user']; 448c52f6cd2SMichael Große } 449c52f6cd2SMichael Große if (isset($filter['name'])) { 450c52f6cd2SMichael Große $result .= 'name-' . $filter['name']; 451c52f6cd2SMichael Große } 452c52f6cd2SMichael Große if (isset($filter['mail'])) { 453c52f6cd2SMichael Große $result .= 'mail-' . $filter['mail']; 454c52f6cd2SMichael Große } 455c52f6cd2SMichael Große if (isset($filter['grps'])) { 456c52f6cd2SMichael Große $result .= 'grps-' . $filter['grps']; 457c52f6cd2SMichael Große } 458c52f6cd2SMichael Große return $result; 459c52f6cd2SMichael Große } 460c52f6cd2SMichael Große 4616fcf992cSMichael Große /** 4627910cbbbSMichael Große * Create an array of $numberOfAdds users passing a certain $filter, including belonging 4637910cbbbSMichael Große * to a certain group and save them to a object-wide array. If the array 4647910cbbbSMichael Große * already exists try to add $numberOfAdds further users to it. 4657910cbbbSMichael Große * 4666fcf992cSMichael Große * @param array $filter 4676fcf992cSMichael Große * @param int $numberOfAdds additional number of users requested 4686fcf992cSMichael Große * @return int number of Users actually add to Array 4696fcf992cSMichael Große */ 470a4337320SAndreas Gohr protected function fillGroupUserArray($filter, $numberOfAdds) 471a4337320SAndreas Gohr { 472fdd649a2SAndreas Gohr if (isset($this->grpsusers[$this->filterToString($filter)])) { 473fdd649a2SAndreas Gohr $actualstart = count($this->grpsusers[$this->filterToString($filter)]); 474fdd649a2SAndreas Gohr } else { 475fdd649a2SAndreas Gohr $this->grpsusers[$this->filterToString($filter)] = []; 476fdd649a2SAndreas Gohr $actualstart = 0; 477fdd649a2SAndreas Gohr } 478fdd649a2SAndreas Gohr 479c52f6cd2SMichael Große $i=0; 480c52f6cd2SMichael Große $count = 0; 481a4337320SAndreas Gohr $this->constructPattern($filter); 482c52f6cd2SMichael Große foreach ($this->users as $user => &$info) { 483fdd649a2SAndreas Gohr if ($i++ < $actualstart) { 484c52f6cd2SMichael Große continue; 485c52f6cd2SMichael Große } 486c52f6cd2SMichael Große if ($info === false) { 487c52f6cd2SMichael Große $info = $this->getUserData($user); 488c52f6cd2SMichael Große } 489a4337320SAndreas Gohr if ($this->filter($user, $info)) { 490a4337320SAndreas Gohr $this->grpsusers[$this->filterToString($filter)][$user] = $info; 491c52f6cd2SMichael Große if (($numberOfAdds > 0) && (++$count >= $numberOfAdds)) break; 492c52f6cd2SMichael Große } 493c52f6cd2SMichael Große } 494c52f6cd2SMichael Große return $count; 495c52f6cd2SMichael Große } 496c52f6cd2SMichael Große 49725f80763SMichael Große /** 498f4476bd9SJan Schumann * Bulk retrieval of user data 499f4476bd9SJan Schumann * 500f4476bd9SJan Schumann * @author Dominik Eckelmann <dokuwiki@cosmocode.de> 501253d4b48SGerrit Uitslag * 50293a7873eSAndreas Gohr * @param int $start index of first user to be returned 50393a7873eSAndreas Gohr * @param int $limit max number of users to be returned 50493a7873eSAndreas Gohr * @param array $filter array of field/pattern pairs, null for no filter 50593a7873eSAndreas Gohr * @return array userinfo (refer getUserData for internal userinfo details) 506f4476bd9SJan Schumann */ 507ab9790caSAndreas Gohr public function retrieveUsers($start = 0, $limit = 0, $filter = []) 508a4337320SAndreas Gohr { 509a4337320SAndreas Gohr $adldap = $this->initAdLdap(null); 510ab9790caSAndreas Gohr if (!$adldap) return []; 511f4476bd9SJan Schumann 512fdd649a2SAndreas Gohr //if (!$this->users) { 513f4476bd9SJan Schumann //get info for given user 514a4337320SAndreas Gohr $result = $adldap->user()->all(false, $this->constructSearchString($filter)); 515ab9790caSAndreas Gohr if (!$result) return []; 516f4476bd9SJan Schumann $this->users = array_fill_keys($result, false); 517fdd649a2SAndreas Gohr //} 518f4476bd9SJan Schumann 519f4476bd9SJan Schumann $i = 0; 520f4476bd9SJan Schumann $count = 0; 521ab9790caSAndreas Gohr $result = []; 522f4476bd9SJan Schumann 523c52f6cd2SMichael Große if (!isset($filter['grps'])) { 524a4337320SAndreas Gohr /** @var admin_plugin_usermanager $usermanager */ 525462e9e37SMichael Große $usermanager = plugin_load("admin", "usermanager", false); 526462e9e37SMichael Große $usermanager->setLastdisabled(false); 527a4337320SAndreas Gohr $this->constructPattern($filter); 528f4476bd9SJan Schumann foreach ($this->users as $user => &$info) { 529f4476bd9SJan Schumann if ($i++ < $start) { 530f4476bd9SJan Schumann continue; 531f4476bd9SJan Schumann } 532f4476bd9SJan Schumann if ($info === false) { 533f4476bd9SJan Schumann $info = $this->getUserData($user); 534f4476bd9SJan Schumann } 535f4476bd9SJan Schumann $result[$user] = $info; 5369a2c73e8SAndreas Gohr if (($limit > 0) && (++$count >= $limit)) break; 537f4476bd9SJan Schumann } 538c52f6cd2SMichael Große } else { 539a4337320SAndreas Gohr /** @var admin_plugin_usermanager $usermanager */ 540462e9e37SMichael Große $usermanager = plugin_load("admin", "usermanager", false); 541462e9e37SMichael Große $usermanager->setLastdisabled(true); 542a4337320SAndreas Gohr if (!isset($this->grpsusers[$this->filterToString($filter)]) || 543a4337320SAndreas Gohr count($this->grpsusers[$this->filterToString($filter)]) < ($start+$limit) 54464159a61SAndreas Gohr ) { 545fdd649a2SAndreas Gohr if(!isset($this->grpsusers[$this->filterToString($filter)])) { 546fdd649a2SAndreas Gohr $this->grpsusers[$this->filterToString($filter)] = []; 547fdd649a2SAndreas Gohr } 548fdd649a2SAndreas Gohr 549a4337320SAndreas Gohr $this->fillGroupUserArray( 55064159a61SAndreas Gohr $filter, 551a4337320SAndreas Gohr $start+$limit - count($this->grpsusers[$this->filterToString($filter)]) +1 55264159a61SAndreas Gohr ); 553c52f6cd2SMichael Große } 554ab9790caSAndreas Gohr if (!$this->grpsusers[$this->filterToString($filter)]) return []; 555a4337320SAndreas Gohr foreach ($this->grpsusers[$this->filterToString($filter)] as $user => &$info) { 556c52f6cd2SMichael Große if ($i++ < $start) { 557c52f6cd2SMichael Große continue; 558c52f6cd2SMichael Große } 559c52f6cd2SMichael Große $result[$user] = $info; 560c52f6cd2SMichael Große if (($limit > 0) && (++$count >= $limit)) break; 561c52f6cd2SMichael Große } 562c52f6cd2SMichael Große } 563f4476bd9SJan Schumann return $result; 564f4476bd9SJan Schumann } 565f4476bd9SJan Schumann 566f4476bd9SJan Schumann /** 567f4476bd9SJan Schumann * Modify user data 568f4476bd9SJan Schumann * 56993a7873eSAndreas Gohr * @param string $user nick of the user to be changed 57093a7873eSAndreas Gohr * @param array $changes array of field/value pairs to be changed 571f4476bd9SJan Schumann * @return bool 572f4476bd9SJan Schumann */ 573a4337320SAndreas Gohr public function modifyUser($user, $changes) 574a4337320SAndreas Gohr { 575f4476bd9SJan Schumann $return = true; 576a4337320SAndreas Gohr $adldap = $this->initAdLdap($this->getUserDomain($user)); 5778f03c311SPatrick Brown if (!$adldap) { 5788f03c311SPatrick Brown msg($this->getLang('connectfail'), -1); 5798f03c311SPatrick Brown return false; 5808f03c311SPatrick Brown } 581f4476bd9SJan Schumann 582f4476bd9SJan Schumann // password changing 583f4476bd9SJan Schumann if (isset($changes['pass'])) { 584f4476bd9SJan Schumann try { 585a4337320SAndreas Gohr $return = $adldap->user()->password($this->getUserName($user), $changes['pass']); 586f4476bd9SJan Schumann } catch (adLDAPException $e) { 58732fd494aSAndreas Gohr if ($this->conf['debug']) msg('AD Auth: '.$e->getMessage(), -1); 588f4476bd9SJan Schumann $return = false; 589f4476bd9SJan Schumann } 5908f03c311SPatrick Brown if (!$return) msg($this->getLang('passchangefail'), -1); 591f4476bd9SJan Schumann } 592f4476bd9SJan Schumann 593f4476bd9SJan Schumann // changing user data 594ab9790caSAndreas Gohr $adchanges = []; 595f4476bd9SJan Schumann if (isset($changes['name'])) { 596f4476bd9SJan Schumann // get first and last name 597f4476bd9SJan Schumann $parts = explode(' ', $changes['name']); 598f4476bd9SJan Schumann $adchanges['surname'] = array_pop($parts); 599ab9790caSAndreas Gohr $adchanges['firstname'] = implode(' ', $parts); 600f4476bd9SJan Schumann $adchanges['display_name'] = $changes['name']; 601f4476bd9SJan Schumann } 602f4476bd9SJan Schumann if (isset($changes['mail'])) { 603f4476bd9SJan Schumann $adchanges['email'] = $changes['mail']; 604f4476bd9SJan Schumann } 605ab9790caSAndreas Gohr if ($adchanges !== []) { 606f4476bd9SJan Schumann try { 607ab9790caSAndreas Gohr $return &= $adldap->user()->modify($this->getUserName($user), $adchanges); 608f4476bd9SJan Schumann } catch (adLDAPException $e) { 60932fd494aSAndreas Gohr if ($this->conf['debug']) msg('AD Auth: '.$e->getMessage(), -1); 610f4476bd9SJan Schumann $return = false; 611f4476bd9SJan Schumann } 6128f03c311SPatrick Brown if (!$return) msg($this->getLang('userchangefail'), -1); 613f4476bd9SJan Schumann } 614f4476bd9SJan Schumann 615f4476bd9SJan Schumann return $return; 616f4476bd9SJan Schumann } 617f4476bd9SJan Schumann 618f4476bd9SJan Schumann /** 619f4476bd9SJan Schumann * Initialize the AdLDAP library and connect to the server 62093a7873eSAndreas Gohr * 62193a7873eSAndreas Gohr * When you pass null as domain, it will reuse any existing domain. 62293a7873eSAndreas Gohr * Eg. the one of the logged in user. It falls back to the default 62393a7873eSAndreas Gohr * domain if no current one is available. 62493a7873eSAndreas Gohr * 62593a7873eSAndreas Gohr * @param string|null $domain The AD domain to use 62693a7873eSAndreas Gohr * @return adLDAP|bool true if a connection was established 627f4476bd9SJan Schumann */ 628a4337320SAndreas Gohr protected function initAdLdap($domain) 629a4337320SAndreas Gohr { 63093a7873eSAndreas Gohr if (is_null($domain) && is_array($this->opts)) { 63193a7873eSAndreas Gohr $domain = $this->opts['domain']; 63293a7873eSAndreas Gohr } 63393a7873eSAndreas Gohr 634a4337320SAndreas Gohr $this->opts = $this->loadServerConfig((string) $domain); 63593a7873eSAndreas Gohr if (isset($this->adldap[$domain])) return $this->adldap[$domain]; 636f4476bd9SJan Schumann 637f4476bd9SJan Schumann // connect 638f4476bd9SJan Schumann try { 63993a7873eSAndreas Gohr $this->adldap[$domain] = new adLDAP($this->opts); 64093a7873eSAndreas Gohr return $this->adldap[$domain]; 641a4337320SAndreas Gohr } catch (Exception $e) { 64232fd494aSAndreas Gohr if ($this->conf['debug']) { 643f4476bd9SJan Schumann msg('AD Auth: '.$e->getMessage(), -1); 644f4476bd9SJan Schumann } 645f4476bd9SJan Schumann $this->success = false; 64693a7873eSAndreas Gohr $this->adldap[$domain] = null; 647f4476bd9SJan Schumann } 648f4476bd9SJan Schumann return false; 649f4476bd9SJan Schumann } 650f4476bd9SJan Schumann 651f4476bd9SJan Schumann /** 65293a7873eSAndreas Gohr * Get the domain part from a user 653f4476bd9SJan Schumann * 654253d4b48SGerrit Uitslag * @param string $user 65593a7873eSAndreas Gohr * @return string 656f4476bd9SJan Schumann */ 657a4337320SAndreas Gohr public function getUserDomain($user) 658a4337320SAndreas Gohr { 659ab9790caSAndreas Gohr [, $domain] = sexplode('@', $user, 2, ''); 66093a7873eSAndreas Gohr return $domain; 661f4476bd9SJan Schumann } 662f4476bd9SJan Schumann 66393a7873eSAndreas Gohr /** 66493a7873eSAndreas Gohr * Get the user part from a user 66593a7873eSAndreas Gohr * 666916ef7cfSAndreas Gohr * When an account suffix is set, we strip the domain part from the user 667916ef7cfSAndreas Gohr * 668253d4b48SGerrit Uitslag * @param string $user 66993a7873eSAndreas Gohr * @return string 67093a7873eSAndreas Gohr */ 671a4337320SAndreas Gohr public function getUserName($user) 672a4337320SAndreas Gohr { 673916ef7cfSAndreas Gohr if ($this->conf['account_suffix'] !== '') { 674ab9790caSAndreas Gohr [$user] = explode('@', $user, 2); 675916ef7cfSAndreas Gohr } 676916ef7cfSAndreas Gohr return $user; 67793a7873eSAndreas Gohr } 67893a7873eSAndreas Gohr 67993a7873eSAndreas Gohr /** 68093a7873eSAndreas Gohr * Fetch the configuration for the given AD domain 68193a7873eSAndreas Gohr * 68293a7873eSAndreas Gohr * @param string $domain current AD domain 68393a7873eSAndreas Gohr * @return array 68493a7873eSAndreas Gohr */ 685a4337320SAndreas Gohr protected function loadServerConfig($domain) 686a4337320SAndreas Gohr { 68793a7873eSAndreas Gohr // prepare adLDAP standard configuration 68832fd494aSAndreas Gohr $opts = $this->conf; 68993a7873eSAndreas Gohr 69093a7873eSAndreas Gohr $opts['domain'] = $domain; 69193a7873eSAndreas Gohr 69293a7873eSAndreas Gohr // add possible domain specific configuration 69332fd494aSAndreas Gohr if ($domain && is_array($this->conf[$domain])) foreach ($this->conf[$domain] as $key => $val) { 69493a7873eSAndreas Gohr $opts[$key] = $val; 69593a7873eSAndreas Gohr } 69693a7873eSAndreas Gohr 69793a7873eSAndreas Gohr // handle multiple AD servers 69893a7873eSAndreas Gohr $opts['domain_controllers'] = explode(',', $opts['domain_controllers']); 69993a7873eSAndreas Gohr $opts['domain_controllers'] = array_map('trim', $opts['domain_controllers']); 70093a7873eSAndreas Gohr $opts['domain_controllers'] = array_filter($opts['domain_controllers']); 70193a7873eSAndreas Gohr 7028257d713SAndreas Gohr // compatibility with old option name 70364159a61SAndreas Gohr if (empty($opts['admin_username']) && !empty($opts['ad_username'])) { 70464159a61SAndreas Gohr $opts['admin_username'] = $opts['ad_username']; 70564159a61SAndreas Gohr } 70664159a61SAndreas Gohr if (empty($opts['admin_password']) && !empty($opts['ad_password'])) { 70764159a61SAndreas Gohr $opts['admin_password'] = $opts['ad_password']; 70864159a61SAndreas Gohr } 709342753d2SAndreas Gohr $opts['admin_password'] = conf_decodeString($opts['admin_password']); // deobfuscate 7108257d713SAndreas Gohr 71193a7873eSAndreas Gohr // we can change the password if SSL is set 712a847f473Spluto00987 if ($opts['update_pass'] && ($opts['use_ssl'] || $opts['use_tls'])) { 71393a7873eSAndreas Gohr $this->cando['modPass'] = true; 71493a7873eSAndreas Gohr } else { 71593a7873eSAndreas Gohr $this->cando['modPass'] = false; 71693a7873eSAndreas Gohr } 71793a7873eSAndreas Gohr 71812d195abSAndreas Gohr // adLDAP expects empty user/pass as NULL, we're less strict FS#2781 71912d195abSAndreas Gohr if (empty($opts['admin_username'])) $opts['admin_username'] = null; 72012d195abSAndreas Gohr if (empty($opts['admin_password'])) $opts['admin_password'] = null; 72112d195abSAndreas Gohr 72212d195abSAndreas Gohr // user listing needs admin priviledges 7238257d713SAndreas Gohr if (!empty($opts['admin_username']) && !empty($opts['admin_password'])) { 72493a7873eSAndreas Gohr $this->cando['getUsers'] = true; 72593a7873eSAndreas Gohr } else { 7261b228d28SKlap-in $this->cando['getUsers'] = false; 72793a7873eSAndreas Gohr } 72893a7873eSAndreas Gohr 72993a7873eSAndreas Gohr return $opts; 73093a7873eSAndreas Gohr } 73193a7873eSAndreas Gohr 73293a7873eSAndreas Gohr /** 733741b8a48SAndreas Gohr * Returns a list of configured domains 734741b8a48SAndreas Gohr * 735741b8a48SAndreas Gohr * The default domain has an empty string as key 736741b8a48SAndreas Gohr * 737741b8a48SAndreas Gohr * @return array associative array(key => domain) 738741b8a48SAndreas Gohr */ 739a4337320SAndreas Gohr public function getConfiguredDomains() 740a4337320SAndreas Gohr { 741ab9790caSAndreas Gohr $domains = []; 742741b8a48SAndreas Gohr if (empty($this->conf['account_suffix'])) return $domains; // not configured yet 743741b8a48SAndreas Gohr 744741b8a48SAndreas Gohr // add default domain, using the name from account suffix 745741b8a48SAndreas Gohr $domains[''] = ltrim($this->conf['account_suffix'], '@'); 746741b8a48SAndreas Gohr 747741b8a48SAndreas Gohr // find additional domains 748741b8a48SAndreas Gohr foreach ($this->conf as $key => $val) { 749741b8a48SAndreas Gohr if (is_array($val) && isset($val['account_suffix'])) { 750741b8a48SAndreas Gohr $domains[$key] = ltrim($val['account_suffix'], '@'); 751741b8a48SAndreas Gohr } 752741b8a48SAndreas Gohr } 7530489c64bSMoisés Braga Ribeiro Sort::ksort($domains); 754741b8a48SAndreas Gohr 755741b8a48SAndreas Gohr return $domains; 756741b8a48SAndreas Gohr } 757741b8a48SAndreas Gohr 758741b8a48SAndreas Gohr /** 75993a7873eSAndreas Gohr * Check provided user and userinfo for matching patterns 76093a7873eSAndreas Gohr * 76193a7873eSAndreas Gohr * The patterns are set up with $this->_constructPattern() 76293a7873eSAndreas Gohr * 76393a7873eSAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 764253d4b48SGerrit Uitslag * 76593a7873eSAndreas Gohr * @param string $user 76693a7873eSAndreas Gohr * @param array $info 76793a7873eSAndreas Gohr * @return bool 76893a7873eSAndreas Gohr */ 769a4337320SAndreas Gohr protected function filter($user, $info) 770a4337320SAndreas Gohr { 771a4337320SAndreas Gohr foreach ($this->pattern as $item => $pattern) { 77293a7873eSAndreas Gohr if ($item == 'user') { 77393a7873eSAndreas Gohr if (!preg_match($pattern, $user)) return false; 77493a7873eSAndreas Gohr } elseif ($item == 'grps') { 77593a7873eSAndreas Gohr if (!count(preg_grep($pattern, $info['grps']))) return false; 776ab9790caSAndreas Gohr } elseif (!preg_match($pattern, $info[$item])) { 777ab9790caSAndreas Gohr return false; 77893a7873eSAndreas Gohr } 77993a7873eSAndreas Gohr } 78093a7873eSAndreas Gohr return true; 78193a7873eSAndreas Gohr } 78293a7873eSAndreas Gohr 78393a7873eSAndreas Gohr /** 78493a7873eSAndreas Gohr * Create a pattern for $this->_filter() 78593a7873eSAndreas Gohr * 78693a7873eSAndreas Gohr * @author Chris Smith <chris@jalakai.co.uk> 787253d4b48SGerrit Uitslag * 78893a7873eSAndreas Gohr * @param array $filter 78993a7873eSAndreas Gohr */ 790a4337320SAndreas Gohr protected function constructPattern($filter) 791a4337320SAndreas Gohr { 792ab9790caSAndreas Gohr $this->pattern = []; 793f4476bd9SJan Schumann foreach ($filter as $item => $pattern) { 794a4337320SAndreas Gohr $this->pattern[$item] = '/'.str_replace('/', '\/', $pattern).'/i'; // allow regex characters 795f4476bd9SJan Schumann } 796f4476bd9SJan Schumann } 797f4476bd9SJan Schumann} 798