-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.php
134 lines (120 loc) · 5.92 KB
/
create.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
130
131
132
133
<?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';
// SET HOSTNAME VARIABLE
$host = $_SERVER['HTTP_HOST'];
// PULL SERVER INFO FOR CREATION
$netflags= VIR_NETWORKS_ALL;
$net = libvirt_list_networks($conn, $netflags);
// INCLUDE HEADER FILE
include 'header.php';
// PAGE CONTENT
echo '
<!-- End of Topbar -->
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Create New VM</h1>
</div>
<p class="h4">Basic Info</p>
<form method="POST" action="vm-create.php" enctype="multipart/form-data">
<div class="form-group col-md-3">
<label for="InputName">Virtual Machine Name</label>
<input type="text" class="form-control" id="InputName" name="hostname" aria-describedby="nameHelp" placeholder="Enter Name" required>
<small id="nameHelp" class="form-text text-muted"></small>
</div>
<div class="form-group col-md-3">
<label for="InputName">Server</label>
<select class="custom-select" name="server">
<option value="0" selected>' . $host . ' (This Server)</option>
</select>
</div>
<div class="form-group col-md-2">
<label for="InputMemory">Memory (MBs)</label>
<input type="text" class="form-control" id="InputMemory" name="memory" aria-describedby="memoryHelp" placeholder="1024" required>
<small id="memoryHelp" class="form-text text-muted">1GB = 1024MBs</small>
</div>
<div class="form-group col-md-2">
<label for="InputCPU">Virtual CPUs</label>
<input type="text" class="form-control" id="InputCPU" name="cpus" aria-describedby="cpuHelp" placeholder="1" required>
<small id="cpuHelp" class="form-text text-muted"></small>
</div>
<hr>
<p class="h4">Storage Info</p>
<strong>Create new virtual disk</strong>
<div class="form-group col-md-2">
<label for="InputDisk">Virtual Disk Size (GBs)</label>
<input type="text" class="form-control" id="InputDisk" name="newdisk" aria-describedby="diskHelp" placeholder="">
<small id="diskHelp" class="form-text text-muted"></small>
</div>
<strong>Or use existing virtual disk</strong>
<div class="form-group col-md-3">
<select class="custom-select" name="existdisk">
<option value="0" selected>Select Existing Disk Image</option>
';
$diskList = glob('/var/lib/libvirt/images/*.qcow2');
foreach($diskList as $filename){
if(is_file($filename)){
echo "<option value='$filename'>$filename</option>";
}
}
echo '
</select>
</div>
<strong>Add VM to Backup Schedule</strong>
<div class="form-group col-md-3">
<div class="custom-control custom-checkbox small">
<input type="checkbox" class="custom-control-input" id="customCheck" name="backup">
<label class="custom-control-label" for="customCheck">Backup Enabled</label>
</div>
</div>
<hr>
<p class="h4">Network Info</p>
<div class="form-group col-md-3">
<select class="custom-select" name="network" required>
<option value="" selected>Select Network</option>
';
for ($i = 0, $n = count($net) ; $i < $n ; $i++)
{
echo "<option value='$net[$i]'>$net[$i]</option>";
}
echo '
</select>
</div>
<hr>
<p class="h4">Choose ISO</p>
<div class="form-group col-md-3">
<select class="custom-select" name="iso" required>
<option value="" selected>Select iso image</option>
';
$isoList = glob('uploads/*');
foreach($isoList as $filename){
if(is_file($filename)){
echo "<option value='$filename'>$filename</option>";
}
}
echo '
</select>
<small id="isoHelp" class="form-text text-muted">Image not listed? Upload it <a href="images.php">here.</a></small>
</div>
<div class="form-group col-md-3">
<button type="submit" class="btn btn-primary">Create</button>
</div>
</form>
</div>
<!-- /.container-fluid -->
</div>
<!-- End of Main Content -->
';
// INCLUDE HEADER FILE
include 'footer.php';