From: Nicolas Boisselier Date: Thu, 22 Dec 2016 01:39:30 +0000 (+0000) Subject: Bed X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=0683bda36c877fc9b739b55560f4356e76e73016;p=nb.git Bed --- diff --git a/lib/php/db.php b/lib/php/db.php index 0155b62c..e47ef864 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -637,7 +637,7 @@ class Db extends nb { $this->out(self::$action_help,['action','description']); $return = true; - } elseif ($action == 'db.ryptkey') { + } elseif ($action == 'db.cryptkey') { echo $this->out($this->cryptkey(),['key']); } elseif ($action == 'db.exec') { diff --git a/lib/php/db/table.php b/lib/php/db/table.php index ed292cfb..d11842c9 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -41,6 +41,7 @@ Class Table extends nb { public $show_hidden_params = true; public $show_buttons = true; public $show_url_sort = true; + public $show_header = true; public static $params = [ 'db', 'table', 'limit', 'debug', 'action' , 'page', 'paged' # wordpress ]; @@ -94,6 +95,9 @@ Class Table extends nb { // Add others foreach ($opt as $k => $v) { $this->$k = $v; } + # NB 22.12.16: TODEL + if (!isset($this->show_header)) $this->show_header = (bool)$this->p('header'); + } /* @@ -952,7 +956,7 @@ Class Table extends nb { # Html # if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format) - ? ( $this->p('header')!=="0") + ? ( $this->show_header ) : false ; @@ -1077,10 +1081,7 @@ Class Table extends nb { } # < is_html - if ($count === 0 and ( - $this->p('header') === 'force' - or !$format - )) { + if ($count === 0 and !$format) { echo $this->{"rows_begin_$format"}($fields,$opt); } @@ -1314,7 +1315,7 @@ Class Table extends nb { public function rows_begin_csv($fields) { if (self::p('rows_head_char')!=='') echo self::p('rows_head_char'); - if ($this->p('header')==="0") return ''; + if (!$this->show_header) return ''; return join(TABLE_CSV_SEP,array_keys($fields))."\n"; } @@ -1337,7 +1338,7 @@ Class Table extends nb { $html .= ''.NB_EOL; #if (!empty($opt)) $html .= '' .NB_EOL; - if ($this->p('header')!=="0") { + if ($this->show_header) { $html .= ''.NB_EOL.''.NB_EOL; if ($this->buttons() and DB_HTML_EDIT) $html .= ''.NB_EOL; @@ -2010,6 +2011,7 @@ Class Table extends nb { } #$opt['var']['rows']=[]; + # Protect $_REQUEST ! $_REQUEST_BAK = $_REQUEST; $_REQUEST = array_merge($_REQUEST,$ROW); diff --git a/lib/php/nb.php b/lib/php/nb.php index 15a680b4..36bc956d 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -69,15 +69,6 @@ class NB { foreach (array_keys((array)$this) as $k) { if (isset($this->$k)) unset($this->$k); }; } - /* - * Function: p - * Return a param - */ - public static function p($name=null,$default=null) { - if ($name === null) return isset($_REQUEST) ? $_REQUEST : []; - return isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default; - } - /* * Replace aliases by long name */ @@ -101,16 +92,31 @@ class NB { return self::p($name); } + /* + * Function: p + * Return a param + */ + public static function p($name=null,$default=null) { + if ($name === null) return isset($_REQUEST) ? $_REQUEST : []; + return isset($_REQUEST[$name]) ? $_REQUEST[$name] : $default; + } + /* * Function: pset * Set a value for param, delete it if null */ public static function pset($name,$value=null) { + + # Brutal ! if (is_array($name)) return ($_REQUEST=$name); + + # Delete key if ($value === null or $value === '') { unset ($_REQUEST[$name]); return null; } + + # Set value return ($_REQUEST[$name] = $value); } @@ -303,6 +309,7 @@ class NB { if (empty($_POST)) $_POST = $_REQUEST; if (empty($_GET)) $_GET = $_REQUEST; } + return $new_argv; } diff --git a/lib/php/oc.php b/lib/php/oc.php index 3e3c5dc7..170848de 100644 --- a/lib/php/oc.php +++ b/lib/php/oc.php @@ -1,5 +1,12 @@ is(): unknow argument '$is'. Accepted values are xhtml, html, xml"); + if ($is == 'text' or $ls == 'txt') return preg_match('/^text\//',self::$content_type); + self::bye("Unknow argument '$is'. Accepted values are xhtml, html, xml, xtml, text|txt"); } public static function path() { diff --git a/src/Docker/nginx/default.conf b/src/Docker/nginx/default.conf index 10aabf51..48c284c6 100644 --- a/src/Docker/nginx/default.conf +++ b/src/Docker/nginx/default.conf @@ -5,10 +5,6 @@ server { charset utf-8; - location / { - try_files $uri $uri/ /index.php?$query_string; - } - location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } @@ -21,6 +17,14 @@ server { client_max_body_size 100m; + location ~ /\.ht { + deny all; + } + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + location ~ /index\.php$ { #location index.php { fastcgi_split_path_info ^(.+\.php)(/.+)$; @@ -32,8 +36,4 @@ server { fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; } - - location ~ /\.ht { - deny all; - } } diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index bf6fcbd2..c901af6b 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -26,20 +26,17 @@ define('DBQ_TITLE',(string)(isset($_SERVER['DBQ_TITLE']) class DbQ extends nb { + public $perm = DBQ_PERM; const ADMIN = 9; const DELETE = 4; const WRITE = 3; const VIEW = 1; - public $perm = DBQ_PERM; - public $run = false; - public $sep = ' / '; public $title = DBQ_TITLE; + public $sep = ' / '; - const PARAM_ARGS_SEP = '|'; - const PARAM_EXP = '[\w\._:-]{2,100}'; - const PARAM_DB_DEFAULT = DBQ_PARAM_DEFAULT; - + const HTML_FORMAT = 'table'; + const CLI_FORMAT = 'human'; public $formats = [ 'table', 'csv', @@ -48,6 +45,10 @@ class DbQ extends nb { 'sh', ]; + + const PARAM_ARGS_SEP = '|'; + const PARAM_EXP = '[\w\._:-]{2,100}'; + const PARAM_DB_DEFAULT = DBQ_PARAM_DEFAULT; public $params = [ 'format' => DBQ_PARAM_FORMAT, 'db' => self::PARAM_DB_DEFAULT, @@ -57,6 +58,8 @@ class DbQ extends nb { ]; public $params_deep = []; + public $run = false; # call run() when __contruct + # NB 10.12.16 public $_colors = [ # NB 10.12.16 'body' => '#ddd', # NB 10.12.16 'body-background' => '#009B9C', @@ -153,6 +156,7 @@ function form_submit_clean(form) { form_clean(form); form.submit(); } + function form_clean(form) { var e; for(i=0;i"+document.querySelector(".nav.bottom").innerHTML+""); } + }); '); + $this->page->begin(); } #die($obj); #if (is_scalar($obj)) { if(is_array($obj)) { - $this->db->out($obj,$head,['row_parse_post'=>$fct]); + $this->db->out($obj,$head,['row_parse_post'=>$fct]); + } elseif (empty($meth)) { echo $obj; + } elseif(is_array($meth)) { - $this->db->out($meth,$head,['row_parse_post'=>$fct]); + $this->db->out($meth,$head,['row_parse_post'=>$fct]); + } else { + # Objects Method $out = $obj->$meth(); if (!empty($out)) { - #bye([$this->params['format'],$this->page->content_type()]); + # bye([$this->params['format'],$this->page->content_type()]); + #bye($out); array_shift($out); + #self::pdef('header',$this->page->is('xtml')); + #self::pdef('header',0); + self::pdef('header',(string)preg_match('/html/',$this->params['format'])); $this->db->out($out,$head,['row_parse_post'=>$fct]); } + } if (empty($this->_nopage)) $this->page->end(); @@ -488,14 +507,22 @@ document.addEventListener("DOMContentLoaded", function() { // $rows[] = [ 'name' => $this->page->tag('h4','*APP'), 'value' => '' ]; // - $rows[] = [ + if ($this->client_content_type()) $rows[] = [ 'name' => 'dbq.client_content_type', 'value' => $this->client_content_type(), ]; + $rows[] = [ + 'name' => 'dbq.page.content_type', + 'value' => $this->page->content_type(), + ]; $rows[] = [ 'name' => 'dbq.params.format', 'value' => $this->params['format'], ]; + if (0) $rows[] = [ + 'name' => 'dbq.page.is.html', + 'value' => ($this->page->is('html') ? 1 : 0), + ]; // $rows[] = [ 'name' => $this->page->tag('h4','*CLIENT HEADERS'), 'value' => '' ]; @@ -534,7 +561,7 @@ document.addEventListener("DOMContentLoaded", function() { $format = (!empty($_SERVER['HTTP_USER_AGENT']) and preg_match(DBQ_HUMAN_UA_EXP,$_SERVER['HTTP_USER_AGENT'])) ? 'html' - : 'human' + : self::CLI_FORMAT ; } @@ -546,17 +573,63 @@ document.addEventListener("DOMContentLoaded", function() { $this->page->title = join($this->sep,$title); $this->page->nav = $nav; - if ($format == 'html') $format = 'table'; + if ($format == 'html') $format = self::HTML_FORMAT; $this->params['format'] = $format; - $this->db->formats = $this->formats; $this->db->format = $format; + if (!empty($this->formats)) $this->db->formats = $this->formats; + // Then content type - if (empty($content_type)) $content_type = Mime::fromExt($format=='human' ? 'txt' : $format); + if (empty($content_type)) $content_type = Mime::fromExt($format==self::CLI_FORMAT ? 'txt' : $format); if ($content_type) $this->page->content_type($content_type); } + public function page_phpinfo() { + $txt = $this->page->is('html') ? 0 : 1; + if (1 or $txt) { + $rows = []; + $row = []; + $section = ''; + + foreach (explode("\n",$this->page->phpinfo()) as $line) { + + if (preg_match(',]*>(.*?),',$line,$m)) { + $section = strtoupper(strip_tags(preg_replace('/\W+/','_',$m[1]))); + + } elseif (preg_match_all(',,',$line,$m)) { + $name = strip_tags($m[1][0]); + $value = isset($m[1][1]) ? strip_tags($m[1][1]) : ''; + + if (preg_match('/^\$_([A-Z_]+)\[["\']([^"\']+)["\']\]/',$name,$m)) { + $_section = $m[1]; + $name = $m[2]; + } else { + $_section = $section; + } + + #debug($m); + $rows[] = [ + 'section' => $_section, + 'name' => $name, + 'value' => $value, + ]; + + } else { + #debug($sec." ".$line); + } + + } + + return $this->page($rows); + return $rows; + exit; + } + + #return $this->page->phpinfo(); + return $this->page($this->page->phpinfo($txt)); + } + public function run() { # @@ -593,9 +666,12 @@ document.addEventListener("DOMContentLoaded", function() { } elseif ($this->perm < self::ADMIN) { // NOW ONLY FOR ADMIN ! + } elseif ($action == 'phpinfo') { #$this->page(['phpinfo'=>$this->page->phpinfo(true)]); - $this->page($this->page->phpinfo()); + #$this->page($this->page->phpinfo()); + #$this->page($this,'phpinfo'); + $this->page_phpinfo(); } elseif (0 or $action == '_SERVER' @@ -638,6 +714,11 @@ document.addEventListener("DOMContentLoaded", function() { } elseif ($action == 'databases') { $this->page($this->db,'databases'); + } elseif ($action == 'dump') { + echo serialize($this->db->tables()); + exit; + $this->page(array_values($this->db()->conf)); + } # diff --git a/www/dbq/etc/nginx/default.conf b/www/dbq/etc/nginx/default.conf index 72721a20..55e60030 100644 --- a/www/dbq/etc/nginx/default.conf +++ b/www/dbq/etc/nginx/default.conf @@ -17,7 +17,7 @@ server { client_max_body_size 100m; - ############################################################### + #--------------------------------------------------------------# # Ignore location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } @@ -28,44 +28,41 @@ server { break; } - ############################################################### + #--------------------------------------------------------------# # Deny -# NB 13.12.16 location ~ /\. { -# NB 13.12.16 deny all; -# NB 13.12.16 access_log off; -# NB 13.12.16 log_not_found off; -# NB 13.12.16 } + location ~ /\.ht { + deny all; + } - ############################################################### + #--------------------------------------------------------------# # serve static files directly #location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ { # access_log off; # expires 30d; #} - ############################################################### + #--------------------------------------------------------------# # All to index.php location / { try_files $uri $uri/ /index.php?$query_string; } - ############################################################### + #--------------------------------------------------------------# # FastCGI - #location ~ \.php$ { location ~ /index\.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; - #fastcgi_pass localhost:9000; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_intercept_errors off; + fastcgi_buffer_size 16k; + fastcgi_buffers 4 16k; + 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; } } diff --git a/www/dbq/html/default.css b/www/dbq/html/default.css index a210f002..58d148d4 100644 --- a/www/dbq/html/default.css +++ b/www/dbq/html/default.css @@ -55,6 +55,7 @@ input[size] { max-width: 70%; } +div.row div label:after, form label:after { content: ':'; } form label, @@ -65,7 +66,7 @@ form select { } table.rows, -div.rows, +div.row, form.edit, .menu, .block, @@ -81,9 +82,18 @@ object, iframe, pre } -table.rows { padding: 0; } -table.rows th, table.rows td { border-bottom: solid 1px #ccc; } -table.rows tr:last-child td { border-bottom: none; } +.rows { padding: 0; } +div.row div, table.rows th, table.rows td { border-bottom: solid 1px #ccc; } +div.row div, table.rows tr:last-child td { border-bottom: none; } +div.row div { + margin: 0; +} + +div.row div label { + padding: 0.1em 0.5em 0.1em 0; + min-width: 20%; + display: inline-block; +} .menu, .nav, .rows, .buttons, .center { @@ -117,7 +127,7 @@ a:hover, opacity: 0.8; } -.menu { padding: 0.5em; width: 75%; } +.menu { padding: 0.5em; } form.menu .criterias { border-top: dashed 1px #ccc;
' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '
(.*?)