* Jail container pages

This commit is contained in:
Momchil Bozhinov
2022-08-05 18:58:36 +03:00
parent 89370fc39c
commit 26fffa3b79
5 changed files with 184 additions and 238 deletions

View File

@@ -1,83 +1,72 @@
<?php
$jail_name='';
if(isset($this->uri_chunks[1])) $jail_name=$this->uri_chunks[1];
if(!empty($jail_name))
{
if(isset($this->uri_chunks[1])){
$jail_name = $this->uri_chunks[1];
include('helpers.json.php');
return;
}
$db = new Db('base','nodes');
$res = $db->select('select nodename from nodelist', []);
$nodes = ['local'];
foreach($res as $val){
$nodes[] = $val['nodename'];
}
$html='';
//$hres=$this->getTableChunk('jailslist','thead');
//if($hres!==false) $thead=$hres[1];
$html = '';
$html_tpl_1 = '';
$statuses = ['Not Launched','Launched','unknown-1','Maintenance','unknown-3','unknown-4','unknown-5','unknown-6'];
$allnodes = [];
$jail_ids = [];
$nth = 0;
$hres = $this->getTableChunk('jailslist','tbody');
$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'];
foreach($nodes as $node){
$db1 = new Db('base', $node);
if($db1->error !== false){
$statuses=array('Not Launched','Launched','unknown-1','Maintenance','unknown-3','unknown-4','unknown-5','unknown-6');
$allnodes=array();
$jails = $db1->select("SELECT jname,ip4_addr,status,protected FROM jails WHERE emulator!='bhyve' and hidden!=1 order by jname asc;", []);
$allnodes[$node] = $jails;
$num = $nth & 1;
$jail_ids=array();
$nth=0;
$hres=$this->getTableChunk('jailslist','tbody');
if(!empty($nodes))foreach($nodes as $node)
{
$db1=new Db('base',$node);
if($db1!==false)
{
$jails=$db1->select("SELECT jname,ip4_addr,status,protected FROM jails WHERE emulator!='bhyve' and hidden!=1 order by jname asc;", []);
Utils::clonos_syslog("jailscontainers a.json.php:" . "SELECT jname,ip4_addr,status,protected FROM jails WHERE emulator!='bhyve' and hidden!=1 order by jname asc;");
$allnodes[$node]=$jails;
$num=$nth & 1;
if(!empty($jails)) foreach($jails as $jail)
{
if($hres!==false)
{
$jname=$jail['jname'];
$vnc_port_status='grey';
$vnc_port='';
$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));
foreach($jails as $jail){
if($hres !== false){
$vnc_port = '';
$vnc_port_file = $this->workdir.'/jails-system/'.$jail['jname'].'/vnc_port';
if(file_exists($vnc_port_file)){
$vnc_port = trim(file_get_contents($vnc_port_file));
}
$html_tpl=$hres[1];
$status=$jail['status'];
$vars=array(
'nth-num'=>'nth'.$num,
'node'=>$node,
'ip4_addr'=>str_replace(',',',<wbr />',$jail['ip4_addr']),
'jname'=>$jname,
'vnc_port'=>$vnc_port,
'vnc_port_status'=>$vnc_port_status,
'status'=>$status,
'jstatus'=>$this->translate($statuses[$status]),
'icon'=>($status==0)?'play':'stop',
'desktop'=>($status==0)?' s-off':' s-on',
'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 jail'),
);
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;
$html_tpl = $hres[1];
$status = $jail['status'];
$vars = [
'nth-num' => 'nth'.$num,
'node' => $node,
'ip4_addr' => str_replace(',',',<wbr />', $jail['ip4_addr']),
'jname' => $jail['jname'],
'vnc_port' => $vnc_port,
'vnc_port_status' => 'grey',
'status' => $status,
'jstatus' => $this->translate($statuses[$status]),
'icon' => ($status == 0) ? 'play' : 'stop',
'desktop' => ($status == 0) ? ' s-off' : ' s-on',
'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 jail'),
];
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;
}
$jail_ids[]=$jail['jname'];
$jail_ids[] = $jail['jname'];
/*
$jname=$jail['jname'];
$jail_ids[]=$jname;
@@ -93,7 +82,7 @@ if(!empty($nodes))foreach($nodes as $node)
$reboot_title=$this->translate('Restart jail');
$html.=
<<<EOT
<tr class="nth{$num}{$desktop}{$maintenance}" id="{$jname}">
<tr class="nth{$num}{$desktop}{$maintenance}" id="{$jail['jname']}">
<td>{$node}</td>
<td class="txtleft">{$jail['jname']}</td>
<td class="txtleft jname">{$jail['ip4_addr']}</td>
@@ -107,70 +96,51 @@ if(!empty($nodes))foreach($nodes as $node)
EOT;
*/
}
$nth++;
} else {
Utils::clonos_syslog("jailscontainers a.json.php: DB1 FALSE");
}
}
$html=str_replace(array("\n","\r","\t"),'',$html);
$tasks = (empty($jail_ids)) ? '' : $this->getRunningTasks($jail_ids);
$tasks='';
if(!empty($jail_ids))
{
$tasks=$this->getRunningTasks($jail_ids);
}
//echo '<pre>';print_r($tasks);exit;
$html_tpl_1=str_replace(array("\n","\r","\t"),'',$hres[1]);
if($hres!==false)
{
$vars=array(
'nth-num'=>'nth0',
'status'=>'',
'jstatus'=>$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);
if($hres !== false){
$html_tpl_1 = str_replace(["\n","\r","\t"], '', $hres[1]);
$vars = [
'nth-num' => 'nth0',
'status' => '',
'jstatus' => $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=array(
0=>array(
'icon'=>'icon-cancel',
'title'=>$this->translate('Delete')
),
1=>array(
'icon'=>'icon-lock',
'title'=>$this->translate('Protected jail')
)
);
$protected = [
0 => [
'icon' => 'icon-cancel',
'title' => $this->translate('Delete')
],
1 => [
'icon' => 'icon-lock',
'title' => $this->translate('Protected jail')
]
];
/*
echo json_encode(array(
// 'thead'=>$thead,
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'jailslist',
'tasks'=>$tasks,
'template'=>$html_tpl_1,
'protected'=>$protected,
));
*/
$included_result_array=array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'jailslist',
'tasks'=>$tasks,
'template'=>$html_tpl_1,
'protected'=>$protected,
);
$included_result_array = [
'tbody' => str_replace(["\n","\r","\t"], '', $html),
'error' => false,
'func' => 'fillTable',
'id' => 'jailslist',
'tasks' => $tasks,
'template' => $html_tpl_1,
'protected' => $protected
];

View File

@@ -1,19 +1,17 @@
<?php
if(isset($clonos->uri_chunks[1]))
{
if(isset($clonos->uri_chunks[1])){
include('helpers.php');
return;
}
$clonos->useDialogs(array(
$clonos->useDialogs([
'vnc',
'jail-settings',
'jail-settings-config-menu',
'jail-import',
'jail-clone',
'jail-rename',
));
]);
?>
<h1>Jail containers:</h1>

View File

@@ -1,113 +1,95 @@
<?php
$hash=$this->url_hash;
if(empty($hash))
{
$hash = $this->url_hash;
if(empty($hash)){
# Узнаём список хелперов
$jails_helpers=array();
$db=new Db('clonos');
if($db!==false)
{
$query="select module from jails_helpers_list";
if(!$db->error)
{
$res=$db->select($query, []);
if(!empty($res))
{
foreach($res as $r) $jails_helpers[]=$r['module'];
$jails_helpers = [];
$db = new Db('clonos');
if (!$db->error){
$res = $db->select("select module from jails_helpers_list", []);
if(!empty($res)){
foreach($res as $r){
$jails_helpers[] = $r['module'];
}
}
}
$lst=array();
if(!empty($jails_helpers)) foreach($jails_helpers as $helper)
{
$db=new Db('helper',array('jname'=>$jail_name,'helper'=>$helper));
$lst = [];
foreach($jails_helpers as $helper){
$db = new Db('helper', ['jname' => $jail_name, 'helper' => $helper]);
if(!$db->error) // !error — значит хелпер установлен
{
$res=$db->selectOne("select longdesc from system", []);
if(isset($res['longdesc'])) $description=$res['longdesc']; else $description=$this->translate('no data').'&hellip; ('.$file_name.')';
$lst[]=array('helper'=>$helper,'description'=>$description);
}else{
$hlst[]=$helper;
$res = $db->selectOne("select longdesc from system", []);
if(isset($res['longdesc'])){
$description = $res['longdesc'];
} else {
$description = $this->translate('no data').'&hellip; ('.$file_name.')';
}
$lst[] = ['helper' => $helper, 'description' => $description];
} else {
$hlst[] = $helper;
}
}
$html='';
$html_tpl='';
$empty_logo='/images/logo/empty.png';
$hres=$this->getTableChunk('helpers','tbody');
if($hres!==false) $html_tpl=$hres[1];
if(!empty($lst) && !empty($html_tpl))
{
foreach($lst as $item)
{
$tpl=$html_tpl;
$logo_file='images/logo/'.$item['helper'].'.png';
$logo=file_exists($this->realpath_public.$logo_file)?'/'.$logo_file:$empty_logo;
$vars=array(
'nth-num'=>'nth0',
'logo'=>$logo,
'name'=>$item['helper'],
'description'=>$item['description'],
'opentitle'=>$this->translate('Open'),
);
foreach($vars as $var=>$val)
$tpl=str_replace('#'.$var.'#',$val,$tpl);
$html.=$tpl;
}
}else{
$html='<tr><td colspan="3">'.$this->translate('No installed helpers').'</td></tr>';
}
// Определяем список хелперов, доступных для установки в клетку
$helpers_list_html='<ul class="helpers-list">';
if(!empty($hlst)) foreach($hlst as $item)
{
$logo_file='images/logo/'.$item.'.png';
$logo=file_exists($this->realpath_public.$logo_file)?'/'.$logo_file:$empty_logo;
$helpers_list_html.='<li><input type="checkbox" name="'.$item.'" id="'.$item.'"><label for="'.$item.'"><img src="'.$logo.'" />&nbsp; '.$item.'</label></li>';
}
$helpers_list_html.='</ul>';
$html=str_replace(array("\n","\r","\t"),'',$html);
/*
echo json_encode(array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'helperslist',
'helpers_list'=>$helpers_list_html,
));
*/
$included_result_array=array(
'tbody'=>$html,
'error'=>false,
'func'=>'fillTable',
'id'=>'helperslist',
'helpers_list'=>$helpers_list_html,
);
$html = '';
$html_tpl = '';
$empty_logo = '/images/logo/empty.png';
$hres = $this->getTableChunk('helpers','tbody');
if($hres !== false){
$html_tpl = $hres[1];
}
if(!empty($lst) && !empty($html_tpl)){
foreach($lst as $item){
$tpl = $html_tpl;
$logo_file = 'images/logo/'.$item['helper'].'.png';
$logo = file_exists($this->realpath_public.$logo_file) ? '/'.$logo_file : $empty_logo;
$vars = [
'nth-num' => 'nth0',
'logo' => $logo,
'name' => $item['helper'],
'description' => $item['description'],
'opentitle' => $this->translate('Open')
];
foreach($vars as $var => $val){
$tpl = str_replace('#'.$var.'#', $val, $tpl);
}
$html .= $tpl;
}
} else {
$html = '<tr><td colspan="3">'.$this->translate('No installed helpers').'</td></tr>';
}
// Определяем список хелперов, доступных для установки в клетку
$helpers_list_html = '<ul class="helpers-list">';
foreach($hlst as $item){
$logo_file = 'images/logo/'.$item.'.png';
$logo = file_exists($this->realpath_public.$logo_file) ? '/'.$logo_file : $empty_logo;
$helpers_list_html .= '<li><input type="checkbox" name="'.$item.'" id="'.$item.'"><label for="'.$item.'"><img src="'.$logo.'" />&nbsp; '.$item.'</label></li>';
}
$helpers_list_html .= '</ul>';
$html = str_replace(["\n","\r","\t"], '', $html);
$included_result_array = [
'tbody' => $html,
'error' => false,
'func' => 'fillTable',
'id' => 'helperslist',
'helpers_list' => $helpers_list_html
];
return;
}else{
} else {
# Открываем настройки хелпера
$db=new Db('helper',array('jname'=>$jail_name,'helper'=>$hash));
if($db->error)
{
//echo json_encode(array('error'=>true,'errorMessage'=>'No helper database!'));
$included_result_array=array('error'=>true,'errorMessage'=>'No helper database!');
$db = new Db('helper', ['jname' => $jail_name, 'helper' => $hash]);
if($db->error){
$included_result_array = ['error' => true,'errorMessage' => 'No helper database!'];
return;
}
$db_path=$db->getFileName();
$res_html=(new Forms($jail_name,$hash,$db_path))->generate();
$res_html='<h1>'.$this->translate('Helper settings: '.$hash).'</h1>'.$res_html;
$db_path = $db->getFileName();
$res_html = (new Forms($jail_name, $hash, $db_path))->generate();
$res_html = '<h1>'.$this->translate('Helper settings: '.$hash).'</h1>'.$res_html;
}
//echo json_encode(array('html'=>$res_html,'func'=>'fillTab'));
$included_result_array=array(
'html'=>$res_html,
'func'=>'fillTab'
);
$included_result_array = [
'html' => $res_html,
'func' => 'fillTab'
];

View File

@@ -1,10 +1,8 @@
<?php
$clonos->useDialogs(array(
'helpers-add',
));
$clonos->useDialogs(['helpers-add']);
?>
<h1><?php echo $clonos->translate('Helpers list for jail'),': ',$clonos->uri_chunks[1]; ?></h1>
<h1><?php echo $clonos->translate('Helpers list for jail'), ': ', $clonos->uri_chunks[1]; ?></h1>
<div id="tab1">
<p><span class="top-button icon-plus id:helpers-add"><?php echo $clonos->translate('Add helper'); ?></span></p>

View File

@@ -1,19 +1,17 @@
<?php
if(isset($clonos->uri_chunks[1]))
{
if(isset($clonos->uri_chunks[1])){
include('helpers.php');
return;
}
$clonos->useDialogs(array(
$clonos->useDialogs([
'vnc',
'jail-settings',
'jail-settings-config-menu',
'jail-import',
'jail-clone',
'jail-rename',
));
'jail-rename'
]);
?>
<h1>Контейнеры:</h1>