feat(MikrotikConfig): enhance MikroTik configuration generation with support for 'text' and 'json' formats; add new API endpoints for interface and recursive route generation
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m37s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m37s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Утилиты для генерации конфигурации MikroTik
|
||||
* Устраняют дублирование кода генерации конфигурации
|
||||
* Поддерживает форматы: 'text' (как раньше) и 'json' (структурированные данные для API)
|
||||
*/
|
||||
|
||||
const { buildNestedGatewayBlocks } = require('./helpers');
|
||||
@@ -8,10 +9,14 @@ const { buildNestedGatewayBlocks } = require('./helpers');
|
||||
/**
|
||||
* Генерация конфигурации MikroTik из массива фильтров
|
||||
* @param {Array} filters - Массив фильтров с полями {community, gateway}
|
||||
* @returns {string} Сгенерированная конфигурация
|
||||
* @param {object} options - { format: 'text'|'json' }
|
||||
* @returns {string|object} Сгенерированная конфигурация (строка или объект)
|
||||
*/
|
||||
function generateMikrotikConfig(filters) {
|
||||
function generateMikrotikConfig(filters, options = {}) {
|
||||
const { format = 'text' } = options;
|
||||
|
||||
if (!Array.isArray(filters) || filters.length === 0) {
|
||||
if (format === 'json') return { gatewayGroups: {}, config: null };
|
||||
return '// No filters to generate configuration';
|
||||
}
|
||||
|
||||
@@ -24,6 +29,14 @@ function generateMikrotikConfig(filters) {
|
||||
gatewayGroups[filter.gateway].push(filter.community);
|
||||
});
|
||||
|
||||
if (format === 'json') {
|
||||
return {
|
||||
gatewayGroups,
|
||||
filterName: 'bgp-in-tmp',
|
||||
generatedAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
let config = '// Frouting filter configuration for MikroTik 7.14+\n';
|
||||
config += '// Generated automatically\n';
|
||||
config += `// Date: ${new Date().toISOString()}\n\n`;
|
||||
|
||||
Reference in New Issue
Block a user