fix: add missing Admin controllers, fix __DIR__ paths (3 levels), defensive ServiceProvider
This commit is contained in:
@@ -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