mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
fix create queue with root user (#409)
* fix create queue with root user * fix * fix queues for root user
This commit is contained in:
@ -9,7 +9,9 @@
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use Exception;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use phpseclib3\Crypt\Common\PrivateKey;
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
@ -106,7 +108,7 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
|
||||
}
|
||||
|
||||
try {
|
||||
if (! $this->connection) {
|
||||
if (! $this->connection instanceof SSH2) {
|
||||
$this->connect();
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
@ -158,7 +160,7 @@ public function upload(string $local, string $remote): void
|
||||
{
|
||||
$this->log = null;
|
||||
|
||||
if (! $this->connection) {
|
||||
if (! $this->connection instanceof SFTP) {
|
||||
$this->connect(true);
|
||||
}
|
||||
|
||||
@ -172,13 +174,43 @@ public function download(string $local, string $remote): void
|
||||
{
|
||||
$this->log = null;
|
||||
|
||||
if (! $this->connection) {
|
||||
if (! $this->connection instanceof SFTP) {
|
||||
$this->connect(true);
|
||||
}
|
||||
|
||||
$this->connection->get($remote, $local, SFTP::SOURCE_LOCAL_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function write(string $remotePath, string $content, bool $sudo = false): void
|
||||
{
|
||||
$tmpName = Str::random(10).strtotime('now');
|
||||
|
||||
try {
|
||||
/** @var FilesystemAdapter $storageDisk */
|
||||
$storageDisk = Storage::disk('local');
|
||||
|
||||
$storageDisk->put($tmpName, $content);
|
||||
|
||||
if ($sudo) {
|
||||
$this->upload($storageDisk->path($tmpName), sprintf('/home/%s/%s', $this->server->ssh_user, $tmpName));
|
||||
$this->exec(sprintf('sudo mv /home/%s/%s %s', $this->server->ssh_user, $tmpName, $remotePath));
|
||||
} else {
|
||||
$this->upload($storageDisk->path($tmpName), $remotePath);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
throw new SSHCommandError(
|
||||
message: $e->getMessage()
|
||||
);
|
||||
} finally {
|
||||
if (Storage::disk('local')->exists($tmpName)) {
|
||||
Storage::disk('local')->delete($tmpName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
Reference in New Issue
Block a user