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
@@ -1,5 +1,6 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const mongoose = require('mongoose');
|
||||
const { DeviceStat, CustomDeviceLabel, Flow } = require('../../models/Schemas');
|
||||
const { getTimeFilter, getBaseFilter, getCustomLabelsMap } = require('./helpers');
|
||||
const { generateMacFromIp, resolveDeviceTypeFromIp, resolveOSFromIp, resolveVendorFromIp, generateAutoLabel } = require('../../deviceResolver');
|
||||
@@ -58,47 +59,7 @@ router.get('/devices', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/dashboard/devices/update-label
|
||||
router.post('/devices/update-label', async (req, res) => {
|
||||
try {
|
||||
const isAuthorized = req.user?.role === 'SUPER_ADMIN' ||
|
||||
req.user?.role === 'TENANT_ADMIN' ||
|
||||
req.user?._originalRole === 'SUPER_ADMIN' ||
|
||||
req.user?._originalRole === 'TENANT_ADMIN';
|
||||
|
||||
if (!isAuthorized) {
|
||||
return res.status(403).json({ ok: false, error: 'Only administrators can update device labels.' });
|
||||
}
|
||||
|
||||
const { mac_address, device_label } = req.body;
|
||||
if (!mac_address) return res.status(400).json({ ok: false, error: 'mac_address required' });
|
||||
if (device_label === undefined) return res.status(400).json({ ok: false, error: 'device_label required' });
|
||||
|
||||
const isGlobalUser = req.user?.role === 'SUPER_ADMIN' ||
|
||||
((!req.user?.site_uuid || req.user?.site_uuid === 'default') && ['SOC_ANALYST', 'ENGINEER'].includes(req.user?.role)) ||
|
||||
req.user?._originalRole === 'SUPER_ADMIN';
|
||||
|
||||
if (!isGlobalUser && req.user?.site_uuid) {
|
||||
const deviceExists = await DeviceStat.findOne({
|
||||
mac_address,
|
||||
site_uuid: req.user.site_uuid
|
||||
});
|
||||
if (!deviceExists) {
|
||||
return res.status(403).json({ ok: false, error: 'Unauthorized: This device does not belong to your tenant.' });
|
||||
}
|
||||
}
|
||||
|
||||
await CustomDeviceLabel.findOneAndUpdate(
|
||||
{ mac_address },
|
||||
{ device_label },
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
|
||||
res.json({ ok: true, message: 'Device label updated successfully' });
|
||||
} catch (err) {
|
||||
res.status(500).json({ ok: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/dashboard/mac-bandwidth
|
||||
router.get('/mac-bandwidth', async (req, res) => {
|
||||
@@ -148,7 +109,44 @@ router.get('/mac-bandwidth', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/dashboard/security-devices
|
||||
// GET /api/dashboard/devices/mac-details?mac=xx:xx:xx:xx:xx:xx
|
||||
// Returns IP history + bandwidth stats per MAC address (used by DeviceMacDetailsModal)
|
||||
router.get('/devices/mac-details', async (req, res) => {
|
||||
try {
|
||||
const mac = (req.query.mac || '').toLowerCase().trim();
|
||||
if (!mac) return res.status(400).json({ ok: false, error: 'mac parameter required' });
|
||||
|
||||
const timeFilter = getTimeFilter(req);
|
||||
const matchBase = getBaseFilter(req, timeFilter);
|
||||
|
||||
// Aggregate IP history for this MAC: group by IP, sum bandwidth, track first/last seen
|
||||
const raw = await DeviceStat.aggregate([
|
||||
{ $match: { ...matchBase, mac_address: { $regex: new RegExp(`^${mac.replace(/:/g, ':')}$`, 'i') } } },
|
||||
{ $group: {
|
||||
_id: '$ip_address',
|
||||
download: { $sum: '$download' },
|
||||
upload: { $sum: '$upload' },
|
||||
flows: { $sum: '$flows' },
|
||||
first_seen: { $min: '$timestamp' },
|
||||
last_seen: { $max: '$timestamp' },
|
||||
}},
|
||||
{ $project: {
|
||||
_id: 0,
|
||||
ip_address: '$_id',
|
||||
download: 1, upload: 1, flows: 1,
|
||||
first_seen: 1, last_seen: 1
|
||||
}},
|
||||
{ $sort: { last_seen: -1 } },
|
||||
{ $limit: 50 }
|
||||
]);
|
||||
|
||||
res.json({ ok: true, ips: raw });
|
||||
} catch (err) {
|
||||
res.status(500).json({ ok: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.get('/security-devices', async (req, res) => {
|
||||
try {
|
||||
const timeFilter = getTimeFilter(req);
|
||||
@@ -239,4 +237,7 @@ router.get('/security-devices', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user