Refactor how repositories for the daemon work.

This commit is contained in:
Dane Everitt 2018-01-05 18:27:47 -06:00
parent 5f9fe4a69b
commit d2afc29a80
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
58 changed files with 388 additions and 997 deletions

View file

@ -1,149 +1,152 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Daemon;
use RuntimeException;
use GuzzleHttp\Client;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Server;
use Illuminate\Foundation\Application;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Contracts\Repository\Daemon\BaseRepositoryInterface;
class BaseRepository implements BaseRepositoryInterface
abstract class BaseRepository implements BaseRepositoryInterface
{
/**
* @var \Illuminate\Foundation\Application
*/
protected $app;
private $app;
/**
* @var
* @var \Pterodactyl\Models\Server
*/
protected $accessServer;
private $server;
/**
* @var
* @var string|null
*/
protected $accessToken;
private $token;
/**
* @var
* @var \Pterodactyl\Models\Node
*/
protected $node;
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
private $node;
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
*/
protected $nodeRepository;
private $nodeRepository;
/**
* BaseRepository constructor.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $nodeRepository
*/
public function __construct(
Application $app,
ConfigRepository $config,
NodeRepositoryInterface $nodeRepository
) {
public function __construct(Application $app, NodeRepositoryInterface $nodeRepository)
{
$this->app = $app;
$this->config = $config;
$this->nodeRepository = $nodeRepository;
}
/**
* {@inheritdoc}
* Set the node model to be used for this daemon connection.
*
* @param \Pterodactyl\Models\Node $node
* @return $this
*/
public function setNode($id)
public function setNode(Node $node)
{
Assert::numeric($id, 'The first argument passed to setNode must be numeric, received %s.');
$this->node = $this->nodeRepository->find($id);
$this->node = $node;
return $this;
}
/**
* {@inheritdoc}
* Return the node model being used.
*
* @return \Pterodactyl\Models\Node
*/
public function getNode()
public function getNode(): Node
{
return $this->node;
}
/**
* {@inheritdoc}
* Set the Server model to use when requesting information from the Daemon.
*
* @param \Pterodactyl\Models\Server $server
* @return $this
*/
public function setAccessServer($server = null)
public function setServer(Server $server)
{
Assert::nullOrString($server, 'The first argument passed to setAccessServer must be null or a string, received %s.');
$this->accessServer = $server;
$this->server = $server;
return $this;
}
/**
* {@inheritdoc}
* Return the Server model.
*
* @return \Pterodactyl\Models\Server|null
*/
public function getAccessServer()
public function getServer()
{
return $this->accessServer;
return $this->server;
}
/**
* {@inheritdoc}
* Set the token to be used in the X-Access-Token header for requests to the daemon.
*
* @param string $token
* @return $this
*/
public function setAccessToken($token = null)
public function setToken(string $token)
{
Assert::nullOrString($token, 'The first argument passed to setAccessToken must be null or a string, received %s.');
$this->accessToken = $token;
$this->token = $token;
return $this;
}
/**
* {@inheritdoc}
* Return the access token being used for requests.
*
* @return string|null
*/
public function getAccessToken()
public function getToken()
{
return $this->accessToken;
return $this->token;
}
/**
* {@inheritdoc}
* Return an instance of the Guzzle HTTP Client to be used for requests.
*
* @param array $headers
* @return \GuzzleHttp\Client
*/
public function getHttpClient(array $headers = [])
public function getHttpClient(array $headers = []): Client
{
if (! is_null($this->accessServer)) {
$headers['X-Access-Server'] = $this->getAccessServer();
// If no node is set, load the relationship onto the Server model
// and pass that to the setNode function.
if (! $this->getNode() instanceof Node) {
if (! $this->getServer() instanceof Server) {
throw new RuntimeException('An instance of ' . Node::class . ' or ' . Server::class . ' must be set on this repository in order to return a client.');
}
$this->getServer()->loadMissing('node');
$this->setNode($this->getServer()->getRelation('node'));
}
if (! is_null($this->accessToken)) {
$headers['X-Access-Token'] = $this->getAccessToken();
} elseif (! is_null($this->node)) {
$headers['X-Access-Token'] = $this->getNode()->daemonSecret;
if ($this->getServer() instanceof Server) {
$headers['X-Access-Server'] = $this->getServer()->uuid;
}
$headers['X-Access-Token'] = $this->getToken() ?? $this->getNode()->daemonSecret;
return new Client([
'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'),
'timeout' => config('pterodactyl.guzzle.timeout'),
'connect_timeout' => config('pterodactyl.guzzle.connect_timeout'),
'headers' => $headers,
]);
}

View file

@ -1,26 +1,21 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Daemon;
use Webmozart\Assert\Assert;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface;
class CommandRepository extends BaseRepository implements CommandRepositoryInterface
{
/**
* {@inheritdoc}
* Send a command to a server.
*
* @param string $command
* @return \Psr\Http\Message\ResponseInterface
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function send($command)
public function send(string $command): ResponseInterface
{
Assert::stringNotEmpty($command, 'First argument passed to send must be a non-empty string, received %s.');
return $this->getHttpClient()->request('POST', 'server/command', [
'json' => [
'command' => $command,

View file

@ -1,22 +1,19 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Daemon;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
class ConfigurationRepository extends BaseRepository implements ConfigurationRepositoryInterface
{
/**
* {@inheritdoc}
* Update the configuration details for the specified node using data from the database.
*
* @param array $overrides
* @return \Psr\Http\Message\ResponseInterface
*/
public function update(array $overrides = [])
public function update(array $overrides = []): ResponseInterface
{
$node = $this->getNode();
$structure = [

View file

@ -1,23 +1,23 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Daemon;
use Webmozart\Assert\Assert;
use stdClass;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
class FileRepository extends BaseRepository implements FileRepositoryInterface
{
public function getFileStat($path)
/**
* Return stat information for a given file.
*
* @param string $path
* @return \stdClass
*
* @throws \GuzzleHttp\Exception\RequestException
*/
public function getFileStat(string $path): stdClass
{
Assert::stringNotEmpty($path, 'First argument passed to getStat must be a non-empty string, received %s.');
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
@ -30,12 +30,15 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
}
/**
* {@inheritdoc}
* Return the contents of a given file if it can be edited in the Panel.
*
* @param string $path
* @return \stdClass
*
* @throws \GuzzleHttp\Exception\RequestException
*/
public function getContent($path)
public function getContent(string $path): stdClass
{
Assert::stringNotEmpty($path, 'First argument passed to getContent must be a non-empty string, received %s.');
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
@ -48,13 +51,16 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
}
/**
* {@inheritdoc}
* Save new contents to a given file.
*
* @param string $path
* @param string $content
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \GuzzleHttp\Exception\RequestException
*/
public function putContent($path, $content)
public function putContent(string $path, string $content): ResponseInterface
{
Assert::stringNotEmpty($path, 'First argument passed to putContent must be a non-empty string, received %s.');
Assert::string($content, 'Second argument passed to putContent must be a string, received %s.');
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
@ -67,20 +73,19 @@ class FileRepository extends BaseRepository implements FileRepositoryInterface
}
/**
* {@inheritdoc}
* Return a directory listing for a given path.
*
* @param string $path
* @return array
*
* @throws \GuzzleHttp\Exception\RequestException
*/
public function getDirectory($path)
public function getDirectory(string $path): array
{
Assert::string($path, 'First argument passed to getDirectory must be a string, received %s.');
$response = $this->getHttpClient()->request('GET', sprintf(
'server/directory/%s',
rawurlencode($path)
));
$response = $this->getHttpClient()->request('GET', sprintf('server/directory/%s', rawurlencode($path)));
$contents = json_decode($response->getBody());
$files = [];
$folders = [];
$files = $folders = [];
foreach ($contents as $value) {
if ($value->directory) {

View file

@ -1,27 +1,23 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Daemon;
use Webmozart\Assert\Assert;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface;
use Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException;
class PowerRepository extends BaseRepository implements PowerRepositoryInterface
{
/**
* {@inheritdoc}
* Send a power signal to a server.
*
* @param string $signal
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException
*/
public function sendSignal($signal)
public function sendSignal(string $signal): ResponseInterface
{
Assert::stringNotEmpty($signal, 'The first argument passed to sendSignal must be a non-empty string, received %s.');
switch ($signal) {
case self::SIGNAL_START:
case self::SIGNAL_STOP:
@ -32,9 +28,8 @@ class PowerRepository extends BaseRepository implements PowerRepositoryInterface
'action' => $signal,
],
]);
break;
default:
throw new InvalidPowerSignalException('The signal ' . $signal . ' is not defined and could not be processed.');
throw new InvalidPowerSignalException('The signal "' . $signal . '" is not defined and could not be processed.');
}
}
}

View file

@ -19,9 +19,8 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
*/
public function create(array $structure, array $overrides = []): ResponseInterface
{
// Loop through overrides.
foreach ($overrides as $key => $value) {
array_set($structure, $key, $value);
$structure[$key] = value($value);
}
return $this->getHttpClient()->request('POST', 'servers', [
@ -30,9 +29,12 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
}
/**
* {@inheritdoc}
* Update server details on the daemon.
*
* @param array $data
* @return \Psr\Http\Message\ResponseInterface
*/
public function update(array $data)
public function update(array $data): ResponseInterface
{
return $this->getHttpClient()->request('PATCH', 'server', [
'json' => $data,
@ -40,65 +42,77 @@ class ServerRepository extends BaseRepository implements ServerRepositoryInterfa
}
/**
* {@inheritdoc}
* Mark a server to be reinstalled on the system.
*
* @param array|null $data
* @return \Psr\Http\Message\ResponseInterface
*/
public function reinstall($data = null)
public function reinstall(array $data = null): ResponseInterface
{
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', [
'json' => $data,
'json' => $data ?? [],
]);
}
/**
* {@inheritdoc}
* Mark a server as needing a container rebuild the next time the server is booted.
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function rebuild()
public function rebuild(): ResponseInterface
{
return $this->getHttpClient()->request('POST', 'server/rebuild');
}
/**
* {@inheritdoc}
* Suspend a server on the daemon.
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function suspend()
public function suspend(): ResponseInterface
{
return $this->getHttpClient()->request('POST', 'server/suspend');
}
/**
* {@inheritdoc}
* Un-suspend a server on the daemon.
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function unsuspend()
public function unsuspend(): ResponseInterface
{
return $this->getHttpClient()->request('POST', 'server/unsuspend');
}
/**
* {@inheritdoc}
* Delete a server on the daemon.
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function delete()
public function delete(): ResponseInterface
{
return $this->getHttpClient()->request('DELETE', 'servers');
}
/**
* {@inheritdoc}
* Return detials on a specific server.
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function details()
public function details(): ResponseInterface
{
return $this->getHttpClient()->request('GET', 'server');
}
/**
* {@inheritdoc}
* Revoke an access key on the daemon before the time is expired.
*
* @param string|array $key
* @return \Psr\Http\Message\ResponseInterface
*
* @throws \GuzzleHttp\Exception\RequestException
*/
public function revokeAccessKey($key)
public function revokeAccessKey($key): ResponseInterface
{
if (is_array($key)) {
return $this->getHttpClient()->request('POST', 'keys', [

View file

@ -70,7 +70,7 @@ class DaemonKeyRepository extends EloquentRepository implements DaemonKeyReposit
*/
public function getKeysForRevocation(User $user): Collection
{
return $this->getBuilder()->with('server:id,uuid,node_id')->where('user_id', $user->id)->get($this->getColumns());
return $this->getBuilder()->with('node')->where('user_id', $user->id)->get($this->getColumns());
}
/**

View file

@ -30,7 +30,7 @@ class UserRepository extends EloquentRepository implements UserRepositoryInterfa
public function getAllUsersWithCounts(): LengthAwarePaginator
{
return $this->getBuilder()->withCount('servers', 'subuserOf')
->setSearchTerm($this->getSearchTerm())
->search($this->getSearchTerm())
->paginate(50, $this->getColumns());
}

View file

@ -1,146 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Wings;
use GuzzleHttp\Client;
use Webmozart\Assert\Assert;
use Illuminate\Foundation\Application;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Pterodactyl\Contracts\Repository\Daemon\BaseRepositoryInterface;
class BaseRepository implements BaseRepositoryInterface
{
/**
* @var \Illuminate\Foundation\Application
*/
protected $app;
/**
* @var
*/
protected $accessServer;
/**
* @var
*/
protected $accessToken;
/**
* @var
*/
protected $node;
/**
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
*/
protected $nodeRepository;
/**
* BaseRepository constructor.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $nodeRepository
*/
public function __construct(
Application $app,
ConfigRepository $config,
NodeRepositoryInterface $nodeRepository
) {
$this->app = $app;
$this->config = $config;
$this->nodeRepository = $nodeRepository;
}
/**
* {@inheritdoc}
*/
public function setNode($id)
{
Assert::numeric($id, 'The first argument passed to setNode must be numeric, received %s.');
$this->node = $this->nodeRepository->find($id);
return $this;
}
/**
* {@inheritdoc}
*/
public function getNode()
{
return $this->node;
}
/**
* {@inheritdoc}
*/
public function setAccessServer($server = null)
{
Assert::nullOrString($server, 'The first argument passed to setAccessServer must be null or a string, received %s.');
$this->accessServer = $server;
return $this;
}
/**
* {@inheritdoc}
*/
public function getAccessServer()
{
return $this->accessServer;
}
/**
* {@inheritdoc}
*/
public function setAccessToken($token = null)
{
Assert::nullOrString($token, 'The first argument passed to setAccessToken must be null or a string, received %s.');
$this->accessToken = $token;
return $this;
}
/**
* {@inheritdoc}
*/
public function getAccessToken()
{
return $this->accessToken;
}
/**
* {@inheritdoc}
*/
public function getHttpClient(array $headers = [])
{
if (! is_null($this->accessToken)) {
$headers['Authorization'] = 'Bearer ' . $this->getAccessToken();
} elseif (! is_null($this->node)) {
$headers['Authorization'] = 'Bearer ' . $this->getNode()->daemonSecret;
}
return new Client([
'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

@ -1,30 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Wings;
use Webmozart\Assert\Assert;
use Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface;
class CommandRepository extends BaseRepository implements CommandRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function send($command)
{
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', [
'json' => [
'command' => $command,
],
]);
}
}

View file

@ -1,24 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Wings;
use Pterodactyl\Exceptions\PterodactylException;
use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
class ConfigurationRepository extends BaseRepository implements ConfigurationRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function update(array $overrides = [])
{
throw new PterodactylException('This has not yet been configured.');
}
}

View file

@ -1,114 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Wings;
use Webmozart\Assert\Assert;
use Pterodactyl\Contracts\Repository\Daemon\FileRepositoryInterface;
class FileRepository extends BaseRepository implements FileRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function getFileStat($path)
{
Assert::stringNotEmpty($path, 'First argument passed to getStat must be a non-empty string, received %s.');
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'server/' . $this->getAccessServer() . '/file/stat/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
return json_decode($response->getBody());
}
/**
* {@inheritdoc}
*/
public function getContent($path)
{
Assert::stringNotEmpty($path, 'First argument passed to getContent must be a non-empty string, received %s.');
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
$response = $this->getHttpClient()->request('GET', sprintf(
'server/' . $this->getAccessServer() . '/file/f/%s',
rawurlencode($file['dirname'] . $file['basename'])
));
return object_get(json_decode($response->getBody()), 'content');
}
/**
* {@inheritdoc}
*/
public function putContent($path, $content)
{
Assert::stringNotEmpty($path, 'First argument passed to putContent must be a non-empty string, received %s.');
Assert::string($content, 'Second argument passed to putContent must be a string, received %s.');
$file = pathinfo($path);
$file['dirname'] = in_array($file['dirname'], ['.', './', '/']) ? null : trim($file['dirname'], '/') . '/';
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/file/save', [
'json' => [
'path' => rawurlencode($file['dirname'] . $file['basename']),
'content' => $content,
],
]);
}
/**
* {@inheritdoc}
*/
public function getDirectory($path)
{
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',
rawurlencode($path)
));
$contents = json_decode($response->getBody());
$files = [];
$folders = [];
foreach ($contents as $value) {
if ($value->directory) {
array_push($folders, [
'entry' => $value->name,
'directory' => trim($path, '/'),
'size' => null,
'date' => strtotime($value->modified),
'mime' => $value->mime,
]);
} elseif ($value->file) {
array_push($files, [
'entry' => $value->name,
'directory' => trim($path, '/'),
'extension' => pathinfo($value->name, PATHINFO_EXTENSION),
'size' => human_readable($value->size),
'date' => strtotime($value->modified),
'mime' => $value->mime,
]);
}
}
return [
'files' => $files,
'folders' => $folders,
];
}
}

View file

@ -1,40 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Wings;
use Webmozart\Assert\Assert;
use Pterodactyl\Contracts\Repository\Daemon\PowerRepositoryInterface;
use Pterodactyl\Exceptions\Repository\Daemon\InvalidPowerSignalException;
class PowerRepository extends BaseRepository implements PowerRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function sendSignal($signal)
{
Assert::stringNotEmpty($signal, 'The first argument passed to sendSignal must be a non-empty string, received %s.');
switch ($signal) {
case self::SIGNAL_START:
case self::SIGNAL_STOP:
case self::SIGNAL_RESTART:
case self::SIGNAL_KILL:
return $this->getHttpClient()->request('PUT', 'server/' . $this->getAccessServer() . '/power', [
'json' => [
'action' => $signal,
],
]);
break;
default:
throw new InvalidPowerSignalException('The signal ' . $signal . ' is not defined and could not be processed.');
}
}
}

View file

@ -1,89 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
namespace Pterodactyl\Repositories\Wings;
use Psr\Http\Message\ResponseInterface;
use Pterodactyl\Exceptions\PterodactylException;
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
class ServerRepository extends BaseRepository implements ServerRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function create(array $structure, array $overrides = []): ResponseInterface
{
throw new PterodactylException('This feature is not yet implemented.');
}
/**
* {@inheritdoc}
*/
public function update(array $data)
{
throw new PterodactylException('This feature is not yet implemented.');
}
/**
* {@inheritdoc}
*/
public function reinstall($data = null)
{
throw new PterodactylException('This feature is not yet implemented.');
}
/**
* {@inheritdoc}
*/
public function rebuild()
{
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/rebuild');
}
/**
* {@inheritdoc}
*/
public function suspend()
{
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/suspend');
}
/**
* {@inheritdoc}
*/
public function unsuspend()
{
return $this->getHttpClient()->request('POST', 'server/' . $this->getAccessServer() . '/unsuspend');
}
/**
* {@inheritdoc}
*/
public function delete()
{
return $this->getHttpClient()->request('DELETE', 'server/' . $this->getAccessServer());
}
/**
* {@inheritdoc}
*/
public function details()
{
return $this->getHttpClient()->request('GET', 'server/' . $this->getAccessServer());
}
/**
* {@inheritdoc}
*/
public function revokeAccessKey($key)
{
throw new PterodactylException('This feature is not yet implemented.');
}
}