Repository navigation
Expand file tree
/
Copy pathhost.php
More file actions
144 lines (132 loc) · 4.36 KB
/
Copy pathhost.php
File metadata and controls
144 lines (132 loc) · 4.36 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require("mysql_config.php");
$hostid = 1;
if (isset($_GET["hostid"])) { $hostid = $_GET["hostid"]; }
if (isset($_POST["hostid"])) { $hostid = $_POST["hostid"]; }
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysqli_error());
mysqli_set_charset($conn, 'utf8');
mysqli_select_db($conn, DB_DATABASE) or die(mysql_error());
$i_res = mysqli_query($conn, "SELECT * FROM vm as v JOIN vm_data as vd ON vd.name=v.name JOIN vm_hosts AS vh ON vh.id=vd.host WHERE vh.id=$hostid");
$h_res = mysqli_query($conn, "SELECT * FROM vm_hosts WHERE id=$hostid");
$host = mysqli_fetch_object($h_res);
$vms = array();
while($i = mysqli_fetch_object($i_res)){
array_push($vms, $i);
}
?>
<html>
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<style>
table {
width: 100%;
}
table, th, td {
border: 1px solid black;
}
td {
padding: 5px;
}
button, td {
font-size: 40px;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<!-- <h1>Virtuelle Maschinen auf <?php echo $host->description; ?></h1> -->
<table>
<thead>
<th>Name</th>
<th>Status</th>
<th>IP</th>
<th>Funktionen</th>
</thead>
<tbody>
<?php foreach($vms as $vm): ?>
<tr>
<td><?php echo $vm->name; ?></td>
<td>
<div style='width:80px;display: block;text-align: center' id="status_<?php echo $vm->name; ?>">
<img id="status_<?php echo $vm->name; ?>_loading" src="img/loading4.gif" style="width: 60px;"/>
<img id="status_<?php echo $vm->name; ?>_check" src="img/check.png" class="hidden" style="width: 60px;"/>
<img id="status_<?php echo $vm->name; ?>_fail" src="img/fail.png" class="hidden" style="width: 60px;"/>
<img id="status_<?php echo $vm->name; ?>_warning" src="img/warning.png" class="hidden" style="width: 60px;"/>
</div>
</td>
<td><?php echo $vm->ip; ?></td>
<td class="hidden" id="cancel_<?php echo $vm->name; ?>"><button onClick="cancel('<?php echo $vm->name; ?>')">Abbrechen</button></td>
<td class="hidden" id="start_<?php echo $vm->name; ?>"><button onClick="start('<?php echo $vm->name; ?>')">Starten</button></td>
<td class="hidden" id="stop_<?php echo $vm->name; ?>">
<button onClick="window.open('<?php echo $vm->guac_link; ?>')">Verbinden</button>
<button onClick="stop('<?php echo $vm->name; ?>')">Stoppen</button>
</div>
</tr>
<script>
$.ajax({
url: "ping.php",
data: {
"host": "<?php echo $vm->ip; ?>"
},
success: function(data) {
res = JSON.parse(data);
$("#status_<?php echo $vm->name; ?>_loading").hide();
if (res && (res.status ? 1 : 2) != <?php echo $vm->state; ?>) {
$("#status_<?php echo $vm->name; ?>_warning").show();
$("#cancel_<?php echo $vm->name; ?>").show();
var button = $("#cancel_ubuntuserver3").find("button");
button[0].onclick = null;
button.on("click", function() {
manageVM("<?php echo $vm->name; ?>", (res.status ? 1 : 2));
});
} else {
$("#status_<?php echo $vm->name; ?>_" + (res && res.status == 1 ? "check" :"fail")).show();
if (res && res.status) {
$("#start_<?php echo $vm->name; ?>").hide();
$("#stop_<?php echo $vm->name; ?>").show();
} else {
$("#start_<?php echo $vm->name; ?>").show();
$("#stop_<?php echo $vm->name; ?>").hide();
}
}
}
});
</script>
<?php endforeach; ?>
</tbody>
</table>
<script>
function start(name) {
manageVM(name, 1);
};
function stop(name) {
manageVM(name, 2);
};
function manageVM(name, state) {
$("img[id^='status_" + name + "']").hide();
$("#status_" + name + "_loading").show();
$.ajax({
url: "managevm.php",
data: {
name: name,
newState: state
},
success: function(data) {
res = JSON.parse(data);
if (res && res.success) {
setTimeout(() => {
window.location.reload();
}, 1000);
}
}
});
}
</script>
</body>
</html>