2017-09-10 04:55:21 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Server\Tasks;
|
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-09-13 04:45:19 +00:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2017-09-10 04:55:21 +00:00
|
|
|
use Illuminate\Contracts\Session\Session;
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Illuminate\Contracts\Session\Session
|
|
|
|
*/
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TaskManagementController constructor.
|
|
|
|
*
|
2017-09-13 04:45:19 +00:00
|
|
|
* @param \Prologue\Alerts\AlertsMessageBag $alert
|
|
|
|
* @param \Pterodactyl\Contracts\Extensions\HashidsInterface $hashids
|
|
|
|
* @param \Illuminate\Contracts\Session\Session $session
|
|
|
|
* @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,
|
|
|
|
Session $session,
|
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;
|
|
|
|
$this->session = $session;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the task page listing.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$server = $this->session->get('server_data.model');
|
2017-09-13 04:45:19 +00:00
|
|
|
$this->authorize('list-schedules', $server);
|
2017-09-10 04:55:21 +00:00
|
|
|
$this->injectJavascript();
|
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
return view('server.schedules.index', [
|
2017-09-13 04:45:19 +00:00
|
|
|
'schedules' => $this->repository->getServerSchedules($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.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
$server = $this->session->get('server_data.model');
|
2017-09-13 04:45:19 +00:00
|
|
|
$this->authorize('create-schedule', $server);
|
2017-09-10 04:55:21 +00:00
|
|
|
$this->injectJavascript();
|
|
|
|
|
2017-09-14 02:46:43 +00:00
|
|
|
return view('server.schedules.new');
|
2017-09-10 04:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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 \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @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-09-13 04:45:19 +00:00
|
|
|
public function store(ScheduleCreationFormRequest $request)
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
|
|
|
$server = $this->session->get('server_data.model');
|
2017-09-13 04:45:19 +00:00
|
|
|
$this->authorize('create-schedule', $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-09-13 04:45:19 +00:00
|
|
|
'task' => $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
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
2017-09-13 04:45:19 +00:00
|
|
|
public function view(Request $request)
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
|
|
|
$server = $this->session->get('server_data.model');
|
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
|
|
|
|
|
|
|
$this->injectJavascript([
|
2017-09-13 04:45:19 +00:00
|
|
|
'tasks' => $schedule->tasks->map(function ($schedule) {
|
|
|
|
return collect($schedule->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
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
|
|
|
public function update(ScheduleCreationFormRequest $request)
|
|
|
|
{
|
|
|
|
$server = $this->session->get('server_data.model');
|
|
|
|
$schedule = $request->attributes->get('schedule');
|
|
|
|
$this->authorize('edit-schedule', $server);
|
|
|
|
|
|
|
|
// $this->updateService->handle($task, $request->normalize(), $request->getChainedTasks());
|
2017-09-14 02:46:43 +00:00
|
|
|
// $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,
|
|
|
|
'task' => $schedule->hashid,
|
|
|
|
]);
|
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-09-13 04:45:19 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
*/
|
|
|
|
public function delete(Request $request)
|
2017-09-10 04:55:21 +00:00
|
|
|
{
|
|
|
|
$server = $this->session->get('server_data.model');
|
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
|
|
|
}
|
|
|
|
}
|