Feature/add remote server logs (#159)

This commit is contained in:
Borja Jiménez
2024-04-14 14:34:47 +02:00
committed by GitHub
parent 75aed62d75
commit 4517ca7d2a
25 changed files with 385 additions and 26 deletions

View File

@ -27,11 +27,13 @@ class ServerLog extends AbstractModel
'type',
'name',
'disk',
'is_remote',
];
protected $casts = [
'server_id' => 'integer',
'site_id' => 'integer',
'is_remote' => 'boolean',
];
public static function boot(): void
@ -64,6 +66,17 @@ public function site(): BelongsTo
return $this->belongsTo(Site::class);
}
public static function getRemote($query, bool $active = true, ?Site $site = null)
{
$query->where('is_remote', $active);
if ($site) {
$query->where('name', 'like', $site->path.'%');
}
return $query;
}
public function write($buf): void
{
if (Str::contains($buf, 'VITO_SSH_ERROR')) {
@ -78,6 +91,10 @@ public function write($buf): void
public function getContent(): ?string
{
if ($this->is_remote) {
return $this->server->os()->readFile($this->name, 150);
}
if (Storage::disk($this->disk)->exists($this->name)) {
return Storage::disk($this->disk)->get($this->name);
}