diff --git a/public/pages/authkey/a.json.php b/public/pages/authkey/a.json.php index cc4cd2cd..d794ac33 100644 --- a/public/pages/authkey/a.json.php +++ b/public/pages/authkey/a.json.php @@ -1,46 +1,35 @@ 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' + ]; } \ No newline at end of file diff --git a/public/pages/bases/a.json.php b/public/pages/bases/a.json.php index bab8a334..a30dd076 100644 --- a/public/pages/bases/a.json.php +++ b/public/pages/bases/a.json.php @@ -1,108 +1,88 @@ 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){ + + $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, -); \ No newline at end of file +$included_result_array = [ + 'tbody' => str_replace(["\n","\r","\t"], '', $html), + 'error' => false, + 'func' => 'fillTable', + 'id' => 'baseslist', + 'tasks' => $tasks, + 'template' => $html_tpl +]; \ No newline at end of file diff --git a/public/pages/bhyvevms/a.json.php b/public/pages/bhyvevms/a.json.php index 0ff1ee91..4fe8645b 100644 --- a/public/pages/bhyvevms/a.json.php +++ b/public/pages/bhyvevms/a.json.php @@ -1,146 +1,125 @@ 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){ + $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('','',$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('', '', $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 +]; diff --git a/public/pages/imported/a.json.php b/public/pages/imported/a.json.php index 0544cf19..cee93578 100644 --- a/public/pages/imported/a.json.php +++ b/public/pages/imported/a.json.php @@ -1,110 +1,85 @@ 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, -); \ No newline at end of file +$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 +]; \ No newline at end of file diff --git a/public/pages/jailscontainers/a.json.php b/public/pages/jailscontainers/a.json.php index 627a077d..5a606743 100644 --- a/public/pages/jailscontainers/a.json.php +++ b/public/pages/jailscontainers/a.json.php @@ -1,83 +1,72 @@ 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){ -$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(',',',',$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('','',$html_tpl); - - $html.=$html_tpl; + $html_tpl = $hres[1]; + $status = $jail['status']; + $vars = [ + 'nth-num' => 'nth'.$num, + 'node' => $node, + 'ip4_addr' => str_replace(',',',', $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('', '', $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.= << + {$node} {$jail['jname']} {$jail['ip4_addr']} @@ -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 '
';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,
-);
\ No newline at end of file
+$included_result_array = [
+	'tbody' => str_replace(["\n","\r","\t"], '', $html),
+	'error' => false,
+	'func' => 'fillTable',
+	'id' => 'jailslist',
+	'tasks' => $tasks,
+	'template' => $html_tpl_1,
+	'protected' => $protected
+];
\ No newline at end of file
diff --git a/public/pages/jailscontainers/en.index.php b/public/pages/jailscontainers/en.index.php
index b482eecb..86e05f9d 100644
--- a/public/pages/jailscontainers/en.index.php
+++ b/public/pages/jailscontainers/en.index.php
@@ -1,19 +1,17 @@
 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 containers:

diff --git a/public/pages/jailscontainers/helpers.json.php b/public/pages/jailscontainers/helpers.json.php index d1b654ac..748c1ffe 100644 --- a/public/pages/jailscontainers/helpers.json.php +++ b/public/pages/jailscontainers/helpers.json.php @@ -1,113 +1,95 @@ 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').'… ('.$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').'… ('.$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=''.$this->translate('No installed helpers').''; - } - - // Определяем список хелперов, доступных для установки в клетку - $helpers_list_html=''; - - $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 = ''.$this->translate('No installed helpers').''; + } + + // Определяем список хелперов, доступных для установки в клетку + $helpers_list_html = ''; + $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='

'.$this->translate('Helper settings: '.$hash).'

'.$res_html; + $db_path = $db->getFileName(); + $res_html = (new Forms($jail_name, $hash, $db_path))->generate(); + $res_html = '

'.$this->translate('Helper settings: '.$hash).'

'.$res_html; } -//echo json_encode(array('html'=>$res_html,'func'=>'fillTab')); -$included_result_array=array( - 'html'=>$res_html, - 'func'=>'fillTab' -); \ No newline at end of file +$included_result_array = [ + 'html' => $res_html, + 'func' => 'fillTab' +]; \ No newline at end of file diff --git a/public/pages/jailscontainers/helpers.php b/public/pages/jailscontainers/helpers.php index 51bd0f6b..cfa9fcb6 100644 --- a/public/pages/jailscontainers/helpers.php +++ b/public/pages/jailscontainers/helpers.php @@ -1,10 +1,8 @@ useDialogs(array( - 'helpers-add', -)); +$clonos->useDialogs(['helpers-add']); ?> -

translate('Helpers list for jail'),': ',$clonos->uri_chunks[1]; ?>

+

translate('Helpers list for jail'), ': ', $clonos->uri_chunks[1]; ?>

translate('Add helper'); ?>

diff --git a/public/pages/jailscontainers/ru.index.php b/public/pages/jailscontainers/ru.index.php index 8c53ca55..781592ab 100644 --- a/public/pages/jailscontainers/ru.index.php +++ b/public/pages/jailscontainers/ru.index.php @@ -1,19 +1,17 @@ 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' +]); ?>

Контейнеры:

diff --git a/public/pages/k8s/a.json.php b/public/pages/k8s/a.json.php index 46b14c38..8ab29f06 100644 --- a/public/pages/k8s/a.json.php +++ b/public/pages/k8s/a.json.php @@ -2,86 +2,83 @@ /* hardcode API ip. Change it later */ //$api_ip='https://bitclouds.convectix.com:1443'; -$api_ip='http://144.76.225.238'; +$api_ip = 'http://144.76.225.238'; function getSslPage($url) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_REFERER, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - $result = curl_exec($ch); - curl_close($ch); - return $result; -} -$file=getSslPage($api_ip.'/clusters'); - -$html=''; - -$res=json_decode($file,true); - -$nth=0; -$hres=$this->getTableChunk('k8slist','tbody'); - -if(!empty($res) && isset($res['clusters']))foreach($res['clusters'] as $cluster) -{ - $num=$nth & 1; - $html_tpl=$hres[1]; - $vars=array( - 'nth-num'=>'nth'.$num, - 'name'=>$cluster['name'], - 'cluster'=>$cluster['cluster'], - 'masters'=>$cluster['masters'], - 'workers'=>$cluster['workers'], - 'bhyves'=>join('; ',$cluster['bhyves']), - //'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('','',$html_tpl); - - $html.=$html_tpl; - - $nth++; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_REFERER, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $result = curl_exec($ch); + curl_close($ch); + return $result; } -$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); +$file = getSslPage($api_ip.'/clusters'); +$html = ''; +$res = json_decode($file, true); +$nth = 0; +$hres = $this->getTableChunk('k8slist','tbody'); + +if(!empty($res) && isset($res['clusters'])){ + foreach($res['clusters'] as $cluster){ + $num = $nth & 1; + $html_tpl = $hres[1]; + $vars = [ + 'nth-num' => 'nth'.$num, + 'name' => $cluster['name'], + 'cluster' => $cluster['cluster'], + 'masters' => $cluster['masters'], + 'workers' => $cluster['workers'], + 'bhyves' => join('; ',$cluster['bhyves']), + //'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('','',$html_tpl); + $html .= $html_tpl; + $nth++; + } } -$included_result_array=array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'k8slist', +$html_tpl_1 = str_replace(["\n","\r","\t"], '', $hres[1]); +if($hres !== false){ + $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); + } +} + +$included_result_array = [ + 'tbody' => $html, + 'error' => false, + 'func' => 'fillTable', + 'id' => 'k8slist', //'tasks'=>$tasks, - 'template'=>$html_tpl_1, + 'template' => $html_tpl_1, //'protected'=>$protected, -); \ No newline at end of file +]; \ No newline at end of file diff --git a/public/pages/k8s/en.index.php b/public/pages/k8s/en.index.php index 98fac70d..1366d239 100644 --- a/public/pages/k8s/en.index.php +++ b/public/pages/k8s/en.index.php @@ -1,16 +1,5 @@ uri_chunks[1])) -{ - include('helpers.php'); - return; -} -*/ - -$clonos->useDialogs(array( - 'k8s-new', -)); - +$clonos->useDialogs(['k8s-new']); ?>

K8S Сlusters:

Создать Kubernetes

diff --git a/public/pages/k8s/ru.index.php b/public/pages/k8s/ru.index.php index feb708ed..4dc26601 100644 --- a/public/pages/k8s/ru.index.php +++ b/public/pages/k8s/ru.index.php @@ -1,15 +1,5 @@ uri_chunks[1])) -{ - include('helpers.php'); - return; -} -*/ - -$clonos->useDialogs(array( - 'k8s-new', -)); +$clonos->useDialogs(['k8s-new']); /* Модуль kubernetes использует в работе преднастроенный образ Linux, который не входит в базовую установку ClonOS. diff --git a/public/pages/media/a.json.php b/public/pages/media/a.json.php index 0b235fa0..cb18f946 100644 --- a/public/pages/media/a.json.php +++ b/public/pages/media/a.json.php @@ -1,48 +1,37 @@ select('SELECT idx,name,path,jname FROM media where type="iso"', []); +$db = new Db('base', 'storage_media'); +$res = $db->select('SELECT idx,name,path,jname FROM media where type="iso"', []); -$html=''; -if($res!==false) -{ - $nth=0; - $num=$nth & 1; +$html = ''; +if($res !== false){ + $nth = 0; + $num = $nth & 1; - if(!empty($res)) foreach($res as $item) - { - $hres=$this->getTableChunk('mediaslist','tbody'); - if($hres!==false) - { - $html_tmp=$hres[1]; - $vars=array( - 'nth-num'=>'nth'.$num, - 'mediaid'=>$item['idx'], - 'medianame'=>$item['name'], - 'mediapath'=>$item['path'], - 'jname'=>$item['jname'], - '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('mediaslist','tbody'); + if($hres !== false){ + $html_tmp = $hres[1]; + $vars = [ + 'nth-num' => 'nth'.$num, + 'mediaid' => $item['idx'], + 'medianame' => $item['name'], + 'mediapath' => $item['path'], + 'jname' => $item['jname'], + 'deltitle' => ' title="'.$this->translate('Delete').'"' + ]; + + foreach($vars as $var => $val){ + $html_tmp = str_replace('#'.$var.'#', $val, $html_tmp); + } + $html .= $html_tmp; } } - - /* - echo json_encode(array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'mediaslist', - )); - */ - $included_result_array=array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'mediaslist', - ); + + $included_result_array = [ + 'tbody' => $html, + 'error' => false, + 'func' => 'fillTable', + 'id' => 'mediaslist' + ]; } \ No newline at end of file diff --git a/public/pages/nodes/a.json.php b/public/pages/nodes/a.json.php index e712f53e..8ecf7359 100644 --- a/public/pages/nodes/a.json.php +++ b/public/pages/nodes/a.json.php @@ -1,4 +1,4 @@ select("select group_concat(ip,'; ') from nodelist", []); // nodes.php -$included_result_array=array(); \ No newline at end of file +$included_result_array = []; \ No newline at end of file diff --git a/public/pages/overview/a.json.php b/public/pages/overview/a.json.php index bdaa53c6..9853e88b 100644 --- a/public/pages/overview/a.json.php +++ b/public/pages/overview/a.json.php @@ -1,62 +1,57 @@ 1, - 'online-nodes'=>1, - 'offline-nodes'=>0, - 'num-jails'=>0, - 'num-cores'=>0, - 'average'=>0, - 'sum-ram'=>0, - 'sum-storage'=>'Unknown', - 'error'=>false, - 'error_message'=>'', -); +$res_array = [ + 'num-nodes' => 1, + 'online-nodes' => 1, + 'offline-nodes' => 0, + 'num-jails' => 0, + 'num-cores' => 0, + 'average' => 0, + 'sum-ram' => 0, + 'sum-storage' => 'Unknown', + 'error' => false, + 'error_message' => '' +]; -$nodenames=array('local'); -$db=new Db('base','nodes'); -$nodes=$db->select('select nodename,ip from nodelist', []); -if(!empty($nodes))foreach($nodes as $node) -{ - $idle=$this->check_locktime($node['ip']); - if($idle==0) $res_array['offline-nodes']++; else $res_array['online-nodes']++; - - $nodenames[]=$node['nodename']; +$nodenames = ['local']; +$db = new Db('base','nodes'); +$nodes = $db->select('select nodename,ip from nodelist', []); +foreach($nodes as $node){ + $idle = $this->check_locktime($node['ip']); + if($idle == 0){ + $res_array['offline-nodes']++; + } else { + $res_array['online-nodes']++; + } + $nodenames[] = $node['nodename']; } - // extra+1: мы предполагаем, что сервер с WEB интерфейсом // также играет роль ноды - ее можно использовать полноценно со // всеми ресурсами -$res_array['num-nodes']=count($nodes)+1; +$res_array['num-nodes'] = count($nodes) + 1; -if(!empty($nodenames))foreach($nodenames as $name) -{ - $ndb=new Db('base',trim($name)); - if($ndb===false) - { - //echo json_encode(array('error'=>true,'error_message'=>$ndb->error_message)); - $included_result_array=array('error'=>true,'error_message'=>$ndb->error_message); +foreach($nodenames as $name){ + $ndb = new Db('base', trim($name)); + if($ndb->error){ + $included_result_array = ['error' => true, 'error_message' => $ndb->error_message]; exit; } - - $jcounts=$ndb->selectOne('SELECT COUNT(*) as count FROM jails;', []); - $res_array['num-jails']+=$jcounts['count']; - - $counts=$ndb->select('SELECT ncpu,physmem,cpufreq FROM local;', []); - if(!empty($counts))foreach($counts as $cel) - { - $res_array['num-cores']+=$cel['ncpu']; - $res_array['sum-ram']+=$cel['physmem']; - $res_array['average']+=$cel['cpufreq']; + + $jcounts = $ndb->selectOne('SELECT COUNT(*) as count FROM jails;', []); + $res_array['num-jails'] += $jcounts['count']; + + $counts = $ndb->select('SELECT ncpu,physmem,cpufreq FROM local;', []); + foreach($counts as $cel){ + $res_array['num-cores'] += $cel['ncpu']; + $res_array['sum-ram'] += $cel['physmem']; + $res_array['average'] += $cel['cpufreq']; } } -if($res_array['average']>0) -{ - $res_array['average']=$this->GhzConvert($res_array['average']/($res_array['num-nodes']?:1)); +if($res_array['average'] > 0){ + $res_array['average'] = $this->GhzConvert($res_array['average']/($res_array['num-nodes']?:1)); } -$res_array['sum-ram']=$this->fileSizeConvert((int) $res_array['sum-ram'],1024,true); +$res_array['sum-ram'] = $this->fileSizeConvert((int) $res_array['sum-ram'], 1024, true); -//echo json_encode($res_array); -$included_result_array=$res_array; \ No newline at end of file +$included_result_array = $res_array; \ No newline at end of file diff --git a/public/pages/sources/a.json.php b/public/pages/sources/a.json.php index 3738ca92..3290ab85 100644 --- a/public/pages/sources/a.json.php +++ b/public/pages/sources/a.json.php @@ -16,7 +16,7 @@ $hres_set = ($hres !== false); foreach($nodes as $node){ $db1 = new Db('base', $node['nodename']); - if($db1->error !== false){ + if(!$db1->error){ $bases = $db1->select("SELECT idx,name,platform,ver,rev,date FROM bsdsrc ORDER BY CAST(ver AS int)", []); $num = $nth & 1; diff --git a/public/pages/tasklog/a.json.php b/public/pages/tasklog/a.json.php index 5bdeb874..046e57ec 100644 --- a/public/pages/tasklog/a.json.php +++ b/public/pages/tasklog/a.json.php @@ -1,84 +1,67 @@ _user_info['username']; - -$db=new Db('base','cbsdtaskd'); - -$res=$db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner=? ORDER BY id DESC", array([$username])); - +$username = $this->_user_info['username']; +$db = new Db('base','cbsdtaskd'); +$res = $db->select("SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner=? ORDER BY id DESC", array([$username])); $html=''; -if($res!==false) -{ - $nth=0; - $num=$nth & 1; - if(!empty($res)) foreach($res as $item) - { +if(!$db->error){ + $nth = 0; + $num = $nth & 1; + + foreach($res as $item){ //Utils::clonos_syslog("tasklog: HTML"); - $hres=$this->getTableChunk('tasklog','tbody'); - if($hres!==false) - { - $html_tmp=$hres[1]; - $vars=array( - 'nth-num'=>'nth'.$num, - 'logid'=>$item['id'], - 'logcmd'=>$this->colorizeCmd($item['cmd']), - 'logstarttime'=>date("d.m.Y H:i",strtotime($item['st_time'])), - 'logendtime'=>date("d.m.Y H:i",strtotime($item['end_time'])), - 'logstatus'=>$item['status'], - 'logerrcode'=>$item['errcode'], - 'logsize'=>'0 B', - ); - - $logsize=0; - $logfile=$item['logfile']; - if(file_exists($logfile)) - { - $logsize=filesize($logfile); - $vars['logsize']=$this->fileSizeConvert($logsize,1024,true); + $hres = $this->getTableChunk('tasklog','tbody'); + if($hres !== false){ + $html_tmp = $hres[1]; + $vars = [ + 'nth-num' => 'nth'.$num, + 'logid' => $item['id'], + 'logcmd' => $this->colorizeCmd($item['cmd']), + 'logstarttime' => date("d.m.Y H:i", strtotime($item['st_time'])), + 'logendtime' => date("d.m.Y H:i", strtotime($item['end_time'])), + 'logstatus' => $item['status'], + 'logerrcode' => $item['errcode'], + 'logsize'=>'0 B' + ]; + + $logsize = 0; + $logfile = $item['logfile']; + if(file_exists($logfile)){ + $logsize = filesize($logfile); + $vars['logsize'] = $this->fileSizeConvert($logsize,1024,true); } - //if($logsize>0) $vars['logfile']=''.$vars['logfile'].''; - - $vars['buttvalue']=$this->translate('Open'); - - $disabled='disabled'; + $vars['buttvalue'] = $this->translate('Open'); + $disabled = 'disabled'; if($logsize>0) // && $logsize<204800 { $disabled=''; } - $vars['disabled']=$disabled; - - $status=''; - if($item['status']==1) $status=' progress'; - if($item['status']==2 && $item['errcode']==0) $status=' ok'; - if($item['status']==2 && $item['errcode']!=0) $status=' error'; - $vars['status']=$status; - - foreach($vars as $var=>$val) - $html_tmp=str_replace('#'.$var.'#',$val,$html_tmp); - - $html.=$html_tmp; + $vars['disabled'] = $disabled; + $status = ''; + if($item['status'] == 1) $status=' progress'; + if($item['status'] == 2 && $item['errcode'] == 0) $status=' ok'; + if($item['status'] == 2 && $item['errcode'] != 0) $status=' error'; + $vars['status'] = $status; + + foreach($vars as $var => $val){ + $html_tmp = str_replace('#'.$var.'#', $val, $html_tmp); + } + $html .= $html_tmp; //Utils::clonos_syslog("tasklog: HTML: ". $html); } - } else { - Utils::clonos_syslog("tasklog: \$res query empty result:". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;"); - } - /* - echo json_encode(array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'taskloglist', - )); - */ - $included_result_array=array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'taskloglist', - ); -} else { - Utils::clonos_syslog("tasklog: \$res query failed:". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;"); -} + } //else { + // Utils::clonos_syslog("tasklog: \$res query empty result:". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;"); + //} + + $included_result_array = [ + 'tbody' => $html, + 'error' => false, + 'func' => 'fillTable', + 'id' => 'taskloglist' + ]; +}// else { +// Utils::clonos_syslog("tasklog: \$res query failed:". "SELECT id,st_time,end_time,cmd,status,errcode,logfile FROM taskd WHERE owner='". $username."' ORDER BY id DESC;"); +//} diff --git a/public/pages/users/a.json.php b/public/pages/users/a.json.php index fd653c32..96db6ec1 100644 --- a/public/pages/users/a.json.php +++ b/public/pages/users/a.json.php @@ -12,53 +12,36 @@ date_joined TIMESTAMP DATE DEFAULT (datetime('now','localtime')) ); */ -$html=''; -$db=new Db('clonos'); -if($db!==false) -{ - $res=$db->select("select id,username,first_name,last_name,date_joined,last_login,is_active from auth_user order by date_joined desc", []); +$db = new Db('clonos'); +if(!$db->error){ + $res = $db->select("select id,username,first_name,last_name,date_joined,last_login,is_active from auth_user order by date_joined desc", []); } -$nth=0; -$hres=$this->getTableChunk('users','tbody'); +$html = ''; +$hres = $this->getTableChunk('users','tbody'); -$html_tpl=$hres[1]; -if(!empty($res))foreach($res as $r) -{ - $html_tpl1=$html_tpl; - $vars=array( - 'id'=>$r['id'], - 'login'=>$r['username'], - 'first_name'=>$r['first_name'], - 'last_name'=>$r['last_name'], - 'date_joined'=>$r['date_joined'], - 'last_login'=>$r['last_login'], - 'is_active'=>($r['is_active']==1)?'icon-ok':'', - 'edit_title'=>$this->translate('edit_title'), - 'delete_title'=>$this->translate('delete_title'), - ); - foreach($vars as $var=>$val) - $html_tpl1=str_replace('#'.$var.'#',$val,$html_tpl1); - $html.=$html_tpl1; +foreach($res as $r){ + $html_tpl1 = $hres[1]; + $vars = [ + 'id' => $r['id'], + 'login' => $r['username'], + 'first_name' => $r['first_name'], + 'last_name' => $r['last_name'], + 'date_joined' => $r['date_joined'], + 'last_login' => $r['last_login'], + 'is_active' => ($r['is_active']==1) ? 'icon-ok' : '', + 'edit_title' => $this->translate('edit_title'), + 'delete_title' => $this->translate('delete_title'), + ]; + foreach($vars as $var => $val){ + $html_tpl1 = str_replace('#'.$var.'#', $val, $html_tpl1); + } + $html .= $html_tpl1; } - -$html=str_replace(array("\n","\r","\t"),'',$html); - -/* -echo json_encode(array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'userslist', - //'tasks'=>$tasks, - //'template'=>$html_tpl_1, - //'protected'=>$protected, -)); -*/ -$included_result_array=array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'userslist', -); \ No newline at end of file +$included_result_array = [ + 'tbody' => str_replace(["\n","\r","\t"], '', $html), + 'error' => false, + 'func' => 'fillTable', + 'id' => 'userslist' +]; \ No newline at end of file diff --git a/public/pages/users/en.index.php b/public/pages/users/en.index.php index 3d40d19a..7644a604 100644 --- a/public/pages/users/en.index.php +++ b/public/pages/users/en.index.php @@ -1,7 +1,5 @@ useDialogs(array( - 'users-new', -)); +$clonos->useDialogs(['users-new']); ?>

User management

diff --git a/public/pages/users/ru.index.php b/public/pages/users/ru.index.php index 1bc71564..44b87ff0 100644 --- a/public/pages/users/ru.index.php +++ b/public/pages/users/ru.index.php @@ -1,7 +1,5 @@ useDialogs(array( - 'users-new', -)); +$clonos->useDialogs(['users-new']); ?>

Пользователи CBSD

diff --git a/public/pages/vm_packages/a.json.php b/public/pages/vm_packages/a.json.php index 1fe4517a..3b62e9fd 100644 --- a/public/pages/vm_packages/a.json.php +++ b/public/pages/vm_packages/a.json.php @@ -1,49 +1,36 @@ select("select id,name,description,pkg_vm_ram,pkg_vm_disk,pkg_vm_cpus,owner from vmpackages order by name asc", []); +$db = new Db('base','local'); +if(!$db->error){ + $res = $db->select("select id,name,description,pkg_vm_ram,pkg_vm_disk,pkg_vm_cpus,owner from vmpackages order by name asc", []); } -$nth=0; -$hres=$this->getTableChunk('packages','tbody'); +$html = ''; +$hres = $this->getTableChunk('packages','tbody'); +$html_tpl = $hres[1]; -$html_tpl=$hres[1]; -if(!empty($res))foreach($res as $r) -{ - $html_tpl1=$html_tpl; - $vars=array( - 'id'=>$r['id'], - 'name'=>$r['name'], - 'description'=>$r['description'], - 'pkg_vm_ram'=>$r['pkg_vm_ram'], - 'pkg_vm_disk'=>$r['pkg_vm_disk'], - 'pkg_vm_cpus'=>$r['pkg_vm_cpus'], - 'owner'=>$r['owner'], - 'edit_title'=>$this->translate('edit_title'), - 'delete_title'=>$this->translate('delete_title'), - ); - foreach($vars as $var=>$val) - $html_tpl1=str_replace('#'.$var.'#',$val,$html_tpl1); - $html.=$html_tpl1; +foreach($res as $r){ + $html_tpl1 = $html_tpl; + $vars = [ + 'id' => $r['id'], + 'name' => $r['name'], + 'description' => $r['description'], + 'pkg_vm_ram' => $r['pkg_vm_ram'], + 'pkg_vm_disk' => $r['pkg_vm_disk'], + 'pkg_vm_cpus' => $r['pkg_vm_cpus'], + 'owner' => $r['owner'], + 'edit_title' => $this->translate('edit_title'), + 'delete_title' => $this->translate('delete_title') + ]; + foreach($vars as $var => $val){ + $html_tpl1 = str_replace('#'.$var.'#', $val, $html_tpl1); + } + $html .= $html_tpl1; } - -$html=str_replace(array("\n","\r","\t"),'',$html); - -/* -echo json_encode(array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'packageslist', -)); -*/ -$included_result_array=array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'packageslist', -); \ No newline at end of file +$included_result_array = [ + 'tbody' => str_replace(["\n","\r","\t"], '', $html), + 'error' => false, + 'func' => 'fillTable', + 'id' => 'packageslist' +]; \ No newline at end of file diff --git a/public/pages/vpnet/a.json.php b/public/pages/vpnet/a.json.php index 16c4ccac..f3aa0624 100644 --- a/public/pages/vpnet/a.json.php +++ b/public/pages/vpnet/a.json.php @@ -1,47 +1,36 @@ select('SELECT idx,name,vpnet FROM vpnet', []); +$db = new Db('base','vpnet'); +$res = $db->select('SELECT idx,name,vpnet FROM vpnet', []); +$html = ''; -$html=''; -if($res!==false) -{ - $nth=0; - $num=$nth & 1; +if(!$db->error){ + $nth = 0; + $num = $nth & 1; - if(!empty($res)) foreach($res as $item) - { - $hres=$this->getTableChunk('vpnetslist','tbody'); - if($hres!==false) - { - $html_tmp=$hres[1]; - $vars=array( - 'nth-num'=>'nth'.$num, - 'netid'=>$item['idx'], - 'netname'=>$item['name'], - 'network'=>$item['vpnet'], - '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('vpnetslist','tbody'); + if($hres !== false){ + $html_tmp = $hres[1]; + $vars = [ + 'nth-num' => 'nth'.$num, + 'netid' => $item['idx'], + 'netname' => $item['name'], + 'network'=> $item['vpnet'], + 'deltitle' => ' title="'.$this->translate('Delete').'"' + ]; + + foreach($vars as $var => $val){ + $html_tmp = str_replace('#'.$var.'#', $val, $html_tmp); + } + $html .= $html_tmp; } } - /* - echo json_encode(array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'vpnetslist', - )); - */ - $included_result_array=array( - 'tbody'=>$html, - 'error'=>false, - 'func'=>'fillTable', - 'id'=>'vpnetslist', - ); + $included_result_array = [ + 'tbody' => $html, + 'error' => false, + 'func' => 'fillTable', + 'id' => 'vpnetslist' + ]; } \ No newline at end of file diff --git a/public/pages/vpnet/en.index.php b/public/pages/vpnet/en.index.php index ead0492c..28902b27 100644 --- a/public/pages/vpnet/en.index.php +++ b/public/pages/vpnet/en.index.php @@ -1,7 +1,5 @@ useDialogs(array( - 'vpnet', -)); +$clonos->useDialogs(['vpnet']); ?>

Subnet list

diff --git a/public/pages/vpnet/ru.index.php b/public/pages/vpnet/ru.index.php index 16307660..0360e0a2 100644 --- a/public/pages/vpnet/ru.index.php +++ b/public/pages/vpnet/ru.index.php @@ -1,7 +1,5 @@ useDialogs(array( - 'vpnet', -)); +$clonos->useDialogs(['vpnet']); ?>

Список подсетей