UNPKG

pbx-backup-tool

Version:

A tool for backing up Vodia PBX systems

46 lines (37 loc) 1.09 kB
const fs = require('fs-extra'); const path = require('path'); const os = require('os'); const chalk = require('chalk'); const CONFIG_FILE = path.join(os.homedir(), '.pbx-admin.conf'); function parseConfigFile(content) { const config = {}; const lines = content.split('\n'); for (const line of lines) { const trimmed = line.trim(); if (!trimmed || trimmed.startsWith('#')) continue; const match = trimmed.match(/^([^:]+):\s*(.+)$/) || trimmed.match(/^([^:]+):(.+)$/); if (match) { const key = match[1].trim(); const value = match[2].trim(); config[key] = value; } } return config; } function loadConfig() { try { if (!fs.existsSync(CONFIG_FILE)) { console.error(chalk.red(`Configuration file not found at ${CONFIG_FILE}`)); process.exit(1); } const content = fs.readFileSync(CONFIG_FILE, 'utf8'); return parseConfigFile(content); } catch (error) { console.error(chalk.red('Error loading configuration:', error.message)); process.exit(1); } } module.exports = { loadConfig, CONFIG_FILE };