2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
namespace Pterodactyl\Http\Controllers\Base;
|
|
|
|
|
2016-12-07 22:46:38 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-01-05 04:49:50 +00:00
|
|
|
use Pterodactyl\Models\User;
|
2018-03-07 04:17:01 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use GuzzleHttp\Exception\ConnectException;
|
2017-09-24 17:34:00 +00:00
|
|
|
use GuzzleHttp\Exception\RequestException;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2017-09-24 17:34:00 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
2017-09-25 02:12:30 +00:00
|
|
|
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
|
2017-08-31 02:14:20 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
2017-08-31 02:11:14 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
2016-10-14 21:15:36 +00:00
|
|
|
|
2015-12-06 18:58:49 +00:00
|
|
|
class IndexController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2017-09-25 02:12:30 +00:00
|
|
|
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
|
2015-12-06 18:58:49 +00:00
|
|
|
*/
|
2017-09-25 02:12:30 +00:00
|
|
|
protected $daemonRepository;
|
2017-04-01 17:14:49 +00:00
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
/**
|
2017-09-25 02:12:30 +00:00
|
|
|
* @var \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService
|
2017-08-31 02:11:14 +00:00
|
|
|
*/
|
2017-09-25 02:12:30 +00:00
|
|
|
protected $keyProviderService;
|
2017-08-31 02:11:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
|
|
|
protected $repository;
|
2017-04-01 17:14:49 +00:00
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
/**
|
|
|
|
* IndexController constructor.
|
|
|
|
*
|
2017-09-25 02:12:30 +00:00
|
|
|
* @param \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService $keyProviderService
|
2017-08-31 02:11:14 +00:00
|
|
|
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonRepository
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
|
|
|
*/
|
|
|
|
public function __construct(
|
2017-09-25 02:12:30 +00:00
|
|
|
DaemonKeyProviderService $keyProviderService,
|
2017-08-31 02:11:14 +00:00
|
|
|
DaemonServerRepositoryInterface $daemonRepository,
|
|
|
|
ServerRepositoryInterface $repository
|
|
|
|
) {
|
|
|
|
$this->daemonRepository = $daemonRepository;
|
2017-09-25 02:12:30 +00:00
|
|
|
$this->keyProviderService = $keyProviderService;
|
2017-08-31 02:11:14 +00:00
|
|
|
$this->repository = $repository;
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-12 06:21:17 +00:00
|
|
|
/**
|
2017-08-31 02:11:14 +00:00
|
|
|
* Returns listing of user's servers.
|
2015-12-12 06:21:17 +00:00
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2017-08-31 02:11:14 +00:00
|
|
|
* @return \Illuminate\View\View
|
2015-12-12 06:21:17 +00:00
|
|
|
*/
|
2017-08-31 02:11:14 +00:00
|
|
|
public function getIndex(Request $request)
|
2015-12-12 06:21:17 +00:00
|
|
|
{
|
2018-01-05 04:49:50 +00:00
|
|
|
$servers = $this->repository->setSearchTerm($request->input('query'))->filterUserAccessServers(
|
|
|
|
$request->user(), User::FILTER_LEVEL_ALL
|
2017-08-31 02:11:14 +00:00
|
|
|
);
|
2016-12-02 00:16:40 +00:00
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
return view('base.index', ['servers' => $servers]);
|
2015-12-12 06:21:17 +00:00
|
|
|
}
|
2017-05-05 20:27:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns status of the server in a JSON response used for populating active status list.
|
|
|
|
*
|
2017-08-22 03:10:48 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param string $uuid
|
2017-05-05 20:27:36 +00:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2017-08-31 02:11:14 +00:00
|
|
|
* @throws \Exception
|
2017-05-05 20:27:36 +00:00
|
|
|
*/
|
|
|
|
public function status(Request $request, $uuid)
|
|
|
|
{
|
2017-09-24 17:34:00 +00:00
|
|
|
$server = $this->repository->findFirstWhere([['uuidShort', '=', $uuid]]);
|
2017-11-05 18:38:39 +00:00
|
|
|
$token = $this->keyProviderService->handle($server, $request->user());
|
2017-05-05 20:27:36 +00:00
|
|
|
|
|
|
|
if (! $server->installed) {
|
|
|
|
return response()->json(['status' => 20]);
|
2017-08-31 02:11:14 +00:00
|
|
|
} elseif ($server->suspended) {
|
2017-05-05 20:27:36 +00:00
|
|
|
return response()->json(['status' => 30]);
|
|
|
|
}
|
|
|
|
|
2017-09-24 17:34:00 +00:00
|
|
|
try {
|
2018-01-06 00:27:47 +00:00
|
|
|
$response = $this->daemonRepository->setServer($server)->setToken($token)->details();
|
2018-03-07 04:17:01 +00:00
|
|
|
} catch (ConnectException $exception) {
|
|
|
|
throw new HttpException(Response::HTTP_GATEWAY_TIMEOUT, $exception->getMessage());
|
2017-09-24 17:34:00 +00:00
|
|
|
} catch (RequestException $exception) {
|
|
|
|
throw new HttpException(500, $exception->getMessage());
|
|
|
|
}
|
2017-05-05 20:27:36 +00:00
|
|
|
|
2017-08-31 02:11:14 +00:00
|
|
|
return response()->json(json_decode($response->getBody()));
|
2017-05-05 20:27:36 +00:00
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|