From 04330ef8b0e34a965b2dc29a55da57badb2c8a20 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Mon, 29 Apr 2024 14:15:17 +0300 Subject: [PATCH] Add remote backup servers --- .../Resources/RemoteBackupServerResource.php | 6 +-- web/app/Models/RemoteBackupServer.php | 54 +++++++++++++++++++ web/resources/phyre-svg/backup-remote.svg | 3 ++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 web/resources/phyre-svg/backup-remote.svg diff --git a/web/app/Filament/Resources/RemoteBackupServerResource.php b/web/app/Filament/Resources/RemoteBackupServerResource.php index 65945e8..d5593c4 100644 --- a/web/app/Filament/Resources/RemoteBackupServerResource.php +++ b/web/app/Filament/Resources/RemoteBackupServerResource.php @@ -17,7 +17,7 @@ class RemoteBackupServerResource extends Resource { protected static ?string $model = RemoteBackupServer::class; - protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; + protected static ?string $navigationIcon = 'phyre-backup-remote'; protected static ?string $navigationGroup = 'Server Clustering'; @@ -70,9 +70,9 @@ class RemoteBackupServerResource extends Resource return $table ->columns([ Tables\Columns\TextColumn::make('name'), - Tables\Columns\TextColumn::make('type'), + Tables\Columns\TextColumn::make('type')->badge(), Tables\Columns\TextColumn::make('hostname'), - Tables\Columns\TextColumn::make('status'), + Tables\Columns\TextColumn::make('status')->badge(), ]) ->filters([ // diff --git a/web/app/Models/RemoteBackupServer.php b/web/app/Models/RemoteBackupServer.php index 0c7dc3a..3a825ee 100644 --- a/web/app/Models/RemoteBackupServer.php +++ b/web/app/Models/RemoteBackupServer.php @@ -2,6 +2,7 @@ namespace App\Models; +use Doctrine\DBAL\DriverManager; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -20,4 +21,57 @@ class RemoteBackupServer extends Model 'ssh_private_key', 'ssh_private_key_password', ]; + + public static function boot() + { + parent::boot(); + + static::created(function ($model) { + $model->healthCheck(); + }); + + static::updated(function ($model) { + $model->healthCheck(); + }); + } + + public function healthCheck() + { + if ($this->type == 'ftp') { + + try { + + $username = trim($this->username); + $password = trim($this->password); + $hostname = trim($this->hostname); + $port = trim($this->port); + $path = trim($this->path); + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, 'ftp://'.$hostname.':'.$port.'/'.$path.'/'); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password); + $curlResponse = curl_exec($curl); + curl_close($curl); + + if ($curlResponse) { + $this->status = 'online'; + $this->save(); + return; + } else { + $this->status = 'offline'; + $this->save(); + return; + } + + } catch (\Exception $e) { + $this->status = 'offline'; + $this->save(); + return; + } + } + + + } } diff --git a/web/resources/phyre-svg/backup-remote.svg b/web/resources/phyre-svg/backup-remote.svg new file mode 100644 index 0000000..6e959c9 --- /dev/null +++ b/web/resources/phyre-svg/backup-remote.svg @@ -0,0 +1,3 @@ + + +