48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
|
||
|
|
#[Fillable(['investigation_id', 'created_by', 'type', 'value', 'notes'])]
|
||
|
|
class Target extends Model
|
||
|
|
{
|
||
|
|
public const TYPES = ['person', 'domain', 'email', 'username', 'ip', 'org'];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Format validation for the `value` column, per target type.
|
||
|
|
* Kept in sync with runners that assume a given shape (e.g.
|
||
|
|
* SherlockRunner's username charset check).
|
||
|
|
*
|
||
|
|
* @return array<int, string>
|
||
|
|
*/
|
||
|
|
public static function valueRulesFor(string $type): array
|
||
|
|
{
|
||
|
|
return match ($type) {
|
||
|
|
'email' => ['required', 'string', 'email', 'max:255'],
|
||
|
|
'domain' => ['required', 'string', 'max:255', 'regex:/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/'],
|
||
|
|
'ip' => ['required', 'ip'],
|
||
|
|
'username' => ['required', 'string', 'max:255', 'regex:/^[a-zA-Z0-9._-]+$/'],
|
||
|
|
default => ['required', 'string', 'max:255'],
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
public function investigation(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Investigation::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function creator(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(User::class, 'created_by');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function findings(): HasMany
|
||
|
|
{
|
||
|
|
return $this->hasMany(Finding::class);
|
||
|
|
}
|
||
|
|
}
|