-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.php
256 lines (185 loc) · 6.62 KB
/
index.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
248
249
250
251
252
253
254
255
256
<?php
function humanFileSize($size, $unit="") {
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"] = "YOUR API KEY";
$postfields["hash"] = "YOUR API 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://master.vpshost.tld";
// </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>SolusVM-Status</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div style="width: 90%; max-width: 800px; margin: 0 auto;">
<h1>SolusVM-Status</h1>
<hr/>
<?php if($return['error'] == 1) { ?>
<div class="alert alert-danger" role="alert"><?php echo $return['message']; ?></div>
<a class="btn btn-default btn-block" href="?action=info" role="button">Return to status page</a>
<?php } else { ?>
<?php if($action == "info") { ?>
<h3>Hostname</h3>
<?php echo $return['hostname']; ?>
<h3>Status</h3>
<?php echo $return['vmstat']; ?>
<h3>IP Address</h3>
<?php echo $return['ipaddress']; ?>
<h3>Hard Disk usage <small><?php echo humanFileSize($return['hdd'][1]); ?> used of <?php echo humanFileSize($return['hdd'][0]); ?></small></h3>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $return['hdd'][3]; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $return['hdd'][3]; ?>%;">
<?php echo $return['hdd'][3]; ?>%
</div>
</div>
<h3>RAM usage <small><?php echo humanFileSize($return['mem'][1]); ?> used of <?php echo humanFileSize($return['mem'][0]); ?></small></h3>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $return['mem'][3]; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $return['mem'][3]; ?>%;">
<?php echo $return['mem'][3]; ?>%
</div>
</div>
<h3>Bandwith usage <small><?php echo humanFileSize($return['bw'][1]); ?> used of <?php echo humanFileSize($return['bw'][0]); ?></small></h3>
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $return['bw'][3]; ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo $return['bw'][3]; ?>%;">
<?php echo $return['bw'][3]; ?>%
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Actions</h3>
</div>
<div class="panel-body">
<?php if($return['vmstat'] == "offline") { ?>
<a class="btn btn-primary btn-block" href="?action=boot" role="button">Boot</a>
<?php } else { ?>
<a class="btn btn-primary btn-block" href="?action=shutdown" role="button">Shutdown</a>
<a class="btn btn-primary btn-block" href="?action=reboot" role="button">Reboot</a>
<a class="btn btn-default btn-block" href="?action=info" role="button">Reload the page</a>
<?php } ?>
</div>
</div>
<?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-default btn-block" href="?action=info" role="button">Return to status page</a>
<?php } ?>
<?php } ?>
<footer style="margin: 20px 0; text-align: center;">
<a href="https://github.com/cuonic/SolusVM-Status" target="_blank">SolusVM-Status</a> by Cuonic
</footer>
</div>
</body>
</html>