--- misc/xenconsole/index.php 2013/03/26 17:17:12 1960 +++ misc/xenconsole/index.php 2014/01/30 09:47:17 2100 @@ -1,5 +1,5 @@ $size) { @@ -60,6 +60,18 @@ var menu = 0; var menu_uuid = ''; +var user = ""; +var password = ""; +var loggedin = false; + +function isLoggedIn() { + if (loggedin == false) { + alert("You need to login to perform this operation"); + } + return loggedin; +} + + $(document).ready( function() { $("#menu").hide(); setInterval(refreshData, 60000); @@ -71,6 +83,8 @@ openConsole(conurl,session,name); }); + $('.bar').progressbar( ); + $('#logo').click( function() { refreshData(); }); @@ -99,12 +113,93 @@ event.stopPropagation(); }); + $('.cd').click( function(event) { + var uuid = $(this).attr('uuid'); + cdSelectorDialog(uuid); + }); + $('#loginlink').click( function(event) { + loginDialog(); + }); + $(document).click( function(event) { closeMenu(); }); - + $('#dialog-login').keypress(function(e) { + if (e.keyCode == $.ui.keyCode.ENTER) { + loginDialogSubmit(); + } + }); }); +function loginDialog() { + $('#dialog-login').dialog({ + modal: true, + height: 210, + width: 350, + buttons: { + Login: loginDialogSubmit + } + }); +} +function loginDialogSubmit() { + var params = $('#loginform').serialize(); + + $.get('login.php?' + params, function(data) { + if (data == "OK") { + loggedin = true; + username = $('#username').val(); + password = $('#password').val(); + + $('#login').html("Logged in as " + username + ""); + refreshData(); + } else { + alert(data); + } + $("#dialog-login").dialog( "close" ); + }); +} + +function cdSelectorDialog(uuid) { + if (isLoggedIn() == false) + return; + + $('#cdselector').html(''); + $('#cdselector').load( 'getisolist.php' ); + var cddata; + + $.getJSON('getcdinfo.php?uuid=' + uuid, function(data) { + cddata = data; + if (data.ISO != '') { + $('#cdcurrent').html( data.ISO ); + $(":button:contains('Mount')").prop("disabled", true).addClass("ui-state-disabled"); + } else { + $('#cdcurrent').html('No ISO currently mounted'); + $(":button:contains('Eject')").prop("disabled", true).addClass("ui-state-disabled"); + } + }); + + $('#dialog-cd').dialog({ + modal: true, + width: 800, + height: 300, + buttons: { + Mount: function() { + $( this ).dialog( "close" ); + var vdi = $("#cdselector").val(); + cdAction("mount", cddata.VBD, vdi); + }, + Eject: function() { + $( this ).dialog( "close" ); + cdAction("eject", cddata.VBD, ""); + }, + Cancel: function() { + $( this ).dialog( "close" ); + } + + } + }); +} + function closeMenu() { if (menu > 0) { $("#menu").menu("destroy").hide(); @@ -118,7 +213,7 @@ $(xml).find('host').each(function() { var memtotal = $(this).find('memtotal').text(); var memfree = $(this).find('memfree').text(); - var cpuavg = $(this).find('cpuavg').text(); + var cpuavg = $(this).find('cpuavg').text() * 1; // *1 is used to convert the string var to an int memtotal = Math.round ( memtotal / (1024*1024) ); memfree = Math.round ( memfree / (1024*1024) ); @@ -127,13 +222,15 @@ //alert(memused + ' ' + mem_percentage); - $('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage); + //$('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage); + $('#server_memory_usage').progressbar( "value", mem_percentage ); $('#server_memory_usage').attr('alt', mem_percentage + '%'); $('#server_memory_usage').attr('title', mem_percentage + '%'); $('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB'); - $('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg); + //$('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg); + $('#server_cpu_usage').progressbar( "value", cpuavg ); $('#server_cpu_usage').attr('alt', cpuavg + '%'); $('#server_cpu_usage').attr('title', cpuavg + '%'); $('#server_cpu_usage_txt').text( cpuavg+ '%'); @@ -154,8 +251,10 @@ var mempercent = Math.round( (curmem*100) / maxmem ); - name = name.replace(" ", "_"); - name = name.replace(".", "_"); + name = name.replace(/ /g, "_"); + name = name.replace(/\./g, "_"); + name = name.replace(/\(/g, "_"); + name = name.replace(/\)/g, "_"); var id = "#vm_" + name; @@ -177,17 +276,21 @@ vm.find('.console').data('session', session); vm.find('.console').data('name', name); vm.find('.settings').hide(); - vm.find('.actionstop').show(); - vm.find('.actionstart').hide(); + if (loggedin) { + vm.find('.actionstop').show(); + vm.find('.actionstart').hide(); + } vm.find('.os').text(' - ' + os); - + cpuavg = cpuavg * 1; vm.find('.cpu_graph').show(); - vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg); + //vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg); + vm.find('.cpu_graph').progressbar( "value", cpuavg ); vm.find('.cpu_graph').attr('title', cpuavg + '%'); vm.find('.mem_graph').show(); - vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent); + //vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent); + vm.find('.mem_graph').progressbar( "value", mempercent ); vm.find('.mem_graph').attr('title', curmem + ' / ' + maxmem + ' MB' ); } else { if (state == "Halted") { @@ -200,11 +303,14 @@ vm.find('.network').hide(); vm.find('.console').hide(); vm.find('.settings').show(); - vm.find('.actionstop').hide(); - vm.find('.actionstart').show(); + if (loggedin) { + vm.find('.actionstop').hide(); + vm.find('.actionstart').show(); + } vm.find('.cpu_graph').hide(); vm.find('.mem_graph').hide(); } + vm.find('.state').attr('title', state); }); $('#logo').show(); @@ -214,10 +320,9 @@ function doAction(action, uuid, vm) { var val=""; - var key = prompt("Key"); - if (key == "" || key == null) { + if (isLoggedIn() == false) return; - } + document.body.style.cursor = 'wait'; $('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); @@ -235,7 +340,7 @@ } } - var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;; + var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + password + "&val=" + val;; var response = $.get(url, function(data) { if (data != 'OK') { alert(data); @@ -246,15 +351,29 @@ }); } +function cdAction(action, vbd,vdi) { + if (isLoggedIn() == false) + return; + + document.body.style.cursor = 'wait'; + var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + password + "&VDI=" + vdi; + var response = $.get(url, function(data) { + if (data != 'OK') { + alert(data); + } + document.body.style.cursor = 'default' + }); + +} + function openConsole(url, session, name) { if (url == '') return; - var key = prompt("Key"); - if (key == "" || key == null) { + if (isLoggedIn() == false) return; - } - var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name; + + var url = "console.php?url=" + url + "&session=" + session + "&key=" + password + "&name=" + name; //window.location = url; //$('#mainwindow').load(url); @@ -295,6 +414,22 @@ margin: 4; border: 1px solid #222; } + +.ui-progressbar-value { + background: #61B4F3; +} + +.ui-progressbar { + border-style:solid; + border-width:1px; + border-color: #666666; +} + +.bar { + width: 102px; + height: 16px; +} + @@ -307,13 +442,22 @@
+ + Not logged in + + - - -
12%
+ +
+ + 12% + - -
0/4 MB
+ +
+ + 0/4 MB +