From 62a27241f8404dbb51e137f9d9cc612c2ba72717 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 19 Dec 2017 00:46:01 +0000 Subject: [PATCH] etc/profile.d/sys.sh --- etc/profile.d/sys.sh | 4 +++- lib/php/db.php | 3 +++ lib/php/nb.php | 15 +++++++++++++-- lib/php/page.php | 8 ++++---- share/sql/host.sql | 7 +++++++ share/sql/host_info.sql | 2 +- www/dbq/dbq.php | 15 ++++++++------- 7 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 share/sql/host.sql diff --git a/etc/profile.d/sys.sh b/etc/profile.d/sys.sh index 99329434..b253cbc8 100644 --- a/etc/profile.d/sys.sh +++ b/etc/profile.d/sys.sh @@ -5,10 +5,12 @@ sys_infos() { local s="$(printf '\t')" - cat </dev/null ) nproc${s}$( (nproc || sysctl -n hw.ncpu || grep ^proc /proc/cpuinfo | wc -l) 2>/dev/null ) date_install${s}$( (date -r $(ls -1drt /lost+found /etc/ssh/ssh_host_dsa_key.pub /etc/ssh_host_dsa_key.pub|head -1) +'%F %T') 2>/dev/null ) +myip${s}$(curl -s http://nbdom.net/myip 2>/dev/null) +ips${s}$(echo -n $(ips 2>/dev/null)) EOF } diff --git a/lib/php/db.php b/lib/php/db.php index c3e23b04..fd4fa4bb 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -538,6 +538,9 @@ class Db extends nb { public function out($rows,$head=[],$conf=[]) { +# NB 19.12.17 See www/dbq/dbq.php: $this->db->out($rows,$head,$conf); + if (empty($rows)) return false; + if ($this->format) { $format = $this->format; diff --git a/lib/php/nb.php b/lib/php/nb.php index a2f95bcd..f97793cf 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -1094,11 +1094,22 @@ class NB { if (!isset($o['dn'])) $o['dn'] = true; #return [$o]; - $connect = ldap_connect($o['host']) or exit(">>Could not connect to LDAP server<<"); + if (!isset($o['exit_on_err'])) $o['exit_on_err'] = true; + #try { $connect = ldap_connect($o['host']); } catch (Exception $e) {}; if (!$connect) { + if (!$connect = @ldap_connect($o['host'])) { + if (empty($o['exit_on_err'])) return []; + self::bye("Could not connect to LDAP server"); + } + ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($connect, LDAP_OPT_REFERRALS, 0); - $bind = ldap_bind($connect, $o['bind_dn'], $o['password']) or self::bye(">>Could not bind to ".$o['ldap_host']."<<"); + #try { $bind = ldap_bind($connect, $o['bind_dn'], $o['password']); } catch (Exception $e) {}; + if (!$bind = @ldap_bind($connect, $o['bind_dn'], $o['password'])) { + if (empty($o['exit_on_err'])) return []; + self::bye("Could not bind to LDAP server"); + } + if (empty($o['filter'])) { $o['filter'] = "(&(userpassword=*))"; $o['base_dn'] = $o['bind_dn']; diff --git a/lib/php/page.php b/lib/php/page.php index c9a2e160..07754a0c 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -5,7 +5,7 @@ require_once(NB_ROOT.'/lib/php/out.php'); if ( !@$_SERVER['DOCUMENT_ROOT'] and (realpath($argv[0]) == __FILE__) ) { -$Page = new Page(array( +$Page = new Page([ #'title' => 'Test', 'call' => array( 'begin', @@ -13,7 +13,7 @@ $Page = new Page(array( #array('out', print_r($_SERVER,true)), 'end', ), -)); +]); } */ @@ -568,9 +568,9 @@ class Page extends nb { } public function status() { - $out = array( + $out = [ 'path' => self::path() - ); + ]; foreach (get_class_vars(get_class($this)) as $k=>$v) { if (!empty($this->$k)) $out[$k] = is_scalar($this->$k) ? $this->$k : out::scalar($this->$k); } diff --git a/share/sql/host.sql b/share/sql/host.sql new file mode 100644 index 00000000..f1e3bd1a --- /dev/null +++ b/share/sql/host.sql @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS host; +CREATE VIEW host AS + SELECT host,LEFT(CAST(MAX(updated) AS TEXT),19) as updated + FROM host_info + GROUP BY host +; +GRANT ALL ON hostGRANT ALL ON ALL TABLES IN SCHEMA public TO TO nico,www; diff --git a/share/sql/host_info.sql b/share/sql/host_info.sql index 318e43a1..18b4ab59 100644 --- a/share/sql/host_info.sql +++ b/share/sql/host_info.sql @@ -11,4 +11,4 @@ CREATE INDEX IF NOT EXISTS host_info_host ON host_info USING btree (host); CREATE INDEX IF NOT EXISTS host_info_key ON host_info USING btree (key); CREATE INDEX IF NOT EXISTS host_info_val ON host_info USING btree (val); CREATE INDEX IF NOT EXISTS host_info_updated ON host_info USING btree (updated); -GRANT ALL ON host_info TO www; +GRANT ALL ON host_info TO nico,www; diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 5c7a2d6f..65f91285 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -6,19 +6,17 @@ require_once(NB_ROOT.'/lib/php/config.php'); require_once(NB_ROOT.'/lib/php/http.php'); require_once(NB_ROOT.'/lib/php/mime.php'); -function dbqErrHandle($errNo, $errStr, $errFile, $errLine) { +if (false) set_error_handler( function ($errNo, $errStr, $errFile, $errLine) { $msg = "$errStr in $errFile on line $errLine\n"; if ($errNo == E_NOTICE || $errNo == E_WARNING) { header("HTTP/1.0 500 Internal Server Error"); -# NB 13.12.17 Revel args from function which could be passwords !!! -# NB 13.12.17 throw new ErrorException($msg, $errNo); + #Revel args from function which could be passwords !!! + #throw new ErrorException($msg, $errNo); nb::bye("$errNo: $msg"); } else { echo $msg; } -} - -set_error_handler('dbqErrHandle'); +}); class DbQ extends nb { @@ -176,6 +174,7 @@ class DbQ extends nb { 'bind_dn_preff' => (!empty($_SERVER['DBQ_LDAP_BIND_DN_PREFF']) ? 'ou='.$_SERVER['DBQ_LDAP_BIND_DN_PREFF'] : 'ou=auth'), 'filter' => $filter, 'attrs' => $attrs, + 'exit_on_err' => $this->p('err',true), ]); #echo $rows[0]['jpegPhoto']; exit; @@ -222,7 +221,6 @@ class DbQ extends nb { ]; $this->page->js_code = 'window._dbq = '.json_encode($this->conf); -# NB 22.05.17 if (is_scalar($obj) and $obj != 'logout') { if ($obj != 'logout') { list($title,$nav) = $this->title_nav(); $this->page->title = join($this->sep_title,$title); @@ -262,6 +260,7 @@ class DbQ extends nb { } # NB 18.12.17 if (!empty($rows)) +#if (empty($rows)) bye($rows); $this->db->out($rows,$head,$conf); if (empty($this->_nopage)) { @@ -281,8 +280,10 @@ class DbQ extends nb { .$this->http_user() .' (can: '.$this->perm2h().')'.''; + if ($this->perm >= self::READ) { #echo ''; #$bottom[] = ''; + } if ($bottom and $this->page->is('html')) echo $this->page->tag('div class="block" style="display:inline-block"',join('
'.NB_EOL,$bottom)); -- 2.47.3