--- /dev/null
+<?php
+/*
+*/
+$CONF = array (
+ 'rent' => array (
+ 'order' => 1,
+ 'pdo' => 'sqlite:/opt/rent/rent.db',
+ 'title' => 'Rent',
+ 'notice' => 'Micro foncier 4BE',
+ 'default_table' => 'rent',
+ 'tables' => array (
+ 'place' => array (
+ 'replace' => array (
+ 'id' => 'addr.addr',
+ ),
+ ),
+ 'rent' => array (
+ 'order_by' => 'start desc',
+ 'replace' => array (
+ 'idtenant' => 'tenant.name',
+ 'idplace' => 'addr.addr',
+ ),
+ 'extras' => array (
+ 'total' => array (
+ 'type' => 'float(8,2)',
+ 'extra' => 'ROUND(rent+charge,2)',
+ ),
+ 'rent_year' => array (
+ 'type' => 'float(8,2)',
+ 'extra' => 'rent * (1 + ( strftime(\'%m\',end)+12*strftime(\'%Y\',end) ) - ( strftime(\'%m\',start)+12*strftime(\'%Y\',start) ))',
+ ),
+ ),
+ ),
+ ),
+ 'name' => 'rent',
+ ),
+ 'ui-mem' => array (
+ 'pdo' => 'sqlite:/dev/shm/semantico.db',
+ 'title' => 'Semantico UI',
+ 'default_table' => 'node',
+ 'tables' => array (
+ 'node' => array (
+ 'order_by' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
+ 'replace_' => array (
+ 'iddc' => 'dc.id',
+ ),
+ ),
+ ),
+ 'replace' => array (
+ 'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
+ ),
+ 'name' => 'ui-mem',
+ ),
+ 'rt' => array (
+ 'pdo' => 'pgsql:host=db.rt.semantico.net;port=5432;dbname=rtdb;user=rtuser;password=',
+ 'title' => 'RT',
+ 'password' => 'scrubchug',
+ 'name' => 'rt',
+ ),
+ 'ui' => array (
+ 'pdo' => 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db',
+ 'title' => 'Semantico UI',
+ 'default_table' => 'node',
+ 'tables' => array (
+ 'node' => array (
+ 'order_by' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
+ 'replace_' => array (
+ 'iddc' => 'dc.id',
+ ),
+ ),
+ ),
+ 'replace' => array (
+ 'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
+ ),
+ 'name' => 'ui',
+ ),
+ 'postfix' => array (
+ 'title' => 'Postfix on Izideal',
+ 'host' => 'media.izideal.vpn',
+ 'user' => 'postfix',
+ 'password' => 'dx7d50nfs',
+ 'type' => 'mysql',
+ 'name' => 'postfix',
+ ),
+ 'izidev' => array (
+ 'host' => 'big.cascais.loc',
+ 'title' => 'Mysql Izi on Big',
+ 'password' => 'mpc60ax73',
+ 'default_table' => 'process',
+ 'user' => 'nico',
+ 'name' => 'izi',
+ 'tables' => array (
+ 'site' => array (
+ 'replace' => array (
+ 'idlang' => 'lang.id',
+ ),
+ ),
+ ),
+ 'type' => 'mysql',
+ ),
+ 'wp' => array (
+ 'host' => 'admin.izideal.vpn',
+ 'user' => 'nico',
+ 'password' => 'mpc60ax73',
+ 'type' => 'mysql',
+ 'name' => 'wp',
+ ),
+ 'nb' => array (
+ 'host' => 'admin.izideal.vpn',
+ 'user' => 'nico',
+ 'password' => 'mpc60ax73',
+ 'type' => 'mysql',
+ 'name' => 'nb',
+ 'tables' => array(
+
+ ),
+ ),
+ 'puppetdb' => array (
+ 'title' => 'Puppetdb',
+ 'host' => 'big',
+ 'type' => 'pgsql',
+ 'user' => 'puppetdb',
+ 'default_table' => 'view_hosts',
+ 'tables' => array (
+ 'hosts' => array (
+ 'extras' => array (
+ 'last_compile' => array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.last_compile, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'last_freshcheck' => array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.last_freshcheck, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'updated_at' => array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.updated_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'created_at' => array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.created_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'test' => array (
+ 'type' => 'int',
+ 'extra' => 1,
+ ),
+ ),
+ ),
+ ),
+ 'password' => 'puppetdb6073/!',
+ 'name' => 'puppetdb',
+ ),
+ 'izi' => array (
+ 'title' => 'Mysql Izi on Admin',
+ 'default_table' => 'process',
+ 'host' => 'admin.izideal.vpn',
+ 'user' => 'izideal',
+ 'name' => 'izi',
+ 'tables' => array (
+ 'site' => array (
+ 'replace' => array (
+ 'idlang' => 'lang.id',
+ ),
+ ),
+ ),
+ 'password' => 'dx7d50nfs',
+ 'type' => 'mysql',
+ ),
+ 'crypt' => array (
+ 'pdo' => 'sqlite:/dev/shm/crypt.db',
+ 'name' => 'crypt',
+ ),
+);
+?>
# NB 28.03.16 public $table;
# Web
- public $dbs; // others databases keys
public $default_table;
public $sort;
public $extras;
$return = true;
} elseif ($action == 'db.tables' or $action == 'tables') {
- foreach ($this->tables() as $t) {
- $rows[] = $t->infos();
- }
+ foreach ($this->tables() as $t) { $rows[] = $t->infos(); }
$return = $this->out2($rows);
} elseif ($action == 'db.dbs' or $action == 'dbs') {
- $return = $this->out2($this->dbs,"name");
+ if (self::p('hash')) $return = $this->out2($this->conf);
+ else $return = $this->out2($this->dbs,"name");
} elseif (preg_match('/^db\.(\w+)/',$action,$m)) {
if ($rows = $this->$m[1]()) $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
} elseif($table) {
if ($r=$table->action($action)) $return = $r;
- #if (!is_scalar($return)) $return = $this->out2($return);
}
}
if (is_scalar($files)) $files = array($files);
foreach ($files as $file) {
- if (is_readable($file) and ($yaml = yaml_parse_file($file))) {
- #foreach ($yaml as $k=>$v) { $yaml[$k]['_conf_dbs'] = $file; }
- #debug($file);
+ if (!is_readable($file)) continue;
+
+ if (preg_match('/\.(yaml|yml)$/i',$file) and ($yaml = yaml_parse_file($file))) {
$h = array_replace_recursive($h,$yaml);
+
+ } elseif (preg_match('/\.php$/i',$file)) {
+ #global $VAR1;
+ require($file);
+ if (!empty($CONF)) $h = $CONF;
+
}
- #debug($file);
- #if ( ($yaml = @yaml_parse_file($file)) ) $h = array_replace_recursive($h,$yaml)
- ;
- #}
+
+ #if ( ($yaml = @yaml_parse_file($file)) ) $h = array_replace_recursive($h,$yaml);
}
- unset($yaml);
+ unset($yaml,$CONF);
# Emulate hash pointer _import
foreach ($h as $db=>$o) {
# Connection
#bye($Db->p('db'));
if (!isset($dbs[$Db->p('db')])) $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
- $db = array_merge($dbs[$Db->p('db')],array('dbs'=>array_keys($dbs)));
+ $db = array_merge($dbs[$Db->p('db')],array(
+ 'dbs'=>array_keys($dbs),
+ 'conf'=>$dbs,
+ ));
$Db->__construct($db);
*/
require_once(dirname(__FILE__).'/../config.php');
require_once(dirname(__FILE__).'/../db.php');
+/*
+# TODO - NB 08.04.16
+$aliases = array(
+ 'd' => 'db',
+ 't' => 'table',
+ 'f' => 'format',
+ 'l' => 'limit',
+ 'a' => 'action',
+ 'h' => 'header',
+);
+*/
#bye(out::client_type());
Db::pdef('format',out::client_type());
Db::pset('db',$m[1]);
Db::pset('table',$m[2]);
}
+
+if(defined('DB_NO_INIT')) return true;
#bye(Db::conf_dbs(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )));
#$conf = Db::conf_dbs(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )); Db::init($conf);
-Db::init(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' ));
+Db::init(array( Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml' ));
-if( defined('DB_NO_ACTION')) return true;
+if(defined('DB_NO_ACTION')) return true;
return $Db->action($Table);
?>
public static $type;
public static function init() {
self::$types = array(
- 'sql' => array(
+ 'sql' => array(),
+
+ #'php' => array( 'function' => function(&$r) {var_dump($r);},),
+ 'php' => array(
+ #'enclose' => array('$VAR=array(',');'),
+ 'enclose' => array('$CONF = ',';'),
+ #'eol' => NB_EOL,
+ 'rec' => ',',
+ #'function' => function(&$r) { echo preg_replace('/[\r\n]/','',var_dump($r,true));},
+ #'function' => function(&$r) {print_r($r);}
+ #'function' => function(&$r) {var_dump($r);}
+ 'function' => function(&$r) { echo preg_replace('/(=>\s*)\n\s+/m','\1',var_export($r,true));}
+ #'function' => function(&$r) { echo preg_replace('/\n/','',var_export($r,true));}
+ #'function' => function(&$r) {var_export($r);}
),
+ #'var_dump' => array( 'function' => function(&$r) {var_dump($r);},),
+ #'print_r' => array( 'function' => function(&$r) {print_r($r);},),
+ #'var_export' => array( 'function' => function(&$r) {var_export($r);},),
'div' => array(
'is_html' => true,
# Defined function
if (isset($o['function'])) {
- if (preg_match('/^out_/',$o['function'])) {
+ if (is_scalar($o['function']) and preg_match('/^out_/',$o['function'])) {
$o['function']($row,$o);
} else {
echo $o['function']($row);