]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/shell.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 1 Dec 2017 05:05:17 +0000 (05:05 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 1 Dec 2017 05:05:17 +0000 (05:05 +0000)
etc/profile.d/envs
lib/awk/ldap2csv.awk
lib/php/db/shell.php

index b016c40f07725765d045ca34729677c5d4edea13..2a718c67942eea9e1ebf597acc57db4d0b1fe952 100644 (file)
@@ -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
 
 #
index 14a4012803851ca722fb5ce9e68cde1d282dde00..9fba2c2f3469121849d54599f098a28a621be158 100755 (executable)
@@ -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
index 78404e2591cdd90f855ec2e5be49ecd3cd6a654e..0f517375a139c72b9e61ec75e1eab20ad15e4b63 100755 (executable)
@@ -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;