From e08c33e299993eb5f6a7f2a7b62f1ab1b052773a Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 13 Dec 2016 02:00:17 +0100 Subject: [PATCH] dbq --- etc/dbq/000-local.php | 3 ++- lib/php/db.php | 10 +++---- www/dbq/dbq.php | 49 +++++++++++++++++++++++----------- www/dbq/etc/nginx/default.conf | 4 +++ 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/etc/dbq/000-local.php b/etc/dbq/000-local.php index d5d6aebd..9bebb26f 100644 --- a/etc/dbq/000-local.php +++ b/etc/dbq/000-local.php @@ -2,7 +2,8 @@ # # !!! MANDATORY !!! # -if (true or !nb::is_vm()) $DBQ = [ +# NB 12.12.16 if (true or !nb::is_vm()) +$DBQ = [ # NB 29.11.16 'shell' => [ # NB 29.11.16 'type' => 'sqlite', # NB 29.11.16 'name' => 'shell', diff --git a/lib/php/db.php b/lib/php/db.php index f9c63997..04e1b1a5 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -7,9 +7,9 @@ *****************************************************************************/ require_once(realpath(dirname(__FILE__).'/nb.php')); -require_once(realpath(dirname(__FILE__).'/out.php')); -require_once(realpath(dirname(__FILE__).'/db/table.php')); -require_once(realpath(dirname(__FILE__).'/db/field.php')); +require_once(NB_ROOT.'/lib/php/out.php'); +require_once(NB_ROOT.'/lib/php/db/table.php'); +require_once(NB_ROOT.'/lib/php/db/field.php'); $DB_TYPES = []; # See db/types/*.php #$arr = ['rent'=>'Rent','nb'=>'Nb']; #if (!empty($argv) and $argv[1] == 'zaza') bye($arr); @@ -452,7 +452,7 @@ class Db extends nb { if (empty($type)) self::bye('Db type is required'); if (empty($require[$type])) { - $require[$type] = dirname(__FILE__).'/db/types/'.$type.'.php'; + $require[$type] = NB_ROOT.'/lib/php/db/types/'.$type.'.php'; if (!file_exists($require[$type])) self::bye("Unknown type `$type`"); $require[$type] = dirname(__FILE__).'/db/types/'.$type.'.php'; require_once($require[$type]); @@ -1297,7 +1297,7 @@ class Db extends nb { } public function page($opt=[]) { - require_once(realpath(dirname(__FILE__).'/page.php')); + require_once(NB_ROOT.'/lib/php/page.php'); return new Page(array_merge([ 'title' => ($this->title ? $this->title : this::prettyText($this->name)), 'css' => [ diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 987f9e84..479e80fd 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -1,20 +1,21 @@ 'human', 'db' => self::PARAM_DB_DEFAULT, @@ -49,7 +50,7 @@ class DbQ extends nb { public $db; public function __construct($opt=[]) { - #debug(self::READ); + #debug(self::VIEW); // Pre defaults values $this->params['format'] = (!empty($_SERVER['HTTP_USER_AGENT']) and @@ -59,6 +60,16 @@ class DbQ extends nb { : $this->params['format'] ; + // Envs + foreach ([ + ] as $k) { + $env = 'DBQ_PARAM_'.strtoupper($k); + if (!empty($_SERVER[$env])) $this->env = $_SERVER[$env]; + } + if (!empty($_SERVER['DBQ_CSS'])) $this->css = $_SERVER['DBQ_CSS']; + if (!empty($_SERVER['DBQ_TITLE'])) $this->title = $_SERVER['DBQ_TITLE']; + + // Init $this->uri_params(); parent::__construct($opt); if (!$this->params['db']) $this->not_implemented('Db missing'); @@ -167,8 +178,11 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; } // Re use if (!empty($this->db)) return $this->db; + require_once(NB_ROOT.'/lib/php/config.php'); + require_once(NB_ROOT.'/lib/php/db.php'); // New + $_SERVER['_DBQ_CONF_FILE'] = '/opt/nb/etc/dbq/000-local.php'; global $DB_CONFS; if (!empty($_SERVER['DBQ_CONF_DIR'])) { $DB_CONFS = Db::conf_load(array_merge( @@ -176,6 +190,10 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; } (array)glob($_SERVER['DBQ_CONF_DIR'].'/*.yaml'), (array)glob($_SERVER['DBQ_CONF_DIR'].'/*.php'), [])); + + } elseif (!empty($_SERVER['DBQ_CONF_FILE'])) { + $DB_CONFS = Db::conf_load([$_SERVER['DBQ_CONF_FILE']]); + } else { require_once(NB_ROOT.'/lib/php/db/config.php'); } @@ -203,11 +221,16 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; } #and $this->table->type() == 'table' ) ? [ 'row_parse_post' => function(&$r){ - $args = join(self::PARAM_ARGS_SEP,$this->table->fields_keys_values($r)); - $args = urlencode($args); - $base = $this->table->base; - $rm = $base.'rm/'.$args; + if ($this->perm < self::VIEW) return; + $args = urlencode( join(self::PARAM_ARGS_SEP,$this->table->fields_keys_values($r)) ); + + $r = ['@' => join(' ',[ + 'View' + ]) ] + $r; + + if ($this->perm < self::DELETE) return; + $rm = $this->table->base.'rm/'.$args; $r['-'] = '' #'Delete' .'
' @@ -216,10 +239,6 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; } .'
' ; - $r = ['@' => join(' ',[ - 'View' - ]) ] + $r; - }, ] : []; @@ -384,7 +403,7 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; } [ 'help', 'This help' ], [ 'ls', 'List configured databases' ], [ 'databases', 'List others databases' ], - [ 'cryptkey', 'Generate a new encryption key' ], + [ 'cryptkey', 'Generate a random encryption key' ], ],['command','description'],function(&$r) { $r['command'] = $this->page->tag('a',$r['command'],'href="'.$this->db->base.$r['command'].'.'.$this->ext.'"'); }); diff --git a/www/dbq/etc/nginx/default.conf b/www/dbq/etc/nginx/default.conf index f5f49945..deeade94 100644 --- a/www/dbq/etc/nginx/default.conf +++ b/www/dbq/etc/nginx/default.conf @@ -52,6 +52,10 @@ server { fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param DBQ_CONF_FILE $document_root/../../../etc/dbq/000-local.php; + fastcgi_param DBQ_PERM 0; + fastcgi_param DBQ_PARAM_DEFAULT ls; + #fastcgi_param DBQ_TITLE 'Local Db'; fastcgi_intercept_errors off; fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; -- 2.47.3