From 4a8c3c4a34146fd26a57268fa94e24ab9ed5ce0d Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Mon, 4 Jul 2022 18:11:53 -0400 Subject: [PATCH] Add activity tracking for console/power actions --- .../Controllers/Api/Client/Servers/CommandController.php | 3 +++ .../Controllers/Api/Client/Servers/PowerController.php | 5 +++-- resources/lang/en/activity.php | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/Client/Servers/CommandController.php b/app/Http/Controllers/Api/Client/Servers/CommandController.php index f9663138c..05be19c60 100644 --- a/app/Http/Controllers/Api/Client/Servers/CommandController.php +++ b/app/Http/Controllers/Api/Client/Servers/CommandController.php @@ -4,6 +4,7 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers; use Illuminate\Http\Response; use Pterodactyl\Models\Server; +use Pterodactyl\Facades\Activity; use Psr\Http\Message\ResponseInterface; use GuzzleHttp\Exception\BadResponseException; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -53,6 +54,8 @@ class CommandController extends ClientApiController throw $exception; } + Activity::event('server:console.command')->property('command', $request->input('command'))->log(); + return $this->returnNoContent(); } } diff --git a/app/Http/Controllers/Api/Client/Servers/PowerController.php b/app/Http/Controllers/Api/Client/Servers/PowerController.php index 984a1edca..01d1c1349 100644 --- a/app/Http/Controllers/Api/Client/Servers/PowerController.php +++ b/app/Http/Controllers/Api/Client/Servers/PowerController.php @@ -4,6 +4,7 @@ namespace Pterodactyl\Http\Controllers\Api\Client\Servers; use Illuminate\Http\Response; use Pterodactyl\Models\Server; +use Pterodactyl\Facades\Activity; use Pterodactyl\Repositories\Wings\DaemonPowerRepository; use Pterodactyl\Http\Controllers\Api\Client\ClientApiController; use Pterodactyl\Http\Requests\Api\Client\Servers\SendPowerRequest; @@ -27,8 +28,6 @@ class PowerController extends ClientApiController /** * Send a power action to a server. - * - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException */ public function index(SendPowerRequest $request, Server $server): Response { @@ -36,6 +35,8 @@ class PowerController extends ClientApiController $request->input('signal') ); + Activity::event(strtolower("server:power.{$request->input('signal')}"))->log(); + return $this->returnNoContent(); } } diff --git a/resources/lang/en/activity.php b/resources/lang/en/activity.php index 203115afa..63d9929ee 100644 --- a/resources/lang/en/activity.php +++ b/resources/lang/en/activity.php @@ -37,6 +37,15 @@ return [ ], 'server' => [ 'reinstall' => 'Reinstalled server', + 'console' => [ + 'command' => 'Executed ":command" on the server', + ], + 'power' => [ + 'start' => 'Started the server', + 'stop' => 'Stopped the server', + 'restart' => 'Restarted the server', + 'kill' => 'Killed the server process', + ], 'backup' => [ 'download' => 'Downloaded the :name backup', 'delete' => 'Deleted the :name backup',