feat(source2): lock dark mode, sans-serif typography, and all recent updates
This commit is contained in:
1 parent
dd4c8f6876
commit
9f24b56e97
259 files changed
+15596
-8966
No files matched your search
@@ -20,29 +20,42 @@ router.get('/summary', async (req, res) => {
|
||||
|
||||
if (base.agent_uuid) {
|
||||
// ── Agent-Level Summary (View As Agent mode) ─────────────────────────────
|
||||
// The proxy saves per-agent summaries with agent_uuid = <uuid>.
|
||||
// Use the latest one for the scoped agent instead of site aggregates.
|
||||
// bandwidth_down/up: SUM semua dokumen dalam timeRange (total traffic selama periode)
|
||||
// active_flows, download_speed, upload_speed: dari dokumen TERBARU saja (nilai real-time)
|
||||
const agentSummaries = await Summary.find(base).lean();
|
||||
bandwidthDown = agentSummaries.reduce((s, x) => s + (x.bandwidth_down || 0), 0);
|
||||
bandwidthUp = agentSummaries.reduce((s, x) => s + (x.bandwidth_up || 0), 0);
|
||||
|
||||
const latestAgentSummary = await Summary
|
||||
.findOne(baseWithoutTime)
|
||||
.sort({ timestamp: -1 })
|
||||
.lean();
|
||||
|
||||
if (latestAgentSummary) {
|
||||
bandwidthDown = latestAgentSummary.bandwidth_down || 0;
|
||||
bandwidthUp = latestAgentSummary.bandwidth_up || 0;
|
||||
activeFlowsCount = latestAgentSummary.active_flows || 0;
|
||||
downloadSpeed = latestAgentSummary.download_speed || 0;
|
||||
uploadSpeed = latestAgentSummary.upload_speed || 0;
|
||||
activeFlowsCount = latestAgentSummary.active_flows || 0;
|
||||
downloadSpeed = latestAgentSummary.download_speed || 0;
|
||||
uploadSpeed = latestAgentSummary.upload_speed || 0;
|
||||
latestTime = latestAgentSummary.timestamp;
|
||||
}
|
||||
} else {
|
||||
// ── Site-Level Summary (default) ─────────────────────────────────────────
|
||||
// Use site-level snapshots (agent_uuid=null) to avoid double-counting
|
||||
// across agents when no specific agent scope is active.
|
||||
const siteIds = baseWithoutTime.site_uuid
|
||||
? [baseWithoutTime.site_uuid]
|
||||
: await Summary.distinct('site_uuid', { agent_uuid: null });
|
||||
|
||||
// bandwidth_down/up: SUM semua dokumen dalam timeRange yang dipilih user.
|
||||
// Setiap dokumen mewakili interval traffic tersendiri (misal 5 menit), sehingga
|
||||
// menjumlahkannya memberikan total traffic dalam periode yang dipilih (misal 7 GB untuk 24 jam).
|
||||
// active_flows, speed: hanya dari dokumen TERBARU (nilai snapshot/real-time, bukan kumulatif).
|
||||
const siteSummaries = await Summary.find({
|
||||
site_uuid: { $in: siteIds },
|
||||
agent_uuid: null,
|
||||
...(timeFilter ? { timestamp: timeFilter } : {})
|
||||
}).lean();
|
||||
|
||||
bandwidthDown = siteSummaries.reduce((s, x) => s + (x.bandwidth_down || 0), 0);
|
||||
bandwidthUp = siteSummaries.reduce((s, x) => s + (x.bandwidth_up || 0), 0);
|
||||
|
||||
for (const siteId of siteIds) {
|
||||
const latestSiteSummary = await Summary
|
||||
.findOne({ agent_uuid: null, site_uuid: siteId })
|
||||
@@ -50,43 +63,78 @@ router.get('/summary', async (req, res) => {
|
||||
.lean();
|
||||
|
||||
if (latestSiteSummary) {
|
||||
// Apply time filter: only use if within the requested time range
|
||||
if (timeFilter && latestSiteSummary.timestamp < timeFilter) continue;
|
||||
|
||||
bandwidthDown += latestSiteSummary.bandwidth_down || 0;
|
||||
bandwidthUp += latestSiteSummary.bandwidth_up || 0;
|
||||
activeFlowsCount += latestSiteSummary.active_flows || 0;
|
||||
downloadSpeed += latestSiteSummary.download_speed || 0;
|
||||
uploadSpeed += latestSiteSummary.upload_speed || 0;
|
||||
activeFlowsCount += latestSiteSummary.active_flows || 0;
|
||||
downloadSpeed += latestSiteSummary.download_speed || 0;
|
||||
uploadSpeed += latestSiteSummary.upload_speed || 0;
|
||||
if (!latestTime || latestSiteSummary.timestamp > latestTime) {
|
||||
latestTime = latestSiteSummary.timestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: if no site-level summaries exist yet, aggregate from per-agent summaries
|
||||
// Fallback: if no site-level summaries, aggregate from per-agent summaries
|
||||
if (bandwidthDown === 0 && bandwidthUp === 0) {
|
||||
const latestAgentDoc = await Summary.findOne(baseWithoutTime).sort({ timestamp: -1 });
|
||||
const allAgentSummaries = await Summary.find(base).lean();
|
||||
bandwidthDown = allAgentSummaries.reduce((s, r) => s + (r.bandwidth_down || 0), 0);
|
||||
bandwidthUp = allAgentSummaries.reduce((s, r) => s + (r.bandwidth_up || 0), 0);
|
||||
|
||||
const latestAgentDoc = await Summary.findOne(baseWithoutTime).sort({ timestamp: -1 }).lean();
|
||||
if (latestAgentDoc) {
|
||||
latestTime = latestAgentDoc.timestamp;
|
||||
const agentSummaries = await Summary.find({ ...baseWithoutTime, timestamp: latestAgentDoc.timestamp }).lean();
|
||||
bandwidthDown = agentSummaries.reduce((s, r) => s + (r.bandwidth_down ?? 0), 0);
|
||||
bandwidthUp = agentSummaries.reduce((s, r) => s + (r.bandwidth_up ?? 0), 0);
|
||||
activeFlowsCount = agentSummaries.reduce((s, r) => s + (r.active_flows ?? 0), 0);
|
||||
downloadSpeed = agentSummaries.reduce((s, r) => s + (r.download_speed ?? 0), 0);
|
||||
uploadSpeed = agentSummaries.reduce((s, r) => s + (r.upload_speed ?? 0), 0);
|
||||
uploadSpeed = agentSummaries.reduce((s, r) => s + (r.upload_speed ?? 0), 0);
|
||||
activeFlowsCount = agentSummaries.reduce((s, r) => s + (r.active_flows ?? 0), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Device count, Threats, Events — always use the scoped base filter
|
||||
// Fallback: if bandwidth is still 0, aggregate from AppCategoryStat or Flow
|
||||
if (bandwidthDown === 0 && bandwidthUp === 0) {
|
||||
const { AppCategoryStat } = require('../../models/Schemas');
|
||||
const cats = await AppCategoryStat.find(base).lean();
|
||||
if (cats.length > 0) {
|
||||
bandwidthDown = cats.reduce((s, x) => s + (x.download || 0), 0);
|
||||
bandwidthUp = cats.reduce((s, x) => s + (x.upload || 0), 0);
|
||||
} else {
|
||||
const flows = await Flow.find(base).select('download upload').lean();
|
||||
bandwidthDown = flows.reduce((s, x) => s + (x.download || 0), 0);
|
||||
bandwidthUp = flows.reduce((s, x) => s + (x.upload || 0), 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Device count, Threats, Events, Flows — always use the scoped base filter
|
||||
// (already contains agent_uuid when in AGENT_VIEWER mode)
|
||||
const [uniqueDevices, realThreatsCount, realEventsCount] = await Promise.all([
|
||||
let [uniqueDevices, realThreatsCount, realEventsCount, realFlowsCount] = await Promise.all([
|
||||
DeviceStat.distinct('ip_address', base).then(r => r.length),
|
||||
Threat.countDocuments(base),
|
||||
Event.countDocuments(base),
|
||||
Flow.countDocuments(base),
|
||||
]);
|
||||
|
||||
if (uniqueDevices === 0) {
|
||||
uniqueDevices = await Flow.distinct('src_ip', base).then(r => r.length);
|
||||
}
|
||||
|
||||
// Fall back to critical/cybersecurity events if no real threats exist (aligned with threats route)
|
||||
if (realThreatsCount === 0) {
|
||||
const baseEventFilter = {};
|
||||
if (base.agent_uuid) baseEventFilter.agent_uuid = base.agent_uuid;
|
||||
if (base.site_uuid) baseEventFilter.site_uuid = base.site_uuid;
|
||||
if (timeFilter) {
|
||||
baseEventFilter.$and = [
|
||||
{ $or: [{ event_at: timeFilter }, { timestamp: timeFilter }] }
|
||||
];
|
||||
}
|
||||
realThreatsCount = await Event.countDocuments({
|
||||
...baseEventFilter,
|
||||
$or: [
|
||||
{ severity: { $in: ['Critical', 'High'] } },
|
||||
{ category_label: 'Cybersecurity' }
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
ok: true,
|
||||
data: {
|
||||
@@ -96,7 +144,7 @@ router.get('/summary', async (req, res) => {
|
||||
last_fetch: latestTime || new Date(),
|
||||
bandwidth_down: bandwidthDown,
|
||||
bandwidth_up: bandwidthUp,
|
||||
active_flows: activeFlowsCount,
|
||||
active_flows: realFlowsCount,
|
||||
download_speed: downloadSpeed,
|
||||
upload_speed: uploadSpeed,
|
||||
flow_speed: 0,
|
||||
|
||||
Reference in new issue
Block a user