]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 22 Dec 2016 01:39:30 +0000 (01:39 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 22 Dec 2016 01:39:30 +0000 (01:39 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/nb.php
lib/php/oc.php
lib/php/page.php
src/Docker/nginx/default.conf
www/dbq/dbq.php
www/dbq/etc/nginx/default.conf
www/dbq/html/default.css

index 0155b62c39872a49ea65a63bd5cdd64af0af4daa..e47ef864f561f64782b5836672e62d0ba7df7006 100644 (file)
@@ -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') {
index ed292cfb6a226432b876a3251a3e1f641e8753ff..d11842c9c32a0c448cac8bd2c173bf43f9bbecc4 100644 (file)
@@ -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 .= '<table class="rows wp-list-table widefat fixed striped">'.NB_EOL;
     #if (!empty($opt)) $html .= '<caption>' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '</caption>' .NB_EOL;
 
-    if ($this->p('header')!=="0") {
+    if ($this->show_header) {
       $html .= '<thead>'.NB_EOL.'<tr class="head">'.NB_EOL;
 
       if ($this->buttons() and DB_HTML_EDIT) $html .= '<th class="edit"></th>'.NB_EOL;
@@ -2010,6 +2011,7 @@ Class Table extends nb {
     }
     #$opt['var']['rows']=[];
 
+    # Protect $_REQUEST !
     $_REQUEST_BAK = $_REQUEST;
     $_REQUEST = array_merge($_REQUEST,$ROW);
 
index 15a680b485d243d09d3ae119627abb09f658c2ea..36bc956d91c8c022f827f0d4e9497b5eacc4b19f 100644 (file)
@@ -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;
 
   }
index 3e3c5dc7b79e1f14974461ce823a1768ff37fd92..170848de3c4b0a088df01fb1d39a35616e07f54f 100644 (file)
@@ -1,5 +1,12 @@
 <?php
+// ownCloud Authentication
+
 function oc_password_verify($pass) {
+  
+  # NB 22.12.16: Change path too standards:
+  # - /var/lib/owncloud/config
+  # - /usr/share/owncloud/lib 
+
   require_once "/home/owncloud/config/config.php";
   require_once '/opt/owncloud/lib/base.php';
   require_once '/opt/owncloud/lib/private/Security/Hasher.php';
index 7b6c26ed03e898017fe1b0083bdbf1e894f3b84f..f636b100fa7ced7bd798e1fe33dfb27fc6c9245f 100644 (file)
@@ -475,8 +475,8 @@ class Page extends nb {
     if ($is == 'html') return preg_match('/html$/',self::$content_type);
     if ($is == 'xml') return preg_match('/xml$/',self::$content_type);
     if ($is == 'xtml') return preg_match('/(x|ht)ml$/',self::$content_type);
-    if ($is == 'text') return preg_match('/^text\//',self::$content_type);
-    die("Db->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() {
index 10aabf51471961499211e5eb58cc39e38be92913..48c284c6a1b01438586051271f36b90c02a40264 100644 (file)
@@ -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;
-    }
 }
index bf6fcbd208403ad0a95f227901271a600577c264..c901af6bcabecd0dff62e146bcae6323bdfc8b7c 100644 (file)
@@ -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<form.length;i++) {
@@ -162,6 +166,7 @@ function form_clean(form) {
       e.value = ""
     }
 }
+
 function form_submit_clean(f) {
   var i = 0;
   var url = "";
@@ -188,7 +193,9 @@ function form_submit_clean(f) {
   window.location = url;
   return false;
 }
+
 document.addEventListener("DOMContentLoaded", function() {
+
   for (var e of document.querySelectorAll("form")) {
     e.onsubmit = function() {
       return form_submit_clean(this);
@@ -196,10 +203,11 @@ document.addEventListener("DOMContentLoaded", function() {
   }
   document.getElementById("table").removeAttribute("name");
   document.getElementById("format").removeAttribute("name");
+
   for (var e of document.querySelectorAll(".menu select.tables, .menu select.format")) {
     e.onchange = function() {
       var format = document.getElementById("format").value;
-      if (format == "table") format = "html";
+      if (format == "'.self::HTML_FORMAT.'") format = "html";
       window.location =  "./" + document.getElementById("table").value + "." + format;
       return false;
     };
@@ -215,25 +223,36 @@ document.addEventListener("DOMContentLoaded", function() {
   if (document.querySelector(".nav.bottom")) {
     document.querySelector("table.rows").insertAdjacentHTML("beforebegin","<div class=\"nav top\">"+document.querySelector(".nav.bottom").innerHTML+"</div>");
   }
+
 });
       ');
+
       $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(',<h2[^>]*>(.*?)</h2>,',$line,$m)) {
+          $section = strtoupper(strip_tags(preg_replace('/\W+/','_',$m[1])));
+
+        } elseif (preg_match_all(',<td>(.*?)</td>,',$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));
+
     }
 
     #
index 72721a20a4e3157548211f54bf210b3a892c3318..55e6003018bf8601997132fe19eea63a363c8f2a 100644 (file)
@@ -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;
     }
 
 }
index a210f0021633aa9e3b8c405b8e97f0c1becb6eef..58d148d4db36e887f0012c4983308860310d316b 100644 (file)
@@ -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;