28 |
/* Establish session with Xenserver */ |
/* Establish session with Xenserver */ |
29 |
$xenserver = new XenApi($url, $login, $password); |
$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(); |
$vms_array = $xenserver->VM__get_all_records(); |
42 |
|
|
43 |
|
|
49 |
|
|
50 |
<script type='text/javascript'> |
<script type='text/javascript'> |
51 |
$(document).ready( function() { |
$(document).ready( function() { |
52 |
loadServer(); |
setInterval(refreshData, 60000); |
53 |
|
refreshData(); |
54 |
|
$('.console').click( function() { |
55 |
|
var session = $(this).data('session'); |
56 |
|
var conurl = $(this).data('conurl'); |
57 |
|
console(conurl,session); |
58 |
|
}); |
59 |
|
|
60 |
|
$('#logo').click( function() { |
61 |
|
refreshData(); |
62 |
|
}); |
63 |
}); |
}); |
64 |
|
|
65 |
function doAction(action, uuid) { |
function refreshData() { |
66 |
|
$.get('ajaxdata.php', function(xml) { |
67 |
|
$(xml).find('vm').each(function() { |
68 |
|
var name = $(this).find('name').text(); |
69 |
|
var state = $(this).find('state').text(); |
70 |
|
var network = $(this).find('network').text(); |
71 |
|
var state = $(this).find('state').text(); |
72 |
|
var conurl = $(this).find('conurl').text(); |
73 |
|
var session = $(this).find('session').text(); |
74 |
|
var os = $(this).find('os').text(); |
75 |
|
|
76 |
|
name = name.replace(" ", "_"); |
77 |
|
name = name.replace(".", "_"); |
78 |
|
|
79 |
|
var id = "#vm_" + name; |
80 |
|
|
81 |
|
var vm = $(id); |
82 |
|
|
83 |
|
if (state == "Running") { |
84 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')"); |
85 |
|
vm.find('.network').show(); |
86 |
|
vm.find('.network').text( '(IP: ' + network + ')' ); |
87 |
|
vm.find('.console').show(); |
88 |
|
vm.find('.console').data('conurl', conurl); |
89 |
|
vm.find('.console').data('session', session); |
90 |
|
vm.find('.actionstop').show(); |
91 |
|
vm.find('.actionstart').hide(); |
92 |
|
vm.find('.os').text(' - ' + os); |
93 |
|
} else { |
94 |
|
if (state == "Halted") { |
95 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topred.png')"); |
96 |
|
} else { |
97 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
98 |
|
} |
99 |
|
vm.find('.network').hide(); |
100 |
|
vm.find('.console').hide(); |
101 |
|
vm.find('.actionstop').hide(); |
102 |
|
vm.find('.actionstart').show(); |
103 |
|
} |
104 |
|
|
105 |
|
}) |
106 |
|
}); |
107 |
|
} |
108 |
|
|
109 |
|
function doAction(action, uuid, vm) { |
110 |
var key = prompt("Key"); |
var key = prompt("Key"); |
111 |
if (key == "" || key == null) { |
if (key == "" || key == null) { |
112 |
return; |
return; |
113 |
} |
} |
114 |
document.body.style.cursor = 'wait'; |
document.body.style.cursor = 'wait'; |
115 |
|
$('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
116 |
|
|
117 |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key; |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key; |
118 |
var response = $.get(url, function(data) { |
var response = $.get(url, function(data) { |
119 |
alert(data); |
if (data != 'OK') { |
120 |
document.body.style.cursor = 'default' |
alert(data); |
|
if (data == "OK") { |
|
|
window.location.reload(); |
|
121 |
} |
} |
122 |
|
document.body.style.cursor = 'default' |
123 |
|
|
124 |
|
refreshData(); |
125 |
}); |
}); |
126 |
} |
} |
127 |
|
|
140 |
window.open(url); |
window.open(url); |
141 |
} |
} |
142 |
|
|
|
function loadServer() { |
|
|
$('#mainwindow').load('server.php'); |
|
|
} |
|
143 |
|
|
|
function loadvm(uuid) { |
|
|
$('#mainwindow').load('vm.php?uuid=' + uuid ); |
|
|
} |
|
144 |
|
|
145 |
</script> |
</script> |
146 |
|
|
182 |
|
|
183 |
<table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'> |
<table width='100%' background='gfx/topbg.png' cellpadding='3' cellspacing='0' border='0' class='toptable'> |
184 |
<tr> |
<tr> |
185 |
<td rowspan='2' width='160'><img src='gfx/citrix-logo.png'></td> |
<td rowspan='2' width='160'><img src='gfx/citrix-logo.png' id='logo'></td> |
186 |
<td colspan='3' class='small' align='right'>Linux:2.6.32.12-0.7.1.xs6.0.2.542.170665xen / xen: 4.1.2 / xapi: 1.3</td> |
<td colspan='3' class='small' align='right'><?php echo $xenversion;?><br><?php echo $license;?></td> |
187 |
</tr> |
</tr> |
188 |
<tr> |
<tr> |
189 |
<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'> |
216 |
$harddrive_size = 0; |
$harddrive_size = 0; |
217 |
$cpu_count = $vm["VCPUs_max"]; |
$cpu_count = $vm["VCPUs_max"]; |
218 |
|
|
219 |
|
$clean_name = str_replace(" ", "_", $name); |
220 |
|
$clean_name = str_replace(".", "_", $clean_name); |
221 |
|
|
222 |
|
|
223 |
foreach ($vm["VBDs"] as $vbds) { |
foreach ($vm["VBDs"] as $vbds) { |
224 |
$vbd = $xenserver->VBD__get_record($vbds); |
$vbd = $xenserver->VBD__get_record($vbds); |
225 |
if ($vbd["type"] == 'Disk') { |
if ($vbd["type"] == 'Disk') { |
228 |
} |
} |
229 |
} |
} |
230 |
|
|
|
$vps_topbg = 'vps_topyellow.png'; |
|
|
|
|
|
if ($state == "Running") { |
|
|
$vps_topbg = 'vps_topgreen.png'; |
|
|
} else if ($state == "Halted") { |
|
|
$vps_topbg = 'vps_topred.png'; |
|
|
} |
|
|
|
|
|
$network = ""; |
|
|
if ( $vm["power_state"] == "Running" && $vm["guest_metrics"] != "OpaqueRef:NULL" ) { |
|
|
$guest_metrics = $xenserver->VM_guest_metrics__get_record( $vm["guest_metrics"] ); |
|
|
$network = "(IP: " . implode( ",", $guest_metrics["networks"]) . ")"; |
|
|
} else { |
|
|
$guest_metrics = Array() ; |
|
|
} |
|
|
|
|
231 |
|
|
232 |
$url = ""; |
|
|
$session = ""; |
|
|
foreach($vm["consoles"] as $conref) { |
|
|
$con = $xenserver->console__get_record( $conref ); |
|
|
//var_dump($con); |
|
|
|
|
|
if ($con["protocol"] == "rfb") { |
|
|
$url = urlencode( $con["location"] ); |
|
|
$session = $xenserver->get_id(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n"; |
|
233 |
?> |
?> |
234 |
<!-- MACHINE --> |
<!-- MACHINE --> |
235 |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps'> |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'> |
236 |
<tr background='gfx/vps_topbg.png'> |
<tr background='gfx/vps_topbg.png' > |
237 |
<td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'> </td> |
<td width='10' class='small state'> </td> |
238 |
<td colspan='2' class='small'><b><?php echo $name; ?></b></td> |
<td colspan='2' class='small'><b><?php echo $name; ?></b><span class='os'></span></td> |
239 |
<td colspan='2' class='small' align='right'> |
<td colspan='2' class='small' align='right'> |
240 |
<?php echo $network;?> |
<span class='network'></span> |
241 |
<a href="#" onclick="console('<?php echo $url;?>','<?php echo $session;?>')"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a> |
<a href='#' style='display:none;' class='console'> |
242 |
|
<img src='gfx/icon-terminal.png' style='vertical-align: middle;'> |
243 |
|
</a> |
244 |
</td> |
</td> |
245 |
</tr> |
</tr> |
246 |
|
|
248 |
<td></td> |
<td></td> |
249 |
|
|
250 |
<td width='150' class='small'> |
<td width='150' class='small'> |
251 |
<?php |
<span class="actionstop" style='display:none'> |
252 |
if ($state == "Running") { |
start | |
253 |
echo "start | "; |
<a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> | |
254 |
echo "<a href='#' onclick=\"doAction('shutdown','$uuid')\">stop</a> | "; |
<a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a> |
255 |
echo "<a href='#' onclick=\"doAction('hardshutdown','$uuid')\">force shutdown</a>"; |
</span> |
256 |
} else { |
|
257 |
echo "<a href='#' onclick=\"doAction('start','$uuid')\">start</a> | "; |
<span class="actionstart"> |
258 |
echo "stop | "; |
<a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> | |
259 |
echo "force shutdown"; |
stop | |
260 |
} |
force shutdown |
261 |
?> |
</span> |
262 |
|
|
263 |
</td> |
</td> |
264 |
|
|