forked from Seitanas/kvm-vdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm_info.php
129 lines (126 loc) · 4.66 KB
/
vm_info.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
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
<?php
/*
KVM-VDI
Tadas Ustinavičius
tadas at ring.lt
Vilnius University.
Center of Information Technology Development.
Vilnius,Lithuania.
2016-08-03
*/
include ('functions/config.php');
require_once('functions/functions.php');
if (!check_session()){
header ("Location: $serviceurl/?error=1");
exit;
}
slash_vars();
$vm=$_GET['vm'];
$hypervisor=$_GET['hypervisor'];
if (empty($vm)||empty($hypervisor)){
exit;
}
$h_reply=get_SQL_line("SELECT * FROM hypervisors WHERE id='$hypervisor'");
$v_reply=get_SQL_array("SELECT * FROM vms WHERE id='$vm'");
$source_machines_reply=get_SQL_array("SELECT * FROM vms WHERE hypervisor='$hypervisor' AND (machine_type='sourcemachine' OR machine_type='initialmachine') AND id<>'$vm' ORDER BY name");
set_lang();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="POST" action="vm_update.php">
<input type="hidden" name="hypervisor" value="<?php echo $hypervisor; ?>">
<input type="hidden" name="vm" value="<?php echo $vm; ?>">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">VM name: <?php echo $v_reply[0]['name']; ?></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-3">
<label><?php echo _("OS type:");?></label>
<select class="form-control" name="os_type" id="os_type">
<option value="linux"><?php echo _("Linux");?></option>
<option value="windows"><?php echo _("Windows");?></option>
</select>
</div>
<div class="col-md-9"></div>
</div>
<div class="row">
<div class="col-md-5">
<label><?php echo _("Machine type:");?></label>
<select class="form-control" name="machine_type" id="machine_type">
<?php if (empty($v_reply[0]['machine_type'])){?>
<option selected value=""><?php echo _("Please select machine type");?></option> <?php } ?>
<option value="simplemachine"><?php echo _("Simple machine");?></option>
<option value="initialmachine"><?php echo _("Initial machine");?></option>
<option value="sourcemachine"><?php echo _("Source machine");?></option>
<option value="vdimachine"><?php echo _("VDI machine");?></option>
</select>
</div>
<div class="col-md-5 hide" id="sourcevolume">
<label>Use volume from:</label>
<?php
echo '<select class="form-control" name="source_volume" id="source_volume">';
$x=0;
while ($x<sizeof($source_machines_reply)){
echo '<option class="' . $source_machines_reply[$x]['machine_type'] .'" value="' . $source_machines_reply[$x]['id'] . '"> ' . $source_machines_reply[$x]['name'] . "</option>\n";
++$x;
}
echo '</select>';?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo _("Use virtual snapshots");?></label>
<input type="checkbox" name="snapshot" id="snapshot">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo _("Close");?></button>
<button type="submit" class="btn btn-primary"><?php echo _("Save changes");?></button>
</div>
</div>
</form>
<script>
function refresh_select(){
$('#source_volume .sourcemachine').show();
$('#source_volume .initialmachine').show();
}
$('#machine_type').on('change', function(){
refresh_select();
if ($(this).val() == 'initialmachine') {
$('#source_volume .initialmachine').hide();
$('#sourcevolume').removeClass('hide');
$('#source_volume').prop('selectedIndex', -1);
}
if ($(this).val() == 'vdimachine') {
$('#source_volume .sourcemachine').hide();
$('#sourcevolume').removeClass('hide');
$('#source_volume').prop('selectedIndex', -1);
}
if ($(this).val() == 'sourcemachine') {
$('#sourcevolume').addClass('hide');
}
if ($(this).val() == 'simplemachine') {
$('#sourcevolume').addClass('hide');
}
})
<?php if (!empty($v_reply[0]['os_type'])){?>
$("#os_type").val(<?php echo '"' . $v_reply[0]['os_type'] . '"'; ?>).change();
<?php } ?>
<?php if (!empty($v_reply[0]['machine_type'])){?>
$("#machine_type").val(<?php echo '"' . $v_reply[0]['machine_type'] . '"'; ?>).change();
<?php } ?>
<?php if (!empty($v_reply[0]['source_volume'])){?>
$("#source_volume").val(<?php echo '"' . $v_reply[0]['source_volume'] . '"'; ?>).change();
<?php } ?>
$("#snapshot").prop('checked', <?php if (empty($v_reply[0]['snapshot'])||$v_reply[0]['snapshot']=='false') echo 0; else echo 1; ?>);
</script>
</body>
</html>