From: Nicolas Boisselier Date: Thu, 31 Jan 2019 00:25:51 +0000 (+0000) Subject: www/dbq/dbq.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=da1907e1c67b7ca206ed3aedbf3449e52a6aa1b9;p=nb.git www/dbq/dbq.php --- diff --git a/lib/php/nb.php b/lib/php/nb.php index eb3fd9ee..7244d46f 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -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)); diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index ec97e872..79cb3a53 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -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));