From ddff7b3ba505843bf679da753fa7ce0d4b7da383 Mon Sep 17 00:00:00 2001 From: olevole Date: Sat, 28 Jan 2017 21:43:33 +0300 Subject: [PATCH] wip --- php/clonos.php | 92 ++++++++++++++++++-- public/css/styles.css | 12 +-- public/dialogs/bhyve-new.php | 18 ++-- public/dialogs/jail-settings.php | 8 +- public/js/clonos.js | 34 +++++++- public/pages/bhyvevms/a.json.php | 2 + public/pages/bhyvevms/bhyveslist.table | 4 +- public/pages/jailscontainers/a.json.php | 2 + public/pages/jailscontainers/jailslist.table | 2 +- public/pages/sqlite/en.index.php | 2 +- public/pages/sqlite/ru.index.php | 2 +- 11 files changed, 145 insertions(+), 33 deletions(-) diff --git a/php/clonos.php b/php/clonos.php index ceffea9f..4e7821ce 100644 --- a/php/clonos.php +++ b/php/clonos.php @@ -147,6 +147,12 @@ class ClonOS case 'bhyveAdd': echo json_encode($this->bhyveAdd()); return;break; + case 'bhyveEdit': + echo json_encode($this->bhyveEdit()); + return;break; + case 'bhyveEditVars': + echo json_encode($this->bhyveEditVars()); + return;break; case 'bhyveObtain': echo json_encode($this->bhyveObtain()); return;break; @@ -762,12 +768,27 @@ class ClonOS function jailEdit() { $form=$this->_vars['form_data']; - print_r($form); + $str=array(); + $jname=$form['jname']; + $arr=array('host_hostname','ip4_addr','allow_mount','interface','mount_ports','astart','vnet'); + foreach($arr as $a) + { + if(isset($form[$a])) + { + $val=$form[$a]; + if($val=='on') $val=1; + $str[]=$a.'='.$val; + }else{ + $str[]=$a.'=0'; + } + } - - //cbsd jset jname=XXX ip4_addr=192.168.0.1 astart=1 baserw=0 - //$res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd jstart inter=0 jname='.$name); + $cmd='jset jname='.$jname.' '.join(' ',$str); + $res=$this->cbsd_cmd($cmd); + $res['mode']='jailEdit'; + $res['form']=$form; + return $res; } function jailStart($name) @@ -791,6 +812,62 @@ class ClonOS return $res; } + function bhyveEditVars() + { + $form=$this->_vars['form_data']; + if(!isset($form['jail_id'])) return array('error'=>true,'error_message'=>'Bad jail id!'); + + $db=new Db('base','local'); + if($db!==false) + { + $query="SELECT b.jname as vm_name,vm_cpus,vm_ram,vm_vnc_port as vnc_port,interface FROM bhyve as b inner join jails as j on b.jname=j.jname and b.jname='{$form['jail_id']}';"; + //$query="SELECT jname as vm_name,vm_cpus,vm_ram,vm_vnc_port as vnc_port FROM bhyve WHERE jname='{$form['jail_id']}';"; + $res['vars']=$db->selectAssoc($query); + + $res['vars']['vm_ram']=$this->fileSizeConvert($res['vars']['vm_ram']); + } + + $res['error']=false; + $res['dialog']=$form['dialog']; + $res['jail_id']=$form['jail_id']; + return $res; + } + + function bhyveEdit() + { + $form=$this->_vars['form_data']; + + $str=array(); + $jname=$form['jname']; + + $ram=$form['vm_ram']; + $ram_tmp=$ram; + $ram=str_replace(' ','',$ram); + $ram=str_ireplace('mb','m',$ram); + $ram=str_ireplace('gb','g',$ram); + $form['vm_ram']=$ram; + + $arr=array('vm_cpus','vm_ram','vnc_port','interface'); + foreach($arr as $a) + { + if(isset($form[$a])) + { + $val=$form[$a]; + if($val=='on') $val=1; + $str[]=$a.'='.$val; + }else{ + $str[]=$a.'=0'; + } + } + + $form['vm_ram']=$ram_tmp; + + $cmd='bset jname='.$jname.' '.join(' ',$str); + $res=$this->cbsd_cmd($cmd); + $res['mode']='bhyveEdit'; + $res['form']=$form; + return $res; + } function bhyveAdd() { $form=$this->_vars['form_data']; @@ -1272,8 +1349,8 @@ class ClonOS $fp=fopen($log_file,'r'); if($fp) { - fseek($fp,-204800,SEEK_END); - $html='Last 2 KB of big file data:
'.fread($fp,204800); + fseek($fp,-1000,SEEK_END); //204800 + $html='Last 1000 Bytes of big file data:
'.fread($fp,1000); //204800 } fclose($fp); } @@ -1345,7 +1422,8 @@ class ClonOS $res=$this->cbsd_cmd("vm_vncwss jname={$jname} permit={$this->_client_ip}"); $res=$this->_db_local->selectAssoc('select nodeip from local'); $nodeip=$res['nodeip']; - if(strlen($nodeip)<10) $nodeip='127.0.0.1'; + // need for IPv4/IPv6 regex here, instead of strlen + if(strlen($nodeip)<7) $nodeip='127.0.0.1'; header('Location: http://'.$nodeip.':6080/vnc_auto.html?host='.$nodeip.'&port=6080'); exit; } diff --git a/public/css/styles.css b/public/css/styles.css index dbc10e2e..314e89fc 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -614,16 +614,12 @@ dialog::backdrop, -webkit-backdrop-filter:blur(5px); z-index:1000; } -dialog.new h1 .edit, -dialog.new .buttons .edit, -dialog.edit h1 .new, -dialog.edit .buttons .new { +dialog.new .edit, +dialog.edit .new { display:none; } -dialog.new h1 .new, -dialog.new .buttons .new, -dialog.edit h1 .edit, -dialog.edit .buttons .edit { +dialog.new .new, +dialog.edit .edit { display:inline-block; } .dialog-close:before { diff --git a/public/dialogs/bhyve-new.php b/public/dialogs/bhyve-new.php index 2f15695c..c00448d8 100644 --- a/public/dialogs/bhyve-new.php +++ b/public/dialogs/bhyve-new.php @@ -6,11 +6,14 @@ err_messages={ }; -

translate('Create Virtual Machine');?>

+

+ translate('Create Virtual Machine');?> + translate('Edit Virtual Machine');?> +

translate('Virtual Machine Settings');?>

-

+

translate('VM OS profile');?>: +

-

+

translate('VM Image size');?>: - +

translate('VM CPUs');?>: @@ -30,7 +33,7 @@ err_messages={

translate('VM RAM');?>: - +

translate('VNC PORT');?>: @@ -50,7 +53,8 @@ err_messages={

- + +
diff --git a/public/dialogs/jail-settings.php b/public/dialogs/jail-settings.php index 00e255a6..e7ef856a 100644 --- a/public/dialogs/jail-settings.php +++ b/public/dialogs/jail-settings.php @@ -17,7 +17,7 @@ err_messages={

translate('Jail name');?>: - +

translate('Hostname');?> (FQDN): @@ -30,11 +30,11 @@ err_messages={ translate('IP address');?>:

-

+

translate('Root password');?>:

-

+

translate('Root password (again)');?>:

@@ -53,7 +53,7 @@ err_messages={

-

+

translate('Enabled services');?>: diff --git a/public/js/clonos.js b/public/js/clonos.js index 8eb74720..fefb9d39 100644 --- a/public/js/clonos.js +++ b/public/js/clonos.js @@ -169,6 +169,8 @@ var clonos={ $(dlg).removeClass('edit').addClass('new'); $(dlg).prop('mode','new'); } + $('dialog#'+id+'.edit .edit-disable, dialog#'+id+'.new .new-disable').prop('disabled',true); + $('dialog#'+id+'.edit .new-disable, dialog#'+id+'.new .edit-disable').prop('disabled',false); if($('span.close-but',dlg).length==0) $('h1',dlg).before('×'); @@ -289,6 +291,7 @@ var clonos={ this.tmp_jail_info[jid]={}; this.tmp_jail_info[jid]['runasap']=$('#astart-id:checked').length>0?1:0; var posts=$('form#jailSettings').serializeArray(); + if(mode=='edit') posts.push({'name':'jname','value':jid}); var jmode=(mode=='edit'?'jailEdit':'jailAdd'); this.loadData(jmode,$.proxy(this.onJailAdd,this),posts); } @@ -297,7 +300,7 @@ var clonos={ var jid=$('form#bhyveSettings input[name="vm_name"]').val(); if(typeof this.trids!='undefined' && this.trids.length>0) { - if(this.trids.indexOf(jid)!=-1) + if(mode!='edit' && this.trids.indexOf(jid)!=-1) { var inp=$('form#bhyveSettings input[name="vm_name"]').get(0); inp.setCustomValidity(this.translate('This name is already exists!')); @@ -308,7 +311,9 @@ var clonos={ this.tmp_jail_info[jid]={}; this.tmp_jail_info[jid]['runasap']=0; // исправить на реальные данные! var posts=$('form#bhyveSettings').serializeArray(); - this.loadData('bhyveAdd',$.proxy(this.onJailAdd,this),posts); + if(mode=='edit') posts.push({'name':'jname','value':jid}); + var bmode=(mode=='edit'?'bhyveEdit':'bhyveAdd'); + this.loadData(bmode,$.proxy(this.onJailAdd,this),posts); } if(id=='bhyve-obtain' && $('form#bhyveObtSettings').length>0) { @@ -345,6 +350,22 @@ var clonos={ } }, + fillFormDataOnChange:function(data) + { + if(typeof data.form!='undefined') + { + if(typeof data.form['jname']!='undefined') + { + var jname=data.form['jname']; + delete(data.form['jname']); + for(k in data.form) + { + var v=data.form[k]; + $('tr#'+jname+' td.'+k).html(v); + } + } + } + }, onJailAdd:function(data) { try{ @@ -357,6 +378,11 @@ var clonos={ { switch(data.mode) { + case 'jailEdit': + case 'bhyveEdit': + this.dialogClose(); + this.fillFormDataOnChange(data); + return;break; case 'jailAdd': var table='jailslist'; var operation='jcreate'; @@ -1502,6 +1528,10 @@ var clonos={ var dialog='jail-settings'; var mode='jailEditVars'; break; + case 'bhyveslist': + var dialog='bhyve-new'; + var mode='bhyveEditVars'; + break; } this.DDMenuClose(); diff --git a/public/pages/bhyvevms/a.json.php b/public/pages/bhyvevms/a.json.php index c08a91fa..59074581 100644 --- a/public/pages/bhyvevms/a.json.php +++ b/public/pages/bhyvevms/a.json.php @@ -55,6 +55,8 @@ if(!empty($nodes))foreach($nodes as $node) 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; } diff --git a/public/pages/bhyvevms/bhyveslist.table b/public/pages/bhyvevms/bhyveslist.table index d4d9d4f8..e98d2dd2 100644 --- a/public/pages/bhyvevms/bhyveslist.table +++ b/public/pages/bhyvevms/bhyveslist.table @@ -2,8 +2,8 @@ #node# #jname# - #vm_ram# - #vm_cpus# + #vm_ram# + #vm_cpus# #vm_os_type# #vm_status# diff --git a/public/pages/jailscontainers/a.json.php b/public/pages/jailscontainers/a.json.php index c1762c0e..c4c5edb6 100644 --- a/public/pages/jailscontainers/a.json.php +++ b/public/pages/jailscontainers/a.json.php @@ -49,6 +49,8 @@ if(!empty($nodes))foreach($nodes as $node) 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; } diff --git a/public/pages/jailscontainers/jailslist.table b/public/pages/jailscontainers/jailslist.table index aaae48d4..14ced005 100644 --- a/public/pages/jailscontainers/jailslist.table +++ b/public/pages/jailscontainers/jailslist.table @@ -2,7 +2,7 @@ #node# #jname# - #ip4_addr# + #ip4_addr# #jstatus# diff --git a/public/pages/sqlite/en.index.php b/public/pages/sqlite/en.index.php index 2aa3a799..065bf66e 100644 --- a/public/pages/sqlite/en.index.php +++ b/public/pages/sqlite/en.index.php @@ -1,3 +1,3 @@

SQLite admin interface

-

Open SQLite Admin interface

\ No newline at end of file +

Open SQLite Admin interface

\ No newline at end of file diff --git a/public/pages/sqlite/ru.index.php b/public/pages/sqlite/ru.index.php index 4c0c259c..db17c6da 100644 --- a/public/pages/sqlite/ru.index.php +++ b/public/pages/sqlite/ru.index.php @@ -1,3 +1,3 @@

Интерфейс админинстрирования SQLite

-

Открыть веб-интерфейс SQLite Admin

\ No newline at end of file +

Открыть веб-интерфейс SQLite Admin

\ No newline at end of file