1 |
<?php |
2 |
require("config.php"); |
3 |
|
4 |
function format_memory($size) { |
5 |
if (1024 > $size) { |
6 |
return "$size B"; |
7 |
} else if (pow(1024,2) > $size) { |
8 |
return round(($size / 1024),2) . " kB"; |
9 |
} else { |
10 |
return round(($size / pow(1024,2)), 2) . " MB"; |
11 |
} |
12 |
} |
13 |
|
14 |
function format_storage($size) { |
15 |
if (1024 > $size) { |
16 |
return "$size B"; |
17 |
} else if (pow(1024,2) > $size) { |
18 |
return round(($size / 1024),2) . " kB"; |
19 |
} else if (pow(1024,3) > $size) { |
20 |
return round(($size / pow(1024,2)), 2) . " MB"; |
21 |
} else if (pow(1024,4) > $size) { |
22 |
return round(($size / pow(1024,3)), 2). " GB"; |
23 |
} |
24 |
} |
25 |
|
26 |
include('xenapi.php'); |
27 |
|
28 |
/* Establish session with Xenserver */ |
29 |
$xenserver = new XenApi($url, $login, $password); |
30 |
|
31 |
$hosts_array = $xenserver->host__get_all(); |
32 |
$host = $xenserver->host__get_record($hosts_array[0]); |
33 |
$host_metrics = $xenserver->host_metrics__get_record($host["metrics"]); |
34 |
|
35 |
$xenversion = $host["software_version"]["product_brand"] . " " . $host["software_version"]["product_version"]; |
36 |
$xenversion .= " / Linux:" . $host["software_version"]["linux"] . " / xen: " . $host["software_version"]["xen"] . " / xapi: " . $host["software_version"]["xapi"] ; |
37 |
|
38 |
$expire = split('T', $host["license_params"]["expiry"]); |
39 |
$license = "License: " . $host["license_params"]["sku_type"] . ", expires " . $expire[0] ; |
40 |
|
41 |
$vms_array = $xenserver->VM__get_all_records(); |
42 |
|
43 |
$namelabel = $host["name_label"]; |
44 |
|
45 |
?> |
46 |
<html> |
47 |
<head> |
48 |
<title>XenServer::<?php echo $namelabel;?></title> |
49 |
|
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'> |
60 |
var menu = 0; |
61 |
var menu_uuid = ''; |
62 |
|
63 |
$(document).ready( function() { |
64 |
$("#menu").hide(); |
65 |
setInterval(refreshData, 60000); |
66 |
refreshData(); |
67 |
$('.console').click( function() { |
68 |
var session = $(this).data('session'); |
69 |
var conurl = $(this).data('conurl'); |
70 |
var name = $(this).data('name'); |
71 |
openConsole(conurl,session,name); |
72 |
}); |
73 |
|
74 |
$('#logo').click( function() { |
75 |
refreshData(); |
76 |
}); |
77 |
|
78 |
$('.settings').click( function(event) { |
79 |
menu_uuid = $(this).attr('uuid'); |
80 |
|
81 |
$('#menu').menu( { |
82 |
select: function(event2,ui) { |
83 |
var action = $(ui.item).attr("action"); |
84 |
if (action == "memory") { |
85 |
doAction("setMemory", menu_uuid, ""); |
86 |
} |
87 |
if (action == "cpu") { |
88 |
doAction("setCPU", menu_uuid, ""); |
89 |
} |
90 |
}, |
91 |
create: function(event3,ui) { |
92 |
menu = 1; |
93 |
} |
94 |
/*position: { |
95 |
my: "left", of: event |
96 |
}*/ |
97 |
}); |
98 |
$('#menu').show().position( {my: "left top", of: event} ); |
99 |
event.stopPropagation(); |
100 |
}); |
101 |
|
102 |
$('.cd').click( function(event) { |
103 |
var uuid = $(this).attr('uuid'); |
104 |
cdSelectorDialog(uuid); |
105 |
}); |
106 |
|
107 |
$(document).click( function(event) { |
108 |
closeMenu(); |
109 |
}); |
110 |
}); |
111 |
|
112 |
function cdSelectorDialog(uuid) { |
113 |
$('#cdselector').html(''); |
114 |
$('#cdselector').load( 'getisolist.php' ); |
115 |
var cddata; |
116 |
|
117 |
$.getJSON('getcdinfo.php?uuid=' + uuid, function(data) { |
118 |
cddata = data; |
119 |
if (data.ISO != '') { |
120 |
$('#cdcurrent').html( data.ISO ); |
121 |
} else { |
122 |
$('#cdcurrent').html('<i>No ISO currently mounted</i>'); |
123 |
} |
124 |
}); |
125 |
|
126 |
$('#dialog-cd').dialog({ |
127 |
modal: true, |
128 |
width: 800, |
129 |
height: 300, |
130 |
buttons: { |
131 |
Mount: function() { |
132 |
$( this ).dialog( "close" ); |
133 |
var vdi = $("#cdselector").val(); |
134 |
cdAction("mount", cddata.VBD, vdi); |
135 |
}, |
136 |
Eject: function() { |
137 |
$( this ).dialog( "close" ); |
138 |
cdAction("eject", cddata.VBD, ""); |
139 |
}, |
140 |
Cancel: function() { |
141 |
$( this ).dialog( "close" ); |
142 |
} |
143 |
|
144 |
} |
145 |
}); |
146 |
} |
147 |
|
148 |
function closeMenu() { |
149 |
if (menu > 0) { |
150 |
$("#menu").menu("destroy").hide(); |
151 |
menu = 0; |
152 |
} |
153 |
} |
154 |
|
155 |
function refreshData() { |
156 |
$("#logo").hide(); |
157 |
$.get('ajaxdata.php', function(xml) { |
158 |
$(xml).find('host').each(function() { |
159 |
var memtotal = $(this).find('memtotal').text(); |
160 |
var memfree = $(this).find('memfree').text(); |
161 |
var cpuavg = $(this).find('cpuavg').text(); |
162 |
|
163 |
memtotal = Math.round ( memtotal / (1024*1024) ); |
164 |
memfree = Math.round ( memfree / (1024*1024) ); |
165 |
var memused = memtotal - memfree; |
166 |
var mem_percentage = Math.round( (memused/memtotal) * 100); |
167 |
|
168 |
//alert(memused + ' ' + mem_percentage); |
169 |
|
170 |
$('#server_memory_usage').attr('src', 'usagebar.php?usage=' + mem_percentage); |
171 |
$('#server_memory_usage').attr('alt', mem_percentage + '%'); |
172 |
$('#server_memory_usage').attr('title', mem_percentage + '%'); |
173 |
$('#server_memory_usage_txt').text( memused + '/' + memtotal + 'MB'); |
174 |
|
175 |
|
176 |
$('#server_cpu_usage').attr('src', 'usagebar.php?usage=' + cpuavg); |
177 |
$('#server_cpu_usage').attr('alt', cpuavg + '%'); |
178 |
$('#server_cpu_usage').attr('title', cpuavg + '%'); |
179 |
$('#server_cpu_usage_txt').text( cpuavg+ '%'); |
180 |
}); |
181 |
$(xml).find('vm').each(function() { |
182 |
var name = $(this).find('name').text(); |
183 |
var state = $(this).find('state').text(); |
184 |
var network = $(this).find('network').text(); |
185 |
var state = $(this).find('state').text(); |
186 |
var conurl = $(this).find('conurl').text(); |
187 |
var session = $(this).find('session').text(); |
188 |
var os = $(this).find('os').text(); |
189 |
var guestversion = $(this).find('guestversion').text(); |
190 |
var cpuavg = $(this).find('cpuavg').text(); |
191 |
var curmem = $(this).find('curmem').text(); |
192 |
var maxmem = $(this).find('maxmem').text(); |
193 |
var cpus = $(this).find('cpus').text(); |
194 |
|
195 |
var mempercent = Math.round( (curmem*100) / maxmem ); |
196 |
|
197 |
name = name.replace(/ /g, "_"); |
198 |
name = name.replace(/\./g, "_"); |
199 |
name = name.replace(/\(/g, "_"); |
200 |
name = name.replace(/\)/g, "_"); |
201 |
|
202 |
var id = "#vm_" + name; |
203 |
|
204 |
var vm = $(id); |
205 |
|
206 |
if (guestversion != '') { |
207 |
os += ' Guest Tools: ' + guestversion; |
208 |
} |
209 |
|
210 |
vm.find('.vps_memory_usage_txt_UID').text( maxmem + " MB"); |
211 |
vm.find('.vps_cpu_usage_txt_UID').text( cpus + " VCPU"); |
212 |
|
213 |
if (state == "Running") { |
214 |
vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')"); |
215 |
vm.find('.network').show(); |
216 |
vm.find('.network').text( '(IP: ' + network + ')' ); |
217 |
vm.find('.console').show(); |
218 |
vm.find('.console').data('conurl', conurl); |
219 |
vm.find('.console').data('session', session); |
220 |
vm.find('.console').data('name', name); |
221 |
vm.find('.settings').hide(); |
222 |
vm.find('.actionstop').show(); |
223 |
vm.find('.actionstart').hide(); |
224 |
vm.find('.os').text(' - ' + os); |
225 |
|
226 |
|
227 |
vm.find('.cpu_graph').show(); |
228 |
vm.find('.cpu_graph').attr('src', 'usagebar.php?usage=' + cpuavg); |
229 |
vm.find('.cpu_graph').attr('title', cpuavg + '%'); |
230 |
|
231 |
vm.find('.mem_graph').show(); |
232 |
vm.find('.mem_graph').attr('src', 'usagebar.php?usage=' + mempercent); |
233 |
vm.find('.mem_graph').attr('title', curmem + ' / ' + maxmem + ' MB' ); |
234 |
} else { |
235 |
if (state == "Halted") { |
236 |
vm.find('.state').css("background-image", "url('gfx/vps_topred.png')"); |
237 |
} else { |
238 |
vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
239 |
} |
240 |
vm.find('.os').text(''); |
241 |
|
242 |
vm.find('.network').hide(); |
243 |
vm.find('.console').hide(); |
244 |
vm.find('.settings').show(); |
245 |
vm.find('.actionstop').hide(); |
246 |
vm.find('.actionstart').show(); |
247 |
vm.find('.cpu_graph').hide(); |
248 |
vm.find('.mem_graph').hide(); |
249 |
} |
250 |
|
251 |
}); |
252 |
$('#logo').show(); |
253 |
}); |
254 |
} |
255 |
|
256 |
function doAction(action, uuid, vm) { |
257 |
var val=""; |
258 |
|
259 |
var key = prompt("Key"); |
260 |
if (key == "" || key == null) { |
261 |
return; |
262 |
} |
263 |
document.body.style.cursor = 'wait'; |
264 |
$('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
265 |
|
266 |
if (action == "setMemory") { |
267 |
val = prompt("Set memory target"); |
268 |
val *= (1024*1024); |
269 |
if (val == "" || val == null) { |
270 |
return; |
271 |
} |
272 |
} |
273 |
if (action == "setCPU") { |
274 |
val = prompt("Set CPU count"); |
275 |
if (val == "" || val == null) { |
276 |
return; |
277 |
} |
278 |
} |
279 |
|
280 |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key + "&val=" + val;; |
281 |
var response = $.get(url, function(data) { |
282 |
if (data != 'OK') { |
283 |
alert(data); |
284 |
} |
285 |
document.body.style.cursor = 'default' |
286 |
|
287 |
refreshData(); |
288 |
}); |
289 |
} |
290 |
|
291 |
function cdAction(action, vbd,vdi) { |
292 |
var key = prompt("Key"); |
293 |
if (key == "" || key == null) { |
294 |
return; |
295 |
} |
296 |
document.body.style.cursor = 'wait'; |
297 |
var url = "cdaction.php?action=" + action + "&VBD=" + vbd + "&key=" + key + "&VDI=" + vdi; |
298 |
var response = $.get(url, function(data) { |
299 |
if (data != 'OK') { |
300 |
alert(data); |
301 |
} |
302 |
document.body.style.cursor = 'default' |
303 |
}); |
304 |
|
305 |
} |
306 |
|
307 |
function openConsole(url, session, name) { |
308 |
if (url == '') |
309 |
return; |
310 |
|
311 |
var key = prompt("Key"); |
312 |
if (key == "" || key == null) { |
313 |
return; |
314 |
} |
315 |
var url = "console.php?url=" + url + "&session=" + session + "&key=" + key + "&name=" + name; |
316 |
|
317 |
//window.location = url; |
318 |
//$('#mainwindow').load(url); |
319 |
window.open(url); |
320 |
} |
321 |
|
322 |
|
323 |
|
324 |
</script> |
325 |
|
326 |
<style> |
327 |
body { |
328 |
background: #eee; |
329 |
margin-top: 5px; |
330 |
font-family:verdana,helvetica,arial,sans-serif; |
331 |
font-size: 14px; |
332 |
|
333 |
} |
334 |
|
335 |
.maintable { |
336 |
background: #fff; |
337 |
margin-left:auto; // Smart center |
338 |
margin-right:auto; |
339 |
padding: 0; |
340 |
border: 3px solid #999; |
341 |
} |
342 |
|
343 |
.small { |
344 |
font-family:verdana,helvetica,arial,sans-serif; |
345 |
font-size: 11px; |
346 |
} |
347 |
|
348 |
.toptable { |
349 |
border-bottom: 3px solid #999; |
350 |
} |
351 |
|
352 |
.vps { |
353 |
margin: 4; |
354 |
border: 1px solid #222; |
355 |
} |
356 |
</style> |
357 |
</head> |
358 |
<body> |
359 |
|
360 |
<table class='maintable' width='800' align='center' cellpadding='0' cellspacing='0'><tr><td> |
361 |
|
362 |
<table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'> |
363 |
<tr> |
364 |
<td rowspan='2' width='160'><img src='gfx/citrix-logo.png' id='logo'></td> |
365 |
<td colspan='4' class='small' align='right'><?php echo $namelabel . " / " . $xenversion;?><br><?php echo $license;?></td> |
366 |
</tr> |
367 |
<tr> |
368 |
<td width='150'></td> |
369 |
<td width='150'></td> |
370 |
<td width='150' align='right' class='small'><img src='gfx/icon-cpu.png'> |
371 |
<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> |
372 |
|
373 |
<td width='150' align='right' class='small'><img src='gfx/icon-memory.png'> |
374 |
<img id='server_memory_usage' src='usagebar.php?usage=1' width='102' height='16' title='static dummy data'><div id='server_memory_usage_txt'>0/4 MB</div></td> |
375 |
<!-- |
376 |
<td width='150' align='right' class='small'><img src='gfx/icon-network.png'> |
377 |
<img id='server_net_usage' src='usagebar.php?usage=41' width='102' height='16' title='static dummy data'><div id='server_net_usage_txt'>1%</div></td> |
378 |
<td width='150' align='right' class='small'><img src='gfx/icon-disk.png'> |
379 |
<img id='server_disk_usage' src='usagebar.php?usage=41' width='102' height='16' title='static dummy data'><div id='server_memory_usage_txt'>89.3/405.5 GB</div></td> |
380 |
</td> |
381 |
--> |
382 |
</tr></table> |
383 |
|
384 |
|
385 |
|
386 |
<?php |
387 |
// List all machines |
388 |
foreach($vms_array as $vm) { |
389 |
if ($vm["is_a_template"] != 0 || $vm["is_control_domain"] != 0) { |
390 |
continue; |
391 |
} |
392 |
|
393 |
$name = $vm["name_label"]; |
394 |
$description = $vm["name_description"]; |
395 |
$uuid = $vm["uuid"]; |
396 |
$state = $vm["power_state"] ; |
397 |
$memory = $vm['memory_target']; |
398 |
$harddrive_size = 0; |
399 |
$cpu_count = $vm["VCPUs_max"]; |
400 |
|
401 |
$clean_name = str_replace(" ", "_", $name); |
402 |
$clean_name = str_replace(".", "_", $clean_name); |
403 |
$clean_name = str_replace("(", "_", $clean_name); |
404 |
$clean_name = str_replace(")", "_", $clean_name); |
405 |
|
406 |
|
407 |
foreach ($vm["VBDs"] as $vbds) { |
408 |
$vbd = $xenserver->VBD__get_record($vbds); |
409 |
if ($vbd["type"] == 'Disk') { |
410 |
$vdi = $xenserver->VDI__get_record( $vbd["VDI"] ); |
411 |
$harddrive_size += $vdi["virtual_size"]; |
412 |
} |
413 |
} |
414 |
|
415 |
|
416 |
|
417 |
?> |
418 |
<!-- MACHINE --> |
419 |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'> |
420 |
<tr background='gfx/vps_topbg.png' > |
421 |
<td width='10' class='small state'> </td> |
422 |
<td colspan='2' class='small' title='<?php echo $description;?>'><b><?php echo $name; ?></b><span class='os'></span></td> |
423 |
<td colspan='2' class='small' align='right'> |
424 |
<span class='network'></span> |
425 |
<a href='#' class='cd' uuid='<?php echo $uuid;?>' > |
426 |
<img src='gfx/icon-cd.png' style='vertical-align: middle;'> |
427 |
</a> |
428 |
<a href='#' style='display:none;' class='console'> |
429 |
<img src='gfx/icon-terminal.png' style='vertical-align: middle;'> |
430 |
</a> |
431 |
<a href='#' style='display:none;' class='settings' uuid='<?php echo $uuid;?>'> |
432 |
<img src='gfx/icon-settings16.png' style='vertical-align: middle;'> |
433 |
</a> |
434 |
</td> |
435 |
</tr> |
436 |
|
437 |
<tr bgcolor='#eee'> |
438 |
<td></td> |
439 |
|
440 |
<td width='150' class='small'> |
441 |
<span class="actionstop" style='display:none'> |
442 |
start | |
443 |
<a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> | |
444 |
<a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a> |
445 |
</span> |
446 |
|
447 |
<span class="actionstart"> |
448 |
<a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> | |
449 |
stop | |
450 |
force shutdown |
451 |
</span> |
452 |
|
453 |
</td> |
454 |
|
455 |
<td width='100' align='right' class='small' valign='top'> |
456 |
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='cpu_graph'><br> |
457 |
<img src='gfx/icon-cpu.png' style='vertical-align: middle;'> |
458 |
<span class='vps_cpu_usage_txt_UID'><?php echo $cpu_count; ?> VCPU</span> |
459 |
</td> |
460 |
<td width='100' align='right' class='small'> |
461 |
<img src='usagebar.php?usage=1' width='102' height='16' title='static dummy data' class='mem_graph'><br> |
462 |
<img src='gfx/icon-memory.png' style='vertical-align: middle;'> |
463 |
<span class='vps_memory_usage_txt_UID'><?php echo format_memory($memory); ?></span> |
464 |
</td> |
465 |
<!-- |
466 |
<td width='100' align='right' class='small'> |
467 |
<img src='gfx/icon-network.png' style='vertical-align: middle;'> |
468 |
<span id='vps_net_usage_txt_UID'>na</span> |
469 |
</td> |
470 |
--> |
471 |
<td width='100' align='right' class='small' valign='bottom'> |
472 |
<img src='gfx/icon-disk.png' style='vertical-align: middle;'> |
473 |
<span id='vps_disk_usage_txt_UID'><?php echo format_storage($harddrive_size); ?></span> |
474 |
</td> |
475 |
</tr> |
476 |
|
477 |
|
478 |
</table> |
479 |
<!-- MACHINE END --> |
480 |
|
481 |
<?PHP } ?> |
482 |
</td></tr></table> |
483 |
|
484 |
<br> |
485 |
|
486 |
<div style="display: none;"> |
487 |
|
488 |
<div id="dialog-cd" title="Select CD"> |
489 |
|
490 |
<table border=0> |
491 |
<tr> |
492 |
<td>Current: <span id="cdcurrent"></span></td> |
493 |
</tr> |
494 |
<tr> |
495 |
<td> |
496 |
CD: <select id="cdselector"></select> |
497 |
</td> |
498 |
</tr> |
499 |
</table> |
500 |
</div> |
501 |
|
502 |
</div> |
503 |
|
504 |
<ul id="menu"> |
505 |
<li action="memory"><a href="#">Set Memory Size</a></li> |
506 |
<li action="cpu"><a href="#">Set CPU Count</a></li> |
507 |
|
508 |
|
509 |
<!-- <li><a href="#">Item 3</a> |
510 |
<ul> |
511 |
<li><a href="#">Item 3-1</a></li> |
512 |
<li><a href="#">Item 3-2</a></li> |
513 |
<li><a href="#">Item 3-3</a></li> |
514 |
<li><a href="#">Item 3-4</a></li> |
515 |
<li><a href="#">Item 3-5</a></li> |
516 |
</ul> |
517 |
</li> |
518 |
<li><a href="#">Item 4</a></li> |
519 |
<li><a href="#">Item 5</a></li>--> |
520 |
</ul> |
521 |
|
522 |
</body></html> |