Initial implementation of improved sever model and logic

This commit is contained in:
Dane Everitt 2017-02-02 18:21:36 -05:00
parent fb589a7f4e
commit d4bcf0be59
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
31 changed files with 223 additions and 158 deletions

View file

@ -21,6 +21,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
* User model now defines mass assignment fields using `$fillable` rather than `$guarded`.
* 2FA checkpoint on login is now its own page, and not an AJAX based call. Improves security on that front.
### Removed
* `Server::getUserDaemonSecret(Server $server)` was removed and replaced with `User::daemonSecret(Server $server)` in order to clean up models.
## v0.5.6 (Bodacious Boreopterus)
### Added
* Added the following languages: Estonian `et`, Dutch `nl`, Norwegian `nb` (partial), Romanian `ro`, and Russian `ru`. Interested in helping us translate the panel into more languages, or improving existing translations? Contact us on Discord and let us know.

View file

@ -122,7 +122,7 @@ class ServerController extends BaseController
'pack'
)->first();
if ($request->input('daemon') === 'true') {
$node = Models\Node::findOrFail($server->node);
$node = Models\Node::findOrFail($server->node_id);
$client = Models\Node::guzzleRequest($node->id);
$response = $client->request('GET', '/servers', [

View file

@ -37,7 +37,7 @@ class InfoController extends BaseController
'id' => $server->uuidShort,
'uuid' => $server->uuid,
'name' => $server->name,
'node' => $server->nodeName,
'node' => $server->node_idName,
'ip' => [
'set' => $server->ip,
'alias' => $server->ip_alias,

View file

@ -35,7 +35,7 @@ class ServerController extends BaseController
public function info(Request $request, $uuid)
{
$server = Models\Server::getByUUID($uuid);
$node = Models\Node::findOrFail($server->node);
$node = Models\Node::findOrFail($server->node_id);
$client = Models\Node::guzzleRequest($node->id);
try {
@ -61,7 +61,7 @@ class ServerController extends BaseController
$allocations = Models\Allocation::select('id', 'ip', 'port', 'ip_alias as alias')->where('assigned_to', $server->id)->get();
foreach ($allocations as &$allocation) {
$allocation->default = ($allocation->id === $server->allocation);
$allocation->default = ($allocation->id === $server->allocation_id);
unset($allocation->id);
}
@ -92,7 +92,7 @@ class ServerController extends BaseController
public function power(Request $request, $uuid)
{
$server = Models\Server::getByUUID($uuid);
$client = Models\Node::guzzleRequest($server->node);
$client = Models\Node::guzzleRequest($server->node_id);
Auth::user()->can('power-' . $request->input('action'), $server);

View file

@ -108,8 +108,8 @@ class NodesController extends Controller
return view('admin.nodes.view', [
'node' => $node,
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail', 'services.name as a_serviceName')
->join('users', 'users.id', '=', 'servers.owner')
->join('services', 'services.id', '=', 'servers.service')
->join('users', 'users.id', '=', 'servers.owner_id')
->join('services', 'services.id', '=', 'servers.service_id')
->where('node', $id)->paginate(10, ['*'], 'servers'),
'stats' => Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(),
'locations' => Models\Location::all(),

View file

@ -54,9 +54,9 @@ class ServersController extends Controller
'allocations.ip',
'allocations.port',
'allocations.ip_alias'
)->join('nodes', 'servers.node', '=', 'nodes.id')
->join('users', 'servers.owner', '=', 'users.id')
->join('allocations', 'servers.allocation', '=', 'allocations.id');
)->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);
@ -96,9 +96,9 @@ class ServersController extends Controller
'allocations.ip',
'allocations.port',
'allocations.ip_alias'
)->join('nodes', 'servers.node', '=', 'nodes.id')
->join('users', 'servers.owner', '=', 'users.id')
->join('allocations', 'servers.allocation', '=', 'allocations.id')
)->join('nodes', 'servers.node_id', '=', 'nodes.id')
->join('users', 'servers.owner_id', '=', 'users.id')
->join('allocations', 'servers.allocation_id', '=', 'allocations.id')
->paginate(20);
}
@ -127,11 +127,11 @@ class ServersController extends Controller
'allocations.ip',
'allocations.port',
'allocations.ip_alias'
)->join('nodes', 'servers.node', '=', 'nodes.id')
->join('users', 'servers.owner', '=', 'users.id')
->join('services', 'servers.service', '=', 'services.id')
->join('service_options', 'servers.option', '=', 'service_options.id')
->join('allocations', 'servers.allocation', '=', 'allocations.id')
)->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();
@ -145,13 +145,13 @@ class ServersController extends Controller
'nodes.*',
'locations.long as a_locationName'
)->join('locations', 'nodes.location', '=', 'locations.id')
->where('nodes.id', $server->node)
->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)->whereNull('assigned_to')->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)
->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')
@ -334,8 +334,8 @@ class ServersController extends Controller
public function postUpdateServerToggleBuild(Request $request, $id)
{
$server = Models\Server::findOrFail($id);
$node = Models\Node::findOrFail($server->node);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::findOrFail($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
try {
$res = $client->request('POST', '/server/rebuild', [

View file

@ -137,7 +137,7 @@ class ServiceController extends Controller
'option' => $opt,
'variables' => Models\ServiceVariables::where('option_id', $option)->get(),
'servers' => Models\Server::select('servers.*', 'users.email as a_ownerEmail')
->join('users', 'users.id', '=', 'servers.owner')
->join('users', 'users.id', '=', 'servers.owner_id')
->where('option', $option)
->paginate(10),
]);

View file

@ -87,7 +87,7 @@ class UserController extends Controller
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', '=', 'nodes.id')
->join('nodes', 'servers.node_id', '=', 'nodes.id')
->join('locations', 'nodes.location', '=', 'locations.id')
->where('owner', $id)
->get(),

View file

@ -66,7 +66,7 @@ class RemoteController extends Controller
], 422);
}
$node = Models\Node::findOrFail($server->node);
$node = Models\Node::findOrFail($server->node_id);
$hmac = $request->input('signed');
$status = $request->input('installed');
@ -93,7 +93,7 @@ class RemoteController extends Controller
], 422);
}
$node = Models\Node::findOrFail($server->node);
$node = Models\Node::findOrFail($server->node_id);
$hmac = $request->input('signed');
if (base64_decode($hmac) !== hash_hmac('sha256', $server->uuid, $node->daemonSecret, true)) {

View file

@ -73,7 +73,7 @@ class AjaxController extends Controller
return response()->json([], 404);
}
$client = Models\Node::guzzleRequest($server->node);
$client = Models\Node::guzzleRequest($server->node_id);
try {
$res = $client->request('GET', '/server', [
@ -178,7 +178,7 @@ class AjaxController extends Controller
$server = Models\Server::getByUUID($uuid);
$this->authorize('set-connection', $server);
if ((int) $request->input('allocation') === $server->allocation) {
if ((int) $request->input('allocation') === $server->allocation_id) {
return response()->json([
'error' => 'You are already using this as your default connection.',
], 409);

View file

@ -55,14 +55,13 @@ class ServerController extends Controller
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\View
*/
public function getIndex(Request $request)
public function getIndex(Request $request, $uuid)
{
$server = Models\Server::getByUUID($request->route()->server);
$node = Models\Node::find($server->node);
$server = Models\Server::byUuid($uuid);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'daemonSecret', 'username']),
'node' => collect($node)->only('fqdn', 'scheme', 'daemonListen'),
'node' => collect($server->node_id)->only('fqdn', 'scheme', 'daemonListen'),
'meta' => [
'saveFile' => route('server.files.save', $server->uuidShort),
'csrfToken' => csrf_token(),
@ -71,7 +70,7 @@ class ServerController extends Controller
return view('server.index', [
'server' => $server,
'node' => $node,
'node' => $server->node_id,
]);
}
@ -86,7 +85,7 @@ class ServerController extends Controller
$server = Models\Server::getByUUID($uuid);
$this->authorize('list-files', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only('uuid', 'uuidShort', 'daemonSecret'),
@ -122,7 +121,7 @@ class ServerController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('add-files', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
@ -148,7 +147,7 @@ class ServerController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('edit-files', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
$fileInfo = (object) pathinfo($file);
$controller = new FileRepository($uuid);
@ -193,7 +192,7 @@ class ServerController extends Controller
public function getDownloadFile(Request $request, $uuid, $file)
{
$server = Models\Server::getByUUID($uuid);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
$this->authorize('download-files', $server);
@ -212,7 +211,7 @@ class ServerController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('view-allocation', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
@ -230,8 +229,8 @@ class ServerController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('view-startup', $server);
$node = Models\Node::find($server->node);
$allocation = Models\Allocation::findOrFail($server->allocation);
$node = Models\Node::find($server->node_id);
$allocation = Models\Allocation::findOrFail($server->allocation_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
@ -242,15 +241,15 @@ class ServerController extends Controller
'service_variables.*',
DB::raw('COALESCE(server_variables.variable_value, service_variables.default_value) as a_serverValue')
)->leftJoin('server_variables', 'server_variables.variable_id', '=', 'service_variables.id')
->where('service_variables.option_id', $server->option)
->where('service_variables.option_id', $server->option_id)
->where('server_variables.server_id', $server->id)
->get();
$service = Models\Service::select(
DB::raw('IFNULL(service_options.executable, services.executable) as executable')
)->leftJoin('service_options', 'service_options.parent_service', '=', 'services.id')
->where('service_options.id', $server->option)
->where('services.id', $server->service)
->where('service_options.id', $server->option_id)
->where('services.id', $server->service_id)
->first();
$serverVariables = [
@ -267,7 +266,7 @@ class ServerController extends Controller
return view('server.settings.startup', [
'server' => $server,
'node' => Models\Node::find($server->node),
'node' => Models\Node::find($server->node_id),
'variables' => $variables->where('user_viewable', 1),
'service' => $service,
'processedStartup' => $processed,
@ -278,7 +277,7 @@ class ServerController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('view-databases', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
@ -299,7 +298,7 @@ class ServerController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('view-sftp', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'daemonSecret', 'username']),

View file

@ -52,7 +52,7 @@ class SubuserController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('list-subusers', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
@ -73,7 +73,7 @@ class SubuserController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('view-subuser', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
@ -150,7 +150,7 @@ class SubuserController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('create-subuser', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),

View file

@ -45,7 +45,7 @@ class TaskController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('list-tasks', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),
@ -67,7 +67,7 @@ class TaskController extends Controller
{
$server = Models\Server::getByUUID($uuid);
$this->authorize('create-task', $server);
$node = Models\Node::find($server->node);
$node = Models\Node::find($server->node_id);
Javascript::put([
'server' => collect($server->makeVisible('daemonSecret'))->only(['uuid', 'uuidShort', 'daemonSecret', 'username']),

View file

@ -26,6 +26,7 @@ namespace Pterodactyl\Http\Middleware;
use Auth;
use Closure;
use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
class CheckServer
@ -37,22 +38,22 @@ class CheckServer
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
public function handle(Request $request, Closure $next)
{
if (! Auth::user()) {
return redirect()->guest('auth/login');
}
$server = Server::getByUUID($request->route()->server);
$server = Server::byUuid($request->route()->server);
if (! $server) {
return response()->view('errors.404', [], 404);
}
if ($server->suspended === 1) {
if ($server->suspended) {
return response()->view('errors.suspended', [], 403);
}
if ($server->installed !== 1) {
if (! $server->installed) {
return response()->view('errors.installing', [], 403);
}

View file

@ -101,28 +101,6 @@ class Server extends Model
self::$user = Auth::user();
}
/**
* Determine if we need to change the server's daemonSecret value to
* match that of the user if they are a subuser.
*
* @param Illuminate\Database\Eloquent\Model\Server $server
* @return string
*/
public static function getUserDaemonSecret(Server $server)
{
if (self::$user->id === $server->owner || self::$user->root_admin === 1) {
return $server->daemonSecret;
}
$subuser = Subuser::where('server_id', $server->id)->where('user_id', self::$user->id)->first();
if (is_null($subuser)) {
return null;
}
return $subuser->daemonSecret;
}
/**
* Returns array of all servers owned by the logged in user.
* Returns all users servers if user is a root admin.
@ -140,11 +118,11 @@ class Server extends Model
'allocations.port',
'services.name as a_serviceName',
'service_options.name as a_serviceOptionName'
)->join('nodes', 'servers.node', '=', 'nodes.id')
)->join('nodes', 'servers.node_id', '=', 'nodes.id')
->join('locations', 'nodes.location', '=', 'locations.id')
->join('services', 'servers.service', '=', 'services.id')
->join('service_options', 'servers.option', '=', 'service_options.id')
->join('allocations', 'servers.allocation', '=', 'allocations.id');
->join('services', 'servers.service_id', '=', 'services.id')
->join('service_options', 'servers.option_id', '=', 'service_options.id')
->join('allocations', 'servers.allocation_id', '=', 'allocations.id');
if (self::$user->root_admin !== 1) {
$query->whereIn('servers.id', Subuser::accessServers());
@ -165,30 +143,21 @@ class Server extends Model
* @param string $uuid The Short-UUID of the server to return an object about.
* @return \Illuminate\Database\Eloquent\Collection
*/
public static function getByUUID($uuid)
public static function byUuid($uuid)
{
if (array_key_exists($uuid, self::$serverUUIDInstance)) {
return self::$serverUUIDInstance[$uuid];
}
$query = self::with('service', 'node')->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
$query = self::select('servers.*', 'services.file as a_serviceFile')
->join('services', 'services.id', '=', 'servers.service')
->where('uuidShort', $uuid)
->orWhere('uuid', $uuid);
if (self::$user->root_admin !== 1) {
$query->whereIn('servers.id', Subuser::accessServers());
if (! Auth::user()->isRootAdmin()) {
$query->whereIn('id', Subuser::accessServers());
}
$result = $query->first();
if (! is_null($result)) {
$result->daemonSecret = self::getUserDaemonSecret($result);
$result->daemonSecret = Auth::user()->daemonToken($result);
}
self::$serverUUIDInstance[$uuid] = $result;
return self::$serverUUIDInstance[$uuid];
return $result;
}
/**
@ -197,18 +166,14 @@ class Server extends Model
* @param string $uuid
* @return array
*/
public static function getGuzzleHeaders($uuid)
public function getHeaders()
{
if (array_key_exists($uuid, self::$serverUUIDInstance)) {
return [
'X-Access-Server' => self::$serverUUIDInstance[$uuid]->uuid,
'X-Access-Token' => self::$serverUUIDInstance[$uuid]->daemonSecret,
'X-Access-Server' => $this->uuid,
'X-Access-Token' => Auth::user()->daemonToken($this),
];
}
return [];
}
/**
* Gets all allocations associated with this server.
*
@ -226,7 +191,7 @@ class Server extends Model
*/
public function pack()
{
return $this->hasOne(ServicePack::class, 'id', 'pack');
return $this->hasOne(ServicePack::class, 'id', 'pack_id');
}
/**
@ -236,7 +201,7 @@ class Server extends Model
*/
public function service()
{
return $this->hasOne(Service::class, 'id', 'service');
return $this->hasOne(Service::class, 'id', 'service_id');
}
/**
@ -246,7 +211,7 @@ class Server extends Model
*/
public function option()
{
return $this->hasOne(ServiceOptions::class, 'id', 'option');
return $this->hasOne(ServiceOptions::class, 'id', 'option_id');
}
/**
@ -258,4 +223,14 @@ class Server extends Model
{
return $this->hasMany(ServerVariables::class);
}
/**
* Gets information for the node associated with this server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function node()
{
return $this->hasOne(Node::class, 'id', 'node_id');
}
}

View file

@ -24,6 +24,7 @@
namespace Pterodactyl\Models;
use Auth;
use Hash;
use Google2FA;
use Illuminate\Auth\Authenticatable;
@ -156,4 +157,24 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
{
return $this->root_admin === 1;
}
/**
* Returns the user's daemon secret for a given server.
* @param Server $server \Pterodactyl\Models\Server
* @return null|string
*/
public function daemonToken(Server $server)
{
if ($this->id === $server->owner_id || $this->isRootAdmin()) {
return $server->daemonSecret;
}
$subuser = Subuser::where('server_id', $server->id)->where('user_id', $this->id)->first();
if (is_null($subuser)) {
return null;
}
return $subuser->daemonSecret;
}
}

View file

@ -59,12 +59,12 @@ class ServerObserver
event(new Events\Server\Created($server));
// Queue Notification Email
$user = Models\User::findOrFail($server->owner);
$node = Models\Node::select('name')->where('id', $server->node)->first();
$user = Models\User::findOrFail($server->owner_id);
$node = Models\Node::select('name')->where('id', $server->node_id)->first();
$service = Models\Service::select('services.name', 'service_options.name as optionName')
->join('service_options', 'service_options.parent_service', '=', 'services.id')
->where('services.id', $server->service)
->where('service_options.id', $server->option)
->where('services.id', $server->service_id)
->where('service_options.id', $server->option_id)
->first();
$user->notify((new ServerCreated([

View file

@ -48,7 +48,7 @@ class ServerPolicy
*/
protected function isOwner(User $user, Server $server)
{
return $server->owner === $user->id;
return $server->owner_id === $user->id;
}
/**

View file

@ -374,7 +374,7 @@ class ServerRepository
try {
$server = Models\Server::findOrFail($id);
$owner = Models\User::findOrFail($server->owner);
$owner = Models\User::findOrFail($server->owner_id);
// Update daemon secret if it was passed.
if ((isset($data['reset_token']) && $data['reset_token'] === true) || (isset($data['owner']) && $data['owner'] !== $owner->email)) {
@ -386,7 +386,7 @@ class ServerRepository
// Update Server Owner if it was passed.
if (isset($data['owner']) && $data['owner'] !== $owner->email) {
$newOwner = Models\User::select('id')->where('email', $data['owner'])->first();
$server->owner = $newOwner->id;
$server->owner_id = $newOwner->id;
}
// Update Server Name if it was passed.
@ -405,8 +405,8 @@ class ServerRepository
}
// If we need to update do it here.
$node = Models\Node::getByID($server->node);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::getByID($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
$res = $client->request('PATCH', '/server', [
'headers' => [
@ -461,8 +461,8 @@ class ServerRepository
$server->image = $data['image'];
$server->save();
$node = Models\Node::getByID($server->node);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::getByID($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
$client->request('PATCH', '/server', [
'headers' => [
@ -520,7 +520,7 @@ class ServerRepository
try {
$server = Models\Server::findOrFail($id);
$allocation = Models\Allocation::findOrFail($server->allocation);
$allocation = Models\Allocation::findOrFail($server->allocation_id);
$newBuild = [];
@ -532,14 +532,14 @@ class ServerRepository
throw new DisplayException('The requested default connection (' . $ip . ':' . $port . ') is not allocated to this server.');
}
$server->allocation = $selection->id;
$server->allocation_id = $selection->id;
$newBuild['default'] = [
'ip' => $ip,
'port' => (int) $port,
];
// Re-Run to keep updated for rest of function
$allocation = Models\Allocation::findOrFail($server->allocation);
$allocation = Models\Allocation::findOrFail($server->allocation_id);
}
}
@ -635,8 +635,8 @@ class ServerRepository
$server->save();
if (! empty($newBuild)) {
$node = Models\Node::getByID($server->node);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::getByID($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
$client->request('PATCH', '/server', [
'headers' => [
@ -679,7 +679,7 @@ class ServerRepository
'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)
->where('option_id', $server->option_id)
->get();
$variableList = [];
@ -747,8 +747,8 @@ class ServerRepository
$model->save();
}
$node = Models\Node::getByID($server->node);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::getByID($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
$client->request('PATCH', '/server', [
'headers' => [
@ -797,7 +797,7 @@ class ServerRepository
public function deleteNow($id, $force = false)
{
$server = Models\Server::withTrashed()->findOrFail($id);
$node = Models\Node::findOrFail($server->node);
$node = Models\Node::findOrFail($server->node_id);
// Handle server being restored previously or
// an accidental queue.
@ -835,7 +835,7 @@ class ServerRepository
$repository->drop($database->id);
}
$client = Models\Node::guzzleRequest($server->node);
$client = Models\Node::guzzleRequest($server->node_id);
$client->request('DELETE', '/servers', [
'headers' => [
'X-Access-Token' => $node->daemonSecret,
@ -888,7 +888,7 @@ 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);
$node = Models\Node::findOrFail($server->node_id);
DB::beginTransaction();
@ -902,7 +902,7 @@ class ServerRepository
$server->suspended = 1;
$server->save();
$client = Models\Node::guzzleRequest($server->node);
$client = Models\Node::guzzleRequest($server->node_id);
$client->request('POST', '/server/suspend', [
'headers' => [
'X-Access-Token' => $node->daemonSecret,
@ -928,7 +928,7 @@ class ServerRepository
public function unsuspend($id)
{
$server = Models\Server::findOrFail($id);
$node = Models\Node::findOrFail($server->node);
$node = Models\Node::findOrFail($server->node_id);
DB::beginTransaction();
@ -942,7 +942,7 @@ class ServerRepository
$server->suspended = 0;
$server->save();
$client = Models\Node::guzzleRequest($server->node);
$client = Models\Node::guzzleRequest($server->node_id);
$client->request('POST', '/server/unsuspend', [
'headers' => [
'X-Access-Token' => $node->daemonSecret,
@ -963,7 +963,7 @@ class ServerRepository
public function updateSFTPPassword($id, $password)
{
$server = Models\Server::findOrFail($id);
$node = Models\Node::findOrFail($server->node);
$node = Models\Node::findOrFail($server->node_id);
$validator = Validator::make([
'password' => $password,
@ -981,7 +981,7 @@ class ServerRepository
try {
$server->save();
$client = Models\Node::guzzleRequest($server->node);
$client = Models\Node::guzzleRequest($server->node_id);
$client->request('POST', '/server/password', [
'headers' => [
'X-Access-Token' => $node->daemonSecret,

View file

@ -146,7 +146,7 @@ class SubuserRepository
} catch (\Exception $ex) {
throw $ex;
}
} elseif ($server->owner === $user->id) {
} elseif ($server->owner_id === $user->id) {
throw new DisplayException('You cannot add the owner of a server as a subuser.');
} elseif (Models\Subuser::select('id')->where('user_id', $user->id)->where('server_id', $server->id)->first()) {
throw new DisplayException('A subuser with that email already exists for this server.');
@ -184,8 +184,8 @@ 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);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::getByID($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
$res = $client->request('PATCH', '/server', [
'headers' => [
@ -240,8 +240,8 @@ class SubuserRepository
try {
Models\Permission::where('user_id', $subuser->user_id)->where('server_id', $subuser->server_id)->delete();
$node = Models\Node::getByID($server->node);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::getByID($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
$res = $client->request('PATCH', '/server', [
'headers' => [
@ -318,8 +318,8 @@ 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);
$client = Models\Node::guzzleRequest($server->node);
$node = Models\Node::getByID($server->node_id);
$client = Models\Node::guzzleRequest($server->node_id);
$res = $client->request('PATCH', '/server', [
'headers' => [

View file

@ -48,7 +48,7 @@ class NotificationService
public function __construct(Server $server)
{
$this->server = $server;
$this->user = User::findOrFail($server->owner);
$this->user = User::findOrFail($server->owner_id);
}
public function pass(array $notification)

View file

@ -24,7 +24,7 @@ class ModifyIpStorageMethod extends Migration
[
'ip' => $server->ip,
'port' => $server->port,
'node' => $server->node,
'node' => $server->node_id,
]
);
@ -61,7 +61,7 @@ class ModifyIpStorageMethod extends Migration
// Find the allocations and reset the servers...
$servers = DB::select('SELECT id, allocation FROM servers');
foreach ($servers as $server) {
$allocation = DB::select('SELECT * FROM allocations WHERE id = :alocid', ['alocid' => $server->allocation]);
$allocation = DB::select('SELECT * FROM allocations WHERE id = :alocid', ['alocid' => $server->allocation_id]);
if (isset($allocation[0])) {
DB::update(

View file

@ -22,7 +22,7 @@ class AddDockerImageColumn extends Migration
$servers = DB::table('servers')->select(
'servers.id',
'service_options.docker_image as s_optionImage'
)->join('service_options', 'service_options.id', '=', 'servers.option')->get();
)->join('service_options', 'service_options.id', '=', 'servers.option_id')->get();
foreach ($servers as $server) {
$server->image = $server->s_optionImage;

View file

@ -0,0 +1,66 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class UpdateColumnNames extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('servers', function (Blueprint $table) {
$table->dropForeign('servers_node_foreign');
$table->dropForeign('servers_owner_foreign');
$table->dropForeign('servers_allocation_foreign');
$table->dropForeign('servers_service_foreign');
$table->dropForeign('servers_option_foreign');
$table->dropIndex('servers_node_foreign');
$table->dropIndex('servers_owner_foreign');
$table->dropIndex('servers_allocation_foreign');
$table->dropIndex('servers_service_foreign');
$table->dropIndex('servers_option_foreign');
$table->renameColumn('node', 'node_id');
$table->renameColumn('owner', 'owner_id');
$table->renameColumn('allocation', 'allocation_id');
$table->renameColumn('service', 'service_id');
$table->renameColumn('option', 'option_id');
$table->renameColumn('pack', 'pack_id');
$table->foreign('node_id')->references('id')->on('nodes');
$table->foreign('owner_id')->references('id')->on('users');
$table->foreign('allocation_id')->references('id')->on('allocations');
$table->foreign('service_id')->references('id')->on('services');
$table->foreign('option_id')->references('id')->on('service_options');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('servers', function (Blueprint $table) {
$table->renameColumn('node_id', 'node');
$table->renameColumn('owner_id', 'owner');
$table->renameColumn('allocation_id', 'allocation');
$table->renameColumn('service_id', 'service');
$table->renameColumn('option_id', 'option');
$table->renameColumn('pack_id', 'pack');
$table->foreign('node')->references('id')->on('nodes');
$table->foreign('owner')->references('id')->on('users');
$table->foreign('allocation')->references('id')->on('allocations');
$table->foreign('service')->references('id')->on('services');
$table->foreign('option')->references('id')->on('service_options');
});
}
}

View file

@ -62,7 +62,7 @@
<tr class="dynamic-update" data-server="{{ $server->uuidShort }}">
<td><code>{{ $server->uuidShort }}</code></td>
<td><a href="{{ route('server.index', $server->uuidShort) }}">{{ $server->name }}</a></td>
<td>{{ $server->nodeName }}</td>
<td>{{ $server->node_idName }}</td>
<td><code>@if(!is_null($server->ip_alias)){{ $server->ip_alias }}@else{{ $server->ip }}@endif:{{ $server->port }}</code></td>
<td class="text-center hidden-sm hidden-xs"><span data-action="memory">--</span> / {{ $server->memory === 0 ? '&infin;' : $server->memory }} MB</td>
<td class="text-center hidden-sm hidden-xs"><span data-action="cpu" data-cpumax="{{ $server->cpu }}">--</span> %</td>

View file

@ -63,7 +63,7 @@
</td>
<td><code>{{ $allocation->port }}</code></td>
<td class="col-xs-2 middle">
@if($allocation->id === $server->allocation)
@if($allocation->id === $server->allocation_id)
<span class="label label-success" data-allocation="{{ $allocation->id }}">@lang('strings.primary')</span>
@else
<span class="label label-default" data-action="set-connection" data-allocation="{{ $allocation->id }}">@lang('strings.make_primary')</span>

View file

@ -405,7 +405,7 @@
@foreach($servers as $server)
<tr data-server="{{ $server->uuid }}">
<td><a href="/admin/servers/view/{{ $server->id }}">{{ $server->name }}</a></td>
<td><a href="/admin/users/view/{{ $server->owner }}"><code>{{ $server->a_ownerEmail }}</a></a></td>
<td><a href="/admin/users/view/{{ $server->owner_id }}"><code>{{ $server->a_ownerEmail }}</a></a></td>
<td>{{ $server->a_serviceName }}</td>
<td class="text-center"><span data-action="memory">--</span> / {{ $server->memory === 0 ? '&infin;' : $server->memory }} MB</td>
<td class="text-center">{{ $server->disk }} MB</td>

View file

@ -64,8 +64,8 @@
<span class="label label-danger">Pending Deletion</span>
@endif
</td>
<td><a href="/admin/users/view/{{ $server->owner }}">{{ $server->a_ownerEmail }}</a></td>
<td><a href="/admin/nodes/view/{{ $server->node }}">{{ $server->a_nodeName }}</a></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 class="hidden-xs"><code>{{ $server->username }}</code></td>
</tr>
@endforeach

View file

@ -89,7 +89,7 @@
</tr>
<tr>
<td>Owner</td>
<td><a href="{{ route('admin.users.view', $server->owner) }}">{{ $server->a_ownerEmail }}</a></td>
<td><a href="{{ route('admin.users.view', $server->owner_id) }}">{{ $server->a_ownerEmail }}</a></td>
</tr>
<tr>
<td>Location</td>
@ -97,7 +97,7 @@
</tr>
<tr>
<td>Node</td>
<td><a href="{{ route('admin.nodes.view', $server->node) }}">{{ $node->name }}</a></td>
<td><a href="{{ route('admin.nodes.view', $server->node_id) }}">{{ $node->name }}</a></td>
</tr>
<tr>
<td>Service</td>
@ -304,7 +304,7 @@
<div>
<select name="remove_additional[]" class="form-control" multiple>
@foreach ($assigned as $assignment)
<option value="{{ $assignment->ip }}:{{ $assignment->port }}" @if($server->allocation === $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>@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>
@endforeach
</select>
</div>
@ -398,7 +398,7 @@
<label class="control-label">Database Server:</label>
<select name="db_server" class="form-control">
@foreach($db_servers as $dbs)
<option value="{{ $dbs->id }}" @if($dbs->linked_node === $server->node)selected="selected"@endif>{{ $dbs->name }} ({{ $dbs->host }}:{{ $dbs->port }})</option>
<option value="{{ $dbs->id }}" @if($dbs->linked_node === $server->node_id)selected="selected"@endif>{{ $dbs->name }} ({{ $dbs->host }}:{{ $dbs->port }})</option>
@endforeach
</select>
</div>

View file

@ -178,7 +178,7 @@
@foreach ($servers as $server)
<tr>
<td><a href="{{ route('admin.servers.view', $server->id) }}">{{ $server->name }}</a></td>
<td><a href="{{ route('admin.users.view', $server->owner) }}">{{ $server->a_ownerEmail }}</a></td>
<td><a href="{{ route('admin.users.view', $server->owner_id) }}">{{ $server->a_ownerEmail }}</a></td>
<td>{{ $server->updated_at }}</td>
</tr>
@endforeach

View file

@ -117,7 +117,7 @@
<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->nodeName }}</td>
<td>{{ $server->node_idName }}</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>