]> git.nbdom.net Git - nb.git/commitdiff
phpseclib
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 22 Jan 2019 03:32:57 +0000 (04:32 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 22 Jan 2019 03:32:57 +0000 (04:32 +0100)
etc/dbq/ldap.php
lib/php/db.php
www/dbq/dbq.php

index 3e24856458ba5a4f51a38c665d7f3e7fb368839f..a4444420b22ba195aaeae66e7deeece0927bbf39 100644 (file)
@@ -44,14 +44,18 @@ $GLOBALS['DBQ_LDAP'] = [
 
 if (preg_match('/^([^,]+),(.*?)$/',$user,$m)) {
        $filter = $m[1];
+
+} elseif($user) {
+       $filter = 'cn='.$user;
+
 } else {
-       $filter = 'cn='.Http::user();
+       $filter = 'cn=';
 }
 $filter = '(&('.$filter.')(userPassword=*))';
 
 $DBQ['ldap'] = $GLOBALS['DBQ_LDAP'] + [
        'name' => $base,
-       'title' => 'nbdom.net',
+       'title' => 'Ldap',
        'type' => 'ldap',
        'tables' => [
                'me' => [
index dfe27487e5f961aacf02e13b2caf5ec93f4ebfec..3c5c22a7f9a1209e01cc3321ae454797efc8da6c 100644 (file)
@@ -709,24 +709,52 @@ class Db extends nb {
                return $return;
        }
 
-       /**
-       * @copyright NB 05.03.16
-       * @param [FILES] $files Files to load
-       * @return ARRAY the new/existing value of $this->db
-       */
-       public static function ar_merge($a,$b) {
+       private static function ar_merge($a,$b) {
                return array_replace_recursive($a,$b);
+               #return array_merge_recursive($a,$b);
                #return array_combine($a,$b);
+
+               /* From doc
+               */
+               foreach ($b as $key => $value ) {
+
+      if (is_array($value)) {
+        if (!isset($a[$key])) {
+          $a[$key] = [];
+        }
+        $a[$key] = self::ar_merge($a[$key], $value);
+      
+      } elseif (isset($a[$key]) and is_array($a[$key])) {
+        if (!isset($value)) {
+          $value = [];
+        }
+        $a[$key] = self::ar_merge($a[$key], $value);
+
+      } else {
+        $a[$key] = $value;
+
+      }
+
+    }
+    return $a;
+
                $n = $a;
                foreach ($b as $k=>$v) {
-                       if (!empty($n[$k]) and is_array($v)) {
-                               $v = array_combine($n[$k],$v);
+
+                       if (!empty($n[$k])) {
+                               $v = array_merge_recursive($n[$k],(array)$v);
                        }
+
                        $n[$k] = $v;
                }
                return $n;
        }
 
+       /**
+       * @copyright NB 05.03.16
+       * @param [FILES] $files Files to load
+       * @return ARRAY the new/existing value of $this->db
+       */
        public static function conf_load($files=[],&$first=false) {
                if (empty($files)) return [];
 
@@ -762,25 +790,49 @@ class Db extends nb {
                #
                # First iteration: Import database conf with key _import
                #
+# NB 22.01.19          foreach (self::$dbq as $id=>$params) {
+# NB 22.01.19                  $params = (array)$params;
+# NB 22.01.19 
+# NB 22.01.19                  foreach ($params as $k => $v) {
+# NB 22.01.19                          if ($k != '_import') continue;
+# NB 22.01.19 
+# NB 22.01.19                          $import = is_array($v) ? $v : explode(',',$v);
+# NB 22.01.19                          #debug(join(', ',$import));
+# NB 22.01.19                          foreach ($import as $v) {
+# NB 22.01.19                                  if ($id == $v) self::bye("Infinite loop: _import $id = $v");
+# NB 22.01.19                                  if (empty(self::$dbq[$v])) continue;
+# NB 22.01.19 
+# NB 22.01.19                                  foreach (self::$dbq[$v] as $kk => $vv) {
+# NB 22.01.19                                          if (!isset($params[$kk])) self::$dbq[$id][$kk] = $vv;
+# NB 22.01.19                                  }
+# NB 22.01.19                          }
+# NB 22.01.19 
+# NB 22.01.19                          unset(self::$dbq[$id][$k]);
+# NB 22.01.19                  }
+# NB 22.01.19          }
+
+               # We use ar_merge
                foreach (self::$dbq as $id=>$params) {
-                       $params = (array)$params;
-
-                       foreach ($params as $k => $v) {
-                               if ($k != '_import') continue;
+                       if (empty(self::$dbq[$id]['_import'])) continue;
 
-                               $import = is_array($v) ? $v : explode(',',$v);
-                               foreach ($import as $v) {
-                                       if ($id == $v) self::bye("Infinite loop: _import $id = $v");
-                                       if (empty(self::$dbq[$v])) continue;
+                       $v = self::$dbq[$id]['_import'];
+                       $import = is_array($v) ? $v : explode(',',$v);
 
-                                       foreach (self::$dbq[$v] as $kk => $vv) {
-                                               if (!isset($params[$kk])) self::$dbq[$id][$kk] = $vv;
-                                       }
-                               }
+                       unset(self::$dbq[$id]['_import']);
 
-                               unset(self::$dbq[$id][$k]);
+                       foreach ($import as $i) {
+                               if (!isset(self::$dbq[$i])) continue;
+                               self::$dbq[$id] = self::ar_merge(self::$dbq[$id],self::$dbq[$i]);
+                               #debug([$id,self::$dbq[$id]['tables']]);
+                               #debug([$id,self::$dbq[$i]['tables']]);
                        }
+
                }
+               /*
+               foreach (self::$dbq as $id=>$params) {
+                       unset(self::$dbq[$id]['_import']);
+               }
+               */
 
                $default = isset(self::$dbq['_default']) ? self::$dbq['_default'] : [];
 
@@ -1003,11 +1055,6 @@ class Db extends nb {
                if ($insert === null) $insert = self::p('insert');
                if (empty($db_type)) $db_type = self::p('db-type');
 
-               # Params ! dirty !
-# NB 10.01.18     $this->pset('orderby',null);
-# NB 10.01.18     $this->pset('extras','0');
-# NB 10.01.18     $this->pset('format','sql');
-
                # Filters
                $type = self::p('table-type',''); $type = $type ? explode(',',$type) : $type;
                $name = self::p('table-name',''); $name = $name ? explode(',',$name) : $name;
index dab1e89fbe04de33e8ab972ff649346d6b7f6572..ec97e87268b0020393b8bc5dadddc978fa161323 100644 (file)
@@ -508,12 +508,13 @@ class DbQ extends nb {
                $this->table->html_edit($values, $this->table->base . '/' . ($add ? 'insert' : 'update') ,$add);
        }
 
-       public function table_rw() {
+       private function table_rw() {
                return (int)(1
                        and ($this->perm >= self::READ)
                        and !empty($this->table)
+# NB 22.01.19                  and ( $this->table->type() == 'sql'  or strpos('table view',$this->table->type()) !== false )
                        and !empty($this->table->type())
-                               and ( strpos('table view',$this->table->type()) !== false )
+                       and ( strpos('table view',$this->table->type()) !== false )
                );
        }
 
@@ -560,7 +561,8 @@ class DbQ extends nb {
                $this->row_parse_post();
 
                $opt = ($this->is_html
-                       and $this->table_rw()
+                       #and $this->table_rw()
+                       and ($this->perm >= self::READ)
                        and empty($this->_nopage)
                ) ? [
                        'row_parse_pre' => function(&$r){
@@ -580,6 +582,10 @@ class DbQ extends nb {
 
                                if ($this->perm < self::DELETE) return;
                                static $delete = 1;
+
+                               # NB 22.01.19: Only table, and view ? 
+                               if ( strpos('table view',$this->table->type()) === false ) $delete = 0;
+
                                if (empty($delete)) {
                                        $delete = ($this->db->type == 'sqlite' and !is_writeable($this->db->host));
                                }