More model updates to more places than I anticipated.

This probably broke a lot of things.
This commit is contained in:
Dane Everitt 2017-02-09 17:43:54 -05:00
parent 0d61417814
commit 4f61637284
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
21 changed files with 339 additions and 433 deletions

View file

@ -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');

View file

@ -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' => [
$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) {

View file

@ -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');
}
}

View file

@ -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();

View file

@ -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));
}
}

View file

@ -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');
}
}

View file

@ -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 = [])

View file

@ -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);
}
}

View file

@ -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');
}
}

View file

@ -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.
*

View file

@ -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);
}
}

View file

@ -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');
}
}

View file

@ -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) {

View file

@ -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;
}
/**

View file

@ -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.');
}

View file

@ -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' => [
$res = $server->node->guzzleClient([
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $node->daemonSecret,
],
'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' => [
$server->node->guzzleClient([
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $node->daemonSecret,
],
'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' => [
$server->node->guzzleClient([
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $node->daemonSecret,
],
'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' => [
$server->node->guzzleClient([
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $node->daemonSecret,
],
'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,
$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,
$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,
$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,
$server->node->guzzleClient([
'X-Access-Token' => $server->node->daemonSecret,
'X-Access-Server' => $server->uuid,
],
'json' => [
'password' => $password,
],
])->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) {

View file

@ -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' => [
$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' => [
$server->node->guzzleClient([
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $node->daemonSecret,
],
'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' => [
$server->node->guzzleClient([
'X-Access-Server' => $server->uuid,
'X-Access-Token' => $node->daemonSecret,
],
'X-Access-Token' => $server->node->daemonSecret,
])->request('PATCH', '/server', [
'json' => [
'keys' => [
$subuser->daemonSecret => $daemonPermissions,

View file

@ -111,7 +111,7 @@ class UserRepository
DB::commit();
return $user->id;
return $user;
} catch (\Exception $ex) {
DB::rollBack();
throw $ex;

View file

@ -32,7 +32,7 @@
<h3>All Servers</h3><hr />
<form method="GET" style="margin-bottom:20px;">
<div class="input-group">
<input type="text" name="filter" class="form-control" value="{{ urldecode(Input::get('filter')) }}" placeholder="search term" />
<input type="text" name="filter" class="form-control" value="{{ urldecode(request()->filter) }}" placeholder="search term" />
<div class="input-group-btn">
<button type="submit" class="btn btn-sm btn-primary">Filter Servers</button>
</div>
@ -64,8 +64,8 @@
<span class="label label-danger">Pending Deletion</span>
@endif
</td>
<td><a href="/admin/users/view/{{ $server->owner_id }}">{{ $server->a_ownerEmail }}</a></td>
<td><a href="/admin/nodes/view/{{ $server->node_id }}">{{ $server->a_nodeName }}</a></td>
<td><a href="/admin/users/view/{{ $server->user->id }}">{{ $server->user->email }}</a></td>
<td><a href="/admin/nodes/view/{{ $server->node->id }}">{{ $server->node->name }}</a></td>
<td class="hidden-xs"><code>{{ $server->username }}</code></td>
</tr>
@endforeach

View file

@ -89,19 +89,19 @@
</tr>
<tr>
<td>Owner</td>
<td><a href="{{ route('admin.users.view', $server->owner_id) }}">{{ $server->a_ownerEmail }}</a></td>
<td><a href="{{ route('admin.users.view', $server->owner_id) }}">{{ $server->user->email }}</a></td>
</tr>
<tr>
<td>Location</td>
<td><a href="{{ route('admin.locations') }}">{{ $node->a_locationName }}</a></td>
<td><a href="{{ route('admin.locations') }}">{{ $server->node->location->short }}</a></td>
</tr>
<tr>
<td>Node</td>
<td><a href="{{ route('admin.nodes.view', $server->node_id) }}">{{ $node->name }}</a></td>
<td><a href="{{ route('admin.nodes.view', $server->node_id) }}">{{ $server->node->name }}</a></td>
</tr>
<tr>
<td>Service</td>
<td>{{ $server->a_serviceName }} :: {{ $server->a_servceOptionName }}</td>
<td>{{ $server->option->service->name }} :: {{ $server->option->name }}</td>
</tr>
<tr>
<td>Name</td>
@ -129,13 +129,13 @@
</tr>
<tr>
<td>Default Connection</td>
<td><code>{{ $server->ip }}:{{ $server->port }}</code></td>
<td><code>{{ $server->allocation->ip }}:{{ $server->allocation->port }}</code></td>
</tr>
<tr>
<td>Connection Alias</td>
<td>
@if(!is_null($server->ip_alias))
<code>{{ $server->ip_alias }}:{{ $server->port }}</code>
@if($server->allocation->alias !== $server->allocation->ip)
<code>{{ $server->allocation->alias }}:{{ $server->allocation->port }}</code>
@else
<span class="label label-default">No Alias Assigned</span>
@endif
@ -170,7 +170,7 @@
<div class="form-group {{ $errors->has('owner') ? 'has-error' : '' }}">
<label for="name" class="control-label">Server Owner</label>
<div>
<input type="text" name="owner" value="{{ old('owner', $server->a_ownerEmail) }}" class="form-control" />
<input type="text" name="owner" value="{{ old('owner', $server->user->email) }}" class="form-control" />
<p class="text-muted"><small>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.</small></p>
</div>
</div>
@ -278,9 +278,15 @@
@foreach ($assigned as $assignment)
<div class="input-group" style="margin:5px auto;">
<span class="input-group-addon">
<input type="radio" @if($assignment->ip == $server->ip && $assignment->port == $server->port) checked="checked" @endif name="default" value="{{ $assignment->ip }}:{{ $assignment->port }}"/>
<input type="radio"
@if($assignment->id === $server->allocation_id) checked="checked" @endif
name="default" value="{{ $assignment->ip }}:{{ $assignment->port }}"/>
</span>
<input type="text" class="form-control" value="@if(!is_null($assignment->ip_alias)){{ $assignment->ip_alias }}@else{{ $assignment->ip }}@endif:{{ $assignment->port }} @if(!is_null($assignment->ip_alias))(alias of {{ $assignment->ip }})@endif" readonly />
<input type="text" class="form-control" value="{{ $assignment->alias }}:{{ $assignment->port }}"
@if($assignment->has_alias)
data-toggle="tooltip" data-placement="left" title="{{ $assignment->ip }}:{{ $assignment->port }}"
@endif
/>
</div>
@endforeach
</div>
@ -291,7 +297,7 @@
<div>
<select name="add_additional[]" class="form-control" multiple>
@foreach ($unassigned as $assignment)
<option value="{{ $assignment->ip }}:{{ $assignment->port }}">@if(!is_null($assignment->ip_alias)){{ $assignment->ip_alias }}@else{{ $assignment->ip }}@endif:{{ $assignment->port }} @if(!is_null($assignment->ip_alias))(alias of {{ $assignment->ip }})@endif</option>
<option value="{{ $assignment->ip }}:{{ $assignment->port }}">{{ $assignment->alias }}:{{ $assignment->port }}</option>
@endforeach
</select>
</div>
@ -304,7 +310,7 @@
<div>
<select name="remove_additional[]" class="form-control" multiple>
@foreach ($assigned as $assignment)
<option value="{{ $assignment->ip }}:{{ $assignment->port }}" @if($server->allocation_id === $assignment->id)disabled @endif>@if(!is_null($assignment->ip_alias)){{ $assignment->ip_alias }}@else{{ $assignment->ip }}@endif:{{ $assignment->port }} @if(!is_null($assignment->ip_alias))(alias of {{ $assignment->ip }})@endif</option>
<option value="{{ $assignment->ip }}:{{ $assignment->port }}" @if($server->allocation_id === $assignment->id)disabled @endif>{{ $assignment->alias }}:{{ $assignment->port }}</option>
@endforeach
</select>
</div>
@ -333,7 +339,7 @@
<div class="alert alert-info">Changing any of the values below will require a restart for them to take effect.</div>
<label class="control-label">Server Startup Command</label>
<div class="input-group">
<span class="input-group-addon">{{ $server->a_serviceExecutable }}</span>
<span class="input-group-addon">{{ $server->option->display_executable }}</span>
<input type="text" class="form-control" name="startup" value="{{ old('startup', $server->startup) }}" />
</div>
<p class="text-muted"><small>The following data replacers are avaliable for the startup command: <code>@{{SERVER_MEMORY}}</code>, <code>@{{SERVER_IP}}</code>, and <code>@{{SERVER_PORT}}</code>. They will be replaced with the allocated memory, server ip, and server port respectively.</small></p>
@ -343,18 +349,18 @@
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
<div class="panel-body">
<div class="row">
@foreach($startup as $item)
@foreach($server->option->variables as $variable)
<div class="form-group col-md-6">
<label class="control-label">
@if($item->required === 1)<span class="label label-primary">Required</span> @endif
@if($item->user_viewable === 0)<span data-toggle="tooltip" data-placement="top" title="Not Visible to Users" class="label label-danger"><i class="fa fa-eye-slash"></i></span> @endif
@if($item->user_editable === 0)<span data-toggle="tooltip" data-placement="top" title="Not Editable by Users" class="label label-danger"><i class="fa fa-edit"></i></span> @endif
{{ $item->name }}
@if($variable->required)<span class="label label-primary">Required</span> @endif
@if(! $variable->user_viewable)<span data-toggle="tooltip" data-placement="top" title="Not Visible to Users" class="label label-danger"><i class="fa fa-eye-slash"></i></span> @endif
@if(! $variable->user_editable)<span data-toggle="tooltip" data-placement="top" title="Not Editable by Users" class="label label-danger"><i class="fa fa-edit"></i></span> @endif
{{ $variable->name }}
</label>
<div>
<input type="text" name="{{ $item->env_variable }}" class="form-control" value="{{ old($item->env_variable, $item->a_serverValue) }}" data-action="matchRegex" data-regex="{{ $item->regex }}" />
<input type="text" name="{{ $variable->env_variable }}" class="form-control" value="{{ old($variable->env_variable, (! $variable->server_value) ? $variable->default_value : $variable->server_value) }}" data-action="matchRegex" data-regex="{{ $variable->regex }}" />
</div>
<p class="text-muted"><small>{!! $item->description !!}<br />Regex: <code>{{ $item->regex }}</code><br />Access as: <code>&#123;&#123;{{$item->env_variable}}&#125;&#125;</code></small></p>
<p class="text-muted"><small>{!! $variable->description !!}<br />Regex: <code>{{ $variable->regex }}</code><br />Access as: <code>&#123;&#123;{{ $variable->env_variable }}&#125;&#125;</code></small></p>
</div>
@endforeach
</div>
@ -412,7 +418,7 @@
</div>
</form>
</div>
@if(count($databases) > 0)
@if(count($server->databases) > 0)
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
<div class="panel-body">
<table class="table table-bordered table-hover">
@ -426,12 +432,12 @@
</th>
</thead>
<tbody>
@foreach($databases as $database)
@foreach($server->databases as $database)
<tr>
<td>{{ $database->database }}</td>
<td>{{ $database->username }} ({{ $database->remote }})</td>
<td><code>{{ Crypt::decrypt($database->password) }}</code> <a href="#" data-action="reset-database-password" data-id="{{ $database->id }}"><i class="fa fa-refresh pull-right"></i></a></td>
<td><code>{{ $database->a_host }}:{{ $database->a_port }}</code></td>
<td><code>{{ $database->host->host }}:{{ $database->host->port }}</code></td>
<td class="text-center"><a href="#delete" data-action="delete_database" data-database="{{ $database->id }}" class="text-danger"><i class="fa fa-trash-o"></i></a></td>
</tr>
@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) {

View file

@ -39,7 +39,7 @@
<div class="col-md-6">
<fieldset>
<div class="form-group">
<label for="email" class="control-label">{{ trans('strings.email') }}</label>
<label for="email" class="control-label">Email</label>
<div>
<input type="text" name="email" value="{{ $user->email }}" class="form-control">
</div>
@ -64,7 +64,7 @@
</div>
<div class="form-group">
{!! csrf_field() !!}
<input type="submit" value="{{ trans('base.account.update_user') }}" class="btn btn-primary btn-sm">
<input type="submit" value="Update User" class="btn btn-primary btn-sm">
</div>
</fieldset>
</div>
@ -72,7 +72,7 @@
<div class="well" style="padding-bottom: 0;">
<div class="alert alert-success" style="display:none;margin-bottom:10px;" id="gen_pass"></div>
<div class="form-group">
<label for="password" class="control-label">{{ trans('strings.password') }}</label>
<label for="password" class="control-label">Password</label>
<div>
<input type="password" id="password" name="password" class="form-control">
</div>
@ -83,7 +83,7 @@
</div>
<div class="well" style="padding-bottom: 0;">
<div class="form-group">
<label for="root_admin" class="control-label">{{ trans('strings.root_administrator') }}</label>
<label for="root_admin" class="control-label">Administrator</label>
<div>
<select name="root_admin" class="form-control">
<option value="0">{{ trans('strings.no') }}</option>
@ -99,7 +99,7 @@
<div class="row">
<div class="col-md-12">
<h3>Associated Servers</h3><hr>
@if($servers)
@if($user->servers)
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
@ -112,12 +112,12 @@
</tr>
</thead>
<tbody>
@foreach($servers as $server)
@foreach($user->servers as $server)
<tr>
<td><a href="/server/{{ $server->uuidShort }}/"><i class="fa fa-tachometer"></i></a></td>
<td><code>{{ $server->uuidShort }}</code></td>
<td><a href="/admin/servers/view/{{ $server->id }}">{{ $server->name }}</a></td>
<td>{{ $server->node_idName }}</td>
<td>{{ $server->node->name }}</td>
<td><code>{{ $server->username }}</code></td>
<td class="centered">@if($server->suspended === 0)<span class="label muted muted-hover label-success">Active</span>@else<span class="label label-warning">Suspended</span>@endif</td>
</td>
@ -127,7 +127,7 @@
@else
<div class="alert alert-info">There are no servers associated with this account.</div>
@endif
<a href="/admin/servers/new?email={{ $user->email }}"><button type="button" class="btn btn-success btn-sm">{{ trans('server.index.add_new') }}</button></a>
<a href="/admin/servers/new?email={{ $user->email }}"><button type="button" class="btn btn-success btn-sm">Add New Server</button></a>
</div>
</div>
<div class="row">