forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for tracking when an activity event is triggered from an …
…API key
- Loading branch information
1 parent
92c1c16
commit 0520014
Showing
7 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Pterodactyl\Http\Middleware\Activity; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Pterodactyl\Models\ApiKey; | ||
use Pterodactyl\Facades\LogTarget; | ||
|
||
class TrackAPIKey | ||
{ | ||
/** | ||
* Determines if the authenticated user making this request is using an actual | ||
* API key, or it is just a cookie authenticated session. This data is set in a | ||
* request singleton so that all tracked activity log events are properly associated | ||
* with the given API key. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle(Request $request, Closure $next) | ||
{ | ||
if ($request->user()) { | ||
$token = $request->user()->currentAccessToken(); | ||
|
||
LogTarget::setApiKeyId($token instanceof ApiKey ? $token->id : null); | ||
} | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
database/migrations/2022_06_18_112822_track_api_key_usage_for_activity_events.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('activity_logs', function (Blueprint $table) { | ||
$table->unsignedInteger('api_key_id')->nullable()->after('actor_id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('activity_logs', function (Blueprint $table) { | ||
$table->dropColumn('api_key_id'); | ||
}); | ||
} | ||
}; |