From 2d989cdff1372605a36ee13041e46c656bbfcc4d Mon Sep 17 00:00:00 2001 From: Momchil Bozhinov Date: Tue, 16 Feb 2021 13:03:16 +0200 Subject: [PATCH] * fixes all around --- php/clonos.php | 45 +++++++++---------- php/config.php | 2 + php/db.php | 3 +- public/pages/authkey/a.json.php | 2 +- public/pages/bases/a.json.php | 4 +- public/pages/bhyvevms/a.json.php | 4 +- public/pages/imported/a.json.php | 2 +- public/pages/instance_jail/a.json.php | 10 +++-- public/pages/instance_jail/helpers.php | 4 +- public/pages/jailscontainers/a.json.php | 4 +- public/pages/jailscontainers/helpers.json.php | 4 +- public/pages/media/a.json.php | 2 +- public/pages/nodes/a.json.php | 2 +- public/pages/overview/a.json.php | 6 +-- public/pages/sources/a.json.php | 4 +- public/pages/tasklog/a.json.php | 2 +- public/pages/users/a.json.php | 2 +- public/pages/vm_packages/a.json.php | 2 +- public/pages/vpnet/a.json.php | 2 +- public/upload.php | 6 +-- 20 files changed, 59 insertions(+), 53 deletions(-) diff --git a/php/clonos.php b/php/clonos.php index 566537cd..347ccb7c 100644 --- a/php/clonos.php +++ b/php/clonos.php @@ -91,7 +91,7 @@ class ClonOS { } $this->config=new Config(); - + /* determine lang */ if(!array_key_exists($this->language, $this->config->languages)) $this->language='en'; include($this->realpath_public.'/lang/'.$this->language.'.php'); @@ -1564,7 +1564,7 @@ class ClonOS { $res=$db->selectOne('SELECT * FROM media WHERE idx=?', array([(int)$this->form['media_id'], PDO::PARAM_INT])); if($res===false || empty($res)) return array('error'=>true,'res'=>print_r($res,true)); - //if($res['jname']=='-') // если медиа отвязана, то Ð¿Ñ€Ð¾Ñ + //if($res['jname']=='-') // если медиа отвязана, то про $res=CBSD::run( 'media mode=remove name="%s" path="%s" jname="%s" type="%s"', //.$res['name'] @@ -1664,7 +1664,7 @@ class ClonOS { $stable_arr=array('release','stable'); $stable_num=strlen(intval($ver))fillRepoTr($id); $html=$res['html']; @@ -1696,12 +1696,12 @@ class ClonOS { if($db->isConnected()){ if($bsdsrc){ $res=$db->selectOne("SELECT idx,platform,ver FROM bsdsrc WHERE idx=?", array([(int)$id, PDO::PARAM_INT])); - $res['name']='—'; - $res['arch']='—'; - $res['targetarch']='—'; + $res['name']='—'; + $res['arch']='—'; + $res['targetarch']='—'; $res['stable']=strlen(intval($res['ver']))selectOne("SELECT idx,platform,name,arch,targetarch,ver,stable,elf,date FROM bsdbase WHERE ver=?", array([(int)$id, PDO::PARAM_INT])); } @@ -1753,7 +1753,7 @@ class ClonOS { $stable_num=strlen(intval($ver))'nth0', @@ -1761,12 +1761,12 @@ class ClonOS { 'node'=>'local', 'ver'=>$ver, 'name'=>'base', - 'platform'=>'—', - 'arch'=>'—', - 'targetarch'=>'—', + 'platform'=>'—', + 'arch'=>'—', + 'targetarch'=>'—', 'stable'=>$stable, - 'elf'=>'—', - 'date'=>'—', + 'elf'=>'—', + 'date'=>'—', 'maintenance'=>' busy', 'protitle'=>$this->translate('Delete'), ); @@ -2021,11 +2021,9 @@ class ClonOS { return $arr; } - function ccmd_getFreeCname() - { + function ccmd_getFreeCname(){ $arr=array(); - $add_cmd=' default_jailname=kube'; - $res=$this->cbsd_cmd("freejname".$add_cmd); + $res=$this->CBSD::run("freejname default_jailname=kube", []); if($res['error']){ $arr['error']=true; $arr['error_message']=$err['error_message']; @@ -2036,8 +2034,7 @@ class ClonOS { return $arr; } - function ccmd_k8sCreate() - { + function ccmd_k8sCreate(){ $form=$this->form; $res=array(); $ass_arr=array( @@ -2075,6 +2072,7 @@ class ClonOS { { if($form['pv_enable']=='on') $res['pv_enable']="1"; } + $res['kubelet_master']="0"; if(isset($form['kubelet_master'])) { @@ -2100,14 +2098,15 @@ class ClonOS { return array('error'=>'true','errorMessage'=>'something wrong...'); } } - + function postCurl($url,$vars=false) { if($vars===false) return array('error'=>true,'errorMessage'=>'something wrong...'); - + $txt_vars=json_encode($vars); //$txt_vars=http_build_query($vars); + $ch = curl_init($url); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -2664,7 +2663,7 @@ class ClonOS { function ccmd_imageExport(){ // cbsd jexport jname=XXX dstdir= $jname=$this->form['id']; - if(empty($jname)) $this->messageError('Jname is incorrect in export command! Is «'.$jname.'».'); + if(empty($jname)) $this->messageError('Jname is incorrect in export command! Is «'.$jname.'».'); return CBSD::run( 'task owner=%s mode=new {cbsd_loc} jexport gensize=1 jname=%s dstdir=%s', diff --git a/php/config.php b/php/config.php index 55da2671..edb7ae3b 100644 --- a/php/config.php +++ b/php/config.php @@ -1,5 +1,7 @@ prep_connect($place, $database); if(is_null($file_name) || !file_exists($file_name)){ @@ -38,6 +38,7 @@ class Db { $this->error=true; $this->error_message=$e->getMessage(); //'DB Error'; } + } private function prep_connect($place, $database){ diff --git a/public/pages/authkey/a.json.php b/public/pages/authkey/a.json.php index 3ab3a0f9..cc4cd2cd 100644 --- a/public/pages/authkey/a.json.php +++ b/public/pages/authkey/a.json.php @@ -1,7 +1,7 @@ select('SELECT idx,name,authkey FROM authkey;'); +$res=$db->select('SELECT idx,name,authkey FROM authkey;', []); $html=''; if($res!==false) diff --git a/public/pages/bases/a.json.php b/public/pages/bases/a.json.php index f2abbbec..bab8a334 100644 --- a/public/pages/bases/a.json.php +++ b/public/pages/bases/a.json.php @@ -2,7 +2,7 @@ $html=''; $db=new Db('base','nodes'); -$nodes=$db->select('select nodename,ip from nodelist order by nodename desc'); +$nodes=$db->select('select nodename,ip from nodelist order by nodename desc', []); $nodes[]=array('nodename'=>'local'); $nodes=array_reverse($nodes); @@ -14,7 +14,7 @@ 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)"); + $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) diff --git a/public/pages/bhyvevms/a.json.php b/public/pages/bhyvevms/a.json.php index e250ff52..0ff1ee91 100644 --- a/public/pages/bhyvevms/a.json.php +++ b/public/pages/bhyvevms/a.json.php @@ -4,7 +4,7 @@ $html=''; //if($hres!==false) $thead=$hres[1]; $db=new Db('base','nodes'); -$res=$db->select('select nodename from nodelist'); +$res=$db->select('select nodename from nodelist', []); $nodes=array('local'); if(!empty($res))foreach($res as $val) $nodes[]=$val['nodename']; @@ -19,7 +19,7 @@ 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;"); + $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; diff --git a/public/pages/imported/a.json.php b/public/pages/imported/a.json.php index d736aef1..0544cf19 100644 --- a/public/pages/imported/a.json.php +++ b/public/pages/imported/a.json.php @@ -57,7 +57,7 @@ if(!empty($images)) foreach($images as $item) $filesize=$this->fileSizeConvert($size,1024,true); $query="select count(*) as busy from taskd where status<2 and jname='${item['jname']}'"; - $busy=$this->_db_tasks->selectAssoc($query); + $busy=$this->_db_tasks->selectOne($query, []); $jstatus=''; $jbusy=''; if($busy['busy']==1) diff --git a/public/pages/instance_jail/a.json.php b/public/pages/instance_jail/a.json.php index e69cc963..3676a167 100644 --- a/public/pages/instance_jail/a.json.php +++ b/public/pages/instance_jail/a.json.php @@ -5,6 +5,8 @@ if(!empty($this->_vars['hash'])) return; } +require_once("../php/cbsd.php"); + $sys_helpers=array(); // 'network','cbsd','bhyvenet','general','zfsinstall','userspw','natcfg','jconstruct', //); @@ -15,7 +17,7 @@ if($db!==false) $query="select module from sys_helpers_list"; if(!$db->error) { - $res=$db->select($query); + $res=$db->select($query, []); if(!empty($res)) { foreach($res as $r) $sys_helpers[]=$r['module']; @@ -26,7 +28,7 @@ if($db!==false) $html=''; $arr=array(); -$res=$this->cbsd_cmd('forms header=0'); +$res=CBSD::run('forms header=0', []); if($res['retval']==0) { $empty_logo='/images/logo/empty.png'; @@ -46,14 +48,14 @@ if($res['retval']==0) $file_name=$db->getFileName(); if(!file_exists($file_name)) { - $res=$this->cbsd_cmd('forms module='.$item.' inter=0'); + $res=CBSD::run('forms module=%s inter=0',[$item]); if($res['retval']==0) { $db=new Db('helper',$item); } } } - if($db!==false && !$db->error) $res=$db->selectAssoc("select longdesc from system limit 1"); + if($db!==false && !$db->error) $res=$db->selectOne("select longdesc from system", []); if(isset($res['longdesc'])) $description=$res['longdesc']; else $description=$this->translate('no data').'… ('.$file_name.')'; }else{ diff --git a/public/pages/instance_jail/helpers.php b/public/pages/instance_jail/helpers.php index 91ba8710..78f1fe66 100644 --- a/public/pages/instance_jail/helpers.php +++ b/public/pages/instance_jail/helpers.php @@ -1,12 +1,14 @@ url_hash; //=preg_replace('/^#/','',$this->_vars['hash']); $db_path=false; if(!isset($this->_vars['db_path'])) { //$db_path=$this->_vars['db_path']; - $res=$this->cbsd_cmd('make_tmp_helper module='.$hash); + $res=CBSD::run('make_tmp_helper module=%s', [$hash]); if($res['retval']==0) { $db_path=$res['message']; diff --git a/public/pages/jailscontainers/a.json.php b/public/pages/jailscontainers/a.json.php index 30f663f5..2e6de2e9 100644 --- a/public/pages/jailscontainers/a.json.php +++ b/public/pages/jailscontainers/a.json.php @@ -13,7 +13,7 @@ $html=''; //if($hres!==false) $thead=$hres[1]; $db=new Db('base','nodes'); -$res=$db->select('select nodename from nodelist'); +$res=$db->select('select nodename from nodelist', []); $nodes=array('local'); if(!empty($res))foreach($res as $val) $nodes[]=$val['nodename']; @@ -28,7 +28,7 @@ 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;"); + $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; diff --git a/public/pages/jailscontainers/helpers.json.php b/public/pages/jailscontainers/helpers.json.php index 56323b59..61b3f367 100644 --- a/public/pages/jailscontainers/helpers.json.php +++ b/public/pages/jailscontainers/helpers.json.php @@ -10,7 +10,7 @@ if(empty($hash)) $query="select module from jails_helpers_list"; if(!$db->error) { - $res=$db->select($query); + $res=$db->select($query, []); if(!empty($res)) { foreach($res as $r) $jails_helpers[]=$r['module']; @@ -24,7 +24,7 @@ if(empty($hash)) $db=new Db('helper',array('jname'=>$jail_name,'helper'=>$helper)); if(!$db->error) // !error — значит хелпер установлен { - $res=$db->selectAssoc("select longdesc from system limit 1"); + $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{ diff --git a/public/pages/media/a.json.php b/public/pages/media/a.json.php index 4d60f4e0..0b235fa0 100644 --- a/public/pages/media/a.json.php +++ b/public/pages/media/a.json.php @@ -1,7 +1,7 @@ select('SELECT idx,name,path,jname FROM media where type="iso"'); +$res=$db->select('SELECT idx,name,path,jname FROM media where type="iso"', []); $html=''; if($res!==false) diff --git a/public/pages/nodes/a.json.php b/public/pages/nodes/a.json.php index fd1390b6..e712f53e 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 +//$ips=$db1->select("select group_concat(ip,'; ') from nodelist", []); // nodes.php $included_result_array=array(); \ No newline at end of file diff --git a/public/pages/overview/a.json.php b/public/pages/overview/a.json.php index 0c7f2163..bdaa53c6 100644 --- a/public/pages/overview/a.json.php +++ b/public/pages/overview/a.json.php @@ -14,7 +14,7 @@ $res_array=array( $nodenames=array('local'); $db=new Db('base','nodes'); -$nodes=$db->select('select nodename,ip from nodelist'); +$nodes=$db->select('select nodename,ip from nodelist', []); if(!empty($nodes))foreach($nodes as $node) { $idle=$this->check_locktime($node['ip']); @@ -39,10 +39,10 @@ if(!empty($nodenames))foreach($nodenames as $name) exit; } - $jcounts=$ndb->selectAssoc('SELECT COUNT(*) as count FROM jails;'); + $jcounts=$ndb->selectOne('SELECT COUNT(*) as count FROM jails;', []); $res_array['num-jails']+=$jcounts['count']; - $counts=$ndb->select('SELECT ncpu,physmem,cpufreq FROM local;'); + $counts=$ndb->select('SELECT ncpu,physmem,cpufreq FROM local;', []); if(!empty($counts))foreach($counts as $cel) { $res_array['num-cores']+=$cel['ncpu']; diff --git a/public/pages/sources/a.json.php b/public/pages/sources/a.json.php index f1b018da..fbbac912 100644 --- a/public/pages/sources/a.json.php +++ b/public/pages/sources/a.json.php @@ -2,7 +2,7 @@ $html=''; $db=new Db('base','nodes'); -$nodes=$db->select('select nodename,ip from nodelist order by nodename desc'); +$nodes=$db->select('select nodename,ip from nodelist order by nodename desc', []); $nodes[]=array('nodename'=>'local'); $nodes=array_reverse($nodes); @@ -14,7 +14,7 @@ if(!empty($nodes))foreach($nodes as $node) $db1=new Db('base',$node['nodename']); if($db1!==false) { - $bases=$db1->select("SELECT idx,name,platform,ver,rev,date FROM bsdsrc ORDER BY CAST(ver AS int)"); + $bases=$db1->select("SELECT idx,name,platform,ver,rev,date FROM bsdsrc ORDER BY CAST(ver AS int)", []); $num=$nth & 1; if(!empty($bases)) foreach($bases as $base) diff --git a/public/pages/tasklog/a.json.php b/public/pages/tasklog/a.json.php index c20abccc..c51e3907 100644 --- a/public/pages/tasklog/a.json.php +++ b/public/pages/tasklog/a.json.php @@ -3,7 +3,7 @@ $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='${username}' ORDER BY id DESC"); +$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) diff --git a/public/pages/users/a.json.php b/public/pages/users/a.json.php index 94bb8256..fd653c32 100644 --- a/public/pages/users/a.json.php +++ b/public/pages/users/a.json.php @@ -16,7 +16,7 @@ $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"); + $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; diff --git a/public/pages/vm_packages/a.json.php b/public/pages/vm_packages/a.json.php index 62e71640..1fe4517a 100644 --- a/public/pages/vm_packages/a.json.php +++ b/public/pages/vm_packages/a.json.php @@ -4,7 +4,7 @@ $html=''; $db=new Db('base','local'); if($db!==false) { - $res=$db->select("select id,name,description,pkg_vm_ram,pkg_vm_disk,pkg_vm_cpus,owner from vmpackages order by name asc"); + $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; diff --git a/public/pages/vpnet/a.json.php b/public/pages/vpnet/a.json.php index 752686fe..16c4ccac 100644 --- a/public/pages/vpnet/a.json.php +++ b/public/pages/vpnet/a.json.php @@ -1,7 +1,7 @@ select('SELECT idx,name,vpnet FROM vpnet'); +$res=$db->select('SELECT idx,name,vpnet FROM vpnet', []); $html=''; if($res!==false) diff --git a/public/upload.php b/public/upload.php index 68c3d0c7..ba88a7c3 100644 --- a/public/upload.php +++ b/public/upload.php @@ -1,6 +1,8 @@ getUserName(); - $command='task owner='.$username.' mode=new /usr/local/bin/cbsd jimport jname='.$filename.' inter=0'; - $res=$clonos->cbsd_cmd($command); + $res=CBSD::run('task owner=%s mode=new /usr/local/bin/cbsd jimport jname=%s' inter=0', [$clonos->getUserName(), $filename]); } }else{ $status = 'Upload Fail: Unknown error occurred!';