forked from Seitanas/kvm-vdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_power.php
42 lines (42 loc) · 1.14 KB
/
client_power.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
KVM-VDI
Tadas Ustinavičius
tadas at ring.lt
2017-04-24
Vilnius, Lithuania.
*/
include ('functions/config.php');
require_once('functions/functions.php');
if (!check_client_session()){
header ("Location: $serviceurl/?error=1");
exit;
}
slash_vars();
$vm=$_POST['vm'];
$action=$_POST['action'];
if (empty($vm)||empty($action)){
exit;
}
$userid=$_SESSION['userid'];
if ($engine == 'OpenStack')
$v_reply = get_SQL_array("SELECT * FROM vms WHERE osInstanceId='$vm'");
else
$v_reply = get_SQL_array("SELECT * FROM vms WHERE id='$vm'");
if ($v_reply[0]['clientid'] != $userid)//allow only clients, which were given current VM to change its power state
exit;
if ($engine == 'OpenStack')
echo vmPowerCycle($vm, $action);
else {
$h_reply = get_SQL_array("SELECT * FROM hypervisors WHERE id='{$v_reply[0]['hypervisor']}'");
ssh_connect($h_reply[0]['ip'].":".$h_reply[0]['port']);
if ($action == "shutdown"){
ssh_command("sudo virsh shutdown " . $v_reply[0]['name'], true);
}
if ($action == "destroy"){
ssh_command("sudo virsh destroy " . $v_reply[0]['name'], true);
}
}
reload_vm_info();
exit;
?>