-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
249 lines (200 loc) · 6.3 KB
/
index.php
File metadata and controls
249 lines (200 loc) · 6.3 KB
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
248
249
<?php
function humanFileSize($size, $unit = "")
{
if ((!$unit && $size >= 1 << 40) || $unit == "TB") return number_format($size / (1 << 40) , 2) . " TB";
if ((!$unit && $size >= 1 << 30) || $unit == "GB") return number_format($size / (1 << 30) , 2) . " GB";
if ((!$unit && $size >= 1 << 20) || $unit == "MB") return number_format($size / (1 << 20) , 2) . " MB";
if ((!$unit && $size >= 1 << 10) || $unit == "KB") return number_format($size / (1 << 10) , 2) . " KB";
return number_format($size) . " bytes";
}
function post($action)
{
// Prepare the POST data
// <configure> :
$postfields["key"] = "";
$postfields["hash"] = "";
// This is the hostname of the master SolusVM server where you go to boot / reboot / configure / reinstall / get API keys for your VPS
$masterurl = "https://vps.solovm.com";
// </configure>
$postfields["action"] = $action;
$postfields["status"] = "true";
if ($action == "info")
{
$postfields["hdd"] = "true";
$postfields["mem"] = "true";
$postfields["bw"] = "true";
}
// Prepare the POST request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "{$masterurl}/api/client/command.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Expect: "
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// Execute the request
$data = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code != 200)
{
$return['error'] = 1;
if ($code == 405)
{
$return['message'] = "Incorrect API credentials.";
return $return;
}
$return['message'] = "Invalid status code.";
return $return;
}
// Close the Curl handle
curl_close($ch);
if (!$data)
{
$return['error'] = 1;
$return['message'] = "Error connecting to API.";
return $return;
}
// Extract the data
preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $match);
$result = array();
foreach($match[1] as $x => $y)
{
$result[$y] = $match[2][$x];
}
if ($result['status'] == "error")
{
$return['error'] = 1;
$return['message'] = $result['statusmsg'];
return $return;
}
$return = $result;
$return['error'] = 0;
return $return;
}
if (isset($_GET['action']))
{
$action = $_GET['action'];
}
else
{
$action = "info";
}
switch ($action)
{
case 'info':
$result = post("info");
if ($result['error'] == 0)
{
$return = $result;
$return['hdd'] = explode(",", $return['hdd']);
$return['mem'] = explode(",", $return['mem']);
$return['bw'] = explode(",", $return['bw']);
}
else
{
$return = $result;
}
break;
case 'reboot':
$result = post("reboot");
if ($result['error'] == 0)
{
$return = $result;
$return['message'] = "Server rebooting now.";
}
else
{
$return = $result;
}
break;
case 'boot':
$result = post("boot");
if ($result['error'] == 0)
{
$return = $result;
$return['message'] = "Server booting now.";
}
else
{
$return = $result;
}
break;
case 'shutdown':
$result = post("shutdown");
if ($result['error'] == 0)
{
$return = $result;
$return['message'] = "Server shutting down now.";
}
else
{
$return = $result;
}
break;
default:
$return['error'] = 1;
$return['message'] = "Invalid action specified.";
}
?>
<!doctype html>
<html>
<head>
<title><?php echo $return['hostname']; ?> | VPS Control Panel</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<div style="width: 90%; margin: 20px auto 40px auto; max-width: 768px;">
<div class="btn-group" role="group">
<?php if($return['vmstat'] == "offline") { ?>
<a class="btn btn-secondary" href="?action=boot" role="button">Boot</a>
<?php } else { ?>
<a class="btn btn-secondary" href="?action=shutdown" role="button">Shutdown</a>
<a class="btn btn-secondary" href="?action=reboot" role="button">Reboot</a>
<a class="btn btn-secondary" href="?action=info" role="button">Reload</a>
<?php } ?>
</div>
<div class="btn-group" role="group" style="padding-left: 10px;">
<a class="btn btn-secondary" href="?action=logout" role="button">Logout</a>
</div>
<hr/>
<?php if($return['error'] == 1) { ?>
<div class="alert alert-danger" role="alert"><?php echo $return['message']; ?></div>
<a class="btn btn-secondary" href="?action=info" role="button">Home</a>
<?php } else { ?>
<?php if($action == "info") { ?>
<h3 class="display-4">Hostname</h3>
<p><?php echo $return['hostname']; ?><p>
<h3 class="display-4">Status</h3>
<p><?php echo $return['vmstat']; ?><p>
<h3 class="display-4">IP Address</h3>
<p><?php echo $return['ipaddress']; ?></p>
<h3 class="display-4">Hard Disk</h3>
<p><?php echo $return['hdd'][3]; ?>% (<?php echo humanFileSize($return['hdd'][1]); ?> used of <?php echo humanFileSize($return['hdd'][0]); ?>)
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $return['hdd'][3]; ?>" aria-valuemin="0" aria-valuemax="100" style="height: 21px; width: <?php echo $return['hdd'][3]; ?>%;">
</div>
</div></p>
<h3 class="display-4">RAM</h3>
<p><?php echo $return['mem'][3]; ?>% (<?php echo humanFileSize($return['mem'][1]); ?> used of <?php echo humanFileSize($return['mem'][0]); ?>)
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $return['mem'][3]; ?>" aria-valuemin="0" aria-valuemax="100" style="height: 21px; width: <?php echo $return['mem'][3]; ?>%;">
</div>
</div></p>
<h3 class="display-4">Bandwidth</h3>
<p><?php echo $return['bw'][3]; ?>% (<?php echo humanFileSize($return['bw'][1]); ?> used of <?php echo humanFileSize($return['bw'][0]); ?>)
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $return['bw'][3]; ?>" aria-valuemin="0" aria-valuemax="100" style="height: 21px; width: <?php echo $return['bw'][3]; ?>%;">
</div>
</div></p>
<?php } ?>
<?php if($action == "reboot" || $action == "boot" || $action == "shutdown") { ?>
<?php if($return['error'] == 0) { ?>
<div class="alert alert-success" role="alert"><?php echo $return['message']; ?></div>
<?php } ?>
<a class="btn btn-secondary" href="?action=info" role="button">Home</a>
<?php } } ?>
</body>
</html>