From 76b53bcc43d4c8aed6d9b5db0661e2bb6f1b17f8 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 30 Oct 2017 22:33:13 +0000 Subject: [PATCH] lib/php/nb.php --- lib/php/functions.php | 12 +---------- lib/php/http.php | 4 ++-- lib/php/nb.php | 20 +++++++++++++++--- www/dbq/dbq.php | 24 +++++++++++----------- www/dbq/etc/{nginx/inc.conf => nginx.conf} | 6 ++++-- www/dbq/html/default.js | 4 ---- www/dbq/html/default.min.css | 1 + www/dbq/html/default.min.js | 1 + 8 files changed, 38 insertions(+), 34 deletions(-) rename www/dbq/etc/{nginx/inc.conf => nginx.conf} (80%) diff --git a/lib/php/functions.php b/lib/php/functions.php index 3886fda5..cefd795a 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -61,17 +61,7 @@ function txt2md($txt) { } function bye($msg='__bye__',$backtrace_deep=0) { - #if ($msg) err($msg,'bye',$backtrace_deep === 0 ? 1 : $backtrace_deep); - - if ($msg!=='__bye__') { - #throw new Exception($msg); - err($msg,'bye',( $backtrace_deep !== false ? (1+-1+$backtrace_deep) : $backtrace_deep )); - exit(1); - } - - #if ($msg) err($msg,'bye',1+$backtrace_deep); - exit; - #die("Can't exit from BYE!!!"); + return nb::bye($msg,$backtrace_deep); } function warn ($msg) { diff --git a/lib/php/http.php b/lib/php/http.php index eeda368e..b98fbbf3 100644 --- a/lib/php/http.php +++ b/lib/php/http.php @@ -94,9 +94,9 @@ class Http { return $id.' '.self::Status[$id]; } - public function bye($id,$body_msg='') { + public function bye($status_code,$body_msg='') { header('Content-type: text/plain'); - $msg = self::msg($id); + $msg = self::msg($status_code); header((empty($_SERVER['SERVER_PROTOCOL']) ? 'HTTP/1.0' : $_SERVER['SERVER_PROTOCOL']).' '.$msg); echo "$msg\n"; if (!empty($body_msg)) echo "$body_msg\n"; diff --git a/lib/php/nb.php b/lib/php/nb.php index 099c38f1..29856040 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -145,9 +145,23 @@ class NB { * Function: bye * Set a value for param, delete it if null */ - public static function bye($msg='',$backtrace_deep=0) { - #throw new Exception($msg); - return bye($msg,$backtrace_deep+1); +# NB 30.10.17 public static function bye($msg='',$backtrace_deep=0) { +# NB 30.10.17 #throw new Exception($msg); +# NB 30.10.17 return bye($msg,$backtrace_deep+1); +# NB 30.10.17 } + # # NB 30.10.17: From function.php + public function bye($msg='__bye__',$backtrace_deep=0) { + #if ($msg) err($msg,'bye',$backtrace_deep === 0 ? 1 : $backtrace_deep); + + if ($msg!=='__bye__') { + #throw new Exception($msg); + err($msg,'bye',( $backtrace_deep !== false ? (1+-1+$backtrace_deep) : $backtrace_deep )); + exit(1); + } + + #if ($msg) err($msg,'bye',1+$backtrace_deep); + exit; + #die("Can't exit from BYE!!!"); } /* diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 724c6a70..06c1c64e 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -299,14 +299,14 @@ class DbQ extends nb { $args = $GLOBALS['dbq_args']; $r = ['view' => join(' ',[ - 'View' + 'View' ]) ] + $r; if ($this->perm < self::DELETE) return; $rm = $this->table->base.'/rm/'.$args; $r['delete'] = '' .'
' - .'Delete' + .'Delete' .$this->form_hidden($r) .'
' ; @@ -546,15 +546,10 @@ EOF; $rows[] = [ 'name' => 'server.'.$k, 'value' => $v ]; } - // User - if ($user = $this->logged()) { - $rows[] = [ 'name' => 'user.name', 'value' => $user ]; - $rows[] = [ 'name' => 'user.perm', 'value' => $this->perm2h() ]; - } - // Client headers foreach ($this->client_header() as $k=>$v) { if ( preg_match('/^(' . $this->hide_keys_exp . ')$/', $k)) $v = $this->hide_keys_value; + if ($k == 'Host') continue; $rows[] = [ 'name' => 'client.header.'.$k, @@ -593,9 +588,14 @@ EOF; 'name' => 'dbq.page.is.html', 'value' => ($this->page->is('html') ? 1 : 0), ]; + $user = ''; + if (true or $user = $this->logged()) { + if ($user) $rows[] = [ 'name' => 'dbq.user.name', 'value' => $user ]; + $rows[] = [ 'name' => 'dbq.user.perm', 'value' => $this->perm2h() ]; + } // Machine - #if ($this->perm >= self::ADMIN) {} + if ($this->perm >= self::ADMIN) if (function_exists('posix_uname')) { foreach (posix_uname() as $k => $v) { if ($k == 'domainname' and $v == '(none)') continue; @@ -964,7 +964,7 @@ EOF; .'"'); }); - } elseif ($action == 'ls') { + } elseif ($action == 'ls' and $this->perm >= self::READ) { $this->page($this,'table_rows'); } elseif ($action == 'fields') { @@ -973,10 +973,10 @@ EOF; } elseif ($action == 'status') { $this->page($this->table->status()+$this->table->status(['fields'])); - } elseif ($action == 'add') { + } elseif ($action == 'add' and $this->perm >= self::WRITE) { $this->page($this,'table_html_add'); - } elseif ($action == 'vi') { + } elseif ($action == 'vi' and $this->perm >= self::READ) { $this->page($this,'table_html_edit'); } elseif ($action == 'insert' and $this->perm >= self::WRITE) { diff --git a/www/dbq/etc/nginx/inc.conf b/www/dbq/etc/nginx.conf similarity index 80% rename from www/dbq/etc/nginx/inc.conf rename to www/dbq/etc/nginx.conf index 2693a15e..f365ac02 100644 --- a/www/dbq/etc/nginx/inc.conf +++ b/www/dbq/etc/nginx.conf @@ -34,6 +34,8 @@ location ~ /index\.php$ { 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; + if ($DBQ_CONF_FILE = "") { set $DBQ_CONF_FILE $document_root/../../../etc/dbq/000-local.php; } + fastcgi_param DBQ_TITLE $DBQ_TITLE; + fastcgi_param DBQ_CONF_FILE $DBQ_CONF_FILE; + fastcgi_param DBQ_PERM $DBQ_PERM; } diff --git a/www/dbq/html/default.js b/www/dbq/html/default.js index a7b57b7e..2164f4bd 100644 --- a/www/dbq/html/default.js +++ b/www/dbq/html/default.js @@ -104,10 +104,6 @@ document.addEventListener("DOMContentLoaded", function() { }); -// NB 13.10.17 if (document.querySelector("h1")) { -// NB 13.10.17 document.querySelector("h1 .table").insertAdjacentHTML("afterbegin",'zaza'); -// NB 13.10.17 } - if (document.querySelector(".nav.bottom") && document.querySelector("table.rows")) { document.querySelector("table.rows").insertAdjacentHTML("beforebegin","
"+document.querySelector(".nav.bottom").innerHTML+"
"); } diff --git a/www/dbq/html/default.min.css b/www/dbq/html/default.min.css index e69de29b..45f46697 100644 --- a/www/dbq/html/default.min.css +++ b/www/dbq/html/default.min.css @@ -0,0 +1 @@ +html{font:90% 'Trebuchet MS',sans-serif;background-color:#eee}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}h1{margin:0 0 .2em 0;font-size:180%;padding-bottom:.3em;margin-bottom:.5em;border-bottom:dashed 1px #444}a{color:inherit}div>a,li a,p a,td a{color:#3572b0}a,a:visited{text-decoration:none}.button:hover,a:hover{opacity:.8}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 .3em}table{border-collapse:collapse}td,th{padding:.2em .7em}th a.sort{padding:0 .3em}input:not([type]),input[type=''],input[type=date],input[type=email],input[type=password],input[type=text],input[type=url],select,textarea{border-radius:3px;border:solid 1px #ddd;padding:.3em .4em;box-shadow:0 1px 1px #eee}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form input,form label,form select{vertical-align:middle;margin:.2em .4em .2em 0}.block,.menu,div.row,form.edit,iframe,object,pre,table.rows,ul.row{border-radius:4px;border-spacing:0;padding:.5em .2em;margin-bottom:.5em;border:solid 1px #ddd;background-color:#fafafa;box-shadow:0 1px 2px #eee}.rows{padding:0}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #ddd;table-layout:fixed}table.rows.fixed{width:100%}table.rows tr:nth-child(even) td{background-color:#fefefe}div.row div,table.rows td,table.rows th,ul.row li{border-bottom:solid 1px #ddd}div.row div,table.rows tr:last-child td,ul.row li{border-bottom:none}table.rows td,table.rows th{border-right:dashed 1px #ddd}table.rows th{text-align:left}table.rows td{padding:.3em .3em}table.rows.fixed td{white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows td.delete,table.rows td.view{width:1%;white-space:nowrap}table.rows.fixed th.view{width:2em}table.rows.fixed th.delete{width:2.7em}div.row div{margin:0}div.row div label,ul.row li label{padding:.1em .5em .1em 0;min-width:20%;display:inline-block}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.5em;cursor:pointer;border-radius:4px;white-space:nowrap;box-sizing:border-box;margin:0 .1em 0 0;cursor:pointer;padding:0 .3em;border:none;color:#3572b0;background-color:#eee;background:linear-gradient(to bottom right,#eee,#ddd);box-shadow:0 1px 1px #bbb}.buttons,.center,.menu,.nav,.rows,td.button{margin-left:auto;margin-right:auto;display:table}form.menu{padding:.5em;background-color:#fafafa}form.menu .button.add{float:right;margin-top:.3ex;display:inline}form.menu .criterias{border-top:dashed 1px #ddd;margin-top:.3em;padding-top:.3em}form.menu .criterias span.label{border-right:solid 1px #fff;padding:.2em .1em;margin:.2em .2em 0 0;border-radius:3px}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]:focus{width:auto}form.menu .criterias input[type=text]{width:4em}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left;vertical-align:middle;margin-top:.2em}form.Wedit .fields .label span input{vertical-align:bottom!important}form.edit .fields input[size],form.edit .fields select,form.edit .fields textarea{width:65%} diff --git a/www/dbq/html/default.min.js b/www/dbq/html/default.min.js index e69de29b..0302e723 100644 --- a/www/dbq/html/default.min.js +++ b/www/dbq/html/default.min.js @@ -0,0 +1 @@ +function form_clean(e){var t;for(i=0;i'+document.querySelector(".nav.bottom").innerHTML+""),document.querySelectorAll("table").forEach(function(e){parseInt(e.offsetWidth)>parseInt(window.innerWidth)&&(e.className=e.className.replace(/(^| +)fixed($| )/,"")+" fixed",e.className=e.className.trim())}),window._dbq.perm'+(window._dbq.perm>=window._dbq.perms.write?' ':""))})}); -- 2.47.3