}
if (!empty($key)) $cipher->setIV($key);
return $cipher;
- return self::_encrypt_decrypt_object($key)->decrypt($value);
+# NB 31.01.19 return self::_encrypt_decrypt_object($key)->decrypt($value);
}
- public static function cryptkey($length=32) {
+ public static function random_str($length=32) {
if (!OLD_CRYPT) {
- self::_encrypt_decrypt_object();
+ self::_encrypt_decrypt_object(null);
return substr(bin2hex(crypt_random_string(($length/2)+1)),0,$length);
}
return bin2hex(mcrypt_create_iv($length/2, MCRYPT_DEV_URANDOM));
const PARAM_DB_DEFAULT = 'ls';
const READ = 9;
-
const ADD = 13;
const UPDATE = 15;
const WRITE = 19;
-
const DELETE = 29;
-
const ADMIN = 99;
+
public $perm = self::ADMIN;
public $perms = [ # keys in lowercase !!!!
'read' => self::READ,
foreach (['table','action','args'] as $k) { if (!empty($this->params[$k])) $arg[] = $this->params[$k]; }
$arg = join('/',$arg);
+ ## NB 30.01.19: >>>>>
+ ## NB 30.01.19: Test with config
+ $conf_run = function($conf,$action) use ($arg) {
+ foreach ($conf as $cmd) {
+ $action_ = $cmd[0];
+ $laius = $cmd[1];
+ $fct = $cmd[2];
+ $perm = empty($cmd[3]) ? 0 : $cmd[3];
+
+ if ($action != $action_) continue;
+ $this->deniedUnless(!$perm or $this->perm >= $perm);
+ #debug($action_);
+ echo "Hi\n";
+ $fct();
+ }
+ };
+ $conf = [
+ 'root' => [
+ [ 'help', 'This help', function() { $this->page($this->db,$conf['root']); } ],
+ [ 'ls', 'List configured databases', function() {
+ $this->page($this->db,'ls',[],function(&$r){
+ if ($this->perm < self::ADMIN) unset($r['host'],$r['type']);
+ $r['id'] = $this->page->tag('a',$r['id'],'href="'.$this->db->base.'/'.$r['id'].'"');
+ });
+ } ],
+ [ 'random_str', 'Generate a random string', function() { $this->page($this->random_str()); } ],
+# NB 30.01.19 [ 'databases', 'List others databases', function() {
+# NB 30.01.19 $this->page($this->db,'databases');
+# NB 30.01.19 }, self::ADMIN ],
+ ],
+ ];
+ $conf_run($conf['root'],$action);
+ ## NB 30.01.19: <<<<<
+
if ($action == 'help') {
+
$this->page($this->db,[
[ 'help', 'This help' ],
[ 'ls', 'List configured databases' ],
[ 'databases', 'List others databases' ],
- [ 'cryptkey', 'Generate a random encryption key' ],
+ [ 'random_str', 'Generate a random string' ],
[ 'ssha_password', 'Encrypt a password' ],
[ 'ssha512_password', 'Encrypt a password' ],
[ 'logout', 'Clear Basic Auth' ],
} elseif ($action == 'logout') { $this->page($this,'logout');
} elseif ($action == 'ssha_password') { $this->page($this,'ssha_password');
} elseif ($action == 'ssha512_password') { $this->page($this,'ssha512_password');
-# NB 03.02.18 } elseif ($action == 'cryptkey') { $this->page($this,'cryptkey',['key']);
- } elseif ($action == 'cryptkey') { $this->page($this->cryptkey());
+ } elseif ($action == 'random_str') { $this->page($this->random_str());
} elseif ($action == 'status') { $this->page($this,'status');
} elseif ($action == 'conf') { $this->page($this,'conf');
} elseif ($action == 'html') { $this->page(Mime::html($arg));