From dc24ddf1e157aed809e1f13ef5807e914e6ac586 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 28 Jan 2018 04:04:03 +0000 Subject: [PATCH] www/dbq/dbq.php --- etc/dbq/ldap.php | 26 +++++++++++++++++--------- www/dbq/dbq.php | 35 ++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/etc/dbq/ldap.php b/etc/dbq/ldap.php index 1729cf07..4a147c22 100644 --- a/etc/dbq/ldap.php +++ b/etc/dbq/ldap.php @@ -10,19 +10,27 @@ if (isset($_SERVER['HTTP_HOST'])) { $password = ''; } -$base = ''; $host = ''; -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]; +$base = ''; + +if (!empty($_SERVER['DBQ_LDAP_HOST'])) $host = $_SERVER['DBQ_LDAP_HOST']; +if (!empty($_SERVER['DBQ_LDAP_BASE'])) $base = $_SERVER['DBQ_LDAP_BASE']; + +if (0 + or $host == '' + or $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]; + elseif (preg_match('/^HOST\s+([^\s#]+)/i',$line,$m)) $host = $m[1]; + } + break; } - break; } -#if (!empty($_SERVER['DBQ_LDAP_BASE'])) $base = $_SERVER['DBQ_LDAP_BASE']; $suff = empty($_SERVER['DBQ_LDAP_USER_SUFF']) ? '' : $_SERVER['DBQ_LDAP_USER_SUFF']; #debug($_SERVER); $GLOBALS['DBQ_LDAP'] = [ diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 4a7252bc..2c5dea85 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -169,33 +169,36 @@ class DbQ extends nb { } - public function ldap() { - $this->deniedUnless($this->perm >= self::READ); - #$this->deniedUnless($this->perm >= self::ADMIN); + public function ldap($table='',$attrs=[]) { + $this->deniedUnless($this->perm >= self::ADMIN); + +# NB 28.01.18 if (!$table) $table = $this->params['table']; +# NB 28.01.18 if (!$attrs) $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []); require_once(NB_ROOT.'/lib/php/ldap.php'); #debug($GLOBALS['DBQ_LDAP']); $ldap = new Ldap($GLOBALS['DBQ_LDAP']); - if ($this->params['table'] == 'add') { + if ($table == 'add') { $this->deniedUnless($this->perm >= self::WRITE); - $rows = (int)$ldap->add($this->params['action'],$_POST); + $rows = (int)$ldap->add($attrs,$_POST); - } elseif ($this->params['table'] == 'update') { + } elseif ($table == 'update') { $this->deniedUnless($this->perm >= self::WRITE); - $rows = (int)$ldap->update($this->params['action'],$_POST); + $rows = (int)$ldap->update($attrs,$_POST); - } elseif ($this->params['table'] == 'rm') { + } elseif ($table == 'rm') { $this->deniedUnless($this->perm >= self::DELETE); - $rows = (int)$ldap->delete($this->params['action'],$_POST); + $rows = (int)$ldap->delete($attrs,$_POST); - } else { // Search - $filter = ($this->params['table'] ? $this->params['table'] : ''); - $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []); + } else { // ls + $this->deniedUnless($this->perm >= self::READ); + + $filter = ($table ? $table : ''); - if (!empty($this->params['table']) and !strpos($this->params['table'],'=')) { + if (!empty($table) and !strpos($table,'=')) { $filter = ''; - $attrs = explode(',',$this->params['table']); + $attrs = explode(',',$table); } $search = [ @@ -1128,7 +1131,9 @@ EOF; $this->page($types); } elseif ($action == 'ldap') { - $this->page($this->ldap()); + $table = $this->params['table']; + $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []); + $this->page($this->ldap($table,$attrs)); } elseif ($action == 'phpinfo') { $this->deniedUnless($this->perm >= self::ADMIN); -- 2.47.3