Update demon routes to use /v1/

This commit is contained in:
Dane Everitt 2017-09-30 21:00:24 -05:00
parent 15d38ce823
commit b1834307d5
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
25 changed files with 55 additions and 67 deletions

View File

@ -30,6 +30,8 @@ use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Testing\HttpException;
use League\Fractal\Serializer\JsonApiSerializer;
use Pterodactyl\Transformers\Daemon\ApiKeyTransformer;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
class ValidateKeyController extends Controller
@ -81,7 +83,11 @@ class ValidateKeyController extends Controller
throw new HttpException(501);
}
$key = $this->daemonKeyRepository->getKeyWithServer($token);
try {
$key = $this->daemonKeyRepository->getKeyWithServer($token);
} catch (RecordNotFoundException $exception) {
throw new NotFoundHttpException;
}
return $this->fractal->item($key, $this->app->make(ApiKeyTransformer::class), 'server')
->serializeWith(JsonApiSerializer::class)

View File

@ -194,7 +194,6 @@ class OptionController extends Controller
$this->optionUpdateService->handle($option, $request->all());
$this->alert->success(trans('admin/services.options.notices.option_updated'))->flash();
} catch (NoParentConfigurationFoundException $exception) {
dd('hodor');
$this->alert->danger($exception->getMessage())->flash();
}

View File

@ -55,7 +55,7 @@ class DownloadController extends Controller
$this->cache->tags(['Server:Downloads'])->put($token, ['server' => $server->uuid, 'path' => $file], 5);
return redirect(sprintf(
'%s://%s:%s/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, $token
'%s://%s:%s/v1/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, $token
));
}
}

View File

@ -9,7 +9,6 @@
namespace Pterodactyl\Models;
use GuzzleHttp\Client;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Validable;
use Illuminate\Database\Eloquent\Model;
@ -126,22 +125,6 @@ class Node extends Model implements CleansAttributes, ValidableContract
'daemonListen' => 8080,
];
/**
* Return an instance of the Guzzle client for this specific node.
*
* @param array $headers
* @return \GuzzleHttp\Client
*/
public function guzzleClient($headers = [])
{
return new Client([
'base_uri' => sprintf('%s://%s:%s/', $this->scheme, $this->fqdn, $this->daemonListen),
'timeout' => config('pterodactyl.guzzle.timeout'),
'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
'headers' => $headers,
]);
}
/**
* Returns the configuration in JSON format.
*

View File

@ -141,7 +141,7 @@ class BaseRepository implements BaseRepositoryInterface
}
return new Client([
'base_uri' => sprintf('%s://%s:%s/', $this->getNode()->scheme, $this->getNode()->fqdn, $this->getNode()->daemonListen),
'base_uri' => sprintf('%s://%s:%s/v1/', $this->getNode()->scheme, $this->getNode()->fqdn, $this->getNode()->daemonListen),
'timeout' => $this->config->get('pterodactyl.guzzle.timeout'),
'connect_timeout' => $this->config->get('pterodactyl.guzzle.connect_timeout'),
'headers' => $headers,

View File

@ -21,7 +21,7 @@ class CommandRepository extends BaseRepository implements CommandRepositoryInter
{
Assert::stringNotEmpty($command, 'First argument passed to send must be a non-empty string, received %s.');
return $this->getHttpClient()->request('POST', '/server/command', [
return $this->getHttpClient()->request('POST', 'server/command', [
'json' => [
'command' => $command,
],

View File

@ -41,7 +41,7 @@ class ConfigurationRepository extends BaseRepository implements ConfigurationRep
],
];
return $this->getHttpClient()->request('PATCH', '/config', [
return $this->getHttpClient()->request('PATCH', 'config', [
'json' => array_merge($structure, $overrides),
]);
}

View File

@ -22,7 +22,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/file/stat/%s',
'server/file/stat/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -40,7 +40,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/file/f/%s',
'server/file/f/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -58,7 +58,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
return $this->getHttpClient()->request('POST', '/server/file/save', [
return $this->getHttpClient()->request('POST', 'server/file/save', [
'json' => [
'path' => rawurlencode($file['dirname'] . $file['basename']),
'content' => $content,
@ -74,7 +74,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
Assert::string($path, 'First argument passed to getDirectory must be a string, received %s.');
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/directory/%s',
'server/directory/%s',
rawurlencode($path)
));

View File

@ -27,7 +27,7 @@ class PowerRepository extends BaseRepository implements PowerRepositoryInterface
case self::SIGNAL_STOP:
case self::SIGNAL_RESTART:
case self::SIGNAL_KILL:
return $this->getHttpClient()->request('PUT', '/server/power', [
return $this->getHttpClient()->request('PUT', 'server/power', [
'json' => [
'action' => $signal,
],

View File

@ -63,7 +63,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
array_set($data, $key, $value);
}
return $this->getHttpClient()->request('POST', '/servers', [
return $this->getHttpClient()->request('POST', 'servers', [
'json' => $data,
]);
}
@ -73,7 +73,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function update(array $data)
{
return $this->getHttpClient()->request('PATCH', '/server', [
return $this->getHttpClient()->request('PATCH', 'server', [
'json' => $data,
]);
}
@ -86,10 +86,10 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
Assert::nullOrIsArray($data, 'First argument passed to reinstall must be null or an array, received %s.');
if (is_null($data)) {
return $this->getHttpClient()->request('POST', '/server/reinstall');
return $this->getHttpClient()->request('POST', 'server/reinstall');
}
return $this->getHttpClient()->request('POST', '/server/reinstall', [
return $this->getHttpClient()->request('POST', 'server/reinstall', [
'json' => $data,
]);
}
@ -99,7 +99,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function rebuild()
{
return $this->getHttpClient()->request('POST', '/server/rebuild');
return $this->getHttpClient()->request('POST', 'server/rebuild');
}
/**
@ -107,7 +107,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function suspend()
{
return $this->getHttpClient()->request('POST', '/server/suspend');
return $this->getHttpClient()->request('POST', 'server/suspend');
}
/**
@ -115,7 +115,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function unsuspend()
{
return $this->getHttpClient()->request('POST', '/server/unsuspend');
return $this->getHttpClient()->request('POST', 'server/unsuspend');
}
/**
@ -123,7 +123,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function delete()
{
return $this->getHttpClient()->request('DELETE', '/servers');
return $this->getHttpClient()->request('DELETE', 'servers');
}
/**
@ -131,7 +131,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function details()
{
return $this->getHttpClient()->request('GET', '/server');
return $this->getHttpClient()->request('GET', 'server');
}
/**
@ -141,6 +141,6 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
{
Assert::stringNotEmpty($key, 'First argument passed to revokeAccessKey must be a non-empty string, received %s.');
return $this->getHttpClient()->request('DELETE', '/keys/' . $key);
return $this->getHttpClient()->request('DELETE', 'keys/' . $key);
}
}

View File

@ -21,7 +21,7 @@ class CommandRepository extends BaseRepository implements CommandRepositoryInter
{
Assert::stringNotEmpty($command, 'First argument passed to send must be a non-empty string, received %s.');
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/command', [
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/command', [
'json' => [
'command' => $command,
],

View File

@ -25,7 +25,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/' . $this->getAccessServer() . '/file/stat/%s',
'server/' . $this->getAccessServer() . '/file/stat/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -43,7 +43,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/' . $this->getAccessServer() . '/file/f/%s',
'server/' . $this->getAccessServer() . '/file/f/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
@ -61,7 +61,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/file/save', [
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/file/save', [
'json' => [
'path' => rawurlencode($file['dirname'] . $file['basename']),
'content' => $content,
@ -77,7 +77,7 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
Assert::string($path, 'First argument passed to getDirectory must be a string, received %s.');
$response = $this->getHttpClient()->request('GET', sprintf(
'/server/' . $this->getAccessServer() . '/directory/%s',
'server/' . $this->getAccessServer() . '/directory/%s',
rawurlencode($path)
));

View File

@ -27,7 +27,7 @@ class PowerRepository extends BaseRepository implements PowerRepositoryInterface
case self::SIGNAL_STOP:
case self::SIGNAL_RESTART:
case self::SIGNAL_KILL:
return $this->getHttpClient()->request('PUT', '/server/' . $this->getAccessServer() . '/power', [
return $this->getHttpClient()->request('PUT', 'server/' . $this->getAccessServer() . '/power', [
'json' => [
'action' => $signal,
],

View File

@ -43,7 +43,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function rebuild()
{
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/rebuild');
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/rebuild');
}
/**
@ -51,7 +51,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function suspend()
{
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/suspend');
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/suspend');
}
/**
@ -59,7 +59,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function unsuspend()
{
return $this->getHttpClient()->request('POST', '/server/' . $this->getAccessServer() . '/unsuspend');
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/unsuspend');
}
/**
@ -67,7 +67,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function delete()
{
return $this->getHttpClient()->request('DELETE', '/server/' . $this->getAccessServer());
return $this->getHttpClient()->request('DELETE', 'server/' . $this->getAccessServer());
}
/**
@ -75,7 +75,7 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function details()
{
return $this->getHttpClient()->request('GET', '/server/' . $this->getAccessServer());
return $this->getHttpClient()->request('GET', 'server/' . $this->getAccessServer());
}
/**

View File

@ -107,7 +107,7 @@ return [
| Configuration for support of the new Golang based daemon.
*/
'daemon' => [
'use_new_daemon' => env('APP_USE_NEW_DAEMON', false),
'use_new_daemon' => (bool) env('APP_USE_NEW_DAEMON', false),
],
/*

File diff suppressed because one or more lines are too long

View File

@ -43,7 +43,7 @@
var notifySocketError = false;
// Main Socket Object
window.Socket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/stats/', {
window.Socket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/v1/stats/', {
'query': 'token=' + Pterodactyl.node.daemonSecret,
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -62,7 +62,7 @@ class ActionsClass {
'X-Access-Server': Pterodactyl.server.uuid,
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/folder`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/folder`,
timeout: 10000,
data: JSON.stringify({
path: val,
@ -107,7 +107,7 @@ class ActionsClass {
'X-Access-Server': Pterodactyl.server.uuid,
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/move`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/move`,
timeout: 10000,
data: JSON.stringify({
from: `${currentPath}${currentName}`,
@ -175,7 +175,7 @@ class ActionsClass {
'X-Access-Server': Pterodactyl.server.uuid,
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/rename`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/rename`,
timeout: 10000,
data: JSON.stringify({
from: `${currentPath}${currentName}`,
@ -240,7 +240,7 @@ class ActionsClass {
'X-Access-Server': Pterodactyl.server.uuid,
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/copy`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/copy`,
timeout: 10000,
data: JSON.stringify({
from: `${currentPath}${currentName}`,
@ -298,7 +298,7 @@ class ActionsClass {
'X-Access-Server': Pterodactyl.server.uuid,
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/delete`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/delete`,
timeout: 10000,
data: JSON.stringify({
items: [`${delPath}${delName}`]
@ -403,7 +403,7 @@ class ActionsClass {
'X-Access-Server': Pterodactyl.server.uuid,
},
contentType: 'application/json; charset=utf-8',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/delete`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/delete`,
timeout: 10000,
data: JSON.stringify({
items: selectedItems
@ -456,7 +456,7 @@ class ActionsClass {
$.ajax({
type: 'POST',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/decompress`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/decompress`,
headers: {
'X-Access-Token': Pterodactyl.server.daemonSecret,
'X-Access-Server': Pterodactyl.server.uuid,
@ -490,7 +490,7 @@ class ActionsClass {
$.ajax({
type: 'POST',
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/server/file/compress`,
url: `${Pterodactyl.node.scheme}://${Pterodactyl.node.fqdn}:${Pterodactyl.node.daemonListen}/v1/server/file/compress`,
headers: {
'X-Access-Token': Pterodactyl.server.daemonSecret,
'X-Access-Server': Pterodactyl.server.uuid,

View File

@ -19,7 +19,7 @@
// SOFTWARE.
(function initUploader() {
var notifyUploadSocketError = false;
uploadSocket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/upload/' + Pterodactyl.server.uuid, {
uploadSocket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/v1/upload/' + Pterodactyl.server.uuid, {
'query': 'token=' + Pterodactyl.server.daemonSecret,
});

View File

@ -53,7 +53,7 @@ var Server = (function () {
var notifySocketError = false;
window.Socket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/ws/' + Pterodactyl.server.uuid, {
window.Socket = io(Pterodactyl.node.scheme + '://' + Pterodactyl.node.fqdn + ':' + Pterodactyl.node.daemonListen + '/v1/ws/' + Pterodactyl.server.uuid, {
'query': 'token=' + Pterodactyl.server.daemonSecret,
});

View File

@ -130,7 +130,7 @@
(function getInformation() {
$.ajax({
method: 'GET',
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}',
url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/v1',
timeout: 5000,
headers: {
'X-Access-Token': '{{ $node->daemonSecret }}'

View File

@ -177,7 +177,7 @@
'X-Access-Token': '{{ $server->daemonSecret }}',
'X-Access-Server': '{{ $server->uuid }}'
},
url: '{{ $server->node->scheme }}://{{ $server->node->fqdn }}:{{ $server->node->daemonListen }}/server',
url: '{{ $server->node->scheme }}://{{ $server->node->fqdn }}:{{ $server->node->daemonListen }}/v1/server',
dataType: 'json',
timeout: 5000,
}).done(function (data) {

View File

@ -71,7 +71,7 @@ class DownloadControllerTest extends TestCase
$response = $this->controller->index('1234', '/my/file.txt');
$this->assertIsRedirectResponse($response);
$this->assertRedirectUrlEquals(sprintf(
'%s://%s:%s/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, 'randomString'
'%s://%s:%s/v1/server/file/download/%s', $server->node->scheme, $server->node->fqdn, $server->node->daemonListen, 'randomString'
), $response);
}
}