Initial Commit

This commit is contained in:
NekoMonci12
2025-02-21 16:31:18 +07:00
parent 5755da9755
commit 5e60ee70e1
5 changed files with 129 additions and 0 deletions

BIN
activitypurges.blueprint Normal file

Binary file not shown.

62
admin/controller.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
namespace Pterodactyl\Http\Controllers\Admin\Extensions\activitypurges;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Illuminate\View\Factory as ViewFactory;
use Illuminate\Support\Facades\DB;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
class activitypurgesExtensionController extends Controller
{
public function __construct(
private ViewFactory $view,
private BlueprintExtensionLibrary $blueprint,
) {}
/**
* Handle both GET and POST requests.
*/
public function index(Request $request): View
{
$message = null;
if ($request->isMethod('post')) {
// Validate the input timestamp.
$validated = $request->validate([
'timestamp' => 'required|date'
]);
// Convert the HTML datetime-local value to MySQL datetime format.
$rawTimestamp = $validated['timestamp'];
$mysqlTimestamp = date('Y-m-d H:i:s', strtotime($rawTimestamp));
try {
// Purge records older than the provided timestamp.
$deleted = DB::table('activity_logs')
->where('timestamp', '<', $mysqlTimestamp)
->delete();
$message = "{$deleted} log(s) have been purged successfully.";
} catch (\Exception $e) {
\Log::error('Purge error: ' . $e->getMessage());
$message = "An error occurred while purging logs.";
}
}
return $this->view->make('admin.extensions.activitypurges.index', [
'root' => "/admin/extensions/activitypurges",
'blueprint' => $this->blueprint,
'message' => $message,
]);
}
/**
* Handle POST requests by delegating to index().
*/
public function post(Request $request): View
{
return $this->index($request);
}
}

30
admin/view.blade.php Normal file
View File

@@ -0,0 +1,30 @@
<!--
Content on this page will be displayed on your extension's admin page.
-->
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Information</h3>
</div>
<div class="box-body">
<!-- Display success message if available -->
@if(isset($message) && $message)
<div class="alert alert-success">
{{ $message }}
</div>
@endif
<p>
An Extension Used To <code>Clear/Purge</code> old Activity Logs, in order to clear database storage used.
</p>
<!-- The form posts to the same page -->
<form method="POST" action="{{ $root }}">
@csrf
<div class="form-group">
<label for="timestamp">Purge logs older than:</label>
<input type="datetime-local" name="timestamp" id="timestamp" class="form-control" required>
</div>
<button type="submit" class="btn btn-danger">Purge Logs</button>
</form>
</div>
</div>

37
conf.yml Normal file
View File

@@ -0,0 +1,37 @@
info:
name: "ActivityPurges"
identifier: "activitypurges"
description: "Purgin Old Activity Logs From Database"
flags: ""
version: "1.10"
target: "beta-2024-12"
author: "nekomonci12"
icon: "public/icon.jpg"
website: ""
admin:
view: "admin/view.blade.php"
controller: "admin/controller.php"
css: ""
wrapper: ""
dashboard:
css: ""
wrapper: ""
components: ""
data:
directory: ""
public: ""
console: ""
requests:
views: ""
app: ""
routers:
application: ""
client: ""
web: ""
database:
migrations: ""

BIN
public/icon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 KiB