# !!! MANDATORY !!!
#
$DBQ = [
- 'nb-sys' => [
+ 'nb' => [
'type' => 'sqlite',
- 'name' => 'Sys',
+ 'name' => 'Nb',
'default_table' => 'mime',
- 'host' => nb::ROOT_DIR.'/share/db/sys.db',
+ 'host' => nb::ROOT_DIR.'/share/db/nb.db',
],
];
?>
+export NB_DB=nb
+
nb_repos_commit_push() {
shell_help "Commit each repos whith a comment" "$@" && return
local status
"
" Command to check files per file types
"
-">SHELL_REPLACE echo "let mimeCheck = {"; dbq db=nb-sys t=mime -cut 1,3 | sort -k 1 | sed -E -e "s/'/''/g" -e "s/^(.*?)\t(.*)$/ \\\,'\1' : '\2'/" -e "0,/,/s/,//" ; echo "\}"
+">SHELL_REPLACE echo "let mimeCheck = {"; dbq db=$NB_DB t=mime -cut 1,3 | sort -k 1 | sed -E -e "s/'/''/g" -e "s/^(.*?)\t(.*)$/ \\\,'\1' : '\2'/" -e "0,/,/s/,//" ; echo "\}"
let mimeCheck = {
\'bash' : 'bash -c'
\,'erb' : 'sh -c \"cat | erb -x - | ruby -c\" <'
<?php
class Http {
const Status = [
-#>SHELL_REPLACE dbq db=nb-sys t=http_status -cut 1,2 | perl -pe "s/'/\\\\'/; s/^(.*?)\t(.*?)$/ '\$1' => '\$2',/"
+#>SHELL_REPLACE dbq db=$NB_DB t=http_status -cut 1,2 | perl -pe "s/'/\\\\'/; s/^(.*?)\t(.*?)$/ '\$1' => '\$2',/"
'100' => 'Continue',
'101' => 'Switching Protocols',
'102' => 'Processing',
<?php
class Mime {
const Types = [
-#>SHELL_REPLACE dbq db=nb-sys t=mime_type -cut 2,3 | perl -pe "s/'/\\\\'/; s/^(.*?)\t(.*?)$/ '\$1' => '\$2',/"
+#>SHELL_REPLACE dbq db=$NB_DB t=mime_type -cut 2,3 | perl -pe "s/'/\\\\'/; s/^(.*?)\t(.*?)$/ '\$1' => '\$2',/"
'application/applixware' => 'aw',
'application/atom+xml' => 'atom xml',
'application/atomcat+xml' => 'atomcat',
const ROOT_DIR = NB_ROOT;
const NB_ROOT = NB_ROOT;
- # Sql: elect type,ext from mime_type where ext in ('json','csv','txt','yaml','xml','html','doc','xls');
protected static $content_types_aliases = array(
+ #>_SHELL_REPLACE dbq db=$NB_DB table="SELECT type,ext FROM mime_type WHERE ext IN ('json','csv','txt','yaml','xml','html','doc','xls')"
'text' => 'txt',
'human' => 'txt',
'table' => 'html',
'div' => 'html',
+ #<_SHELL_REPLACE
);
protected static $content_types = array(
if ($name === null) return isset($_GET) ? $_GET : [];
return isset($_GET[$name]) ? $_GET[$name] : $default;
}
+
public static function p($name=null,$default=null) {
if(NB_P_GET) return self::_p_get($name,$default);
if ($name === null) return isset($_REQUEST) ? $_REQUEST : [];
'end' => 'out_human_end',
],
+ 'php_hash' => [
+ 'align' => ' => ',
+ 'eol' => ",\n",
+ 'quote' => "'",
+ ],
+
'cust' => [
'_web_' => false,
'cust' => self::p('cust',"CHANGE ME"),
echo $call($o,$row);
# Internal method
- } elseif(is_scalar($o[$k]) and preg_match('/^out_tag|out_human/',$o[$k])) {
+ } elseif(is_scalar($o[$k]) and preg_match('/^(out_tag|out_human|out_size)/',$o[$k])) {
$f = $o[$k];
echo self::$f($o,$row);
}
public static function head(&$o,$head,$data=[]) {
- $o['out_count'] = 0;
+ $o['row_count'] = 0;
# Format $head
if ($head !== false) {
) return;
if (self::type_call('head',$o,$head)) {
- $o['out_count']++;
+ $o['row_count']++;
if (isset($o['eol'])) echo $o['eol'];
}
return $head;
public static function row(&$o,&$row) {
- if ($o['out_count'] and isset($o['rec'])) echo $o['rec'];
- if (self::type_call('row',$o,$row)) {
+ if ($o['row_count'] and isset($o['rec'])) echo $o['rec'];
+ $o['row_count']++;
+
+ # buffering
+ if (!empty($o['align'])) {
+ if (!isset($o['sep'])) $o['sep'] = $o['align'];
+ if (!isset($o['rows'])) $o['rows'] = [];
+ if (!isset($o['length'])) $o['length'] = [];
+
+ $tmp_row = $row;
+ foreach ($tmp_row as $k => $v) {
+ if (!isset($o['length'][$k])) $o['length'][$k] = 0;
+ if (!empty($o['quote'])) $tmp_row[$k] = $v = self::quote($v,$o['quote'],isset($o['quote_escape']) ? $o['quote_escape'] : null);
+ $l = mb_strlen($v,self::$charset);
+ if ($l > $o['length'][$k]) $o['length'][$k] = $l;
+ }
+
+ $o['rows'][] = $tmp_row;
+ return true;
+
+ # row() or defined
+ } elseif (self::type_call('row',$o,$row)) {
$ret = true;
# Assume html/xml tag style
}
if (isset($o['eol'])) echo $o['eol'];
- $o['out_count']++;
return $ret;
}
public static function end(&$o) {
#if (isset($o['end'])) echo $o['end']($o);
+ if (!empty($o['align'])) {
+ foreach ($o['rows'] as $rec) {
+ $values = [];
+
+ foreach ($rec as $k => $v) {
+ $v = self::mb_str_pad($v, $o['length'][$k], ' ', STR_PAD_RIGHT);
+ $values[] = $v;
+ }
+
+ echo join($o['sep'],$values) . $o['eol'];
+ }
+ return;
+ }
+
self::type_call('end',$o);
if (isset($o['enclose'])) echo $o['enclose'][1];
- unset($o['out_count']);
+ unset($o['row_count']);
}
public static function rows_get($type,$data,$head=array()) {
# NB 27.09.16 if ($count>0) self::row_end($conf);
$count++;
+
self::row($conf,$row);
}
return $v;
}
+ public static function quote($str,$quote='"',$quote_escape='\\') {
+ if ($quote === null or $quote == true) $quote = '"';
+ if ($quote_escape === null) $quote_escape = '\\';
+ $str = str_replace($quote,$quote_escape.$quote,$str);
+ $str = $quote . $str . $quote;
+ return $str;
+ }
+
public static function row_txt(&$o,&$row) {
if (!isset($o['col'])) $o['col'] = '';
self::row_parse($row,$o);
# header
if (!$count) echo $sep_line;
-# NB 23.11.17 if ($header or $count) echo ''
echo ''
. ltrim($o['_human']['sep'])
. join($o['_human']['sep'],$values)
}
+ private static function out_sized(&$o,&$recs) {
+ $len = [];
+
+ foreach ($recs as $rec) {
+
+ foreach ($rec as $k => $v) {
+ if (!isset($len[$k])) $len[$k] = 0;
+
+ $l = mb_strlen($v,self::$charset);
+
+ if ($l > $len[$k]) $len[$k] = $l;
+ }
+
+ }
+
+ foreach ($recs as $rec) {
+ $values = [];
+
+ foreach ($rec as $k => $v) {
+ $v = self::mb_str_pad($v, $len[$k], ' ', STR_PAD_RIGHT);
+ $values[] = $v;
+ }
+
+ echo join($o['sep'],$values) . $o['eol'];
+ }
+
+ }
+
} Out::init() ; # < Class
/****************************************************************************/
--- /dev/null
+-- NB 05.12.17 DROP TABLE IF EXISTS service;
+-- NB 25.10.17 CREATE TABLE IF NOT EXISTS service (
+-- NB 25.10.17 name VARCHAR(100),
+-- NB 25.10.17 description VARCHAR(200),
+-- NB 25.10.17 PRIMARY KEY (port,name)
+-- NB 25.10.17 );
+
+-- NB 25.10.17 DROP TABLE IF EXISTS service_port;
+
+-- NB 25.10.17 DROP TABLE IF EXISTS ovh_dedicated;
+-- NB 25.10.17 CREATE TABLE ovh_dedicated (
+-- NB 25.10.17 offer VARCHAR(80),
+-- NB 25.10.17 proc VARCHAR(150),
+-- NB 25.10.17 cpu VARCHAR(150),
+-- NB 25.10.17 ram VARCHAR(150),
+-- NB 25.10.17 disk VARCHAR(150),
+-- NB 25.10.17 option VARCHAR(100),
+-- NB 25.10.17 price float(5,2)
+-- NB 25.10.17 );
--- /dev/null
+-- DROP TABLE IF EXISTS http_status;
+CREATE TABLE IF NOT EXISTS http_status (
+ id int PRIMARY KEY,
+ name varchar(100),
+ description varchar(1000)
+);
--- /dev/null
+CREATE TABLE IF NOT EXISTS mime (
+ id varchar(32) NOT NULL PRIMARY KEY,
+ name varchar(128),
+ cmd_check varchar(300)
+);
--- /dev/null
+CREATE TABLE IF NOT EXISTS mime_type (
+ name varchar(128),
+ type varchar(128) NOT NULL DEFAULT '' PRIMARY KEY,
+ ext varchar(128)
+);
+CREATE INDEX IF NOT EXISTS mime_type_ext_idx ON mime_type (ext);
--- /dev/null
+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)
+);
--- /dev/null
+DROP TABLE IF EXISTS shell_function;
+CREATE TABLE shell_function (
+ name VARCHAR(255) PRIMARY KEY,
+ code BLOB
+);
+++ /dev/null
--- NB 05.12.17 DROP TABLE IF EXISTS service;
--- NB 25.10.17 CREATE TABLE IF NOT EXISTS service (
--- NB 25.10.17 name VARCHAR(100),
--- NB 25.10.17 description VARCHAR(200),
--- NB 25.10.17 PRIMARY KEY (port,name)
--- NB 25.10.17 );
-
--- NB 25.10.17 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
-);
-
--- NB 25.10.17 DROP TABLE IF EXISTS ovh_dedicated;
--- NB 25.10.17 CREATE TABLE ovh_dedicated (
--- NB 25.10.17 offer VARCHAR(80),
--- NB 25.10.17 proc VARCHAR(150),
--- NB 25.10.17 cpu VARCHAR(150),
--- NB 25.10.17 ram VARCHAR(150),
--- NB 25.10.17 disk VARCHAR(150),
--- NB 25.10.17 option VARCHAR(100),
--- NB 25.10.17 price float(5,2)
--- NB 25.10.17 );
-CREATE TABLE IF NOT EXISTS mime (
- id varchar(32) NOT NULL PRIMARY KEY,
- name varchar(128),
- cmd_check varchar(300)
-);
-CREATE TABLE IF NOT EXISTS mime_type (
- name varchar(128),
- type varchar(128) NOT NULL DEFAULT '' PRIMARY KEY,
- ext varchar(128)
-);
-CREATE INDEX IF NOT EXISTS mime_type_ext_idx ON mime_type (ext);
#!/bin/bash --login
set +e
-dir=$(dirname "$0")
+DIR=$(dirname "$0")
tmp=`mktemp -d`
csv2table() {
# NB 25.10.17 perl -ne 'm,^(\w+)\s+\d+/\w+\s+#\s*(.*?)$, and $_=join(qq|\t|,map(/^\s*(.*?)\s*$/,$1,$2)).qq|\n| and !$h{$_}++ and print' \
# NB 25.10.17 /etc/services \
-# NB 25.10.17 > "$tmp/service.csv"
-# NB 25.10.17 csv2table service "$tmp/service.csv"
+# NB 25.10.17 > "$TMP/service.csv"
+# NB 25.10.17 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"
+ > "$TMP/port.csv"
+ csv2table port "$TMP/port.csv"
# NB 25.10.17 html-table2csv https://www.ovh.co.uk/dedicated_servers/|perl -ne \
# NB 25.10.17 '/^\w/ or next; @F=split("\t",$_);splice(@F,6,1); $F[6] =~s/ ex.*$//; $F[6] =~s/[^\d\.]//g; print $_ if $_=join("\t",map{$_ eq "-" ? "" : $_} @F[0..6])."\n" and !$dbl{$_}++' \
-# NB 25.10.17 > "$tmp/ovh_dedicated.csv"
-# NB 25.10.17 csv2table ovh_dedicated "$tmp/ovh_dedicated.csv"
+# NB 25.10.17 > "$TMP/ovh_dedicated.csv"
+# NB 25.10.17 csv2table ovh_dedicated "$TMP/ovh_dedicated.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"
+ > "$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"
+ > "$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"
+ > "$TMP/useragent.csv"
+ csv2table useragent "$TMP/useragent.csv"
}
(
-cat "$dir/sys.sql"
+cat "$DIR/*.sql"
cat << EOF
PRAGMA foreign_keys=OFF;
.separator \t
VACUUM;
EOF
-) | sqlite3 "$dir/sys.db"
+) | sqlite3 "$DIR/nb.db"
-#cp -a "$tmp/" /Users/nico/Downloads/commit/
-rm -rf "$tmp"
+rm -rf "$TMP"
(
-export DBQ_PARAMS="db=nb-sys"
-
for f in $(grep -ErlI '^.{1,3}<SHELL_REPLACE' $NB_ROOT); do
echo "Update $f" | sed "s; $NB_ROOT/; ;"