first commit: Complete phishing test management panel with Node.js backend and React frontend
This commit is contained in:
127
backend/src/controllers/settings.controller.js
Normal file
127
backend/src/controllers/settings.controller.js
Normal file
@@ -0,0 +1,127 @@
|
||||
const { Settings } = require('../models');
|
||||
const mailService = require('../services/mail.service');
|
||||
const telegramService = require('../services/telegram.service');
|
||||
|
||||
// Get all settings
|
||||
exports.getAllSettings = async (req, res, next) => {
|
||||
try {
|
||||
const settings = await Settings.findAll();
|
||||
|
||||
// Hide sensitive values
|
||||
const sanitized = settings.map(s => ({
|
||||
...s.toJSON(),
|
||||
value: s.is_encrypted ? '********' : s.value,
|
||||
}));
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: sanitized,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Update Gmail settings
|
||||
exports.updateGmailSettings = async (req, res, next) => {
|
||||
try {
|
||||
const { gmail_user, gmail_password, gmail_from_name } = req.body;
|
||||
|
||||
if (gmail_user) {
|
||||
await Settings.upsert({
|
||||
key: 'gmail_user',
|
||||
value: gmail_user,
|
||||
is_encrypted: false,
|
||||
description: 'Gmail email address',
|
||||
});
|
||||
}
|
||||
|
||||
if (gmail_password) {
|
||||
await Settings.upsert({
|
||||
key: 'gmail_password',
|
||||
value: gmail_password,
|
||||
is_encrypted: true,
|
||||
description: 'Gmail App Password',
|
||||
});
|
||||
}
|
||||
|
||||
if (gmail_from_name) {
|
||||
await Settings.upsert({
|
||||
key: 'gmail_from_name',
|
||||
value: gmail_from_name,
|
||||
is_encrypted: false,
|
||||
description: 'Sender name for emails',
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Gmail settings updated successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Update Telegram settings
|
||||
exports.updateTelegramSettings = async (req, res, next) => {
|
||||
try {
|
||||
const { telegram_bot_token, telegram_chat_id } = req.body;
|
||||
|
||||
if (telegram_bot_token) {
|
||||
await Settings.upsert({
|
||||
key: 'telegram_bot_token',
|
||||
value: telegram_bot_token,
|
||||
is_encrypted: true,
|
||||
description: 'Telegram Bot Token',
|
||||
});
|
||||
}
|
||||
|
||||
if (telegram_chat_id) {
|
||||
await Settings.upsert({
|
||||
key: 'telegram_chat_id',
|
||||
value: telegram_chat_id,
|
||||
is_encrypted: false,
|
||||
description: 'Telegram Chat ID',
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Telegram settings updated successfully',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Test Gmail connection
|
||||
exports.testGmail = async (req, res, next) => {
|
||||
try {
|
||||
const result = await mailService.testConnection();
|
||||
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Test Telegram connection
|
||||
exports.testTelegram = async (req, res, next) => {
|
||||
try {
|
||||
const result = await telegramService.sendTestMessage();
|
||||
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
Reference in New Issue
Block a user