89 lines
3.1 KiB
PHP
89 lines
3.1 KiB
PHP
<?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();
|
|
}
|
|
}
|