API model updates, as well as general model updates and code fixes.
This commit is contained in:
parent
8dc1f41b73
commit
32a1dc17ed
16 changed files with 162 additions and 272 deletions
|
@ -49,11 +49,12 @@ class LocationController extends BaseController
|
|||
*/
|
||||
public function lists(Request $request)
|
||||
{
|
||||
return Location::select('locations.*', DB::raw('GROUP_CONCAT(nodes.id) as nodes'))
|
||||
->join('nodes', 'locations.id', '=', 'nodes.location')
|
||||
->groupBy('locations.id')
|
||||
->get()->each(function ($location) {
|
||||
$location->nodes = explode(',', $location->nodes);
|
||||
})->all();
|
||||
return Location::with('nodes')->get()->map(function ($item) {
|
||||
$item->nodes->transform(function ($item) {
|
||||
return collect($item)->only(['id', 'name', 'fqdn', 'scheme', 'daemonListen', 'daemonSFTP']);
|
||||
});
|
||||
|
||||
return $item;
|
||||
})->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
namespace Pterodactyl\Http\Controllers\API;
|
||||
|
||||
use Log;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
use Dingo\Api\Exception\ResourceException;
|
||||
|
@ -96,15 +97,21 @@ class NodeController extends BaseController
|
|||
public function create(Request $request)
|
||||
{
|
||||
try {
|
||||
$node = new NodeRepository;
|
||||
$new = $node->create($request->all());
|
||||
$repo = new NodeRepository;
|
||||
$node = $repo->create($request->only([
|
||||
'name', 'location_id', 'public', 'fqdn',
|
||||
'scheme', 'memory', 'memory_overallocate',
|
||||
'disk', 'disk_overallocate', 'daemonBase',
|
||||
'daemonSFTP', 'daemonListen',
|
||||
]));
|
||||
|
||||
return ['id' => $new];
|
||||
return ['id' => $repo->id];
|
||||
} catch (DisplayValidationException $ex) {
|
||||
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
|
||||
} catch (DisplayException $ex) {
|
||||
throw new ResourceException($ex->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
throw new BadRequestHttpException('There was an error while attempting to add this node to the system.');
|
||||
}
|
||||
}
|
||||
|
@ -124,88 +131,35 @@ class NodeController extends BaseController
|
|||
*/
|
||||
public function view(Request $request, $id, $fields = null)
|
||||
{
|
||||
$node = Models\Node::where('id', $id);
|
||||
$node = Models\Node::with('allocations')->where('id', $id)->first();
|
||||
if (! $node) {
|
||||
throw new NotFoundHttpException('No node by that ID was found.');
|
||||
}
|
||||
|
||||
$node->allocations->transform(function ($item) {
|
||||
return collect($item)->only([
|
||||
'id', 'ip', 'ip_alias', 'port', 'server_id'
|
||||
]);
|
||||
});
|
||||
|
||||
if (! is_null($request->input('fields'))) {
|
||||
foreach (explode(',', $request->input('fields')) as $field) {
|
||||
if (! empty($field)) {
|
||||
$node->addSelect($field);
|
||||
}
|
||||
$fields = explode(',', $request->input('fields'));
|
||||
if (! empty($fields) && is_array($fields)) {
|
||||
return collect($node)->only($fields);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (! $node->first()) {
|
||||
throw new NotFoundHttpException('No node by that ID was found.');
|
||||
}
|
||||
|
||||
return [
|
||||
'node' => $node->first(),
|
||||
'allocations' => [
|
||||
'assigned' => Models\Allocation::where('node', $id)->whereNotNull('assigned_to')->get(),
|
||||
'unassigned' => Models\Allocation::where('node', $id)->whereNull('assigned_to')->get(),
|
||||
],
|
||||
];
|
||||
} catch (NotFoundHttpException $ex) {
|
||||
throw $ex;
|
||||
} catch (\Exception $ex) {
|
||||
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function config(Request $request, $id)
|
||||
{
|
||||
if (! $request->secure()) {
|
||||
throw new BadRequestHttpException('This API route can only be accessed using a secure connection.');
|
||||
}
|
||||
|
||||
$node = Models\Node::where('id', $id)->first();
|
||||
if (! $node) {
|
||||
throw new NotFoundHttpException('No node by that ID was found.');
|
||||
}
|
||||
|
||||
return [
|
||||
'web' => [
|
||||
'listen' => $node->daemonListen,
|
||||
'host' => '0.0.0.0',
|
||||
'ssl' => [
|
||||
'enabled' => ($node->scheme === 'https'),
|
||||
'certificate' => '/etc/certs/' . $node->fqdn . '/fullchain.pem',
|
||||
'key' => '/etc/certs/' . $node->fqdn . '/privkey.pem',
|
||||
],
|
||||
],
|
||||
'docker' => [
|
||||
'socket' => '/var/run/docker.sock',
|
||||
'autoupdate_images' => true,
|
||||
],
|
||||
'sftp' => [
|
||||
'path' => $node->daemonBase,
|
||||
'port' => (int) $node->daemonSFTP,
|
||||
'container' => 'ptdl-sftp',
|
||||
],
|
||||
'query' => [
|
||||
'kill_on_fail' => true,
|
||||
'fail_limit' => 5,
|
||||
],
|
||||
'logger' => [
|
||||
'path' => 'logs/',
|
||||
'src' => false,
|
||||
'level' => 'info',
|
||||
'period' => '1d',
|
||||
'count' => 3,
|
||||
],
|
||||
'remote' => [
|
||||
'base' => config('app.url'),
|
||||
'download' => route('remote.download'),
|
||||
'installed' => route('remote.install'),
|
||||
],
|
||||
'uploads' => [
|
||||
'size_limit' => $node->upload_size,
|
||||
],
|
||||
'keys' => [
|
||||
$node->daemonSecret,
|
||||
],
|
||||
];
|
||||
return $node->getConfigurationAsJson();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -219,12 +173,7 @@ class NodeController extends BaseController
|
|||
*/
|
||||
public function allocations(Request $request)
|
||||
{
|
||||
$allocations = Models\Allocation::all();
|
||||
if ($allocations->count() < 1) {
|
||||
throw new NotFoundHttpException('No allocations have been created.');
|
||||
}
|
||||
|
||||
return $allocations;
|
||||
return Models\Allocation::all()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,18 +187,7 @@ class NodeController extends BaseController
|
|||
*/
|
||||
public function allocationsView(Request $request, $id)
|
||||
{
|
||||
$query = Models\Allocation::where('assigned_to', $id)->get();
|
||||
try {
|
||||
if (empty($query)) {
|
||||
throw new NotFoundHttpException('No allocations for that server were found.');
|
||||
}
|
||||
|
||||
return $query;
|
||||
} catch (NotFoundHttpException $ex) {
|
||||
throw $ex;
|
||||
} catch (\Exception $ex) {
|
||||
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
|
||||
}
|
||||
return Models\Allocation::where('assigned_to', $id)->get()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,10 +72,10 @@ class ServerController extends BaseController
|
|||
public function create(Request $request)
|
||||
{
|
||||
try {
|
||||
$server = new ServerRepository;
|
||||
$new = $server->create($request->all());
|
||||
$repo = new ServerRepository;
|
||||
$server = $repo->create($request->all());
|
||||
|
||||
return ['id' => $new];
|
||||
return ['id' => $server->id];
|
||||
} catch (DisplayValidationException $ex) {
|
||||
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
|
||||
} catch (DisplayException $ex) {
|
||||
|
@ -101,58 +101,38 @@ class ServerController extends BaseController
|
|||
*/
|
||||
public function view(Request $request, $id)
|
||||
{
|
||||
$query = Models\Server::where('id', $id);
|
||||
$server = Models\Server::with('node', 'allocations', 'pack')->where('id', $id)->first();
|
||||
if (! $server) {
|
||||
throw new NotFoundHttpException('No server by that ID was found.');
|
||||
}
|
||||
|
||||
if (! is_null($request->input('fields'))) {
|
||||
foreach (explode(',', $request->input('fields')) as $field) {
|
||||
if (! empty($field)) {
|
||||
$query->addSelect($field);
|
||||
}
|
||||
$fields = explode(',', $request->input('fields'));
|
||||
if (! empty($fields) && is_array($fields)) {
|
||||
return collect($server)->only($fields);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (! $query->first()) {
|
||||
throw new NotFoundHttpException('No server by that ID was found.');
|
||||
}
|
||||
if ($request->input('daemon') === 'true') {
|
||||
try {
|
||||
$response = $server->node->guzzleClient([
|
||||
'X-Access-Token' => $server->node->daemonSecret,
|
||||
])->request('GET', '/servers');
|
||||
|
||||
// Requested Daemon Stats
|
||||
$server = $query->with(
|
||||
'allocations',
|
||||
'pack'
|
||||
)->first();
|
||||
if ($request->input('daemon') === 'true') {
|
||||
$node = Models\Node::findOrFail($server->node_id);
|
||||
$client = Models\Node::guzzleRequest($node->id);
|
||||
|
||||
$response = $client->request('GET', '/servers', [
|
||||
'headers' => [
|
||||
'X-Access-Token' => $node->daemonSecret,
|
||||
],
|
||||
]);
|
||||
|
||||
// Only return the daemon token if the request is using HTTPS
|
||||
if ($request->secure()) {
|
||||
$server->daemon_token = $server->daemonSecret;
|
||||
}
|
||||
$server->daemon = json_decode($response->getBody())->{$server->uuid};
|
||||
|
||||
return $server->toArray();
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
// Couldn't hit the daemon, return what we have though.
|
||||
$server->daemon = [
|
||||
'error' => 'There was an error encountered while attempting to connect to the remote daemon.',
|
||||
];
|
||||
}
|
||||
|
||||
return $server->toArray();
|
||||
} catch (NotFoundHttpException $ex) {
|
||||
throw $ex;
|
||||
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||
// Couldn't hit the daemon, return what we have though.
|
||||
$server->daemon = [
|
||||
'error' => 'There was an error encountered while attempting to connect to the remote daemon.',
|
||||
];
|
||||
|
||||
return $server->toArray();
|
||||
} catch (\Exception $ex) {
|
||||
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
|
||||
}
|
||||
|
||||
$server->allocations->transform(function ($item) {
|
||||
return collect($item)->except(['created_at', 'updated_at']);
|
||||
});
|
||||
|
||||
return $server->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,7 +159,9 @@ class ServerController extends BaseController
|
|||
{
|
||||
try {
|
||||
$server = new ServerRepository;
|
||||
$server->updateDetails($id, $request->all());
|
||||
$server->updateDetails($id, $request->only([
|
||||
'owner', 'name', 'reset_token',
|
||||
]));
|
||||
|
||||
return Models\Server::findOrFail($id);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
|
@ -224,7 +206,10 @@ class ServerController extends BaseController
|
|||
{
|
||||
try {
|
||||
$server = new ServerRepository;
|
||||
$server->changeBuild($id, $request->all());
|
||||
$server->changeBuild($id, $request->only([
|
||||
'default', 'add_additional', 'remove_additional',
|
||||
'memory', 'swap', 'io', 'cpu', 'disk',
|
||||
]));
|
||||
|
||||
return Models\Server::findOrFail($id);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
|
|
|
@ -45,18 +45,11 @@ class ServiceController extends BaseController
|
|||
|
||||
public function view(Request $request, $id)
|
||||
{
|
||||
$service = Models\Service::find($id);
|
||||
$service = Models\Service::with('options.variables', 'options.packs')->find($id);
|
||||
if (! $service) {
|
||||
throw new NotFoundHttpException('No service by that ID was found.');
|
||||
}
|
||||
|
||||
return [
|
||||
'service' => $service,
|
||||
'options' => Models\ServiceOptions::select('id', 'name', 'description', 'tag', 'docker_image')
|
||||
->where('service_id', $service->id)
|
||||
->with('variables')
|
||||
->with('packs')
|
||||
->get(),
|
||||
];
|
||||
return $service->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,19 +32,16 @@ class InfoController extends BaseController
|
|||
{
|
||||
public function me(Request $request)
|
||||
{
|
||||
return $request->user()->serverAccessCollection()->map(function ($server) {
|
||||
return $request->user()->serverAccessCollection()->load('allocation', 'option')->map(function ($server) {
|
||||
return [
|
||||
'id' => $server->uuidShort,
|
||||
'uuid' => $server->uuid,
|
||||
'name' => $server->name,
|
||||
'node' => $server->node_idName,
|
||||
'ip' => [
|
||||
'set' => $server->ip,
|
||||
'alias' => $server->ip_alias,
|
||||
],
|
||||
'port' => $server->port,
|
||||
'service' => $server->a_serviceName,
|
||||
'option' => $server->a_serviceOptionName,
|
||||
'node' => $server->node->name,
|
||||
'ip' => $server->allocation->alias,
|
||||
'port' => $server->allocation->port,
|
||||
'service' => $server->service->name,
|
||||
'option' => $server->option->name,
|
||||
];
|
||||
})->all();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
namespace Pterodactyl\Http\Controllers\API\User;
|
||||
|
||||
use Log;
|
||||
use Auth;
|
||||
use Pterodactyl\Models;
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Http\Controllers\API\BaseController;
|
||||
|
@ -43,20 +42,14 @@ class ServerController extends BaseController
|
|||
$daemon = [
|
||||
'status' => $json->status,
|
||||
'stats' => $json->proc,
|
||||
'query' => $json->query,
|
||||
];
|
||||
} catch (\Exception $ex) {
|
||||
$daemon = [
|
||||
'error' => 'An error was encountered while trying to connect to the daemon to collece information. It might be offline.',
|
||||
'error' => 'An error was encountered while trying to connect to the daemon to collect information. It might be offline.',
|
||||
];
|
||||
Log::error($ex);
|
||||
}
|
||||
|
||||
foreach ($server->allocations as &$allocation) {
|
||||
$allocation->default = ($allocation->id === $server->allocation_id);
|
||||
unset($allocation->id);
|
||||
}
|
||||
|
||||
return [
|
||||
'uuidShort' => $server->uuidShort,
|
||||
'uuid' => $server->uuid,
|
||||
|
@ -70,12 +63,18 @@ class ServerController extends BaseController
|
|||
'cpu' => $server->cpu,
|
||||
'oom_disabled' => (bool) $server->oom_disabled,
|
||||
],
|
||||
'allocations' => $server->allocations,
|
||||
'allocations' => $server->allocations->map(function ($item) use ($server) {
|
||||
return [
|
||||
'ip' => $item->alias,
|
||||
'port' => $item->port,
|
||||
'default' => ($item->id === $server->allocation_id),
|
||||
];
|
||||
}),
|
||||
'sftp' => [
|
||||
'username' => (Auth::user()->can('view-sftp', $server)) ? $server->username : null,
|
||||
'username' => ($request->user()->can('view-sftp', $server)) ? $server->username : null,
|
||||
],
|
||||
'daemon' => [
|
||||
'token' => ($request->secure()) ? $server->daemonSecret : false,
|
||||
'token' => $server->daemonSecret,
|
||||
'response' => $daemon,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -75,31 +75,27 @@ class UserController extends BaseController
|
|||
*/
|
||||
public function view(Request $request, $id)
|
||||
{
|
||||
$query = Models\User::where((is_numeric($id) ? 'id' : 'email'), $id);
|
||||
$user = Models\User::with('servers')->where((is_numeric($id) ? 'id' : 'email'), $id)->first();
|
||||
if (! $user->first()) {
|
||||
throw new NotFoundHttpException('No user by that ID was found.');
|
||||
}
|
||||
|
||||
$user->servers->transform(function ($item) {
|
||||
return collect($item)->only([
|
||||
'id', 'node_id', 'uuidShort',
|
||||
'uuid', 'name', 'suspended',
|
||||
'owner_id',
|
||||
]);
|
||||
});
|
||||
|
||||
if (! is_null($request->input('fields'))) {
|
||||
foreach (explode(',', $request->input('fields')) as $field) {
|
||||
if (! empty($field)) {
|
||||
$query->addSelect($field);
|
||||
}
|
||||
$fields = explode(',', $request->input('fields'));
|
||||
if (! empty($fields) && is_array($fields)) {
|
||||
return collect($user)->only($fields);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (! $query->first()) {
|
||||
throw new NotFoundHttpException('No user by that ID was found.');
|
||||
}
|
||||
|
||||
$user = $query->first();
|
||||
$userArray = $user->toArray();
|
||||
$userArray['servers'] = Models\Server::select('id', 'uuid', 'node', 'suspended')->where('owner', $user->id)->get();
|
||||
|
||||
return $userArray;
|
||||
} catch (NotFoundHttpException $ex) {
|
||||
throw $ex;
|
||||
} catch (\Exception $ex) {
|
||||
throw new BadRequestHttpException('There was an issue with the fields passed in the request.');
|
||||
}
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,7 +119,9 @@ class UserController extends BaseController
|
|||
try {
|
||||
$user = new UserRepository;
|
||||
$create = $user->create($request->only([
|
||||
'email', 'username', 'name_first', 'name_last', 'password', 'root_admin', 'custom_id',
|
||||
'email', 'username', 'name_first',
|
||||
'name_last', 'password',
|
||||
'root_admin', 'custom_id',
|
||||
]));
|
||||
$create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'), $request->input('custom_id'));
|
||||
|
||||
|
@ -160,7 +158,9 @@ class UserController extends BaseController
|
|||
try {
|
||||
$user = new UserRepository;
|
||||
$user->update($id, $request->only([
|
||||
'username', 'email', 'name_first', 'name_last', 'password', 'root_admin', 'language',
|
||||
'username', 'email', 'name_first',
|
||||
'name_last', 'password',
|
||||
'root_admin', 'language',
|
||||
]));
|
||||
|
||||
return Models\User::findOrFail($id);
|
||||
|
|
|
@ -86,16 +86,9 @@ class ServersController extends Controller
|
|||
{
|
||||
try {
|
||||
$server = new ServerRepository;
|
||||
$response = $server->create($request->only([
|
||||
'owner', 'name', 'memory', 'swap',
|
||||
'node', 'ip', 'port', 'allocation',
|
||||
'cpu', 'disk', 'service',
|
||||
'option', 'location', 'pack',
|
||||
'startup', 'custom_image_name',
|
||||
'auto_deploy', 'custom_id',
|
||||
]));
|
||||
$response = $server->create($request->except('_token'));
|
||||
|
||||
return redirect()->route('admin.servers.view', ['id' => $response]);
|
||||
return redirect()->route('admin.servers.view', ['id' => $response->id]);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.servers.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
|
@ -188,7 +181,7 @@ class ServersController extends Controller
|
|||
], 500);
|
||||
}
|
||||
|
||||
$option = Models\ServiceOptions::with('variables', ['packs' => function ($query) {
|
||||
$option = Models\ServiceOptions::with('variables')->with(['packs' => function ($query) {
|
||||
$query->where('selectable', true);
|
||||
}])->findOrFail($request->input('option'));
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ class APISecretToken extends Authorization
|
|||
// Log the Route Access
|
||||
APILogService::log($request, null, true);
|
||||
|
||||
return Auth::loginUsingId($key->user);
|
||||
return Auth::loginUsingId($key->user_id);
|
||||
}
|
||||
|
||||
protected function _generateHMAC($body, $key)
|
||||
|
|
|
@ -66,28 +66,12 @@ class Node extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'uuidShort',
|
||||
'node_id',
|
||||
'name',
|
||||
'suspended',
|
||||
'owner_id',
|
||||
'memory',
|
||||
'swap',
|
||||
'disk',
|
||||
'io',
|
||||
'cpu',
|
||||
'oom_disabled',
|
||||
'allocation_id',
|
||||
'service_id',
|
||||
'option_id',
|
||||
'pack_id',
|
||||
'startup',
|
||||
'daemonSecret',
|
||||
'image',
|
||||
'username',
|
||||
'sftp_password',
|
||||
'installed',
|
||||
'public', 'name', 'location_id',
|
||||
'fqdn', 'scheme', 'memory',
|
||||
'memory_overallocate', 'disk',
|
||||
'disk_overallocate', 'upload_size',
|
||||
'daemonSecret', 'daemonBase',
|
||||
'daemonSFTP', 'daemonListen',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,8 +62,8 @@ class APIRepository
|
|||
|
||||
// Node Management Routes
|
||||
'nodes.list',
|
||||
'nodes.view',
|
||||
'nodes.create',
|
||||
'nodes.list',
|
||||
'nodes.allocations',
|
||||
'nodes.delete',
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class NodeRepository
|
|||
// Validate Fields
|
||||
$validator = Validator::make($data, [
|
||||
'name' => 'required|regex:/^([\w .-]{1,100})$/',
|
||||
'location' => 'required|numeric|min:1|exists:locations,id',
|
||||
'location_id' => 'required|numeric|min:1|exists:locations,id',
|
||||
'public' => 'required|numeric|between:0,1',
|
||||
'fqdn' => 'required|string|unique:nodes,fqdn',
|
||||
'scheme' => 'required|regex:/^(http(s)?)$/',
|
||||
|
@ -91,7 +91,7 @@ class NodeRepository
|
|||
// Validate Fields
|
||||
$validator = $validator = Validator::make($data, [
|
||||
'name' => 'regex:/^([\w .-]{1,100})$/',
|
||||
'location' => 'numeric|min:1|exists:locations,id',
|
||||
'location_id' => 'numeric|min:1|exists:locations,id',
|
||||
'public' => 'numeric|between:0,1',
|
||||
'fqdn' => 'string|unique:nodes,fqdn,' . $id,
|
||||
'scheme' => 'regex:/^(http(s)?)$/',
|
||||
|
@ -210,13 +210,13 @@ class NodeRepository
|
|||
|
||||
foreach ($portBlock as $assignPort) {
|
||||
$alloc = Models\Allocation::firstOrNew([
|
||||
'node' => $node->id,
|
||||
'node_id' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort,
|
||||
]);
|
||||
if (! $alloc->exists) {
|
||||
$alloc->fill([
|
||||
'node' => $node->id,
|
||||
'node_id' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $assignPort,
|
||||
'ip_alias' => $setAlias,
|
||||
|
@ -227,13 +227,13 @@ class NodeRepository
|
|||
}
|
||||
} else {
|
||||
$alloc = Models\Allocation::firstOrNew([
|
||||
'node' => $node->id,
|
||||
'node_id' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $port,
|
||||
]);
|
||||
if (! $alloc->exists) {
|
||||
$alloc->fill([
|
||||
'node' => $node->id,
|
||||
'node_id' => $node->id,
|
||||
'ip' => $ip,
|
||||
'port' => $port,
|
||||
'ip_alias' => $setAlias,
|
||||
|
@ -269,7 +269,7 @@ class NodeRepository
|
|||
]);
|
||||
|
||||
// Delete Allocations
|
||||
Models\Allocation::where('node', $node->id)->delete();
|
||||
Models\Allocation::where('node_id', $node->id)->delete();
|
||||
|
||||
// Delete configure tokens
|
||||
Models\NodeConfigurationToken::where('node', $node->id)->delete();
|
||||
|
|
|
@ -90,17 +90,17 @@ class ServerRepository
|
|||
'io' => 'required|numeric|min:10|max:1000',
|
||||
'cpu' => 'required|numeric|min:0',
|
||||
'disk' => 'required|numeric|min:0',
|
||||
'service' => 'required|numeric|min:1|exists:services,id',
|
||||
'option' => 'required|numeric|min:1|exists:service_options,id',
|
||||
'location' => 'required|numeric|min:1|exists:locations,id',
|
||||
'pack' => 'sometimes|nullable|numeric|min:0',
|
||||
'service_id' => 'required|numeric|min:1|exists:services,id',
|
||||
'option_id' => 'required|numeric|min:1|exists:service_options,id',
|
||||
'location_id' => 'required|numeric|min:1|exists:locations,id',
|
||||
'pack_id' => 'sometimes|nullable|numeric|min:0',
|
||||
'startup' => 'string',
|
||||
'custom_image_name' => 'required_if:use_custom_image,on',
|
||||
'auto_deploy' => 'sometimes|boolean',
|
||||
'custom_id' => 'sometimes|required|numeric|unique:servers,id',
|
||||
]);
|
||||
|
||||
$validator->sometimes('node', 'bail|required|numeric|min:1|exists:nodes,id', function ($input) {
|
||||
$validator->sometimes('node_id', 'bail|required|numeric|min:1|exists:nodes,id', function ($input) {
|
||||
return ! ($input->auto_deploy);
|
||||
});
|
||||
|
||||
|
@ -112,7 +112,7 @@ class ServerRepository
|
|||
return ! $input->auto_deploy && ! $input->allocation;
|
||||
});
|
||||
|
||||
$validator->sometimes('allocation', 'numeric|exists:allocations,id', function ($input) {
|
||||
$validator->sometimes('allocation_id', 'numeric|exists:allocations,id', function ($input) {
|
||||
return ! ($input->auto_deploy || ($input->port && $input->ip));
|
||||
});
|
||||
|
||||
|
@ -131,19 +131,19 @@ class ServerRepository
|
|||
if (isset($data['auto_deploy']) && in_array($data['auto_deploy'], [true, 1, '1'])) {
|
||||
// This is an auto-deployment situation
|
||||
// Ignore any other passed node data
|
||||
unset($data['node'], $data['ip'], $data['port'], $data['allocation']);
|
||||
unset($data['node_id'], $data['ip'], $data['port'], $data['allocation_id']);
|
||||
|
||||
$autoDeployed = true;
|
||||
$node = DeploymentService::smartRandomNode($data['memory'], $data['disk'], $data['location']);
|
||||
$node = DeploymentService::smartRandomNode($data['memory'], $data['disk'], $data['location_id']);
|
||||
$allocation = DeploymentService::randomAllocation($node->id);
|
||||
} else {
|
||||
$node = Models\Node::findOrFail($data['node']);
|
||||
$node = Models\Node::findOrFail($data['node_id']);
|
||||
}
|
||||
|
||||
// Verify IP & Port are a.) free and b.) assigned to the node.
|
||||
// We know the node exists because of 'exists:nodes,id' in the validation
|
||||
if (! $autoDeployed) {
|
||||
if (! isset($data['allocation'])) {
|
||||
if (! isset($data['allocation_id'])) {
|
||||
$allocation = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port'])->where('node', $data['node'])->whereNull('assigned_to')->first();
|
||||
} else {
|
||||
$allocation = Models\Allocation::where('id', $data['allocation'])->where('node', $data['node'])->whereNull('assigned_to')->first();
|
||||
|
@ -165,12 +165,12 @@ class ServerRepository
|
|||
}
|
||||
|
||||
// Validate the Pack
|
||||
if ($data['pack'] == 0) {
|
||||
$data['pack'] = null;
|
||||
if ($data['pack_id'] == 0) {
|
||||
$data['pack_id'] = null;
|
||||
}
|
||||
|
||||
if (! is_null($data['pack'])) {
|
||||
$pack = Models\ServicePack::where('id', $data['pack'])->where('option', $data['option'])->first();
|
||||
if (! is_null($data['pack_id'])) {
|
||||
$pack = Models\ServicePack::where('id', $data['pack_id'])->where('option', $data['option_id'])->first();
|
||||
if (! $pack) {
|
||||
throw new DisplayException('The requested service pack does not seem to exist for this combination.');
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ class ServerRepository
|
|||
$service = Models\Service::find($option->service_id);
|
||||
|
||||
// Check those Variables
|
||||
$variables = Models\ServiceVariables::where('option_id', $data['option'])->get();
|
||||
$variables = Models\ServiceVariables::where('option_id', $data['option_id'])->get();
|
||||
$variableList = [];
|
||||
if ($variables) {
|
||||
foreach ($variables as $variable) {
|
||||
|
@ -254,10 +254,10 @@ class ServerRepository
|
|||
$server->fill([
|
||||
'uuid' => $genUuid,
|
||||
'uuidShort' => $genShortUuid,
|
||||
'node' => $node->id,
|
||||
'node_id' => $node->id,
|
||||
'name' => $data['name'],
|
||||
'suspended' => 0,
|
||||
'owner' => $user->id,
|
||||
'owner_id' => $user->id,
|
||||
'memory' => $data['memory'],
|
||||
'swap' => $data['swap'],
|
||||
'disk' => $data['disk'],
|
||||
|
@ -265,9 +265,9 @@ class ServerRepository
|
|||
'cpu' => $data['cpu'],
|
||||
'oom_disabled' => (isset($data['oom_disabled'])) ? true : false,
|
||||
'allocation' => $allocation->id,
|
||||
'service' => $data['service'],
|
||||
'option' => $data['option'],
|
||||
'pack' => $data['pack'],
|
||||
'service_id' => $data['service_id'],
|
||||
'option_id' => $data['option_id'],
|
||||
'pack_id' => $data['pack_id'],
|
||||
'startup' => $data['startup'],
|
||||
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
|
||||
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
|
||||
|
@ -277,7 +277,7 @@ class ServerRepository
|
|||
$server->save();
|
||||
|
||||
// Mark Allocation in Use
|
||||
$allocation->assigned_to = $server->id;
|
||||
$allocation->server_id = $server->id;
|
||||
$allocation->save();
|
||||
|
||||
// Add Variables
|
||||
|
@ -329,7 +329,7 @@ class ServerRepository
|
|||
|
||||
DB::commit();
|
||||
|
||||
return $server->id;
|
||||
return $server;
|
||||
} catch (TransferException $ex) {
|
||||
DB::rollBack();
|
||||
throw new DisplayException('There was an error while attempting to connect to the daemon to add this server.', $ex);
|
||||
|
@ -782,8 +782,8 @@ class ServerRepository
|
|||
DB::beginTransaction();
|
||||
try {
|
||||
// Unassign Allocations
|
||||
Models\Allocation::where('assigned_to', $server->id)->update([
|
||||
'assigned_to' => null,
|
||||
Models\Allocation::where('server_id', $server->id)->update([
|
||||
'server_id' => null,
|
||||
]);
|
||||
|
||||
// Remove Variables
|
||||
|
|
|
@ -44,9 +44,9 @@
|
|||
<div class="form-group col-md-4">
|
||||
<label for="name" class="control-label">Location</label>
|
||||
<div>
|
||||
<select name="location" class="form-control">
|
||||
<select name="location_id" class="form-control">
|
||||
@foreach($locations as $location)
|
||||
<option value="{{ $location->id }}" {{ (old('location') === $location->id) ? 'checked' : '' }}>{{ $location->long }} ({{ $location->short }})</option>
|
||||
<option value="{{ $location->id }}" {{ (old('location_id') === $location->id) ? 'selected' : '' }}>{{ $location->long }} ({{ $location->short }})</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -138,9 +138,9 @@
|
|||
<div class="form-group col-md-4">
|
||||
<label for="name" class="control-label">Location</label>
|
||||
<div>
|
||||
<select name="location" class="form-control">
|
||||
<select name="location_id" class="form-control">
|
||||
@foreach($locations as $location)
|
||||
<option value="{{ $location->id }}" {{ (old('location', $node->location) === $location->id) ? 'checked' : '' }}>{{ $location->long }} ({{ $location->short }})</option>
|
||||
<option value="{{ $location->id }}" {{ (old('location_id', $node->location) === $location->id) ? 'selected' : '' }}>{{ $location->long }} ({{ $location->short }})</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<div class="form-group col-md-6">
|
||||
<label for="location" class="control-label">Server Location</label>
|
||||
<div>
|
||||
<select name="location" id="getLocation" class="form-control">
|
||||
<select name="location_id" id="getLocation" class="form-control">
|
||||
<option disabled selected> -- Select a Location</option>
|
||||
@foreach($locations as $location)
|
||||
<option value="{{ $location->id }}">{{ $location->long }} ({{ $location->short }})</option>
|
||||
|
@ -75,7 +75,7 @@
|
|||
<div class="form-group col-md-6 hidden" id="allocationNode">
|
||||
<label for="node" class="control-label">Server Node</label>
|
||||
<div>
|
||||
<select name="node" id="getNode" class="form-control">
|
||||
<select name="node_id" id="getNode" class="form-control">
|
||||
<option disabled selected> -- Select a Node</option>
|
||||
</select>
|
||||
<p class="text-muted"><small>The node which this server will be deployed to.</small></p>
|
||||
|
@ -181,9 +181,9 @@
|
|||
<div class="row">
|
||||
<div class="ajax_loading_box" style="display:none;"><i class="fa fa-refresh fa-spin ajax_loading_position"></i></div>
|
||||
<div class="form-group col-md-12">
|
||||
<label for="service" class="control-label">Service Type</label>
|
||||
<label for="service_id" class="control-label">Service Type</label>
|
||||
<div>
|
||||
<select name="service" id="getService" class="form-control">
|
||||
<select name="service_id" id="getService" class="form-control">
|
||||
<option disabled selected> -- Select a Service</option>
|
||||
@foreach($services as $service)
|
||||
<option value="{{ $service->id }}">{{ $service->name }}</option>
|
||||
|
@ -193,18 +193,18 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12 hidden">
|
||||
<label for="option" class="control-label">Service Option</label>
|
||||
<label for="option_id" class="control-label">Service Option</label>
|
||||
<div>
|
||||
<select name="option" id="getOption" class="form-control">
|
||||
<select name="option_id" id="getOption" class="form-control">
|
||||
<option disabled selected> -- Select a Service Option</option>
|
||||
</select>
|
||||
<p class="text-muted"><small>Select the type of service that this server will be running.</small></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12 hidden">
|
||||
<label for="option" class="control-label">Service Pack</label>
|
||||
<label for="pack_id" class="control-label">Service Pack</label>
|
||||
<div>
|
||||
<select name="pack" id="getPack" class="form-control">
|
||||
<select name="pack_id" id="getPack" class="form-control">
|
||||
<option disabled selected> -- Select a Service Pack</option>
|
||||
</select>
|
||||
<p class="text-muted"><small>Select the service pack that should be used for this server. This option can be changed later.</small></p>
|
||||
|
|
Loading…
Reference in a new issue