-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
144 lines (119 loc) · 4.61 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
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8" />
<meta name="description" content="PHPing: The Pinger" />
<meta name="theme-color" content="#0072C6" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="refresh" content="60">
<link rel="shortcut icon" href="ico_favicon.ico" />
<link rel="stylesheet" type="text/css" href="./css/style.css" />
<title>PHPing: The Pinger</title>
</head>
<body>
<?php
require_once "./php/dbconfig.php";
function renderDevice($status, $name, $number, $lastUpdate)
{
$since = "";
if ($status != "blind") {
if ($lastUpdate == "0000-00-00 00:00:00") {
$since = "
<span> </span>
<span class='sp_since'>" . $status . " since begining</span>
";
} else {
$now = new DateTime();
$last = new DateTime($lastUpdate);
$diff = $now->diff($last);
if ($diff->y > 0) {
$since = "<span class='sp_since'>" . $status . " since " . $diff->y . " years ago</span>";
} else if ($diff->m > 0) {
$since = "<span class='sp_since'>" . $status . " since " . $diff->m . " months ago</span>";
} else if ($diff->d > 0) {
$since = "<span class='sp_since'>" . $status . " since " . $diff->d . " days ago</span>";
} else if ($diff->h > 0) {
$since = "<span class='sp_since'>" . $status . " since " . $diff->h . " hours ago</span>";
} else if ($diff->i > 0) {
$since = "<span class='sp_since'>" . $status . " since " . $diff->i . " minutes ago</span>";
}
$since .= "<span class='sp_lastupdate'>(" . $lastUpdate . ")</span>";
}
} else {
$since = "
<span> </span>
<span class='sp_since'>(unmonitored)</span>
";
}
return "
<div class='div_device " . $status . "'>
<span class='sp_name'>" . $name . "</span>
<span class='sp_name'>" . $number . "</span>" .
$since .
"</div>
";
}
$ipQuery = $conn->query("
SELECT
ip.number,
ip.name,
ip.status,
ip.lastupdate,
ip.priority
FROM
ip
ORDER BY
ip.name
");
$devices = array();
while ($row = $ipQuery->fetch_assoc()) {
$device = array(
"number" => $row["number"],
"name" => $row["name"],
"status" => "",
"lastupdate" => $row["lastupdate"],
"priority" => $row["priority"],
);
if ($row["priority"] == 0) {
$device["status"] = "blind";
} else {
$device["status"] = ($row["status"] == 1) ? "up" : "down";
}
$devices[] = $device;
}
$upDevices = array_filter($devices, function ($device) {
return ($device["status"] == "up");
});
$downDevices = array_filter($devices, function ($device) {
return ($device["status"] == "down");
});
$blindDevices = array_filter($devices, function ($device) {
return ($device["status"] == "blind");
});
echo "<div class='div_monitor'><div class='div_deviceGroup'><div class='div_deviceHeader'>";
echo "<a class='a_title'>Summary ►</a>";
echo "<a class='a_downCount' href='#downDevices'>" . count($downDevices) . " offline ▼</a>";
echo "<a class='a_upCount'>" . count($upDevices) . " online</a>";
echo "<a class='a_blindCount' href='#blindDevices'>" . count($blindDevices) . " unmonitored</a>";
echo "<a id='a_add'><img src='img/img_add.gif' alt='img_add'/></a>";
echo "</div><div class='div_deviceItems' id='downDevices'>";
foreach ($downDevices as $device) {
echo renderDevice($device["status"], $device["name"], $device["number"], $device["lastupdate"]);
}
echo "</div></div><div class='div_deviceGroup'><div class='div_deviceHeader'>";
echo "<a class='a_title'>All Devices (" . count($devices) . ") ▼</a>";
echo "</div><div class='div_deviceItems'>";
foreach ($devices as $device) {
echo renderDevice($device["status"], $device["name"], $device["number"], $device["lastupdate"]);
}
echo "</div></div><div class='div_deviceGroup'><div class='div_deviceHeader'>";
echo "<a class='a_title'>Unmonitored Devices (" . count($blindDevices) . ") ▼</a>";
echo "</div><div class='div_deviceItems' id='blindDevices'>";
foreach ($blindDevices as $device) {
echo renderDevice($device["status"], $device["name"], $device["number"], $device["lastupdate"]);
}
echo "</div></div></div><button class='bt_blue' id='bt_toTop'><img src='img/img_toTop.gif' alt='img_toTop'/></button>";
?>
<script type="text/javascript" src="./js/jquery.js" defer></script>
<script type="text/javascript" src="./js/script.js" defer></script>
</body>