-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.php
64 lines (54 loc) · 1.91 KB
/
status.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
define("DATABASE_SERVER", "localhost");
define("DATABASE_USER", "api");
define("DATABASE_PASSWORD", "********");
$outcome = array();
function GetDDBState($name)
{
$connection = mysql_connect(DATABASE_SERVER, DATABASE_USER, DATABASE_PASSWORD);
mysql_select_db($name, $connection);
$result = mysql_query("SELECT MAX(`Date`) AS `date` FROM Tables", $connection);
$row = mysql_fetch_assoc($result);
mysql_close($connection);
$date = DateTime::createFromFormat("Y-m-d H:i:s", $row["date"], new DateTimeZone("UTC"));
return array("date" => $date->getTimestamp());
}
function GetRP2CState($file)
{
$data = file_get_contents($file);
$parameters = unpack("A19date/@31/astate", $data);
$date = DateTime::createFromFormat("Y-m-d H:i:s", $parameters["date"], new DateTimeZone("UTC"));
$state = ($parameters["state"] == '*');
return array("date" => $date->getTimestamp(), "state" => $state);
}
function GetCCSState($file)
{
$data = file_get_contents($file);
$parameters = unpack("Lnumber/Lzero/a14date", $data);
$date = DateTime::createFromFormat("YmdHis", $parameters["date"], new DateTimeZone("CET"));
return array("date" => $date->getTimestamp());
}
function GetMasterState($file)
{
$data = file_get_contents($file);
$parameters = unpack("Qdate", $data);
return array("date" => $parameters["date"]);
}
$outcome = array(
"A" => GetDDBState("Local"),
"B" => GetDDBState("Global"),
"C" => GetRP2CState("/opt/BorderGate/Data/ModuleC.dat"),
"D" => GetCCSState("/opt/BorderGate/Data/ModuleD.dat"),
"E" => GetMasterState("/opt/BorderGate/Data/ModuleE.dat")
);
if (array_key_exists("callback", $_GET))
{
header("Conent-Type: application/javascript");
print($_GET["callback"] . "(" . json_encode($outcome) . ")");
}
else
{
header("Conent-Type: application/json");
print(json_encode($outcome));
}
?>