forked from Seitanas/kvm-vdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_hypervisors.php
75 lines (75 loc) · 2.06 KB
/
update_hypervisors.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
<?php
include ('functions/config.php');
require_once('functions/functions.php');
if (!check_session()){
header ("Location: $serviceurl/?error=1");
exit;
}
slash_vars();
$name='';
$type='';
if (isset($_POST['type']))
$type=$_POST['type'];
if (isset($_POST['name']))
$name=$_POST['name'];
if ($type=='new'){
if (empty($_POST['address1'])){
echo 'EMPTY_ADDRESS';
exit;
}
else $address1=$_POST['address1'];
if (!empty($_POST['address2']))
$address2=$_POST['address2'];
else
$address2=$address1;
if (!empty($_POST['port']))
$port=$_POST['port'];
else
$port=22;
$existing=get_SQL_line("SELECT id FROM hypervisors WHERE ip = '$address1'");
if (!empty($existing[0])){
echo 'EXISTS';
exit;
}
$reply=ssh_connect($address1 . ":" . $port);
if (!empty($reply)) {
echo $reply;
exit;
}
else {
$output=ssh_command("sudo virsh list --all",true);
if (strpos($output, 'sudo:')!== false){ //check if sudo is configured
echo 'SUDO_FAILURE';
exit;
}
add_SQL_line("INSERT INTO hypervisors (name,ip, port, maintenance,address2) VALUES ('$name','$address1','$port',0,'$address2')");
echo 'SUCCESS';
}
exit;
}
if ($name=='update-name'){//using x-editable jQuery plugin, which uses different param naming
$pk=$_POST['pk'];
$value=$_POST['value'];
add_SQL_line("UPDATE hypervisors SET name='$value' WHERE id='$pk'");
exit;
}
if ($name=='update-address'){//using x-editable jQuery plugin, which uses different param naming
$pk=$_POST['pk'];
$value=$_POST['value'];
add_SQL_line("UPDATE hypervisors SET ip='$value' WHERE id='$pk'");
exit;
}
if ($name=='update-spice'){//using x-editable jQuery plugin, which uses different param naming
$pk=$_POST['pk'];
$value=$_POST['value'];
add_SQL_line("UPDATE hypervisors SET address2='$value' WHERE id='$pk'");
exit;
}
if ($type=='delete'){
$hypervisor=$_POST['hypervisor'];
foreach ($hypervisor as $id){
add_SQL_line("DELETE FROM hypervisors WHERE id='$id'");
add_SQL_line("DELETE FROM vms WHERE hypervisor='$id'");
}
}
?>