From bc153d935e24989eb4b25232fa34c22149c6d965 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 20 Nov 2024 23:07:36 +0100 Subject: [PATCH] www/dbq/dbq.php --- www/dbq/dbq.php | 102 ++++++++++++++++++++++++++-------------- www/dbq/html/default.js | 5 +- 2 files changed, 70 insertions(+), 37 deletions(-) diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 5db3b656..a537be73 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -47,10 +47,10 @@ class DbQ extends nb { public $formats = [ 'html','div.html','csv','xml','json','yaml','sh','sql','php' ]; public $format_cli = 'csv'; public $format_html = 'table'; - public $format_html_ua_exp = '/^\S+\s+.Windows|iPhone|Android|Macintosh|Linux/'; + private $format_html_ua_exp = '/^\S+\s+.Windows|iPhone|Android|Macintosh|Linux/'; - public $hide_keys_exp = 'PHP_AUTH_DIGEST|PHP_AUTH_PW|PHP_AUTH_USER|REMOTE_PASSWORD|Authorization|HTTP_AUTHORIZATION'; - public $hide_keys_value = '****************'; + private $hide_keys_exp = 'PHP_AUTH_DIGEST|PHP_AUTH_PW|PHP_AUTH_USER|REMOTE_PASSWORD|Authorization|HTTP_AUTHORIZATION'; + private $hide_keys_value = '****************'; public $uri; public $uri_params; @@ -1148,35 +1148,35 @@ EOF; $arg = []; foreach (['table','action','args'] as $k) { if (!empty($this->params[$k])) $arg[] = $this->params[$k]; } $arg = join('/',$arg); + $help = array_merge( + [ + [ 'help', 'This help' ], + [ 'ls', 'List configured databases' ], + # NB 14.12.22 [ 'databases', 'List others databases' ], + [ 'random_str', 'Generate a random string' ], + [ 'ssha_password', 'Encrypt a password' ], + [ 'ssha512_password', 'Encrypt a password' ], + [ 'random_str', 'Generate a random str' ], + [ 'logout', 'Clear Basic Auth' ], + [ 'status', 'Status infos page' ], + [ 'conf', 'Dump api infos and params' ], + [ 'types', 'Available mime types for output' ], + ], + ( + ($this->perm < self::ADMIN) ? [] : + [ + [ 'phpinfo', 'Phpinfo' ], + [ '_SERVER', 'Dump _SERVER' ], + [ '_REQUEST', 'Dump _REQUEST' ], + ] + ) + ); if ($action == 'help') { $this->page($this->db # Rows - ,array_merge( - [ - [ 'help', 'This help' ], - [ 'ls', 'List configured databases' ], - # NB 14.12.22 [ 'databases', 'List others databases' ], - [ 'random_str', 'Generate a random string' ], - [ 'ssha_password', 'Encrypt a password' ], - [ 'ssha512_password', 'Encrypt a password' ], - [ 'ssha512_password', 'Encrypt a password' ], - [ 'random_str', 'Generate a random str' ], - [ 'logout', 'Clear Basic Auth' ], - [ 'status', 'Status infos page' ], - [ 'conf', 'Dump api infos and params' ], - [ 'types', 'Available mime types for output' ], - ], - ( - ($this->perm < self::ADMIN) ? [] : - [ - [ 'phpinfo', 'Phpinfo' ], - [ '_SERVER', 'Dump _SERVER' ], - [ '_REQUEST', 'Dump _REQUEST' ], - ] - ) - ) + ,$help # Head ,['command','description'] # Print @@ -1191,6 +1191,34 @@ EOF; }) ; + } elseif ($action == 'ls') { + + $rows = []; + foreach ($this->db->ls() as $i) { + #$rows[] = [ 'id' => $i['id'], 'name' => $i['name'] ]; + $rows[] = $i; + } + + if ($this->perm >= self::ADMIN) { + #$rows[] = [ 'id' => '----------', 'name' => '----------' ]; + foreach ($help as $i) { + if ($i[0] === 'ls') continue; + $rows[] = [ + 'id' => $i[0], + 'name' => $i[0], + 'title' => $i[1], + 'type' => 'function', + 'host' => '', + ]; + } + } + + #$rows = $this->db->ls(); + $this->page($rows,'',[],function(&$r){ + if ($this->perm < self::ADMIN) unset($r['host'],$r['type']); + $r['id'] = $this->page->tag('a',$r['id'],'href="'.$this->db->base.'/'.$r['id'].'"'); + }); + } elseif ($action == 'ls') { $this->page($this->db,'ls',[],function(&$r){ @@ -1326,16 +1354,18 @@ EOF; $action = $this->params['table']; if (!$action and self::PARAM_DB_DEFAULT) $action = self::PARAM_DB_DEFAULT; + $help = [ + [ 'help', 'This help' ], + [ 'status', 'Database status' ], + [ 'ls', 'List tables [type,name,count,fields]' ], + [ 'databases', 'List databases' ], + [ 'schema', 'Dump database structure only [/DB_TYPE]' ], + [ 'dump', 'Dump database structure with datas [/DB_TYPE]' ], + [ 'csv', 'Dump database data in csv with table name as first colum' ], + ]; + if ($action == 'help') { - $this->page($this->db,[ - [ 'help', 'This help' ], - [ 'status', 'Database status' ], - [ 'ls', 'List tables [type,name,count,fields]' ], - [ 'databases', 'List databases' ], - [ 'schema', 'Dump database structure only [/DB_TYPE]' ], - [ 'dump', 'Dump database structure with datas [/DB_TYPE]' ], - [ 'csv', 'Dump database data in csv with table name as first colum' ], - ],['command','description'],function(&$r){ + $this->page($this->db,$help,['command','description'],function(&$r){ $r['command'] = $this->page->tag('a',$r['command'],'href="' .$this->db->base.'/'.($r['command'] == self::PARAM_DB_DEFAULT ? '' diff --git a/www/dbq/html/default.js b/www/dbq/html/default.js index 8e5d2a02..915c65b2 100644 --- a/www/dbq/html/default.js +++ b/www/dbq/html/default.js @@ -170,9 +170,10 @@ function dbqLoad(DBQ) { var s = o.select(fields[0],fields[1], window._dbq['param.'+cname]); // Add missing is action is not db + console.log(title); var exists = 0; for (const option of s.options) { - console.log(title + ' <> ' + option.value); + //console.log(title + ' <> ' + option.value); if (option.value != title && option.innerHTML != title) continue; exists = 1; break; @@ -282,8 +283,10 @@ function dbqGet(url,callback) { } function dbqPrettyText(str) { + var strSave = str; str = str.replace(/(\b\w)/g,function(m){return m.toUpperCase();}); str = str.replace(/[^a-zA-Z0-9]+/g,' '); + if (!str.length) return strSave; return str; } -- 2.47.3