From 5f64179de9029b099115304913889fd8e6d0ec92 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 22 Jan 2019 04:32:57 +0100 Subject: [PATCH] phpseclib --- etc/dbq/ldap.php | 8 +++- lib/php/db.php | 99 +++++++++++++++++++++++++++++++++++------------- www/dbq/dbq.php | 12 ++++-- 3 files changed, 88 insertions(+), 31 deletions(-) diff --git a/etc/dbq/ldap.php b/etc/dbq/ldap.php index 3e248564..a4444420 100644 --- a/etc/dbq/ldap.php +++ b/etc/dbq/ldap.php @@ -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' => [ diff --git a/lib/php/db.php b/lib/php/db.php index dfe27487..3c5c22a7 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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; diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index dab1e89f..ec97e872 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -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)); } -- 2.47.3