ваше сообщение коммита
This commit is contained in:
@@ -30,6 +30,8 @@ const monitoringRoutes = require('./routes/monitoring');
|
||||
const pagesRoutes = require('./routes/pages'); // Добавляем импорт роутера страниц
|
||||
const uploadsRoutes = require('./routes/uploads');
|
||||
const ensRoutes = require('./routes/ens');
|
||||
const sshRoutes = require('./routes/ssh'); // SSH роуты
|
||||
const encryptionRoutes = require('./routes/encryption'); // Encryption роуты
|
||||
// Factory routes removed - no longer needed
|
||||
|
||||
// Проверка и создание директорий для хранения данных контрактов
|
||||
@@ -211,6 +213,8 @@ app.use('/api/pages', pagesRoutes); // Подключаем роутер стр
|
||||
app.use('/api/system', systemRoutes); // Добавляем маршрут системного мониторинга
|
||||
app.use('/api/uploads', uploadsRoutes); // Загрузка файлов (логотипы)
|
||||
app.use('/api/ens', ensRoutes); // ENS utilities
|
||||
app.use('/api', sshRoutes); // SSH роуты
|
||||
app.use('/api', encryptionRoutes); // Encryption роуты
|
||||
// app.use('/api/factory', factoryRoutes); // Factory routes removed - no longer needed
|
||||
app.use('/api/compile-contracts', compileRoutes); // Компиляция контрактов
|
||||
|
||||
|
||||
67
backend/routes/encryption.js
Normal file
67
backend/routes/encryption.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
|
||||
// Путь к папке с ключами шифрования
|
||||
const KEYS_DIR = path.join(__dirname, '../../ssl/keys');
|
||||
const ENCRYPTION_KEY_PATH = path.join(KEYS_DIR, 'full_db_encryption.key');
|
||||
|
||||
// Создаем папку keys если её нет
|
||||
if (!fs.existsSync(KEYS_DIR)) {
|
||||
fs.mkdirSync(KEYS_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
// Helper to read encryption key
|
||||
const readEncryptionKey = (keyPath) => {
|
||||
try {
|
||||
return fs.readFileSync(keyPath, 'utf8');
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// Helper to write encryption key
|
||||
const writeEncryptionKey = (keyPath, key) => {
|
||||
try {
|
||||
fs.writeFileSync(keyPath, key, { mode: 0o600 });
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// GET /api/encryption-key - Get existing encryption key
|
||||
router.get('/encryption-key', (req, res) => {
|
||||
const encryptionKey = readEncryptionKey(ENCRYPTION_KEY_PATH);
|
||||
|
||||
if (encryptionKey) {
|
||||
res.json({ success: true, encryptionKey: encryptionKey });
|
||||
} else {
|
||||
res.status(404).json({ success: false, message: 'Encryption key not found' });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/encryption-key/generate - Generate a new encryption key
|
||||
router.post('/encryption-key/generate', (req, res) => {
|
||||
try {
|
||||
// Генерируем новый ключ шифрования (256 бит)
|
||||
const encryptionKey = crypto.randomBytes(32).toString('hex');
|
||||
|
||||
// Сохраняем ключ в файл
|
||||
if (writeEncryptionKey(ENCRYPTION_KEY_PATH, encryptionKey)) {
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Encryption key generated successfully',
|
||||
encryptionKey: encryptionKey
|
||||
});
|
||||
} else {
|
||||
res.status(500).json({ success: false, message: 'Failed to save encryption key' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ success: false, message: `Failed to generate encryption key: ${error.message}` });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
42
backend/routes/ssh.js
Normal file
42
backend/routes/ssh.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const SSH_DIR = path.join(process.env.HOME || process.env.USERPROFILE, '.ssh');
|
||||
const DEFAULT_KEY_PATH = path.join(SSH_DIR, 'id_rsa');
|
||||
const DEFAULT_PUB_KEY_PATH = path.join(SSH_DIR, 'id_rsa.pub');
|
||||
|
||||
// Helper to read SSH key
|
||||
const readSshKey = (keyPath) => {
|
||||
try {
|
||||
return fs.readFileSync(keyPath, 'utf8');
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// GET /api/ssh-key - Get existing SSH private key
|
||||
router.get('/ssh-key', (req, res) => {
|
||||
const privateKey = readSshKey(DEFAULT_KEY_PATH);
|
||||
const publicKey = readSshKey(DEFAULT_PUB_KEY_PATH);
|
||||
|
||||
if (privateKey) {
|
||||
res.json({ success: true, sshKey: privateKey, publicKey: publicKey, keyType: 'rsa' });
|
||||
} else {
|
||||
res.status(404).json({ success: false, message: 'SSH private key not found' });
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/ssh-key/public - Get existing SSH public key
|
||||
router.get('/ssh-key/public', (req, res) => {
|
||||
const publicKey = readSshKey(DEFAULT_PUB_KEY_PATH);
|
||||
|
||||
if (publicKey) {
|
||||
res.json({ success: true, publicKey: publicKey, keyType: 'rsa' });
|
||||
} else {
|
||||
res.status(404).json({ success: false, message: 'SSH public key not found' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user