]> git.nbdom.net Git - nb.git/commitdiff
dbq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 13 Dec 2016 01:00:17 +0000 (02:00 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 13 Dec 2016 01:00:17 +0000 (02:00 +0100)
etc/dbq/000-local.php
lib/php/db.php
www/dbq/dbq.php
www/dbq/etc/nginx/default.conf

index d5d6aebd14cf299b045bc0811ec8c21d3950057c..9bebb26fd5e86d9540631fd09a29786522d42150 100644 (file)
@@ -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',
index f9c639979cfc3c64479f6691d3bea326ce2f824d..04e1b1a5e2e880fe4ee022016e66c2db70f7ffbc 100644 (file)
@@ -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' => [
index 987f9e8400e7f673cb58f965d838d169f8f23500..479e80fd6b8a2e098ead1514f917a53c8d6d2e07 100644 (file)
@@ -1,20 +1,21 @@
 <?php
-require_once(dirname(__FILE__).'/../../lib/php/nb.php');
+require_once(realpath(dirname(__FILE__).'/../../lib/php/nb.php'));
 require_once(NB_ROOT.'/lib/php/http.php');
+define('DBQ_PERM',(int)(isset($_SERVER['DBQ_PERM']) ? $_SERVER['DBQ_PERM'] : 9));
+define('DBQ_PARAM_DEFAULT',(string)(isset($_SERVER['DBQ_PARAM_DEFAULT']) ? $_SERVER['DBQ_PARAM_DEFAULT'] : 'ls'));
 class DbQ extends nb {
   const ADMIN = 9;
   const DELETE = 4;
   const WRITE = 3;
-  const READ = 1;
-  public $perm = self::ADMIN;
+  const VIEW = 1;
+  public $perm = DBQ_PERM;
 
   public $run = false;
   public $title = 'Dbq';
-  public $admin = true;
 
-  const PARAM_DB_DEFAULT = 'ls';
   const PARAM_ARGS_SEP = '|';
   const PARAM_EXP = '[\w\._:-]{2,100}';
+  const PARAM_DB_DEFAULT = DBQ_PARAM_DEFAULT;
   public $params = [
     'format' => '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(' ',[
+          '<a class="button select" href="'.$this->table->base.'vi/'.$args.'">View</a>'
+        ]) ] + $r;
+
+        if ($this->perm < self::DELETE) return;
+        $rm = $this->table->base.'rm/'.$args;
         $r['-'] = ''
           #'<a class="button delete" href="'.$this->table->name.'/rm/'.$args.'">Delete</a>'
           .'<form action="'.$rm.'" method="post">'
@@ -216,10 +239,6 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; }
           .'</form>'
         ;
 
-        $r = ['@' => join(' ',[
-          '<a class="button select" href="'.$base.'vi/'.$args.'">View</a>'
-        ]) ] + $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.'"');
       });
index f5f49945313729167b9b3bebb9038bfb3dc4a33a..deeade946c55101dca772ef5a49efb1f4e998576 100644 (file)
@@ -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;