some progress
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class DnsRecord extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'site_id',
|
||||
'domain',
|
||||
'record_type',
|
||||
'expected_value',
|
||||
'last_checked_at',
|
||||
'is_valid',
|
||||
'actual_value',
|
||||
'error_message',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'last_checked_at' => 'datetime',
|
||||
'is_valid' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
'actual_value' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* Available DNS record types.
|
||||
*/
|
||||
public static function getRecordTypes(): array
|
||||
{
|
||||
return [
|
||||
'A' => 'A (IPv4 Address)',
|
||||
'AAAA' => 'AAAA (IPv6 Address)',
|
||||
'CNAME' => 'CNAME (Canonical Name)',
|
||||
'MX' => 'MX (Mail Exchange)',
|
||||
'TXT' => 'TXT (Text Record)',
|
||||
'NS' => 'NS (Name Server)',
|
||||
'SOA' => 'SOA (Start of Authority)',
|
||||
'PTR' => 'PTR (Pointer)',
|
||||
'SRV' => 'SRV (Service)',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the site that owns the DNS record.
|
||||
*/
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter active DNS records.
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter valid records.
|
||||
*/
|
||||
public function scopeValid($query)
|
||||
{
|
||||
return $query->where('is_valid', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter invalid records.
|
||||
*/
|
||||
public function scopeInvalid($query)
|
||||
{
|
||||
return $query->where('is_valid', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status badge color.
|
||||
*/
|
||||
public function getStatusColorAttribute(): string
|
||||
{
|
||||
if ($this->is_valid === null) {
|
||||
return 'secondary';
|
||||
}
|
||||
|
||||
return $this->is_valid ? 'success' : 'danger';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status text.
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
if ($this->is_valid === null) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
return $this->is_valid ? 'Valid' : 'Invalid';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get display name for the record.
|
||||
*/
|
||||
public function getDisplayNameAttribute(): string
|
||||
{
|
||||
return "{$this->record_type} - {$this->domain}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatted actual value for display.
|
||||
*/
|
||||
public function getFormattedActualValueAttribute(): ?string
|
||||
{
|
||||
if (!$this->actual_value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_array($this->actual_value)) {
|
||||
if (count($this->actual_value) === 1) {
|
||||
return $this->actual_value[0];
|
||||
}
|
||||
return implode(', ', $this->actual_value);
|
||||
}
|
||||
|
||||
return $this->actual_value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class HealthCheck extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'site_id',
|
||||
'endpoint',
|
||||
'expected_json_keys',
|
||||
'last_checked_at',
|
||||
'is_healthy',
|
||||
'response_data',
|
||||
'response_time_ms',
|
||||
'performance_threshold',
|
||||
'status_code',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'expected_json_keys' => 'array',
|
||||
'response_data' => 'array',
|
||||
'last_checked_at' => 'datetime',
|
||||
'is_healthy' => 'boolean',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the site that owns the health check.
|
||||
*/
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter active health checks.
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter healthy checks.
|
||||
*/
|
||||
public function scopeHealthy($query)
|
||||
{
|
||||
return $query->where('is_healthy', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter unhealthy checks.
|
||||
*/
|
||||
public function scopeUnhealthy($query)
|
||||
{
|
||||
return $query->where('is_healthy', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full URL for the health check endpoint.
|
||||
*/
|
||||
public function getFullUrlAttribute(): string
|
||||
{
|
||||
$siteUrl = rtrim($this->site->url, '/');
|
||||
$endpoint = ltrim($this->endpoint, '/');
|
||||
|
||||
return $siteUrl . '/' . $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status badge color.
|
||||
*/
|
||||
public function getStatusColorAttribute(): string
|
||||
{
|
||||
if ($this->is_healthy === null) {
|
||||
return 'secondary';
|
||||
}
|
||||
|
||||
return $this->is_healthy ? 'success' : 'danger';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status text.
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
if ($this->is_healthy === null) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
return $this->is_healthy ? 'Healthy' : 'Unhealthy';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get display name for the endpoint.
|
||||
*/
|
||||
public function getDisplayNameAttribute(): string
|
||||
{
|
||||
return $this->endpoint ?: 'Health Check';
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if response contains all expected keys.
|
||||
*/
|
||||
public function validateResponseKeys(array $responseData): bool
|
||||
{
|
||||
if (empty($this->expected_json_keys)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->expected_json_keys as $key) {
|
||||
if (!$this->hasNestedKey($responseData, $key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if nested key exists in array using dot notation.
|
||||
*/
|
||||
protected function hasNestedKey(array $array, string $key): bool
|
||||
{
|
||||
if (array_key_exists($key, $array)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (explode('.', $key) as $segment) {
|
||||
if (!is_array($array) || !array_key_exists($segment, $array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$array = $array[$segment];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -38,4 +38,19 @@ class Site extends Model
|
||||
{
|
||||
return $this->hasMany(BrokenLink::class);
|
||||
}
|
||||
|
||||
public function tcpPorts(): HasMany
|
||||
{
|
||||
return $this->hasMany(TcpPort::class);
|
||||
}
|
||||
|
||||
public function healthChecks(): HasMany
|
||||
{
|
||||
return $this->hasMany(HealthCheck::class);
|
||||
}
|
||||
|
||||
public function dnsRecords(): HasMany
|
||||
{
|
||||
return $this->hasMany(DnsRecord::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class TcpPort extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'site_id',
|
||||
'port',
|
||||
'name',
|
||||
'is_active',
|
||||
'last_checked_at',
|
||||
'is_open',
|
||||
'response_time_ms',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'is_open' => 'boolean',
|
||||
'last_checked_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the site that owns the TCP port.
|
||||
*/
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter active ports.
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter open ports.
|
||||
*/
|
||||
public function scopeOpen($query)
|
||||
{
|
||||
return $query->where('is_open', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter closed ports.
|
||||
*/
|
||||
public function scopeClosed($query)
|
||||
{
|
||||
return $query->where('is_open', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get common port names.
|
||||
*/
|
||||
public static function getCommonPorts(): array
|
||||
{
|
||||
return [
|
||||
21 => 'FTP',
|
||||
22 => 'SSH',
|
||||
23 => 'Telnet',
|
||||
25 => 'SMTP',
|
||||
53 => 'DNS',
|
||||
80 => 'HTTP',
|
||||
110 => 'POP3',
|
||||
143 => 'IMAP',
|
||||
443 => 'HTTPS',
|
||||
465 => 'SMTPS',
|
||||
587 => 'SMTP (Submission)',
|
||||
993 => 'IMAPS',
|
||||
995 => 'POP3S',
|
||||
3306 => 'MySQL',
|
||||
3389 => 'RDP',
|
||||
5432 => 'PostgreSQL',
|
||||
6379 => 'Redis',
|
||||
8080 => 'HTTP Alternate',
|
||||
8443 => 'HTTPS Alternate',
|
||||
27017 => 'MongoDB',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get display name for the port.
|
||||
*/
|
||||
public function getDisplayNameAttribute(): string
|
||||
{
|
||||
if ($this->name) {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
$commonPorts = self::getCommonPorts();
|
||||
return $commonPorts[$this->port] ?? "Port {$this->port}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status badge color.
|
||||
*/
|
||||
public function getStatusColorAttribute(): string
|
||||
{
|
||||
if ($this->is_open === null) {
|
||||
return 'secondary';
|
||||
}
|
||||
|
||||
return $this->is_open ? 'success' : 'danger';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status text.
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
if ($this->is_open === null) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
return $this->is_open ? 'Open' : 'Closed';
|
||||
}
|
||||
}
|
||||
@@ -11,15 +11,42 @@ class UptimeCheck extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'site_id',
|
||||
'check_type',
|
||||
'status_code',
|
||||
'response_time_ms',
|
||||
'is_online',
|
||||
'checked_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'checked_at' => 'datetime',
|
||||
'is_online' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope to filter by check type.
|
||||
*/
|
||||
public function scopeOfType($query, string $type)
|
||||
{
|
||||
return $query->where('check_type', $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter HTTP checks.
|
||||
*/
|
||||
public function scopeHttpChecks($query)
|
||||
{
|
||||
return $query->where('check_type', 'http');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to filter ping checks.
|
||||
*/
|
||||
public function scopePingChecks($query)
|
||||
{
|
||||
return $query->where('check_type', 'ping');
|
||||
}
|
||||
|
||||
public function site(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
|
||||
+2
-1
@@ -7,11 +7,12 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
use HasFactory, Notifiable, HasApiTokens;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
||||
Reference in New Issue
Block a user