You've already forked Atomcms-edit
0b6f14d5bf
- Centralize all CDN URLs in config('habbo.cdn.*') with env overrides
- Replace hardcoded CDN URLs in 12+ blade views (fancybox, sweetalert2,
alpinejs, fontsource, fontawesome, html2canvas)
- Fix font-awesome 7.0.0 (non-existent) -> config with 6.7.0 default
- Centralize all hardcoded min_staff_rank defaults (3 and 7) to config
- Add MIN_STAFF_RANK and MIN_STAFF_RANK_LOGIN env variables
94 lines
3.0 KiB
PHP
Executable File
94 lines
3.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\StaffActivity;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class LogStaffActivity
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
return $next($request);
|
|
}
|
|
|
|
public function terminate(Request $request, Response $response): void
|
|
{
|
|
if (auth()->check() && auth()->user()->rank >= (int) setting('min_staff_rank', config('habbo.defaults.min_staff_rank_login'))) {
|
|
$this->logRequest($request);
|
|
}
|
|
}
|
|
|
|
private function logRequest(Request $request): void
|
|
{
|
|
$user = auth()->user();
|
|
$path = $request->path();
|
|
|
|
if (str_contains($path, 'housekeeping') || str_starts_with($path, 'hk')) {
|
|
$action = $this->determineAction($request);
|
|
$description = $this->generateDescription($request);
|
|
|
|
if ($action && $description) {
|
|
StaffActivity::log(
|
|
$user->id,
|
|
$action,
|
|
$description,
|
|
$request->route()?->getName(),
|
|
null,
|
|
[
|
|
'method' => $request->method(),
|
|
'path' => $path,
|
|
'route' => $request->route()?->getName(),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function determineAction(Request $request): ?string
|
|
{
|
|
$method = $request->method();
|
|
$path = $request->path();
|
|
|
|
if ($method === 'POST') {
|
|
if (str_contains($path, 'ban')) {
|
|
return 'user_ban';
|
|
} elseif (str_contains($path, 'delete')) {
|
|
return 'content_delete';
|
|
} elseif (str_contains($path, 'create') || str_contains($path, 'store')) {
|
|
return 'content_create';
|
|
} elseif (str_contains($path, 'edit') || str_contains($path, 'update')) {
|
|
return 'content_edit';
|
|
} elseif (str_contains($path, 'rank')) {
|
|
return 'rank_change';
|
|
} elseif (str_contains($path, 'settings')) {
|
|
return 'settings_update';
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private function generateDescription(Request $request): ?string
|
|
{
|
|
$action = $this->determineAction($request);
|
|
|
|
if (! $action) {
|
|
return null;
|
|
}
|
|
|
|
return match ($action) {
|
|
'user_ban' => 'Banned user: ' . ($request->input('user_id') ?? $request->input('username') ?? 'unknown'),
|
|
'user_unban' => 'Unbanned user',
|
|
'content_delete' => 'Deleted content: ' . $request->path(),
|
|
'content_create' => 'Created new content',
|
|
'content_edit' => 'Updated content: ' . $request->path(),
|
|
'rank_change' => 'Changed user rank',
|
|
'settings_update' => 'Updated settings',
|
|
default => 'Performed action: ' . $action,
|
|
};
|
|
}
|
|
}
|