forked from Seitanas/kvm-vdi
/
power.php
49 lines (48 loc) · 1.47 KB
/
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
43
44
45
46
47
48
49
<?php
/*
KVM-VDI
Tadas Ustinavičius
tadas at ring.lt
2015-12-10
Vilnius, Lithuania.
*/
include ('functions/config.php');
require_once('functions/functions.php');
if (!check_session()){
header ("Location: $serviceurl/?error=1");
exit;
}
$vm=addslashes($_GET['vm']);
$hypervisor=addslashes($_GET['hypervisor']);
$action=addslashes($_GET['action']);
if (empty($vm)||empty($hypervisor)){
exit;
}
$h_reply=get_SQL_line("SELECT * FROM hypervisors WHERE id='$hypervisor'");
ssh_connect($h_reply[2].":".$h_reply[3]);
if ($action=="mass_on" || $action == "mass_off" || $action == "mass_destroy"){
$child_vms=get_SQL_array("SELECT name FROM vms WHERE source_volume='$vm'");
$x=0;
while ($child_vms[$x]['name']){
if ($action=="mass_on")
ssh_command("sudo virsh start " . $child_vms[$x]['name'],true);
if ($action=="mass_off")
ssh_command("sudo virsh shutdown " . $child_vms[$x]['name'], true);
if ($action=="mass_destroy")
ssh_command("sudo virsh destroy " . $child_vms[$x]['name'], true);
++$x;
}
}
if ($action=="single"){
$v_reply=get_SQL_line("SELECT name FROM vms WHERE id='$vm'");
$state=addslashes($_GET['state']);
if ($state=="up")
ssh_command("sudo virsh start " . $v_reply[0], true);
if ($state=="down")
ssh_command("sudo virsh shutdown " . $v_reply[0], true);
if ($state=="destroy")
ssh_command("sudo virsh destroy " . $v_reply[0], true);
}
header("Location: $serviceurl/reload_vm_info.php");
exit;
?>