2017-09-10 04:55:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Server\Tasks;
|
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
use Illuminate\View\View;
|
2017-09-14 02:46:43 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-10-28 02:42:53 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-09-13 04:45:19 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2017-09-10 04:55:21 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
|
|
|
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
|
|
|
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
2017-09-13 04:45:19 +00:00
|
|
|
use Pterodactyl\Services\Schedules\ScheduleCreationService;
|
|
|
|
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
|
|
|
use Pterodactyl\Http\Requests\Server\ScheduleCreationFormRequest;
|
2017-09-10 04:55:21 +00:00
|
|
|
|
|
|
|
class TaskManagementController extends Controller
|
|
|
|
{
|
|
|
|
use JavascriptInjection;
|
|
|
|
|
|
|
|
/**
|
2017-09-13 04:45:19 +00:00
|
|
|
* @var \Prologue\Alerts\AlertsMessageBag
|
|
|
|
*/
|
|
|
|
protected $alert;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Schedules\ScheduleCreationService
|
2017-09-10 04:55:21 +00:00
|
|
|
*/
|
|
|
|
protected $creationService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Extensions\HashidsInterface
|
|
|
|
*/
|
|
|
|
protected $hashids;
|
|
|
|
|
|
|
|
/**
|
2017-09-13 04:45:19 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
|
2017-09-10 04:55:21 +00:00
|
|
|
*/
|
|
|
|
protected $repository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TaskManagementController constructor.
|
|
|
|
*
|
2017-09-13 04:45:19 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Pterodactyl\Contracts\Extensions\HashidsInterface $hashids
|
|
|
|
* @param \Pterodactyl\Services\Schedules\ScheduleCreationService $creationService
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
|
2017-09-10 04:55:21 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2017-09-13 04:45:19 +00:00
|
|
|
AlertsMessageBag $alert,
|
2017-09-10 04:55:21 +00:00
|
|
|
HashidsInterface $hashids,
|
2017-09-13 04:45:19 +00:00
|
|
|
ScheduleCreationService $creationService,
|
|
|
|
ScheduleRepositoryInterface $repository
|
2017-09-10 04:55:21 +00:00
|
|
|
) {
|
2017-09-13 04:45:19 +00:00
|
|
|
$this->alert = $alert;
|
2017-09-10 04:55:21 +00:00
|
|
|
$this->creationService = $creationService;
|
|
|
|
$this->hashids = $hashids;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the task page listing.
|
|
|
|
*
|
2017-10-28 02:42:53 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\View\View
|
2017-09-10 04:55:21 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function index(Request $request): View
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-13 04:45:19 +00:00
|
|
|
$this->authorize('list-schedules', $server);
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->setRequest($request)->injectJavascript();
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
return view('server.schedules.index', [
|
2017-10-28 02:42:53 +00:00
|
|
|
'schedules' => $this->repository->findServerSchedules($server->id),
|
2017-09-10 04:55:21 +00:00
|
|
|
'actions' => [
|
2017-09-14 02:46:43 +00:00
|
|
|
'command' => trans('server.schedule.actions.command'),
|
|
|
|
'power' => trans('server.schedule.actions.power'),
|
2017-09-10 04:55:21 +00:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the task creation page.
|
|
|
|
*
|
2017-10-28 02:42:53 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\View\View
|
2017-09-10 04:55:21 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function create(Request $request): View
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-13 04:45:19 +00:00
|
|
|
$this->authorize('create-schedule', $server);
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->setRequest($request)->injectJavascript();
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
return view('server.schedules.new');
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-28 02:42:53 +00:00
|
|
|
* Handle request to store a new schedule and tasks in the database.
|
|
|
|
*
|
2017-09-13 04:45:19 +00:00
|
|
|
* @param \Pterodactyl\Http\Requests\Server\ScheduleCreationFormRequest $request
|
2017-09-10 04:55:21 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
2017-09-13 04:45:19 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException
|
2017-09-10 04:55:21 +00:00
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function store(ScheduleCreationFormRequest $request): RedirectResponse
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-13 04:45:19 +00:00
|
|
|
$schedule = $this->creationService->handle($server, $request->normalize(), $request->getTasks());
|
2017-09-14 02:46:43 +00:00
|
|
|
$this->alert->success(trans('server.schedules.task_created'))->flash();
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
return redirect()->route('server.schedules.view', [
|
2017-09-10 04:55:21 +00:00
|
|
|
'server' => $server->uuidShort,
|
2017-10-28 02:42:53 +00:00
|
|
|
'schedule' => $schedule->hashid,
|
2017-09-10 04:55:21 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-13 04:45:19 +00:00
|
|
|
* Return a view to modify a schedule.
|
2017-09-10 04:55:21 +00:00
|
|
|
*
|
2017-09-14 02:46:43 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-09-10 04:55:21 +00:00
|
|
|
* @return \Illuminate\View\View
|
2017-10-28 02:42:53 +00:00
|
|
|
*
|
2017-09-10 04:55:21 +00:00
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function view(Request $request): View
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-13 04:45:19 +00:00
|
|
|
$schedule = $request->attributes->get('schedule');
|
|
|
|
$this->authorize('view-schedule', $server);
|
2017-09-10 04:55:21 +00:00
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->setRequest($request)->injectJavascript([
|
|
|
|
'tasks' => $schedule->getRelation('tasks')->map(function ($task) {
|
|
|
|
/* @var \Pterodactyl\Models\Task $task */
|
|
|
|
return collect($task->toArray())->only('action', 'time_offset', 'payload')->all();
|
2017-09-10 04:55:21 +00:00
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
return view('server.schedules.view', ['schedule' => $schedule]);
|
2017-09-13 04:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a specific parent task on the system.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Http\Requests\Server\ScheduleCreationFormRequest $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function update(ScheduleCreationFormRequest $request): RedirectResponse
|
2017-09-13 04:45:19 +00:00
|
|
|
{
|
2017-10-28 02:42:53 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-13 04:45:19 +00:00
|
|
|
$schedule = $request->attributes->get('schedule');
|
|
|
|
|
2017-10-28 02:42:53 +00:00
|
|
|
$this->alert->warning('Function is not implemented.')->flash();
|
|
|
|
// $this->updateService->handle($task, $request->normalize(), $request->getChainedTasks());
|
|
|
|
// $this->alert->success(trans('server.schedules.task_updated'))->flash();
|
2017-09-13 04:45:19 +00:00
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
return redirect()->route('server.schedules.view', [
|
2017-09-13 04:45:19 +00:00
|
|
|
'server' => $server->uuidShort,
|
2017-10-28 02:42:53 +00:00
|
|
|
'schedule' => $schedule->hashid,
|
2017-09-13 04:45:19 +00:00
|
|
|
]);
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 04:45:19 +00:00
|
|
|
/**
|
|
|
|
* Delete a parent task from the Panel.
|
|
|
|
*
|
2017-09-14 02:46:43 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-10-28 02:42:53 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
2017-09-13 04:45:19 +00:00
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
2017-10-28 02:42:53 +00:00
|
|
|
public function delete(Request $request): Response
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
2017-12-02 02:10:06 +00:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-13 04:45:19 +00:00
|
|
|
$schedule = $request->attributes->get('schedule');
|
|
|
|
$this->authorize('delete-schedule', $server);
|
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
$this->repository->delete($schedule->id);
|
2017-09-13 04:45:19 +00:00
|
|
|
|
|
|
|
return response('', 204);
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
}
|