]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 31 Jan 2019 00:25:51 +0000 (00:25 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 31 Jan 2019 00:25:51 +0000 (00:25 +0000)
lib/php/nb.php
www/dbq/dbq.php

index eb3fd9ee67f3f8853345b9679b88741d63452487..7244d46fb19dce4bc025139fbe10360aaaebf1ec 100644 (file)
@@ -981,12 +981,12 @@ class NB {
                }
                if (!empty($key)) $cipher->setIV($key);
                return $cipher;
-               return self::_encrypt_decrypt_object($key)->decrypt($value);
+# NB 31.01.19          return self::_encrypt_decrypt_object($key)->decrypt($value);
        }
 
-       public static function cryptkey($length=32) {
+       public static function random_str($length=32) {
                if (!OLD_CRYPT) {
-                       self::_encrypt_decrypt_object();
+                       self::_encrypt_decrypt_object(null);
                        return substr(bin2hex(crypt_random_string(($length/2)+1)),0,$length);
                }
                return bin2hex(mcrypt_create_iv($length/2, MCRYPT_DEV_URANDOM));
index ec97e87268b0020393b8bc5dadddc978fa161323..79cb3a530d3d4583259c8cbec57b0767e205c9e5 100644 (file)
@@ -27,14 +27,12 @@ class DbQ extends nb {
        const PARAM_DB_DEFAULT = 'ls';
        
        const READ = 9;
-
        const ADD = 13;
        const UPDATE = 15;
        const WRITE = 19;
-
        const DELETE = 29;
-
        const ADMIN = 99;
+
        public $perm = self::ADMIN;
        public $perms = [ # keys in lowercase !!!!
                'read' => self::READ,
@@ -1180,12 +1178,47 @@ EOF;
                foreach (['table','action','args'] as $k) { if (!empty($this->params[$k])) $arg[] = $this->params[$k]; }
                $arg = join('/',$arg);
 
+               ## NB 30.01.19: >>>>> 
+               ## NB 30.01.19: Test with config 
+               $conf_run = function($conf,$action) use ($arg) {
+                       foreach ($conf as $cmd) {
+                               $action_ = $cmd[0];
+                               $laius = $cmd[1];
+                               $fct = $cmd[2];
+                               $perm = empty($cmd[3]) ? 0 : $cmd[3];
+
+                               if ($action != $action_) continue;
+                               $this->deniedUnless(!$perm or $this->perm >= $perm);
+                               #debug($action_);
+                               echo "Hi\n";
+                               $fct();
+                       }
+               };
+               $conf = [ 
+                       'root' => [
+                               [ 'help', 'This help', function() { $this->page($this->db,$conf['root']); } ],
+                               [ 'ls', 'List configured databases', function() {
+                                       $this->page($this->db,'ls',[],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'].'"');
+                                       });
+                               } ],
+                               [ 'random_str', 'Generate a random string', function() { $this->page($this->random_str()); } ],
+# NB 30.01.19                          [ 'databases', 'List others databases', function() {
+# NB 30.01.19                                  $this->page($this->db,'databases');
+# NB 30.01.19                          }, self::ADMIN ],
+                       ],
+               ];
+               $conf_run($conf['root'],$action);
+               ## NB 30.01.19: <<<<< 
+
                if ($action == 'help') {
+
                        $this->page($this->db,[
                                [ 'help', 'This help' ],
                                [ 'ls', 'List configured databases' ],
                                [ 'databases', 'List others databases' ],
-                               [ 'cryptkey', 'Generate a random encryption key' ],
+                               [ 'random_str', 'Generate a random string' ],
                                [ 'ssha_password', 'Encrypt a password' ],
                                [ 'ssha512_password', 'Encrypt a password' ],
                                [ 'logout', 'Clear Basic Auth' ],
@@ -1220,8 +1253,7 @@ EOF;
                } elseif ($action == 'logout') { $this->page($this,'logout'); 
                } elseif ($action == 'ssha_password') { $this->page($this,'ssha_password');
                } elseif ($action == 'ssha512_password') { $this->page($this,'ssha512_password');
-# NB 03.02.18          } elseif ($action == 'cryptkey') { $this->page($this,'cryptkey',['key']);
-               } elseif ($action == 'cryptkey') { $this->page($this->cryptkey());
+               } elseif ($action == 'random_str') { $this->page($this->random_str());
                } elseif ($action == 'status') { $this->page($this,'status');
                } elseif ($action == 'conf') { $this->page($this,'conf');
                } elseif ($action == 'html') { $this->page(Mime::html($arg));