From: Nicolas Boisselier Date: Fri, 1 Dec 2017 05:05:17 +0000 (+0000) Subject: lib/php/db/shell.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=9d5455dd3897143435fc93fdc77649ba4e7e37a9;p=nb.git lib/php/db/shell.php --- diff --git a/etc/profile.d/envs b/etc/profile.d/envs index b016c40f..2a718c67 100644 --- a/etc/profile.d/envs +++ b/etc/profile.d/envs @@ -55,6 +55,12 @@ MANPATH=$(env_add_path "$MANPATH" \ ) export MANPATH +# Awk lib +AWKPATH=$(env_add_path "$AWKPATH" \ + $NB_ROOT/lib/awk +) +[ -n "$AWKPATH" ] && export AWKPATH + fi # < env_add_path # diff --git a/lib/awk/ldap2csv.awk b/lib/awk/ldap2csv.awk index 14a40128..9fba2c2f 100755 --- a/lib/awk/ldap2csv.awk +++ b/lib/awk/ldap2csv.awk @@ -1,32 +1,6 @@ #!/usr/bin/gawk -f -function base64decode(str) { - BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" - - result = "" - - # Specify byte values - base1 = substr(str, 1, 1) - base2 = substr(str, 2, 1) - base3 = substr(str, 3, 1) - base4 = substr(str, 4, 1) - # Now find numerical position in BASE64 string - byte1 = index(BASE64, base1) - 1 - if (byte1 < 0) byte1 = 0 - byte2 = index(BASE64, base2) - 1 - if (byte2 < 0) byte2 = 0 - byte3 = index(BASE64, base3) - 1 - if (byte3 < 0) byte3 = 0 - byte4 = index(BASE64, base4) - 1 - if (byte4 < 0) byte4 = 0 - # Reconstruct ASCII string - result = result sprintf( "%c", lshift(and(byte1, 63), 2) + rshift(and(byte2, 48), 4) ) - result = result sprintf( "%c", lshift(and(byte2, 15), 4) + rshift(and(byte3, 60), 2) ) - result = result sprintf( "%c", lshift(and(byte3, 3), 6) + byte4 ) - # Decrease incoming string with 4 - str = substr(str, 5) - return str -} - +#lib=ENVIRON["NB_ROOT"]"/lib/awk" +@include "base64decode.awk" BEGIN { FS = ": " CONCAT = " " @@ -64,7 +38,6 @@ BEGIN { if (i ~ /:$/) { # NB 01.12.17 cmd="echo "h[i]" | base64 -d" -# NB 01.12.17 cmd='base64 -d <<< "'h[i]."' # NB 01.12.17 cmd | getline x # NB 01.12.17 close(cmd) # NB 01.12.17 h[i] = x @@ -84,7 +57,7 @@ BEGIN { next } -1 && /: / && !/^(objectClass_): / { +/: / && !/^(objectClass_): / { FOUND = 1 field = $1 diff --git a/lib/php/db/shell.php b/lib/php/db/shell.php index 78404e25..0f517375 100755 --- a/lib/php/db/shell.php +++ b/lib/php/db/shell.php @@ -98,7 +98,7 @@ function db_shell_action($k,$v) { } if (empty($Db)) { - echo "Database is missing, use db= or try help\n"; + echo "!Database is missing, use db= or try help\n"; break; } $Db->action($Db->p('action'),$Table); @@ -106,6 +106,10 @@ function db_shell_action($k,$v) { case 'db': #bye($DB_CONFS[$v]); + if (empty($DB_CONFS[$v])) { + echo "!Unknown database: $v\n"; + break; + } $Db = new Db($DB_CONFS[$v]+['conf'=>$DB_CONFS]); $Db->connect(); break; @@ -124,7 +128,7 @@ function db_shell_action($k,$v) { break; # default: -# echo "ERR: $k=$v\n"; +# echo "!ERR: $k=$v\n"; # Db::pset($k,null); # break;