From 4f61637284ed74c15969e945c73f73dc03b8ed4e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 9 Feb 2017 17:43:54 -0500 Subject: [PATCH] More model updates to more places than I anticipated. This probably broke a lot of things. --- .../Controllers/Admin/LocationsController.php | 2 +- .../Controllers/Admin/ServersController.php | 174 ++++----------- app/Http/Controllers/Admin/UserController.php | 41 +--- .../Controllers/Server/SubuserController.php | 6 +- app/Models/Allocation.php | 11 + app/Models/DatabaseServer.php | 10 + app/Models/Node.php | 1 + app/Models/Server.php | 10 + app/Models/ServerVariables.php | 10 + app/Models/ServiceOptions.php | 22 ++ app/Models/Subuser.php | 20 ++ app/Models/User.php | 30 ++- app/Repositories/DatabaseRepository.php | 56 +++-- app/Repositories/LocationRepository.php | 11 +- app/Repositories/NodeRepository.php | 11 +- app/Repositories/ServerRepository.php | 202 +++++++----------- app/Repositories/SubuserRepository.php | 77 +++---- app/Repositories/UserRepository.php | 2 +- resources/views/admin/servers/index.blade.php | 6 +- resources/views/admin/servers/view.blade.php | 54 ++--- resources/views/admin/users/view.blade.php | 16 +- 21 files changed, 339 insertions(+), 433 deletions(-) diff --git a/app/Http/Controllers/Admin/LocationsController.php b/app/Http/Controllers/Admin/LocationsController.php index 93a45fb66..d74f05d18 100644 --- a/app/Http/Controllers/Admin/LocationsController.php +++ b/app/Http/Controllers/Admin/LocationsController.php @@ -97,7 +97,7 @@ class LocationsController extends Controller { try { $location = new LocationRepository; - $id = $location->create($request->only(['long', 'short'])); + $location->create($request->only(['long', 'short'])); Alert::success('New location successfully added.')->flash(); return redirect()->route('admin.locations'); diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index eee134d3e..d287e7819 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -47,63 +47,8 @@ class ServersController extends Controller public function getIndex(Request $request) { - $query = Models\Server::withTrashed()->select( - 'servers.*', - 'nodes.name as a_nodeName', - 'users.email as a_ownerEmail', - 'allocations.ip', - 'allocations.port', - 'allocations.ip_alias' - )->join('nodes', 'servers.node_id', '=', 'nodes.id') - ->join('users', 'servers.owner_id', '=', 'users.id') - ->join('allocations', 'servers.allocation_id', '=', 'allocations.id'); - - if ($request->input('filter') && ! is_null($request->input('filter'))) { - preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches); - foreach ($matches[0] as $match) { - $match = str_replace('"', '', $match); - if (strpos($match, ':')) { - list($field, $term) = explode(':', $match); - if ($field === 'node') { - $field = 'nodes.name'; - } elseif ($field === 'owner') { - $field = 'users.email'; - } elseif (! strpos($field, '.')) { - $field = 'servers.' . $field; - } - - $query->orWhere($field, 'LIKE', '%' . $term . '%'); - } else { - $query->where('servers.name', 'LIKE', '%' . $match . '%'); - $query->orWhere([ - ['servers.username', 'LIKE', '%' . $match . '%'], - ['users.email', 'LIKE', '%' . $match . '%'], - ['allocations.port', 'LIKE', '%' . $match . '%'], - ['allocations.ip', 'LIKE', '%' . $match . '%'], - ]); - } - } - } - - try { - $servers = $query->paginate(20); - } catch (\Exception $ex) { - Alert::warning('There was an error with the search parameters provided.'); - $servers = Models\Server::withTrashed()->select( - 'servers.*', - 'nodes.name as a_nodeName', - 'users.email as a_ownerEmail', - 'allocations.ip', - 'allocations.port', - 'allocations.ip_alias' - )->join('nodes', 'servers.node_id', '=', 'nodes.id') - ->join('users', 'servers.owner_id', '=', 'users.id') - ->join('allocations', 'servers.allocation_id', '=', 'allocations.id') - ->paginate(20); - } - return view('admin.servers.index', [ - 'servers' => $servers, + 'servers' => Models\Server::withTrashed()->with('node', 'user')->paginate(25), ]); } @@ -117,47 +62,22 @@ class ServersController extends Controller public function getView(Request $request, $id) { - $server = Models\Server::withTrashed()->select( - 'servers.*', - 'users.email as a_ownerEmail', - 'services.name as a_serviceName', - DB::raw('IFNULL(service_options.executable, services.executable) as a_serviceExecutable'), - 'service_options.docker_image', - 'service_options.name as a_servceOptionName', - 'allocations.ip', - 'allocations.port', - 'allocations.ip_alias' - )->join('nodes', 'servers.node_id', '=', 'nodes.id') - ->join('users', 'servers.owner_id', '=', 'users.id') - ->join('services', 'servers.service_id', '=', 'services.id') - ->join('service_options', 'servers.option_id', '=', 'service_options.id') - ->join('allocations', 'servers.allocation_id', '=', 'allocations.id') - ->where('servers.id', $id) - ->first(); - if (! $server) { - return abort(404); - } + $server = Models\Server::withTrashed()->with( + 'user', 'option.variables', 'variables', + 'node.allocations', 'databases.host' + )->findOrFail($id); + + $server->option->variables->transform(function ($item, $key) use ($server) { + $item->server_value = $server->variables->where('variable_id', $item->id)->pluck('variable_value')->first(); + + return $item; + }); return view('admin.servers.view', [ 'server' => $server, - 'node' => Models\Node::select( - 'nodes.*', - 'locations.long as a_locationName' - )->join('locations', 'nodes.location', '=', 'locations.id') - ->where('nodes.id', $server->node_id) - ->first(), - 'assigned' => Models\Allocation::where('assigned_to', $id)->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(), - 'unassigned' => Models\Allocation::where('node', $server->node_id)->whereNull('assigned_to')->orderBy('ip', 'asc')->orderBy('port', 'asc')->get(), - 'startup' => Models\ServiceVariables::select('service_variables.*', 'server_variables.variable_value as a_serverValue') - ->join('server_variables', 'server_variables.variable_id', '=', 'service_variables.id') - ->where('service_variables.option_id', $server->option_id) - ->where('server_variables.server_id', $server->id) - ->get(), - 'databases' => Models\Database::select('databases.*', 'database_servers.host as a_host', 'database_servers.port as a_port') - ->where('server_id', $server->id) - ->join('database_servers', 'database_servers.id', '=', 'databases.db_server') - ->get(), + 'assigned' => $server->node->allocations->where('server_id', $server->id)->sortBy('port')->sortBy('ip'), + 'unassigned' => $server->node->allocations->where('server_id', null)->sortBy('port')->sortBy('ip'), 'db_servers' => Models\DatabaseServer::all(), ]); } @@ -166,7 +86,14 @@ class ServersController extends Controller { try { $server = new ServerRepository; - $response = $server->create($request->all()); + $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', + ])); return redirect()->route('admin.servers.view', ['id' => $response]); } catch (DisplayValidationException $ex) { @@ -261,18 +188,15 @@ class ServersController extends Controller ], 500); } - $option = Models\ServiceOptions::select( - DB::raw('COALESCE(service_options.executable, services.executable) as executable'), - DB::raw('COALESCE(service_options.startup, services.startup) as startup') - )->leftJoin('services', 'services.id', '=', 'service_options.service_id') - ->where('service_options.id', $request->input('option')) - ->first(); + $option = Models\ServiceOptions::with('variables', ['packs' => function ($query) { + $query->where('selectable', true); + }])->findOrFail($request->input('option')); return response()->json([ - 'packs' => Models\ServicePack::select('id', 'name', 'version')->where('option', $request->input('option'))->where('selectable', true)->get(), - 'variables' => Models\ServiceVariables::where('option_id', $request->input('option'))->get(), - 'exec' => $option->executable, - 'startup' => $option->startup, + 'packs' => $option->packs, + 'variables' => $option->variables, + 'exec' => $option->display_executable, + 'startup' => $option->display_startup, ]); } @@ -309,9 +233,7 @@ class ServersController extends Controller { try { $server = new ServerRepository; - $server->updateContainer($id, [ - 'image' => $request->input('docker_image'), - ]); + $server->updateContainer($id, ['image' => $request->input('docker_image')]); Alert::success('Successfully updated this server\'s docker image.')->flash(); } catch (DisplayValidationException $ex) { return redirect()->route('admin.servers.view', [ @@ -333,17 +255,13 @@ class ServersController extends Controller public function postUpdateServerToggleBuild(Request $request, $id) { - $server = Models\Server::findOrFail($id); - $node = Models\Node::findOrFail($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); + $server = Models\Server::with('node')->findOrFail($id); try { - $res = $client->request('POST', '/server/rebuild', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], - ]); + $res = $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $node->daemonSecret, + ])->request('POST', '/server/rebuild'); Alert::success('A rebuild has been queued successfully. It will run the next time this server is booted.')->flash(); } catch (\GuzzleHttp\Exception\TransferException $ex) { Log::warning($ex); @@ -360,15 +278,15 @@ class ServersController extends Controller { try { $server = new ServerRepository; - $server->changeBuild($id, [ - 'default' => $request->input('default'), - 'add_additional' => $request->input('add_additional'), - 'remove_additional' => $request->input('remove_additional'), - 'memory' => $request->input('memory'), - 'swap' => $request->input('swap'), - 'io' => $request->input('io'), - 'cpu' => $request->input('cpu'), - ]); + $server->changeBuild($id, $request->only([ + 'default', + 'add_additional', + 'remove_additional', + 'memory', + 'swap', + 'io', + 'cpu', + ])); Alert::success('Server details were successfully updated.')->flash(); } catch (DisplayValidationException $ex) { return redirect()->route('admin.servers.view', [ @@ -458,8 +376,10 @@ class ServersController extends Controller { try { $repo = new DatabaseRepository; - $repo->create($id, $request->except([ - '_token', + $repo->create($id, $request->only([ + 'db_server', + 'database', + 'remote', ])); Alert::success('Added new database to this server.')->flash(); } catch (DisplayValidationException $ex) { diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index c2dea5f54..eef57a895 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -45,35 +45,11 @@ class UserController extends Controller // } + // @TODO: implement nicolaslopezj/searchable to clean up this disaster. public function getIndex(Request $request) { - $query = User::select('users.*'); - if ($request->input('filter') && ! is_null($request->input('filter'))) { - preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches); - foreach ($matches[0] as $match) { - $match = str_replace('"', '', $match); - if (strpos($match, ':')) { - list($field, $term) = explode(':', $match); - $query->orWhere($field, 'LIKE', '%' . $term . '%'); - } else { - $query->where('email', 'LIKE', '%' . $match . '%'); - $query->orWhere([ - ['uuid', 'LIKE', '%' . $match . '%'], - ['root_admin', 'LIKE', '%' . $match . '%'], - ]); - } - } - } - - try { - $users = $query->paginate(20); - } catch (\Exception $ex) { - Alert::warning('There was an error with the search parameters provided.'); - $users = User::all()->paginate(20); - } - return view('admin.users.index', [ - 'users' => $users, + 'users' => User::paginate(25), ]); } @@ -85,12 +61,7 @@ class UserController extends Controller public function getView(Request $request, $id) { return view('admin.users.view', [ - 'user' => User::findOrFail($id), - 'servers' => Server::select('servers.*', 'nodes.name as nodeName', 'locations.long as location') - ->join('nodes', 'servers.node_id', '=', 'nodes.id') - ->join('locations', 'nodes.location', '=', 'locations.id') - ->where('owner', $id) - ->get(), + 'user' => User::with('servers.node')->findOrFail($id), ]); } @@ -162,10 +133,6 @@ class UserController extends Controller public function getJson(Request $request) { - foreach (User::select('email')->get() as $user) { - $resp[] = $user->email; - } - - return $resp; + return User::select('email')->get()->pluck('email'); } } diff --git a/app/Http/Controllers/Server/SubuserController.php b/app/Http/Controllers/Server/SubuserController.php index 8c4452457..ed25d4a2c 100644 --- a/app/Http/Controllers/Server/SubuserController.php +++ b/app/Http/Controllers/Server/SubuserController.php @@ -156,14 +156,14 @@ class SubuserController extends Controller try { $repo = new SubuserRepository; - $id = $repo->create($server->id, $request->except([ - '_token', + $subuser = $repo->create($server->id, $request->only([ + 'permissions', 'email', ])); Alert::success('Successfully created new subuser.')->flash(); return redirect()->route('server.subusers.view', [ 'uuid' => $uuid, - 'id' => md5($id), + 'id' => md5($subuser->id), ]); } catch (DisplayValidationException $ex) { return redirect()->route('server.subusers.new', $uuid)->withErrors(json_decode($ex->getMessage()))->withInput(); diff --git a/app/Models/Allocation.php b/app/Models/Allocation.php index 2df21976f..4799ebc98 100644 --- a/app/Models/Allocation.php +++ b/app/Models/Allocation.php @@ -63,4 +63,15 @@ class Allocation extends Model { return (is_null($this->ip_alias)) ? $this->ip : $this->ip_alias; } + + /** + * Accessor to quickly determine if this allocation has an alias. + * + * @param null|string $value + * @return boolean + */ + public function getHasAliasAttribute($value) + { + return (! is_null($this->ip_alias)); + } } diff --git a/app/Models/DatabaseServer.php b/app/Models/DatabaseServer.php index c71d1b8d7..1ebb7546f 100644 --- a/app/Models/DatabaseServer.php +++ b/app/Models/DatabaseServer.php @@ -69,4 +69,14 @@ class DatabaseServer extends Model { return $this->belongsTo(Node::class, 'linked_node'); } + + /** + * Gets the databases assocaited with this host. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function databases() + { + return $this->hasMany(Database::class, 'db_server'); + } } diff --git a/app/Models/Node.php b/app/Models/Node.php index 936682644..3da24531c 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -122,6 +122,7 @@ class Node extends Model /** * Return an instance of the Guzzle client for this specific node. * + * @param array $headers * @return \GuzzleHttp\Client */ public function guzzleClient($headers = []) diff --git a/app/Models/Server.php b/app/Models/Server.php index b6ffa2e4e..3ea72e2b9 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -276,4 +276,14 @@ class Server extends Model { return $this->hasMany(Task::class, 'server', 'id'); } + + /** + * Gets all databases associated with a server. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function databases() + { + return $this->hasMany(Database::class); + } } diff --git a/app/Models/ServerVariables.php b/app/Models/ServerVariables.php index c6c6970bc..bc7244234 100644 --- a/app/Models/ServerVariables.php +++ b/app/Models/ServerVariables.php @@ -51,4 +51,14 @@ class ServerVariables extends Model 'server_id' => 'integer', 'variable_id' => 'integer', ]; + + /** + * Returns information about a given variables parent. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function variable() + { + return $this->belongsTo(ServiceVariables::class, 'variable_id'); + } } diff --git a/app/Models/ServiceOptions.php b/app/Models/ServiceOptions.php index 9cd61a702..09c0ba9a0 100644 --- a/app/Models/ServiceOptions.php +++ b/app/Models/ServiceOptions.php @@ -51,6 +51,28 @@ class ServiceOptions extends Model 'service_id' => 'integer', ]; + /** + * Returns the display executable for the option and will use the parent + * service one if the option does not have one defined. + * + * @return string + */ + public function getDisplayExecutableAttribute($value) + { + return (is_null($this->executable)) ? $this->service->executable : $this->executable; + } + + /** + * Returns the display startup string for the option and will use the parent + * service one if the option does not have one defined. + * + * @return string + */ + public function getDisplayStartupAttribute($value) + { + return (is_null($this->startup)) ? $this->service->startup : $this->startup; + } + /** * Gets service associated with a service option. * diff --git a/app/Models/Subuser.php b/app/Models/Subuser.php index ea855d671..826995d0c 100644 --- a/app/Models/Subuser.php +++ b/app/Models/Subuser.php @@ -59,4 +59,24 @@ class Subuser extends Model 'user_id' => 'integer', 'server_id' => 'integer', ]; + + /** + * Gets the server associated with a subuser. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function server() + { + return $this->belongsTo(Server::class); + } + + /** + * Gets the user associated with a subuser. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user() + { + return $this->belongsTo(User::class); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 1714dcebf..6d1bfa19b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -167,16 +167,6 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac return $subuser->daemonSecret; } - /** - * Returns all permissions that a user has. - * - * @return \Illuminate\Database\Eloquent\Relations\HasMany - */ - public function permissions() - { - return $this->hasMany(Permission::class); - } - /** * Returns an array of all servers a user is able to access. * Note: does not account for user admin status. @@ -205,4 +195,24 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac return (is_numeric($paginate)) ? $query->paginate($paginate) : $query->get(); } + + /** + * Returns all permissions that a user has. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function permissions() + { + return $this->hasMany(Permission::class); + } + + /** + * Returns all servers that a user owns. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function servers() + { + return $this->hasMany(Server::class, 'owner_id'); + } } diff --git a/app/Repositories/DatabaseRepository.php b/app/Repositories/DatabaseRepository.php index 1abf8e155..c605a32de 100644 --- a/app/Repositories/DatabaseRepository.php +++ b/app/Repositories/DatabaseRepository.php @@ -114,28 +114,27 @@ class DatabaseRepository /** * Updates the password for a given database. - * @param int $database The ID of the database to modify. + * @param int $id The ID of the database to modify. * @param string $password The new password to use for the database. * @return bool */ - public function modifyPassword($database, $password) + public function modifyPassword($id, $password) { - $db = Models\Database::findOrFail($database); - $dbr = Models\DatabaseServer::findOrFail($db->db_server); + $database = Models\Database::with('host')->findOrFail($id); DB::beginTransaction(); try { - $db->password = Crypt::encrypt($password); - $db->save(); + $database->password = Crypt::encrypt($password); + $database->save(); $capsule = new Capsule; $capsule->addConnection([ 'driver' => 'mysql', - 'host' => $dbr->host, - 'port' => $dbr->port, + 'host' => $database->host->host, + 'port' => $database->host->port, 'database' => 'mysql', - 'username' => $dbr->username, - 'password' => Crypt::decrypt($dbr->password), + 'username' => $database->host->username, + 'password' => Crypt::decrypt($database->host->password), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', @@ -147,8 +146,8 @@ class DatabaseRepository $capsule->setAsGlobal(); Capsule::statement(sprintf( 'SET PASSWORD FOR `%s`@`%s` = PASSWORD(\'%s\')', - $db->username, - $db->remote, + $database->username, + $database->remote, $password )); @@ -161,13 +160,12 @@ class DatabaseRepository /** * Drops a database from the associated MySQL Server. - * @param int $database The ID of the database to drop. + * @param int $id The ID of the database to drop. * @return bool */ - public function drop($database) + public function drop($id) { - $db = Models\Database::findOrFail($database); - $dbr = Models\DatabaseServer::findOrFail($db->db_server); + $database = Models\Database::with('host')->findOrFail($id); DB::beginTransaction(); @@ -175,11 +173,11 @@ class DatabaseRepository $capsule = new Capsule; $capsule->addConnection([ 'driver' => 'mysql', - 'host' => $dbr->host, - 'port' => $dbr->port, + 'host' => $database->host->host, + 'port' => $database->host->port, 'database' => 'mysql', - 'username' => $dbr->username, - 'password' => Crypt::decrypt($dbr->password), + 'username' => $database->host->username, + 'password' => Crypt::decrypt($database->host->password), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', @@ -190,10 +188,10 @@ class DatabaseRepository $capsule->setAsGlobal(); - Capsule::statement('DROP USER `' . $db->username . '`@`' . $db->remote . '`'); - Capsule::statement('DROP DATABASE `' . $db->database . '`'); + Capsule::statement('DROP USER `' . $database->username . '`@`' . $database->remote . '`'); + Capsule::statement('DROP DATABASE `' . $database->database . '`'); - $db->delete(); + $database->delete(); DB::commit(); @@ -206,19 +204,19 @@ class DatabaseRepository /** * Deletes a database server from the system if it is empty. + * * @param int $server The ID of the Database Server. * @return */ public function delete($server) { - $dbh = Models\DatabaseServer::findOrFail($server); - $databases = Models\Database::where('db_server', $dbh->id)->count(); + $host = Models\DatabaseServer::withCount('databases')->findOrFail($server); - if ($databases > 0) { + if ($host->databases_count > 0) { throw new DisplayException('You cannot delete a database server that has active databases attached to it.'); } - return $dbh->delete(); + return $host->delete(); } /** @@ -268,8 +266,7 @@ class DatabaseRepository // Allows us to check that we can connect to things. Capsule::select('SELECT 1 FROM dual'); - $dbh = new Models\DatabaseServer; - $dbh->fill([ + Models\DatabaseServer::create([ 'name' => $data['name'], 'host' => $data['host'], 'port' => $data['port'], @@ -278,7 +275,6 @@ class DatabaseRepository 'max_databases' => null, 'linked_node' => (! empty($data['linked_node']) && $data['linked_node'] > 0) ? $data['linked_node'] : null, ]); - $dbh->save(); DB::commit(); } catch (\Exception $ex) { diff --git a/app/Repositories/LocationRepository.php b/app/Repositories/LocationRepository.php index e25446d31..1b6f50613 100644 --- a/app/Repositories/LocationRepository.php +++ b/app/Repositories/LocationRepository.php @@ -37,9 +37,10 @@ class LocationRepository /** * Creates a new location on the system. + * * @param array $data - * @throws Pterodactyl\Exceptions\DisplayValidationException - * @return int + * @throws \Pterodactyl\Exceptions\DisplayValidationException + * @return \Pterodactyl\Models\Location */ public function create(array $data) { @@ -54,14 +55,12 @@ class LocationRepository throw new DisplayValidationException($validator->errors()); } - $location = new Models\Location; - $location->fill([ + $location = Models\Location::create([ 'long' => $data['long'], 'short' => $data['short'], ]); - $location->save(); - return $location->id; + return $location; } /** diff --git a/app/Repositories/NodeRepository.php b/app/Repositories/NodeRepository.php index b9ba82e4b..e409a011a 100644 --- a/app/Repositories/NodeRepository.php +++ b/app/Repositories/NodeRepository.php @@ -81,12 +81,7 @@ class NodeRepository $uuid = new UuidService; $data['daemonSecret'] = (string) $uuid->generate('nodes', 'daemonSecret'); - // Store the Data - $node = new Models\Node; - $node->fill($data); - $node->save(); - - return $node; + return Models\Node::create($data); } public function update($id, array $data) @@ -260,8 +255,8 @@ class NodeRepository public function delete($id) { - $node = Models\Node::findOrFail($id); - if (Models\Server::where('node', $id)->count() > 0) { + $node = Models\Node::withCount('servers')->findOrFail($id); + if ($node->servers_count > 0) { throw new DisplayException('You cannot delete a node with servers currently attached to it.'); } diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index fe2a2f840..13caf0a5c 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -30,6 +30,7 @@ use Crypt; use Validator; use Pterodactyl\Models; use Pterodactyl\Services\UuidService; +use GuzzleHttp\Exception\TransferException; use Pterodactyl\Services\DeploymentService; use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayValidationException; @@ -121,12 +122,7 @@ class ServerRepository throw new DisplayValidationException($validator->errors()); } - if (is_int($data['owner'])) { - $user = Models\User::select('id', 'email')->where('id', $data['owner'])->first(); - } else { - $user = Models\User::select('id', 'email')->where('email', $data['owner'])->first(); - } - + $user = Models\User::select('id', 'email')->where((is_int($data['owner'])) ? 'id' : 'email', $data['owner'])->first(); if (! $user) { throw new DisplayException('The user id or email passed to the function was not found on the system.'); } @@ -141,7 +137,7 @@ class ServerRepository $node = DeploymentService::smartRandomNode($data['memory'], $data['disk'], $data['location']); $allocation = DeploymentService::randomAllocation($node->id); } else { - $node = Models\Node::getByID($data['node']); + $node = Models\Node::findOrFail($data['node']); } // Verify IP & Port are a.) free and b.) assigned to the node. @@ -299,11 +295,7 @@ class ServerRepository ]); } - $client = Models\Node::guzzleRequest($node->id); - $client->request('POST', '/servers', [ - 'headers' => [ - 'X-Access-Token' => $node->daemonSecret, - ], + $node->guzzleClient(['X-Access-Token' => $node->daemonSecret])->request('POST', '/servers', [ 'json' => [ 'uuid' => (string) $server->uuid, 'user' => $server->username, @@ -338,7 +330,7 @@ class ServerRepository DB::commit(); return $server->id; - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { DB::rollBack(); throw new DisplayException('There was an error while attempting to connect to the daemon to add this server.', $ex); } catch (\Exception $ex) { @@ -373,11 +365,10 @@ class ServerRepository DB::beginTransaction(); try { - $server = Models\Server::findOrFail($id); - $owner = Models\User::findOrFail($server->owner_id); + $server = Models\Server::with('user')->findOrFail($id); // Update daemon secret if it was passed. - if ((isset($data['reset_token']) && $data['reset_token'] === true) || (isset($data['owner']) && $data['owner'] !== $owner->email)) { + if ((isset($data['reset_token']) && $data['reset_token'] === true) || (isset($data['owner']) && $data['owner'] !== $server->user->email)) { $oldDaemonKey = $server->daemonSecret; $server->daemonSecret = $uuid->generate('servers', 'daemonSecret'); $resetDaemonKey = true; @@ -404,15 +395,10 @@ class ServerRepository return true; } - // If we need to update do it here. - $node = Models\Node::getByID($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); - - $res = $client->request('PATCH', '/server', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], + $res = $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $server->node->daemonSecret, + ])->request('PATCH', '/server', [ 'exceptions' => false, 'json' => [ 'keys' => [ @@ -461,14 +447,10 @@ class ServerRepository $server->image = $data['image']; $server->save(); - $node = Models\Node::getByID($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); - - $client->request('PATCH', '/server', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], + $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $server->node->daemonSecret, + ])->request('PATCH', '/server', [ 'json' => [ 'build' => [ 'image' => $server->image, @@ -479,7 +461,7 @@ class ServerRepository DB::commit(); return true; - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { DB::rollBack(); throw new DisplayException('An error occured while attempting to update the container image.', $ex); } catch (\Exception $ex) { @@ -519,15 +501,13 @@ class ServerRepository DB::beginTransaction(); try { - $server = Models\Server::findOrFail($id); - $allocation = Models\Allocation::findOrFail($server->allocation_id); - + $server = Models\Server::with('allocation', 'allocations')->findOrFail($id); $newBuild = []; if (isset($data['default'])) { list($ip, $port) = explode(':', $data['default']); - if ($ip !== $allocation->ip || (int) $port !== $allocation->port) { - $selection = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->first(); + if ($ip !== $server->allocation->ip || (int) $port !== $server->allocation->port) { + $selection = $server->allocations->where('ip', $ip)->where('port', $port)->first(); if (! $selection) { throw new DisplayException('The requested default connection (' . $ip . ':' . $port . ') is not allocated to this server.'); } @@ -539,7 +519,7 @@ class ServerRepository ]; // Re-Run to keep updated for rest of function - $allocation = Models\Allocation::findOrFail($server->allocation_id); + $server->load('allocation'); } } @@ -554,15 +534,17 @@ class ServerRepository } // Can't remove the assigned IP/Port combo - if ($ip === $allocation->ip && (int) $port === (int) $allocation->port) { + if ($ip === $server->allocation->ip && (int) $port === (int) $server->allocation->port) { break; } $newPorts = true; - Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->update([ + $server->allocations->where('ip', $ip)->where('port', $port)->update([ 'assigned_to' => null, ]); } + + $server->load('allocations'); } // Add Assignments @@ -575,7 +557,7 @@ class ServerRepository } // Don't allow double port assignments - if (Models\Allocation::where('port', $port)->where('assigned_to', $server->id)->count() !== 0) { + if ($server->allocations->where('port', $port)->count() !== 0) { break; } @@ -584,12 +566,13 @@ class ServerRepository 'assigned_to' => $server->id, ]); } + + $server->load('allocations'); } // Loop All Assignments $additionalAssignments = []; - $assignments = Models\Allocation::where('assigned_to', $server->id)->get(); - foreach ($assignments as &$assignment) { + foreach ($server->allocations as &$assignment) { if (array_key_exists((string) $assignment->ip, $additionalAssignments)) { array_push($additionalAssignments[(string) $assignment->ip], (int) $assignment->port); } else { @@ -635,14 +618,10 @@ class ServerRepository $server->save(); if (! empty($newBuild)) { - $node = Models\Node::getByID($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); - - $client->request('PATCH', '/server', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], + $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $server->node->daemonSecret, + ])->request('PATCH', '/server', [ 'json' => [ 'build' => $newBuild, ], @@ -652,7 +631,7 @@ class ServerRepository DB::commit(); return true; - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { DB::rollBack(); throw new DisplayException('An error occured while attempting to update the configuration.', $ex); } catch (\Exception $ex) { @@ -663,7 +642,7 @@ class ServerRepository public function updateStartup($id, array $data, $admin = false) { - $server = Models\Server::findOrFail($id); + $server = Models\Server::with('variables', 'option.variables')->findOrFail($id); DB::beginTransaction(); @@ -675,22 +654,22 @@ class ServerRepository } // Check those Variables - $variables = Models\ServiceVariables::select( - 'service_variables.*', - DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_currentValue') - )->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id') - ->where('option_id', $server->option_id) - ->get(); + $server->option->variables->transform(function ($item, $key) use ($server) { + $displayValue = $server->variables->where('variable_id', $item->id)->pluck('variable_value')->first(); + $item->server_value = (! is_null($displayValue)) ? $displayValue : $item->default_value; + + return $item; + }); $variableList = []; - if ($variables) { - foreach ($variables as &$variable) { + if ($server->option->variables) { + foreach ($server->option->variables as &$variable) { // Move on if the new data wasn't even sent if (! isset($data[$variable->env_variable])) { $variableList[] = [ 'id' => $variable->id, 'env' => $variable->env_variable, - 'val' => $variable->a_currentValue, + 'val' => $variable->server_value, ]; continue; } @@ -708,13 +687,13 @@ class ServerRepository // Is the variable required? // @TODO: is this even logical to perform this check? if (isset($data[$variable->env_variable]) && empty($data[$variable->env_variable])) { - if ($variable->required === 1) { + if ($variable->required) { throw new DisplayException('A required service option variable field (' . $variable->env_variable . ') was included in this request but was left blank.'); } } // Variable hidden and/or not user editable - if (($variable->user_viewable === 0 || $variable->user_editable === 0) && ! $admin) { + if ((! $variable->user_viewable || ! $variable->user_editable) && ! $admin) { throw new DisplayException('A service option variable field (' . $variable->env_variable . ') does not exist or you do not have permission to edit it.'); } @@ -747,14 +726,10 @@ class ServerRepository $model->save(); } - $node = Models\Node::getByID($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); - - $client->request('PATCH', '/server', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], + $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $server->node->daemonSecret, + ])->request('PATCH', '/server', [ 'json' => [ 'build' => [ 'env|overwrite' => $environmentVariables, @@ -765,7 +740,7 @@ class ServerRepository DB::commit(); return true; - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { DB::rollBack(); throw new DisplayException('An error occured while attempting to update the server configuration.', $ex); } catch (\Exception $ex) { @@ -780,7 +755,7 @@ class ServerRepository DB::beginTransaction(); try { - if ($force === 'force' || $force === true) { + if ($force === 'force' || $force) { $server->installed = 3; $server->save(); } @@ -796,8 +771,7 @@ class ServerRepository public function deleteNow($id, $force = false) { - $server = Models\Server::withTrashed()->findOrFail($id); - $node = Models\Node::findOrFail($server->node_id); + $server = Models\Server::withTrashed()->with('node')->findOrFail($id); // Handle server being restored previously or // an accidental queue. @@ -835,17 +809,14 @@ class ServerRepository $repository->drop($database->id); } - $client = Models\Node::guzzleRequest($server->node_id); - $client->request('DELETE', '/servers', [ - 'headers' => [ - 'X-Access-Token' => $node->daemonSecret, - 'X-Access-Server' => $server->uuid, - ], - ]); + $server->node->guzzleRequest([ + 'X-Access-Token' => $server->node->daemonSecret, + 'X-Access-Server' => $server->uuid, + ])->request('DELETE', '/servers'); $server->forceDelete(); DB::commit(); - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { // Set installed is set to 3 when force deleting. if ($server->installed === 3 || $force) { $server->forceDelete(); @@ -875,7 +846,7 @@ class ServerRepository if ($server->installed === 2) { throw new DisplayException('This server was marked as having a failed install, you cannot override this.'); } - $server->installed = ($server->installed === 1) ? 0 : 1; + $server->installed = ($server->installed) ? 0 : 1; return $server->save(); } @@ -887,31 +858,27 @@ class ServerRepository */ public function suspend($id, $deleted = false) { - $server = ($deleted) ? Models\Server::withTrashed()->findOrFail($id) : Models\Server::findOrFail($id); - $node = Models\Node::findOrFail($server->node_id); + $server = Models\Server::withTrashed()->with('node')->findOrFail($id); DB::beginTransaction(); try { // Already suspended, no need to make more requests. - if ($server->suspended === 1) { + if ($server->suspended) { return true; } $server->suspended = 1; $server->save(); - $client = Models\Node::guzzleRequest($server->node_id); - $client->request('POST', '/server/suspend', [ - 'headers' => [ - 'X-Access-Token' => $node->daemonSecret, - 'X-Access-Server' => $server->uuid, - ], - ]); + $server->node->guzzleClient([ + 'X-Access-Token' => $server->node->daemonSecret, + 'X-Access-Server' => $server->uuid, + ])->request('POST', '/server/suspend'); return DB::commit(); - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { DB::rollBack(); throw new DisplayException('An error occured while attempting to contact the remote daemon to suspend this server.', $ex); } catch (\Exception $ex) { @@ -927,8 +894,7 @@ class ServerRepository */ public function unsuspend($id) { - $server = Models\Server::findOrFail($id); - $node = Models\Node::findOrFail($server->node_id); + $server = Models\Server::with('node')->findOrFail($id); DB::beginTransaction(); @@ -942,16 +908,13 @@ class ServerRepository $server->suspended = 0; $server->save(); - $client = Models\Node::guzzleRequest($server->node_id); - $client->request('POST', '/server/unsuspend', [ - 'headers' => [ - 'X-Access-Token' => $node->daemonSecret, - 'X-Access-Server' => $server->uuid, - ], - ]); + $server->node->guzzleClient([ + 'X-Access-Token' => $server->node->daemonSecret, + 'X-Access-Server' => $server->uuid, + ])->request('POST', '/server/unsuspend'); return DB::commit(); - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { DB::rollBack(); throw new DisplayException('An error occured while attempting to contact the remote daemon to un-suspend this server.', $ex); } catch (\Exception $ex) { @@ -962,12 +925,9 @@ class ServerRepository public function updateSFTPPassword($id, $password) { - $server = Models\Server::findOrFail($id); - $node = Models\Node::findOrFail($server->node_id); + $server = Models\Server::with('node')->findOrFail($id); - $validator = Validator::make([ - 'password' => $password, - ], [ + $validator = Validator::make(['password' => $password], [ 'password' => 'required|regex:/^((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,})$/', ]); @@ -981,21 +941,17 @@ class ServerRepository try { $server->save(); - $client = Models\Node::guzzleRequest($server->node_id); - $client->request('POST', '/server/password', [ - 'headers' => [ - 'X-Access-Token' => $node->daemonSecret, - 'X-Access-Server' => $server->uuid, - ], - 'json' => [ - 'password' => $password, - ], + $server->node->guzzleClient([ + 'X-Access-Token' => $server->node->daemonSecret, + 'X-Access-Server' => $server->uuid, + ])->request('POST', '/server/password', [ + 'json' => ['password' => $password], ]); DB::commit(); return true; - } catch (\GuzzleHttp\Exception\TransferException $ex) { + } catch (TransferException $ex) { DB::rollBack(); throw new DisplayException('There was an error while attmping to contact the remote service to change the password.', $ex); } catch (\Exception $ex) { diff --git a/app/Repositories/SubuserRepository.php b/app/Repositories/SubuserRepository.php index 335e6926d..94a8ccecb 100644 --- a/app/Repositories/SubuserRepository.php +++ b/app/Repositories/SubuserRepository.php @@ -112,11 +112,11 @@ class SubuserRepository * @param array $data * @throws DisplayValidationException * @throws DisplayException - * @return int Returns the ID of the newly created subuser. + * @return \Pterodactyl\Models\Subuser */ public function create($sid, array $data) { - $server = Models\Server::findOrFail($sid); + $server = Models\Server::with('node')->findOrFail($sid); $validator = Validator::make($data, [ 'permissions' => 'required|array', @@ -135,14 +135,13 @@ class SubuserRepository if (! $user) { try { $repo = new UserRepository; - $uid = $repo->create([ + $user = $repo->create([ 'email' => $data['email'], - 'username' => substr(str_replace('@', '', $data['email']), 0, 8), - 'name_first' => 'John', - 'name_last' => 'Doe', + 'username' => str_random(8), + 'name_first' => 'Unassigned', + 'name_last' => 'Name', 'root_admin' => false, ]); - $user = Models\User::findOrFail($uid); } catch (\Exception $ex) { throw $ex; } @@ -153,14 +152,11 @@ class SubuserRepository } $uuid = new UuidService; - - $subuser = new Models\Subuser; - $subuser->fill([ + $subuser = Models\Subuser::create([ 'user_id' => $user->id, 'server_id' => $server->id, 'daemonSecret' => (string) $uuid->generate('servers', 'uuid'), ]); - $subuser->save(); $daemonPermissions = $this->coreDaemonPermissions; foreach ($data['permissions'] as $permission) { @@ -170,13 +166,11 @@ class SubuserRepository array_push($daemonPermissions, $this->permissions[$permission]); } - $model = new Models\Permission; - $model->fill([ + Models\Permission::create([ 'user_id' => $user->id, 'server_id' => $server->id, 'permission' => $permission, ]); - $model->save(); } } @@ -184,14 +178,10 @@ class SubuserRepository // We contact even if they don't have any daemon permissions to overwrite // if they did have them previously. - $node = Models\Node::getByID($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); - - $res = $client->request('PATCH', '/server', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], + $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $node->daemonSecret, + ])->request('PATCH', '/server', [ 'json' => [ 'keys' => [ $subuser->daemonSecret => $daemonPermissions, @@ -199,18 +189,9 @@ class SubuserRepository ], ]); - $email = $data['email']; - Mail::queue('emails.added-subuser', [ - 'serverName' => $server->name, - 'url' => route('server.index', $server->uuidShort), - ], function ($message) use ($email) { - $message->to($email); - $message->from(Settings::get('email_from', env('MAIL_FROM')), Settings::get('email_sender_name', env('MAIL_FROM_NAME', 'Pterodactyl Panel'))); - $message->subject(Settings::get('company') . ' - Added to Server'); - }); DB::commit(); - return $subuser->id; + return $subuser; } catch (\GuzzleHttp\Exception\TransferException $ex) { DB::rollBack(); throw new DisplayException('There was an error attempting to connect to the daemon to add this user.', $ex); @@ -232,22 +213,18 @@ class SubuserRepository */ public function delete($id) { - $subuser = Models\Subuser::findOrFail($id); - $server = Models\Server::findOrFail($subuser->server_id); + $subuser = Models\Subuser::with('server.node', 'permissions')->findOrFail($id); + $server = $subuser->server; DB::beginTransaction(); try { Models\Permission::where('user_id', $subuser->user_id)->where('server_id', $subuser->server_id)->delete(); - $node = Models\Node::getByID($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); - - $res = $client->request('PATCH', '/server', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], + $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $server->node->daemonSecret, + ])->request('PATCH', '/server', [ 'json' => [ 'keys' => [ $subuser->daemonSecret => [], @@ -290,8 +267,8 @@ class SubuserRepository throw new DisplayValidationException(json_encode($validator->all())); } - $subuser = Models\Subuser::findOrFail($id); - $server = Models\Server::findOrFail($data['server']); + $subuser = Models\Subuser::with('server.node')->findOrFail($id); + $server = $subuser->server; DB::beginTransaction(); @@ -318,14 +295,10 @@ class SubuserRepository // Contact Daemon // We contact even if they don't have any daemon permissions to overwrite // if they did have them previously. - $node = Models\Node::getByID($server->node_id); - $client = Models\Node::guzzleRequest($server->node_id); - - $res = $client->request('PATCH', '/server', [ - 'headers' => [ - 'X-Access-Server' => $server->uuid, - 'X-Access-Token' => $node->daemonSecret, - ], + $server->node->guzzleClient([ + 'X-Access-Server' => $server->uuid, + 'X-Access-Token' => $server->node->daemonSecret, + ])->request('PATCH', '/server', [ 'json' => [ 'keys' => [ $subuser->daemonSecret => $daemonPermissions, diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index b46727e1b..68ae134f1 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -111,7 +111,7 @@ class UserRepository DB::commit(); - return $user->id; + return $user; } catch (\Exception $ex) { DB::rollBack(); throw $ex; diff --git a/resources/views/admin/servers/index.blade.php b/resources/views/admin/servers/index.blade.php index 11d852ecf..e2e5010f5 100644 --- a/resources/views/admin/servers/index.blade.php +++ b/resources/views/admin/servers/index.blade.php @@ -32,7 +32,7 @@

All Servers


- +
@@ -64,8 +64,8 @@ Pending Deletion @endif - {{ $server->a_ownerEmail }} - {{ $server->a_nodeName }} + {{ $server->user->email }} + {{ $server->node->name }} {{ $server->username }} @endforeach diff --git a/resources/views/admin/servers/view.blade.php b/resources/views/admin/servers/view.blade.php index 7def73236..3f65dbd11 100644 --- a/resources/views/admin/servers/view.blade.php +++ b/resources/views/admin/servers/view.blade.php @@ -89,19 +89,19 @@ Owner - {{ $server->a_ownerEmail }} + {{ $server->user->email }} Location - {{ $node->a_locationName }} + {{ $server->node->location->short }} Node - {{ $node->name }} + {{ $server->node->name }} Service - {{ $server->a_serviceName }} :: {{ $server->a_servceOptionName }} + {{ $server->option->service->name }} :: {{ $server->option->name }} Name @@ -129,13 +129,13 @@ Default Connection - {{ $server->ip }}:{{ $server->port }} + {{ $server->allocation->ip }}:{{ $server->allocation->port }} Connection Alias - @if(!is_null($server->ip_alias)) - {{ $server->ip_alias }}:{{ $server->port }} + @if($server->allocation->alias !== $server->allocation->ip) + {{ $server->allocation->alias }}:{{ $server->allocation->port }} @else No Alias Assigned @endif @@ -170,7 +170,7 @@
- +

You can change the owner of this server by changing this field to an email matching another use on this system. If you do this a new daemon security token will be generated automatically.

@@ -278,9 +278,15 @@ @foreach ($assigned as $assignment)
- ip == $server->ip && $assignment->port == $server->port) checked="checked" @endif name="default" value="{{ $assignment->ip }}:{{ $assignment->port }}"/> + id === $server->allocation_id) checked="checked" @endif + name="default" value="{{ $assignment->ip }}:{{ $assignment->port }}"/> - + has_alias) + data-toggle="tooltip" data-placement="left" title="{{ $assignment->ip }}:{{ $assignment->port }}" + @endif + />
@endforeach
@@ -291,7 +297,7 @@
@@ -304,7 +310,7 @@
@@ -333,7 +339,7 @@
Changing any of the values below will require a restart for them to take effect.
- {{ $server->a_serviceExecutable }} + {{ $server->option->display_executable }}

The following data replacers are avaliable for the startup command: @{{SERVER_MEMORY}}, @{{SERVER_IP}}, and @{{SERVER_PORT}}. They will be replaced with the allocated memory, server ip, and server port respectively.

@@ -343,18 +349,18 @@
- @foreach($startup as $item) + @foreach($server->option->variables as $variable)
- +
-

{!! $item->description !!}
Regex: {{ $item->regex }}
Access as: {{{{$item->env_variable}}}}

+

{!! $variable->description !!}
Regex: {{ $variable->regex }}
Access as: {{{{ $variable->env_variable }}}}

@endforeach
@@ -412,7 +418,7 @@
- @if(count($databases) > 0) + @if(count($server->databases) > 0)
@@ -426,12 +432,12 @@ - @foreach($databases as $database) + @foreach($server->databases as $database) - + @endforeach @@ -568,7 +574,7 @@ $(document).ready(function () { 'X-Access-Token': '{{ $server->daemonSecret }}', 'X-Access-Server': '{{ $server->uuid }}' }, - url: '{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/server', + url: '{{ $server->node->scheme }}://{{ $server->node->fqdn }}:{{ $server->node->daemonListen }}/server', dataType: 'json', timeout: 5000, }).done(function (data) { diff --git a/resources/views/admin/users/view.blade.php b/resources/views/admin/users/view.blade.php index 314fc8ba7..3ba9ec035 100644 --- a/resources/views/admin/users/view.blade.php +++ b/resources/views/admin/users/view.blade.php @@ -39,7 +39,7 @@
- +
@@ -64,7 +64,7 @@
{!! csrf_field() !!} - +
@@ -72,7 +72,7 @@
- +
@@ -83,7 +83,7 @@
- +
{{ $database->database }} {{ $database->username }} ({{ $database->remote }}) {{ Crypt::decrypt($database->password) }} {{ $database->a_host }}:{{ $database->a_port }}{{ $database->host->host }}:{{ $database->host->port }}
@@ -112,12 +112,12 @@ - @foreach($servers as $server) + @foreach($user->servers as $server) - + @@ -127,7 +127,7 @@ @else
There are no servers associated with this account.
@endif - +
{{ $server->uuidShort }} {{ $server->name }}{{ $server->node_idName }}{{ $server->node->name }} {{ $server->username }} @if($server->suspended === 0)Active@elseSuspended@endif