Skip to content

Commit

Permalink
Merge pull request #3 from clonos/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
olevole committed Apr 9, 2017
2 parents e3b714a + d4a75b9 commit 94e83d5
Show file tree
Hide file tree
Showing 718 changed files with 3,387 additions and 140,817 deletions.
992 changes: 752 additions & 240 deletions php/clonos.php

Large diffs are not rendered by default.

27 changes: 18 additions & 9 deletions php/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Config
'en'=>'English',
'ru'=>'Russian',
);

public $other_titles=array(
'settings'=>'CBSD Settings',
);

/* Меню проекта */
/* Так же можно использовать подменю (в menu.php есть пример) */
Expand All @@ -32,13 +36,13 @@ class Config
'title'=>'Virtual machine control panel',
'icon'=>'icon-th-list',
),
/*
'nodes'=>array(
'name'=>'Nodes',
'title'=>'Nodes control panel',
'icon'=>'icon-buffer',
),
*/
'vpnet'=>array(
'name'=>'Virtual Private Network',
'title'=>'Manage for virtual private networks',
Expand All @@ -56,13 +60,13 @@ class Config
'title'=>'Virtual Media Manager',
'icon'=>'icon-inbox',
),

/*
'repo'=>array(
'name'=>'Repository',
'title'=>'Remote repository',
'icon'=>'icon-globe',
),

*/
'bases'=>array(
'name'=>'FreeBSD Bases',
'title'=>'FreeBSD bases manager',
Expand All @@ -74,19 +78,19 @@ class Config
'title'=>'FreeBSD sources manager',
'icon'=>'icon-edit',
),
/*
'jail_marketplace'=>array(
'name'=>'Jail Marketplace',
'title'=>'Public remote containers marketplace',
'icon'=>'icon-flag',
),
*//*
'bhyve_marketplace'=>array(
'name'=>'Bhyve Marketplace',
'title'=>'Public remote virtual machine marketplace',
'icon'=>'icon-flag-checkered',
),
*/
'tasklog'=>array(
'name'=>'TaskLog',
'title'=>'System task log',
Expand All @@ -102,6 +106,13 @@ class Config
);

public $os_types=array(
array(
'os'=>'DragonflyBSD',
'items'=>array(
array('name'=>'DragonflyBSD 4','type'=>'dflybsd',
'profile'=>'x86-4','obtain'=>false),
),
),
array(
'os'=>'FreeBSD',
'items'=>array(
Expand All @@ -120,8 +131,6 @@ class Config
'profile'=>'ArchLinux-x86-2016','obtain'=>false),
array('name'=>'Linux CentOS 7','type'=>'linux',
'profile'=>'CentOS-7-x86_64','obtain'=>false),
array('name'=>'Linux Debian 7','type'=>'linux',
'profile'=>'Debian-x86-7','obtain'=>false),
array('name'=>'Linux Debian 8','type'=>'linux',
'profile'=>'Debian-x86-8','obtain'=>false),
array('name'=>'Linux Open Suse 42','type'=>'linux',
Expand Down
46 changes: 32 additions & 14 deletions php/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,37 @@ function __construct($place='base',$database='')
{
$this->_workdir=getenv('WORKDIR'); // /usr/jails/

// sqlite:/usr/jails/var/db/local.sqlite
if($place=='base')
switch($place)
{
$file_name=$this->_workdir.'/var/db/'.$database.'.sqlite';
$connect='sqlite:'.$file_name;
}elseif($place=='file'){

}elseif($place=='helper'){
$file_name=$this->_workdir.'/formfile/'.$database.".sqlite";
$connect='sqlite:'.$file_name;
}elseif($place=='helpers'){
//$file_name=$this->_workdir.'/formfile/'.$database['jname'].'/helpers/'.$database.".sqlite";
//$connect='sqlite:'.$file_name;
case 'base':
$file_name=$this->_workdir.'/var/db/'.$database.'.sqlite';
$connect='sqlite:'.$file_name;
break;
case 'file':
$file_name=$database;
$connect='sqlite:'.$file_name;
break;
case 'helper':
if(is_array($database))
{
///usr/jails/jails-system/cbsdpuppet1/helpers/redis.sqlite
$file_name=$this->_workdir.'/jails-system/'.$database['jname'].'/helpers/'.$database['helper'].".sqlite";
$connect='sqlite:'.$file_name;
}else{
$file_name=$this->_workdir.'/formfile/'.$database.".sqlite";
$connect='sqlite:'.$file_name;
}
break;
case 'cbsd-settings':
$file_name=$this->_workdir.'/jails-system/CBSDSYS/helpers/cbsd.sqlite';
$connect='sqlite:'.$file_name;
break;
case 'clonos':
$file_name='/var/db/clonos/clonos.sqlite';
$connect='sqlite:'.$file_name;
break;
}

/*
$databases=array(
'tasks'=>'cbsdtaskd',
Expand Down Expand Up @@ -81,15 +98,16 @@ function __construct($place='base',$database='')
}
*/

$this->_filename=$file_name;
//echo $file_name,PHP_EOL,PHP_EOL;

if(!isset($file_name) || empty($file_name) || !file_exists($file_name))
{
$this->error=true;
$this->error_message='DB file not found!';
return false;
}

$this->_filename=$file_name;

if(!empty($connect))
{
try
Expand Down
146 changes: 135 additions & 11 deletions php/forms.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,100 @@
<?php
/*
(
[idx] => 1
[mytable] => forms
[group_id] => 1
[order_id] => 1
[param] => ldap_host
[desc] => LDAP server
[def] => 192.168.1.3
[cur] =>
[new] =>
[mandatory] => 1
[attr] => maxlen=60
[xattr] =>
[type] => inputbox
[link] =>
)
*/
class Forms
{
private $name='';
private $db='';
private $html='';

function __construct($jname,$helper)
function __construct($jname,$helper='',$db_path=false)
{
$this->name=$jname;
$this->db=new Db('helpers',array('jname'=>$jname,'helper'=>$helper));
if($jname=='')
{
$database=$helper;
}else if($jname=='cbsd-settings'){
$this->db=new Db('cbsd-settings');
}else{
$database=array('jname'=>$jname,'helper'=>$helper);
}
if($helper!='')
{
if($db_path!==false)
{
$this->db=new Db('file',$db_path);
}else{
$this->db=new Db('helper',$database);
}
}
}

function generate()
{
if($this->db->error) return;
$query="select * from forms order by group_id asc, order_id asc";
//$query="select * from forms order by group_id asc, order_id asc";
$query="select * from forms order by groupname asc, group_id asc, order_id asc";
$fields=$this->db->select($query);
//print_r($fields);exit;
//echo '<pre>';print_r($fields);
$defaults=array();
//$defaults=array();
//$currents=array();

// Строим карту формы с группами элементов
$groups=array();
foreach($fields as $key=>$field)
{
$group=$field['groupname'];
if(!empty($group))
{
if($field['type']=='group_add')
{ // Expand
$groups[$group]['_title']=$field['desc'];
}else if($field['type']=='delimer'){
// Delimer
$groups[$group][$field['group_id']]=$key;
}else{
// Other elements
$groups[$group][$field['group_id']]['_group_id']=$field['group_id'];
$groups[$group][$field['group_id']][$field['order_id']]=$key;
}
}else{
$groups[]=$key;
}
}
//print_r($fields);print_r($groups);exit;

$arr=array();
$last_type='';
$this->html='<form name=""><div class="form-fields">';
foreach($fields as $key=>$field)
{
/*
if($last_type=='delimer' && $field['type']!='delimer')
$this->html.='<div class="pad-head"></div>';
*/
$last_type=$field['type'];


if(isset($field['cur']) && isset($field['def']))
{
if(empty($field['cur'])) $field['cur']=$field['def'];
}

$tpl=$this->getElement($field['type'],$field);
$params=array('param','desc','attr','cur');
foreach($params as $param)
Expand All @@ -47,15 +113,45 @@ function generate()

$required=($field['mandatory']==1)?' required':'';
$tpl=str_replace('${required}',$required,$tpl);
$this->html.=$tpl;
$arr[$key]=$tpl;

if(!empty($field['def'])) $defaults[$key]=$field['def'];
//if($field['param']!='-') $currents[$field['param']]=$field['cur'];
//if($field['param']!='-') $defaults[$field['param']]=$field['def'];
}

// Выстраиваем форму по карте
$this->html='<form class="helper" name="" onsubmit="return false;"><div class="form-fields">';
foreach($groups as $key=>$txt)
{
if(is_numeric($key))
{
$this->html.=$arr[$key];
}else if(is_array($txt)){
$group_name=key($txt);
$group_title=$txt['_title'];
unset($txt['_title']);
foreach($txt as $key1=>$val1)
{
$group_id=$val1['_group_id'];
unset($val1['_group_id']);
if(is_array($val1))
{
$this->html.='<div class="form-field"><fieldset id="ind-'.$group_id.'"><legend>'.$group_title.'</legend>';
foreach($val1 as $key2=>$val2)
$this->html.=$arr[$val2];
$this->html.='<div><input type="button" value="delete group" class="fgroup-del-butt" /></div></fieldset></div>';
}else{
$this->html.=$arr[$key1];
}
}
$this->html.='<div class="form-field"><input type="button" value="add group" class="fgroup-add-butt" /></div>';
}
}
$this->html.='</div>';

$this->setButtons();
$this->html.='</form>';
return array('html'=>$this->html,'defaults'=>$defaults);
return array('html'=>$this->html); // ,'currents'=>$currents //,'defaults'=>$defaults
}

function getElement($el,$arr=array())
Expand All @@ -64,7 +160,17 @@ function getElement($el,$arr=array())
switch(trim($el))
{
case 'inputbox':
$tpl='<div class="form-field"><input type="text" name="${param}" value="${value}" ${attr}${required} /><span class="default val-${def}" title="Click to fill dafault value">[default]</span><span class="small">${desc}</span></div>';
$res=$this->getInputAutofill($arr);
if($res===false)
{
$list='';
$datalist='';
}else{
$list=' list="'.$res['list'].'"';
$datalist=$res['datalist'];
}
$tpl='<div class="form-field"><input type="text" name="${param}" value="${value}" ${attr}${required}'.$list.' /><span class="default val-${def}" title="Click to fill dafault value">[default]</span><span class="small">${desc}</span>'.$datalist.'</div>';
//'.$default.'
break;
case 'password':
$tpl='<div class="form-field"><input type="password" name="${param}" value="${value}" ${attr}${required} /><span class="default val-${def}" title="Click to fill dafault value">[default]</span><span class="small">${desc}</span></div>';
Expand All @@ -85,14 +191,32 @@ function getElement($el,$arr=array())
return $tpl;
}

function getInputAutofill($arr)
{
if(isset($arr['link']))
{
$id=$arr['link']; //$arr['param'].'-'.
$tpl='<datalist id="'.$id.'">';
$query="select * from {$arr['link']} order by order_id asc";
$opts=$this->db->select($query);
if(!empty($opts))foreach($opts as $key=>$opt)
{
$tpl.='<option>'.$opt['text'].'</option>';
}
$tpl.='</datalist>';
return array('list'=>$id,'datalist'=>$tpl);
}else return false;
}

function getSelect($el,$arr)
{
$tpl='<div class="form-field"><select name="${param}">';
if(isset($arr['link']))
{
$query="select * from {$arr['link']} order by order_id asc";
$opts=$this->db->select($query);
array_unshift($opts,array('id'=>0,'text'=>'','order_id'=>-1));
// Пустое поле в списках оказалось ненужным!
//array_unshift($opts,array('id'=>0,'text'=>'','order_id'=>-1));
if(!empty($opts))foreach($opts as $key=>$opt)
{
$selected=($opt['id']==$arr['cur'])?' selected':'';
Expand Down
13 changes: 10 additions & 3 deletions php/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ function __construct($menu_config=array(),$parent)

$this->html='<ul class="menu">'.PHP_EOL;

$qstr=trim($_SERVER['REQUEST_URI'],'/');
//$qstr=trim($_SERVER['REQUEST_URI'],'/');
$qstr=trim($parent->uri_chunks[0],'/');
$this->path=$qstr; //$_MENU_PATH
if(!empty($menu_config))foreach($menu_config as $key=>$val)
{
{
$mname=$parent->translate($val['name']);
$mtitle=$parent->translate($val['title']);

Expand Down Expand Up @@ -85,6 +86,12 @@ function __construct($menu_config=array(),$parent)
$this->html.= '</li>'.PHP_EOL;
}

$this->html.='</ul>';
$this->html.='</ul>';

if($this->title=='Error')
{
if(isset($parent->config->other_titles[$qstr]))
$this->title=$parent->translate($parent->config->other_titles[$qstr]);
}
}
}
Loading

0 comments on commit 94e83d5

Please sign in to comment.