-
Notifications
You must be signed in to change notification settings - Fork 0
/
tanpaupdate.php
90 lines (80 loc) · 2.73 KB
/
tanpaupdate.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
<?php
require('routeros_api.class.php');
$API = new RouterosAPI();
$status = '';
if ($API->connect('192.168.2.1', '1234', '4321')) {
$data = $API->comm('/tool/netwatch/print');
$API->disconnect();
// Urutkan data berdasarkan host secara numerik ascending
usort($data, function($a, $b) {
$hostA = ip2long($a['host'] ?? '0.0.0.0');
$hostB = ip2long($b['host'] ?? '0.0.0.0');
return $hostA <=> $hostB;
});
$status = '<table class="table table-bordered" style="border-collapse: collapse; width: 100%;">';
$status .= '<thead><tr><th>Name</th><th>Address</th><th>Status</th><th>Timeout</th></tr></thead>';
$status .= '<tbody>';
foreach ($data as $entry) {
$statusColor = '';
if (isset($entry['status'])) {
if ($entry['status'] == 'up') {
$statusColor = 'table-success';
} elseif ($entry['status'] == 'down') {
$statusColor = 'table-danger';
} elseif ($entry['status'] == 'unknown') {
$statusColor = 'table-warning';
}
}
$status .= '<tr class="' . $statusColor . '">';
$status .= '<td>' . htmlspecialchars($entry['comment'] ?? 'N/A') . '</td>';
$status .= '<td>' . htmlspecialchars($entry['host'] ?? 'N/A') . '</td>';
$status .= '<td>' . htmlspecialchars($entry['status'] ?? 'N/A') . '</td>';
$status .= '<td>' . htmlspecialchars($entry['timeout'] ?? 'N/A') . '</td>';
$status .= '</tr>';
}
$status .= '</tbody></table>';
} else {
$status = 'Gagal terhubung ke MikroTik.';
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Status Netwatch MikroTik</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.3.3/css/bootstrap.min.css">
<style>
body {
padding: 20px;
}
.table-container {
width: 80%;
margin: auto;
}
table {
border: 1px solid #dee2e6;
width: 100%;
}
th, td {
border: 1px solid #dee2e6 !important; /* Tambahkan batas dalam tabel */
}
.table-success {
background-color: #d4edda !important;
}
.table-danger {
background-color: #f8d7da !important;
}
.table-warning {
background-color: #fff3cd !important;
}
</style>
</head>
<body>
<h1>Status Netwatch MikroTik</h1>
<div class="table-container">
<?php echo $status; ?>
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.3.3/js/bootstrap.bundle.min.js"></script>
</body>
</html>