--- misc/xenconsole/index.php 2013/07/18 13:00:14 2018 +++ misc/xenconsole/index.php 2013/07/23 15:30:12 2028 @@ -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); @@ -103,13 +115,52 @@ 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; @@ -118,8 +169,10 @@ 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"); } }); @@ -219,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); @@ -242,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(); } @@ -256,10 +313,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')"); @@ -277,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); @@ -289,12 +345,11 @@ } function cdAction(action, vbd,vdi) { - var key = prompt("Key"); - if (key == "" || key == null) { + if (isLoggedIn() == false) return; - } + document.body.style.cursor = 'wait'; - var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + key + "&VDI=" + vdi; + var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + password + "&VDI=" + vdi; var response = $.get(url, function(data) { if (data != 'OK') { alert(data); @@ -308,11 +363,10 @@ 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); @@ -365,7 +419,10 @@
- + + Not logged in + +
12%
@@ -423,11 +480,11 @@ - - + + @@ -444,7 +501,7 @@ force shutdown - +