feat: новая функция
This commit is contained in:
@@ -787,21 +787,25 @@ router.get('/encryption-key/status', requireAdmin, async (req, res) => {
|
||||
|
||||
const exists = fs.existsSync(keyPath);
|
||||
|
||||
let key = null;
|
||||
if (exists) {
|
||||
try {
|
||||
key = fs.readFileSync(keyPath, 'utf8').trim();
|
||||
} catch (error) {
|
||||
logger.error('Ошибка чтения ключа:', error);
|
||||
}
|
||||
// Возвращаем только метаданные без содержимого ключа
|
||||
let checksum = null;
|
||||
if (exists) {
|
||||
try {
|
||||
const data = fs.readFileSync(keyPath);
|
||||
// лёгкая хэш-сумма для проверки целостности без раскрытия ключа
|
||||
const crypto = require('crypto');
|
||||
checksum = crypto.createHash('sha256').update(data).digest('hex');
|
||||
} catch (error) {
|
||||
logger.error('Ошибка чтения ключа для метаданных:', error);
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
exists,
|
||||
path: keyPath,
|
||||
key: key
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
exists,
|
||||
path: keyPath,
|
||||
checksum
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Ошибка проверки статуса ключа шифрования:', error);
|
||||
res.status(500).json({ success: false, error: error.message });
|
||||
|
||||
@@ -1,48 +1,10 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
const { promisify } = require('util');
|
||||
const dns = require('dns');
|
||||
|
||||
const resolve4 = promisify(dns.resolve4);
|
||||
|
||||
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' });
|
||||
}
|
||||
});
|
||||
// Удалено: эндпоинты выдачи приватного/публичного SSH-ключа
|
||||
|
||||
// GET /api/dns-check/:domain - Check DNS and get IP address
|
||||
router.get('/dns-check/:domain', async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user