fix: add missing Admin controllers, fix __DIR__ paths (3 levels), defensive ServiceProvider
This commit is contained in:
@@ -26,7 +26,7 @@ class AddonServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
// Merge addon config (won't overwrite user's published config)
|
// Merge addon config (won't overwrite user's published config)
|
||||||
$this->mergeConfigFrom(
|
$this->mergeConfigFrom(
|
||||||
__DIR__ . '/../../config/advanced-admin.php',
|
__DIR__ . '/../../../config/advanced-admin.php',
|
||||||
'advanced-admin'
|
'advanced-admin'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -43,8 +43,8 @@ class AddonServiceProvider extends ServiceProvider
|
|||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
// ── Routes ────────────────────────────────────────────────────────────
|
// ── Routes ────────────────────────────────────────────────────────────
|
||||||
$clientRoutes = __DIR__ . '/../../routes/addon-client.php';
|
$clientRoutes = __DIR__ . '/../../../routes/addon-client.php';
|
||||||
$appRoutes = __DIR__ . '/../../routes/addon-application.php';
|
$appRoutes = __DIR__ . '/../../../routes/addon-application.php';
|
||||||
|
|
||||||
if (file_exists($clientRoutes)) {
|
if (file_exists($clientRoutes)) {
|
||||||
$this->loadRoutesFrom($clientRoutes);
|
$this->loadRoutesFrom($clientRoutes);
|
||||||
@@ -54,7 +54,7 @@ class AddonServiceProvider extends ServiceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Migrations ────────────────────────────────────────────────────────
|
// ── Migrations ────────────────────────────────────────────────────────
|
||||||
$migrationsPath = __DIR__ . '/../../database/migrations/addon';
|
$migrationsPath = __DIR__ . '/../../../database/migrations/addon';
|
||||||
if (is_dir($migrationsPath)) {
|
if (is_dir($migrationsPath)) {
|
||||||
$this->loadMigrationsFrom($migrationsPath);
|
$this->loadMigrationsFrom($migrationsPath);
|
||||||
}
|
}
|
||||||
@@ -129,11 +129,11 @@ class AddonServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
// ── Publishable Assets ────────────────────────────────────────────────
|
// ── Publishable Assets ────────────────────────────────────────────────
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
__DIR__ . '/../../config/advanced-admin.php' => config_path('advanced-admin.php'),
|
__DIR__ . '/../../../config/advanced-admin.php' => config_path('advanced-admin.php'),
|
||||||
], 'advanced-admin-config');
|
], 'advanced-admin-config');
|
||||||
|
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
__DIR__ . '/../../config/addon-commands' => base_path('config/addon-commands'),
|
__DIR__ . '/../../../config/addon-commands' => base_path('config/addon-commands'),
|
||||||
], 'advanced-admin-commands');
|
], 'advanced-admin-commands');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Addons\AdvancedAdmin\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Controller;
|
||||||
|
use Pterodactyl\Addons\AdvancedAdmin\Models\CommandDefinition;
|
||||||
|
|
||||||
|
class CommandDefinitionController extends Controller
|
||||||
|
{
|
||||||
|
/** GET api/application/addons/console/definitions */
|
||||||
|
public function index(): JsonResponse
|
||||||
|
{
|
||||||
|
$defs = class_exists(CommandDefinition::class)
|
||||||
|
? CommandDefinition::orderBy('command')->get()
|
||||||
|
: collect([]);
|
||||||
|
|
||||||
|
return response()->json(['data' => $defs]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** POST api/application/addons/console/definitions */
|
||||||
|
public function store(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$validated = $request->validate([
|
||||||
|
'command' => 'required|string|max:100',
|
||||||
|
'description' => 'required|string|max:255',
|
||||||
|
'syntax' => 'nullable|string|max:255',
|
||||||
|
'dangerous' => 'boolean',
|
||||||
|
'plugin' => 'nullable|string|max:80',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!class_exists(CommandDefinition::class)) {
|
||||||
|
return response()->json(['error' => 'CommandDefinition model not available'], 501);
|
||||||
|
}
|
||||||
|
|
||||||
|
$def = CommandDefinition::create($validated);
|
||||||
|
return response()->json(['data' => $def], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** GET api/application/addons/console/definitions/{id} */
|
||||||
|
public function show(int $id): JsonResponse
|
||||||
|
{
|
||||||
|
if (!class_exists(CommandDefinition::class)) {
|
||||||
|
return response()->json(['error' => 'Not available'], 501);
|
||||||
|
}
|
||||||
|
return response()->json(['data' => CommandDefinition::findOrFail($id)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PUT api/application/addons/console/definitions/{id} */
|
||||||
|
public function update(Request $request, int $id): JsonResponse
|
||||||
|
{
|
||||||
|
if (!class_exists(CommandDefinition::class)) {
|
||||||
|
return response()->json(['error' => 'Not available'], 501);
|
||||||
|
}
|
||||||
|
$def = CommandDefinition::findOrFail($id);
|
||||||
|
$def->update($request->only(['command', 'description', 'syntax', 'dangerous', 'plugin']));
|
||||||
|
return response()->json(['data' => $def]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** DELETE api/application/addons/console/definitions/{id} */
|
||||||
|
public function destroy(int $id): JsonResponse
|
||||||
|
{
|
||||||
|
if (!class_exists(CommandDefinition::class)) {
|
||||||
|
return response()->json(['error' => 'Not available'], 501);
|
||||||
|
}
|
||||||
|
CommandDefinition::findOrFail($id)->delete();
|
||||||
|
return response()->json(null, 204);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** GET api/application/addons/console/settings */
|
||||||
|
public function settings(): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'data' => [
|
||||||
|
'enabled' => config('advanced-admin.console.enabled', true),
|
||||||
|
'rate_limit' => config('advanced-admin.console.rate_limit', 60),
|
||||||
|
'player_ttl' => config('advanced-admin.console.player_ttl_minutes', 30),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PUT api/application/addons/console/settings */
|
||||||
|
public function updateSettings(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
return $this->settings();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Addons\AdvancedAdmin\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Routing\Controller;
|
||||||
|
use Pterodactyl\Models\Node;
|
||||||
|
use Pterodactyl\Addons\AdvancedAdmin\Models\NetworkMetric;
|
||||||
|
|
||||||
|
class NodeNetworkController extends Controller
|
||||||
|
{
|
||||||
|
/** GET api/application/addons/network/nodes */
|
||||||
|
public function index(): JsonResponse
|
||||||
|
{
|
||||||
|
$nodes = Node::all()->map(function (Node $node) {
|
||||||
|
$latest = NetworkMetric::where('node_id', $node->id)
|
||||||
|
->orderByDesc('recorded_at')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $node->id,
|
||||||
|
'name' => $node->name,
|
||||||
|
'fqdn' => $node->fqdn,
|
||||||
|
'rx_bytes' => $latest?->rx_bytes ?? 0,
|
||||||
|
'tx_bytes' => $latest?->tx_bytes ?? 0,
|
||||||
|
'recorded_at'=> $latest?->recorded_at,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return response()->json(['data' => $nodes]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** GET api/application/addons/network/nodes/{node} */
|
||||||
|
public function show(Node $node): JsonResponse
|
||||||
|
{
|
||||||
|
$metrics = NetworkMetric::where('node_id', $node->id)
|
||||||
|
->orderByDesc('recorded_at')
|
||||||
|
->limit(60)
|
||||||
|
->get(['recorded_at', 'rx_bytes', 'tx_bytes', 'server_id']);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'node' => ['id' => $node->id, 'name' => $node->name, 'fqdn' => $node->fqdn],
|
||||||
|
'metrics' => $metrics,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Addons\AdvancedAdmin\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Routing\Controller;
|
||||||
|
|
||||||
|
class RevisionSettingsController extends Controller
|
||||||
|
{
|
||||||
|
/** GET api/application/addons/revisions/settings */
|
||||||
|
public function show(): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'data' => [
|
||||||
|
'enabled' => config('advanced-admin.revisions.enabled', true),
|
||||||
|
'max_file_size' => config('advanced-admin.revisions.max_file_size', 10485760),
|
||||||
|
'max_per_file' => config('advanced-admin.revisions.max_per_file', 50),
|
||||||
|
'retention_days' => config('advanced-admin.revisions.retention_days', 90),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PUT api/application/addons/revisions/settings */
|
||||||
|
public function update(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
// Settings are managed via .env / config — return current for now
|
||||||
|
return $this->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user