]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 28 Jan 2018 04:04:03 +0000 (04:04 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 28 Jan 2018 04:04:03 +0000 (04:04 +0000)
etc/dbq/ldap.php
www/dbq/dbq.php

index 1729cf0790e03214ecaeb3bd96c9e0834efb0454..4a147c22d53bf4d979c89cdeabf81743681b705b 100644 (file)
@@ -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'] = [
index 4a7252bcc07574e9b658ece9cb25a4af0e103bd8..2c5dea850c7785611486769a466e30cbbfe484d7 100644 (file)
@@ -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);