--- misc/xenconsole/index.php 2013/07/18 13:00:14 2018 +++ misc/xenconsole/index.php 2013/07/24 06:36:43 2032 @@ -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(); }); @@ -103,13 +117,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 +171,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"); } }); @@ -158,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) ); @@ -167,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+ '%'); @@ -219,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") { @@ -242,8 +303,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 +319,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 +339,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 +351,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 +369,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); @@ -353,6 +413,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; +} + @@ -365,13 +441,22 @@
+ + Not logged in + + - - -
12%
+ +
+ + 12% + - -
0/4 MB
+ +
+ + 0/4 MB +