<?php
require_once dirname(__FILE__).'/../lib/php/nb.php';
-$CONF = [];
+$DB_CONFS = [];
#$dev = (bool)(stripos(gethostname(),'macbook') !== false);
$LOCAL_DB = (
file_exists('/opt/local/var/run/mysql5')
# Create *-sqlite databases
#
$host_already_exists = [];
-foreach ($CONF as $id => $db) {
+foreach ($DB_CONFS as $id => $db) {
if (1
and !empty($db['type']) and $db['type'] == 'sqlite'
and !empty($db['host'])
foreach (nb::ls_dir($DIR_SQLITE,'\.db$') as $file) {
if (isset($host_already_exists["$DIR_SQLITE/$file"])) {
- $CONF[$host_already_exists["$DIR_SQLITE/$file"]]['sql_pre'][] = 'PRAGMA journal_mode=OFF';
+ $DB_CONFS[$host_already_exists["$DIR_SQLITE/$file"]]['sql_pre'][] = 'PRAGMA journal_mode=OFF';
continue;
}
$name = basename($file,'.db');
$id = "$name-sqlite";
- $CONF[$id] = [
+ $DB_CONFS[$id] = [
'host' => "$DIR_SQLITE/$file",
'type' => 'sqlite',
'title' => 'created by dbs.php',
'_import' => $name
];
- #if (!empty($CONF[$name])) $CONF[$id] = array_merge_recursive($CONF[$name],$CONF[$id]);
+ #if (!empty($DB_CONFS[$name])) $DB_CONFS[$id] = array_merge_recursive($DB_CONFS[$name],$DB_CONFS[$id]);
}
}
# Sqlite all Attach db type=sqlite
#
#return;
-$CONF['all'] = [
+$DB_CONFS['all'] = [
'host' => ':memory:',
'type' => 'sqlite',
'pdo' => '',
],
];
-foreach ($CONF as $id => $db) {
+foreach ($DB_CONFS as $id => $db) {
if (0
or empty($db['type'] )
or $db['type']!='sqlite'
or !is_readable($db['host'])
) continue;
$fname = basename($db['host'],'.db');
- $CONF['all']['types']['sql_pre'][] = "ATTACH DATABASE '".$db['host']."' as ".$fname."";
- conf_merge($CONF[$fname],$CONF['all']);
+ $DB_CONFS['all']['types']['sql_pre'][] = "ATTACH DATABASE '".$db['host']."' as ".$fname."";
+ conf_merge($DB_CONFS[$fname],$DB_CONFS['all']);
}
-conf_merge($CONF['nb'],$CONF['all']);
+conf_merge($DB_CONFS['nb'],$DB_CONFS['all']);
return 1;
<?php
-$CONF['nb'] = array(
+$DB_CONFS['nb'] = array(
'host' => 'admin.izideal.vpn',
'type' => 'mysql',
'name' => 'nb',
),
);
-if (strpos(php_uname("n"),'ovh.net')!==false) $CONF['nb']['order'] = 1;
+if (strpos(php_uname("n"),'ovh.net')!==false) $DB_CONFS['nb']['order'] = 1;
return 1;
function tenant_doc(&$r) { return rent_doc('tenant',$r); }
<?php
-$CONF['owncloud'] = [
+$DB_CONFS['owncloud'] = [
'_import' => '_nico',
'name' => 'owncloud',
'type' => 'mysql',
<?php
-$CONF['postfix'] = array (
+$DB_CONFS['postfix'] = array (
'title' => 'Postfix on Izideal',
'type' => 'mysql',
'host' => 'admin.izideal.vpn',
<?php
-$CONF['puppetdb'] = array (
+$DB_CONFS['puppetdb'] = array (
'title' => 'Puppetdb',
'host' => 'big.cascais.loc',
'type' => 'pgsql',
<?php
-$CONF['_ui'] = array(
+$DB_CONFS['_ui'] = array(
'title' => 'Semantico UI',
'type' => 'sqlite',
'host' => (file_exists('/opt/www/sem_ui/var/db/semantico.db') ? '/opt/www/sem_ui/var/db/semantico.db' : "$DIR_SQLITE/semantico.db"),
),
);
-$CONF['ui'] = [
+$DB_CONFS['ui'] = [
'_import' => ['_ui'],
'order' => (preg_match('/^(dev|isp|ist)/',php_uname('n')) ? 1 : null),
#'order' => 1,
];
-$CONF['ui-pgsql'] = [
+$DB_CONFS['ui-pgsql'] = [
'host' => 'ui.semantico.net',
'type' => 'pgsql',
'name' => 'ui',
'pdo' => '',
'_import' => ['_ui','_semadm'],
];
-$CONF['ui-mysql'] = [
+$DB_CONFS['ui-mysql'] = [
'host' => 'ui.semantico.net',
'type' => 'mysql',
'name' => 'ui',
<?php
-$CONF['wp'] = [
+$DB_CONFS['wp'] = [
'title' => 'Wordpress',
'host' => 'admin.izideal.vpn',
'type' => 'mysql',
];
if (false and !empty($GLOBALS['wpdb'])) {
- $CONF['wp']['type'] = 'sqlite';
- $CONF['wp']['host'] = DB_DIR.'/'.DB_FILE;
+ $DB_CONFS['wp']['type'] = 'sqlite';
+ $DB_CONFS['wp']['host'] = DB_DIR.'/'.DB_FILE;
}
-$CONF['wp-sqlite'] = array (
+$DB_CONFS['wp-sqlite'] = array (
'host' => "$DIR_SQLITE/wp.db",
'type' => 'sqlite',
'_import' => 'wp',
+++ /dev/null
-#!/bin/bash
-[% programname=input("Program name: ")
- log4perl=choice('with Log::Log4perl: ', 'no', 'yes')
--%]
-fetchmail=`which fetchmail`
-
-case "$1" in
-
-'start')
- if pidof fetchmail &>/dev/null; then
- echo "Fetchmail is already running"
- exit 1
- fi
- if $fetchmail -f $fetchmailrc; then
- echo "Fetchmail is up"
- exit 0
- else
- echo "Fetchmail can not start"
- exit 2
- fi
-;;
-
-'stop')
- if !(pidof fetchmail &>/dev/null); then
- echo "Fetchmail is already down"
- exit 1
- fi
- if $fetchmail -q; then
- echo "Fetchmail is down"
- exit 0
- else
- echo "Fetchmail can not stop"
- exit 2
- fi
-;;
-
-'restart')
- $0 stop
- sleep 2
- $0 start
-;;
-
-'status')
- if pidof fetchmail &>/dev/null; then
- echo "Fetchmail is up"
- exit 0
- else
- echo "Fetchmail is down"
- exit 1
- fi
-;;
-
-*)
- echo "usage $0 start|stop|restart|status"
- exit -1
-;;
-
-esac
-
-exit
if (empty($this->type)) $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$this->pdo));
if (!$this->type) return false;
- if ($this->type('use_path')) {
+ if ($this->conf_type('use_path')) {
if ($p = $this->p('db.host')) $this->host = $p;
if (empty($this->host)) $this->host = preg_replace('/^\w+:/','',$this->pdo);
# Add file
if (empty($this->title)) $this->title = prettyText($this->name);
# Row parser
- if (empty($this->row_parse) and $this->type('row_parse')) {
- $this->row_parse = $this->type('row_parse');
+ if (empty($this->row_parse) and $this->conf_type('row_parse')) {
+ $this->row_parse = $this->conf_type('row_parse');
}
}
if (empty($this->pdo)) return false;
# Type
- if (!$this->type(null)) $this->bye("Unknow type = `".$this->type."`");
+ $this->conf_type_load();
# Connect
try {
if (empty($this->conn)) return false;
# Create functions
- if ($this->type('sqliteCreateFunction')) {
- foreach ($this->type('sqliteCreateFunction') as $name => $fct) {
- if (is_array($fct)) {
- $this->conn->sqliteCreateFunction($name,$fct[0],$fct[1]);
- } else {
- $this->conn->sqliteCreateFunction($name,$fct);
- }
+ foreach ((array)$this->conf_type('sqliteCreateFunction') as $name => $fct) {
+ if (is_array($fct)) {
+ $this->conn->sqliteCreateFunction($name,$fct[0],$fct[1]);
+ } else {
+ $this->conn->sqliteCreateFunction($name,$fct);
}
}
}
function quote($v) {
- static $fct = false; if ($fct === false) $fct = $this->type('quote');
+ static $fct = false; if ($fct === false) $fct = $this->conf_type('quote');
if ($fct) return $fct($v);
return $this->conn->quote($v);
}
}
public function method($key=null,$args=null) {
- $method = $this->type($key);
+ $method = $this->conf_type($key);
if (is_callable($method)) return $this->unvar($method($this));
return $this->unvar($method);
}
- public function type($key=null,$die=false,$type=null) {
+ public function conf_type_load($type=null) {
global $DB_TYPES;
- if (!$type) $type = $this->type;
- if ($key == 'type') return $type;
-
- # Load php file
static $require = [];
+
+ if (empty($type)) $type = $this->type;
+ if (empty($type)) self::bye('Db type is required');
+
if (empty($require[$type])) {
- if (empty($type)) self::bye('Db->type is required');
- require_once(dirname(__FILE__).'/db/types/'.$type.'.php');
- $require[$type] = 1;
+ $require[$type] = dirname(__FILE__).'/db/types/'.$type.'.php';
+ if (!file_exists($require[$type])) self::bye("Unknow type `$type`");
+ $require[$type] = dirname(__FILE__).'/db/types/'.$type.'.php';
+ require_once($require[$type]);
}
- $db_type = $DB_TYPES[$type];
+ return $DB_TYPES[$type];
+ }
+
+ public function conf_type($key=null,$die_if_empty=false) {
+
+ # Load php file
+ $db_type = $this->conf_type_load();
# Dump all array
if ($key === null) return $db_type;
# Check key exists
if (empty($db_type[$key])) {
- if ($die) self::bye("db.type(): Unknow key `$key` for type `".$type."`");#.' - '.print_r($DB_TYPES,true));
+ if ($die_if_empty) self::bye("db.type(): Unknow key `$key` for type `".$this->type."`");#.' - '.print_r($db_type,true));
return;
}
return $this->unvar($db_type[$key]);
- $value = $db_type[$key];
- /*
- */
- if (is_scalar($value)) {
- $value = $this->unvar($value);
- } elseif (is_scalar($value) and !$this->is_hash($value)) {
- for ($i=0;$i<count($value);$i++) {
- if (is_scalar($value[$i])) $value[$i] = $this->unvar($value[$i]);
- }
- }
- return $value;
- return $db_type[$key];
+ }
+
+ public function type($key=null,$die=false,$type=null) {
+ if (empty($type)) $type = $this->type;
+ if (!empty($key) and $key == 'type') return $type;
+
+ return $this->conf_type($key,$die);
}
public function tables() {
if (strpos($value,'.') !== false) return $value;
# specific quote
- if ($q=$this->type('quote_name')) return $q.$value.$q;
+ if ($q=$this->conf_type('quote_name')) return $q.$value.$q;
# default quote
return '"'.$value.'"';
$h = array_replace_recursive($h,$yaml);
} elseif (preg_match('/\.php$/i',$file)) {
- #global $CONF;
- require($file); if (!empty($CONF)) $h = array_replace_recursive($h,$CONF);
+ #global $DB_CONFS;
+ require($file);
+ if (!empty($DB_CONFS)) $h = array_replace_recursive($h,$DB_CONFS);
}
}
- unset($yaml,$CONF);
+ unset($yaml,$DB_CONFS);
if (!$h) return false;
# Emulate hash pointer _import
'DROP '.strtoupper($t->type).' IF EXISTS '.$t->sql_name()
;
/*
- if ($drop = $this->type('sql.drop')) {
+ if ($drop = $this->conf_type('sql.drop')) {
$drop = str_replace('<NAME>',$t->name,$drop);
$drop = str_replace('<TYPE>',strtoupper($t->type),$drop);
} else {
#'conf' => count(array_keys($this->conf)),
'tables' => count($this->tables()),
]
- +($this->type('use_path') ? [] : array(
+ +($this->conf_type('use_path') ? [] : array(
'port' => $this->port,
'user' => $this->user,
))
+$new;
- if (($sqls=$this->type('status'))) {
+ if (($sqls=$this->conf_type('status'))) {
foreach ($sqls as $sql => $fct) {
} # << type.status
- if (($call=$this->type('status_callback'))) {
+ if (($call=$this->conf_type('status_callback'))) {
$call($new);
}
public function sql_pre() {
$return = [];
- foreach ((array)$this->type('sql_pre') as $s) {
+ foreach ((array)$this->conf_type('sql_pre') as $s) {
if (!empty($s)) $return[] = $s;
}
$this->databases = [];
$name = self::p('name','');
- if ($sql = $this->type('databases')) {
+ if ($sql = $this->conf_type('databases')) {
$fct = '';
if (is_array($sql)) list($sql,$fct) = count($sql)>1 ? $sql : [$sql[0],''];
public function create($from_sql=true) {
// String replace function
- $sql_replace_fct = $this->db()->type('table.sql.create',false);
+ $sql_replace_fct = $this->db()->conf_type('table.sql.create',false);
$db_sql_replace_fct = empty($this->db()->sql_replace) ? '' : $this->db()->sql_replace;
$sql_replace = function($sql) use ($sql_replace_fct,$db_sql_replace_fct) {
if ($db_sql_replace_fct) $sql = $db_sql_replace_fct($sql);
}
// Specific function for fields if return something use it instead of default
- $_create_fct = $this->db()->type('field.create',false);
+ $_create_fct = $this->db()->conf_type('field.create',false);
$_create = function(&$field) use ($_create_fct) {
if ($_create_fct and ($sql=$_create_fct($field))) return $sql;
;
}
- $indexes = [];#$this->db()->type('table.sql.index',false);
+ $indexes = [];#$this->db()->conf_type('table.sql.index',false);
foreach ($this->indexes() as $i) {
if (!empty($i['unique']) or !empty($i['key'])) continue;
$indexes[] = 'CREATE INDEX '.$i['name'].' ON '.$this->sql_name().' ('.$i['field'].')';
*/
public function indexes() {
if (!isset($this->indexes)) {
- $sql = $this->db()->type('table.sql.index');
+ $sql = $this->db()->conf_type('table.sql.index');
$fct = '';
if (is_array($sql)) list($sql,$fct) = (count($sql)==1 ? [$sql[0],null] : $sql);
return $this->sql;
}
- $sql = str_replace('<T.NAME>',$this->name,$this->db()->type('table.sql',true));
+ $sql = str_replace('<T.NAME>',$this->name,$this->db()->conf_type('table.sql',true));
# Noise before CREATE like MySql
$this->sql = explode('\0',$this->db()->row($sql,'\0'));
if (!isset($this->fields)) {
$this->fields = array();
- $conf = $this->unvar($this->db()->type('table.fields',true));
+ $conf = $this->unvar($this->db()->conf_type('table.fields',true));
if (is_scalar($conf)) $conf = array('sql'=>$conf);
$rows = $this->db()->conn->query($conf['sql']);
$rows->setFetchMode(PDO::FETCH_ASSOC);
$having = $where = array();
if (empty($logic)) $logic = 'AND';
- $regexp = $this->db()->type('regexp');
+ $regexp = $this->db()->conf_type('regexp');
if (empty($regexp)) $regexp = 'REGEXP';
foreach ($this->fields() as $k => $field) {
}
# having, denorm, EMPTY
- $extra_where = (string)$this->db()->type('extra_where');
+ $extra_where = (string)$this->db()->conf_type('extra_where');
if ($extra_where == 'having' and $field->extras) {
$having[] = $this->extras[$k]->sql_name()."$equal$v";
#return false;
# Test if type exists because of a bug from shell.php
-# NB 30.08.16 if ($this->db()->type('type')) $this->fields();
+# NB 30.08.16 if ($this->db()->conf_type('type')) $this->fields();
foreach ($extras as $k => $v) {
} else {
$where = $this->where_criterias($this->p(),$this->p('op'));
- $select_count = ( $where ? $this->db()->type('select_count') : null );
+ $select_count = ( $where ? $this->db()->conf_type('select_count') : null );
if (empty($select_count)) $select_count = array('','');
if (!empty($this->_rows_fields)) {
public function rows_begin_xml() {
return ''
.'<?xml version="1.0" encoding="utf-8"?>'.NB_EOL #<?
- .'<rows name="'.$this->name.'" database="'.$this->db()->name.'" database-type="'.$this->db()->type('type').'">'.NB_EOL
+ .'<rows name="'.$this->name.'" database="'.$this->db()->name.'" database-type="'.$this->db()->conf_type('type').'">'.NB_EOL
;
}
exit;
}
- public static function oc_password_verify($pass) {
- require_once "/home/owncloud/config/config.php";
- require_once '/opt/owncloud/lib/base.php';
- require_once '/opt/owncloud/lib/private/Security/Hasher.php';
- return \OC::$server->getHasher()->hash($pass);
- $l = new Hasher($CONFIG);
- debug($l->legacyHashVerify($pass,"YbS9N9cK8TY6b7oyw3skfcHykXIjlx"));
- return $CONFIG;
- debug($CONF);
- }
-
/*
* Function client_content_type
* Return the head Accept from the client
--- /dev/null
+<?php
+function oc_password_verify($pass) {
+ require_once "/home/owncloud/config/config.php";
+ require_once '/opt/owncloud/lib/base.php';
+ require_once '/opt/owncloud/lib/private/Security/Hasher.php';
+ return \OC::$server->getHasher()->hash($pass);
+ $l = new Hasher($CONFIG);
+ debug($l->legacyHashVerify($pass,"YbS9N9cK8TY6b7oyw3skfcHykXIjlx"));
+ return $CONFIG;
+ debug($CONFIG);
+}
+?>
'php' => array(
'enclose' => [
- '<?php'.(NB_EOL ? NB_EOL:' ') . '$CONF = array('.NB_EOL
+ '<?php'.(NB_EOL ? NB_EOL:' ') . '$VAR = array('.NB_EOL
,NB_EOL.');' . (NB_EOL ? NB_EOL:' ').'?'.'>'.NB_EOL
],
'eol' => self::p('eol',NB_EOL),