Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/AuditLog.php
7432 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
public function user(): BelongsTo
43
{
44
return $this->belongsTo(User::class);
45
}
46
47
public function server(): BelongsTo
48
{
49
return $this->belongsTo(Server::class);
50
}
51
52
/**
53
* Creates a new AuditLog model and returns it, attaching device information and the
54
* currently authenticated user if available. This model is not saved at this point, so
55
* you can always make modifications to it as needed before saving.
56
*
57
* @deprecated
58
*/
59
public static function instance(string $action, array $metadata, bool $isSystem = false): self
60
{
61
/** @var Request $request */
62
$request = Container::getInstance()->make('request');
63
if ($isSystem || !$request instanceof Request) {
64
$request = null;
65
}
66
67
return (new self())->fill([
68
'uuid' => Uuid::uuid4()->toString(),
69
'is_system' => $isSystem,
70
'user_id' => ($request && $request->user()) ? $request->user()->id : null,
71
'server_id' => null,
72
'action' => $action,
73
'device' => $request ? [
74
'ip_address' => $request->getClientIp() ?? '127.0.0.1',
75
'user_agent' => $request->userAgent() ?? '',
76
] : [],
77
'metadata' => $metadata,
78
]);
79
}
80
}
81
82