2017-09-13 06:45:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Middleware\Server;
|
|
|
|
|
|
|
|
use Closure;
|
2017-10-29 18:37:25 +01:00
|
|
|
use Illuminate\Http\Request;
|
2017-09-13 06:45:19 +02:00
|
|
|
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
|
|
|
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
2017-10-28 04:42:53 +02:00
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
2017-09-13 06:45:19 +02:00
|
|
|
|
2017-10-19 05:32:19 +02:00
|
|
|
class ScheduleBelongsToServer
|
2017-09-13 06:45:19 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Extensions\HashidsInterface
|
|
|
|
*/
|
2017-10-28 04:42:53 +02:00
|
|
|
private $hashids;
|
2017-09-13 06:45:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
|
|
|
|
*/
|
2017-10-28 04:42:53 +02:00
|
|
|
private $repository;
|
2017-09-13 06:45:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TaskAccess constructor.
|
|
|
|
*
|
2019-09-06 06:32:57 +02:00
|
|
|
* @param \Pterodactyl\Contracts\Extensions\HashidsInterface $hashids
|
2017-09-13 06:45:19 +02:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
|
|
|
|
*/
|
2017-10-28 04:42:53 +02:00
|
|
|
public function __construct(HashidsInterface $hashids, ScheduleRepositoryInterface $repository)
|
|
|
|
{
|
2017-09-13 06:45:19 +02:00
|
|
|
$this->hashids = $hashids;
|
|
|
|
$this->repository = $repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a task is assigned to the active server.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2019-09-06 06:32:57 +02:00
|
|
|
* @param \Closure $next
|
2017-09-13 06:45:19 +02:00
|
|
|
* @return mixed
|
|
|
|
*
|
2017-10-28 04:42:53 +02:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
2017-09-24 03:45:25 +02:00
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
2017-09-13 06:45:19 +02:00
|
|
|
*/
|
2017-10-29 18:37:25 +01:00
|
|
|
public function handle(Request $request, Closure $next)
|
2017-09-13 06:45:19 +02:00
|
|
|
{
|
2017-10-28 04:42:53 +02:00
|
|
|
$server = $request->attributes->get('server');
|
2017-09-13 06:45:19 +02:00
|
|
|
|
2017-09-14 04:46:43 +02:00
|
|
|
$scheduleId = $this->hashids->decodeFirst($request->route()->parameter('schedule'), 0);
|
2017-09-13 06:45:19 +02:00
|
|
|
$schedule = $this->repository->getScheduleWithTasks($scheduleId);
|
|
|
|
|
2017-12-02 03:10:06 +01:00
|
|
|
if ($schedule->server_id !== $server->id) {
|
2017-10-28 04:42:53 +02:00
|
|
|
throw new NotFoundHttpException;
|
2017-09-13 06:45:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$request->attributes->set('schedule', $schedule);
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|