From: Nicolas Boisselier Date: Tue, 20 Sep 2016 22:47:10 +0000 (+0200) Subject: Bed X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=5fbc78d527b02e0e7877312f12f3dbe014ba1139;p=nb.git Bed --- diff --git a/etc/dbs.php b/etc/dbs.php index 8af2fee8..799ff544 100644 --- a/etc/dbs.php +++ b/etc/dbs.php @@ -1,6 +1,6 @@ $db) { +foreach ($DB_CONFS as $id => $db) { if (1 and !empty($db['type']) and $db['type'] == 'sqlite' and !empty($db['host']) @@ -45,20 +45,20 @@ if ($DIR_SQLITE) { 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]); } } @@ -66,7 +66,7 @@ if ($DIR_SQLITE) { # Sqlite all Attach db type=sqlite # #return; -$CONF['all'] = [ +$DB_CONFS['all'] = [ 'host' => ':memory:', 'type' => 'sqlite', 'pdo' => '', @@ -82,7 +82,7 @@ $CONF['all'] = [ ], ]; -foreach ($CONF as $id => $db) { +foreach ($DB_CONFS as $id => $db) { if (0 or empty($db['type'] ) or $db['type']!='sqlite' @@ -92,11 +92,11 @@ foreach ($CONF as $id => $db) { 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; diff --git a/etc/dbs/nb.php b/etc/dbs/nb.php index c2de8764..c6a5a731 100644 --- a/etc/dbs/nb.php +++ b/etc/dbs/nb.php @@ -1,6 +1,6 @@ 'admin.izideal.vpn', 'type' => 'mysql', 'name' => 'nb', @@ -64,7 +64,7 @@ $CONF['nb'] = array( ), ); -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); } diff --git a/etc/dbs/owncloud.php b/etc/dbs/owncloud.php index fd39f573..f1c78170 100644 --- a/etc/dbs/owncloud.php +++ b/etc/dbs/owncloud.php @@ -1,5 +1,5 @@ '_nico', 'name' => 'owncloud', 'type' => 'mysql', diff --git a/etc/dbs/postfix.php b/etc/dbs/postfix.php index ee0122d3..8c10855b 100644 --- a/etc/dbs/postfix.php +++ b/etc/dbs/postfix.php @@ -1,5 +1,5 @@ 'Postfix on Izideal', 'type' => 'mysql', 'host' => 'admin.izideal.vpn', diff --git a/etc/dbs/puppetdb.php b/etc/dbs/puppetdb.php index 71949728..cfe407b1 100644 --- a/etc/dbs/puppetdb.php +++ b/etc/dbs/puppetdb.php @@ -1,5 +1,5 @@ 'Puppetdb', 'host' => 'big.cascais.loc', 'type' => 'pgsql', diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index 70de31d5..eaae442c 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -1,5 +1,5 @@ '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"), @@ -153,19 +153,19 @@ $CONF['_ui'] = array( ), ); -$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', diff --git a/etc/dbs/wp.php b/etc/dbs/wp.php index 8940b04b..af776f2c 100644 --- a/etc/dbs/wp.php +++ b/etc/dbs/wp.php @@ -1,5 +1,5 @@ 'Wordpress', 'host' => 'admin.izideal.vpn', 'type' => 'mysql', @@ -13,11 +13,11 @@ $CONF['wp'] = [ ]; 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', diff --git a/etc/vim/templates/daemon.tt.bak b/etc/vim/templates/daemon.tt.bak deleted file mode 100644 index e3704c27..00000000 --- a/etc/vim/templates/daemon.tt.bak +++ /dev/null @@ -1,60 +0,0 @@ -#!/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 diff --git a/lib/php/db.php b/lib/php/db.php index 8758af67..b5b6623f 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -139,7 +139,7 @@ class Db extends nb { 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 @@ -184,8 +184,8 @@ class Db extends nb { 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'); } } @@ -203,7 +203,7 @@ class Db extends nb { if (empty($this->pdo)) return false; # Type - if (!$this->type(null)) $this->bye("Unknow type = `".$this->type."`"); + $this->conf_type_load(); # Connect try { @@ -223,13 +223,11 @@ class Db extends nb { 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); } } @@ -309,7 +307,7 @@ class Db extends nb { } 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); } @@ -371,25 +369,32 @@ class Db extends nb { } 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; @@ -401,23 +406,18 @@ class Db extends nb { # 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;$iunvar($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() { @@ -453,7 +453,7 @@ class Db extends nb { 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.'"'; @@ -550,13 +550,14 @@ class Db extends nb { $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 @@ -800,7 +801,7 @@ class Db extends nb { '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('',$t->name,$drop); $drop = str_replace('',strtoupper($t->type),$drop); } else { @@ -849,13 +850,13 @@ class Db extends nb { #'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) { @@ -876,7 +877,7 @@ class Db extends nb { } # << type.status - if (($call=$this->type('status_callback'))) { + if (($call=$this->conf_type('status_callback'))) { $call($new); } @@ -923,7 +924,7 @@ class Db extends nb { 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; } @@ -945,7 +946,7 @@ class Db extends nb { $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],'']; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 461759f6..c92f6033 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -137,7 +137,7 @@ Class Table extends nb { 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); @@ -151,7 +151,7 @@ Class Table extends nb { } // 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; @@ -177,7 +177,7 @@ Class Table extends nb { ; } - $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'].')'; @@ -193,7 +193,7 @@ Class Table extends nb { */ 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); @@ -228,7 +228,7 @@ Class Table extends nb { return $this->sql; } - $sql = str_replace('',$this->name,$this->db()->type('table.sql',true)); + $sql = str_replace('',$this->name,$this->db()->conf_type('table.sql',true)); # Noise before CREATE like MySql $this->sql = explode('\0',$this->db()->row($sql,'\0')); @@ -269,7 +269,7 @@ Class Table extends nb { 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); @@ -539,7 +539,7 @@ Class Table extends nb { $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) { @@ -605,7 +605,7 @@ Class Table extends nb { } # 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"; @@ -632,7 +632,7 @@ Class Table extends nb { #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) { @@ -688,7 +688,7 @@ Class Table extends nb { } 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)) { @@ -1049,7 +1049,7 @@ Class Table extends nb { public function rows_begin_xml() { return '' .''.NB_EOL #name.'" database="'.$this->db()->name.'" database-type="'.$this->db()->type('type').'">'.NB_EOL + .''.NB_EOL ; } diff --git a/lib/php/nb.php b/lib/php/nb.php index 2451ddac..3687550a 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -750,17 +750,6 @@ class NB { 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 diff --git a/lib/php/oc.php b/lib/php/oc.php new file mode 100644 index 00000000..3e3c5dc7 --- /dev/null +++ b/lib/php/oc.php @@ -0,0 +1,12 @@ +getHasher()->hash($pass); + $l = new Hasher($CONFIG); + debug($l->legacyHashVerify($pass,"YbS9N9cK8TY6b7oyw3skfcHykXIjlx")); + return $CONFIG; + debug($CONFIG); +} +?> diff --git a/lib/php/out.php b/lib/php/out.php index 0585e17c..e73c974c 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -37,7 +37,7 @@ Class Out extends Nb { 'php' => array( 'enclose' => [ - ''.NB_EOL ], 'eol' => self::p('eol',NB_EOL),