feat(mikrotikConfigRoutes, FilterManager): add run-script endpoint and integrate BGP update functionality in FilterManager
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m7s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m7s
This commit is contained in:
@@ -272,10 +272,46 @@ async function applyMikrotikConfig(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/mikrotik/run-script
|
||||
* Body: { serverId, script?: string } — по умолчанию script=update_bgp_filter
|
||||
*/
|
||||
async function runScript(req, res) {
|
||||
try {
|
||||
const { serverId, script = 'update_bgp_filter' } = req.body || {};
|
||||
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') {
|
||||
return sendError(res, 400, 'Jumphost 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);
|
||||
// /rest/execute — выполнение произвольной команды (как в CLI)
|
||||
await client.command('execute', { script: `/system script run ${script}` });
|
||||
|
||||
return sendOk(res, { ok: true, message: `Скрипт ${script} запущен` });
|
||||
} catch (error) {
|
||||
const msg = error.response?.data?.message || error.message || 'Ошибка запуска скрипта';
|
||||
const status = error.response?.status;
|
||||
console.error('runScript:', error);
|
||||
return sendError(res, status && status >= 400 ? status : 502, msg, 'E_SCRIPT');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateMikrotikConfig,
|
||||
generateInterfaces,
|
||||
generateRecursiveRoutes,
|
||||
testMikrotikConnection,
|
||||
applyMikrotikConfig,
|
||||
runScript,
|
||||
};
|
||||
|
||||
@@ -452,6 +452,7 @@ app.get('/api/mikrotik/generate-recursive-routes', mikrotikConfigRoutes.generate
|
||||
app.post('/api/mikrotik/test-connection', mikrotikConfigRoutes.testMikrotikConnection);
|
||||
app.get('/api/mikrotik/ping', (req, res) => res.json({ ok: true, ts: Date.now() }));
|
||||
app.post('/api/mikrotik/apply', mikrotikConfigRoutes.applyMikrotikConfig);
|
||||
app.post('/api/mikrotik/run-script', mikrotikConfigRoutes.runScript);
|
||||
|
||||
// === MIKROTIK VALIDATION ===
|
||||
app.post('/api/mikrotik/validate', async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user