feat: Netzwerk-Modul v0.5.0 – Import, Geräte-Tracking, Ereignislog

This commit is contained in:
2026-06-29 15:18:49 +02:00
parent eb57be730b
commit 402537805d
21 changed files with 1269 additions and 7 deletions
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class NetworkDevice extends Model
{
protected $fillable = [
'mac_address', 'current_ip', 'hostname', 'mac_vendor',
'status', 'netbios_name', 'ttl', 'ports', 'notes',
'label', 'first_seen_at', 'last_seen_at',
];
protected $casts = [
'first_seen_at' => 'datetime',
'last_seen_at' => 'datetime',
];
public function hosts(): HasMany
{
return $this->hasMany(NetworkHost::class, 'device_id');
}
public function events(): HasMany
{
return $this->hasMany(NetworkDeviceEvent::class, 'device_id')->latest();
}
public function getDisplayNameAttribute(): string
{
return $this->label
?? $this->hostname
?? $this->current_ip
?? $this->mac_address;
}
public function getStatusColorAttribute(): string
{
return match($this->status) {
'online' => 'green',
'offline' => 'red',
default => 'gray',
};
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class NetworkDeviceEvent extends Model
{
protected $fillable = [
'device_id', 'scan_id', 'event_type', 'old_value',
'new_value', 'description', 'documented',
'documented_by', 'documented_at',
];
protected $casts = [
'documented' => 'boolean',
'documented_at' => 'datetime',
];
public function device(): BelongsTo
{
return $this->belongsTo(NetworkDevice::class, 'device_id');
}
public function documentedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'documented_by');
}
public function getEventLabelAttribute(): string
{
return match($this->event_type) {
'new_device' => 'Neues Gerät',
'ip_changed' => 'IP-Adresse geändert',
'came_online' => 'Gerät online',
'went_offline' => 'Gerät offline',
'manual_note' => 'Manuelle Notiz',
'label_changed' => 'Bezeichnung geändert',
default => $this->event_type,
};
}
public function getEventColorAttribute(): string
{
return match($this->event_type) {
'new_device' => 'blue',
'ip_changed' => 'yellow',
'came_online' => 'green',
'went_offline' => 'red',
'manual_note' => 'purple',
'label_changed' => 'gray',
default => 'gray',
};
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class NetworkHost extends Model
{
protected $fillable = [
'scan_id', 'device_id', 'ip_address', 'mac_address',
'hostname', 'mac_vendor', 'status', 'ping_ms',
'netbios_info', 'ttl', 'ports', 'http_sender', 'web_detection',
];
public function scan(): BelongsTo
{
return $this->belongsTo(NetworkScan::class, 'scan_id');
}
public function device(): BelongsTo
{
return $this->belongsTo(NetworkDevice::class, 'device_id');
}
}
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class NetworkScan extends Model
{
protected $fillable = [
'subnet', 'source', 'scanner', 'total_hosts',
'online_hosts', 'new_devices', 'changed_devices',
'notes', 'created_by',
];
protected $casts = [
'created_at' => 'datetime',
];
public function hosts(): HasMany
{
return $this->hasMany(NetworkHost::class, 'scan_id');
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
}