-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachines.php
More file actions
94 lines (74 loc) · 2.72 KB
/
machines.php
File metadata and controls
94 lines (74 loc) · 2.72 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?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();
}
// INCLUDE CONNECT FILE
include 'connect.php';
// INCLUDE HEADER FILE
include 'header.php';
// PAGE CONTENT
echo '
<meta http-equiv="refresh" content="10">
<!-- End of Topbar -->
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800">Virtual Machines</h1>
<p><a href="create.php" class="btn btn-primary btn-icon-split">
<span class="icon text-white-50">
<i class="fas fa-plus"></i>
</span>
<span class="text">Create New VM</span>
</a></p>
';
// ADD IN JQUERY LIBRARY
echo "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script>";
// LIST VMS
$doms = libvirt_list_domains($conn);
echo "<table class='table'><thead><tr><th scope='col'>Active</th><th scope='col'>Name</th><th scope='col'>Controls</th></tr></thead><tbody>";
for ($i = 0, $n = count($doms) ; $i < $n ; $i++)
{
echo "<tr><th scope='row'>";
// DISPLAY ACTIVE ICON
$res = libvirt_domain_lookup_by_name($conn, $doms[$i]) ;
if (libvirt_domain_get_id($res) != "-1") {echo " " . "🟢";} else {echo " " . "🔴";} ;
echo "</th>";
// DISPLAY VM NAME AND INFO LINK
echo "<td><a href='vm.php?vmid=" . $doms[$i] . "'>" . $doms[$i] . "</a></td><td>";
// DISPLAY POWER BUTTONS
if (libvirt_domain_get_id($res) == "-1") {echo "<input type='submit' class='btn btn-success button' name='start' data-value='" . $doms[$i] . "' value='Start' />";}
else {echo "<input type='submit' class='btn btn-danger button' name='shutdown' data-value='" . $doms[$i] . "' value='Shutdown' />"; }
echo "</td></tr>" ;
}
// CLOSE TABLE
echo "</tbody></table>" ;
// VM CONTROLS JS
echo "
<script>$(document).ready(function(){
$('.button').click(function(){
var clickBtnValue = $(this).val();
var clickBtnDom = $(this).attr('data-value');
var ajaxurl = 'vm-func.php';
data = {'action': clickBtnValue, 'seldom': clickBtnDom};
$.post(ajaxurl, data, function (response) {
// Response div goes here.
location.reload();
});
});
});
</script>
";
echo '
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
';
// INCLUDE HEADER FILE
include 'footer.php';