]> git.nbdom.net Git - nb.git/commitdiff
lib/php/nb.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 17 Jan 2018 01:29:14 +0000 (01:29 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 17 Jan 2018 01:29:14 +0000 (01:29 +0000)
lib/php/db/table.php
lib/php/http.php
lib/php/nb.php
lib/php/out/php_hash.php
lib/php/out/sh.php
www/dbq/dbq.php

index bf66e64dff05636f9abdbac9c89c733de358b12c..0866b7dbf630b5706d0d5573cb83565a4cd336bb 100644 (file)
@@ -145,7 +145,7 @@ Class Table extends nb {
     foreach ($this->rows as $row) {
 
       foreach ($row as $k=>$v) {
-        $field = $this->fields($k);
+        $field = $this->field($k);
         $field->bindParam($query,$v,":$k");
       }
 
@@ -661,7 +661,7 @@ Class Table extends nb {
 
   public function url_sort($name) {
 
-    if (!$this->show_url_sort or !($f=$this->fields($name)) or !empty($f->dyn) or $f->is_encrypt()) return self::prettyText($name);
+    if (!$this->show_url_sort or !($f=$this->field($name)) or !empty($f->dyn) or $f->is_encrypt()) return self::prettyText($name);
     #debug($f);
 
     # See: http://dev.w3.org/html5/html-author/charref
@@ -1213,6 +1213,7 @@ Class Table extends nb {
       $count_fields = 0;
 
       foreach ($fields as $f => $field) {
+                               if (!$this->field($f)) continue;
         $row[$f] = $field->out(isset($row[$f]) ? $row[$f] : '');
         $count_fields++;
       }
@@ -1395,7 +1396,7 @@ Class Table extends nb {
 
        foreach ($row as $k=>$v) {
        if (isset($this->extras[$k])) continue;
-       $f = $this->fields($k);
+       $f = $this->field($k);
 
        $values[] = $f->quote($v);
        $keys[] = $f->sql_name();
@@ -2216,11 +2217,6 @@ Class Table extends nb {
 
   public function unserialize() {
     $o = unserialize($this->serialize());
-    #return $this->out($this->fields('id'));
-    #return serialize($this->fields());
-    #$this = $o;
-    #return($o->sql_name());
-    #debug($o->sql_name());
     return var_export($o,true);
   }
 
index 9b5d5cdf56e583225b4c770a2a45d2e344e82b4f..e1f85b1d2c0b40ad3a092d4645d5fbc6d40d08a7 100644 (file)
@@ -1,91 +1,91 @@
 <?php
 class Http {
   const Status = [
-#>SHELL_REPLACE dbq db=$NB_DB t=http_status -cut 1,2 | perl -pe "s/'/\\\\'/; s/^(.*?)\t(.*?)$/    '\$1' => '\$2',/"
-    '100' => 'Continue',
-    '101' => 'Switching Protocols',
-    '102' => 'Processing',
-    '200' => 'OK',
-    '201' => 'Created',
-    '202' => 'Accepted',
-    '203' => 'Non-Authoritative Information',
-    '204' => 'No Content',
-    '205' => 'Reset Content',
-    '206' => 'Partial Content',
-    '207' => 'Multi-Status',
-    '208' => 'Already Reported',
-    '226' => 'IM Used',
-    '300' => 'Multiple Choices',
-    '301' => 'Moved Permanently',
-    '302' => 'Found',
-    '303' => 'See Other',
-    '304' => 'Not Modified',
-    '305' => 'Use Proxy',
-    '306' => 'Switch Proxy',
-    '307' => 'Temporary Redirect',
-    '308' => 'Permanent Redirect',
-    '400' => 'Bad Request',
-    '401' => 'Unauthorized',
-    '402' => 'Payment Required',
-    '403' => 'Forbidden',
-    '404' => 'Not Found',
-    '405' => 'Method Not Allowed',
-    '406' => 'Not Acceptable',
-    '407' => 'Proxy Authentication Required',
-    '408' => 'Request Time-out',
-    '409' => 'Conflict',
-    '410' => 'Gone',
-    '411' => 'Length Required',
-    '412' => 'Precondition Failed',
-    '413' => 'Payload Too Large',
-    '414' => 'URI Too Long',
-    '415' => 'Unsupported Media Type',
-    '416' => 'Range Not Satisfiable',
-    '417' => 'Expectation Failed',
-    '418' => 'I\'m a teapot',
-    '421' => 'Misdirected Request',
-    '422' => 'Unprocessable Entity',
-    '423' => 'Locked',
-    '424' => 'Failed Dependency',
-    '426' => 'Upgrade Required',
-    '428' => 'Precondition Required',
-    '429' => 'Too Many Requests',
-    '431' => 'Request Header Fields Too Large',
-    '451' => 'Unavailable For Legal Reasons',
-    '500' => 'Internal Server Error',
-    '501' => 'Not Implemented',
-    '502' => 'Bad Gateway',
-    '503' => 'Service Unavailable',
-    '504' => 'Gateway Time-out',
-    '505' => 'HTTP Version Not Supported',
-    '506' => 'Variant Also Negotiates',
-    '507' => 'Insufficient Storage',
-    '508' => 'Loop Detected',
-    '510' => 'Not Extended',
-    '511' => 'Network Authentication Required',
-    '420' => 'Method Failure',
-    '450' => 'Blocked by Windows Parental Controls',
-    '498' => 'Invalid Token',
-    '509' => 'Bandwidth Limit Exceeded',
-    '530' => 'Site is frozen',
-    '599' => 'Network connect timeout error',
-    '440' => 'Login Time-out',
-    '449' => 'Retry With',
-    '444' => 'No Response',
-    '495' => 'SSL Certificate Error',
-    '496' => 'SSL Certificate Required',
-    '497' => 'HTTP Request Sent to HTTPS Port',
-    '499' => 'Client Closed Request',
-    '520' => 'Unknown Error',
-    '521' => 'Web Server Is Down',
-    '522' => 'Connection Timed Out',
-    '523' => 'Origin Is Unreachable',
-    '524' => 'A Timeout Occurred',
-    '525' => 'SSL Handshake Failed',
-    '526' => 'Invalid SSL Certificate',
-    '527' => 'Railgun Error',
-    '103' => 'Checkpoint',
-    '419' => 'I',
+#>SHELL_REPLACE dbq db=$NB_DB t=http_status rows.fields=id,name orderby=id f=php_hash | sed "s/^/\t/"
+       "100" => "Continue",
+       "101" => "Switching Protocols",
+       "102" => "Processing",
+       "103" => "Checkpoint",
+       "200" => "OK",
+       "201" => "Created",
+       "202" => "Accepted",
+       "203" => "Non-Authoritative Information",
+       "204" => "No Content",
+       "205" => "Reset Content",
+       "206" => "Partial Content",
+       "207" => "Multi-Status",
+       "208" => "Already Reported",
+       "226" => "IM Used",
+       "300" => "Multiple Choices",
+       "301" => "Moved Permanently",
+       "302" => "Found",
+       "303" => "See Other",
+       "304" => "Not Modified",
+       "305" => "Use Proxy",
+       "306" => "Switch Proxy",
+       "307" => "Temporary Redirect",
+       "308" => "Permanent Redirect",
+       "400" => "Bad Request",
+       "401" => "Unauthorized",
+       "402" => "Payment Required",
+       "403" => "Forbidden",
+       "404" => "Not Found",
+       "405" => "Method Not Allowed",
+       "406" => "Not Acceptable",
+       "407" => "Proxy Authentication Required",
+       "408" => "Request Time-out",
+       "409" => "Conflict",
+       "410" => "Gone",
+       "411" => "Length Required",
+       "412" => "Precondition Failed",
+       "413" => "Payload Too Large",
+       "414" => "URI Too Long",
+       "415" => "Unsupported Media Type",
+       "416" => "Range Not Satisfiable",
+       "417" => "Expectation Failed",
+       "418" => "I'm a teapot",
+       "419" => "I",
+       "420" => "Method Failure",
+       "421" => "Misdirected Request",
+       "422" => "Unprocessable Entity",
+       "423" => "Locked",
+       "424" => "Failed Dependency",
+       "426" => "Upgrade Required",
+       "428" => "Precondition Required",
+       "429" => "Too Many Requests",
+       "431" => "Request Header Fields Too Large",
+       "440" => "Login Time-out",
+       "444" => "No Response",
+       "449" => "Retry With",
+       "450" => "Blocked by Windows Parental Controls",
+       "451" => "Unavailable For Legal Reasons",
+       "495" => "SSL Certificate Error",
+       "496" => "SSL Certificate Required",
+       "497" => "HTTP Request Sent to HTTPS Port",
+       "498" => "Invalid Token",
+       "499" => "Client Closed Request",
+       "500" => "Internal Server Error",
+       "501" => "Not Implemented",
+       "502" => "Bad Gateway",
+       "503" => "Service Unavailable",
+       "504" => "Gateway Time-out",
+       "505" => "HTTP Version Not Supported",
+       "506" => "Variant Also Negotiates",
+       "507" => "Insufficient Storage",
+       "508" => "Loop Detected",
+       "509" => "Bandwidth Limit Exceeded",
+       "510" => "Not Extended",
+       "511" => "Network Authentication Required",
+       "520" => "Unknown Error",
+       "521" => "Web Server Is Down",
+       "522" => "Connection Timed Out",
+       "523" => "Origin Is Unreachable",
+       "524" => "A Timeout Occurred",
+       "525" => "SSL Handshake Failed",
+       "526" => "Invalid SSL Certificate",
+       "527" => "Railgun Error",
+       "530" => "Site is frozen",
+       "599" => "Network connect timeout error",
 #<SHELL_REPLACE
   ];
 
@@ -102,6 +102,23 @@ class Http {
     if (!empty($body_msg)) echo "$body_msg\n";
     exit;
   }
+
+       public static function user() {
+               foreach ([
+                       'PHP_AUTH_USER',
+                       'REMOTE_USER',
+               ] as $k) {
+                       if (!empty($_SERVER[$k])) return $_SERVER[$k];
+               }
+       }
+
+       public static function password() {
+               foreach ([
+                       'PHP_AUTH_PW',
+               ] as $k) {
+                       if (!empty($_SERVER[$k])) return $_SERVER[$k];
+               }
+       }
 }
 
 #var_export(Http::msg(500));
index f6a5b23378c6c8c2c5257da7b05daf83eb89ce1b..8ee8880b59a09681ba6da9d87991e49ca384b6d2 100644 (file)
@@ -7,6 +7,7 @@ if (!defined('NB_EOL')) define('NB_EOL',(defined('NB_PROD') and NB_PROD) ? '' :
 if (!defined('NB_P_GET')) define('NB_P_GET',true);
 
 require_once(NB_ROOT.'/lib/php/functions.php');
+require_once(NB_ROOT.'/lib/php/http.php');
 
 if (class_exists('NB')) return; # protect against double include
 class NB {
@@ -1058,23 +1059,6 @@ class NB {
                return $code;
        }
 
-       public static function http_pass() {
-               foreach ([
-                       'PHP_AUTH_PW',
-               ] as $k) {
-                       if (!empty($_SERVER[$k])) return $_SERVER[$k];
-               }
-       }
-
-       public static function http_user() {
-               foreach ([
-                       'PHP_AUTH_USER',
-                       'REMOTE_USER',
-               ] as $k) {
-                       if (!empty($_SERVER[$k])) return $_SERVER[$k];
-               }
-       }
-
        private static function ar_filter_keys($ar,$keys) {
                $new = [];
                foreach ($keys as $k) {
@@ -1091,9 +1075,9 @@ class NB {
                if (!isset($o['host'])) $o['host'] = $host;
                if (!isset($o['base_dn'])) $o['base_dn'] = 'dc=' . str_replace('.',',dc=',preg_replace('/^ldap[^.]*./','',$host));
 
-               if (!isset($o['user'])) $o['user'] = self::http_user();
+               if (!isset($o['user'])) $o['user'] = Http::http_user();
 
-               if (!isset($o['password'])) $o['password'] = self::http_pass();
+               if (!isset($o['password'])) $o['password'] = Http::http_pass();
 
                $o['bind_dn_preff'] = isset($o['bind_dn_preff']) ? ','.$o['bind_dn_preff'].',' : '';
 
index c0962e829bf05820d01911702228559219211c8d..f56823c479c8d8b541cf40bc446445e9a56f9f48 100644 (file)
@@ -1,3 +1,16 @@
 <?php
-return [ 'align' => self::p('sep',' => '), 'eol' => ",\n", 'quote' => "'", ];
+return [
+'align' => self::p('sep',' => '),
+'eol' => ",\n",
+'quote' => "'",
+'preff' => self::p('preff',''),
+'row' => function (&$o,&$r) {
+       if ($o['preff']) echo $o['preff'];
+       $keys = array_keys($r);
+       for ($i=2;$i<count($keys);$i++) {
+               $k = $keys[$i];
+               unset($r[$k]);
+       }
+},
+];
 ?>
index 11f18afa8f2c711613845ed743dba1743ad0fb3b..ff3914448da3286ff96a70879a24993a273589d7 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 if (!class_exists('out')) return;
 return [
-  'preff' => self::p('preff',""),
+  'preff' => self::p('preff',''),
   'kuc' => (int)self::p('kuc',false),
   'nl' => (int)self::p('nl',false),
   'rec' => self::p('rec',';'),
index e19e8ecd5ece20e5eb073863b909ed3c53c89b40..f70750e72053006a9e70130dde4030150b1274e8 100644 (file)
@@ -5,6 +5,7 @@ require_once(realpath(dirname(__FILE__).'/../../lib/php/nb.php'));
 require_once(NB_ROOT.'/lib/php/config.php');
 require_once(NB_ROOT.'/lib/php/http.php');
 require_once(NB_ROOT.'/lib/php/mime.php');
+require_once(NB_ROOT.'/lib/php/page.php');
 
 # NB 03.01.18 if (false) set_error_handler( function ($errNo, $errStr, $errFile, $errLine) {
 # NB 03.01.18          $msg = "$errStr in $errFile on line $errLine\n";
@@ -135,16 +136,16 @@ class DbQ extends nb {
 
                parent::__construct($opt);
 
-               //
                // Page
-               require_once(NB_ROOT.'/lib/php/page.php');
-
                $this->page = new Page([
                        'css' => $this->css,
                        'sep' => $this->sep_title,
 # NB 05.01.18                  'expires' => $this->expires,
                ]);
 
+               // Http
+               $this->http = new Http();
+
                if ($run) $this->run();
        }
 
@@ -285,11 +286,11 @@ class DbQ extends nb {
 
                        $bottom = [];
 
-                       if ($this->http_user()) {
+                       if ($this->http->user()) {
                                $bottom[] = '<a href="/logout"'
-                                       .($this->http_user() ? ' style="background:url(\'/ldap/jpegPhoto.jpg?w=20\') right no-repeat;padding-right:22px"' : '')
+                                       .($this->http->user() ? ' style="background:url(\'/ldap/jpegPhoto.jpg?w=20\') right no-repeat;padding-right:22px"' : '')
                                        .'>Logout: '
-                                       .$this->http_user()
+                                       .$this->http->user()
                                        .' (can: '.$this->perm2h().')'
                                        #.'<img src="/ldap/jpegPhoto.jpg?w=20" />'
                                .'</a>';
@@ -854,7 +855,7 @@ EOF;
                ];
 
                $user = '';
-               if (true or $user = $this->http_user()) {
+               if (true or $user = $this->http->user()) {
                        if ($user) $rows[] = [ 'name' => 'dbq.user.name', 'value' => $user ];
                        $rows[] = [ 'name' => 'dbq.user.perm', 'value' => $this->perm2h() ];
                }