39 |
|
|
40 |
<script type='text/javascript'> |
<script type='text/javascript'> |
41 |
$(document).ready( function() { |
$(document).ready( function() { |
42 |
loadServer(); |
setInterval(refreshData, 60000); |
43 |
|
refreshData(); |
44 |
|
$('.console').click( function() { |
45 |
|
var session = $(this).data('session'); |
46 |
|
var conurl = $(this).data('conurl'); |
47 |
|
console(conurl,session); |
48 |
|
}); |
49 |
}); |
}); |
50 |
|
|
51 |
function doAction(action, uuid) { |
function refreshData() { |
52 |
|
$.get('ajaxdata.php', function(xml) { |
53 |
|
$(xml).find('vm').each(function() { |
54 |
|
var name = $(this).find('name').text(); |
55 |
|
var state = $(this).find('state').text(); |
56 |
|
var network = $(this).find('network').text(); |
57 |
|
var state = $(this).find('state').text(); |
58 |
|
var conurl = $(this).find('conurl').text(); |
59 |
|
var session = $(this).find('session').text(); |
60 |
|
|
61 |
|
name = name.replace(" ", "_"); |
62 |
|
name = name.replace(".", "_"); |
63 |
|
|
64 |
|
var id = "#vm_" + name; |
65 |
|
|
66 |
|
var vm = $(id); |
67 |
|
|
68 |
|
if (state == "Running") { |
69 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topgreen.png')"); |
70 |
|
vm.find('.network').show(); |
71 |
|
vm.find('.network').text( '(IP: ' + network + ')' ); |
72 |
|
vm.find('.console').show(); |
73 |
|
vm.find('.console').data('conurl', conurl); |
74 |
|
vm.find('.console').data('session', session); |
75 |
|
vm.find('.actionstop').show(); |
76 |
|
vm.find('.actionstart').hide(); |
77 |
|
} else { |
78 |
|
if (state == "Halted") { |
79 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topred.png')"); |
80 |
|
} else { |
81 |
|
vm.find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
82 |
|
} |
83 |
|
vm.find('.network').hide(); |
84 |
|
vm.find('.console').hide(); |
85 |
|
vm.find('.actionstop').hide(); |
86 |
|
vm.find('.actionstart').show(); |
87 |
|
} |
88 |
|
|
89 |
|
}) |
90 |
|
}); |
91 |
|
} |
92 |
|
|
93 |
|
function doAction(action, uuid, vm) { |
94 |
var key = prompt("Key"); |
var key = prompt("Key"); |
95 |
if (key == "" || key == null) { |
if (key == "" || key == null) { |
96 |
return; |
return; |
97 |
} |
} |
98 |
document.body.style.cursor = 'wait'; |
document.body.style.cursor = 'wait'; |
99 |
|
$('#vm_' + vm).find('.state').css("background-image", "url('gfx/vps_topyellow.png')"); |
100 |
|
|
101 |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key; |
var url = "action.php?action=" + action + "&uuid=" + uuid + "&key=" + key; |
102 |
var response = $.get(url, function(data) { |
var response = $.get(url, function(data) { |
103 |
alert(data); |
if (data != 'OK') { |
104 |
document.body.style.cursor = 'default' |
alert(data); |
|
if (data == "OK") { |
|
|
window.location.reload(); |
|
105 |
} |
} |
106 |
|
document.body.style.cursor = 'default' |
107 |
|
|
108 |
|
refreshData(); |
109 |
}); |
}); |
110 |
} |
} |
111 |
|
|
124 |
window.open(url); |
window.open(url); |
125 |
} |
} |
126 |
|
|
|
function loadServer() { |
|
|
$('#mainwindow').load('server.php'); |
|
|
} |
|
127 |
|
|
|
function loadvm(uuid) { |
|
|
$('#mainwindow').load('vm.php?uuid=' + uuid ); |
|
|
} |
|
128 |
|
|
129 |
</script> |
</script> |
130 |
|
|
200 |
$harddrive_size = 0; |
$harddrive_size = 0; |
201 |
$cpu_count = $vm["VCPUs_max"]; |
$cpu_count = $vm["VCPUs_max"]; |
202 |
|
|
203 |
|
$clean_name = str_replace(" ", "_", $name); |
204 |
|
$clean_name = str_replace(".", "_", $clean_name); |
205 |
|
|
206 |
|
|
207 |
foreach ($vm["VBDs"] as $vbds) { |
foreach ($vm["VBDs"] as $vbds) { |
208 |
$vbd = $xenserver->VBD__get_record($vbds); |
$vbd = $xenserver->VBD__get_record($vbds); |
209 |
if ($vbd["type"] == 'Disk') { |
if ($vbd["type"] == 'Disk') { |
212 |
} |
} |
213 |
} |
} |
214 |
|
|
|
$vps_topbg = 'vps_topyellow.png'; |
|
215 |
|
|
|
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() ; |
|
|
} |
|
|
|
|
|
|
|
|
$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(); |
|
|
} |
|
|
} |
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
// echo "<a href='#' onclick=\"loadvm('$uuid');\">$name</a><br>\n"; |
|
217 |
?> |
?> |
218 |
<!-- MACHINE --> |
<!-- MACHINE --> |
219 |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='<?php echo $name;?>'> |
<table width='99%' cellpadding='3' cellspacing='0' border='0' class='vps' id='vm_<?php echo $clean_name;?>'> |
220 |
<tr background='gfx/vps_topbg.png'> |
<tr background='gfx/vps_topbg.png' > |
221 |
<td width='10' background='gfx/<?php echo $vps_topbg; ?>' class='small'> </td> |
<td width='10' class='small state'> </td> |
222 |
<td colspan='2' class='small'><b><?php echo $name; ?></b></td> |
<td colspan='2' class='small'><b><?php echo $name; ?></b></td> |
223 |
<td colspan='2' class='small' align='right'> |
<td colspan='2' class='small' align='right'> |
224 |
<?php echo $network;?> |
<span class='network'></span> |
225 |
<?php |
<a href='#' style='display:none;' class='console'> |
226 |
if ($url != "") { |
<img src='gfx/icon-terminal.png' style='vertical-align: middle;'> |
227 |
echo "<a href='#' onclick=\"console('$url','$session')\"><img src='gfx/icon-terminal.png' style='vertical-align: middle;'></a>"; |
</a> |
|
} |
|
|
?> |
|
228 |
</td> |
</td> |
229 |
</tr> |
</tr> |
230 |
|
|
232 |
<td></td> |
<td></td> |
233 |
|
|
234 |
<td width='150' class='small'> |
<td width='150' class='small'> |
235 |
<?php |
<span class="actionstop" style='display:none'> |
236 |
if ($state == "Running") { |
start | |
237 |
echo "start | "; |
<a href='#' onclick="doAction('shutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >stop</a> | |
238 |
echo "<a href='#' onclick=\"doAction('shutdown','$uuid')\">stop</a> | "; |
<a href='#' onclick="doAction('hardshutdown','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >force shutdown</a> |
239 |
echo "<a href='#' onclick=\"doAction('hardshutdown','$uuid')\">force shutdown</a>"; |
</span> |
240 |
} else { |
|
241 |
echo "<a href='#' onclick=\"doAction('start','$uuid')\">start</a> | "; |
<span class="actionstart"> |
242 |
echo "stop | "; |
<a href='#' onclick="doAction('start','<?php echo $uuid;?>','<?php echo $clean_name;?>')" >start</a> | |
243 |
echo "force shutdown"; |
stop | |
244 |
} |
force shutdown |
245 |
?> |
</span> |
246 |
|
|
247 |
</td> |
</td> |
248 |
|
|