2021-01-17 18:49:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Container\Container;
|
|
|
|
|
|
|
|
/**
|
2022-05-29 22:20:54 +00:00
|
|
|
* @deprecated — this class will be dropped in a future version, use the activity log
|
2021-01-17 18:49:36 +00:00
|
|
|
*/
|
|
|
|
class AuditLog extends Model
|
|
|
|
{
|
2021-01-26 03:20:51 +00:00
|
|
|
public const UPDATED_AT = null;
|
2021-01-17 18:49:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
public static $validationRules = [
|
|
|
|
'uuid' => 'required|uuid',
|
2021-01-17 19:52:44 +00:00
|
|
|
'action' => 'required|string|max:191',
|
|
|
|
'subaction' => 'nullable|string|max:191',
|
2021-01-17 19:46:08 +00:00
|
|
|
'device' => 'array',
|
2021-01-17 18:49:36 +00:00
|
|
|
'device.ip_address' => 'ip',
|
|
|
|
'device.user_agent' => 'string',
|
|
|
|
'metadata' => 'array',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'audit_logs';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $immutableDates = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2021-07-11 19:15:39 +00:00
|
|
|
'is_system' => 'bool',
|
2021-01-17 18:49:36 +00:00
|
|
|
'device' => 'array',
|
|
|
|
'metadata' => 'array',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
*/
|
|
|
|
protected $guarded = [
|
|
|
|
'id',
|
|
|
|
'created_at',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function server()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Server::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new AuditLog model and returns it, attaching device information and the
|
|
|
|
* currently authenticated user if available. This model is not saved at this point, so
|
|
|
|
* you can always make modifications to it as needed before saving.
|
|
|
|
*
|
|
|
|
* @return $this
|
2022-05-29 22:20:54 +00:00
|
|
|
*
|
|
|
|
* @deprecated
|
2021-01-17 18:49:36 +00:00
|
|
|
*/
|
2021-01-31 02:07:48 +00:00
|
|
|
public static function instance(string $action, array $metadata, bool $isSystem = false)
|
2021-01-17 18:49:36 +00:00
|
|
|
{
|
|
|
|
/** @var \Illuminate\Http\Request $request */
|
|
|
|
$request = Container::getInstance()->make('request');
|
2021-01-26 03:20:51 +00:00
|
|
|
if ($isSystem || !$request instanceof Request) {
|
2021-01-17 18:49:36 +00:00
|
|
|
$request = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (new self())->fill([
|
|
|
|
'uuid' => Uuid::uuid4()->toString(),
|
|
|
|
'is_system' => $isSystem,
|
2021-01-17 19:46:08 +00:00
|
|
|
'user_id' => ($request && $request->user()) ? $request->user()->id : null,
|
2021-01-17 18:49:36 +00:00
|
|
|
'server_id' => null,
|
|
|
|
'action' => $action,
|
|
|
|
'device' => $request ? [
|
2021-09-11 20:00:53 +00:00
|
|
|
'ip_address' => $request->getClientIp() ?? '127.0.0.1',
|
|
|
|
'user_agent' => $request->userAgent() ?? '',
|
2021-01-17 18:49:36 +00:00
|
|
|
] : [],
|
|
|
|
'metadata' => $metadata,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|