This commit is contained in:
Momchil Bozhinov
2022-08-05 17:02:04 +03:00
parent a514093616
commit 89370fc39c
4 changed files with 284 additions and 361 deletions

View File

@@ -1,46 +1,35 @@
<?php
$db=new Db('base','authkey');
$res=$db->select('SELECT idx,name,authkey FROM authkey;', []);
$db = new Db('base','authkey');
$res = $db->select('SELECT idx,name,authkey FROM authkey;', []);
$html = '';
$html='';
if($res!==false)
{
$nth=0;
$num=$nth & 1;
if($res !== false){
$nth = 0;
$num = $nth & 1;
if(!empty($res)) foreach($res as $item)
{
$hres=$this->getTableChunk('authkeyslist','tbody');
if($hres!==false)
{
$html_tmp=$hres[1];
$vars=array(
'nth-num'=>'nth'.$num,
'keyid'=>$item['idx'],
'keyname'=>$item['name'],
'keysrc'=>$item['authkey'],
'deltitle'=>' title="'.$this->translate('Delete').'"',
);
foreach($vars as $var=>$val)
$html_tmp=str_replace('#'.$var.'#',$val,$html_tmp);
$html.=$html_tmp;
foreach($res as $item){
$hres = $this->getTableChunk('authkeyslist', 'tbody');
if($hres !== false){
$vars = [
'nth-num' => 'nth'.$num,
'keyid' => $item['idx'],
'keyname' => $item['name'],
'keysrc' => $item['authkey'],
'deltitle' => ' title="'.$this->translate('Delete').'"'
];
foreach($vars as $var => $val){
$html_tmp = str_replace('#'.$var.'#', $val, $hres[1]);
}
$html .= $html_tmp;
}
}
/*
echo json_encode(array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'authkeyslist',
));
*/
$included_result_array=array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'authkeyslist',
);
$included_result_array = [
'tbody' => $html,
'error' => false,
'func' => 'fillTable',
'id' => 'authkeyslist'
];
}

View File

@@ -1,108 +1,88 @@
<?php
$html='';
$db=new Db('base','nodes');
$nodes=$db->select('select nodename,ip from nodelist order by nodename desc', []);
$nodes[]=array('nodename'=>'local');
$nodes=array_reverse($nodes);
$db = new Db('base','nodes');
$nodes = $db->select('select nodename,ip from nodelist order by nodename desc', []);
$nodes[] = ['nodename' => 'local'];
$nodes = array_reverse($nodes);
$ids=array();
$nth=0;
$hres=$this->getTableChunk('baseslist','tbody');
if(!empty($nodes))foreach($nodes as $node)
{
$db1=new Db('base',$node['nodename']);
if($db1!==false)
{
$bases=$db1->select("SELECT idx,platform,name,arch,targetarch,ver,stable,elf,date FROM bsdbase order by cast(ver AS int)", []);
$num=$nth & 1;
if(!empty($bases)) foreach($bases as $base)
{
$idle=1;
//print_r($node);exit;
if($node['nodename']!='local')
{
$idle=$this->check_locktime($node['ip']);
$ids = [];
$nth = 0;
$html = '';
$html_tpl = '';
$hres = $this->getTableChunk('baseslist','tbody');
foreach($nodes as $node){
$db1 = new Db('base', $node['nodename']);
if($db1->error !== false){
$bases = $db1->select("SELECT idx,platform,name,arch,targetarch,ver,stable,elf,date FROM bsdbase order by cast(ver AS int)", []);
$num = $nth & 1;
foreach($bases as $base){
$idle = 1;
if($node['nodename'] != 'local'){
$idle = $this->check_locktime($node['ip']);
}
$ids[] = $base['idx'];
$id = 'base'.$base['ver'].'-'.$base['arch'].'-'.$base['stable'];
$ids[]=$base['idx'];
$id='base'.$base['ver'].'-'.$base['arch'].'-'.$base['stable'];
if($hres!==false)
{
$html_tpl=$hres[1];
$vars=array(
'id'=>$id,
'nth-num'=>'nth'.$num,
'node'=>$node['nodename'],
'name'=>$base['name'],
'platform'=>$base['platform'],
'arch'=>$base['arch'],
'targetarch'=>$base['targetarch'],
'version'=>$base['ver'],
'version1'=>($base['stable']==1)?'stable':'release',
'elf'=>$base['elf'],
'date'=>$base['date'],
'jstatus'=>'',
'maintenance'=>($idle==0)?' maintenance':'',
'deltitle'=>$this->translate('Delete'),
);
foreach($vars as $var=>$val)
$html_tpl=str_replace('#'.$var.'#',$val,$html_tpl);
$html.=$html_tpl;
if($hres !== false){
$vars = [
'id' => $id,
'nth-num' => 'nth'.$num,
'node' => $node['nodename'],
'name' => $base['name'],
'platform' => $base['platform'],
'arch' => $base['arch'],
'targetarch' => $base['targetarch'],
'version' => $base['ver'],
'version1' => ($base['stable']==1) ? 'stable' : 'release',
'elf' => $base['elf'],
'date' => $base['date'],
'jstatus' => '',
'maintenance' => ($idle == 0) ? ' maintenance' : '',
'deltitle' => $this->translate('Delete')
];
foreach($vars as $var => $val){
$html_tpl = str_replace('#'.$var.'#', $val, $hres[1]);
}
$html .= $html_tpl;
}
//$ids[]='#base'.$bid;
$ids[]='#'.$id;
}
$nth++;
}
}
$html=str_replace(array("\n","\r","\t"),'',$html);
$tasks = (empty($ids)) ? '' : $tasks = $this->getRunningTasks($ids);
$tasks='';
if(!empty($ids))
{
$tasks=$this->getRunningTasks($ids);
if($hres! == false){
$html_tpl = str_replace(["\n","\r","\t"]), '', $hres[1]);
$vars = [
'nth-num' => 'nth0',
'status' => '',
//'jstatus' => $this->translate('Updating'),
//'icon' => 'spin6 animate-spin',
'desktop' => ' s-off',
'maintenance' => ' maintenance busy',
'updtitle' => $this->translate('Update'),
'deltitle' => $this->translate('Delete')
];
foreach($vars as $var => $val){
$html_tpl = str_replace('#'.$var.'#', $val, $html_tpl);
}
}
$html_tpl=str_replace(array("\n","\r","\t"),'',$hres[1]);
if($hres!==false)
{
$vars=array(
'nth-num'=>'nth0',
'status'=>'',
//'jstatus'=>$this->translate('Updating'),
//'icon'=>'spin6 animate-spin',
'desktop'=>' s-off',
'maintenance'=>' maintenance busy',
'updtitle'=>$this->translate('Update'),
'deltitle'=>$this->translate('Delete'),
);
foreach($vars as $var=>$val)
$html_tpl=str_replace('#'.$var.'#',$val,$html_tpl);
}
/*
echo json_encode(array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'baseslist',
'tasks'=>$tasks,
'template'=>$html_tpl,
));
*/
$included_result_array=array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'baseslist',
'tasks'=>$tasks,
'template'=>$html_tpl,
);
$included_result_array = [
'tbody' => str_replace(["\n","\r","\t"], '', $html),
'error' => false,
'func' => 'fillTable',
'id' => 'baseslist',
'tasks' => $tasks,
'template' => $html_tpl
];

View File

@@ -1,146 +1,125 @@
<?php
$html='';
//$hres=$this->getTableChunk('jailslist','thead');
//if($hres!==false) $thead=$hres[1];
$db=new Db('base','nodes');
$res=$db->select('select nodename from nodelist', []);
$nodes=array('local');
if(!empty($res))foreach($res as $val) $nodes[]=$val['nodename'];
$db = new Db('base','nodes');
$res = $db->select('select nodename from nodelist', []);
$nodes = ['local'];
foreach($res as $val){
$nodes[] = $val['nodename'];
}
$statuses=array('Not Launched','Launched','unknown-1','Maintenance','unknown-3','unknown-4','unknown-5','unknown-6');
$allnodes=array();
$statuses = ['Not Launched','Launched','unknown-1','Maintenance','unknown-3','unknown-4','unknown-5','unknown-6'];
$allnodes = [];
$jail_ids = [];
$nth = 0;
$html = '';
$html_tpl_1 = '';
$hres = $this->getTableChunk('bhyveslist','tbody');
$jail_ids=array();
$nth=0;
$hres=$this->getTableChunk('bhyveslist','tbody');
if(!empty($nodes))foreach($nodes as $node)
{
$db1=new Db('base',$node);
if($db1!==false)
{
$bhyves=$db1->select("SELECT jname,vm_ram,vm_cpus,vm_os_type,hidden,protected,bhyve_vnc_tcp_bind FROM bhyve where hidden!=1 order by jname asc;", []);
foreach($nodes as $node){
$db1 = new Db('base', $node);
if($db1->error !== false){
$bhyves = $db1->select("SELECT jname,vm_ram,vm_cpus,vm_os_type,hidden,protected,bhyve_vnc_tcp_bind FROM bhyve where hidden!=1 order by jname asc;", []);
//$allnodes[$node]=$bhyves;
$num=$nth & 1;
if(!empty($bhyves)) foreach($bhyves as $bhyve)
{
if($hres!==false)
{
$html_tpl=$hres[1];
$status=$this->check_vmonline($bhyve['jname']);
$num = $nth & 1;
foreach($bhyves as $bhyve){
if($hres !== false){
$jname=$bhyve['jname'];
$vnc_port_status='grey';
$vnc_ip=$bhyve['bhyve_vnc_tcp_bind'];
if($status==1)
{
$vnc_port_file=$this->workdir.'/jails-system/'.$jname.'/vnc_port';
if(file_exists($vnc_port_file))
{
$vnc_port=trim(file_get_contents($vnc_port_file));
$status = $this->check_vmonline($bhyve['jname']);
$vnc_port_status = 'grey';
if($status == 1){
$vnc_port_file = $this->workdir.'/jails-system/'.$bhyve['jname'].'/vnc_port';
if(file_exists($vnc_port_file)){
$vnc_port = trim(file_get_contents($vnc_port_file));
}
}else{
$vnc_port='';
} else {
$vnc_port = '';
}
if($vnc_ip!='127.0.0.1') $vnc_port_status='black';
$vars=array(
'jname'=>$bhyve['jname'],
'nth-num'=>'nth'.$num,
'desktop'=>'',
'maintenance'=>'',
'node'=>$node,
'vm_name'=>'',
'vm_ram'=>$this->fileSizeConvert($bhyve['vm_ram']),
'vm_cpus'=>$bhyve['vm_cpus'],
'vm_os_type'=>$bhyve['vm_os_type'],
'vm_status'=>$this->translate($statuses[$status]),
'desktop'=>($status==0)?' s-off':' s-on',
'icon'=>($status==0)?'play':'stop',
'protected'=>($bhyve['protected']==1)?'icon-lock':'icon-cancel',
'protitle'=>' title="'.$this->translate('Delete').'"',
// 'maintenance'=>($status==3)?' maintenance':'',
// 'protected'=>($jail['protected']==1)?'icon-lock':'icon-cancel',
// 'protitle'=>($jail['protected']==1)?' title="'.$this->translate('Protected jail').'"':' title="'.$this->translate('Delete').'"',
'vnc_title'=>$this->translate('Open VNC'),
'reboot_title'=>$this->translate('Restart bhyve'),
'vnc_port'=>$vnc_port,
'vnc_port_status'=>$vnc_port_status,
);
foreach($vars as $var=>$val)
$html_tpl=str_replace('#'.$var.'#',$val,$html_tpl);
if($node!='local') $html_tpl=str_replace('<span class="icon-cog"></span>','',$html_tpl);
$html.=$html_tpl;
if($bhyve['bhyve_vnc_tcp_bind'] != '127.0.0.1'){
$vnc_port_status = 'black';
}
$vars = [
'jname' => $bhyve['jname'],
'nth-num' => 'nth'.$num,
'desktop' => '',
'maintenance' => '',
'node' => $node,
'vm_name' => '',
'vm_ram' => $this->fileSizeConvert($bhyve['vm_ram']),
'vm_cpus' => $bhyve['vm_cpus'],
'vm_os_type' => $bhyve['vm_os_type'],
'vm_status' => $this->translate($statuses[$status]),
'desktop' => ($status == 0) ? ' s-off' : ' s-on',
'icon' => ($status == 0) ? 'play' : 'stop',
'protected' => ($bhyve['protected'] == 1) ? 'icon-lock' : 'icon-cancel',
'protitle' => ' title="'.$this->translate('Delete').'"',
// 'maintenance' => ($status == 3) ? ' maintenance' : '',
// 'protected' => ($jail['protected'] == 1 ) ? 'icon-lock' : 'icon-cancel',
// 'protitle' => ($jail['protected'] == 1) ? ' title="'.$this->translate('Protected jail').'"' : ' title="'.$this->translate('Delete').'"',
'vnc_title' => $this->translate('Open VNC'),
'reboot_title' => $this->translate('Restart bhyve'),
'vnc_port' => $vnc_port,
'vnc_port_status' => $vnc_port_status
];
foreach($vars as $var => $val){
$html_tpl = str_replace('#'.$var.'#', $val, $hres[1]);
}
if($node != 'local'){
$html_tpl = str_replace('<span class="icon-cog"></span>', '', $html_tpl);
}
$html .= $html_tpl;
}
$bhyve_ids[]=$bhyve['jname'];
$bhyve_ids[] = $bhyve['jname'];
}
$nth++;
}
}
$html=str_replace(array("\n","\r","\t"),'',$html);
$tasks = (empty($bhyve_ids)) ? '' : $this->getRunningTasks($bhyve_ids);
$tasks='';
if(!empty($bhyve_ids))
{
$tasks=$this->getRunningTasks($bhyve_ids);
if($hres !== false){
$html_tpl_1 = str_replace(["\n","\r","\t"], '', $hres[1]);
$vars = [
'nth-num' => 'nth0',
'vm_status' => $this->translate('Creating'),
'icon' => 'spin6 animate-spin',
'desktop' => ' s-off',
'maintenance' => ' maintenance busy',
'protected' => 'icon-cancel',
'protitle' => '',
'vnc_title' => $this->translate('Open VNC'),
'reboot_title' => $this->translate('Restart jail')
];
foreach($vars as $var => $val){
$html_tpl_1 = str_replace('#'.$var.'#', $val, $html_tpl_1);
}
}
$html_tpl_1=str_replace(array("\n","\r","\t"),'',$hres[1]);
if($hres!==false)
{
$vars=array(
'nth-num'=>'nth0',
'vm_status'=>$this->translate('Creating'),
'icon'=>'spin6 animate-spin',
'desktop'=>' s-off',
'maintenance'=>' maintenance busy',
'protected'=>'icon-cancel',
'protitle'=>'',
'vnc_title'=>$this->translate('Open VNC'),
'reboot_title'=>$this->translate('Restart jail'),
);
foreach($vars as $var=>$val)
$html_tpl_1=str_replace('#'.$var.'#',$val,$html_tpl_1);
}
$protected = [
0 => [
'icon' => 'icon-cancel',
'title' => $this->translate('Delete')
],
1 => [
'icon' => 'icon-lock',
'title' => $this->translate('Protected bhyve')
]
];
$protected=array(
0=>array(
'icon'=>'icon-cancel',
'title'=>$this->translate('Delete')
),
1=>array(
'icon'=>'icon-lock',
'title'=>$this->translate('Protected bhyve')
)
);
/*
echo json_encode(array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'bhyveslist',
'tasks'=>$tasks,
'template'=>$html_tpl_1,
'protected'=>$protected,
));
*/
$included_result_array=array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'bhyveslist',
'tasks'=>$tasks,
'template'=>$html_tpl_1,
'protected'=>$protected,
);
$included_result_array = [
'tbody' => str_replace(["\n","\r","\t"], '', $html),
'error' => false,
'func' => 'fillTable',
'id' => 'bhyveslist',
'tasks' => $tasks,
'template' => $html_tpl_1,
'protected' => $protected
];

View File

@@ -1,110 +1,85 @@
<?php
$res=array(
// 'item'=>array(
0=>array(
'id'=>1,
'name'=>'test',
'path'=>'test/test/',
'type'=>'клетка',
)
// )
);
$images=$this->getImportedImages();
$html='';
$nth=0;
$num=$nth & 1;
$html_tpl='';
$hres=$this->getTableChunk('impslist','tbody');
if($hres!==false)
{
$html_tmp=$hres[1];
$html_tmp=replaceVars($html_tmp,array(
'deltitle'=>' title="'.$this->translate('Delete').'"',
'dnldtitle'=>' title="'.$this->translate('Download').'"',
'imptitle'=>' title="'.$this->translate('Create').'"')
);
$html_tpl_1=$html_tmp;
}
if(!empty($images)) foreach($images as $item)
{
if(!isset($item['type'])) $item['type']='unknown';
//$hres=$this->getTableChunk('impslist','tbody');
if($hres!==false)
{
/*
$html_tmp=$hres[1];
$html_tmp=replaceVars($html_tmp,array(
'deltitle'=>' title="'.$this->translate('Delete').'"',
'dnldtitle'=>' title="'.$this->translate('Download').'"',
'imptitle'=>' title="'.$this->translate('Create').'"')
);
$html_tpl=$html_tmp;
*/
$html_tpl=$html_tmp;
$filename=$this->media_import.$item['name'];
$sizefilename=$filename.'.size';
if(file_exists($sizefilename))
{
$size=file_get_contents($sizefilename);
}else{
$size=filesize($filename);
}
$filesize=$this->fileSizeConvert($size,1024,true);
$query="select count(*) as busy from taskd where status<2 and jname='${item['jname']}'";
$busy=$this->_db_tasks->selectOne($query, []);
$jstatus='';
$jbusy='';
if($busy['busy']==1)
{
$jstatus=$this->translate('Exporting');
$jbusy='busy';
}
$vars=array(
'nth-num'=>'nth'.$num,
'id'=>$item['name'],
'jname'=>$item['name'],
'impsize'=>$filesize,
'jstatus'=>$jstatus,
'busy'=>$jbusy,
'imptype'=>$this->translate($item['type']),
);
foreach($vars as $var=>$val)
$html_tpl=str_replace('#'.$var.'#',$val,$html_tpl);
// $html_tmp=str_replace('#'.$var.'#',$val,$html_tmp);
$html.=$html_tpl;
function replaceVars($tpl,$vars){
foreach($vars as $var => $val){
$tpl = str_replace('#'.$var.'#', $val, $tpl);
}
}
function replaceVars($tpl,$vars)
{
foreach($vars as $var=>$val)
$tpl=str_replace('#'.$var.'#',$val,$tpl);
return $tpl;
}
/*
echo json_encode(array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'impslist',
'template'=>$html_tpl_1,
));
*/
$res = [
// 'item' => [
0 => [
'id' => 1,
'name' => 'test',
'path' => 'test/test/',
'type' => 'клетка'
]
// ]
];
$included_result_array=array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'impslist',
'template'=>$html_tpl_1,
);
$images = $this->getImportedImages();
$html = '';
$html_tpl_1 = '';
$nth = 0;
$num = $nth & 1;
$html_tpl = '';
$hres = $this->getTableChunk('impslist','tbody');
if($hres !== false){
$html_tpl_1 = replaceVars($hres[1], [
'deltitle' => ' title="'.$this->translate('Delete').'"',
'dnldtitle' => ' title="'.$this->translate('Download').'"',
'imptitle' => ' title="'.$this->translate('Create').'"')
];
}
foreach($images as $item){
if(!isset($item['type'])){
$item['type'] = 'unknown';
}
//$hres=$this->getTableChunk('impslist','tbody');
if($hres !== false){
$html_tpl = $html_tpl_1;
$filename = $this->media_import.$item['name'];
$sizefilename = $filename.'.size';
if(file_exists($sizefilename)){
$size = file_get_contents($sizefilename);
} else {
$size = filesize($filename);
}
$filesize = $this->fileSizeConvert($size, 1024, true);
$query = "select count(*) as busy from taskd where status<2 and jname='".$item['jname']."'";
$busy = $this->_db_tasks->selectOne($query, []);
$jstatus = '';
$jbusy = '';
if($busy['busy'] == 1){
$jstatus = $this->translate('Exporting');
$jbusy = 'busy';
}
$vars = [
'nth-num' => 'nth'.$num,
'id' => $item['name'],
'jname' => $item['name'],
'impsize' => $filesize,
'jstatus' => $jstatus,
'busy' => $jbusy,
'imptype' => $this->translate($item['type'])
];
foreach($vars as $var => $val){
$html_tpl = str_replace('#'.$var.'#', $val, $html_tpl);
}
$html .= $html_tpl;
}
}
$included_result_array = [
'tbody' => $html,
'error' => false,
'func' => 'fillTable',
'id' => 'impslist',
'template' => $html_tpl_1
];