$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'] = [
}
- 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 = [
$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);