/
index.php
42 lines (42 loc) · 1.17 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
<?php
include('../includes/config.php');
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$sId = mysql_real_escape_string($_GET['url']);
if(is_numeric($sId)){
$data = mysql_query("SELECT * FROM servers WHERE id='$sId'");
$result = mysql_fetch_array($data);
$url = "http://".$result['url']."/uptime.php";
$output = get_data($url);
if(($output == NULL) || ($output === false)){
$array = array();
$array['uptime'] = '
<div class="progress">
<div class="bar bar-danger" style="width: 100%;"><small>Down</small></div>
</div>
';
$array['load'] = '
<div class="progress">
<div class="bar bar-danger" style="width: 100%;"><small>Down</small></div>
</div>
';
$array['online'] = '
<div class="progress">
<div class="bar bar-danger" style="width: 100%;"><small>Down</small></div>
</div>
';
echo json_encode($array);
} else {
$data = json_decode($output, true);
$data["load"] = number_format($data["load"], 2);
echo json_encode($data);
}
}