From: Nicolas Boisselier Date: Wed, 24 Jan 2018 03:34:51 +0000 (+0000) Subject: www/dbq/dbq.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=2b16a7581f4c3d77a44d0ce00125a120ebb54095;p=nb.git www/dbq/dbq.php --- diff --git a/etc/dbq/ldap.php b/etc/dbq/ldap.php new file mode 100644 index 00000000..d57ae0eb --- /dev/null +++ b/etc/dbq/ldap.php @@ -0,0 +1,35 @@ + 'cn=' . $user . ',' . $suff . $base, + 'password' => $password, + 'host' => $host, + 'base' => $base, +]; +#debug($GLOBALS['DBQ_LDAP']); +?> diff --git a/lib/php/ldap.php b/lib/php/ldap.php index b03d7737..0318f787 100644 --- a/lib/php/ldap.php +++ b/lib/php/ldap.php @@ -129,8 +129,7 @@ class Ldap { private $conn; public function __construct($opt = []) { - foreach ($opt as $k => $v) $this->$k = $v; - #if (isset($this->search)) return $this->_search($this->search); + foreach ($opt as $k => $v) if ((string)$v !== '') $this->$k = $v; } public function __destruct() { diff --git a/lib/php/nb.php b/lib/php/nb.php index 9dd3ede0..f7ce4fcc 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -1,6 +1,7 @@ params); $this->deniedUnless($this->perm >= self::READ); $filter = ($this->params['table'] ? $this->params['table'] : ''); $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []); @@ -178,36 +180,24 @@ class DbQ extends nb { $attrs = explode(',',$this->params['table']); } - # Get server and base from host or ldap.conf - # NB 23.01.18: TODO - if (isset($_SERVER['HTTP_HOST']) and preg_match('/^.*?([^\.]+\.[^\.]+)$/',$_SERVER['HTTP_HOST'],$m)) { - $host = 'ldap.'.$m[1]; - $base = 'dc=' . str_replace('.',',dc=',preg_replace('/^ldap[^.]*./','',$host)); - } else { - $host = '127.0.0.1'; - $base = ''; - foreach (array_unique(glob('~/.ldap.conf')+glob('/etc/ldap/ldap.conf')) as $f) { - if (!is_readable($f)) continue; - foreach (file($f,FILE_SKIP_EMPTY_LINES + FILE_IGNORE_NEW_LINES) as $line) { - $line = trim($line); - if (preg_match('/^BASE\s+([^\s#]+)/i',$line,$m)) $base = $m[1]; - if (preg_match('/^HOST\s+([^\s#]+)/i',$line,$m)) $host = $m[1]; - } - break; - } - } - $preff = (!empty($_SERVER['DBQ_LDAP_BIND_DN_PREFF']) ? 'ou='.$_SERVER['DBQ_LDAP_BIND_DN_PREFF'] : ''); - #$base = $preff . $base; - #$ldap = new Ldap([ ]); $search = [ 'filter' => $filter, 'attrs' => $attrs, ]; - $rows = Ldap::search([ - 'bind_dn_preff' => (!empty($_SERVER['DBQ_LDAP_BIND_DN_PREFF']) ? 'ou='.$_SERVER['DBQ_LDAP_BIND_DN_PREFF'] : 'ou=auth'), - 'exit_on_err' => $this->p('err',true), - ]+$search); + if (false and !empty($GLOBALS['DBQ_LDAP'])) { + #debug($GLOBALS['DBQ_LDAP']); + $ldap = new Ldap($GLOBALS['DBQ_LDAP']); + if (!$search['filter']) { + $search['filter'] = 'cn='.Http::user(); + } + $rows = $ldap->_search($GLOBALS['DBQ_LDAP'] + $search); + } else { + $rows = Ldap::search([ + 'bind_dn_preff' => (!empty($_SERVER['DBQ_LDAP_BIND_DN_PREFF']) ? 'ou='.$_SERVER['DBQ_LDAP_BIND_DN_PREFF'] : 'ou=auth'), + 'exit_on_err' => $this->p('err',true), + ]+$search); + } #echo $rows[0]['jpegPhoto']; exit; #$rows = [ 'jpegPhoto' => $rows[0]['jpegPhoto'] ];