diff --git a/backend/server.js b/backend/server.js index fadce56..1d046f0 100644 --- a/backend/server.js +++ b/backend/server.js @@ -425,43 +425,46 @@ app.get('/api/filters/generate-config', async (req, res) => { let config = '// Frouting filter configuration for MikroTik 7.14+\n'; config += '// Generated automatically\n'; config += `// Date: ${new Date().toISOString()}\n\n`; + config += '/routing filter bgp-in-tmp {\n'; // Если есть только один gateway, создаем простую конфигурацию if (Object.keys(gatewayGroups).length === 1) { const [gateway, communities] = Object.entries(gatewayGroups)[0]; - config += `if (\n`; + config += ` if (\n`; communities.forEach((community, index) => { - config += `(bgp-communities includes ${community})`; + config += ` (bgp-communities includes ${community})`; if (index < communities.length - 1) { - config += ` \nor `; + config += ` or \n`; } }); - config += `\n)\n{\n set gw ${gateway}; accept;\n}\nelse\n{\n reject;\n}\n`; + config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`; } else { // Если несколько gateway, создаем каскадную структуру const gatewayEntries = Object.entries(gatewayGroups); gatewayEntries.forEach(([gateway, communities], gatewayIndex) => { if (gatewayIndex === 0) { - config += `if (\n`; + config += ` if (\n`; } else { - config += `else if (\n`; + config += ` else if (\n`; } communities.forEach((community, index) => { - config += `(bgp-communities includes ${community})`; + config += ` (bgp-communities includes ${community})`; if (index < communities.length - 1) { - config += ` \nor `; + config += ` or \n`; } }); - config += `\n)\n{\n set gw ${gateway}; accept;\n}`; + config += `\n )\n {\n set gw ${gateway}; accept;\n }`; if (gatewayIndex === gatewayEntries.length - 1) { - config += `\nelse\n{\n reject;\n}\n`; + config += `\n else\n {\n reject;\n }\n`; } else { config += `\n`; } }); } + + config += '}\n'; res.json({ config }); } catch (error) { @@ -512,43 +515,46 @@ app.post('/api/filters/export-config', async (req, res) => { let config = '// Frouting filter configuration for MikroTik 7.14+\n'; config += '// Generated automatically\n'; config += `// Date: ${new Date().toISOString()}\n\n`; + config += '/routing filter bgp-in-tmp {\n'; // Если есть только один gateway, создаем простую конфигурацию if (Object.keys(gatewayGroups).length === 1) { const [gateway, communities] = Object.entries(gatewayGroups)[0]; - config += `if (\n`; + config += ` if (\n`; communities.forEach((community, index) => { - config += `(bgp-communities includes ${community})`; + config += ` (bgp-communities includes ${community})`; if (index < communities.length - 1) { - config += ` \nor `; + config += ` or \n`; } }); - config += `\n)\n{\n set gw ${gateway}; accept;\n}\nelse\n{\n reject;\n}\n`; + config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`; } else { // Если несколько gateway, создаем каскадную структуру const gatewayEntries = Object.entries(gatewayGroups); gatewayEntries.forEach(([gateway, communities], gatewayIndex) => { if (gatewayIndex === 0) { - config += `if (\n`; + config += ` if (\n`; } else { - config += `else if (\n`; + config += ` else if (\n`; } communities.forEach((community, index) => { - config += `(bgp-communities includes ${community})`; + config += ` (bgp-communities includes ${community})`; if (index < communities.length - 1) { - config += ` \nor `; + config += ` or \n`; } }); - config += `\n)\n{\n set gw ${gateway}; accept;\n}`; + config += `\n )\n {\n set gw ${gateway}; accept;\n }`; if (gatewayIndex === gatewayEntries.length - 1) { - config += `\nelse\n{\n reject;\n}\n`; + config += `\n else\n {\n reject;\n }\n`; } else { config += `\n`; } }); } + + config += '}\n'; // Save configuration to S3 const exportParams = { @@ -788,43 +794,46 @@ app.post('/api/server-filters/generate-config', async (req, res) => { let config = '// Frouting filter configuration for MikroTik 7.14+\n'; config += '// Generated automatically\n'; config += `// Date: ${new Date().toISOString()}\n\n`; + config += '/routing filter bgp-in-tmp {\n'; // Если есть только один gateway, создаем простую конфигурацию if (Object.keys(gatewayGroups).length === 1) { const [gateway, communities] = Object.entries(gatewayGroups)[0]; - config += `if (\n`; + config += ` if (\n`; communities.forEach((community, index) => { - config += `(bgp-communities includes ${community})`; + config += ` (bgp-communities includes ${community})`; if (index < communities.length - 1) { - config += ` \nor `; + config += ` or \n`; } }); - config += `\n)\n{\n set gw ${gateway}; accept;\n}\nelse\n{\n reject;\n}\n`; + config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`; } else { // Если несколько gateway, создаем каскадную структуру const gatewayEntries = Object.entries(gatewayGroups); gatewayEntries.forEach(([gateway, communities], gatewayIndex) => { if (gatewayIndex === 0) { - config += `if (\n`; + config += ` if (\n`; } else { - config += `else if (\n`; + config += ` else if (\n`; } communities.forEach((community, index) => { - config += `(bgp-communities includes ${community})`; + config += ` (bgp-communities includes ${community})`; if (index < communities.length - 1) { - config += ` \nor `; + config += ` or \n`; } }); - config += `\n)\n{\n set gw ${gateway}; accept;\n}`; + config += `\n )\n {\n set gw ${gateway}; accept;\n }`; if (gatewayIndex === gatewayEntries.length - 1) { - config += `\nelse\n{\n reject;\n}\n`; + config += `\n else\n {\n reject;\n }\n`; } else { config += `\n`; } }); } + + config += '}\n'; console.log('Generated config:', config); console.log('Sending response:', { config });