-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddCluster.php
64 lines (56 loc) · 1.68 KB
/
AddCluster.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
<?php
if(!isset($_SESSION))
{
session_start();
}
include 'connect.php';
if($_SERVER['REQUEST_METHOD']=='POST'){
$username=$_SESSION['Username'];
$userId=$_SESSION['UserId'];
$ipAddress=$db->real_escape_string($_POST['ipAddress']);
$password="CloudFi"; //$db->real_escape_string($_POST['password']);n
$hostName=$db->real_escape_string($_POST['hostname']);
$sql="insert into tblcluster (UserId, Ip, password, IsActive,hostname) values ('$userId','$ipAddress','$password',0,'$hostName')";
if($db->query($sql)==TRUE){
$ClusterInsertedId=$db->insert_id;
$output= shell_exec("ping ".$ipAddress." -c 1 -w 1");
$pos= strpos($output,'received');
$pingStatus=(int)substr($output,$pos-2,1);
if($pingStatus==1){
$output = shell_exec("sshpass -p 'CloudFi' ssh -o StrictHostKeyChecking=no CloudFi@".$ipAddress." df /home");
//echo "<pre>$output</pre>";
$resultArry=explode(' ',$output);
$availableSpace= $resultArry[24];
echo $availableSpace;
$sql="update tblcluster set IsActive=1,Space=$availableSpace where ClusterId=$ClusterInsertedId";
if($db->query($sql)==TRUE){
echo "Cluster added";
}else{
echo "Fail to update cluster status";
echo mysqli_error($db);
}
}else{
echo "Fail to ping";
}
//if fail to ping
//send retry message
}else{
echo mysqli_error($db);
}
}else{
?>
<!DOCTYPE html>
<html>
<title>Add Cluster</title>
<body>
<form action="AddCluster.php" method="POST">
<input type="text" name="ipAddress" placeholder="IP Address" /> <br/>
<input type="text" name="hostname" placeholder="HostName"><br/>
<input type="text" name="password" placeholder="Password of Cluster" /> <br/>
<input type="submit" name="Submit"/>
</form>
</body>
</html>
<?php
}
?>