feat(MikrotikConfigRoutes, App): add endpoint for retrieving address lists and integrate firewall page in frontend
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 3m58s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 3m58s
This commit is contained in:
@@ -15,7 +15,7 @@ const {
|
||||
buildMikrotikRecursiveRoutes,
|
||||
getParentGateway,
|
||||
} = require('../utils/mikrotikInterfaceGenerator');
|
||||
const { createRosClient, applyBlock } = require('../services/mikrotikApplyService');
|
||||
const { createRosClient, applyBlock, rosPrint } = require('../services/mikrotikApplyService');
|
||||
|
||||
const IPSEC_PASSWORDS_KEY = 'network-config/ipsec-passwords.json';
|
||||
const NETWORK_CONFIG_KEY = 'network-config.json';
|
||||
@@ -1146,6 +1146,50 @@ async function runScript(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/mikrotik/address-lists?serverId=xxx
|
||||
* Возвращает address-list списки ban и ban_counter с выбранного роутера (MikroTik).
|
||||
*/
|
||||
async function getAddressLists(req, res) {
|
||||
try {
|
||||
const serverId = req.query?.serverId;
|
||||
if (!serverId) {
|
||||
return sendError(res, 400, 'serverId is required', 'E_BAD_REQUEST');
|
||||
}
|
||||
|
||||
const servers = await readServersFromS3();
|
||||
const server = servers.find((s) => (s.id || s.dns || s.ip) === serverId);
|
||||
if (!server || (server.type !== 'jumphost' && server.type !== 'home')) {
|
||||
return sendError(res, 400, 'Jumphost or home server not found', 'E_NOT_FOUND');
|
||||
}
|
||||
|
||||
const creds = getMikrotikCredentials(server);
|
||||
if (!creds) {
|
||||
return sendError(res, 400, 'MikroTik credentials not configured for this server', 'E_CREDENTIALS');
|
||||
}
|
||||
|
||||
const client = createRosClient(creds);
|
||||
const path = 'ip/firewall/address-list';
|
||||
|
||||
const [ban, banCounter] = await Promise.all([
|
||||
rosPrint(client, path, { list: 'ban' }),
|
||||
rosPrint(client, path, { list: 'ban_counter' }),
|
||||
]);
|
||||
|
||||
return sendOk(res, {
|
||||
serverId,
|
||||
serverLabel: server.dns || server.ip || serverId,
|
||||
ban: Array.isArray(ban) ? ban : [],
|
||||
ban_counter: Array.isArray(banCounter) ? banCounter : [],
|
||||
});
|
||||
} catch (error) {
|
||||
const msg = error.response?.data?.detail || error.response?.data?.message || error.message || 'Ошибка получения address-list';
|
||||
const status = error.response?.status;
|
||||
console.error('getAddressLists:', error);
|
||||
return sendError(res, status && status >= 400 ? status : 502, msg, 'E_ADDRESS_LISTS');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateMikrotikConfig,
|
||||
generateInterfaces,
|
||||
@@ -1158,4 +1202,5 @@ module.exports = {
|
||||
runPingViaRouter,
|
||||
speedTestViaTunnel,
|
||||
loadNetworkConfig,
|
||||
getAddressLists,
|
||||
};
|
||||
|
||||
@@ -467,6 +467,7 @@ app.post('/api/mikrotik/traceroute', writeLimiter, mikrotikConfigRoutes.tracerou
|
||||
app.post('/api/mikrotik/speed-test', writeLimiter, mikrotikConfigRoutes.speedTestViaTunnel);
|
||||
app.post('/api/mikrotik/apply', mikrotikConfigRoutes.applyMikrotikConfig);
|
||||
app.post('/api/mikrotik/run-script', mikrotikConfigRoutes.runScript);
|
||||
app.get('/api/mikrotik/address-lists', mikrotikConfigRoutes.getAddressLists);
|
||||
|
||||
// === TRAFFIC STATS (MikroTik interfaces by jumphost) ===
|
||||
app.get('/api/traffic/interface-stats', trafficRoutes.getInterfaceStats);
|
||||
|
||||
Reference in New Issue
Block a user