This commit is contained in:
Saeed Vaziry
2024-03-24 09:56:34 +01:00
committed by GitHub
parent 884f18db63
commit 4d051330d6
1055 changed files with 14493 additions and 20278 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace App\SSH\Storage;
use App\Models\Server;
use App\Models\StorageProvider;
abstract class AbstractStorage implements Storage
{
public function __construct(protected Server $server, protected StorageProvider $storageProvider)
{
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace App\SSH\Storage;
use App\Exceptions\SSHCommandError;
use App\SSH\HasScripts;
use Illuminate\Support\Facades\Log;
class Dropbox extends AbstractStorage
{
use HasScripts;
public function upload(string $src, string $dest): array
{
$upload = $this->server->ssh()->exec(
$this->getScript('dropbox/upload.sh', [
'src' => $src,
'dest' => $dest,
'token' => $this->storageProvider->credentials['token'],
]),
'upload-to-dropbox'
);
$data = json_decode($upload, true);
if (isset($data['error'])) {
Log::error('Failed to upload to Dropbox', $data);
throw new SSHCommandError('Failed to upload to Dropbox');
}
return [
'size' => $data['size'] ?? null,
];
}
public function download(string $src, string $dest): void
{
$this->server->ssh()->exec(
$this->getScript('dropbox/download.sh', [
'src' => $src,
'dest' => $dest,
'token' => $this->storageProvider->credentials['token'],
]),
'download-from-dropbox'
);
}
}

48
app/SSH/Storage/FTP.php Normal file
View File

@ -0,0 +1,48 @@
<?php
namespace App\SSH\Storage;
use App\SSH\HasScripts;
class FTP extends AbstractStorage
{
use HasScripts;
public function upload(string $src, string $dest): array
{
$this->server->ssh()->exec(
$this->getScript('ftp/upload.sh', [
'src' => $src,
'dest' => $this->storageProvider->credentials['path'].'/'.$dest,
'host' => $this->storageProvider->credentials['host'],
'port' => $this->storageProvider->credentials['port'],
'username' => $this->storageProvider->credentials['username'],
'password' => $this->storageProvider->credentials['password'],
'ssl' => $this->storageProvider->credentials['ssl'],
'passive' => $this->storageProvider->credentials['passive'],
]),
'upload-to-ftp'
);
return [
'size' => null,
];
}
public function download(string $src, string $dest): void
{
$this->server->ssh()->exec(
$this->getScript('ftp/download.sh', [
'src' => $this->storageProvider->credentials['path'].'/'.$src,
'dest' => $dest,
'host' => $this->storageProvider->credentials['host'],
'port' => $this->storageProvider->credentials['port'],
'username' => $this->storageProvider->credentials['username'],
'password' => $this->storageProvider->credentials['password'],
'ssl' => $this->storageProvider->credentials['ssl'],
'passive' => $this->storageProvider->credentials['passive'],
]),
'download-from-ftp'
);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\SSH\Storage;
interface Storage
{
public function upload(string $src, string $dest): array;
public function download(string $src, string $dest): void;
}

View File

@ -0,0 +1,4 @@
curl -o __dest__ --location --request POST 'https://content.dropboxapi.com/2/files/download' \
--header 'Accept: application/json' \
--header 'Dropbox-API-Arg: {"path":"__src__"}' \
--header 'Authorization: Bearer __token__'

View File

@ -0,0 +1,6 @@
curl -sb --location --request POST 'https://content.dropboxapi.com/2/files/upload' \
--header 'Accept: application/json' \
--header 'Dropbox-API-Arg: {"path":"__dest__"}' \
--header 'Content-Type: text/plain; charset=dropbox-cors-hack' \
--header 'Authorization: Bearer __token__' \
--data-binary '@__src__'

View File

@ -0,0 +1 @@
curl __passive__ -u "__username__:__password__" ftp__ssl__://__host__:__port__/__src__ -o "__dest__"

View File

@ -0,0 +1 @@
curl __passive__ -T "__src__" -u "__username__:__password__" ftp__ssl__://__host__:__port__/__dest__