From: Nicolas Boisselier Date: Fri, 2 Dec 2016 16:55:11 +0000 (+0000) Subject: lb X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=94aaa6f2b659cc9c7bd0814394b196a3faf5385b;p=nb.git lb --- diff --git a/etc/dbq/ui.php b/etc/dbq/ui.php index 9ed51562..89dfc9a3 100644 --- a/etc/dbq/ui.php +++ b/etc/dbq/ui.php @@ -1,6 +1,7 @@ (preg_match('/^(dev|isp|ist)/',php_uname('n')) ? 1 : null), #'order' => 1, ]; +return; $DBQ['ui-pgsql'] = [ 'host' => 'ui.semantico.net', 'type' => 'pgsql', diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 705d5b95..43e503b4 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1034,29 +1034,41 @@ Class Table extends nb { Template -----------------------------------------------------------------*/ public function rows_begin_template($fields,&$o) { - if (empty($id) and !( $id=self::p('table.template.id') ) ) self::bye('Wrong parameter!'); + $id = self::templateid(); $id = preg_replace('/[^\w\._-]/','',$id); $file = TABLE_TEMPLATE.'/'.$id.'.php'; if (!is_readable($file)) return false; #self::bye("Wrong id `$id`"); - $o['file'] = $file; - $HEAD = array_keys($fields); - $ROWS = []; - $ROW = []; - require $o['file']; +# NB 02.12.16 $o['file'] = $file; + $this->__file = $file; + $this->__fields = array_keys($fields); +# NB 02.12.16 $HEAD = array_keys($fields); +# NB 02.12.16 $ROWS = []; +# NB 02.12.16 $ROW = []; +# NB 02.12.16 require $o['file']; } public function rows_rec_template($row,&$o) { - $HEAD = []; - $ROWS = [$row]; - $ROW = $row; - require $o['file']; + $i = 0; + foreach ($row as $k=>$v) { + $row[$i] = $v; + $i++; + } + $this->__rows[] = $row; +# NB 02.12.16 $HEAD = []; +# NB 02.12.16 $ROWS = [$row]; +# NB 02.12.16 $ROW = $row; } public function rows_end_template() { + $HEAD = &$this->__fields; + $ROWS = &$this->__rows; + $ROW = &$ROWS[0];; + require $this->__file; unset($this->__file); unset($this->__fields); + unset($this->__rows); } /*----------------------------------------------------------------- @@ -1850,11 +1862,16 @@ Class Table extends nb { return $this->status; } - public function template($id=null) { + private static function templateid($id=null) { if (empty($id) and !( $id=self::p('table.template.id') ) and !( $id=self::p('idtemplate') ) ) self::bye('Wrong parameter!'); + return $id; + } + + public function template($id=null) { + $id = self::templateid($id); $id = preg_replace('/[^\w\._-]/','',$id); diff --git a/share/templates/hosts.php b/share/templates/hosts.php index 47e33df1..00232ce4 100644 --- a/share/templates/hosts.php +++ b/share/templates/hosts.php @@ -8,7 +8,9 @@ if (isset($ROWS)) foreach ($ROWS as $r) { 'addr', 'address', ] as $k) { - if (isset($r[$k])) $line[] = $r[$k]; + if (!isset($r[$k])) continue; + $line[] = $r[$k]; + break; } foreach ([ @@ -17,7 +19,9 @@ if (isset($ROWS)) foreach ($ROWS as $r) { 'name', 'id', ] as $k) { - if (isset($r[$k])) $line[] = $r[$k]; + if (!isset($r[$k])) continue; + $line[] = $r[$k]; + break; } if (count($line)==2) echo join(' ',$line)."\n"; diff --git a/share/templates/nginx-lb.php b/share/templates/nginx-lb.php new file mode 100644 index 00000000..3c49d933 --- /dev/null +++ b/share/templates/nginx-lb.php @@ -0,0 +1,26 @@ + $servers) { + echo "upstream $name {\n"; + foreach ($servers as $server) { + echo " server $server;\n"; + } + echo "}\n"; +}