2017-07-20 01:49:41 +00:00
|
|
|
<?php
|
2017-09-26 02:43:01 +00:00
|
|
|
/**
|
2017-07-20 01:49:41 +00:00
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2017-07-20 01:49:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Daemon;
|
|
|
|
|
2017-08-27 19:55:25 +00:00
|
|
|
use Webmozart\Assert\Assert;
|
2017-08-05 22:26:30 +00:00
|
|
|
use Pterodactyl\Services\Servers\EnvironmentService;
|
2017-07-20 01:49:41 +00:00
|
|
|
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
|
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface as DatabaseServerRepositoryInterface;
|
|
|
|
|
|
|
|
class ServerRepository extends BaseRepository implements ServerRepositoryInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-08-26 23:08:11 +00:00
|
|
|
public function create($id, array $overrides = [], $start = false)
|
2017-07-20 01:49:41 +00:00
|
|
|
{
|
2017-08-26 23:08:11 +00:00
|
|
|
Assert::numeric($id, 'First argument passed to create must be numeric, received %s.');
|
|
|
|
Assert::boolean($start, 'Third argument passed to create must be boolean, received %s.');
|
|
|
|
|
2017-07-20 01:49:41 +00:00
|
|
|
$repository = $this->app->make(DatabaseServerRepositoryInterface::class);
|
|
|
|
$environment = $this->app->make(EnvironmentService::class);
|
|
|
|
|
|
|
|
$server = $repository->getDataForCreation($id);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'uuid' => (string) $server->uuid,
|
|
|
|
'user' => $server->username,
|
|
|
|
'build' => [
|
|
|
|
'default' => [
|
|
|
|
'ip' => $server->allocation->ip,
|
|
|
|
'port' => $server->allocation->port,
|
|
|
|
],
|
|
|
|
'ports' => $server->allocations->groupBy('ip')->map(function ($item) {
|
|
|
|
return $item->pluck('port');
|
|
|
|
})->toArray(),
|
|
|
|
'env' => $environment->process($server),
|
|
|
|
'memory' => (int) $server->memory,
|
|
|
|
'swap' => (int) $server->swap,
|
|
|
|
'io' => (int) $server->io,
|
|
|
|
'cpu' => (int) $server->cpu,
|
|
|
|
'disk' => (int) $server->disk,
|
2017-07-25 02:34:10 +00:00
|
|
|
'image' => $server->image,
|
2017-07-20 01:49:41 +00:00
|
|
|
],
|
|
|
|
'service' => [
|
|
|
|
'type' => $server->option->service->folder,
|
|
|
|
'option' => $server->option->tag,
|
|
|
|
'pack' => object_get($server, 'pack.uuid'),
|
|
|
|
'skip_scripts' => $server->skip_scripts,
|
|
|
|
],
|
|
|
|
'rebuild' => false,
|
|
|
|
'start_on_completion' => $start,
|
|
|
|
];
|
|
|
|
|
|
|
|
// Loop through overrides.
|
|
|
|
foreach ($overrides as $key => $value) {
|
|
|
|
array_set($data, $key, $value);
|
|
|
|
}
|
|
|
|
|
2017-07-22 02:17:42 +00:00
|
|
|
return $this->getHttpClient()->request('POST', '/servers', [
|
|
|
|
'json' => $data,
|
|
|
|
]);
|
2017-07-20 01:49:41 +00:00
|
|
|
}
|
2017-07-23 01:15:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function update(array $data)
|
|
|
|
{
|
|
|
|
return $this->getHttpClient()->request('PATCH', '/server', [
|
|
|
|
'json' => $data,
|
|
|
|
]);
|
|
|
|
}
|
2017-07-23 19:51:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2017-07-25 02:34:10 +00:00
|
|
|
public function reinstall($data = null)
|
2017-07-23 19:51:18 +00:00
|
|
|
{
|
2017-08-26 23:08:11 +00:00
|
|
|
Assert::nullOrIsArray($data, 'First argument passed to reinstall must be null or an array, received %s.');
|
|
|
|
|
2017-07-25 02:34:10 +00:00
|
|
|
if (is_null($data)) {
|
|
|
|
return $this->getHttpClient()->request('POST', '/server/reinstall');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getHttpClient()->request('POST', '/server/reinstall', [
|
|
|
|
'json' => $data,
|
|
|
|
]);
|
2017-07-23 19:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function rebuild()
|
|
|
|
{
|
|
|
|
return $this->getHttpClient()->request('POST', '/server/rebuild');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function suspend()
|
|
|
|
{
|
|
|
|
return $this->getHttpClient()->request('POST', '/server/suspend');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function unsuspend()
|
|
|
|
{
|
|
|
|
return $this->getHttpClient()->request('POST', '/server/unsuspend');
|
|
|
|
}
|
2017-07-25 02:34:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
return $this->getHttpClient()->request('DELETE', '/servers');
|
|
|
|
}
|
2017-08-31 02:11:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function details()
|
|
|
|
{
|
|
|
|
return $this->getHttpClient()->request('GET', '/servers');
|
|
|
|
}
|
2017-09-25 02:12:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function revokeAccessKey($key)
|
|
|
|
{
|
|
|
|
Assert::stringNotEmpty($key, 'First argument passed to revokeAccessKey must be a non-empty string, received %s.');
|
|
|
|
|
|
|
|
return $this->getHttpClient()->request('DELETE', '/keys/' . $key);
|
|
|
|
}
|
2017-07-20 01:49:41 +00:00
|
|
|
}
|