From b893ab2332104dd5e85f33b151c57f14f2d919d4 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 4 Dec 2016 21:32:47 +0000 Subject: [PATCH] fix content type bug --- etc/dbq/crypt.yaml | 1 + etc/dbq/zzz-all.php | 1 - lib/php/config.php | 4 +++- lib/php/db.php | 17 +++++++++++++---- lib/php/nb.php | 2 +- lib/php/page.php | 4 +++- www/dbq/html/index.php | 27 ++++++++++++++++++++++++--- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/etc/dbq/crypt.yaml b/etc/dbq/crypt.yaml index ba97cdee..ab86bdc6 100644 --- a/etc/dbq/crypt.yaml +++ b/etc/dbq/crypt.yaml @@ -1,3 +1,4 @@ crypt: type: sqlite host: /dev/shm/crypt.db + default_table: credential diff --git a/etc/dbq/zzz-all.php b/etc/dbq/zzz-all.php index 37f1a702..fb25631c 100644 --- a/etc/dbq/zzz-all.php +++ b/etc/dbq/zzz-all.php @@ -79,4 +79,3 @@ foreach ($DBQ as $id => $db) { $DBQ['all']['_import'][] = $id; } -if (nb::p('db')!='nb') $DBQ['all']['_import'][] = 'nb'; diff --git a/lib/php/config.php b/lib/php/config.php index 570d834b..0a33302a 100644 --- a/lib/php/config.php +++ b/lib/php/config.php @@ -9,6 +9,7 @@ #define('NB_PROD',true); if (empty($_SERVER['PROD'])) error_reporting(E_ALL | E_STRICT | E_NOTICE); +// Base lib require(dirname(__FILE__).'/nb.php'); // Cli @@ -18,13 +19,14 @@ if (nb::php_cli()) { ini_set('log_errors', false); if (nb::p('txt_errors')) ini_set('html_errors', false); } + // Web else { ini_set('display_errors',empty($_SERVER['PROD'])); ini_set('html_errors',empty($_SERVER['PROD'])); } -// Should be done in php.ini for performance +// Should be done in php.ini for performance ? if (!ini_get('UTC')) date_default_timezone_set('UTC'); ini_set('include_path','' diff --git a/lib/php/db.php b/lib/php/db.php index ce8ea218..97f0a713 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -814,10 +814,18 @@ class Db extends nb { if (isset($Table)) self::bye("Table.init(): GLOBALS['Table'] already exists !"); if (isset($Db)) self::bye("Db.init(): GLOBALS['Db'] already exists !"); + # + # Db + # $Db = new self(); - $Db->pinit(); if (empty($Db)) return false; + # + # Params + $Db->pinit(); + + # + # Load conf $db = $Db->conf_search_db($conf); if ($Db->p('localFile')) { foreach ($Db->localFile($db['name']) as $k=>$v) { @@ -825,13 +833,14 @@ class Db extends nb { } } + # # Connection $Db->__construct($db); $Db->connect(); - /* - Table - */ + # + # Table + # if (self::p('action') and !self::p('table') and !preg_match('/^(table\.\w+|rows|insert|edit|delete|update)$/',self::p('action')) diff --git a/lib/php/nb.php b/lib/php/nb.php index ec349bf8..e9a06cd3 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -95,7 +95,7 @@ class NB { * Return the value set or existing */ public static function pdef($name,$value) { - if (preg_match('/^\s*$/',self::p($name))) return self::pset($name,is_callable($value) ? $value() : $value); + if (preg_match('/^\s*$/',self::p($name))) return self::pset($name,(!is_scalar($value) and is_callable($value)) ? $value() : $value); return self::p($name); } diff --git a/lib/php/page.php b/lib/php/page.php index 884da78a..2d3f32cd 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -328,6 +328,7 @@ class Page extends nb { } public static function headers_no_cache() { + if (self::php_cli()) return false; $ts = gmdate("D, d M Y H:i:s") . " GMT"; header("Expires: $ts"); header("Last-Modified: $ts"); @@ -336,6 +337,7 @@ class Page extends nb { } public static function headers_cache($seconds_to_cache=3600) { + if (self::php_cli()) return false; if ($seconds_to_cache === 0) return headers_no_cache(); $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT"; header("Expires: $ts"); @@ -344,9 +346,9 @@ class Page extends nb { } public function headers() { + if (self::php_cli()) return false; #header('Content-type: ' . self::$content_type); - self::$content_type = 'text/plain'; header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : "")); if (isset($this->expires)) self::headers_cache($this->expires); diff --git a/www/dbq/html/index.php b/www/dbq/html/index.php index f907dd8c..8ac3a3d2 100644 --- a/www/dbq/html/index.php +++ b/www/dbq/html/index.php @@ -1,9 +1,30 @@ '', + 'table' => '', + 'action' => '', + 'format' => '', + ]; + + $i=0; + $count = count($values); + foreach ($P as $p => $default) { + if ($i>=$count) break; + $P[$p] = $values[$i]; + $i++; + } + +} +#var_dump(parse_uri()); $params = [ - #'db', + 'db', 'table', 'action', 'format', @@ -26,10 +47,10 @@ foreach ($values as $k=>$v) { } Page::pdef('format','human'); -#Page::pdef('action','db.ls'); +Page::pdef('action','db.ls'); require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/db/init.php'); -header('Content-type: text/plain'); +#header('Content-type: text/plain'); $Page = $Db->page(); $Page->headers_no_cache(); $Page->call([ -- 2.47.3