ваше сообщение коммита

This commit is contained in:
2025-10-03 18:48:11 +03:00
parent ad7b8e9716
commit 67cf473455
42 changed files with 5515 additions and 1180 deletions

View File

@@ -0,0 +1,61 @@
const { exec } = require('child_process');
const log = require('./logger');
/**
* Выполнение команд локально (на хосте)
*/
const execLocalCommand = async (command) => {
return new Promise((resolve) => {
exec(command, (error, stdout, stderr) => {
resolve({
code: error ? error.code : 0,
stdout: stdout || '',
stderr: stderr || ''
});
});
});
};
/**
* Создание SSH ключей локально на хосте
*/
const createSshKeys = async (email) => {
log.info('Создание SSH ключей на хосте...');
return new Promise((resolve) => {
// Сначала исправляем права доступа к SSH конфигу
exec('chmod 600 /root/.ssh/config 2>/dev/null || true', (configError) => {
if (configError) {
log.warn('Не удалось исправить права доступа к SSH конфигу: ' + configError.message);
}
// Создаем SSH ключи
exec(`ssh-keygen -t rsa -b 4096 -C "${email}" -f ~/.ssh/id_rsa -N ""`, (error, stdout, stderr) => {
if (error) {
log.error('Ошибка создания SSH ключей: ' + error.message);
} else {
log.success('SSH ключи успешно созданы на хосте');
// Устанавливаем правильные права доступа к созданным ключам
exec('chmod 600 /root/.ssh/id_rsa && chmod 644 /root/.ssh/id_rsa.pub', (permError) => {
if (permError) {
log.warn('Не удалось установить права доступа к SSH ключам: ' + permError.message);
} else {
log.success('Права доступа к SSH ключам установлены');
}
resolve();
});
}
if (error) {
resolve();
}
});
});
});
};
module.exports = {
execLocalCommand,
createSshKeys
};