-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_ping_status.php
44 lines (37 loc) · 1.39 KB
/
get_ping_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
<?php
include 'config.php'; // Veritabanı bağlantısı
try {
// Veritabanından tüm IP'leri alıyoruz
$stmt = $pdo->query("SELECT * FROM ips");
$ips = $stmt->fetchAll(PDO::FETCH_ASSOC);
$response = [
'ips' => [],
'logs' => []
];
foreach ($ips as $ip) {
// Veritabanındaki IP bilgilerini yanıt dizisine ekle
$response['ips'][] = [
'id' => $ip['id'],
'name' => $ip['name'],
'host_port' => $ip['host_port'],
'last_ping_time' => $ip['last_ping_time'],
'result' => $ip['result'],
'uptime' => ($ip['result'] === 'online' && $ip['last_online_time']) ? (new DateTime())->diff(new DateTime($ip['last_online_time']))->format('%h saat %i dakika') : 'N/A'
];
}
// Logları ekleyelim
$log_stmt = $pdo->query("SELECT ip_logs.*, ips.host_port FROM ip_logs JOIN ips ON ip_logs.ip_id = ips.id ORDER BY log_time DESC LIMIT 10");
$logs = $log_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($logs as $log) {
$response['logs'][] = [
'host_port' => $log['host_port'],
'previous_result' => $log['previous_result'],
'current_result' => $log['current_result'],
'log_time' => $log['log_time']
];
}
echo json_encode($response);
} catch (PDOException $e) {
echo json_encode(['error' => $e->getMessage()]);
}
?>