/** * @ControllerManaged * @NoCSRFRequired * * Upload SSH private key file */ protected function uploadSshKey() { $file = $this->request->getUploadedFile('easybackup_sshKeyFile'); if (!$file || !file_exists($file['tmp_name'])) { throw new EasyBackupException('Uploaded file not found'); } $key = file_get_contents($file['tmp_name']); if ($key === false || strlen($key) == 0) { throw new EasyBackupException('Uploaded file is empty'); } if (!$this->backupService->validatePrivateSshKey($key)) { throw new EasyBackupException('Key is not well-formed'); } $filename = $this->configService->getPrivateKeyFilename(); if (!file_put_contents($filename, $key)) { throw new \Exception('Could not store private key in ' . $filename); } chmod($filename, 0600); $publicKey = $this->backupService->getPublicSshKeyFromPrivateKey(); $this->configService->setPublicKey($publicKey); return array('preconditionsHtml' => $this->renderPreconditionsHtml(), 'publicKeyHtml' => $this->renderPublicKeyHtml()); }