-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-delete.php
39 lines (36 loc) · 1 KB
/
vm-delete.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
<?php
// START SESSION
session_start();
// LOGOUT REQUEST
if (isset($_POST["logout"])) { unset($_SESSION["user"]); }
// REDIRECT TO LOGIN PAGE IF NOT LOGGED IN
if (!isset($_SESSION["user"])) {
header("Location: login.php");
exit();
}
// CONNECT
$uri="qemu:///system";
echo ("Connecting to KVM host via (URI:$uri)\n"."<br/>"."<br/>");
$conn=libvirt_connect($uri,false);
if ($conn==false)
{
echo ("Libvirt last error: ".libvirt_get_last_error()."\n");
exit;
}
// ASSIGN SELECTED DOMAIN TO VARIABLE
if (isset($_POST['vmid'])) {
$vmid = $_POST['vmid'];
}
// CHECK FOR USER CONFIRMATION
if (isset($_POST['confirm'])) {
destroy($conn, $vmid);
}
// VM DESTROY FUNCTION
function destroy($conn, $vmid) {
echo "Deleting " . $vmid;
$res = libvirt_domain_lookup_by_name($conn, $vmid);
libvirt_domain_shutdown($res);
libvirt_domain_undefine($res);
header("Location: machines.php");
}
?>