fix(backup): add sshpass dependency for remote SSH backups (v1.3.4)
This commit is contained in:
1 parent
e8c25309e3
commit
c638f14c06
5 files changed
+34
-9
No files matched your search
@@ -659,12 +659,24 @@ class BackupManager
|
||||
// MÉTHODES PRIVÉES / UTILITAIRES
|
||||
// =========================================================================
|
||||
|
||||
private static function isSshpassInstalled(): bool
|
||||
{
|
||||
return file_exists('/usr/bin/sshpass') || !empty(trim((string)shell_exec('which sshpass 2>/dev/null')));
|
||||
}
|
||||
|
||||
private static function runSshCommand(string $host, int $port, string $user, string $authType, string $password, string $cmd): array
|
||||
{
|
||||
$sshOptions = "-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 -p " . (int)$port;
|
||||
$target = escapeshellarg("{$user}@{$host}");
|
||||
|
||||
if ($authType === 'password') {
|
||||
if (!self::isSshpassInstalled()) {
|
||||
return [
|
||||
'exit_code' => 1,
|
||||
'output' => '',
|
||||
'error' => "Le paquet 'sshpass' n'est pas installé sur le système pour l'authentification SSH par mot de passe. Installez-le avec : apt install -y sshpass",
|
||||
];
|
||||
}
|
||||
$fullCmd = "sshpass -p " . escapeshellarg($password) . " ssh {$sshOptions} {$target} " . escapeshellarg($cmd);
|
||||
} else {
|
||||
$fullCmd = "ssh {$sshOptions} {$target} " . escapeshellarg($cmd);
|
||||
@@ -713,6 +725,12 @@ class BackupManager
|
||||
$src = escapeshellarg($localFile);
|
||||
|
||||
if ($authType === 'password') {
|
||||
if (!self::isSshpassInstalled()) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => "Le paquet 'sshpass' n'est pas installé sur le système pour l'authentification SSH par mot de passe. Installez-le avec : apt install -y sshpass",
|
||||
];
|
||||
}
|
||||
$scpCmd = "sshpass -p " . escapeshellarg($password) . " scp {$scpOptions} {$src} {$dest}";
|
||||
} else {
|
||||
$scpCmd = "scp {$scpOptions} {$src} {$dest}";
|
||||
@@ -742,6 +760,12 @@ class BackupManager
|
||||
$dest = escapeshellarg($localDest);
|
||||
|
||||
if ($authType === 'password') {
|
||||
if (!self::isSshpassInstalled()) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => "Le paquet 'sshpass' n'est pas installé sur le système pour l'authentification SSH par mot de passe. Installez-le avec : apt install -y sshpass",
|
||||
];
|
||||
}
|
||||
$scpCmd = "sshpass -p " . escapeshellarg($password) . " scp {$scpOptions} {$src} {$dest}";
|
||||
} else {
|
||||
$scpCmd = "scp {$scpOptions} {$src} {$dest}";
|
||||
|
||||
Reference in new issue
Block a user