mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-25 09:00:27 +00:00
Add remote backup servers
This commit is contained in:
parent
e2faa62f93
commit
04330ef8b0
3 changed files with 60 additions and 3 deletions
|
@ -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([
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
3
web/resources/phyre-svg/backup-remote.svg
Normal file
3
web/resources/phyre-svg/backup-remote.svg
Normal file
|
@ -0,0 +1,3 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M12 4.5a4.5 4.5 0 0 0-4.495 4.285a.75.75 0 0 1-.75.715H6.5a3 3 0 1 0 0 6h3.576a6.6 6.6 0 0 0-.057 1.5H6.5a4.5 4.5 0 0 1-.42-8.98a6.001 6.001 0 0 1 11.84 0a4.5 4.5 0 0 1 4.053 4.973a6.5 6.5 0 0 0-1.8-1.857A3 3 0 0 0 17.5 9.5h-.256a.75.75 0 0 1-.749-.715A4.5 4.5 0 0 0 12 4.5m10 12a5.5 5.5 0 1 1-11 0a5.5 5.5 0 0 1 11 0m-6 3a.5.5 0 0 0 1 0v-4.793l1.646 1.647a.5.5 0 0 0 .708-.708l-2.5-2.5a.5.5 0 0 0-.708 0l-2.5 2.5a.5.5 0 0 0 .708.708L16 14.707z" />
|
||||
</svg>
|
After Width: | Height: | Size: 575 B |
Loading…
Reference in a new issue