mirror of
https://github.com/optim-enterprises-bv/control-pane.git
synced 2025-10-29 09:02:21 +00:00
ClonOS Beta
This commit is contained in:
246
php/clonos.php
246
php/clonos.php
@@ -20,7 +20,7 @@ class ClonOS
|
||||
private $_db=null;
|
||||
private $_client_ip='';
|
||||
private $_dialogs=array();
|
||||
private $_cmd_array=array('jcreate','jstart','jstop','jrestart','jedit','jremove','jexport','jimport','jclone','jrename','madd','sstart','sstop','projremove','bcreate','bstart','bstop','brestart','bremove','bclone','brename','vm_obtain','removesrc','srcup','removebase','world','repo');
|
||||
private $_cmd_array=array('jcreate','jstart','jstop','jrestart','jedit','jremove','jexport','jimport','jclone','jrename','madd','sstart','sstop','projremove','bcreate','bstart','bstop','brestart','bremove','bclone','brename','vm_obtain','removesrc','srcup','removebase','world','repo','forms');
|
||||
|
||||
/*
|
||||
public $projectId=0;
|
||||
@@ -90,7 +90,7 @@ class ClonOS
|
||||
$this->realpath_public=$_REALPATH.'/public/';
|
||||
# /usr/home/web/cp/clonos/public/
|
||||
|
||||
if(isset($_SERVER['SERVER_NAME']))
|
||||
if(isset($_SERVER['SERVER_NAME']) && !empty(trim($_SERVER['SERVER_NAME'])))
|
||||
$this->server_name=$_SERVER['SERVER_NAME'];
|
||||
else
|
||||
$this->server_name=$_SERVER['SERVER_ADDR'];
|
||||
@@ -266,6 +266,9 @@ class ClonOS
|
||||
echo json_encode($this->vpnetRemove());
|
||||
return;break;
|
||||
|
||||
case 'updateBhyveISO':
|
||||
echo json_encode($this->updateBhyveISO());
|
||||
return;break;
|
||||
case 'mediaAdd':
|
||||
//echo json_encode($this->mediaAdd());
|
||||
return;break;
|
||||
@@ -284,6 +287,15 @@ class ClonOS
|
||||
case 'repoCompile':
|
||||
echo json_encode($this->repoCompile());
|
||||
return;break;
|
||||
case 'srcUpdate':
|
||||
echo json_encode($this->srcUpdate());
|
||||
return;break;
|
||||
case 'srcRemove':
|
||||
echo json_encode($this->srcRemove());
|
||||
return;break;
|
||||
case 'baseRemove':
|
||||
echo json_encode($this->baseRemove());
|
||||
return;break;
|
||||
|
||||
/* case 'saveHelperValues':
|
||||
echo json_encode($this->saveHelperValues());
|
||||
@@ -456,7 +468,7 @@ class ClonOS
|
||||
*/
|
||||
function _getTasksStatus($jsonObj)
|
||||
{
|
||||
return $jsonObj;
|
||||
//return $jsonObj;
|
||||
$tasks=array();
|
||||
$obj=json_decode($jsonObj,true);
|
||||
|
||||
@@ -767,6 +779,7 @@ class ClonOS
|
||||
$form=$this->form;
|
||||
$helper=preg_replace('/^#/','',$this->_vars['hash']);
|
||||
|
||||
$db_path='';
|
||||
$with_img_helpers='';
|
||||
if($this->mode=='saveHelperValues')
|
||||
{
|
||||
@@ -774,6 +787,22 @@ class ClonOS
|
||||
{
|
||||
return $this->saveSettingsCBSD();
|
||||
}
|
||||
|
||||
if(!isset($this->_vars['db_path']))
|
||||
{
|
||||
$res=$this->cbsd_cmd('make_tmp_helper module='.$helper);
|
||||
if($res['retval']==0)
|
||||
{
|
||||
$db_path=$res['message'];
|
||||
}else{
|
||||
echo json_encode(array('error'=>true,'errorMessage'=>'Error on open temporary form database!'));
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
$db_path=$this->_vars['db_path'];
|
||||
}
|
||||
|
||||
/*
|
||||
$file_name=$this->workdir.'/formfile/'.$helper.'.sqlite';
|
||||
if(file_exists($file_name))
|
||||
{
|
||||
@@ -797,6 +826,24 @@ class ClonOS
|
||||
//echo $with_img_helpers;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$db=new Db('file',$db_path);
|
||||
if($db!==false)
|
||||
{
|
||||
foreach($form as $key=>$val)
|
||||
{
|
||||
if($key!='jname' && $key!='ip4_addr')
|
||||
{
|
||||
$query="update forms set new='{$val}' where param='{$key}'";
|
||||
$db->update($query);
|
||||
unset($form[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$with_img_helpers=$db_path;
|
||||
}
|
||||
|
||||
$form['interface']='auto';
|
||||
$form['user_pw_root']='';
|
||||
$form['astart']=1;
|
||||
@@ -861,6 +908,7 @@ class ClonOS
|
||||
$err='Jail was created!';
|
||||
$taskId=$res['message'];
|
||||
}
|
||||
|
||||
// local - поменять на реальный сервер, на котором создаётся клетка!
|
||||
$jid=$arr['jname'];
|
||||
|
||||
@@ -901,7 +949,7 @@ class ClonOS
|
||||
)));
|
||||
*/
|
||||
|
||||
return array('errorMessage'=>$err,'jail_id'=>$jid,'taskId'=>$taskId,'mode'=>$this->mode,'redirect'=>$redirect); //,'html'=>$html
|
||||
return array('errorMessage'=>$err,'jail_id'=>$jid,'taskId'=>$taskId,'mode'=>$this->mode,'redirect'=>$redirect,'db_path'=>$db_path); //,'html'=>$html
|
||||
}
|
||||
function jailRenameVars()
|
||||
{
|
||||
@@ -1192,6 +1240,7 @@ class ClonOS
|
||||
$res['error']=false;
|
||||
$res['dialog']=$form['dialog'];
|
||||
$res['jail_id']=$form['jail_id'];
|
||||
$res['iso_list']=$this->updateBhyveISO($form['jail_id']);
|
||||
return $res;
|
||||
}
|
||||
function bhyveRename()
|
||||
@@ -1251,7 +1300,7 @@ class ClonOS
|
||||
}
|
||||
function bhyveEdit()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
|
||||
$str=array();
|
||||
$jname=$form['jname'];
|
||||
@@ -1278,6 +1327,26 @@ class ClonOS
|
||||
|
||||
$form['vm_ram']=$ram_tmp;
|
||||
|
||||
/* check mounted ISO */
|
||||
$db=new Db('base','storage_media');
|
||||
$res=$db->selectAssoc('select * from media where jname="'.$jname.'" and type="iso"');
|
||||
if($res!==false && !empty($res))
|
||||
{
|
||||
$cmd1="cbsd media mode=unregister name=\"${res['name']}\" path=\"${res['path']}\" jname=${jname} type=${res['type']}";
|
||||
//echo $cmd1,PHP_EOL,PHP_EOL;
|
||||
$this->cbsd_cmd($cmd1);
|
||||
$res=$db->selectAssoc('select * from media where idx='.$form['vm_iso_image']);
|
||||
if($res!==false && !empty($res) && $form['vm_iso_image']!=-2)
|
||||
{
|
||||
$cmd2="cbsd media mode=register name=\"${res['name']}\" path=\"${res['path']}\" jname=${jname} type=${res['type']}";
|
||||
$this->cbsd_cmd($cmd2);
|
||||
//echo $cmd2;
|
||||
}
|
||||
}
|
||||
//exit;
|
||||
|
||||
/* end check */
|
||||
|
||||
$cmd='bset jname='.$jname.' '.join(' ',$str);
|
||||
$res=$this->cbsd_cmd($cmd);
|
||||
$res['mode']='bhyveEdit';
|
||||
@@ -1286,7 +1355,8 @@ class ClonOS
|
||||
}
|
||||
function bhyveAdd()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
|
||||
|
||||
$os_types=$this->config->os_types;
|
||||
$sel_os=$form['vm_os_profile'];
|
||||
@@ -1316,6 +1386,33 @@ class ClonOS
|
||||
'vm_vnc_port'=>$form['vm_vnc_port'],
|
||||
);
|
||||
|
||||
$iso=true;
|
||||
$res=array('name'=>'','path'=>'','iso_var_block'=>'');
|
||||
$crlf="\r\n";
|
||||
$iso_var_block='iso_extract=""'.$crlf.'iso_img_dist=""'.$crlf.'iso_img=""'.$crlf.'iso_site=""';
|
||||
$iso_id=$form['vm_iso_image'];
|
||||
if(!empty($iso_id))
|
||||
{
|
||||
if($iso_id>0)
|
||||
{
|
||||
$db=new Db('base','storage_media');
|
||||
$res=$db->selectAssoc('select name,path from media where idx='.$iso_id);
|
||||
if($res===false || empty($res)) $iso=false;
|
||||
}
|
||||
|
||||
if($iso_id==-1)
|
||||
{
|
||||
$iso=false;
|
||||
}
|
||||
|
||||
if($iso)
|
||||
{
|
||||
$arr['register_iso_as']='register_iso_as="'.$res['name'].'"';
|
||||
$arr['register_iso_name']='register_iso_name="'.$res['path'].'"';
|
||||
if($iso_id!=-2) $arr['iso_var_block']=$iso_var_block;
|
||||
}
|
||||
}
|
||||
|
||||
/* create vm */
|
||||
$file_name='/tmp/'.$arr['jname'].'.conf';
|
||||
|
||||
@@ -1327,6 +1424,7 @@ class ClonOS
|
||||
$file=str_replace('#'.$var.'#',$val,$file);
|
||||
}
|
||||
}
|
||||
//echo $file;exit;
|
||||
file_put_contents($file_name,$file);
|
||||
|
||||
$res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bcreate inter=0 jconf='.$file_name);
|
||||
@@ -1438,28 +1536,28 @@ class ClonOS
|
||||
}
|
||||
function bhyveStart()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
$name=$form['jname'];
|
||||
$res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bstart inter=0 jname='.$name); // autoflush=2
|
||||
return $res;
|
||||
}
|
||||
function bhyveStop()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
$name=$form['jname'];
|
||||
$res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bstop inter=0 jname='.$name); // autoflush=2
|
||||
return $res;
|
||||
}
|
||||
function bhyveRestart()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
$name=$form['jname'];
|
||||
$res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd brestart inter=0 jname='.$name); // autoflush=2
|
||||
return $res;
|
||||
}
|
||||
function bhyveRemove() //$name
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
$name=$form['jname'];
|
||||
$res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd bremove inter=0 jname='.$name); // autoflush=2
|
||||
return $res;
|
||||
@@ -1467,7 +1565,7 @@ class ClonOS
|
||||
|
||||
function authkeyAdd()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
|
||||
$query="insert into authkey (name,authkey) values ('{$form['keyname']}','{$form['keysrc']}')";
|
||||
|
||||
@@ -1558,24 +1656,49 @@ class ClonOS
|
||||
|
||||
function mediaRemove()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
/*
|
||||
$form=$this->form;
|
||||
$db=new Db('base','storage_media');
|
||||
$res=$db->update('delete from media where idx='.$form['media_id']);
|
||||
if($res===false) return array('error'=>true,'res'=>print_r($res,true));
|
||||
*/
|
||||
return array('error'=>false,'media_id'=>$form['media_id']);
|
||||
//$res=$db->update('delete from media where idx='.$form['media_id']);
|
||||
$res=$db->selectAssoc('select * from media where idx='.$form['media_id']);
|
||||
if($res===false || empty($res)) return array('error'=>true,'res'=>print_r($res,true));
|
||||
|
||||
//if($res['jname']=='-') // если медиа отвязана, то просто удаляем
|
||||
//print_r($res);exit;
|
||||
$cmd='media mode=remove name="'.$res['name'].'" path="'.$res['path'].'" jname="'.$res['jname'].'" type="'.$res['type'].'"'; //.$res['name']
|
||||
//echo $cmd;exit;
|
||||
|
||||
$res=$this->cbsd_cmd($cmd);
|
||||
|
||||
if($res['error'])
|
||||
{
|
||||
$arr['error']=true;
|
||||
$arr['error_message']='File image was not deleted! '.$res['error_message'];
|
||||
}else{
|
||||
$arr['error']=false;
|
||||
}
|
||||
$arr['media_id']=$form['media_id'];
|
||||
$arr['cmd']=$res;
|
||||
//echo json_encode($arr);
|
||||
|
||||
|
||||
//return array('error'=>false,'media_id'=>$form['media_id']);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
function srcRemove($ver)
|
||||
function srcRemove()
|
||||
{
|
||||
$form=$this->form;
|
||||
$ver=$form['jname'];
|
||||
$ver=str_replace('src','',$ver);
|
||||
if(empty($ver)) return array('error'=>true,'errorMessage'=>'Version of sources is emtpy!');
|
||||
$res=$this->cbsd_cmd('task owner=cbsdwebsys mode=new /usr/local/bin/cbsd removesrc inter=0 ver='.$ver.' jname=#src'.$ver);
|
||||
return $res;
|
||||
}
|
||||
function srcUpdate($ver)
|
||||
function srcUpdate()
|
||||
{
|
||||
$form=$this->form;
|
||||
$ver=$form['jname'];
|
||||
//$ver=str_replace('src','',$ver);
|
||||
$ver=str_replace('src','',$ver);
|
||||
$stable=(preg_match('#\.\d#',$ver))?0:1;
|
||||
if(empty($ver)) return array('error'=>true,'errorMessage'=>'Version of sources is emtpy!');
|
||||
@@ -1620,9 +1743,12 @@ class ClonOS
|
||||
|
||||
return array('html'=>$html,'arr'=>$res);
|
||||
}
|
||||
function baseRemove($id)
|
||||
function baseRemove() //$id
|
||||
{
|
||||
//$id=str_replace('base','',$id);
|
||||
//base10.3-amd64-0
|
||||
$form=$this->form;
|
||||
$id=$form['jname'];
|
||||
$orig_id=$id;
|
||||
preg_match('#base([0-9\.]+)-([^-]+)-(\d+)#',$id,$res);
|
||||
$ver=$res[1];
|
||||
@@ -1636,7 +1762,7 @@ class ClonOS
|
||||
|
||||
function basesCompile()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
if(!isset($form['sources']) || !is_numeric($form['sources'])) return array('error'=>true,'errorMessage'=>'Wrong OS type selected!');
|
||||
$id=$form['sources'];
|
||||
|
||||
@@ -1647,7 +1773,6 @@ class ClonOS
|
||||
}else{
|
||||
return array('error'=>true,'errorMessage'=>'Database connect error!');
|
||||
}
|
||||
|
||||
$ver=$base['ver'];
|
||||
$stable_arr=array('release','stable');
|
||||
$stable_num=strlen(intval($ver))<strlen($ver)?0:1;
|
||||
@@ -1732,7 +1857,7 @@ class ClonOS
|
||||
|
||||
function repoCompile()
|
||||
{
|
||||
$form=$this->_vars['form_data'];
|
||||
$form=$this->form;
|
||||
if(!isset($form['version']) || !is_numeric($form['version'])) return array('error'=>true,'errorMessage'=>'Wrong OS type input!');
|
||||
|
||||
$stable_arr=array('release','stable');
|
||||
@@ -1881,7 +2006,7 @@ class ClonOS
|
||||
function addHelperGroup($mode)
|
||||
{
|
||||
$module=$this->url_hash;
|
||||
$form=$this->form;
|
||||
if(isset($this->form)) $form=$this->form; else $form=array();
|
||||
if(isset($form['db_path']) && !empty($form['db_path']))
|
||||
{
|
||||
$db_path=$form['db_path'];
|
||||
@@ -1904,13 +2029,15 @@ class ClonOS
|
||||
function deleteHelperGroup($mode)
|
||||
{
|
||||
$module=$this->url_hash;
|
||||
$form=$this->form;
|
||||
$index=$form['index'];
|
||||
$index=str_replace('ind-','',$index);
|
||||
if(isset($this->form)) $form=$this->form; else $form=array();
|
||||
if(!isset($form['db_path']) || empty($form['db_path'])) return;
|
||||
|
||||
if(!file_exists($form['db_path']))
|
||||
return array('error'=>true,'errorMessage'=>'Error on open temporary form file!');
|
||||
|
||||
$index=$form['index'];
|
||||
$index=str_replace('ind-','',$index);
|
||||
|
||||
$db_path=$form['db_path'];
|
||||
$res=$this->cbsd_cmd('forms inter=0 module='.$module.' formfile='.$db_path.' group=del index='.$index);
|
||||
$form=new Forms('',$module,$db_path);
|
||||
@@ -1973,10 +2100,13 @@ class ClonOS
|
||||
function runVNC($jname)
|
||||
{
|
||||
$res=$this->cbsd_cmd("vm_vncwss jname={$jname} permit={$this->_client_ip}");
|
||||
$res=$this->_db_local->selectAssoc('select nodeip from local');
|
||||
$nodeip=$res['nodeip'];
|
||||
//$res=$this->_db_local->selectAssoc('select nodeip from local');
|
||||
//$nodeip=$res['nodeip'];
|
||||
// need for IPv4/IPv6 regex here, instead of strlen
|
||||
if(strlen($nodeip)<7) $nodeip='127.0.0.1';
|
||||
//if(strlen($nodeip)<7) $nodeip='127.0.0.1';
|
||||
//if(strlen($nodeip)<7) $nodeip=$this->server_name;
|
||||
$nodeip=$this->server_name;
|
||||
|
||||
header('Location: http://'.$nodeip.':6080/vnc_auto.html?host='.$nodeip.'&port=6080');
|
||||
exit;
|
||||
}
|
||||
@@ -2059,4 +2189,60 @@ class ClonOS
|
||||
|
||||
return '<span class="cbsd-str">'.$cmd_string.'</span>';
|
||||
}
|
||||
|
||||
|
||||
function register_media($path,$file,$ext)
|
||||
{
|
||||
$cmd='cbsd media mode=register name='.$file.' path='.$path.$file.' type='.$ext;
|
||||
$res=$this->cbsd_cmd($cmd);
|
||||
if($res['error'])
|
||||
{
|
||||
$arr['error']=true;
|
||||
$arr['error_message']='File image not registered!';
|
||||
}else{
|
||||
$arr['error']=false;
|
||||
}
|
||||
echo json_encode($arr);
|
||||
}
|
||||
function media_iso_list_html()
|
||||
{
|
||||
// $form=$this->form;
|
||||
$db=new Db('base','storage_media');
|
||||
$res=$db->select('select * from media where type="iso"');
|
||||
if($res===false || empty($res)) return;
|
||||
|
||||
$html='';
|
||||
foreach($res as $r)
|
||||
{
|
||||
$html.='<option value="'.$r['idx'].'">'.$r['name'].'.'.$r['type'].'</option>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
function updateBhyveISO($iso='')
|
||||
{
|
||||
$db=new Db('base','storage_media');
|
||||
$res=$db->select('select * from media where type="iso"');
|
||||
if($res===false || empty($res)) return;
|
||||
|
||||
$sel='';
|
||||
//if(empty($iso)) $sel='#sel#';
|
||||
$html='<option value="-2"></option><option value="-1"#sel#>Profile default ISO</option>';
|
||||
foreach($res as $r)
|
||||
{
|
||||
$sel1='';
|
||||
if(empty($sel) && $iso==$r['jname']) $sel1='#sel1#';
|
||||
$html.='<option value="'.$r['idx'].'"'.$sel1.'>'.$r['name'].'.'.$r['type'].'</option>';
|
||||
}
|
||||
|
||||
if(strpos($html,'#sel1#')!==false)
|
||||
{
|
||||
$html=str_replace('#sel1#',' selected="selected"',$html);
|
||||
$html=str_replace('#sel#','',$html);
|
||||
}else{
|
||||
$html=str_replace('#sel1#','',$html);
|
||||
$html=str_replace('#sel#',' selected="selected"',$html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,13 @@ class Config
|
||||
'title'=>'Virtual machine control panel',
|
||||
'icon'=>'icon-th-list',
|
||||
),
|
||||
|
||||
/*
|
||||
'nodes'=>array(
|
||||
'name'=>'Nodes',
|
||||
'title'=>'Nodes control panel',
|
||||
'icon'=>'icon-buffer',
|
||||
),
|
||||
|
||||
*/
|
||||
'vpnet'=>array(
|
||||
'name'=>'Virtual Private Network',
|
||||
'title'=>'Manage for virtual private networks',
|
||||
@@ -78,19 +78,19 @@ class Config
|
||||
'title'=>'FreeBSD sources manager',
|
||||
'icon'=>'icon-edit',
|
||||
),
|
||||
|
||||
/*
|
||||
'jail_marketplace'=>array(
|
||||
'name'=>'Jail Marketplace',
|
||||
'title'=>'Public remote containers marketplace',
|
||||
'icon'=>'icon-flag',
|
||||
),
|
||||
|
||||
*//*
|
||||
'bhyve_marketplace'=>array(
|
||||
'name'=>'Bhyve Marketplace',
|
||||
'title'=>'Public remote virtual machine marketplace',
|
||||
'icon'=>'icon-flag-checkered',
|
||||
),
|
||||
|
||||
*/
|
||||
'tasklog'=>array(
|
||||
'name'=>'TaskLog',
|
||||
'title'=>'System task log',
|
||||
@@ -109,8 +109,8 @@ class Config
|
||||
array(
|
||||
'os'=>'DragonflyBSD',
|
||||
'items'=>array(
|
||||
array('name'=>'DragonflyBSD Daily SNAPSHOT','type'=>'dflybsd',
|
||||
'profile'=>'x86-LATEST','obtain'=>false),
|
||||
array('name'=>'DragonflyBSD 4','type'=>'dflybsd',
|
||||
'profile'=>'x86-4','obtain'=>false),
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -131,8 +131,6 @@ class Config
|
||||
'profile'=>'ArchLinux-x86-2016','obtain'=>false),
|
||||
array('name'=>'Linux CentOS 7','type'=>'linux',
|
||||
'profile'=>'CentOS-7-x86_64','obtain'=>false),
|
||||
array('name'=>'Linux Debian 7','type'=>'linux',
|
||||
'profile'=>'Debian-x86-7','obtain'=>false),
|
||||
array('name'=>'Linux Debian 8','type'=>'linux',
|
||||
'profile'=>'Debian-x86-8','obtain'=>false),
|
||||
array('name'=>'Linux Open Suse 42','type'=>'linux',
|
||||
|
||||
@@ -411,7 +411,7 @@ thead td:first-child, td:first-child {
|
||||
.tsimple thead th,
|
||||
.tsimple thead td {
|
||||
border-bottom:3px solid #337ab7;
|
||||
padding:10px;
|
||||
padding:8px 8px 8px 0;
|
||||
text-align:left;
|
||||
}
|
||||
.tsimple tbody td {
|
||||
@@ -423,12 +423,15 @@ thead td:first-child, td:first-child {
|
||||
.tsimple tbody tr:nth-child(2n){
|
||||
background-color: #fafafa;
|
||||
}
|
||||
.tsimple td.txtleft {
|
||||
.tsimple .txtleft {
|
||||
text-align:left;
|
||||
}
|
||||
.tsimple td.txtright {
|
||||
.tsimple .txtright {
|
||||
text-align:right;
|
||||
}
|
||||
.tsimple .txtcenter {
|
||||
text-align:center;
|
||||
}
|
||||
.tsimple td input[type="button"] {
|
||||
font-size:86%;
|
||||
padding:2px 4px;
|
||||
@@ -959,6 +962,7 @@ http://dimox.name/custom-checkboxes-and-radio-buttons-using-css-only/
|
||||
#config-menu li {
|
||||
padding:6px !important;
|
||||
line-height:110%;
|
||||
white-space:nowrap;
|
||||
}
|
||||
#config-menu li:hover {
|
||||
background:#f0f0f0;
|
||||
@@ -1208,3 +1212,86 @@ input[type=range]::-moz-range-track {
|
||||
}
|
||||
.online:before {content: '\e82c';color:green;}
|
||||
.offline:before {content: '\e82d';color:red;}
|
||||
|
||||
|
||||
#drag-and-drop-zone {
|
||||
width:400px;
|
||||
border:1px dotted gray;
|
||||
}
|
||||
.uploader div {
|
||||
padding:10px;
|
||||
text-align:center;
|
||||
}
|
||||
.uploader .browser label {
|
||||
background-color: #337ab7;
|
||||
padding: 5px 15px;
|
||||
color: white;
|
||||
padding: 6px 0px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
width: 300px;
|
||||
margin: 10px auto 0px auto;
|
||||
box-shadow: 2px 2px 2px #888888;
|
||||
}
|
||||
.uploader div.browser input {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
border: solid transparent;
|
||||
border-width: 0 0 100px 200px;
|
||||
opacity: .0;
|
||||
filter: alpha(opacity= 0);
|
||||
-o-transform: translate(250px,-50px) scale(1);
|
||||
-moz-transform: translate(-300px,0) scale(4);
|
||||
direction: ltr;
|
||||
cursor: pointer;
|
||||
}
|
||||
.uploader-progress {
|
||||
width:100%;
|
||||
background-color:white;
|
||||
}
|
||||
.uploader-progress .file {
|
||||
padding:4px;
|
||||
border:1px solid silver;
|
||||
margin-top:4px;
|
||||
}
|
||||
.uploader-progress .file-name {
|
||||
overflow:hidden;
|
||||
text-overflow:ellipsis;
|
||||
white-space:nowrap;
|
||||
width:390px;
|
||||
}
|
||||
.uploader-progress .line {
|
||||
background-color:#337ab7;
|
||||
height:10px;
|
||||
opacity:.7;
|
||||
margin-top:4px;
|
||||
width:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#debug {
|
||||
position:fixed;
|
||||
top:20%;
|
||||
bottom:20%;
|
||||
left:30%;
|
||||
right:30%;
|
||||
overflow:auto;
|
||||
z-index:15;
|
||||
border:3px double red;
|
||||
background-color:antiquewhite;
|
||||
}
|
||||
#debug h1 {
|
||||
background:darkred;
|
||||
padding:10px;
|
||||
color:white;
|
||||
}
|
||||
#debug div {
|
||||
padding:20px;
|
||||
}
|
||||
@@ -39,6 +39,14 @@ err_messages.add({
|
||||
<span class="field-name"><?php echo $this->translate('VM RAM');?>:</span>
|
||||
<input type="text" name="vm_ram" value="" pattern="^[0-9]+\s*(g|G|gb|GB|mb|MB|m|M)$" placeholder="1g" required="required" />
|
||||
</p>
|
||||
<p>
|
||||
<span class="field-name"><?php echo $this->translate('Attached boot ISO image');?>:</span>
|
||||
<select name="vm_iso_image">
|
||||
<option value="-2"></option>
|
||||
<option value="-1" selected>Profile default ISO</option>
|
||||
<?php echo $this->media_iso_list_html(); ?>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<span class="field-name"><?php echo $this->translate('VNC IP address');?>:</span>
|
||||
<input type="radio" name="bhyve_vnc_tcp_bind" value="127.0.0.1" id="vncip0" checked="checked" class="inline"><label for="vncip0">127.0.0.1</label></radio>
|
||||
|
||||
30
public/dialogs/media-upload.php
Normal file
30
public/dialogs/media-upload.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<script type="text/javascript">
|
||||
err_messages.add({});
|
||||
</script>
|
||||
<dialog id="media-upload" class="window-box">
|
||||
<h1><?php echo $this->translate('Add Storage Media');?></h1>
|
||||
<h2><?php echo $this->translate('Upload ISO');?></h2>
|
||||
<form class="win" method="post" id="mediaSettings" onsubmit="return false;">
|
||||
<div class="window-content">
|
||||
<p>
|
||||
<!-- D&D Markup -->
|
||||
<div id="drag-and-drop-zone" class="uploader">
|
||||
<div>Drag & Drop Files Here</div>
|
||||
<div class="or">-or-</div>
|
||||
<div class="browser">
|
||||
<label>
|
||||
<span>Click to open the file Browser</span>
|
||||
<input type="file" name="files[]" multiple="multiple" title='Click to add Files'>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uploader-progress"></div>
|
||||
<!-- /D&D Markup -->
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
<div class="buttons">
|
||||
<input type="button" value="<?php echo $this->translate('Close');?>" class="button red cancel-but" />
|
||||
</div>
|
||||
</dialog>
|
||||
<script type="text/javascript">clonos.fileUploadPrepare();</script>
|
||||
BIN
public/images/logo-orig/rtorrent2_orig.png
Normal file
BIN
public/images/logo-orig/rtorrent2_orig.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 6.1 KiB |
@@ -10,6 +10,13 @@ $uri=trim($_SERVER['REQUEST_URI'],'/');
|
||||
include($_REALPATH.'/php/clonos.php');
|
||||
$clonos=new ClonOS($_REALPATH,$uri);
|
||||
|
||||
if(isset($_GET['upload']))
|
||||
{
|
||||
include('upload.php');
|
||||
$clonos->register_media($path,$file,$ext);
|
||||
exit;
|
||||
}
|
||||
|
||||
$lang=$clonos->getLang();
|
||||
$root=trim($_SERVER['DOCUMENT_ROOT'],DIRECTORY_SEPARATOR);
|
||||
$_ds=DIRECTORY_SEPARATOR;
|
||||
@@ -39,6 +46,7 @@ error_reporting(E_ALL);
|
||||
<link href="/images/favicon.ico?" rel="shortcut icon" type="image/x-icon" />
|
||||
<script src="/js/jquery.js" type="text/javascript"></script>
|
||||
<script src="/js/clonos.js" type="text/javascript"></script>
|
||||
<script src="/js/dmuploader.js" type="text/javascript"></script>
|
||||
<script src="/js/noty/packaged/jquery.noty.packaged.min.js" type="text/javascript"></script>
|
||||
<link type="text/css" href="/css/reset.css" rel="stylesheet" />
|
||||
<link type="text/css" href="/css/styles.css" rel="stylesheet" />
|
||||
@@ -97,6 +105,6 @@ if(isset($_languages))foreach($_languages as $lng=>$lngname)
|
||||
</div></header>
|
||||
|
||||
<div class="spinner"></div>
|
||||
<div class="online icon-online" id="net-stat"></div>
|
||||
<div class="online icon-online" id="net-stat" onclick="ws_debug();"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -22,6 +22,11 @@ var clonos={
|
||||
'bclone':{stat:['Clone','Cloning','Cloned'],cmd:'bhyveClone'},
|
||||
'brename':{stat:['Rename','Renaming','Renamed'],cmd:'bhyveRename'},
|
||||
'vm_obtain':{stat:['Create','Creating','Created'],cmd:'bhyveObtain'},
|
||||
'srcup':{stat:['Update','Updating','Updated'],cmd:'srcUpdate'},
|
||||
'world':{stat:['Compile','Compiling','Compiled'],cmd:'basesCompile'},
|
||||
'repo':{stat:['Fetch','Fetching','Fetched'],cmd:'repoCompile'},
|
||||
'removesrc':{stat:['Remove','Removing','Removed'],cmd:'srcRemove'},
|
||||
'removebase':{stat:['Remove','Removing','Removed'],cmd:'baseRemove'},
|
||||
},
|
||||
|
||||
start:function()
|
||||
@@ -66,7 +71,7 @@ var clonos={
|
||||
addEvents:function()
|
||||
{
|
||||
$(window).on('hashchange',$.proxy(this.onHashChange,this));
|
||||
$('#lng-sel').on('change',function(){document.cookie="lang="+$(this).val()+";path=/;";location.reload();});
|
||||
$('#lng-sel').on('change',$.proxy(this.setLang,this)); //function(){document.cookie="lang="+$(this).val()+";path=/;";location.reload();});
|
||||
$('#content').on('click',$.proxy(this.bodyClick,this));
|
||||
$('.closer').on('click',$.proxy(this.closerClick,this));
|
||||
$(window).on('keypress',$.proxy(this.dialogCloseByKey,this))
|
||||
@@ -180,6 +185,8 @@ var clonos={
|
||||
if(id=='bhyve-new')
|
||||
{
|
||||
this.trids=this.getTrIdsForCheck('bhyveslist');
|
||||
this.updateBhyveISO();
|
||||
this.updateBhyveOSProfile();
|
||||
}
|
||||
this.dialogShow1(id);
|
||||
}
|
||||
@@ -375,6 +382,7 @@ var clonos={
|
||||
}
|
||||
if(id=='bhyve-new' && $('form#bhyveSettings').length>0)
|
||||
{
|
||||
this.storageBhyveOSProfile();
|
||||
var jid=$('form#bhyveSettings input[name="vm_name"]').val();
|
||||
if(typeof this.trids!='undefined' && this.trids.length>0)
|
||||
{
|
||||
@@ -441,7 +449,11 @@ var clonos={
|
||||
}
|
||||
if(id=='srcget')
|
||||
{
|
||||
this.srcVerAdd();
|
||||
//this.srcVerAdd();
|
||||
var inp=$('form#srcSettings input[name="version"]');
|
||||
var id=$(inp).val();
|
||||
this.dialogClose();
|
||||
this.srcUpdate(id);
|
||||
}
|
||||
if(id=='basescompile')
|
||||
{
|
||||
@@ -486,7 +498,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data!='undefined' && !data.error)
|
||||
{
|
||||
@@ -521,11 +533,11 @@ var clonos={
|
||||
var table='bhyveslist';
|
||||
var operation='vm_obtain';
|
||||
break;
|
||||
case 'basesCompile':
|
||||
case 'basesCompile': this.dialogClose();return;
|
||||
var table='baseslist';
|
||||
var operation='world';
|
||||
break;
|
||||
case 'repoCompile':
|
||||
case 'repoCompile': this.dialogClose();return;
|
||||
var table='baseslist';
|
||||
var operation='repo';
|
||||
break;
|
||||
@@ -578,7 +590,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
this.dialogClose();
|
||||
|
||||
@@ -588,7 +600,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data!='undefined' && !data.error)
|
||||
{
|
||||
@@ -621,7 +633,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data!='undefined' && !data.error)
|
||||
{
|
||||
@@ -651,7 +663,7 @@ var clonos={
|
||||
}
|
||||
},
|
||||
srcVerAdd:function()
|
||||
{
|
||||
{return;
|
||||
var n,nl;
|
||||
var posts=$('form#srcSettings').serializeArray();
|
||||
var version=$('form#srcSettings input[name="version"]').val();
|
||||
@@ -689,13 +701,51 @@ var clonos={
|
||||
}
|
||||
if(!injected)
|
||||
{
|
||||
//$(html).insertAfter(tr);
|
||||
if(trs.length==0)
|
||||
{
|
||||
$('table#srcslist tbody').append(html);
|
||||
}else{
|
||||
$(html).insertAfter(tr);
|
||||
}
|
||||
this.srcUpdate('src'+version);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
updateBhyveOSProfile:function()
|
||||
{
|
||||
if(localStorage)
|
||||
{
|
||||
var pos=localStorage['vm_os_profile_pos'];
|
||||
if(typeof pos!='undefined')
|
||||
$('#bhyveSettings select[name="vm_os_profile"]').val(pos);
|
||||
}
|
||||
|
||||
//if(localStorage) db_path=localStorage[var_name];
|
||||
},
|
||||
storageBhyveOSProfile:function()
|
||||
{
|
||||
if(localStorage)
|
||||
{
|
||||
var pos=$('#bhyveSettings select[name="vm_os_profile"]').val();
|
||||
localStorage['vm_os_profile_pos']=pos;
|
||||
}
|
||||
},
|
||||
updateBhyveISO:function()
|
||||
{
|
||||
this.loadData('updateBhyveISO',$.proxy(this.onUpdateBhyveISO,this));
|
||||
},
|
||||
onUpdateBhyveISO:function(data)
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
if(typeof data.iso_list!='undefined')
|
||||
{
|
||||
$('dialog #bhyveSettings select[name="vm_iso_image"]').html(data.iso_list);
|
||||
}
|
||||
},
|
||||
getFreeJname:function()
|
||||
{
|
||||
this.loadData('freejname',$.proxy(this.onGetFreeJname,this));
|
||||
@@ -704,7 +754,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
$('dialog#jail-settings input[name="jname"]').val(data.freejname);
|
||||
$('dialog#jail-settings input[name="host_hostname"]').val(data.freejname+'.my.domain');
|
||||
},
|
||||
@@ -751,7 +801,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(data.error)
|
||||
{
|
||||
@@ -789,7 +839,7 @@ var clonos={
|
||||
{
|
||||
var txt_status=task.txt_status;
|
||||
//this.tasks.add({'operation':task.task_cmd,'jail_id':t,'status':status,'task_id':task.task_id,'txt_status':txt_status});
|
||||
$('tr#'+t+' .jstatus').html(this.translate(txt_status));
|
||||
$('tr#'+this.dotEscape(t)+' .jstatus').html(this.translate(txt_status));
|
||||
this.enableWait(t);
|
||||
}
|
||||
}
|
||||
@@ -1072,7 +1122,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
/* if(typeof data['mod_ops']!='undefined')
|
||||
{
|
||||
@@ -1297,7 +1347,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data.error!='undefined')
|
||||
{
|
||||
@@ -1322,7 +1372,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data.error!='undefined')
|
||||
{
|
||||
@@ -1347,7 +1397,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data.error!='undefined')
|
||||
{
|
||||
@@ -1367,18 +1417,23 @@ var clonos={
|
||||
if(!c) return;
|
||||
var ver=$('#srcslist tr#'+this.dotEscape(id)+' .version').html();
|
||||
var op='removesrc';
|
||||
this.enableWait(id);
|
||||
this.tasks.add({'operation':op,'jail_id':id});
|
||||
this.tasks.start();
|
||||
//this.enableWait(id);
|
||||
//this.tasks.add({'operation':op,'jail_id':id});
|
||||
//this.tasks.start();
|
||||
var posts=[{'name':'operation','value':op},{'name':'jname','value':id}];
|
||||
if(typeof this.commands[op]!='undefined')
|
||||
this.loadData(this.commands[op]['cmd'],$.proxy(this.onJailStart,this),posts,false);
|
||||
},
|
||||
srcUpdate:function(id,vers)
|
||||
{
|
||||
if(typeof vers=='undefined') vers='stable';
|
||||
var ver=$('#srcslist tr#'+this.dotEscape(id)+' .version').html();
|
||||
var op='srcup';
|
||||
this.enableWait(id);
|
||||
this.tasks.add({'operation':op,'jail_id':id});
|
||||
this.tasks.start();
|
||||
//this.tasks.add({'operation':op,'jail_id':id});
|
||||
//this.tasks.start();
|
||||
var posts=[{'name':'operation','value':op},{'name':'jname','value':id}];
|
||||
if(typeof this.commands[op]!='undefined')
|
||||
this.loadData(this.commands[op]['cmd'],$.proxy(this.onJailStart,this),posts,false);
|
||||
},
|
||||
baseRemove:function(id)
|
||||
{
|
||||
@@ -1386,9 +1441,15 @@ var clonos={
|
||||
if(!c) return;
|
||||
var ver=$('#baseslist tr#'+this.dotEscape(id)+' .version').html();
|
||||
var op='removebase';
|
||||
this.enableWait(id);
|
||||
this.tasks.add({'operation':op,'jail_id':id});
|
||||
this.tasks.start();
|
||||
//this.enableWait(id);
|
||||
//this.tasks.add({'operation':op,'jail_id':id});
|
||||
//this.tasks.start();
|
||||
var posts=[{'name':'operation','value':op},{'name':'jname','value':id}];
|
||||
if(typeof this.commands[op]!='undefined')
|
||||
{
|
||||
this.loadData(this.commands[op]['cmd'],$.proxy(this.onJailStart,this),posts,false);
|
||||
$('tr#'+id+' .jstatus').html(this.translate(this.commands[op]['stat'][1]));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1403,7 +1464,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data.error!='undefined')
|
||||
{
|
||||
@@ -1425,7 +1486,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data.error!='undefined')
|
||||
{
|
||||
@@ -1780,6 +1841,9 @@ var clonos={
|
||||
var id=dt.id;
|
||||
var table_id=dt.table_id;
|
||||
var preloadVars=false;
|
||||
|
||||
this.DDMenuClose();
|
||||
|
||||
switch(table_id)
|
||||
{
|
||||
case 'jailslist':
|
||||
@@ -1864,7 +1928,6 @@ var clonos={
|
||||
break;
|
||||
}
|
||||
|
||||
this.DDMenuClose();
|
||||
if(preloadVars)
|
||||
{
|
||||
var posts=[{'name':'jail_id','value':id},{'name':'dialog','value':dialog},{'name':'elid','value':elid}];
|
||||
@@ -1877,7 +1940,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data.error!='undefined')
|
||||
{
|
||||
@@ -1886,8 +1949,8 @@ var clonos={
|
||||
this.notify(data.error_message,'error');
|
||||
if(typeof data.reload!='undefined')
|
||||
{
|
||||
if(data.reload)
|
||||
this.loadData('getJsonPage',$.proxy(this.onLoadData,this));
|
||||
if(data.reload) this.dataReload();
|
||||
//this.loadData('getJsonPage',$.proxy(this.onLoadData,this));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1895,6 +1958,8 @@ var clonos={
|
||||
|
||||
var dialog=data.dialog;
|
||||
this.fillDialogVars(dialog,data.vars);
|
||||
if(data.dialog=='bhyve-new' && typeof data.iso_list!='undefined')
|
||||
$('dialog#bhyve-new select[name="vm_iso_image"]').html(data.iso_list);
|
||||
this.dialogShow1(dialog,this.cnt_mode);
|
||||
|
||||
/*
|
||||
@@ -1907,6 +1972,36 @@ var clonos={
|
||||
|
||||
},
|
||||
|
||||
dataReload:function()
|
||||
{
|
||||
this.loadData('getJsonPage',$.proxy(this.onLoadData,this));
|
||||
},
|
||||
|
||||
fillFormVars:function(form,data)
|
||||
{
|
||||
var n=0,
|
||||
f=$(form);
|
||||
if(f.length<1) return;
|
||||
|
||||
for(n=0,nl=data.length;n<nl;n++)
|
||||
{
|
||||
var $el=$('[name="'+data[n].name+'"]'),
|
||||
type=$el.attr('type'),
|
||||
val=data[n].value;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case 'checkbox':
|
||||
$el.attr('checked', val);
|
||||
break;
|
||||
case 'radio':
|
||||
$el.filter('[value="'+val+'"]').attr('checked', 'checked');
|
||||
break;
|
||||
default:
|
||||
$el.val(val);
|
||||
}
|
||||
}
|
||||
},
|
||||
fillDialogVars:function(dialog,vars)
|
||||
{
|
||||
var d=$('dialog#'+dialog);
|
||||
@@ -1979,7 +2074,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(typeof data.error!='undefined' && data.error)
|
||||
{
|
||||
@@ -1999,6 +2094,9 @@ var clonos={
|
||||
|
||||
deleteHelperGroup:function(form,id)
|
||||
{
|
||||
this.tmp_formdata=$(form).serializeArray();
|
||||
this.tmp_form=form;
|
||||
|
||||
var mode='deleteHelperGroup';
|
||||
var fh=$('form#newJailSettings');
|
||||
if(fh.length==0)
|
||||
@@ -2015,7 +2113,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(!data) return;
|
||||
if(typeof data.error!='undefined')
|
||||
@@ -2034,6 +2132,10 @@ var clonos={
|
||||
{
|
||||
$('form.helper').html(data.html);
|
||||
}
|
||||
if(this.tmp_form)
|
||||
{
|
||||
this.fillFormVars(this.tmp_form,this.tmp_formdata);
|
||||
}
|
||||
},
|
||||
|
||||
getDbPath:function()
|
||||
@@ -2056,6 +2158,9 @@ var clonos={
|
||||
|
||||
addHelperGroup:function(form)
|
||||
{
|
||||
this.tmp_formdata=$(form).serializeArray();
|
||||
this.tmp_form=form;
|
||||
|
||||
var mode='addHelperGroup';
|
||||
var fh=$('form#newJailSettings');
|
||||
var posts=[];
|
||||
@@ -2072,7 +2177,7 @@ var clonos={
|
||||
{
|
||||
try{
|
||||
var data=JSON.parse(data);
|
||||
}catch(e){alert(e.message);return;}
|
||||
}catch(e){this.debug(e.message,data);return;}
|
||||
|
||||
if(!data) return;
|
||||
if(typeof data.error!='undefined')
|
||||
@@ -2091,6 +2196,10 @@ var clonos={
|
||||
{
|
||||
$('form.helper').html(data.html);
|
||||
}
|
||||
if(this.tmp_form)
|
||||
{
|
||||
this.fillFormVars(this.tmp_form,this.tmp_formdata);
|
||||
}
|
||||
},
|
||||
|
||||
notify:function(message,type)
|
||||
@@ -2129,7 +2238,7 @@ var clonos={
|
||||
if_wsopened:function()
|
||||
{
|
||||
if(!this.connected) return;
|
||||
if(!_first_start) this.loadData('getJsonPage',$.proxy(this.onLoadData,this));
|
||||
if(!_first_start) this.dataReload(); //this.loadData('getJsonPage',$.proxy(this.onLoadData,this));
|
||||
_first_start=false;
|
||||
$('#net-stat').attr('class','online icon-online');
|
||||
|
||||
@@ -2288,7 +2397,7 @@ return;
|
||||
case 'bstart':
|
||||
if(status==1)
|
||||
{
|
||||
$('#'+id).removeClass('s-on').addClass('s-off').addClass('busy');
|
||||
$('#'+this.dotEscape(id)).removeClass('s-on').addClass('s-off').addClass('busy');
|
||||
this.enableWait(id);
|
||||
}
|
||||
if(status==2)
|
||||
@@ -2301,7 +2410,7 @@ return;
|
||||
case 'bstop':
|
||||
if(status==1)
|
||||
{
|
||||
$('#'+id).removeClass('s-on').addClass('s-off').addClass('busy');
|
||||
$('#'+this.dotEscape(id)).removeClass('s-on').addClass('s-off').addClass('busy');
|
||||
this.enableWait(id);
|
||||
}
|
||||
if(status==2)
|
||||
@@ -2318,12 +2427,19 @@ return;
|
||||
case 'jclone':
|
||||
case 'bclone':
|
||||
case 'jexport':
|
||||
case 'srcup':
|
||||
case 'world':
|
||||
case 'repo':
|
||||
if(status==1)
|
||||
{
|
||||
if(isset(data.data))
|
||||
{
|
||||
this.addNewJail(data,cmd);
|
||||
}
|
||||
if(['srcup','world','repo'].indexOf(cmd)!=-1)
|
||||
{
|
||||
this.enableWait(id);
|
||||
}
|
||||
}
|
||||
if(status==2)
|
||||
{
|
||||
@@ -2336,7 +2452,7 @@ return;
|
||||
case 'removebase':
|
||||
if(status==1)
|
||||
{
|
||||
$('#'+id).removeClass('s-on').addClass('s-off').addClass('busy');
|
||||
$('#'+this.dotEscape(id)).removeClass('s-on').addClass('s-off').addClass('busy');
|
||||
this.enableWait(id);
|
||||
}
|
||||
if(status==2)
|
||||
@@ -2350,7 +2466,7 @@ return;
|
||||
{
|
||||
for(n in data.data)
|
||||
{
|
||||
$('#'+id+' .'+n).html(data.data[n]);
|
||||
$('#'+this.dotEscape(id)+' .'+n).html(data.data[n]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -2369,6 +2485,16 @@ return;
|
||||
if(status==2)
|
||||
{
|
||||
var cmd=data.cmd;
|
||||
|
||||
if(['srcup','repo','world'].indexOf(cmd)!=-1)
|
||||
{
|
||||
$('#'+this.dotEscape(id))
|
||||
.removeClass('s-off').removeClass('busy').removeClass('maintenance')
|
||||
.addClass('s-on');
|
||||
this.enableClear(id);
|
||||
return;
|
||||
}
|
||||
|
||||
var stat_cl='s-off';
|
||||
if(isset(data.data))
|
||||
{
|
||||
@@ -2378,7 +2504,7 @@ return;
|
||||
var stat_cl=(stat==0?'s-off':'s-on');
|
||||
}
|
||||
}
|
||||
$('#'+id)
|
||||
$('#'+this.dotEscape(id))
|
||||
.removeClass('maintenance').removeClass('s-on').removeClass('s-off').removeClass('busy')
|
||||
.addClass(stat_cl);
|
||||
if(stat==0) this.enablePlay(id); else this.enableStop(id);
|
||||
@@ -2394,15 +2520,24 @@ return;
|
||||
var id=data.id;
|
||||
|
||||
var html=this.template;
|
||||
if(typeof html=='undefined') html='no data!';
|
||||
var table='jailslist';
|
||||
if(['bcreate','bclone'].indexOf(cmd)!=-1) table='bhyveslist';
|
||||
if(['srcup'].indexOf(cmd)!=-1) table='srcslist';
|
||||
if(['repo','world'].indexOf(cmd)!=-1) table='baseslist';
|
||||
|
||||
if(isset(data.data))
|
||||
{
|
||||
if(isset(this.commands[cmd]['stat']))
|
||||
data.data['jstatus']=this.translate(this.commands[cmd]['stat'][1]);
|
||||
if(!isset(data.data['id'])) data.data['id']=data['id'];
|
||||
for(n in data.data)
|
||||
html=html.replace(new RegExp('#'+n+'#','g'),data.data[n]);
|
||||
}
|
||||
|
||||
var el=$('#'+this.dotEscape(id));
|
||||
if(el.length>0) return;
|
||||
|
||||
var trs=$('table#'+table+' tbody tr');
|
||||
for(n=0,nl=trs.length;n<nl;n++)
|
||||
{
|
||||
@@ -2418,7 +2553,12 @@ return;
|
||||
}
|
||||
if(!injected) // Вставляем запись в конец таблицы
|
||||
{
|
||||
if(trs.length==0)
|
||||
{
|
||||
$('table#'+table+' tbody').append(html);
|
||||
}else{
|
||||
$(html).insertAfter(tr);
|
||||
}
|
||||
status=true;
|
||||
}
|
||||
},
|
||||
@@ -2477,10 +2617,128 @@ return;
|
||||
arr[z] = arr[z].join("");
|
||||
return arr;
|
||||
},
|
||||
|
||||
fileUploadPrepare:function()
|
||||
{
|
||||
$('#drag-and-drop-zone').dmUploader(
|
||||
{
|
||||
url: '/?upload',
|
||||
dataType: 'json',
|
||||
//allowedTypes: 'iso/*',
|
||||
extFilter: 'iso', //iso;jpg;jpeg;
|
||||
onInit: function(){
|
||||
clonos.add_log('Penguin initialized :)');
|
||||
},
|
||||
onBeforeUpload: function(id){
|
||||
//add_log('Starting the upload of #' + id);
|
||||
|
||||
clonos.update_file_status(id, 'uploading', 'Uploading...');
|
||||
},
|
||||
onNewFile: function(id, file){
|
||||
clonos.add_log('New file added to queue #' + id);
|
||||
|
||||
clonos.add_file(id, file);
|
||||
},
|
||||
onComplete: function(){
|
||||
clonos.add_log('All pending tranfers finished');
|
||||
},
|
||||
onUploadProgress: function(id, percent){
|
||||
var percentStr = percent + '%';
|
||||
clonos.update_file_progress(id, percentStr);
|
||||
},
|
||||
onUploadSuccess: function(id, data){
|
||||
clonos.add_log('Upload of file #p-' + id + ' completed');
|
||||
|
||||
clonos.add_log('Server Response for file #' + id + ': ' + JSON.stringify(data));
|
||||
|
||||
clonos.update_file_status(id, 'success', 'Upload Complete');
|
||||
|
||||
//clonos.update_file_progress(id, '0');
|
||||
//window.setTimeout($.proxy(this.deleteItemsOk,this,id),2000);
|
||||
setTimeout($.proxy(clonos.delete_file,this,id),3000);
|
||||
clonos.dataReload();
|
||||
},
|
||||
onUploadError: function(id, message){
|
||||
clonos.add_log('Failed to Upload file #p-' + id + ': ' + message);
|
||||
|
||||
clonos.update_file_status(id, 'error', message);
|
||||
},
|
||||
onFileTypeError: function(file){
|
||||
clonos.notify('File \'' + file.name + '\' cannot be added: must be an ISO','error');
|
||||
},
|
||||
onFileSizeError: function(file){
|
||||
clonos.notify('File \'' + file.name + '\' cannot be added: size excess limit','error');
|
||||
},
|
||||
onFileExtError: function(file){
|
||||
clonos.notify('File \'' + file.name + '\' has a Not Allowed Extension','error');
|
||||
},
|
||||
onFallbackMode: function(message){
|
||||
alert('Browser not supported(do something else here!): ' + message);
|
||||
}
|
||||
});
|
||||
},
|
||||
update_file_status:function(id,type,message)
|
||||
{
|
||||
console.log(message);
|
||||
if(type=='error')
|
||||
{
|
||||
this.notify(message,'error');
|
||||
$('#p-'+id+'.line').css('background-color','red');
|
||||
}
|
||||
if(type=='success')
|
||||
{
|
||||
$('#p-'+id+'.line').css('background-color','green');
|
||||
}
|
||||
},
|
||||
update_file_progress:function(id, percent)
|
||||
{
|
||||
$('#p-'+id+'.line').width(percent);
|
||||
console.log(percent);
|
||||
},
|
||||
add_log:function(message)
|
||||
{
|
||||
console.log(message);
|
||||
},
|
||||
add_file:function(id, file)
|
||||
{
|
||||
$('.uploader-progress').append('<div class="file" id="f-'+id+'"><div class="file-name">'+file.name+'</div><div id="p-'+id+'" class="line"></div></div>');
|
||||
},
|
||||
delete_file:function(id)
|
||||
{
|
||||
$('.uploader-progress #f-'+id).remove();
|
||||
},
|
||||
|
||||
debug:function(message,data)
|
||||
{
|
||||
this.dialogClose();
|
||||
$('body').append('<div id="debug" onclick="clonos.closeDebug();"><h1>'+message+'</h1><div>'+data+'</div>');
|
||||
},
|
||||
closeDebug:function()
|
||||
{
|
||||
$('#debug').remove();
|
||||
},
|
||||
|
||||
setLang:function(event)
|
||||
{
|
||||
var target=event.target;
|
||||
var lang=$(target).val();
|
||||
if(localStorage)
|
||||
{
|
||||
//localStorage['lang']=lang;
|
||||
}
|
||||
document.cookie="lang="+lang+";path=/;";
|
||||
location.reload();
|
||||
},
|
||||
}
|
||||
|
||||
function isset(varr){for(a in arguments){if(typeof arguments[a]=='undefined')return false;}return true;}
|
||||
|
||||
function ws_debug(){
|
||||
var res=prompt('Введите JSON строку','');
|
||||
if(res=='' || res==null) return;
|
||||
var data=JSON.parse(res);
|
||||
clonos.onChangeStatus(data);
|
||||
}
|
||||
|
||||
|
||||
$(window).on('load',function(){clonos.start();});
|
||||
|
||||
9
public/js/dmuploader.js
Normal file
9
public/js/dmuploader.js
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* dmuploader.min.js - Jquery File Uploader - 0.1
|
||||
* http://www.daniel.com.uy/projects/jquery-file-uploader/
|
||||
*
|
||||
* Copyright (c) 2013 Daniel Morales
|
||||
* Dual licensed under the MIT and GPL licenses.
|
||||
* http://www.daniel.com.uy/doc/license/
|
||||
*/
|
||||
(function(t){var n="dmUploader";var r={url:document.URL,method:"POST",extraData:{},maxFileSize:0,allowedTypes:"*",extFilter:null,dataType:null,fileName:"file",onInit:function(){},onFallbackMode:function(){message},onNewFile:function(e,t){},onBeforeUpload:function(e){},onComplete:function(){},onUploadProgress:function(e,t){},onUploadSuccess:function(e,t){},onUploadError:function(e,t){},onFileTypeError:function(e){},onFileSizeError:function(e){},onFileExtError:function(e){}};var i=function(e,n){this.element=t(e);this.settings=t.extend({},r,n);if(!this.checkBrowser()){return false}this.init();return true};i.prototype.checkBrowser=function(){if(window.FormData===undefined){this.settings.onFallbackMode.call(this.element,"Browser doesn't support Form API");return false}if(this.element.find("input[type=file]").length>0){return true}if(!this.checkEvent("drop",this.element)||!this.checkEvent("dragstart",this.element)){this.settings.onFallbackMode.call(this.element,"Browser doesn't support Ajax Drag and Drop");return false}return true};i.prototype.checkEvent=function(e,t){var t=t||document.createElement("div");var e="on"+e;var n=e in t;if(!n){if(!t.setAttribute){t=document.createElement("div")}if(t.setAttribute&&t.removeAttribute){t.setAttribute(e,"");n=typeof t[e]=="function";if(typeof t[e]!="undefined"){t[e]=undefined}t.removeAttribute(e)}}t=null;return n};i.prototype.init=function(){var e=this;e.queue=new Array;e.queuePos=-1;e.queueRunning=false;e.element.on("drop",function(t){t.preventDefault();var n=t.originalEvent.dataTransfer.files;e.queueFiles(n)});e.element.find("input[type=file]").on("change",function(n){var r=n.target.files;e.queueFiles(r);t(this).val("")});this.settings.onInit.call(this.element)};i.prototype.queueFiles=function(e){var n=this.queue.length;for(var r=0;r<e.length;r++){var i=e[r];if(this.settings.maxFileSize>0&&i.size>this.settings.maxFileSize){this.settings.onFileSizeError.call(this.element,i);continue}if(this.settings.allowedTypes!="*"&&!i.type.match(this.settings.allowedTypes)){this.settings.onFileTypeError.call(this.element,i);continue}if(this.settings.extFilter!=null){var s=this.settings.extFilter.toLowerCase().split(";");var o=i.name.toLowerCase().split(".").pop();if(t.inArray(o,s)<0){this.settings.onFileExtError.call(this.element,i);continue}}this.queue.push(i);var u=this.queue.length-1;this.settings.onNewFile.call(this.element,u,i)}if(this.queueRunning){return false}if(this.queue.length==n){return false}this.processQueue();return true};i.prototype.processQueue=function(){var n=this;n.queuePos++;if(n.queuePos>=n.queue.length){n.settings.onComplete.call(n.element);n.queuePos=n.queue.length-1;n.queueRunning=false;return}var r=n.queue[n.queuePos];var i=new FormData;i.append(n.settings.fileName,r);n.settings.onBeforeUpload.call(n.element,n.queuePos);t.each(n.settings.extraData,function(e,t){i.append(e,t)});n.queueRunning=true;t.ajax({url:n.settings.url,type:n.settings.method,dataType:n.settings.dataType,data:i,cache:false,contentType:false,processData:false,forceSync:false,xhr:function(){var r=t.ajaxSettings.xhr();if(r.upload){r.upload.addEventListener("progress",function(t){var r=0;var i=t.loaded||t.position;var s=t.total||e.totalSize;if(t.lengthComputable){r=Math.ceil(i/s*100)}n.settings.onUploadProgress.call(n.element,n.queuePos,r)},false)}return r},success:function(e,t,r){n.settings.onUploadSuccess.call(n.element,n.queuePos,e)},error:function(e,t,r){n.settings.onUploadError.call(n.element,n.queuePos,r)},complete:function(e,t){n.processQueue()}})};t.fn.dmUploader=function(e){return this.each(function(){if(!t.data(this,n)){t.data(this,n,new i(this,e))}})};t(document).on("dragenter",function(e){e.stopPropagation();e.preventDefault()});t(document).on("dragover",function(e){e.stopPropagation();e.preventDefault()});t(document).on("drop",function(e){e.stopPropagation();e.preventDefault()})})(jQuery)
|
||||
@@ -42,6 +42,12 @@ clonos.lang={
|
||||
"Rename":"Переименовать",
|
||||
"Renaming":"Переименовываем",
|
||||
"Renamed":"Переименовано",
|
||||
"Fetch":"Получить",
|
||||
"Fetching":"Получаем",
|
||||
"Fetched":"Получено",
|
||||
"Compile":"Собрать",
|
||||
"Compiling":"Собираем",
|
||||
"Compiled":"Собрано",
|
||||
|
||||
//"Create jail":"Создание контейнера",
|
||||
//"Edit jail":"Редактирование параметров контейнера",
|
||||
|
||||
@@ -8,6 +8,7 @@ $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']);
|
||||
@@ -26,24 +27,24 @@ if(!empty($nodes))foreach($nodes as $node)
|
||||
}
|
||||
|
||||
$ids[]=$base['idx'];
|
||||
$bid=$base['ver'].'-'.$base['arch'].'-'.$base['stable'];
|
||||
$id='base'.$base['ver'].'-'.$base['arch'].'-'.$base['stable'];
|
||||
|
||||
$hres=$this->getTableChunk('baseslist','tbody');
|
||||
if($hres!==false)
|
||||
{
|
||||
$html_tpl=$hres[1];
|
||||
$vars=array(
|
||||
'bid'=>$bid,
|
||||
'id'=>$id,
|
||||
'nth-num'=>'nth'.$num,
|
||||
'node'=>$node['nodename'],
|
||||
'name'=>$base['name'],
|
||||
'platform'=>$base['platform'],
|
||||
'arch'=>$base['arch'],
|
||||
'targetarch'=>$base['targetarch'],
|
||||
'ver'=>$base['ver'],
|
||||
'stable'=>($base['stable']==1)?'stable':'release',
|
||||
'version'=>$base['ver'],
|
||||
'version1'=>($base['stable']==1)?'stable':'release',
|
||||
'elf'=>$base['elf'],
|
||||
'date'=>$base['date'],
|
||||
'jstatus'=>'',
|
||||
'maintenance'=>($idle==0)?' maintenance':'',
|
||||
'deltitle'=>$this->translate('Delete'),
|
||||
);
|
||||
@@ -54,23 +55,45 @@ if(!empty($nodes))foreach($nodes as $node)
|
||||
$html.=$html_tpl;
|
||||
}
|
||||
|
||||
$ids[]='#base'.$bid;
|
||||
//$ids[]='#base'.$bid;
|
||||
$ids[]='#'.$id;
|
||||
}
|
||||
|
||||
$nth++;
|
||||
}
|
||||
}
|
||||
|
||||
$html=str_replace(array("\n","\r","\t"),'',$html);
|
||||
|
||||
$tasks='';
|
||||
if(!empty($ids))
|
||||
{
|
||||
$tasks=$this->getRunningTasks($ids);
|
||||
}
|
||||
|
||||
$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,
|
||||
));
|
||||
@@ -1,16 +1,16 @@
|
||||
<tbody>
|
||||
<tr class="#nth-num##maintenance#" id="#name##bid#">
|
||||
<td class="wordwreck">#node#</td>
|
||||
<td class="txtleft">#name#</td>
|
||||
<td class="txtleft">#platform#</td>
|
||||
<td>#arch#</td>
|
||||
<td>#targetarch#</td>
|
||||
<td class="version">#ver#</td>
|
||||
<td class="txtleft">#stable#</td>
|
||||
<td>#elf#</td>
|
||||
<td class="small">#date#</td>
|
||||
<tr class="#nth-num##maintenance#" id="#id#"> <!-- #name# -->
|
||||
<td class="wordwreck node">#node#</td>
|
||||
<td class="txtleft name">#name#</td>
|
||||
<td class="txtleft platform">#platform#</td>
|
||||
<td class="arch">#arch#</td>
|
||||
<td class="targetarch">#targetarch#</td>
|
||||
<td class="version">#version#</td>
|
||||
<td class="txtleft version1">#version1#</td>
|
||||
<td class="elf">#elf#</td>
|
||||
<td class="small date">#date#</td>
|
||||
<td width="5" class="ops op-del" title="#deltitle#"><span class="icon-cancel"></span></td>
|
||||
<td class="ops"><span class="icon-cnt"><span></span></span></td>
|
||||
<td class="jstatus wdt-90"></td>
|
||||
<td class="jstatus wdt-90">#jstatus#</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -13,6 +13,7 @@ $allnodes=array();
|
||||
|
||||
$jail_ids=array();
|
||||
$nth=0;
|
||||
$hres=$this->getTableChunk('bhyveslist','tbody');
|
||||
if(!empty($nodes))foreach($nodes as $node)
|
||||
{
|
||||
$db1=new Db('base',$node);
|
||||
@@ -25,7 +26,6 @@ if(!empty($nodes))foreach($nodes as $node)
|
||||
if(!empty($bhyves)) foreach($bhyves as $bhyve)
|
||||
{
|
||||
|
||||
$hres=$this->getTableChunk('bhyveslist','tbody');
|
||||
if($hres!==false)
|
||||
{
|
||||
$html_tpl=$hres[1];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<tr class="#nth-num##desktop##maintenance#" id="#jname#">
|
||||
<td class="node">#node#</td>
|
||||
<td class="txtleft jname">#jname#</td>
|
||||
<td class="txtleft vm_ram">#vm_ram#</td>
|
||||
<td class="txtcenter vm_ram">#vm_ram#</td>
|
||||
<td class="vm_cpus">#vm_cpus#</td>
|
||||
<td class="vm_os_type">#vm_os_type#</td>
|
||||
<td class="jstatus">#vm_status#</td>
|
||||
|
||||
@@ -19,10 +19,10 @@ $clonos->useDialogs(array(
|
||||
<thead>
|
||||
<th class="wdt-120">Имя сервера</th>
|
||||
<th class="txtleft">Виртуальная машина</th>
|
||||
<th class="txtleft wdt-70">RAM</th>
|
||||
<th class="txtcenter wdt-70">RAM</th>
|
||||
<th class="wdt-30">CPU</th>
|
||||
<th class="wdt-100">Тип ОС</th>
|
||||
<th class="wdt-120">Статус</th>
|
||||
<th class="txtcenter wdt-100">Тип ОС</th>
|
||||
<th class="txtcenter wdt-120">Статус</th>
|
||||
<th colspan="4" class="wdt-100">Действия</th>
|
||||
<th class="wdt-30">VNC</th>
|
||||
</thead>
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
$hash=$this->url_hash; //=preg_replace('/^#/','',$this->_vars['hash']);
|
||||
|
||||
$db_path=false;
|
||||
if(isset($this->_vars['db_path']) && !empty($this->_vars['db_path']))
|
||||
if(!isset($this->_vars['db_path']))
|
||||
{
|
||||
$db_path=$this->_vars['db_path'];
|
||||
//$db_path=$this->_vars['db_path'];
|
||||
$res=$this->cbsd_cmd('make_tmp_helper module='.$hash);
|
||||
if($res['retval']==0)
|
||||
{
|
||||
$db_path=$res['message'];
|
||||
}else{
|
||||
echo json_encode(array('error'=>true,'errorMessage'=>'Error on open temporary form file!'));
|
||||
echo json_encode(array('error'=>true,'errorMessage'=>'Error on open temporary form database!'));
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
$db_path=$this->_vars['db_path'];
|
||||
}
|
||||
|
||||
$form=new Forms('',$hash,$db_path);
|
||||
|
||||
@@ -22,6 +22,7 @@ $allnodes=array();
|
||||
|
||||
$jail_ids=array();
|
||||
$nth=0;
|
||||
$hres=$this->getTableChunk('jailslist','tbody');
|
||||
if(!empty($nodes))foreach($nodes as $node)
|
||||
{
|
||||
$db1=new Db('base',$node);
|
||||
@@ -33,8 +34,6 @@ if(!empty($nodes))foreach($nodes as $node)
|
||||
$num=$nth & 1;
|
||||
if(!empty($jails)) foreach($jails as $jail)
|
||||
{
|
||||
|
||||
$hres=$this->getTableChunk('jailslist','tbody');
|
||||
if($hres!==false)
|
||||
{
|
||||
$html_tpl=$hres[1];
|
||||
|
||||
@@ -91,7 +91,7 @@ if(empty($hash))
|
||||
$db_path=$db->getFileName();
|
||||
$form=new Forms($jail_name,$hash,$db_path);
|
||||
$res=$form->generate();
|
||||
$res['html']='<h1>'.$this->translate('Helper settings').'</h1>'.$res['html'];
|
||||
$res['html']='<h1>'.$this->translate('Helper settings: '.$hash).'</h1>'.$res['html'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ $clonos->useDialogs(array(
|
||||
<th class="wdt-200 elastic">Имя сервера</th>
|
||||
<th class="txtleft">Контейнер</th>
|
||||
<th class="txtleft wdt-200">IP-адрес</th>
|
||||
<th class="wdt-120">Статус</th>
|
||||
<th class="txtcenter wdt-120">Статус</th>
|
||||
<th colspan="4" class="wdt-100">Действия</th>
|
||||
<th class="wdt-30">VNC</th>
|
||||
</tr>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
$db=new Db('base','storage_media');
|
||||
$res=$db->select('SELECT idx,name,path FROM media');
|
||||
$res=$db->select('SELECT idx,name,path,jname FROM media where type="iso"');
|
||||
|
||||
$html='';
|
||||
if($res!==false)
|
||||
@@ -20,6 +20,7 @@ if($res!==false)
|
||||
'mediaid'=>$item['idx'],
|
||||
'medianame'=>$item['name'],
|
||||
'mediapath'=>$item['path'],
|
||||
'jname'=>$item['jname'],
|
||||
'deltitle'=>' title="'.$this->translate('Delete').'"',
|
||||
);
|
||||
|
||||
|
||||
@@ -2,19 +2,22 @@
|
||||
$section_name='media';
|
||||
|
||||
$clonos->useDialogs(array(
|
||||
$section_name,
|
||||
//$section_name,
|
||||
'media-upload',
|
||||
));
|
||||
?>
|
||||
<h1>Subnet list</h1>
|
||||
<h1>Virtual media list</h1>
|
||||
|
||||
<p>
|
||||
<span class="top-button icon-plus id:<?php echo $section_name;?>">Add ISO</span>
|
||||
<!-- <span class="top-button icon-plus id:<?php echo $section_name;?>">Info</span> -->
|
||||
<span class="top-button icon-plus id:media-upload">Upload ISO</span>
|
||||
</p>
|
||||
|
||||
<table class="tsimple" id="<?php echo $section_name;?>slist" width="100%">
|
||||
<thead>
|
||||
<td class="wdt-200 keyname">Storage name</td>
|
||||
<td class="wdt-200 keyname">Name of the disk</td>
|
||||
<td class="txtleft">Path</td>
|
||||
<td class="txtleft wdt-80">VM</td>
|
||||
<td class="wdt-80">Action</td>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<tr id="#mediaid#">
|
||||
<td class="txtleft">#medianame#</td>
|
||||
<td class="txtleft wordwreck"><span class="max-100">#mediapath#</span></td>
|
||||
<td class="txtleft">#jname#</td>
|
||||
<td class="ops">
|
||||
<span#deltitle# class="icon-cancel"></span>
|
||||
</td>
|
||||
|
||||
@@ -2,19 +2,22 @@
|
||||
$section_name='media';
|
||||
|
||||
$clonos->useDialogs(array(
|
||||
$section_name,
|
||||
//$section_name,
|
||||
'media-upload',
|
||||
));
|
||||
?>
|
||||
<h1>Список подсетей</h1>
|
||||
<h1>Список виртуальных дисков</h1>
|
||||
|
||||
<p>
|
||||
<span class="top-button icon-plus id:<?php echo $section_name;?>">Добавить ISO</span>
|
||||
<!-- <span class="top-button icon-plus id:<?php echo $section_name;?>">Info</span> -->
|
||||
<span class="top-button icon-plus id:media-upload">Добавить ISO</span>
|
||||
</p>
|
||||
|
||||
<table class="tsimple" id="<?php echo $section_name;?>slist" width="100%">
|
||||
<thead>
|
||||
<td class="wdt-200 keyname">Имя носителя</td>
|
||||
<td class="txtleft">Путь</td>
|
||||
<td class="txtleft wdt-80">Клетка/VM</td>
|
||||
<td class="wdt-80">Действия</td>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<table class="tfill">
|
||||
<thead>
|
||||
<tr>
|
||||
<td width="200">Item</td><td width="200">Value</td>
|
||||
<td width="200">Param</td><td width="200">Values</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -14,7 +14,7 @@
|
||||
<tr><td>Num of cores:</td><td id="num-cores"></td></tr>
|
||||
<tr><td>Average freq. Mhz:</td><td id="average"></td></tr>
|
||||
<tr><td>Summary RAM:</td><td id="sum-ram"></td></tr>
|
||||
<tr><td>Summary Storage:</td><td id="sum-storage"></td></tr>
|
||||
<tr><td>Summary storage size:</td><td id="sum-storage"></td></tr>
|
||||
</tbody>
|
||||
<tbody class="error" style="display:none;">
|
||||
<tr><td colspan="2" class="error_message">Unable to fetch net info!</td></tr>
|
||||
@@ -23,216 +23,13 @@
|
||||
<p>It is an open source and free product which powered by other project (major importance list):</p>
|
||||
<ul>
|
||||
<li><a href="https://www.bsdstore.ru/" target="_blank">CBSD Project</a> — FreeBSD OS virtual environment management framework</li>
|
||||
<li><a href="https://www.freebsd.org/" target="_blank">FreeBSD Project</a> — FreeBSD is a free and open source Unix-like operating system descended from Research Unix created in <a href="https://en.wikipedia.org/wiki/Berkeley_Software_Distribution">University of California, Berkeley, U.S.</a></li>
|
||||
<li><a href="https://www.freebsd.org/" target="_blank">FreeBSD Project</a> — FreeBSD is a free and open source Unix-like operating system descended from Research Unix created in <a href="https://en.wikipedia.org/wiki/Berkeley_Software_Distribution">University of California, Berkeley, U.S.</li>
|
||||
<li><a href="https://puppet.com/" target="_blank">Puppet</a> — Puppet is an open-source configuration management tool.</li>
|
||||
<li>and many other..</li>
|
||||
</ul>
|
||||
<?php
|
||||
|
||||
|
||||
return;
|
||||
echo '<pre>';
|
||||
print_r($wd->getHello());
|
||||
|
||||
return;
|
||||
|
||||
function fetch_node_inv($dbfilepath)
|
||||
{
|
||||
global $allncpu, $allcpufreq, $allphysmem, $allnodes, $nodetable, $alljails, $knownfreq, $workdir;
|
||||
|
||||
$stat = file_exists($dbfilepath);
|
||||
|
||||
if (!$stat) {
|
||||
$nodetable .= "<tr><td bgcolor=\"#CCFFCC\">$allnodes</td><td colspan=10><center>$dbfilepath not found</center></td></tr>";
|
||||
return 0;
|
||||
}
|
||||
|
||||
$db = new SQLite3($dbfilepath); $db->busyTimeout(5000);
|
||||
$results = $db->query('SELECT COUNT(*) FROM jails;');
|
||||
|
||||
if (!($results instanceof Sqlite3Result)) {
|
||||
$numjails=0;
|
||||
} else {
|
||||
while ($row = $results->fetchArray()) {
|
||||
$numjails=$row[0];
|
||||
}
|
||||
}
|
||||
|
||||
$gwinfo="";
|
||||
|
||||
$netres = $db->query('SELECT ip4,ip6,mask4,mask6 FROM net;');
|
||||
|
||||
if (!($netres instanceof Sqlite3Result)) {
|
||||
echo "Error: $dbfilepath";
|
||||
$gwinfo="unable to fetch net info";
|
||||
} else {
|
||||
while ($row = $netres->fetchArray()) {
|
||||
for ($i=0;$i<4;$i++)
|
||||
if (isset($row[$i])) $gwinfo.= $row[$i]." ";
|
||||
}
|
||||
}
|
||||
|
||||
$netres = $db->query('select * from gw;');
|
||||
|
||||
if (!($netres instanceof Sqlite3Result)) {
|
||||
} else {
|
||||
while ($row = $netres->fetchArray()) {
|
||||
for ($i=0;$i<4;$i++)
|
||||
if (isset($row[$i])) $gwinfo.= $row[$i]." ";
|
||||
}
|
||||
}
|
||||
|
||||
$results = $db->query('SELECT nodename,nodeip,fs,ncpu,physmem,cpufreq,osrelease FROM local;');
|
||||
if (!($results instanceof Sqlite3Result)) {
|
||||
$nodetable .=<<<EOF
|
||||
<tr>
|
||||
<td bgcolor="#CCFFCC">$allnodes</td><td colspan=10></td>
|
||||
</tr>
|
||||
EOF;
|
||||
} else {
|
||||
while ($row = $results->fetchArray()) {
|
||||
list($nodename, $nodeip, $fs, $ncpu, $physmem, $cpufreq, $osrelease) = $row;
|
||||
$descrfile=$workdir."/var/db/nodedescr/".$nodename.".descr";
|
||||
$desc="";
|
||||
if (file_exists($descrfile)) {
|
||||
$fp = fopen($descrfile, "r");
|
||||
$size = filesize($descrfile);
|
||||
if ($size>0)
|
||||
$desc = fread($fp, filesize($descrfile));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
$locfile=$workdir."/var/db/nodedescr/".$nodename.".location";
|
||||
$loc="";
|
||||
|
||||
if (file_exists($locfile)) {
|
||||
$fp = fopen($locfile, "r");
|
||||
$size = filesize($locfile);
|
||||
if ($size>0)
|
||||
$loc = fread($fp, filesize($locfile));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
$notesfile=$workdir."/var/db/nodedescr/".$nodename.".notes";
|
||||
$notes="";
|
||||
|
||||
if (file_exists($notesfile)) {
|
||||
$fp = fopen($notesfile, "r");
|
||||
$size = filesize($notesfile);
|
||||
if ($size>0)
|
||||
$notes = fread($fp, filesize($notesfile));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
$nodetable .=<<<EOF
|
||||
<tr rel="{$nodename}">
|
||||
<td bgcolor="#CCFFCC" class="node-name" data-file="descr" data-type="text">$nodename</td>
|
||||
<td data-togle="toolkip" title="$gwinfo">$nodeip</td>
|
||||
<td class="edited" data-file="descr" data-type="textarea">$desc</td>
|
||||
<td class="edited" data-file="location" data-type="text">$loc</td>
|
||||
<td>$osrelease</td>
|
||||
<td>$fs</td>
|
||||
<td>$physmem</td>
|
||||
<td>$ncpu</td>
|
||||
<td>$cpufreq</td>
|
||||
<td>$numjails</td>
|
||||
<td class="edited" data-file="notes" data-type="textarea">$notes</td>
|
||||
</tr>
|
||||
EOF;
|
||||
$allncpu+=$ncpu;
|
||||
$allphysmem+=$physmem;
|
||||
$allcpufreq+=$cpufreq;
|
||||
$alljails+=$numjails;
|
||||
if ($cpufreq>1) $knownfreq++;
|
||||
}
|
||||
}
|
||||
$db->close();
|
||||
}
|
||||
|
||||
|
||||
function show_overview($workdir)
|
||||
{
|
||||
global $allncpu, $allcpufreq, $allphysmem, $allnodes, $nodetable, $alljails, $knownfreq, $workdir;
|
||||
echo "<strong>Summary statistics for cloud:</strong>";
|
||||
|
||||
$allncpu=0;
|
||||
$allcpufreq=0;
|
||||
$allphysmem=0;
|
||||
$allnodes=0;
|
||||
$nodetable="";
|
||||
$alljails=0;
|
||||
$knownfreq=0;
|
||||
$offlinenodes=0;
|
||||
|
||||
$db = new SQLite3("$workdir/var/db/nodes.sqlite"); $db->busyTimeout(5000);
|
||||
$sql = "SELECT nodename,ip FROM nodelist";
|
||||
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
|
||||
$row = array();
|
||||
$i = 0;
|
||||
|
||||
while($res = $result->fetchArray(SQLITE3_ASSOC)){
|
||||
if(!isset($res['nodename'])) continue;
|
||||
$nodename = $res['nodename'];
|
||||
$nodeip = $res['ip'];
|
||||
++$allnodes;
|
||||
$path=$workdir."/var/db/";
|
||||
$postfix=".sqlite";
|
||||
$dbpath=$path.chop($nodename).$postfix;
|
||||
|
||||
$idle=check_locktime($nodeip);
|
||||
|
||||
if ( $idle == 0 ) {
|
||||
$offlinenodes++;
|
||||
}
|
||||
|
||||
fetch_node_inv($dbpath);
|
||||
}
|
||||
|
||||
fetch_node_inv($workdir."/var/db/local.sqlite");
|
||||
|
||||
if ( $offlinenodes == 0 ) {
|
||||
$offlinecolor="#FFFF99";
|
||||
} else {
|
||||
$offlinecolor="#FF9B77";
|
||||
}
|
||||
|
||||
|
||||
if ( $knownfreq > 0 ) {
|
||||
$avgfreq=round($allcpufreq / $knownfreq);
|
||||
} else {
|
||||
$avgfreq=0;
|
||||
}
|
||||
|
||||
$outstr=<<<EOF
|
||||
<table>
|
||||
<tr>
|
||||
<td bgcolor="#00FF00">Num of nodes:</td><td bgcolor="#FFFF99">$allnodes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#00FF00">Online nodes:</td><td bgcolor="#FFFF99">$allnodes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="$offlinecolor">Offline nodes:</td><td bgcolor="$offlinecolor">$offlinenodes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#00FF00">Num of jails:</td><td bgcolor="#FFFF99">$alljails</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#00FF00">Num of core:</td><td bgcolor="#FFFF99">$allncpu</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#00FF00">Average freq. Mhz:</td><td bgcolor="#FFFF99">$avgfreq</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#00FF00">Summary RAM:</td><td bgcolor="#FFFF99">$allphysmem</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#00FF00">Summary Storage:</td><td bgcolor="#FFFF99">Unknown</td>
|
||||
</tr>
|
||||
</table>
|
||||
EOF;
|
||||
|
||||
echo $outstr;
|
||||
}
|
||||
|
||||
show_overview($wd->workdir);
|
||||
<!--
|
||||
CHAT:
|
||||
<input type="text" id="wsinp" />
|
||||
<input type="button" onclick="clonos.wssend($('#wsinp').val());$('#wsinp').val('');" value="Send" />
|
||||
-->
|
||||
7
public/pages/settings/en.index.php
Normal file
7
public/pages/settings/en.index.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<h1>ClonOS Settings</h1>
|
||||
<?php
|
||||
|
||||
$form=new Forms('cbsd-settings');
|
||||
$res=$form->generate();
|
||||
|
||||
echo $res['html'];
|
||||
@@ -1,4 +1,4 @@
|
||||
<h1>Настройки CBSD</h1>
|
||||
<h1>Настройки ClonOS</h1>
|
||||
<?php
|
||||
|
||||
$form=new Forms('cbsd-settings');
|
||||
|
||||
@@ -8,6 +8,7 @@ $nodes=array_reverse($nodes);
|
||||
|
||||
$ids=array();
|
||||
$nth=0;
|
||||
$hres=$this->getTableChunk('srcslist','tbody');
|
||||
if(!empty($nodes))foreach($nodes as $node)
|
||||
{
|
||||
$db1=new Db('base',$node['nodename']);
|
||||
@@ -25,7 +26,6 @@ if(!empty($nodes))foreach($nodes as $node)
|
||||
$idle=$this->check_locktime($node['ip']);
|
||||
}
|
||||
|
||||
$hres=$this->getTableChunk('srcslist','tbody');
|
||||
if($hres!==false)
|
||||
{
|
||||
$html_tpl=$hres[1];
|
||||
@@ -35,10 +35,12 @@ if(!empty($nodes))foreach($nodes as $node)
|
||||
'node'=>$node['nodename'],
|
||||
'name'=>$base['name'],
|
||||
'platform'=>$base['platform'],
|
||||
'ver'=>$base['ver'],
|
||||
'ver1'=>$vers,
|
||||
'version'=>$base['ver'],
|
||||
'version1'=>$vers,
|
||||
'rev'=>$base['rev'],
|
||||
'date'=>$base['date'],
|
||||
'jstatus'=>'',
|
||||
'icon'=>'',
|
||||
'maintenance'=>($idle==0)?' maintenance':'',
|
||||
'deltitle'=>$this->translate('Delete'),
|
||||
'updtitle'=>$this->translate('Update'),
|
||||
@@ -57,16 +59,37 @@ if(!empty($nodes))foreach($nodes as $node)
|
||||
}
|
||||
}
|
||||
|
||||
$html=str_replace(array("\n","\r","\t"),'',$html);
|
||||
|
||||
$tasks='';
|
||||
if(!empty($ids))
|
||||
{
|
||||
$tasks=$this->getRunningTasks($ids);
|
||||
}
|
||||
|
||||
$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'=>'srcslist',
|
||||
'tasks'=>$tasks,
|
||||
'template'=>$html_tpl,
|
||||
));
|
||||
@@ -1,14 +1,14 @@
|
||||
<tbody>
|
||||
<tr class="#nth-num##maintenance#" id="src#ver#">
|
||||
<td class="wordwreck">#node#</td>
|
||||
<tr class="#nth-num##maintenance#" id="src#version#">
|
||||
<td class="wordwreck node">#node#</td>
|
||||
<!--td class="txtleft">#platform#</td-->
|
||||
<td class="version">#ver#</td>
|
||||
<td class="version1">#ver1#</td>
|
||||
<td class="txtleft nowrap">#rev#</td>
|
||||
<td class="small">#date#</td>
|
||||
<td class="ops op-update" title="#updtitle#"><span class="icon-arrows-cw"></span></td>
|
||||
<td class="ops op-del" title="#deltitle#"><span class="icon-cancel"></span></td>
|
||||
<td class="version">#version#</td>
|
||||
<td class="version1">#version1#</td>
|
||||
<td class="txtleft nowrap rev">#rev#</td>
|
||||
<td class="small date">#date#</td>
|
||||
<td class="op-update" title="#updtitle#"><span class="icon-arrows-cw"></span></td>
|
||||
<td class="op-del" title="#deltitle#"><span class="icon-cancel"></span></td>
|
||||
<td class="ops"><span class="icon-cnt"><span></span></span></td>
|
||||
<td class="jstatus"></td>
|
||||
<td class="jstatus">#jstatus#</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -57,6 +57,9 @@ vm_efi="uefi";
|
||||
#iso_img=""; # must be merged from CBSD profiles
|
||||
#register_iso_name="" # must be merged from CBSD profiles
|
||||
#register_iso_as="" # must be merged from CBSD profiles
|
||||
#register_iso_name# # template for iso name variable
|
||||
#register_iso_as# # template for iso path variable
|
||||
#iso_var_block# # template for block of vars: iso_extract, iso_img_dist, iso_img, iso_site
|
||||
|
||||
#vm_hostbridge="hostbridge"; # must be merged from CBSD profiles
|
||||
#bhyve_flags=""; # must be merged from CBSD profiles
|
||||
|
||||
77
public/upload.php
Normal file
77
public/upload.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] === 'POST')
|
||||
{
|
||||
$path=realpath('').'/media/';
|
||||
if(is_uploaded_file($_FILES['file']['tmp_name']))
|
||||
{
|
||||
$ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
|
||||
$file = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_FILENAME));
|
||||
$uid = uniqid();
|
||||
$date = time();
|
||||
|
||||
$returnJson[]=array('filepath'=>$path);
|
||||
|
||||
//$filename=$path.$filename.'-'.$uid.".".$ext;
|
||||
$file=$file.'.'.$ext;
|
||||
$filename=$path.$file; //.'.'.$ext;
|
||||
if (move_uploaded_file($_FILES['file']['tmp_name'], $filename))
|
||||
{
|
||||
$status = 'ok'; //'Successfully uploaded!';
|
||||
}else{
|
||||
$status = 'Upload Fail: Unknown error occurred!';
|
||||
}
|
||||
}
|
||||
}
|
||||
if($status!='ok') {echo json_encode(array('status' => $status));exit;}
|
||||
return;
|
||||
|
||||
$valid_exts = array('image/jpeg', 'image/jpg', 'image/png', 'image/gif'); // valid extensions
|
||||
$max_size = 30000 * 1024; // max file size in bytes
|
||||
|
||||
$json = array();
|
||||
if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
|
||||
{
|
||||
for($i=0;$i<count($_FILES['file']['tmp_name']);$i++)
|
||||
{
|
||||
$path="/media/";
|
||||
|
||||
if(is_uploaded_file($_FILES['file']['tmp_name'][$i]) )
|
||||
{
|
||||
// get uploaded file extension
|
||||
$ext = strtolower(pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION));
|
||||
// looking for format and size validity
|
||||
if (in_array($ext, $valid_exts) AND $_FILES['file']['size'][$i] < $max_size)
|
||||
{
|
||||
// unique file path
|
||||
$uid = uniqid();
|
||||
$date = date('Y-m-d-H-i-s');
|
||||
$path = $path ."image_" .$date. '_' . $uid . "." .$ext;
|
||||
|
||||
$returnJson[]= array("filepath"=>$path);
|
||||
|
||||
$filename = "image_" . $date . "_" .$uid . "." . $ext;
|
||||
//$this->createthumb($i,$filename);
|
||||
|
||||
// move uploaded file from temp to uploads directory
|
||||
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $path))
|
||||
{
|
||||
$status = 'ok'; //'Successfully uploaded!';
|
||||
//perform sql updates here
|
||||
}else{
|
||||
$status = 'Upload Fail: Unknown error occurred!';
|
||||
}
|
||||
}else{
|
||||
$status = 'Upload Fail: Unsupported file format or It is too large to upload!';
|
||||
}
|
||||
}else{
|
||||
$status = 'Upload Fail: File not uploaded!';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$status = 'Bad request!';
|
||||
}
|
||||
|
||||
echo json_encode(array('status' => $status));
|
||||
//echo json_encode($json);
|
||||
Reference in New Issue
Block a user