From: Nicolas Boisselier Date: Thu, 14 Dec 2017 20:44:49 +0000 (+0000) Subject: www/dbq/dbq.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=a26c839d4777085f0480b70068734b9ce50f4485;p=nb.git www/dbq/dbq.php --- diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 53b533da..154fd488 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -161,6 +161,38 @@ class DbQ extends nb { } + public function page_ldap() { + #debug($this->params); + $this->deniedUnless($this->perm >= self::READ); + $filter = ($this->params['table'] ? $this->params['table'] : ''); + $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []); + + if (!strpos($this->params['table'],'=')) { + $filter = ''; + $attrs = explode(',',$this->params['table']); + } + + $rows = $this->ldap_search([ + 'bind_dn_preff' => (!empty($_SERVER['DBQ_LDAP_BIND_DN_PREFF']) ? 'ou='.$_SERVER['DBQ_LDAP_BIND_DN_PREFF'] : 'ou=auth'), + 'filter' => $filter, + 'attrs' => $attrs, + ]); + + #echo $rows[0]['jpegPhoto']; exit; + #$rows = [ 'jpegPhoto' => $rows[0]['jpegPhoto'] ]; + if ($this->is_html + or ($this->params['format'] == $this->format_cli) + or ($this->params['format'] == 'csv') + ) $rows = $this->array_fill_assoc($rows); + $this->page($rows); + } + + public function page_ls($args) { + $this->deniedUnless($this->perm >= self::READ); + if (!strpos($args,'=')) $this->table->fields_only = explode(',',$args); + $this->page($this,'table_rows'); + } + public function page($obj,$meth=null,$head=[],$fct=null) { // Defaults @@ -680,14 +712,6 @@ EOF; return $this->perm; } -# NB 11.12.17 public function can($perm) { -# NB 11.12.17 if ($perm == 'read') return ($this->perm >= self::READ); -# NB 11.12.17 if ($perm == 'write') return ($this->perm >= self::WRITE); -# NB 11.12.17 if ($perm == 'delete') return ($this->perm >= self::DELETE); -# NB 11.12.17 if ($perm == 'admin') return ($this->perm >= self::ADMIN); -# NB 11.12.17 return null; -# NB 11.12.17 } - public function status() { #$this->perm--; $rows = []; @@ -756,8 +780,7 @@ EOF; } // Machine - if ($this->perm >= self::ADMIN) - if (function_exists('posix_uname')) { + if ($this->perm >= self::ADMIN and function_exists('posix_uname')) { foreach (posix_uname() as $k => $v) { if ($k == 'domainname' and $v == '(none)') continue; $rows[] = [ 'name' => 'posix.uname.'.$k, 'value' => $v ]; @@ -1011,26 +1034,12 @@ EOF; } $this->page($types); - // NOW ONLY FOR ADMIN ! - } elseif ($this->perm < self::ADMIN) { - } elseif ($action == 'ldap') { - #debug($this->params); - $rows = $this->ldap_search([ - 'bind_dn_preff' => (!empty($_SERVER['DBQ_LDAP_BIND_DN_PREFF']) ? 'ou='.$_SERVER['DBQ_LDAP_BIND_DN_PREFF'] : 'ou=auth'), - #'bind_dn' => 'ou=auth', - 'filter' => ($this->params['table'] ? $this->params['table'] : ''), - 'attrs' => ($this->params['action'] ? explode(',',$this->params['action']) : []), - ]); - #echo $rows[0]['jpegPhoto']; exit; - #$rows = [ 'jpegPhoto' => $rows[0]['jpegPhoto'] ]; - if ($this->is_html - or ($this->params['format'] == $this->format_cli) - or ($this->params['format'] == 'csv') - ) $rows = $this->array_fill_assoc($rows); - $this->page($rows); + $this->deniedUnless($this->perm >= self::ADMIN); + $this->page_ldap(); } elseif ($action == 'phpinfo') { + $this->deniedUnless($this->perm >= self::ADMIN); $this->rows_table($action,$this->phpinfo_rows()); #$this->page(['phpinfo'=>$this->page->phpinfo(true)]); #$this->page($this->page->phpinfo()); @@ -1041,6 +1050,7 @@ EOF; or $action == '_SERVER' or $action == '_REQUEST' ) { + $this->deniedUnless($this->perm >= self::ADMIN); $rows = []; foreach ($GLOBALS[$action] as $k=>$v) { if (preg_match('/^(' . $this->hide_keys_exp . ')/', $k)) $v = $this->hide_keys_value; @@ -1055,6 +1065,7 @@ EOF; } public function run_db() { + $this->deniedUnless($this->perm >= self::READ); $this->db(true); # Db Connections $action = $this->params['table']; if (!$action and self::PARAM_DB_DEFAULT) $action = self::PARAM_DB_DEFAULT; @@ -1131,10 +1142,7 @@ EOF; }); } elseif ($action == 'ls') { - $this->deniedUnless($this->perm >= self::READ); - $fields_only = []; - if (!strpos($this->params['args'],'=')) $this->table->fields_only = explode(',',$this->params['args']); - $this->page($this,'table_rows'); + $this->page_ls($this->params['args']); } elseif ($action == 'fields') { $this->page($this->table,'fields_rows'); @@ -1168,13 +1176,15 @@ EOF; $this->redirect_if_no_referer($this->table->base.'/'); $this->page($info); - } elseif ($action == 'rm' and $this->perm >= self::DELETE) { + } elseif ($action == 'rm') { + $this->deniedUnless($this->perm >= self::DELETE); if (!$this->table->delete($_POST,$info)) $this->error('rm: '.print_r($info,true)); $this->redirect_if_no_referer($this->table->base.'/'); $this->page($info); } else { + if (!strpos($action,'=')) $this->page_ls($action); $this->notImplemented('Unknown table action'." `$action`"); }