]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 8 Jan 2017 03:31:31 +0000 (03:31 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 8 Jan 2017 03:31:31 +0000 (03:31 +0000)
13 files changed:
bin/dbq
etc/profile.d/dbq.sh
etc/profile.d/functions
lib/php/db/field.php
lib/php/db/table.php
lib/php/http.php
lib/php/out.php
share/db/sys.sql [new file with mode: 0644]
share/db/update.sh
src/Docker/php/Dockerfile
www/dbq/dbq.php
www/dbq/docker-compose.yaml
www/dbq/html/default.css

diff --git a/bin/dbq b/bin/dbq
index 72c74ef34671ff37768ccef6aedf37230d94bced..895373e0c8f74ffc157d27ce830451c3017c7435 100755 (executable)
--- a/bin/dbq
+++ b/bin/dbq
@@ -44,9 +44,9 @@ my %CMD_ALIASE = (
 # NB 09.04.16   'h' => 'header',
 );
 
-## Vim: r!% --curl_help_hash | grep X
 my @H;
 my %CURL_OPT = (
+#>_SHELL_REPLACE dbq --curl_help
   'compressed|z!' => 1, # Request compressed response (using deflate or gzip)
   'dump-header|D=s' => undef, # FILE  Write the headers to FILE
   'get|G!' => undef, # Send the -d data with a HTTP GET (H)
@@ -56,6 +56,7 @@ my %CURL_OPT = (
   'insecure|k!' => undef, # Allow connections to SSL sites without certs (H)
   'user-agent|A=s' => undef, # STRING  User-Agent to send to server (H)
   'user|u=s' => undef, # USER[:PASSWORD]  Server user and password
+#<_SHELL_REPLACE
 );
 my @CURL_OPT = keys %CURL_OPT;
 my $CURL_OPT_EXP = join('|',map{ /^(.*?)\|/ ? $1 : $_ } @CURL_OPT);
index 21d483e9c8a28aa37316b40115f5a454f7e336e2..e6e6f10675746f3cfd8b60540fe68afe63b0566e 100644 (file)
@@ -11,3 +11,7 @@ dbq2mysql() {
 dbq2pgsql() {
   dbq f=txt a=db.dump db.type=pgsql $@
 }
+
+dbq_data_src() {
+  eval $(dbq t=data_src header=0 format=csv rows.fields=src name=$1)
+}
index 6895df0ef3220179a82f2838444a8c5bcd9709aa..00c6a7cf7d7d72934d6a507410f93e8540301f42 100644 (file)
@@ -774,7 +774,7 @@ http_get() {
     echo "Can't find web client" 1>&2
   fi
 }
-alias Get=http_get
+# NB 07.01.17 alias Get=http_get
 
 http_head() {
   if which curl 1>/dev/null; then
index ba96d60842b0d7dea644795b0e2275b1d318804d..6ddc1912399f2050f1970d60e0ed47792feebb77 100644 (file)
@@ -75,14 +75,14 @@ class field extends nb {
   public function html_edit($value,$type=null) {
 
     $size = ($this->size() and is_scalar($this->size())) ? $this->size() : 0;
-    $tag = ( ($size>$this->textarea_size) or preg_match('/^(text|binary)/i',$this->type) ) ? 'textarea' : 'input';
+    $tag = ( ($size>$this->textarea_size) or preg_match('/^(text|binary|blob)/i',$this->type) ) ? 'textarea' : 'input';
     return '<div class="label '.$this->name.'"><label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
       .($this->extras
         ? '<span class="extra" id="'.$this->name.'">'.$this->out($value).'</span>'
         : '<'.$tag
           .' name="'.$this->name.'"'
           .' id="'.$this->name.'"'
-          .( $size ? ' size="'.$size.'"' : '')
+          .( ($size and $tag != 'textarea') ? ' size="'.$size.'"' : '')
           #.' value="'.$value.'"'
           .($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'
             .($type ? $type : $this->html_type())
index e4c9c39a31c33e26248edfb8c0965da97a4875b6..e8ca333554f76917e2b44852158c90c17814c762 100644 (file)
@@ -103,11 +103,11 @@ Class Table extends nb {
     }
 
     # NB 22.12.16: TODEL 
-    $this->show_header =
-      (bool)$this->p('header',$this->show_header)
-    ;
-    # TODE FOR out::
+    $this->show_header = (bool)$this->p('header',$this->show_header);
+
+    # TODEL WHEN NOT NEEDED ????
     $this->pdef('header',$this->show_header);
+    #bye((int)$this->show_header);
 
   }
 
@@ -895,7 +895,11 @@ Class Table extends nb {
     # Run query
     #
     $this->create_temporary();
+
+    $this->show_header = (bool)$this->p('rows.header',$this->show_header);
     $this->db()->out->header($this->show_header);
+    # TODEL WHEN NOT NEEDED ????
+    $this->pdef('header',$this->show_header);
 
     if ($opt_by_val !== null) $opt = $opt_by_val;
 
index 9b1ff0e6253a611a81b8ac57a251bb1a0a1a54df..a6975ed03bdd0c9054a22206c7dbb544e1d00cb5 100644 (file)
@@ -84,6 +84,8 @@ class Http {
 '525' => 'SSL Handshake Failed',
 '526' => 'Invalid SSL Certificate',
 '527' => 'Railgun Error',
+'103' => 'Checkpoint',
+'419' => 'I',
 #<SHELL_REPLACE
   ];
 
index 16712b0103b7707eae09359c3aecb9f3c850d3dd..ae4723c2186cb9bf47f3aedef2c6eb23faf623c3 100644 (file)
@@ -9,9 +9,9 @@ Class Out extends Nb {
   protected static $header = true;
   public static function init() {
 
-    self::$header =
-      (bool)self::p('header',self::$header)
-    ;
+    self::$header = (bool)self::p('header',self::$header);
+    #self::$header = (bool)self::p('out.header',self::$header);
+
     self::$types = [
 
       'sql' => [], # Code still in db/table.php !
@@ -99,6 +99,8 @@ Class Out extends Nb {
           foreach ($r as $k=>$v) {
             if (!preg_match('/^[a-zA-Z\w_]+$/',$k)) continue;
             $v = str_replace('"','\\"',$v);
+            $v = str_replace('$','\\$',$v);
+            $v = str_replace('`','\\`',$v);
             $line[] = $o['preff']."$k=\"$v\"";
           }
           if ($line) echo join(' ',$line).";\n";
@@ -208,6 +210,7 @@ Class Out extends Nb {
     foreach ([
       'charset',
       'type',
+      'header',
     ] as $k) {
       if (isset($opt[$k])) self::$k($opt[$k]);
       unset($opt[$k]);
@@ -221,6 +224,8 @@ Class Out extends Nb {
   }
 
   public static function charset($set=null) { if (!empty($set)) self::$charset = $set; return self::$charset; }
+  public static function type($set=null) { if (!empty($set)) self::$type = $set; return self::$type; }
+  public static function header($set=null) { if (!empty($set)) self::$header = $set; return self::$header; }
 
   public static function types($type=null) {
     if ($type === '_web_') return array_filter(self::$types,function($v){return !isset($v['_web_']) or (bool)$v['_web_'];});
@@ -228,9 +233,6 @@ Class Out extends Nb {
     return self::$types;
   }
 
-  public static function type($set=null) { if (!empty($set)) self::$type = $set; return self::$type; }
-  public static function header($set=null) { if (!empty($set)) self::$header = $set; return self::$header; }
-
   public static function scalar($v) {
     if ($v === null) return '';
     if (is_scalar($v)) return $v;
diff --git a/share/db/sys.sql b/share/db/sys.sql
new file mode 100644 (file)
index 0000000..d86cbb5
--- /dev/null
@@ -0,0 +1,30 @@
+--DROP TABLE IF EXISTS service;
+CREATE TABLE IF NOT EXISTS service (
+  name VARCHAR(100),
+  description VARCHAR(200),
+  PRIMARY KEY (port,name)
+);
+
+--DROP TABLE IF EXISTS service_port;
+DROP TABLE IF EXISTS service_port;
+DROP TABLE IF EXISTS port;
+CREATE TABLE IF NOT EXISTS port (
+  port INT,
+  proto VARCHAR(3),
+  name VARCHAR(100),
+  PRIMARY KEY (port,proto,name),
+  FOREIGN KEY(name) REFERENCES service(name)
+);
+
+--DROP TABLE IF EXISTS http_status;
+CREATE TABLE IF NOT EXISTS http_status (
+  id int PRIMARY KEY,
+  name varchar(100),
+  description varchar(1000)
+);
+
+DROP TABLE IF EXISTS shell_function;
+CREATE TABLE shell_function (
+  name VARCHAR(255) PRIMARY KEY,
+  code BLOB
+);
index 6d96a7696d9d744565c9f179f130c8525c76ae1e..8dc00cd441cbda4726be92895fbb3cb88ac364f0 100755 (executable)
@@ -1,23 +1,93 @@
 #!/usr/bin/env bash --login
-set -e
-cd "$(dirname "$0")"
+set +e
+dir=$(dirname "$0")
+tmp=`mktemp -d`
+
+csv2table() {
+  local name="$1"; shift
+  local file="$1"; shift
+
+  cat << EOF
+DELETE FROM _var;
+DROP TABLE IF EXISTS ${name}_tmp;
+CREATE TEMPORARY TABLE ${name}_tmp AS SELECT * FROM $name WHERE 0;
+
+INSERT INTO _var VALUES('pre',(SELECT count(*) FROM ${name}));
+
+-- SELECT 'Update $name ('||(SELECT count(*) FROM ${name})||')';
+
+BEGIN TRANSACTION;
+.import "$file" ${name}_tmp
+COMMIT;
+INSERT INTO _var VALUES('import',(SELECT count(*) FROM ${name}_tmp));
+
+INSERT OR IGNORE INTO $name SELECT * FROM ${name}_tmp;
+INSERT INTO _var VALUES('post',(SELECT count(*) FROM ${name}));
+
+SELECT 'Update sys:$name ('
+  || ((SELECT v FROM _var WHERE k='post')-(SELECT v FROM _var WHERE k='pre'))
+  || '/' 
+  ||(SELECT v FROM _var WHERE k='import')
+||')'
+||' = ('||(SELECT count(*) FROM ${name})||')'
+;
+EOF
+}
+
+data_src() {
+  #pwd
+
+  perl -ne 'm,^(\w+)\s+\d+/\w+\s+#\s*(.*?)$, and $_=join(qq|\t|,map(/^\s*(.*?)\s*$/,$1,$2)).qq|\n| and !$h{$_}++ and print' \
+    /etc/services \
+    > "$tmp/service.csv"
+  csv2table service "$tmp/service.csv"
+
+  perl -ne 'm,^(\w+)\s+(\d+)/(\w+)\s+#\s*(.*?)$, and print join(qq|\t|,map(/^\s*(.*?)\s*$/,$2,$3,$1)).qq|\n|' \
+    /etc/services \
+    > "$tmp/port.csv"
+  csv2table port "$tmp/port.csv"
+
+  return 0
+  w3m -dump -cols 999999 https://en.wikipedia.org/wiki/List_of_HTTP_status_codes| \
+    perl -ne 'next unless /^\d\d\d / .. /^ /;s/.\[\d+\]//g; s/^ *//; s/^(\d+) ([\w _-]+).*?\n$/$1\t$2\t/;print' \
+    > "$tmp/http_status.csv"
+  csv2table http_status "$tmp/http_status.csv"
+
+  curl -s http://pgl.yoyo.org/adservers/serverlist.php?hostformat=nohtml \
+    > "$tmp/adservers.csv"
+  csv2table adservers "$tmp/adservers.csv"
+
+  curl -s 'http://www.user-agents.org/' | perl -e '$_=join(qq||,<>); print map {s/^\s*(.*?)(?:.nbsp.)?\s*$/$1/;qq|$_\n|} m,<td class=.right.>([^<]+),g'
+    > "$tmp/useragent.csv"
+  csv2table useragent "$tmp/useragent.csv"
+
+}
+
 (
 
+cat "$dir/sys.sql"
 cat << EOF
 PRAGMA foreign_keys=OFF;
-BEGIN TRANSACTION;
+.separator \t
+CREATE TEMPORARY TABLE _var (k varchar(10),v varhcar(10));
 
-SELECT 'Update sys.shell_function';
-`shell_functions2sql shell_function`
+`data_src`
 
+SELECT 'Update sys:shell_function';
+BEGIN TRANSACTION;
+`shell_functions2sql shell_function`
 COMMIT;
+
+VACUUM;
 EOF
 
-) | sqlite3 sys.db
+) | sqlite3 "$dir/sys.db"
+
+#cp -a "$tmp/" /Users/nico/Downloads/commit/
+rm -rf "$tmp"
 
-IFS=$'\n'
-for f in $(grep -lrI SHELL_REPLACE $NB_ROOT); do
+for f in $(grep -ErlI '^.{1,3}<SHELL_REPLACE' $NB_ROOT); do
 
-  echo "Update $f"
+  echo "Update $f" | sed "s; $NB_ROOT/; ;"
   shell_replace -i "$f"
 done
index 6f743cefc613b752022d09911f7a5b6385cf4ea1..27172f5c4cbe953dca495d34adf1cd97211d40d9 100644 (file)
@@ -10,4 +10,5 @@ RUN mkdir -p /var/www/html && echo '<html><head><title>Welcom to php:7.0-fpm-alp
 
 EXPOSE 9000
 #CMD ["/usr/local/bin/php", "-a"]
+#ENTRYPOINT printf "[www]\n\nuser = $USER\n" > /usr/local/etc/php-fpm.d/www.conf.default && /usr/local/sbin/php-fpm
 ENTRYPOINT /usr/local/sbin/php-fpm
index 5a48eb48a6a1613a444bfa9a579a430b8be6f0b6..bad188c5cb9b29c3725b4c564d52b0bd7dba7f95 100644 (file)
@@ -24,6 +24,7 @@ class DbQ extends nb {
   public $uri_params;
   public $param_args_sep = '|';
   public $param_exp_value = '[\w\._:-]{2,100}';
+  const ACTIONS_NO_TITLE = ['ls','vi'];
   const PARAM_DB_DEFAULT = 'ls';
   public $params = [
     'format' => '',
@@ -220,7 +221,7 @@ class DbQ extends nb {
     if (!$keys) $keys = $all;
     $keys = array_keys($keys);
 
-    $values = explode($this->param_args_sep,$this->params['args']);
+    $values = $add ? array_fill(0,count($keys),'') : explode($this->param_args_sep,$this->params['args']);
 
     $this->table->html_edit(array_combine($keys,$values),$this->table->base.($add ? 'insert/' : 'update/').$this->params['args'],$add);
   }
@@ -296,12 +297,10 @@ class DbQ extends nb {
     $params = $this->params;
     $ext = $this->ext;
 
-    /*
-    $title = array_unique(array_slice(array_values($params),1));
-    */
     $title = array_filter(array_unique(array_slice(array_values($params),1)),
       function($v){
-        return($v==self::PARAM_DB_DEFAULT ? '' : $v);
+        return(in_array($v,self::ACTIONS_NO_TITLE) ? '' : $v);
+# NB 07.01.17         return($v==self::PARAM_DB_DEFAULT ? '' : $v);
       }
     );
 
index cbfb0328efcb5c168a685c633aba4b924484f70d..e357eabbe47edb0578ae320b08a50a51395e01a4 100644 (file)
@@ -16,7 +16,8 @@ services:
       - $HOME/.dbq:/etc/dbq
       - $HOME/ownCloud/var/lib/sqlite:/var/lib/sqlite
 # NB 16.12.16     network_mode: "host"
-    entrypoint: sh -c "echo . $NB_ROOT/etc/profile > /etc/profile.d/nb.sh && /usr/local/sbin/php-fpm"
+    #entrypoint: sh -c "echo . $NB_ROOT/etc/profile > /etc/profile.d/nb.sh && /usr/local/sbin/php-fpm"
+    entrypoint: sh -c "echo . $NB_ROOT/etc/profile > /etc/profile.d/nb.sh && echo _www:x:50:www-data >> /etc/group && /usr/local/sbin/php-fpm"
     #entrypoint: "/usr/local/sbin/php-fpm"
 
   nginx: 
index aeafd5adfbc65fef809cc0713172ca4e9ae1ba19..f4cc36277bb27be68ec2a7f6cb5f17c4528ff1a8 100644 (file)
@@ -54,6 +54,7 @@ input[type=''] {
   border: solid 1px #ddd;
   padding: 0.3em 0.4em;
 }
+
 input[size] {
   max-width: 70%;
 }
@@ -222,6 +223,3 @@ form.edit .fields .label span {
   text-align: left;
 }
 
-form.edit .fields input, form.edit .fields textarea, form.edit .fields select {
-  width: 65%;
-}