NOVNC_PORT = 3388; IMPORT_VM_EXTENSION_PC = [".ova", ".ovf", '.qvm', '.xml']; IMPORT_VM_EXTENSION_NAS = [".ova", ".ovf", ".vmx", '.qvm', '.xml']; PERMISSION_LIMIT_CONTROL = 2; PERMISSION_LIMIT_VIEWONLY = 2; function ShowMask(bShowCancel, elemID, blackMask) { if(document.getElementById("document-mask")){ var o = document.getElementById("document-mask"); o.style.visibility = "visible"; o.style.zIndex = 10000; o.style.display = 'block'; o.style.position = 'absolute'; o.style.filter = "alpha(opacity:50)"; o.style.KHTMLOpacity = 0.8; o.style.MozOpacity = 0.8; o.style.opacity = 0.8; o.style.background = '#FFF'; o.style.height = window.innerHeight + 'px'; if (blackMask){ o.style.opacity = 0.6 o.style.background = '#000'; } if (elemID) { var rect = document.getElementById(elemID).getBoundingClientRect(); //o.style.top = rect.top + 'px'; o.style.left = rect.left + 'px'; o.style.width = (window.innerWidth-rect.left) + "px"; document.getElementById("loading-icon").style.left = ((rect.right-rect.left)/2-32) + 'px'; } else { o.style.width = window.innerWidth + "px"; document.getElementById("loading-icon").style.left = (document.body.clientWidth/2-32) + 'px'; } document.getElementById("loading-icon").style.top = ($(window).height()/2-32) + 'px'; o = document.getElementById("loading-cancel"); o.style.zIndex = 20000; o.style.display = 'block'; o.style.position = 'absolute'; o.style.height = document.getElementsByName('importvm_cancel')[0].clientHeight + 'px'; if (elemID) { var rect = document.getElementById(elemID).getBoundingClientRect(); o.style.left = (rect.left-15) + 'px'; o.style.width = (window.innerWidth-rect.left) + "px"; } else { o.style.width = window.innerWidth + "px"; } document.getElementById("loading-cancel").style.top = (document.body.clientHeight/2+52) + 'px'; document.getElementById("loading-cancel").style.visibility = bShowCancel ? 'visible':'hidden'; } } function CloseMask() { var o = document.getElementById("document-mask"); o.style.visibility = "hidden"; document.getElementById("loading-cancel").style.visibility = 'hidden'; } /* function normalConfirm(msg) { var ret = confirm(msg); if (ret) { ShowMask(); } return ret; } */ function SubmitConfirm(msg, msgTitle, submitID, sendValue, blackMask) { jConfirm(msg, msgTitle, function(r) { if(r) { if(submitID) { $('#'+submitID).val(sendValue); $('#'+submitID).click(); } } else { if(!blackMask) CloseMask(); return; } },blackMask); if(!blackMask) ShowMask(); } window.alert = function(str,_callback, blackMask) { jAlert(str, '', _callback, blackMask); } function SubmitConfirmCustom(msg, msgTitle, formID, sendID, _call_backend) { jConfirm(msg, msgTitle, function(r) { if(r) { if(_call_backend) { _call_backend(); } else { $('#'+sendID).attr("disabled", false); $('#'+formID).submit(); } } else CloseMask(); }); ShowMask(); } function wait(ms) { var start = +(new Date()); while (new Date() - start < ms); } function makeRequest(url, data, func, param, sync) { var http_request = true; if (sync=="false") sync = false; else // (typeof sync == "undefined") sync = true; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } http_request.onreadystatechange = function(){ func(http_request, param); }; if(data==''){ http_request.open('GET', url, sync); http_request.send(null); } else{ http_request.open('POST', url, sync); http_request.send(data); } } function UpdateVMState(host_id, vname, vmstate) { clearTimeout(VMStateTimer); var bExtendExpire = 0; if (typeof(bAutoLogin) !== "undefined" && bAutoLogin) { bExtendExpire = 1; } if($('#div_cpuus_text').length) // Update cpu state UpdateVMHwState(host_id, vname, vmstate); url = "/vminfo/" + host_id + "/"+ vname +"/?bExtendExpire="+bExtendExpire+"&r=" + Math.random(); makeRequest(url, '', _callbk_update_vmstate, {'host_id':host_id, 'vname':vname, 'vmstate':vmstate}); } function _callbk_update_vmstate(http_request, param) { if (http_request.readyState == 4) { if (http_request.status == 200) { var json = JSON.parse(http_request.responseText); if ((!json.success && (json.errors.indexOf('Authentication failed') != -1)) || (param.vmstate != json.state)) { window.location.href = window.location.href return; } } VMStateTimer = setTimeout(function(){UpdateVMState(param.host_id, param.vname, param.vmstate);}, 5000); } } function UpdateVMHwState(host_id, vname, vmstate) { url = "/vminfo/" + host_id + "/"+ vname +"/cpuus/?r=" + Math.random(); makeRequest(url, '', _callbk_update_vm_cpuus, vmstate); } function _callbk_update_vm_cpuus(http_request, vmstate) { if (http_request.readyState == 4) { if (http_request.status == 200) { var json = JSON.parse(http_request.responseText); var new_cpu_usg = parseInt(json.percentage,10); var old_cpu_usg = parseInt(document.getElementById('div_cpuus_text').innerHTML); if((new_cpu_usg > 10 && old_cpu_usg < 10) || (new_cpu_usg < 10 && old_cpu_usg > 10)) { var str = ''; if(new_cpu_usg > 10) str = ''+new_cpu_usg+'%'; else str = ''+new_cpu_usg+'%'; document.getElementById('div_cpuus').innerHTML = str; } else { document.getElementById('div_cpuus_bar').style.width = new_cpu_usg+'%'; document.getElementById('div_cpuus_text').innerHTML = new_cpu_usg+'%'; } } } } function UpdateTaskInfo(host_id) { clearTimeout(TaskInfoTimer); makeRequest( "/taskinfo/"+host_id+'/', '', _callbk_update_taskinfo, host_id); } function _callbk_update_taskinfo(http_request, host_id) { if (http_request.readyState == 4) { if (http_request.status == 200) { var json = JSON.parse(http_request.responseText); if (!json.success && (json.errors.indexOf('Authentication failed') != -1)) { var refreshURL=window.location.href; refreshURL=refreshURL.substr(0,refreshURL.lastIndexOf('/')); refreshURL=refreshURL.substr(0,refreshURL.lastIndexOf('/'))+'/'; window.location.href = refreshURL; return; } // show/hide export/import icon var elem = document.getElementById('task-import-icon'); var title = ""; if (elem) { elem.style.display = (json.tasks.import.running || json.tasks.import.queuing) ? '' : 'none'; if (json.tasks.import.running) { title += gettext('Running')+' : ' + json.tasks.import.running + '\n'; } if (json.tasks.import.queuing) { title += gettext('Queuing')+' : ' + json.tasks.import.queuing; } elem.title = title; } elem = document.getElementById('task-export-icon'); title = ""; if (elem) { elem.style.display = (json.tasks.export.running || json.tasks.export.queuing) ? '' : 'none'; if (json.tasks.export.running) { title += gettext('Running')+' : ' + json.tasks.export.running + '\n'; } if (json.tasks.export.queuing) { title += gettext('Queuing')+' : ' + json.tasks.export.queuing; } elem.title = title; } // show/hide vm background action icon var cloningVM = ''; for (var i=0; i 0) ? false : true; } function GetScrollbarWidth() { var parent, child, width; if (width === undefined) { parent = $('
').appendTo('body'); child = parent.children(); width = child.innerWidth() - child.height(99).innerWidth(); parent.remove(); } return width; } function MacGenerator(inputID) { var mac = "52:54:00" for (var i=0; i<3; i++) { var tmp = Math.floor(Math.random()*256).toString(16).toUpperCase(); if (tmp.length < 2) { tmp = '0' + tmp; } mac += ':' + tmp; } $('#'+inputID).css({'background-color':'','border':'', 'box-shadow': ''}); $('#'+inputID).attr('title',''); return mac; } function CreateMemSliderElement(elem_id) { var link = [256, MAX_MEMORY_VALUE/4, MAX_MEMORY_VALUE/2, MAX_MEMORY_VALUE*3/4, MAX_MEMORY_VALUE]; if (MAX_MEMORY_VALUE == 512){ link = [256, 512]; } else if (MAX_MEMORY_VALUE == 768){ link = [256, 512, 768]; } else if (MAX_MEMORY_VALUE == 1024){ link = [256, 512, 768, 1024]; } var str = ''; for (var i=0; i'+str2+''; } str += '
'; document.getElementById("memory_slider_link").innerHTML = str; } function UpdateMemorySlider(elemID, value) { var reg = /^[0-9]*$/; if (!reg.test(value)) { value = $("#slider-range-min").slider("value"); } if (value < 256) { value = 256; } else if (value > MAX_MEMORY_VALUE) { value = MAX_MEMORY_VALUE; } $("#slider-range-min").slider("value", value); if (document.getElementById(elemID).value != value) { document.getElementById(elemID).value = value; } } function OnHDDSourceChange(value, id_prefix, total) { for (var i=0; i<=total;i++) { document.getElementById(id_prefix+i).className = (value == i) ? "active" : ""; } var eleTrs = document.getElementById("hdd_table").getElementsByTagName('tr'); var cnt = 0; for (var i=0; i=level_3) { link = [level_3, endSize]; } else if(startSize>=level_2) { link = [level_2, level_3, endSize]; } else if(startSize>=level_1) { link = [level_1, level_2, level_3, endSize]; } else { link = [0, level_1, level_2, level_3, endSize]; } sliderWidth=305; } else { style='others'; } var str = ''; for (var i=0; i'+str2+''; } else { str += ''+str2+''; } } str += ''; str += '
'; document.getElementById("HDD_slider_link").innerHTML = str; } function UpdateHDDSlider(elemID, value, startSize, endSize, style) { var reg = /^[0-9]*$/; if (!reg.test(value)) { value = $("#slider-range-HDDmin").slider("value"); } if (value < startSize) { value = startSize; } else if (value > endSize) { value = endSize; } $("#slider-range-HDDmin").slider("value", value); if (document.getElementById(elemID).value != value) { document.getElementById(elemID).value = value; } if(style=='exMode'){ document.getElementById("Hddresize_id").value = value-startSize; } } function FL_CreateHDDSliderElement(elem_id,startSize,endSize) { startSize=parseInt(startSize); endSize=parseInt(endSize); var sizeRange=endSize-startSize; var level_1=1024; var level_2=2048; var level_3=3072; /* var level_1=Math.round((startSize+sizeRange/4)/50)*50; var level_2=Math.round((startSize+sizeRange/2)/50)*50; var level_3=Math.round((startSize+sizeRange*3/4)/50)*50; */ var link = [startSize, level_1, level_2, level_3, endSize]; var str = ''; for (var i=0; i'+str2+''; } str += ''; str += '
'; document.getElementById("FL_HDD_slider_link").innerHTML = str; } function FL_UpdateHDDSlider(elemID, value, startSize, endSize) { var reg = /^[0-9]*$/; if (!reg.test(value)) { value = $("#FL_slider-range-HDDmin").slider("value"); } if (value < startSize) { value = startSize; } else if (value > endSize) { value = endSize; } $("#FL_slider-range-HDDmin").slider("value", value); if (document.getElementById(elemID).value != value) { document.getElementById(elemID).value = value; } } function ReloadShareList(func, params) { url = "/sharelist/"; makeRequest(url, '', _callbk_reload_sharelist, {'func':func, 'params':params}); } function _callbk_reload_sharelist(http_request, data) { if (http_request.readyState == 4) { if (http_request.status == 200) { var json = JSON.parse(http_request.responseText); if (json.success) { if (data.params) { data.func(json.list_data, data.params); } else { data.func(json.list_data); } } else { func(null, []); } } else { func(null, []); } } } function decodeHTMLEntities(text) { var entities = [ ['apos', '\''], ['amp', '&'], ['lt', '<'], ['gt', '>'] ]; for (var i = 0, max = entities.length; i < max; ++i) { text = text.replace(new RegExp('&'+entities[i][0]+';', 'g'), entities[i][1]); } return text; } function FileSizeFormat(bytes) { var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes == 0) return 'n/a'; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]; }; function onMultiCkboxChange(elem, prefix, totalCnt,openBtn) { if (elem.id == (prefix+'all')) { for (var i=0; i').attr('id','helpTip').addClass('helpTip').appendTo($('#rightDiv')); var helpTipBody = $('
').addClass('helpTipBody').css({'width':baseWidth}).appendTo(helpTip); var helpTipHeadBg = $('
').addClass('helpTipHeadBg').appendTo(helpTip); var helpTipHead = $('
').addClass('helpTipHead').appendTo(helpTip); $(helpContent).appendTo(helpTipBody); var detectUserAgent = navigator.userAgent; if (detectUserAgent.match(/(iPhone|iPod|iPad|Android)/)){ $('#help-window').on('touchstart click',function(e){ e.preventDefault(); var rect = document.getElementById('help-window').getBoundingClientRect(); var baseLeft=rect.left+11; var baseTop=rect.top+30; helpTipBody.css({'left':baseLeft-baseWidth,'top':baseTop}); helpTipHeadBg.css({'left':baseLeft-5,'top':baseTop-6}); helpTipHead.css({'left':baseLeft-5,'top':baseTop-5}); helpTip.show(); helpTip.before($('
')); $('#closeMask').on('touchstart click',closeTip); }); } else{ $('#help-window').mouseover(function(){ var rect = document.getElementById('help-window').getBoundingClientRect(); var baseLeft=rect.left+11; var baseTop=rect.top+30; helpTipBody.css({'left':baseLeft-baseWidth,'top':baseTop}); helpTipHeadBg.css({'left':baseLeft-5,'top':baseTop-6}); helpTipHead.css({'left':baseLeft-5,'top':baseTop-5}); helpTip.show(); $('#help-window').click(function(e){ if(!$('#closeMask').attr('id')) helpTip.before($('
')); $('#help-window').off('mouseout'); $('#closeMask').on('click',closeTip); }); $('#help-window').mouseout(function(){ $('.helpTip').hide(); }); function closeTip(e){ e.preventDefault(); $('.helpTip').hide(); $('#closeMask').remove(); } }); } } function closeTip(e){ e.preventDefault(); $('.helpTip').hide(); $('#closeMask').remove(); } //account function start function accountMenu(userName,lastLoginTime,page){ if($('#accountMenu').attr('id')!=undefined){ $('#accountMenu').remove(); $('#closeMask').remove(); } else{ var rect = $('.account')[0].getBoundingClientRect(); var baseTop=rect.top+28; var scrollWidth=18; if (oBrowser.isCh){ scrollWidth=4; } if($('#rightDiv')[0].scrollHeight > $('#rightDiv')[0].clientHeight){ scrollWidth=0; } if(page=='vm'){ baseTop = 60; } $('
').appendTo($('#rightDiv')); var accountMenu = $('
').appendTo($('#rightDiv')); if (oBrowser.isCh){ var accountMenuContent = $('
').addClass('accountContent').css({'right':15-scrollWidth,'top':baseTop}).appendTo(accountMenu); var accountHeadBg = $('
').addClass('accountHeadBg').css({'right':33-scrollWidth,'top':baseTop-7}).appendTo(accountMenu); var accountHead = $('
').addClass('accountHead').css({'right':33-scrollWidth,'top':baseTop-5}).appendTo(accountMenu); } else{ var accountMenuContent = $('
').addClass('accountContent').css({'right':30-scrollWidth,'top':baseTop}).appendTo(accountMenu); var accountHeadBg = $('
').addClass('accountHeadBg').css({'right':48-scrollWidth,'top':baseTop-7}).appendTo(accountMenu); var accountHead = $('
').addClass('accountHead').css({'right':48-scrollWidth,'top':baseTop-5}).appendTo(accountMenu); } if(userName=='admin'){ if(window.parent != window.self){ accountMenuContent.append('
'+userName+'
'+gettext('Last login time')+':
'+ '
'+lastLoginTime+'
'+ '
'+gettext('About')+'
'); } else{ accountMenuContent.append('
'+userName+'
'+gettext('Last login time')+':
'+ '
'+lastLoginTime+'
'+ '
'+gettext('Logout')+'
'+ '
'+gettext('About')+'
'); } } else{ accountMenuContent.append('
'+userName+'
'+gettext('Last login time')+':
'+ '
'+lastLoginTime+'
'+ '
'+gettext('Change Password')+'
'+ '
'+gettext('Logout')+'
'+ '
'+gettext('About')+'
'); } $('#closeMask').on('touchstart click',closeAccount); } } function closeAccount(e){ e.preventDefault(); $('#accountMenu').remove(); $('#closeMask').remove(); } function accountControl(choice,blackMask){ $('.warningStr').hide(); $('#closeMask').remove(); $('#accountMenu').remove(); if(choice=='logout'){ ShowMask(); jConfirm(gettext('Are you sure to log out?'), gettext('Logout Confirm'), function(r) { if(r) { document.location.href='/admin/logout/'; } else { CloseMask(); return; } },blackMask); } } //account function end function getCookie(key) { if( document.cookie.length==0 ) return false; var i=document.cookie.search(key+'='); if( i==-1 ) return false; i+=key.length+1; var j=document.cookie.indexOf(';', i); if( j==-1 ) j=document.cookie.length; return document.cookie.slice(i,j); } function fireEvent(element, event) { if (document.createEventObject) { // dispatch for IE var evt = document.createEventObject(); return element.fireEvent('on'+event,evt) } else { // dispatch for firefox + others var evt = document.createEvent("HTMLEvents"); evt.initEvent(event, true, true ); // event type,bubbling,cancelable return !element.dispatchEvent(evt); } } function OnVNCShapshot(host_id, vmname, elem) { url = "/vncsnapshot/"+host_id+"/"+vmname+"/?r=" + Math.random(); makeRequest(url, '', _callbk_vnc_snapshot, elem.id); } function _callbk_vnc_snapshot(http_request, elemID) { if (http_request.readyState == 4) { if (http_request.status == 200) { var json = JSON.parse(http_request.responseText); console.log(json); if (!json.success) { console.log('[Failed]'+json.errors) return; } // update image source path = '/media/img/'+json.vname+'_snapshot.jpg' showVNCSnapshot(json.vname); } } } function creatVNCSnapshot(host_id){ var helpTip = $('
').attr('id','vncSnapshot').addClass('helpTip').appendTo($('#rightDiv')); var helpTipBody = $('
').attr('id','vncSnapshotBody').addClass('helpTipBody').appendTo(helpTip); var helpTipHeadBg = $('
').attr('id','vncSnapshotHeadBg').addClass('helpTipHeadBg').appendTo(helpTip); var helpTipHead = $('
').attr('id','vncSnapshotHead').addClass('helpTipHead').appendTo(helpTip); $('.OnVNCShapshot').on('mouseover',function(e){ e.preventDefault(); var vmname = $(this).attr('id').replace('vnc_',''); if(oBrowser.isFF){ OnVNCShapshot(host_id, vmname, $(this)); } else if(oBrowser.isCh){ if(e.relatedTarget.id == $(this).attr('id')) OnVNCShapshot(host_id, vmname, $(this)); } else{ var sAgent = navigator.userAgent.toLowerCase() isWin8 = (sAgent.indexOf("windows nt 6.2")!=-1); if(isWin8){ OnVNCShapshot(host_id, vmname, $(this)); } else{ if(e.relatedTarget.id == $(this).attr('id')) OnVNCShapshot(host_id, vmname, $(this)); } } $('#rightDiv').on('touchstart click',function(e){ e.preventDefault(); $('#vncSnapshot').hide(); }); }); $('.OnVNCShapshot').mouseout(function(e){ e.preventDefault(); $('#vncSnapshot').hide(); }); } function showVNCSnapshot(vname){ $('#vncSnapshotBody').children().remove(); var baseWidth = 400; var baseHeight = 250; var dt=new Date(); var imgPath = '/media/img/'+vname+'_snapshot.jpg?r='+dt.getTime(); $('').attr('src',imgPath).css('height',250).appendTo($('#vncSnapshotBody')); var detectUserAgent = navigator.userAgent; if($('#btn_console').attr('id')==undefined){ //overview page $('#vncSnapshotBody').css({'height':baseHeight}); var winWidth = window.innerWidth; var rect = document.getElementById('vnc_'+vname).getBoundingClientRect(); var baseLeft=rect.left+11; var baseTop=rect.top-5; if((baseTop-272)>0){ $('#vncSnapshotHeadBg').removeClass().addClass('vncSnapshotHeadBg'); $('#vncSnapshotHead').removeClass().addClass('vncSnapshotHead'); $('#vncSnapshotBody').css({'right':winWidth-baseLeft-10,'top':baseTop-272}); $('#vncSnapshotHeadBg').css({'left':baseLeft-10,'top':baseTop-5}); $('#vncSnapshotHead').css({'left':baseLeft-10,'top':baseTop-6}); } else{ $('#vncSnapshotHeadBg').removeClass().addClass('helpTipHeadBg'); $('#vncSnapshotHead').removeClass().addClass('helpTipHead'); baseTop=rect.top+30; $('#vncSnapshotBody').css({'right':winWidth-baseLeft-10,'top':baseTop}); $('#vncSnapshotHeadBg').css({'left':baseLeft-10,'top':baseTop-6}); $('#vncSnapshotHead').css({'left':baseLeft-10,'top':baseTop-5}); } $('#vncSnapshot').show(); } else{ //VM page //$('#vncSnapshotBody').css({'width':baseWidth}); $('#vncSnapshotHeadBg').addClass('helpTipHeadBg'); $('#vncSnapshotHead').addClass('helpTipHead'); var windowHeight = window.innerHeight; var rect = document.getElementById('btn_console').getBoundingClientRect(); var baseLeft=rect.left+11; var baseTop=rect.top+30; $('#vncSnapshotBody').css({'left':baseLeft+20,'top':baseTop+7}); $('#vncSnapshotHeadBg').css({'left':baseLeft-5+40,'top':baseTop-6+5}); $('#vncSnapshotHead').css({'left':baseLeft-5+40,'top':baseTop-5+5}); if($('#conselModal').hasClass('in')){ $('#vncSnapshot').hide(); } else{ $('#vncSnapshot').show(); } $('#btn_console').on('mouseout click',function(){ $('#vncSnapshot').hide(); }); $('body').click(function(){ $('#vncSnapshot').hide(); }); } } function addSSLHint(){ var targetVNC = window.location.protocol + "//" + window.location.hostname + ":" + WebUtil.getQueryVar('port', ''); var SSLbrowser = "FF"; var hint = ""; $('#noVNC_canvas').hide(); $('body').css('overflow','auto'); if(oBrowser.isFF){ SSLbrowser = "FF"; hint = '
'+gettext("Please add the console's URL to your web browser's [Exception List].")+'
'+ '
1.'+gettext('Please click to open a new tab.')+'
'+ '
'+ '
4.'+gettext('Close the new tab')+'
'+ '
5.'+gettext('Please click to refresh this page.')+'
'; $('
').attr('id','addSSLHint').appendTo($('#noVNC_container')); } else if(oBrowser.isIE){ SSLbrowser = "IE"; hint = '
'+gettext('For security concerns, the HTML5 Console with SSL does not support Internet Explorer.')+'
'+ '
'+gettext('Click [Redirect] button to open a normal console page.')+'
'+ '
'; $('
').attr('id','addSSLHint').css({'height':'150px','width':'800px','margin-left':'-400px','padding':'40px 20px 0 20px'}).appendTo($('#noVNC_container')); } $(hint).appendTo($('#addSSLHint')); $('#hintBtn01').on('touchstart click',function(){ window.open(targetVNC, '_blank'); }); $('#hintBtn02').on('touchstart click',function(){ location=location; }); $('#hintBtn03').on('touchstart click',function(){ var port = window.location.port; var url = window.location.href.replace('https:','http:'); var r1 = ':'+port+'/'; var r2 = ':'+(port-1)+'/'; url = url.replace(r1, r2); location=url; }); }