- Add settings form with all config fields (Bot, Commission, Wallets, WireGuard) - POST handler writes .env file and restarts container via process.exit(0) - Secrets (ENCRYPTION_KEY, ADMIN_SECRET, GITEA_TOKEN, WG_PRIVATE_KEY, WG_PRESHARED_KEY) are never sent to browser - masked placeholders used instead - PRESERVE_KEYS enforced: secret keys cannot be overwritten via form - Values sanitized: newlines stripped before writing to .env - start.sh loads .env file before node to override Docker env_file cache - Extract shared escapeHtml utility to escape.js (used by 6 view files) - Update paymentWallets view to link to Settings page instead of .env - Add .env volume mount for settings panel read/write - Fix registerRoutes() not being called in index.js (bot menu buttons)
78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
import 'dotenv/config';
|
|
import { runMigrations, cleanUpInvalidForeignKeys } from './migrations/runner.js';
|
|
import { registerRoutes } from './router/routes.js';
|
|
import bot from './context/bot.js';
|
|
import ErrorHandler from './utils/errorHandler.js';
|
|
import logger from './utils/logger.js';
|
|
import userHandler from './handlers/userHandlers/userHandler.js';
|
|
import adminHandler from './handlers/adminHandlers/adminHandler.js';
|
|
import callbackRouter from './router/callbackRouter.js';
|
|
import messageRouter from './router/messageRouter.js';
|
|
|
|
import { initStates } from './services/stateService.js';
|
|
|
|
await runMigrations();
|
|
await cleanUpInvalidForeignKeys();
|
|
await initStates();
|
|
registerRoutes();
|
|
|
|
const logDebug = (action, functionName) => {
|
|
logger.debug({ action, functionName }, 'Button Press');
|
|
};
|
|
|
|
bot.onText(/\/start/, async (msg) => {
|
|
logDebug('/start', 'handleStart');
|
|
const canUse = await userHandler.canUseBot(msg);
|
|
if (!canUse) return;
|
|
try {
|
|
await userHandler.handleStart(msg);
|
|
} catch (error) {
|
|
await ErrorHandler.handleError(bot, msg.chat.id, error, 'start command');
|
|
}
|
|
});
|
|
|
|
bot.onText(/\/admin/, async (msg) => {
|
|
logDebug('/admin', 'handleAdminCommand');
|
|
try {
|
|
await adminHandler.handleAdminCommand(msg);
|
|
} catch (error) {
|
|
await ErrorHandler.handleError(bot, msg.chat.id, error, 'admin command');
|
|
}
|
|
});
|
|
|
|
bot.on('message', async (msg) => {
|
|
if (msg.text?.toLowerCase() === '/start') return;
|
|
const canUse = await userHandler.canUseBot(msg);
|
|
if (!canUse) return;
|
|
try {
|
|
await messageRouter.dispatch(msg);
|
|
} catch (error) {
|
|
await ErrorHandler.handleError(bot, msg.chat.id, error, 'message handler');
|
|
}
|
|
});
|
|
|
|
bot.on('callback_query', async (callbackQuery) => {
|
|
const canUse = await userHandler.canUseBot(callbackQuery);
|
|
if (!canUse) {
|
|
await bot.answerCallbackQuery(callbackQuery.id);
|
|
return;
|
|
}
|
|
try {
|
|
await callbackRouter.dispatch(callbackQuery);
|
|
await bot.answerCallbackQuery(callbackQuery.id);
|
|
} catch (error) {
|
|
await ErrorHandler.handleError(bot, callbackQuery.message.chat.id, error, 'callback query');
|
|
}
|
|
});
|
|
|
|
bot.on('polling_error', ErrorHandler.handlePollingError);
|
|
|
|
process.on('unhandledRejection', (error) => {
|
|
logger.error({ err: error }, 'Unhandled promise rejection');
|
|
});
|
|
|
|
logger.info('Bot is running...');
|
|
|
|
import { startAdminPanel } from './admin/server.js';
|
|
startAdminPanel();
|