*****************************************************************************/
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);
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]);
}
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' => [
<?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,
public $db;
public function __construct($opt=[]) {
- #debug(self::READ);
+ #debug(self::VIEW);
// Pre defaults values
$this->params['format'] = (!empty($_SERVER['HTTP_USER_AGENT']) and
: $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');
// 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(
(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');
}
#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">'
.'</form>'
;
- $r = ['@' => join(' ',[
- '<a class="button select" href="'.$base.'vi/'.$args.'">View</a>'
- ]) ] + $r;
-
},
] : [];
[ '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.'"');
});