]> git.nbdom.net Git - nb.git/commitdiff
lib/php/nb.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 30 Oct 2017 22:33:13 +0000 (22:33 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 30 Oct 2017 22:33:13 +0000 (22:33 +0000)
lib/php/functions.php
lib/php/http.php
lib/php/nb.php
www/dbq/dbq.php
www/dbq/etc/nginx.conf [new file with mode: 0644]
www/dbq/etc/nginx/inc.conf [deleted file]
www/dbq/html/default.js
www/dbq/html/default.min.css
www/dbq/html/default.min.js

index 3886fda58fbfb163b449485550098163723913d7..cefd795a08e39ec510161c0ad961e482c7c6245d 100644 (file)
@@ -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) {
index eeda368eb885e31a5dd9e3b3cf3982605081b7b5..b98fbbf321e1b90b7533b8a2357a557eaf234ba3 100644 (file)
@@ -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";
index 099c38f18bf46d00351f958897e74b8b8e31e006..2985604012bc6800efe075ea914aba19bd7fea20 100644 (file)
@@ -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!!!");
   }
 
   /*
index 724c6a70a210aa352f606b9303962739b896737d..06c1c64e85b42e1f77dcc1f686b895999d051b2f 100644 (file)
@@ -299,14 +299,14 @@ class DbQ extends nb {
         $args = $GLOBALS['dbq_args'];
 
         $r = ['view' => join(' ',[
-          '<a class="button select" href="'.$this->table->base.'/vi/'.$args.'/">View</a>'
+          '<a class="button select vi" href="'.$this->table->base.'/vi/'.$args.'/">View</a>'
         ]) ] + $r;
 
         if ($this->perm < self::DELETE) return;
         $rm = $this->table->base.'/rm/'.$args;
         $r['delete'] = ''
           .'<form action="'.$rm.'" method="post">'
-          .'<a class="button" href="'.$rm.'" onclick="parentNode.submit();return false;">Delete</a>'
+          .'<a class="button rm" href="'.$rm.'" onclick="parentNode.submit();return false;">Delete</a>'
           .$this->form_hidden($r)
           .'</form>'
         ;
@@ -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.conf b/www/dbq/etc/nginx.conf
new file mode 100644 (file)
index 0000000..f365ac0
--- /dev/null
@@ -0,0 +1,41 @@
+index index.php index.html;
+
+charset utf-8;
+
+sendfile off;
+
+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; }
+
+#--------------------------------------------------------------#
+# Deny
+location ~ /\.ht { deny all; }
+
+#--------------------------------------------------------------#
+# All to index.php
+location / {
+    try_files $uri $uri/ /index.php?$query_string;
+}
+
+#--------------------------------------------------------------#
+# FastCGI
+
+location ~ /index\.php$ {
+    fastcgi_split_path_info ^(.+\.php)(/.+)$;
+    fastcgi_pass php-handler;
+    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;
+
+    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/etc/nginx/inc.conf b/www/dbq/etc/nginx/inc.conf
deleted file mode 100644 (file)
index 2693a15..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-index index.php index.html;
-
-charset utf-8;
-
-sendfile off;
-
-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; }
-
-#--------------------------------------------------------------#
-# Deny
-location ~ /\.ht { deny all; }
-
-#--------------------------------------------------------------#
-# All to index.php
-location / {
-    try_files $uri $uri/ /index.php?$query_string;
-}
-
-#--------------------------------------------------------------#
-# FastCGI
-
-location ~ /index\.php$ {
-    fastcgi_split_path_info ^(.+\.php)(/.+)$;
-    fastcgi_pass php-handler;
-    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;
-}
index a7b57b7e6080c54f6036f6b6629adc6c183f9667..2164f4bd0ddac6e6209c10f415c7758febb0a9aa 100644 (file)
@@ -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","<div class=\"nav top\">"+document.querySelector(".nav.bottom").innerHTML+"</div>");
   }
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..45f4669777b2f16836064679874e2cc1f80f48de 100644 (file)
@@ -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%}
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0302e723fd2eb39a4f54ebd17269c3ad362e0ec9 100644 (file)
@@ -0,0 +1 @@
+function form_clean(e){var t;for(i=0;i<e.length;i++)"none"!=(t=e.elements[i]).style.display&&("text"==t.type?t.value="":!t.type.match(/^select/)||"limit"!=t.name&&"format"!=t.name||(t.selectedIndex=0))}function form_submit_clean(e){var t=0,n="",o=e.getAttribute("action");if("get"!=e.getAttribute("method"))return!0;for(t=0;t<e.length;t++){var r=e[t];r.name&&(""!=r.value&&"undefined"!=r.value&&(n+=(n?"&":"?")+encodeURI(r.name)+"="+encodeURI(r.value)))}return n=("?"==o?"":o)+n,e.reset(),window.location=n,!1}document.addEventListener("DOMContentLoaded",function(){NodeList.prototype.forEach=Array.prototype.forEach,document.querySelectorAll("form").forEach(function(e){e.onsubmit=function(){if(this.elements.limit){var e=this.elements.limit;"undefined"!=window._dbq.default_limit&&e.value==window._dbq.default_limit&&e.removeAttribute("value")}return form_submit_clean(this)}}),document.querySelectorAll("form.menu").forEach(function(e){e.setAttribute("action",window.location.toString().replace(/\?.*$/,"")),e.querySelectorAll("form.menu select.format").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["table.base"]+"."+this.value),this.form.onsubmit()}}),e.querySelectorAll("form.menu select.tables").forEach(function(e){e.removeAttribute("name"),e.onchange=function(){return this.form.setAttribute("action",window._dbq["db.base"]+"/"+this.value+".html"),this.form.onsubmit()}}),e.querySelectorAll("form.menu select.limit").forEach(function(e){e.onchange=function(){return this.form.onsubmit()}})}),document.querySelector(".nav.bottom")&&document.querySelector("table.rows")&&document.querySelector("table.rows").insertAdjacentHTML("beforebegin",'<div class="nav top">'+document.querySelector(".nav.bottom").innerHTML+"</div>"),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.perms.write&&(document.querySelectorAll("form.edit").forEach(function(e){e.setAttribute("onsubmit","return false")}),document.querySelectorAll("form.edit input[type=submit],form.edit input[type=reset]").forEach(function(e){e.setAttribute("style","display:none")})),document.querySelectorAll("form.menu input[type=submit]").forEach(function(e){e.insertAdjacentHTML("afterend",'&nbsp;<input type="button" class="clear '+e.className+'" onclick="form_clean(this.form)" value="'+window._dbq["text.clear"]+'" />'+(window._dbq.perm>=window._dbq.perms.write?'&nbsp;<input type="button" class="add '+e.className+'" onclick="window.location=\''+window._dbq["table.base"]+'/add/\'" value="'+window._dbq["text.add"]+'"/>':""))})});