]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/sys.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 19 Dec 2017 00:46:01 +0000 (00:46 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 19 Dec 2017 00:46:01 +0000 (00:46 +0000)
etc/profile.d/sys.sh
lib/php/db.php
lib/php/nb.php
lib/php/page.php
share/sql/host.sql [new file with mode: 0644]
share/sql/host_info.sql
www/dbq/dbq.php

index 9932943427161e1e12b4bfbe52c6a1895fe71b29..b253cbc8e669e18eafeacac4cdc60d6121774eba 100644 (file)
@@ -5,10 +5,12 @@
 
 sys_infos() {
        local s="$(printf '\t')"
-       cat <<EOF
+       cat <<EOF | grep -vE "^[^${s}]+${s}$"
 arch${s}$( (arch || sysctl -n hw.machine) 2>/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
 }
 
index c3e23b04fca0a3ddca925465af42059e0483a1c8..fd4fa4bb101d4973a85d5b969c6df18ddbda5310 100644 (file)
@@ -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;
 
index a2f95bcde30db9c01c75f4e2d49f5b927b57a184..f97793cf4f0b106cd4252fe8738fbfb7205a2b79 100644 (file)
@@ -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'];
index c9a2e16093c005e903e630d85f8a4c812eb7d66f..07754a0c48664303c664e19547eb1ed9ce88ce95 100644 (file)
@@ -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 (file)
index 0000000..f1e3bd1
--- /dev/null
@@ -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;
index 318e43a175fd2891246e98610ef07467f3cf93a4..18b4ab592e846684bd31c6abc7fdc6d4fd75b3db 100644 (file)
@@ -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;
index 5c7a2d6f18f2ad1e788c07f5dd5782c89fd3133a..65f9128509510afc01c2433090efb9f3bb08874f 100644 (file)
@@ -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().')'.'</a>';
 
+                       if ($this->perm >= self::READ) {
                        #echo '<img src="/ldap/jpegPhoto.png?w=25" />';
                        #$bottom[] = '<object type="image/jpeg" data="/ldap/jpegPhoto.bin"></object>';
+                       }
 
                        if ($bottom and $this->page->is('html')) echo $this->page->tag('div class="block" style="display:inline-block"',join('<br />'.NB_EOL,$bottom));