--- misc/xenconsole/index.php 2013/03/26 13:43:07 1958 +++ misc/xenconsole/index.php 2013/07/23 15:30:12 2028 @@ -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); @@ -99,12 +111,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(); @@ -154,8 +247,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,8 +272,10 @@ 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); @@ -200,8 +297,10 @@ 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(); } @@ -214,15 +313,15 @@ 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')"); if (action == "setMemory") { val = prompt("Set memory target"); + val *= (1024*1024); if (val == "" || val == null) { return; } @@ -234,7 +333,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); @@ -245,15 +344,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); @@ -306,7 +419,10 @@
- + + Not logged in + +
12%
@@ -341,6 +457,8 @@ $clean_name = str_replace(" ", "_", $name); $clean_name = str_replace(".", "_", $clean_name); + $clean_name = str_replace("(", "_", $clean_name); + $clean_name = str_replace(")", "_", $clean_name); foreach ($vm["VBDs"] as $vbds) { @@ -361,9 +479,12 @@ + + + @@ -380,7 +501,7 @@ force shutdown - +