Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/AuditLog.php
10266 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Ramsey\Uuid\Uuid;
6
use Illuminate\Http\Request;
7
use Illuminate\Container\Container;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
10
/**
11
* @deprecated — this class will be dropped in a future version, use the activity log
12
*/
13
class AuditLog extends Model
14
{
15
public const UPDATED_AT = null;
16
17
public static array $validationRules = [
18
'uuid' => 'required|uuid',
19
'action' => 'required|string|max:191',
20
'subaction' => 'nullable|string|max:191',
21
'device' => 'array',
22
'device.ip_address' => 'ip',
23
'device.user_agent' => 'string',
24
'metadata' => 'array',
25
];
26
27
protected $table = 'audit_logs';
28
29
protected bool $immutableDates = true;
30
31
protected $casts = [
32
'is_system' => 'bool',
33
'device' => 'array',
34
'metadata' => 'array',
35
];
36
37
protected $guarded = [
38
'id',
39
'created_at',
40
];
41
42
/**
43
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Pterodactyl\Models\User, $this>
44
*/
45
public function user(): BelongsTo
46
{
47
return $this->belongsTo(User::class);
48
}
49
50
/**
51
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Pterodactyl\Models\Server, $this>
52
*/
53
public function server(): BelongsTo
54
{
55
return $this->belongsTo(Server::class);
56
}
57
58
/**
59
* Creates a new AuditLog model and returns it, attaching device information and the
60
* currently authenticated user if available. This model is not saved at this point, so
61
* you can always make modifications to it as needed before saving.
62
*
63
* @deprecated
64
*/
65
public static function instance(string $action, array $metadata, bool $isSystem = false): self
66
{
67
$request = Container::getInstance()->make('request');
68
if ($isSystem || !$request instanceof Request) { // @phpstan-ignore instanceof.alwaysTrue
69
$request = null;
70
}
71
72
return (new self())->fill([
73
'uuid' => Uuid::uuid4()->toString(),
74
'is_system' => $isSystem,
75
'user_id' => ($request && $request->user()) ? $request->user()->id : null,
76
'server_id' => null,
77
'action' => $action,
78
'device' => $request ? [
79
'ip_address' => $request->getClientIp() ?? '127.0.0.1',
80
'user_agent' => $request->userAgent() ?? '',
81
] : [],
82
'metadata' => $metadata,
83
]);
84
}
85
}
86
87