diff --git a/app/Http/Controllers/API/LocationController.php b/app/Http/Controllers/API/LocationController.php index 3bae975d8..94ec5fe7d 100755 --- a/app/Http/Controllers/API/LocationController.php +++ b/app/Http/Controllers/API/LocationController.php @@ -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(); } } diff --git a/app/Http/Controllers/API/NodeController.php b/app/Http/Controllers/API/NodeController.php index 0eda949f4..fd87770f7 100755 --- a/app/Http/Controllers/API/NodeController.php +++ b/app/Http/Controllers/API/NodeController.php @@ -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(); } /** diff --git a/app/Http/Controllers/API/ServerController.php b/app/Http/Controllers/API/ServerController.php index 24a2bc00e..e6b2add2c 100755 --- a/app/Http/Controllers/API/ServerController.php +++ b/app/Http/Controllers/API/ServerController.php @@ -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) { diff --git a/app/Http/Controllers/API/ServiceController.php b/app/Http/Controllers/API/ServiceController.php index 81d5a955d..b1c600e27 100755 --- a/app/Http/Controllers/API/ServiceController.php +++ b/app/Http/Controllers/API/ServiceController.php @@ -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(); } } diff --git a/app/Http/Controllers/API/User/InfoController.php b/app/Http/Controllers/API/User/InfoController.php index 844e493dc..6ef84ce50 100644 --- a/app/Http/Controllers/API/User/InfoController.php +++ b/app/Http/Controllers/API/User/InfoController.php @@ -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(); } diff --git a/app/Http/Controllers/API/User/ServerController.php b/app/Http/Controllers/API/User/ServerController.php index c6091f0b1..465c7a345 100644 --- a/app/Http/Controllers/API/User/ServerController.php +++ b/app/Http/Controllers/API/User/ServerController.php @@ -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, ], ]; diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php index a330ef61c..14c212f77 100755 --- a/app/Http/Controllers/API/UserController.php +++ b/app/Http/Controllers/API/UserController.php @@ -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); diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index b68f8d01c..ab73937c4 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -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')); diff --git a/app/Http/Middleware/APISecretToken.php b/app/Http/Middleware/APISecretToken.php index a1c203c9d..25bf891ba 100755 --- a/app/Http/Middleware/APISecretToken.php +++ b/app/Http/Middleware/APISecretToken.php @@ -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) diff --git a/app/Models/Node.php b/app/Models/Node.php index 3da24531c..78e0828f7 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -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', ]; /** diff --git a/app/Repositories/APIRepository.php b/app/Repositories/APIRepository.php index 14348b2db..71fbb88b5 100644 --- a/app/Repositories/APIRepository.php +++ b/app/Repositories/APIRepository.php @@ -62,8 +62,8 @@ class APIRepository // Node Management Routes 'nodes.list', + 'nodes.view', 'nodes.create', - 'nodes.list', 'nodes.allocations', 'nodes.delete', diff --git a/app/Repositories/NodeRepository.php b/app/Repositories/NodeRepository.php index e409a011a..1af316b23 100644 --- a/app/Repositories/NodeRepository.php +++ b/app/Repositories/NodeRepository.php @@ -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(); diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 13caf0a5c..6e441666a 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -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 diff --git a/resources/views/admin/nodes/new.blade.php b/resources/views/admin/nodes/new.blade.php index 07227daa7..37add9812 100644 --- a/resources/views/admin/nodes/new.blade.php +++ b/resources/views/admin/nodes/new.blade.php @@ -44,9 +44,9 @@
- @foreach($locations as $location) - + @endforeach
diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index 5fa054703..9b569d5c8 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -138,9 +138,9 @@
- @foreach($locations as $location) - + @endforeach
diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index 2c3d655a2..2fe12b1dd 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -63,7 +63,7 @@
- @foreach($locations as $location) @@ -75,7 +75,7 @@