1 |
<?php |
<?php |
2 |
include("config.php"); |
require("config.php"); |
3 |
|
|
4 |
function format_memory($size) { |
function format_memory($size) { |
5 |
if (1024 > $size) { |
if (1024 > $size) { |
46 |
<html> |
<html> |
47 |
<head> |
<head> |
48 |
<title>XenServer::<?php echo $namelabel;?></title> |
<title>XenServer::<?php echo $namelabel;?></title> |
49 |
<script type='text/javascript' src="jquery-1.8.2.min.js"></script> |
|
50 |
|
<link rel="stylesheet" type="text/css" href="jquery/theme/jquery-ui.css"> |
51 |
|
<style> |
52 |
|
.ui-menu { |
53 |
|
width: 200px; |
54 |
|
} |
55 |
|
</style> |
56 |
|
<script type='text/javascript' src="jquery/jquery-1.9.1.min.js"></script> |
57 |
|
<script type='text/javascript' src="jquery/jquery-ui-1.10.2.min.js"></script> |
58 |
|
|
59 |
<script type='text/javascript'> |
<script type='text/javascript'> |
60 |
|
var menu = 0; |
61 |
|
var menu_uuid = ''; |
62 |
|
|
63 |
|
var user = ""; |
64 |
|
var password = ""; |
65 |
|
var loggedin = false; |
66 |
|
|
67 |
|
function isLoggedIn() { |
68 |
|
if (loggedin == false) { |
69 |
|
alert("You need to login to perform this operation"); |
70 |
|
} |
71 |
|
return loggedin; |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
$(document).ready( function() { |
$(document).ready( function() { |
76 |
|
$("#menu").hide(); |
77 |
setInterval(refreshData, 60000); |
setInterval(refreshData, 60000); |
78 |
refreshData(); |
refreshData(); |
79 |
$('.console').click( function() { |
$('.console').click( function() { |
80 |
var session = $(this).data('session'); |
var session = $(this).data('session'); |
81 |
var conurl = $(this).data('conurl'); |
var conurl = $(this).data('conurl'); |
82 |
var name = $(this).data('name'); |
var name = $(this).data('name'); |
83 |
console(conurl,session,name); |
openConsole(conurl,session,name); |
84 |
}); |
}); |
85 |
|
|
86 |
$('#logo').click( function() { |
$('#logo').click( function() { |
87 |
refreshData(); |
refreshData(); |
88 |
}); |
}); |
89 |
|
|
90 |
|
$('.settings').click( function(event) { |
91 |
|
menu_uuid = $(this).attr('uuid'); |
92 |
|
|
93 |
|
$('#menu').menu( { |
94 |
|
select: function(event2,ui) { |
95 |
|
var action = $(ui.item).attr("action"); |
96 |
|
if (action == "memory") { |
97 |
|
doAction("setMemory", menu_uuid, ""); |
98 |
|
} |
99 |
|
if (action == "cpu") { |
100 |
|
doAction("setCPU", menu_uuid, ""); |
101 |
|
} |
102 |
|
}, |
103 |
|
create: function(event3,ui) { |
104 |
|
menu = 1; |
105 |
|
} |
106 |
|
/*position: { |
107 |
|
my: "left", of: event |
108 |
|
}*/ |
109 |
|
}); |
110 |
|
$('#menu').show().position( {my: "left top", of: event} ); |
111 |
|
event.stopPropagation(); |
112 |
|
}); |
113 |
|
|
114 |
|
$('.cd').click( function(event) { |
115 |
|
var uuid = $(this).attr('uuid'); |
116 |
|
cdSelectorDialog(uuid); |
117 |
|
}); |
118 |
|
$('#loginlink').click( function(event) { |
119 |
|
loginDialog(); |
120 |
|
}); |
121 |
|
|
122 |
|
$(document).click( function(event) { |
123 |
|
closeMenu(); |
124 |
|
}); |
125 |
|
$('#dialog-login').keypress(function(e) { |
126 |
|
if (e.keyCode == $.ui.keyCode.ENTER) { |
127 |
|
loginDialogSubmit(); |
128 |
|
} |
129 |
|
}); |
130 |
}); |
}); |
131 |
|
|
132 |
|
function loginDialog() { |
133 |
|
$('#dialog-login').dialog({ |
134 |
|
modal: true, |
135 |
|
height: 210, |
136 |
|
width: 325, |
137 |
|
buttons: { |
138 |
|
Login: loginDialogSubmit |
139 |
|
} |
140 |
|
}); |
141 |
|
} |
142 |
|
function loginDialogSubmit() { |
143 |
|
var params = $('#loginform').serialize(); |
144 |
|
|
145 |
|
$.get('login.php?' + params, function(data) { |
146 |
|
if (data == "OK") { |
147 |
|
loggedin = true; |
148 |
|
username = $('#username').val(); |
149 |
|
password = $('#password').val(); |
150 |
|
|
151 |
|
$('#login').html("Logged in as <i>" + username + "</i>"); |
152 |
|
} else { |
153 |
|
alert(data); |
154 |
|
} |
155 |
|
$("#dialog-login").dialog( "close" ); |
156 |
|
}); |
157 |
|
} |
158 |
|
|
159 |
|
function cdSelectorDialog(uuid) { |
160 |
|
if (isLoggedIn() == false) |
161 |
|
return; |
162 |
|
|
163 |
|
$('#cdselector').html(''); |
164 |
|
$('#cdselector').load( 'getisolist.php' ); |
165 |
|
var cddata; |
166 |
|
|
167 |
|
$.getJSON('getcdinfo.php?uuid=' + uuid, function(data) { |
168 |
|
cddata = data; |
169 |
|
if (data.ISO != '') { |
170 |
|
$('#cdcurrent').html( data.ISO ); |
171 |
|
} else { |
172 |
|
$('#cdcurrent').html('<i>No ISO currently mounted</i>'); |
173 |
|
} |
174 |
|
}); |
175 |
|
|
176 |
|
$('#dialog-cd').dialog({ |
177 |
|
modal: true, |
178 |
|
width: 800, |
179 |
|
height: 300, |
180 |
|
buttons: { |
181 |
|
Mount: function() { |
182 |
|
$( this ).dialog( "close" ); |
183 |
|
var vdi = $("#cdselector").val(); |
184 |
|
cdAction("mount", cddata.VBD, vdi); |
185 |
|
}, |
186 |
|
Eject: function() { |
187 |
|
$( this ).dialog( "close" ); |
188 |
|
cdAction("eject", cddata.VBD, ""); |
189 |
|
}, |
190 |
|
Cancel: function() { |
191 |
|
$( this ).dialog( "close" ); |
192 |
|
} |
193 |
|
|
194 |
|
} |
195 |
|
}); |
196 |
|
} |
197 |
|
|
198 |
|
function closeMenu() { |
199 |
|
if (menu > 0) { |
200 |
|
$("#menu").menu("destroy").hide(); |
201 |
|
menu = 0; |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
function refreshData() { |
function refreshData() { |
206 |
$("#logo").hide(); |
$("#logo").hide(); |
207 |
$.get('ajaxdata.php', function(xml) { |
$.get('ajaxdata.php', function(xml) { |
240 |
var cpuavg = $(this).find('cpuavg').text(); |
var cpuavg = $(this).find('cpuavg').text(); |
241 |
var curmem = $(this).find('curmem').text(); |
var curmem = $(this).find('curmem').text(); |
242 |
var maxmem = $(this).find('maxmem').text(); |
var maxmem = $(this).find('maxmem').text(); |
243 |
|
var cpus = $(this).find('cpus').text(); |
244 |
|
|
245 |
var mempercent = Math.round( (curmem*100) / maxmem ); |
var mempercent = Math.round( (curmem*100) / maxmem ); |
246 |
|
|
247 |
name = name.replace(" ", "_"); |
name = name.replace(/ /g, "_"); |
248 |
name = name.replace(".", "_"); |
name = name.replace(/\./g, "_"); |
249 |
|
name = name.replace(/\(/g, "_"); |
250 |
|
name = name.replace(/\)/g, "_"); |
251 |
|
|
252 |
var id = "#vm_" + name; |
var id = "#vm_" + name; |
253 |
|
|
257 |
os += ' Guest Tools: ' + guestversion; |
os += ' Guest Tools: ' + guestversion; |
258 |
} |
} |
259 |
|
|
260 |
|
vm.find('.vps_memory_usage_txt_UID').text( maxmem + " MB"); |
261 |
|
vm.find('.vps_cpu_usage_txt_UID').text( cpus + " VCPU"); |
262 |
|
|
263 |
if (state == "Running") { |
if (state == "Running") { |
264 |
vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')"); |
vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')"); |
265 |
vm.find('.network').show(); |
vm.find('.network').show(); |
268 |
vm.find('.console').data('conurl', conurl); |
vm.find('.console').data('conurl', conurl); |
269 |
vm.find('.console').data('session', session); |
vm.find('.console').data('session', session); |
270 |
vm.find('.console').data('name', name); |
vm.find('.console').data('name', name); |
271 |
|
vm.find('.settings').hide(); |
272 |
vm.find('.actionstop').show(); |
vm.find('.actionstop').show(); |
273 |
vm.find('.actionstart').hide(); |
vm.find('.actionstart').hide(); |
274 |
vm.find('.os').text(' - ' + os); |
vm.find('.os').text(' - ' + os); |
291 |
|
|
292 |
vm.find('.network').hide(); |
vm.find('.network').hide(); |
293 |
vm.find('.console').hide(); |
vm.find('.console').hide(); |
294 |
|
vm.find('.settings').show(); |
295 |
vm.find('.actionstop').hide(); |
vm.find('.actionstop').hide(); |
296 |
vm.find('.actionstart').show(); |
vm.find('.actionstart').show(); |
297 |
vm.find('.cpu_graph').hide(); |
vm.find('.cpu_graph').hide(); |
304 |
} |
} |
305 |
|
|
306 |
function doAction(action, uuid, vm) { |
function doAction(action, uuid, vm) { |
307 |
var key = prompt("Key"); |
var val=""; |
308 |
if (key == "" || key == null) { |
|
309 |
|
if (isLoggedIn() == false) |
310 |
return; |
return; |
311 |
} |
|
312 |
document.body.style.cursor = 'wait'; |
document.body.style.cursor = 'wait'; |
313 |
$('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
$('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
314 |
|
|
315 |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key; |
if (action == "setMemory") { |
316 |
|
val = prompt("Set memory target"); |
317 |
|
val *= (1024*1024); |
318 |
|
if (val == "" || val == null) { |
319 |
|
return; |
320 |
|
} |
321 |
|
} |
322 |
|
if (action == "setCPU") { |
323 |
|
val = prompt("Set CPU count"); |
324 |
|
if (val == "" || val == null) { |
325 |
|
return; |
326 |
|
} |
327 |
|
} |
328 |
|
|
329 |
|
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + password + "&val=" + val;; |
330 |
var response = $.get(url, function(data) { |
var response = $.get(url, function(data) { |
331 |
if (data != 'OK') { |
if (data != 'OK') { |
332 |
alert(data); |
alert(data); |
337 |
}); |
}); |
338 |
} |
} |
339 |
|
|
340 |
function console(url, session, name) { |
function cdAction(action, vbd,vdi) { |
341 |
|
if (isLoggedIn() == false) |
342 |
|
return; |
343 |
|
|
344 |
|
document.body.style.cursor = 'wait'; |
345 |
|
var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + password + "&VDI=" + vdi; |
346 |
|
var response = $.get(url, function(data) { |
347 |
|
if (data != 'OK') { |
348 |
|
alert(data); |
349 |
|
} |
350 |
|
document.body.style.cursor = 'default' |
351 |
|
}); |
352 |
|
|
353 |
|
} |
354 |
|
|
355 |
|
function openConsole(url, session, name) { |
356 |
if (url == '') |
if (url == '') |
357 |
return; |
return; |
358 |
|
|
359 |
var key = prompt("Key"); |
if (isLoggedIn() == false) |
|
if (key == "" || key == null) { |
|
360 |
return; |
return; |
361 |
} |
|
362 |
var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name; |
var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name; |
363 |
|
|
364 |
//window.location = url; |
//window.location = url; |
412 |
<td colspan='4' class='small' align='right'><?php echo $namelabel . " / " . $xenversion;?><br><?php echo $license;?></td> |
<td colspan='4' class='small' align='right'><?php echo $namelabel . " / " . $xenversion;?><br><?php echo $license;?></td> |
413 |
</tr> |
</tr> |
414 |
<tr> |
<tr> |
415 |
<td width='150'></td> |
<td width='150'> |
416 |
|
<span id="login" class='small'><i>Not <a href="#" id="loginlink">logged in</a></i> |
417 |
|
</span> |
418 |
|
</td> |
419 |
<td width='150'></td> |
<td width='150'></td> |
420 |
<td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'> |
<td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'> |
421 |
<img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16' title='static dummy data'><div id='server_cpu_usage_txt'>12%</div></td> |
<img id='server_cpu_usage' src='usagebar.php?usage=12' width='102' height='16' title='static dummy data'><div id='server_cpu_usage_txt'>12%</div></td> |
450 |
|
|
451 |
$clean_name = str_replace(" ", "_", $name); |
$clean_name = str_replace(" ", "_", $name); |
452 |
$clean_name = str_replace(".", "_", $clean_name); |
$clean_name = str_replace(".", "_", $clean_name); |
453 |
|
$clean_name = str_replace("(", "_", $clean_name); |
454 |
|
$clean_name = str_replace(")", "_", $clean_name); |
455 |
|
|
456 |
|
|
457 |
foreach ($vm["VBDs"] as $vbds) { |
foreach ($vm["VBDs"] as $vbds) { |
469 |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'> |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'> |
470 |
<tr background='gfx/vps_topbg.png' > |
<tr background='gfx/vps_topbg.png' > |
471 |
<td width='10' class='small state'> </td> |
<td width='10' class='small state'> </td> |
472 |
<td colspan='3' class='small' title='<?php echo $description;?>'><b><?php echo $name; ?></b><span class='os'></span></td> |
<td colspan='2' class='small' title='<?php echo $description;?>'><b><?php echo $name; ?></b><span class='os'></span></td> |
473 |
<td colspan='1' class='small' align='right'> |
<td colspan='2' class='small' align='right'> |
474 |
<span class='network'></span> |
<span class='network'></span> |
475 |
|
<a href='#' class='cd' uuid='<?php echo $uuid;?>' > |
476 |
|
<img src='gfx/icon-cd.png' style='vertical-align: middle;'> |
477 |
|
</a> |
478 |
<a href='#' style='display:none;' class='console'> |
<a href='#' style='display:none;' class='console'> |
479 |
<img src='gfx/icon-terminal.png' style='vertical-align: middle;'> |
<img src='gfx/icon-terminal.png' style='vertical-align: middle;'> |
480 |
</a> |
</a> |
481 |
|
<a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'> |
482 |
|
<img src='gfx/icon-settings16.png' style='vertical-align: middle;'> |
483 |
|
</a> |
484 |
</td> |
</td> |
485 |
</tr> |
</tr> |
486 |
|
|
505 |
<td width='100' align='right' class='small' valign='top'> |
<td width='100' align='right' class='small' valign='top'> |
506 |
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br> |
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br> |
507 |
<img src='gfx/icon-cpu.png' style='vertical-align: middle;'> |
<img src='gfx/icon-cpu.png' style='vertical-align: middle;'> |
508 |
<span id='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span> |
<span class='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span> |
509 |
</td> |
</td> |
510 |
<td width='100' align='right' class='small'> |
<td width='100' align='right' class='small'> |
511 |
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br> |
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br> |
512 |
<img src='gfx/icon-memory.png' style='vertical-align: middle;'> |
<img src='gfx/icon-memory.png' style='vertical-align: middle;'> |
513 |
<span id='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span> |
<span class='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span> |
514 |
</td> |
</td> |
515 |
<!-- |
<!-- |
516 |
<td width='100' align='right' class='small'> |
<td width='100' align='right' class='small'> |
530 |
|
|
531 |
<?PHP } ?> |
<?PHP } ?> |
532 |
</td></tr></table> |
</td></tr></table> |
533 |
|
|
534 |
|
<br> |
535 |
|
|
536 |
|
<div style="display: none;"> |
537 |
|
|
538 |
|
<div id="dialog-login" title="Login"> |
539 |
|
<form id="loginform"> |
540 |
|
<table border="0"> |
541 |
|
<tr> |
542 |
|
<td>Username: </td> |
543 |
|
<td><input type="text" id="username" name="username"></td> |
544 |
|
<tr> |
545 |
|
<tr> |
546 |
|
<td>Password: </td> |
547 |
|
<td><input type="password" id="password" name="password"></td> |
548 |
|
</tr> |
549 |
|
</table> |
550 |
|
</form> |
551 |
|
</div> |
552 |
|
|
553 |
|
<div id="dialog-cd" title="Select CD"> |
554 |
|
|
555 |
|
<table border=0> |
556 |
|
<tr> |
557 |
|
<td>Current: <span id="cdcurrent"></span></td> |
558 |
|
</tr> |
559 |
|
<tr> |
560 |
|
<td> |
561 |
|
CD: <select id="cdselector"></select> |
562 |
|
</td> |
563 |
|
</tr> |
564 |
|
</table> |
565 |
|
</div> |
566 |
|
|
567 |
|
</div> |
568 |
|
|
569 |
|
<ul id="menu"> |
570 |
|
<li action="memory"><a href="#">Set Memory Size</a></li> |
571 |
|
<li action="cpu"><a href="#">Set CPU Count</a></li> |
572 |
|
|
573 |
|
|
574 |
|
<!-- <li><a href="#">Item 3</a> |
575 |
|
<ul> |
576 |
|
<li><a href="#">Item 3-1</a></li> |
577 |
|
<li><a href="#">Item 3-2</a></li> |
578 |
|
<li><a href="#">Item 3-3</a></li> |
579 |
|
<li><a href="#">Item 3-4</a></li> |
580 |
|
<li><a href="#">Item 3-5</a></li> |
581 |
|
</ul> |
582 |
|
</li> |
583 |
|
<li><a href="#">Item 4</a></li> |
584 |
|
<li><a href="#">Item 5</a></li>--> |
585 |
|
</ul> |
586 |
|
|
587 |
</body></html> |
</body></html> |
588 |
|
|