]> git.nbdom.net Git - nb.git/commitdiff
cryptkey
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Dec 2016 10:50:09 +0000 (10:50 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Dec 2016 10:50:09 +0000 (10:50 +0000)
lib/php/nb.php
www/dbq/dbq.php

index 85090a2883489b7625605260aa8a3cfeab71999f..5e80a6f8b02de5a622f71175e49d85049b304787 100644 (file)
@@ -835,8 +835,11 @@ class NB {
     return str_pad($input,$pad_length-$mb_diff,$pad_string,$pad_type);
   } 
 
+  public static function cryptkey($length=32) {
+    return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
+  }
+
   public static function encrypt($key,$value) {
-    #$key = hash("SHA256", 'your pass', true); //we want a 32 byte binary blob 
     $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
     $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
     return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_CBC, $iv));
@@ -858,7 +861,7 @@ return;
 if (!count($argv) or (string)$argv[1] != 'test') return;
 $value = 'Hello World !';
 #$value = file_get_contents('/etc/hosts');
-$key = hash("SHA256", '5587eeb68760aa0ed7d2d1212d0829c3', true); //we want a 32 byte binary blob 
+$key = hash("MD5", '5587eeb68760aa0ed7d2d1212d0829c3'); //we want a 32 byte binary blob 
 #$key = '5587eeb68760aa0ed7d2d1212d0829c3';
 #$key = '76a553babab7a62b7935d9a10f73777bf57b043c9d0f1fc22ea51dd9484154bc91afafd0f92e773e590ad05ebca9aec3fac11ebada7e517c78d32790e5a8f3ed';
 $enc = nb::encrypt($key,$value);
index 0f4d8d26f9c15d338e00a9a77750fb8b7b49434f..ccfc2584925a9b580c3f7d819f28ec0bdddda1d1 100644 (file)
@@ -10,6 +10,7 @@ function dbq_run() {
     'db' => 'ls',
     'table' => 'ls',
     'action' => 'ls',
+    'params' => '',
   ]);
   #var_export($params);
   $ext = $params['format'];
@@ -24,7 +25,7 @@ function dbq_run() {
   #Page::pdef('out',1);
   $Page = new Page([
     'css' => '/default.css',
-    'title' => join(' ',array_unique(array_slice(array_values($params),1))),
+    'title' => join(' ',array_filter(array_unique(array_slice(array_values($params),1)),function($v){if ($v!=='ls') return $v;})),
   ]);
   $params['ext'] = $ext;
 
@@ -74,7 +75,6 @@ function dbq_run() {
   #
   # Db actions
   if ($params['table'] == 'help') {
-    #$this->out->rows($format,$rows,$head);
     $Db->out([
       [ 'help', 'This help' ],
       [ 'ls', 'List tables' ],
@@ -85,15 +85,6 @@ function dbq_run() {
     return $Page->end();
 
   } elseif ($params['table'] == 'ls') {
-    /*
-    bye('zaza');
-    $Table->row_parse_post = function(&$row) use($Page) {
-      debug($row);
-      $row['name'] = '';
-        #$Page->tag('a',$row['name']);
-    };
-    */
-    #$Db->action('db.tables');
     $Db->out($Db->tables_rows(),[],['row_parse_post'=>function(&$r) use ($Page,$params) {
       $r['name'] = $Page->tag('a',$r['name'],'href="'.$params['db'].'/'.$r['name'].'.'.$params['ext'].'"');
     }]);
@@ -124,7 +115,7 @@ function dbq_run() {
       [ 'fields', 'List fields' ],
     ],['command','description'],
     ['row_parse_post'=>function(&$r) use ($Page,$params) {
-      $r['command'] = $Page->tag('a',$r['command'],'href="'.$r['command'].'.'.$params['ext'].'"');
+      $r['command'] = $Page->tag('a',$r['command'],'href="'.($r['command']=='ls'?'../'.$params['table']:$r['command']).'.'.$params['ext'].'"');
     }]);
     return $Page->end();