From c3e0dfb84875cab51c9890c43d6fab724d1e3729 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 5 Sep 2024 21:01:51 +0200 Subject: [PATCH] bin/dbq-vi --- bin/dbq-vi | 27 ++++++++++++++++++++-- bin/dbq.php | 21 ++++++++++++++--- www/dbq/dbq.php | 60 +++++++++++++------------------------------------ 3 files changed, 58 insertions(+), 50 deletions(-) diff --git a/bin/dbq-vi b/bin/dbq-vi index 6d783231..96f510ca 100755 --- a/bin/dbq-vi +++ b/bin/dbq-vi @@ -1,7 +1,7 @@ #!/usr/bin/env bash tmp=/tmp/$USER-dbq-vi-$$ -main() { +_main() { #exec echo $tmp dbq.php "$1/vi/$2.sh" > "$tmp" || return @@ -15,7 +15,29 @@ main() { bash -f "$tmp" || return #echo $md5 " == $(md5sum "$tmp")" - eval "dbq.php $1/update/ format=human $(cat "$tmp")" + eval dbq.php $1/update/ format=yaml $(cat "$tmp") + +} + +main() { + #exec echo $tmp + cat < "$tmp" +# +# dbq-vi +# Use "key: |" for new lines +# +EOF + + dbq.php "$1/vi/$2.yaml" >> "$tmp" || return + md5=$(md5sum "$tmp") + + vi "$tmp" + [ -s "$tmp" ] || return + + [ "$md5" == "$(md5sum "$tmp")" ] && return + #echo $md5 " == $(md5sum "$tmp")" + + dbq.php $1/update.yaml __YAML__="$tmp" } @@ -26,6 +48,7 @@ Usage: dbq-vi /db/table id EOF exit fi + main $@ rm -f "$tmp" diff --git a/bin/dbq.php b/bin/dbq.php index 12d91a09..81ee0efc 100755 --- a/bin/dbq.php +++ b/bin/dbq.php @@ -1,5 +1,6 @@ #!/usr/bin/env php 1) { $_SERVER['REQUEST_URI'] = $GLOBALS['argv'][1]; for($i=2;$i diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 41ab6e69..98dc6185 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -757,12 +757,6 @@ class DbQ extends nb { foreach (['json','yaml'] as $type) { if (!strpos($content_type,'/'.$type)) continue; -# NB 20.07.18 if ($raw) $_POST = [ $type => $raw ]; -# NB 20.07.18 if (empty($_POST[$type])) continue; -# NB 20.07.18 #bye($_POST); -# NB 20.07.18 $post = $_POST; -# NB 20.07.18 -# NB 20.07.18 unset($post[$type]); $fct = $type . '_decode'; $_POST = (array)$this->$fct(file_get_contents("php://input")); @@ -789,6 +783,7 @@ class DbQ extends nb { # NB 30.08.24: Done in bin/dbq.php //if (empty($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI'] = join('/',( count($GLOBALS['argv'])>0 ) ? array_slice($GLOBALS['argv'],1) : []); + if (!isset($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI'] = '/'; list ($path,$args) = strpos($_SERVER['REQUEST_URI'],'?') ? explode('?',$_SERVER['REQUEST_URI']) : [$_SERVER['REQUEST_URI'],'']; $this->uri = $path; $this->uri_params = explode($this->explode_args,$args); @@ -1200,41 +1195,6 @@ EOF; foreach (['table','action','args'] as $k) { if (!empty($this->params[$k])) $arg[] = $this->params[$k]; } $arg = join('/',$arg); -/* -# NB 14.12.22: What use ??? - $conf = []; - $fct_help = function() use ($conf,$arg) { - $this->page($this->db,$conf['root']); - }; - $conf = [ - 'root' => [ - [ 'help', 'This help', $fct_help ], - # NB 14.12.22 [ 'help', 'This help', function() use ($conf) { $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['root'][0][2] = function() use ($conf) { $this->page($this->db,$conf['root']); }; - foreach ($conf['root'] 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_); - $fct(); - } -*/ if ($action == 'help') { $this->page($this->db @@ -1445,25 +1405,25 @@ EOF; } elseif ($action == 'insert') { $this->deniedUnless($this->perm >= self::WRITE); - if (!$this->table->insert(empty($_POST) ? $_GET : $_POST,$info)) $this->error('insert: '.print_r($info,true)); + if (!$this->table->insert($this->getData(),$info)) $this->error('insert: '.print_r($info,true)); header('Location: '.$this->table->base.'/'); $this->page($info); } elseif ($action == 'update') { $this->deniedUnless($this->perm >= self::WRITE); - if (!$this->table->update(empty($_POST) ? $_GET : $_POST,$info)) $this->error('update: '.print_r($info,true)); + if (!$this->table->update($this->getData(),$info)) $this->error('update: '.print_r($info,true)); $this->redirect_if_no_referer($this->table->base.'/'); $this->page($info); } elseif ($action == 'replace') { $this->deniedUnless($this->perm >= self::WRITE); - if (!$this->table->replace(empty($_POST) ? $_GET : $_POST,$info)) $this->error('replace: '.print_r($info,true)); + if (!$this->table->replace($this->getData(),$info)) $this->error('replace: '.print_r($info,true)); $this->redirect_if_no_referer($this->table->base.'/'); $this->page($info); } elseif ($action == 'rm') { $this->deniedUnless($this->perm >= self::DELETE); - if (!$this->table->delete(empty($_POST) ? $_GET : $_POST,$info)) $this->error('rm: '.print_r($info,true)); + if (!$this->table->delete($this->getData(),$info)) $this->error('rm: '.print_r($info,true)); $this->redirect_if_no_referer($this->table->base.'/'); $this->page($info); @@ -1486,6 +1446,16 @@ EOF; } + private function getData() { + $data = []; + if (empty($data) and !empty($_POST)) $data = $_POST; + if (empty($data) and !empty($_GET)) $data = $_GET; + # NB 05.09.24 if (!empty($data['__YAML__'])) $data = $this->yaml_decode($data['__YAML__']); + # NB 05.09.24 if (!empty($data['__JSON__'])) $data = $this->yaml_decode($data['__JSON__']); +#bye($data); + return $data; + } + public function redirect_if_no_referer($url) { if (!empty($_SERVER['HTTP_REFERER'])) $url = $_SERVER['HTTP_REFERER']; if ($this->p('referer')) $url = urldecode($this->p('referer')); -- 2.47.3