Repository navigation
Expand file tree
/
Copy pathmonitor.php
More file actions
103 lines (93 loc) · 4.73 KB
/
Copy pathmonitor.php
File metadata and controls
103 lines (93 loc) · 4.73 KB
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
<?php
require_once __DIR__ . '/inc/bootstrap.php';
requireLogin();
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html>
<head>
<title>OPNsense Health Monitor</title>
<meta http-equiv="refresh" content="30">
<style>
body { font-family: Arial, sans-serif; background: var(--bg); color: var(--text-primary); padding: 20px; }
.container { max-width: 800px; margin: 0 auto; }
.firewall { background: var(--bg-elevated); margin: 10px 0; padding: 15px; border-radius: 5px; border-left: 4px solid #4CAF50; }
.firewall.offline { border-left-color: #f44336; }
.firewall.warning { border-left-color: #ff9800; }
.status { font-weight: bold; }
.online { color: #4CAF50; }
.offline { color: #f44336; }
.warning { color: #ff9800; }
.header { text-align: center; margin-bottom: 30px; }
.info { margin: 5px 0; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔥 OPNsense Health Monitor</h1>
<p>Auto-refreshes every 30 seconds</p>
<p>Current time: <?php echo date('Y-m-d H:i:s'); ?> UTC</p>
</div>
<?php
try {
$stmt = db()->prepare('SELECT id, hostname, wan_ip, lan_ip, agent_version, version, last_checkin, status FROM firewalls ORDER BY hostname');
$stmt->execute();
$firewalls = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($firewalls)) {
echo '<div class="firewall"><p>No firewalls found in the system.</p></div>';
} else {
foreach ($firewalls as $fw) {
$lastCheckin = $fw['last_checkin'];
$minutesAgo = $lastCheckin ? round((time() - strtotime($lastCheckin)) / 60) : 999;
$statusClass = 'offline';
$statusText = '🔴 Offline';
if ($minutesAgo <= 5) {
$statusClass = 'online';
$statusText = '🟢 Online';
} elseif ($minutesAgo <= 15) {
$statusClass = 'warning';
$statusText = '🟡 Warning';
}
$timeAgo = $minutesAgo < 60 ? "{$minutesAgo} min ago" : round($minutesAgo/60) . " hr ago";
if ($minutesAgo < 1) $timeAgo = "Just now";
if ($minutesAgo > 1440) $timeAgo = round($minutesAgo/1440) . " days ago";
echo "<div class='firewall {$statusClass}'>";
echo "<h3>" . htmlspecialchars($fw['hostname'] ?: 'Unknown') . "</h3>";
echo "<div class='info'>Status: <span class='status {$statusClass}'>{$statusText}</span></div>";
echo "<div class='info'>Agent: " . htmlspecialchars($fw['agent_version'] ?: 'Unknown') . "</div>";
echo "<div class='info'>Last Checkin: {$timeAgo}</div>";
echo "<div class='info'>WAN IP: " . htmlspecialchars($fw['wan_ip'] ?: 'Unknown') . "</div>";
echo "<div class='info'>LAN IP: " . htmlspecialchars($fw['lan_ip'] ?: 'Unknown') . "</div>";
echo "<div class='info'>OPNsense: " . htmlspecialchars($fw['version'] ?: 'Unknown') . "</div>";
echo "</div>";
}
// Summary
$total = count($firewalls);
$online = 0;
$offline = 0;
foreach ($firewalls as $fw) {
$minutesAgo = $fw['last_checkin'] ? round((time() - strtotime($fw['last_checkin'])) / 60) : 999;
if ($minutesAgo <= 5) $online++;
elseif ($minutesAgo > 15) $offline++;
}
echo "<div class='firewall'>";
echo "<h3>📊 System Summary</h3>";
echo "<div class='info'>Total Firewalls: {$total}</div>";
echo "<div class='info'>Online: <span class='online'>{$online}</span></div>";
echo "<div class='info'>Offline: <span class='offline'>{$offline}</span></div>";
echo "</div>";
}
} catch (Exception $e) {
error_log("monitor.php error: " . $e->getMessage());
echo "<div class='firewall'><p>An internal error occurred.</p></div>";
}
?>
<div class="firewall">
<h3>🔗 Quick Links</h3>
<div class="info"><a href="/system_status.php" style="color: #4CAF50;">JSON API Status</a></div>
<div class="info"><a href="/" style="color: #4CAF50;">Main Dashboard</a></div>
</div>
</div>
</body>
</html>