-
Notifications
You must be signed in to change notification settings - Fork 1
/
VM_approval.php
executable file
·247 lines (224 loc) · 10.8 KB
/
VM_approval.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
session_start();
require_once 'checksession.php' ;
require_once 'db_connect.php';
require_once 'header.php';
require_once('logging.php');
if($_SESSION['privilege']!='A'){
header("location:VMdetails.php");
}
if( isset($_GET['VM_name']) && (!empty($_GET['VM_name'])) )
{
$query='SELECT VM_name,username,os,cpu,ram,storage,doe FROM VMrequest WHERE VM_name = :vm_name';
$param = array(
":vm_name"=>$_GET['VM_name']
);
$db = getDBConnection();
$stmt = PrepareQuery($db,$query);
if(!executeQuery($stmt,$param)){
$l = logError("1101");
$l[0]->log($l[1]);
header("location:error.php?error=1101");
die();
}
if($row = $stmt->fetch()){
$VM_name = $row['VM_name'];
$username = $row['username'];
$os = $row['os'];
$cpu = $row['cpu'];
$ram = $row['ram'];
$storage = $row['storage'];
$doe = $row['doe'];
}
$query = "SELECT description FROM name_description WHERE name=:vm_name";
$stmt = prepareQuery($db,$query);
if(!executeQuery($stmt,$param)){
$l = logError("1102");
$l[0]->log($l[1]);
header("location:error.php?error=1102");
die();
}
$row = $stmt->fetch();
$description = $row['description'];
}
?>
<link rel="stylesheet" href="includes/css/jquery-ui.css">
<script src="includes/js/jquery.min.js"></script>
<script src="includes/js/jquery-ui.min.js"></script>
<script>
function isValidDate(date)
{
var matches = /^(\d{1,2})[-\/](\d{1,2})[-\/](\d{4})$/.exec(date);
if (matches == null) return false;
var d = matches[2];
var m = matches[1] - 1;
var y = matches[3];
var composedDate = new Date(y, m, d);
return composedDate.getDate() == d &&
composedDate.getMonth() == m &&
composedDate.getFullYear() == y;
}
function validateForm(){
var name = document.forms["request"]["VM_name"].value;
var date = document.forms["request"]["doe"].value;
//var val = document.getElementById("res");
//alert("wait:"+name+"res:"+val.innerHTML);
if(name==""){
alert("VM name should be unique and should not contain special characters or spaces");
return false;
}
if(!isValidDate(date)){
alert("Date Format is : mm/dd/yyyy");
return false;
}
var x = date.split("/");
var newdate = ""+x[2]+"-"+x[0]+"-"+x[1]+"";
document.forms["request"]["doe"].value = newdate;
//alert(""+newdate);
return true;
}
function checkVMNameValidity(){ //
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4 && xmlHttp.status==200){
document.getElementById('res').innerHTML = xmlHttp.response;
}
}
var VM_name = document.getElementById('VM_name').value;
//alert('hello : '+VM_name+'');
xmlHttp.open('GET','check_VMname_validity.php'+'?VM_name='+VM_name+'&t='+Math.random(),true);
xmlHttp.send();
}
$(document).ready(function() {
$("#datepicker").datepicker();
});
window.onload = function(){
//alert('hello');
var date = document.forms["request"]["doe"].value;
//alert(date);
var arr = date.split('-');
//alert('hi/');
var newdate = arr[1]+'/'+arr[2]+'/'+arr[0];
//alert(''+newdate);
document.forms["request"]["doe"].value = newdate;
}
</script>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-2">
<?php include 'navigation_bar.php'; ?>
</div>
<div class="col-sm-8">
<br>
<div class="row" id="features">
<div class="col-sm-2">
</div>
<div class="col-sm-8 text-left">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Requirements given by user : <?php echo $username; ?> </h3>
</div>
<form name="request" class="form-horizontal" role="form" action="create_vm.php" method='POST' onsubmit="return validateForm();">
<div class="form-group">
<label class="control-label col-sm-3">Username:</label>
<div class="col-sm-7">
<input type="text" class="form-control" id="username" name="username" value=<?php echo '"'.$username.'"'; ?> readonly>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="pwd">VM Name:</label>
<div class="col-sm-7" >
<input type="text" class="form-control" id="VM_name" name="VM_name" value=<?php echo '"'.$VM_name.'"'; ?> >
</div>
<div class="col-sm-2" id="res"></div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="description">Description:</label>
<div class="col-sm-7">
<textarea class="form-control" name="description" id="description"><?php echo $description;?></textarea>
</div>
</div>
<div class="form-group" id="main_form">
<label class="control-label col-sm-3" for="os">OS:</label>
<div class="col-sm-7">
<select class="form-control" name="os" id="os" >
<?php
$sql = "SELECT * FROM `template`";
$stmt = prepareQuery($db,$sql);
executeQuery($stmt,array());
while($row = $stmt->fetch()){
echo '<option value="'.$row['name'].'"';
if($os == $row['name']){
echo ' selected="selected"';
}
echo '>'.$row['name'].'</option>';
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="pwd">vCPU:</label>
<div class="col-sm-7">
<input class="form-control" type="number" name="cpu" id="cpu" value=<?php echo '"'.$cpu.'"';?>>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="pwd">Storage(GB):</label>
<div class="col-sm-7">
<input type="number" name="storage" id="storage" class="form-control" value=<?php echo '"'.$storage.'"'; ?>>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="pwd">RAM(MB):</label>
<div class="col-sm-7">
<input type="number" name="ram" id="ram" class="form-control" value=<?php echo '"'.$ram.'"'; ?>>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3">Date of Expiry:</label>
<div class="col-sm-7">
<input type="text" class="form-control" id="datepicker" placeholder="mm/dd/yyyy" name="doe" value=<?php echo '"'.$doe.'"'; ?> >
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="pwd">Hypervisor:</label>
<div class="col-sm-7">
<select class="form-control" name="hypervisor" id="hypervisor" >
<?php
$query= "SELECT * FROM hypervisor";
$stmt = PrepareQuery($db,$query);
executeQuery($stmt,array());
while($row = $stmt->fetch()){
echo '<option value="'.$row['name'].'">'.$row['name'].'</option>';
}
?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="submit" class="btn btn-danger btn-sm form-horizontal-sm pull-right" name="button" value="Reject" style="margin: 0 15px 15px 0;">
<input type="submit" class="btn btn-info btn-sm form-horizontal-sm pull-right" name="button" value="Approve" style="margin: 0 15px 15px 0;">
</div>
</div>
</form>
</div>
<br>
<h4 style="color:red;">Note</h4>
<ul class="list-group list">
<li class="list-group-item list-group-item-info">
<span class="glyphicon glyphicon-pencil"></span> Please check the memory availability before creating VM. VM would be created but not start if low on memory.</li>
</ul>
</div>
<div class="col-sm-2">
</div>
</div>
</div>
</div>
<div class="col-sm-1"></div>
<br>