]> git.nbdom.net Git - nb.git/commitdiff
www/dbq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 3 Dec 2016 21:22:11 +0000 (21:22 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 3 Dec 2016 21:22:11 +0000 (21:22 +0000)
etc/profile.d/mac.sh
etc/profile.d/sys.sh
lib/php/db.php
www/dbq/etc/nginx/default.conf
www/dbq/html/index.php

index 4749e8db87cb48c74609766611c8021c5faa2d3d..395f054e55e4a6e3756553806b976ae9a59be354 100644 (file)
@@ -131,6 +131,7 @@ mac_install() {
       local os=$(mac_version)
       local vers="8.2_beta_2"
       open "http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_macOS_${os}_for_Xcode_${vers}/Command_Line_Tools_macOS_${os}_for_Xcode_${vers}.dmg"
+      return
     ;;
 
     virtualbox)
@@ -138,8 +139,13 @@ mac_install() {
     ;;
 
     macport)
+      #prg="https://github.com"$(getexp_url '[^"]+'$(mac_version_name)'.*?pkg' "https://github.com/macports/macports-base/releases")
       prg=$(getexp_url 'https?://.*'$(mac_version_name)'[^"\s]+pkg' https://www.macports.org/install.php)
+      echo 'Please visit https://www.macports.org/install.php'
+      return
+      #echo ">$prg"; return;
     ;;
+
   esac
 
   #echo ">$prg"; return
@@ -152,7 +158,9 @@ mac_install() {
       #type mac_install|perl -ne '/^\s*([\w-_]+)\)/&&push(@a,$1);END{print join("|",@a)}'
     return
     ;;
-    *.pkg) udo installer -verbose -pkg "$prg" -target / ;;
+    *.pkg)
+      sudo installer -verbose -pkg "$prg" -target /
+    ;;
     *)
       local MOUNTDIR=$(echo `sudo hdiutil mount "$prg" | tail -1 | awk '{$1=$2=""; print $0}'` | xargs -0 echo)
 
index 3560eecbf5bd039d1a7cd160d37a262bb8ebda28..5d6522a150569a7be8fc04c58f81bcf25d693209 100644 (file)
@@ -1,6 +1,6 @@
 case "$OSTYPE" in
   linux*) [ 1 ] ;;
-  *) return ;;
+  #*) return ;;
 esac
 
 sys_is_vm() {
@@ -14,6 +14,10 @@ sys_watch() {
   watch --no-title $opt bash -c "sys_activity"
 }
 
+sys_logs() {
+  true
+}
+
 sys_activity() {
 
   local tmp=/tmp/
@@ -21,13 +25,13 @@ sys_activity() {
   tmp="$tmp/$FUNCNAME.$$"
   netstat -autpn > $tmp.netstat
 
-  echo 'Load:'
-  w | head -1
-  echo
-
-  echo 'IO:'
-  iostat -c -m -d -x `df -hT -x tmpfs|perl -ane 'm:^/: and print $F[0]."\n"'` | tail -n +3 | grep -vFx ''| sed 's/^/  /'
-  echo
+  case "$OSTYPE" in
+    linux*)
+      echo 'IO:'
+      iostat -c -m -d -x `df -hT -x tmpfs|perl -ane 'm:^/: and print $F[0]."\n"'` | tail -n +3 | grep -vFx ''| sed 's/^/  /' 
+      echo
+    ;;
+  esac
 
   echo 'Mem:'
   free -hm | sed 's/^/  /'
@@ -37,13 +41,21 @@ sys_activity() {
   cat "$tmp.netstat" | tail -n +2 | awk '$5~/^[0-9]/{gsub(/:.*/,"",$5);print $5}' | sort | uniq -c| sed 's/^ *//'|sort -nr -k 1 |head | sed 's/^/  /'
   echo
 
-  echo 'dmeg:'
-  dmesg -T | tail | sed 's/^/  /'
+  echo 'dmesg:'
+  ( dmesg -T 2>/dev/null || dmesg ) | tail -4 | sed 's/^/  /'
   echo
 
-  echo 'auth:'
-  tail /var/log/auth.log | sed 's/^/  /'
-  echo
+  if [ -e /var/log/auth.log ]; then
+    echo 'auth:'
+    tail -2 /var/log/auth.log | sed 's/^/  /'
+    echo
+  fi
+
+  if [ -e /var/log/system.log ]; then
+    echo 'system:'
+    tail -5 /var/log/system.log | sed 's/^/  /'
+    echo
+  fi
 
   rm -rf "$tmp"*
 }
index 80eb96d823bd969906f3184d699e77c3b5128ad2..9d995226a68cbeb394ad807d5030b5b7bcf2e759 100644 (file)
@@ -49,7 +49,6 @@ class Db extends nb {
   public $title;
   public $notice;
   public $type;
-  public $table; # table name
   public $tables = [];
   public $types = [];
   public $conf = [];
@@ -380,7 +379,7 @@ class Db extends nb {
   */
   public function table($name='',$params=[]) {
     #if (!array_key_exists($name,$this->tables)) {
-    if (!$name and !empty($this->table)) $name = $this->table;
+    if (!$name and !empty($this->default_table)) $name = $this->default_table;
     if (!$name) bye('table name is empty');
     if (empty($this->tables[$name])) {
       $this->tables[$name] = new Table($name,['db'=>$this]+$params);
@@ -1267,7 +1266,7 @@ class Db extends nb {
     }
   }
   public function page($opt=[]) {
-    return new Page([
+    return new Page(array_merge([
       'title' => ($this->title ? $this->title : this::prettyText($this->name)),
       'css' => [
         'css/*.css',
@@ -1281,29 +1280,9 @@ class Db extends nb {
       'nav' => [
         [ (!empty($this) and !empty($this->title)) ? $this->title : 'Home', '/'],
         ( (!empty($this->table()) and !empty($this->table()->name)) ? [Page::prettyText($this->table()->name),Page::path().'?table='.urlencode($this->table()->name)] : '' ),
-        ( Page::p('action') ? Page::prettyText(Page::p('action')) : '' ),
+        ( Page::p('action') ? Page::prettyText(preg_replace('/^\w+\./','',Page::p('action'))) : '' ),
       ],
-      'call' => array(
-        'begin',
-        #['out', "Hello World !!!\n"],
-
-        function($page){
-          $this->pdef('format',$this->content_type2format($page->content_type()));
-          if (!$page->action()) return $this->action($this->p('action'),$this->table());
-        },
-
-        function($page){
-          #if (!$page->is('html')) return;
-          if (!empty($this)) echo $page->tag('p class="db-infos"',join(' | ',[
-            $this->type,
-            $this->host,
-            ($this->name ? $this->name : null),
-          ]));
-        },
-
-        'end',
-      ),
-    ]);
+    ],$opt));
   }
 
   #public function default_table() { return $this->default_table; }
index 667824314648613f9807047d8597503621be58bd..9f614b03b3efa9604b79ccbf1e008c610b791b37 100644 (file)
@@ -5,13 +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; }
-
     #access_log off;
     #error_log  /var/log/nginx/error.log error;
 
@@ -21,6 +14,34 @@ server {
 
     client_max_body_size 100m;
 
+               ###############################################################
+               # All to index.php
+    location / {
+        try_files $uri $uri/ /index.php?$query_string;
+    }
+
+               ###############################################################
+               # Ignore
+    location = /favicon.ico { access_log off; log_not_found off; }
+    location = /robots.txt  { access_log off; log_not_found off; }
+
+               ###############################################################
+               # Deny
+    location ~ /\. {
+      deny all;
+      access_log off;
+      log_not_found off;
+    }
+
+               ###############################################################
+               # serve static files directly
+               location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
+                               access_log off;
+                               expires    30d;
+               } 
+
+               ###############################################################
+               # FastCGI
     location ~ \.php$ {
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass php:9000;
@@ -32,7 +53,4 @@ server {
         fastcgi_buffers 4 16k;
     }
 
-    location ~ /\.ht {
-        deny all;
-    }
 }
index c2280d329cef92ddf434b9faec8b3b5c2377cef5..298c2d6d77353d611b2618d176fb220310b68445 100644 (file)
@@ -1,6 +1,63 @@
 <?php
+if (empty($_SERVER['DOCUMENT_ROOT'])) $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);
+if (empty($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI'] = '';
+
+$params = [
+  #'db',
+  'action',
+  'table',
+  'format',
+];
+# NB 03.12.16 list(
+# NB 03.12.16   $action,
+# NB 03.12.16   $db,
+# NB 03.12.16   $table,
+# NB 03.12.16   $format,
+# NB 03.12.16 ) = 
+#if (strpos($_SERVER['REQUEST_URI'],'?')!==false) return header('HTTP/1.1 501 Not Implemented');
+if (strpos($_SERVER['REQUEST_URI'],'?')!==false) return http_response_code(501);
+$values = explode('/',$_SERVER['REQUEST_URI']);
+while (count($values)>0 and $values[0]==='') {
+  array_shift($values);
+}
+#for ($i=count($values);$i>0 and $values[
 require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/page.php');
+#debug($_SERVER['REQUEST_URI']);
+
+foreach ($values as $k=>$v) {
+  if ($v!=='') Page::pdef($params[$k],$v);
+}
+
+Page::pdef('format','human');
 Page::pdef('action','ls');
-require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/db/page.php');
+
+require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/db/init.php');
+$Db->page([
+    'call' => [
+      'begin',
+      #['out', "Hello World !!!\n"],
+
+      function($page) use($Db){
+        if (!$page->action()) return $Db->action($Db->p('action'),$Db->table());
+      },
+
+      function($page) use($Db){
+        #global $values; debug($values);
+        if (!$page->is('html')) return;
+        if (!empty($Db)) echo $page->tag('p class="db-infos"',join(' | ',[
+          $Db->type,
+          $Db->host,
+          ($Db->name ? $Db->name : null),
+        ]));
+      },
+
+      'end',
+    ],
+]);
+#require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/db/page.php');
+# /DB/ACTION/[TABLE]/[FORMAT]
+# /ACTION/DB/[TABLE]/[FORMAT]
+#debug($_SERVER['REQUEST_URI']);
+#debug($_SERVER['QUERY_STRING']);
 #debug($_SERVER);
 ?>