refactor: Improve configuration generation formatting in server.js for better readability and structure
Publish Fast Tabler Docker image / build-and-push-fast (push) Has been cancelled
Publish Fast Tabler Docker image / build-and-push-fast (push) Has been cancelled
This commit is contained in:
+15
-6
@@ -425,6 +425,7 @@ app.get('/api/filters/generate-config', async (req, res) => {
|
|||||||
let config = '// Frouting filter configuration for MikroTik 7.14+\n';
|
let config = '// Frouting filter configuration for MikroTik 7.14+\n';
|
||||||
config += '// Generated automatically\n';
|
config += '// Generated automatically\n';
|
||||||
config += `// Date: ${new Date().toISOString()}\n\n`;
|
config += `// Date: ${new Date().toISOString()}\n\n`;
|
||||||
|
config += '/routing filter bgp-in-tmp {\n';
|
||||||
|
|
||||||
// Если есть только один gateway, создаем простую конфигурацию
|
// Если есть только один gateway, создаем простую конфигурацию
|
||||||
if (Object.keys(gatewayGroups).length === 1) {
|
if (Object.keys(gatewayGroups).length === 1) {
|
||||||
@@ -433,7 +434,7 @@ app.get('/api/filters/generate-config', async (req, res) => {
|
|||||||
communities.forEach((community, index) => {
|
communities.forEach((community, index) => {
|
||||||
config += ` (bgp-communities includes ${community})`;
|
config += ` (bgp-communities includes ${community})`;
|
||||||
if (index < communities.length - 1) {
|
if (index < communities.length - 1) {
|
||||||
config += ` \nor `;
|
config += ` or \n`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`;
|
config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`;
|
||||||
@@ -450,7 +451,7 @@ app.get('/api/filters/generate-config', async (req, res) => {
|
|||||||
communities.forEach((community, index) => {
|
communities.forEach((community, index) => {
|
||||||
config += ` (bgp-communities includes ${community})`;
|
config += ` (bgp-communities includes ${community})`;
|
||||||
if (index < communities.length - 1) {
|
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 }`;
|
||||||
@@ -463,6 +464,8 @@ app.get('/api/filters/generate-config', async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config += '}\n';
|
||||||
|
|
||||||
res.json({ config });
|
res.json({ config });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'NoSuchKey') {
|
if (error.code === 'NoSuchKey') {
|
||||||
@@ -512,6 +515,7 @@ app.post('/api/filters/export-config', async (req, res) => {
|
|||||||
let config = '// Frouting filter configuration for MikroTik 7.14+\n';
|
let config = '// Frouting filter configuration for MikroTik 7.14+\n';
|
||||||
config += '// Generated automatically\n';
|
config += '// Generated automatically\n';
|
||||||
config += `// Date: ${new Date().toISOString()}\n\n`;
|
config += `// Date: ${new Date().toISOString()}\n\n`;
|
||||||
|
config += '/routing filter bgp-in-tmp {\n';
|
||||||
|
|
||||||
// Если есть только один gateway, создаем простую конфигурацию
|
// Если есть только один gateway, создаем простую конфигурацию
|
||||||
if (Object.keys(gatewayGroups).length === 1) {
|
if (Object.keys(gatewayGroups).length === 1) {
|
||||||
@@ -520,7 +524,7 @@ app.post('/api/filters/export-config', async (req, res) => {
|
|||||||
communities.forEach((community, index) => {
|
communities.forEach((community, index) => {
|
||||||
config += ` (bgp-communities includes ${community})`;
|
config += ` (bgp-communities includes ${community})`;
|
||||||
if (index < communities.length - 1) {
|
if (index < communities.length - 1) {
|
||||||
config += ` \nor `;
|
config += ` or \n`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`;
|
config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`;
|
||||||
@@ -537,7 +541,7 @@ app.post('/api/filters/export-config', async (req, res) => {
|
|||||||
communities.forEach((community, index) => {
|
communities.forEach((community, index) => {
|
||||||
config += ` (bgp-communities includes ${community})`;
|
config += ` (bgp-communities includes ${community})`;
|
||||||
if (index < communities.length - 1) {
|
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 }`;
|
||||||
@@ -550,6 +554,8 @@ app.post('/api/filters/export-config', async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config += '}\n';
|
||||||
|
|
||||||
// Save configuration to S3
|
// Save configuration to S3
|
||||||
const exportParams = {
|
const exportParams = {
|
||||||
Bucket: BUCKET_NAME,
|
Bucket: BUCKET_NAME,
|
||||||
@@ -788,6 +794,7 @@ app.post('/api/server-filters/generate-config', async (req, res) => {
|
|||||||
let config = '// Frouting filter configuration for MikroTik 7.14+\n';
|
let config = '// Frouting filter configuration for MikroTik 7.14+\n';
|
||||||
config += '// Generated automatically\n';
|
config += '// Generated automatically\n';
|
||||||
config += `// Date: ${new Date().toISOString()}\n\n`;
|
config += `// Date: ${new Date().toISOString()}\n\n`;
|
||||||
|
config += '/routing filter bgp-in-tmp {\n';
|
||||||
|
|
||||||
// Если есть только один gateway, создаем простую конфигурацию
|
// Если есть только один gateway, создаем простую конфигурацию
|
||||||
if (Object.keys(gatewayGroups).length === 1) {
|
if (Object.keys(gatewayGroups).length === 1) {
|
||||||
@@ -796,7 +803,7 @@ app.post('/api/server-filters/generate-config', async (req, res) => {
|
|||||||
communities.forEach((community, index) => {
|
communities.forEach((community, index) => {
|
||||||
config += ` (bgp-communities includes ${community})`;
|
config += ` (bgp-communities includes ${community})`;
|
||||||
if (index < communities.length - 1) {
|
if (index < communities.length - 1) {
|
||||||
config += ` \nor `;
|
config += ` or \n`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`;
|
config += `\n )\n {\n set gw ${gateway}; accept;\n }\n else\n {\n reject;\n }\n`;
|
||||||
@@ -813,7 +820,7 @@ app.post('/api/server-filters/generate-config', async (req, res) => {
|
|||||||
communities.forEach((community, index) => {
|
communities.forEach((community, index) => {
|
||||||
config += ` (bgp-communities includes ${community})`;
|
config += ` (bgp-communities includes ${community})`;
|
||||||
if (index < communities.length - 1) {
|
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 }`;
|
||||||
@@ -826,6 +833,8 @@ app.post('/api/server-filters/generate-config', async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config += '}\n';
|
||||||
|
|
||||||
console.log('Generated config:', config);
|
console.log('Generated config:', config);
|
||||||
console.log('Sending response:', { config });
|
console.log('Sending response:', { config });
|
||||||
res.json({ config });
|
res.json({ config });
|
||||||
|
|||||||
Reference in New Issue
Block a user