]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Nov 2024 22:07:36 +0000 (23:07 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Nov 2024 22:07:36 +0000 (23:07 +0100)
www/dbq/dbq.php
www/dbq/html/default.js

index 5db3b65607f08007a8b3b510d1d072a9ce55cca1..a537be735d1d687a0d565df33e17885f8dacbc22 100644 (file)
@@ -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
                                                ? ''
index 8e5d2a02e1d2f9f1f8360986592c0987a2d0a593..915c65b2188814ce34a9cd700afaef0cc1d4829d 100644 (file)
@@ -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;
 }