Merge pull request #155 from Pterodactyl/feature/database-improvements

Foreign Keys & Deletion Improvements
This commit is contained in:
Dane Everitt 2016-10-27 20:29:52 -04:00 committed by GitHub
commit bcaaefbc64
28 changed files with 931 additions and 80 deletions

View file

@ -4,6 +4,7 @@ APP_KEY=SomeRandomString3232RandomString
APP_THEME=default
APP_TIMEZONE=UTC
APP_CLEAR_TASKLOG=720
APP_DELETE_MINUTES=10
CONSOLE_PUSH_FREQ=250
CONSOLE_PUSH_COUNT=10
@ -15,7 +16,6 @@ DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=database
QUEUE_DRIVER=database
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
@ -28,3 +28,12 @@ MAIL_FROM=you@example.com
API_PREFIX=api
API_VERSION=v1
API_DEBUG=false
QUEUE_DRIVER=database
QUEUE_HIGH=high
QUEUE_STANDARD=standard
QUEUE_LOW=low
SQS_KEY=aws-public
SQS_SECRET=aws-secret
SQS_QUEUE_PREFIX=aws-queue-prefix

View file

@ -74,7 +74,7 @@ class RunTasks extends Command
foreach ($tasks as &$task) {
$bar->advance();
$this->dispatch(new SendScheduledTask(Models\Server::findOrFail($task->server), $task));
$this->dispatch((new SendScheduledTask(Models\Server::findOrFail($task->server), $task))->onQueue(env('QUEUE_LOW', 'low')));
}
$bar->finish();

View file

@ -0,0 +1,44 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Events;
use Illuminate\Queue\SerializesModels;
class ServerDeleted
{
use SerializesModels;
public $server;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($id)
{
$this->server = $id;
}
}

View file

@ -51,7 +51,7 @@ class ServersController extends Controller
public function getIndex(Request $request)
{
$query = Models\Server::select(
$query = Models\Server::withTrashed()->select(
'servers.*',
'nodes.name as a_nodeName',
'users.email as a_ownerEmail',
@ -84,7 +84,7 @@ class ServersController extends Controller
$servers = $query->paginate(20);
} catch (\Exception $ex) {
Alert::warning('There was an error with the search parameters provided.');
$servers = Models\Server::select(
$servers = Models\Server::withTrashed()->select(
'servers.*',
'nodes.name as a_nodeName',
'users.email as a_ownerEmail',
@ -112,7 +112,7 @@ class ServersController extends Controller
public function getView(Request $request, $id)
{
$server = Models\Server::select(
$server = Models\Server::withTrashed()->select(
'servers.*',
'nodes.name as a_nodeName',
'users.email as a_ownerEmail',
@ -394,7 +394,7 @@ class ServersController extends Controller
try {
$server = new ServerRepository;
$server->deleteServer($id, $force);
Alert::success('Server was successfully deleted from the panel and the daemon.')->flash();
Alert::success('Server has been marked for deletion on the system.')->flash();
return redirect()->route('admin.servers');
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
@ -510,4 +510,31 @@ class ServersController extends Controller
}
}
public function postQueuedDeletionHandler(Request $request, $id)
{
try {
$repo = new ServerRepository;
if (!is_null($request->input('cancel'))) {
$repo->cancelDeletion($id);
Alert::success('Server deletion has been cancelled. This server will remain suspended until you unsuspend it.')->flash();
return redirect()->route('admin.servers.view', $id);
} else if(!is_null($request->input('delete'))) {
$repo->deleteNow($id);
Alert::success('Server was successfully deleted from the system.')->flash();
return redirect()->route('admin.servers');
} else if(!is_null($request->input('force_delete'))) {
$repo->deleteNow($id, true);
Alert::success('Server was successfully force deleted from the system.')->flash();
return redirect()->route('admin.servers');
}
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
return redirect()->route('admin.servers.view', $id);
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled error occured while attempting to perform this action.')->flash();
return redirect()->route('admin.servers.view', $id);
}
}
}

View file

@ -210,6 +210,11 @@ class AdminRoutes {
'uses' => 'Admin\ServersController@deleteServer'
]);
$router->post('/view/{id}/queuedDeletion', [
'uses' => 'Admin\ServersController@postQueuedDeletionHandler',
'as' => 'admin.servers.post.queuedDeletion'
]);
});
// Node Routes

67
app/Jobs/DeleteServer.php Normal file
View file

@ -0,0 +1,67 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Jobs;
use DB;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Pterodactyl\Models;
use Pterodactyl\Repositories\ServerRepository;
class DeleteServer extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* Id of server to be deleted.
* @var object
*/
protected $id;
/**
* Create a new job instance.
*
* @param integer $server
* @return void
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$repo = new ServerRepository;
$repo->deleteNow($this->id);
}
}

View file

@ -0,0 +1,65 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Jobs;
use Debugbar;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Pterodactyl\Repositories\ServerRepository;
class SuspendServer extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* ID of associated server model.
* @var object
*/
protected $id;
/**
* Create a new job instance.
*
* @param integer $id
* @return void
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$repo = new ServerRepository;
$repo->suspend($this->id, true);
}
}

View file

@ -0,0 +1,64 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2016 Dane Everitt <dane@daneeveritt.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Listeners;
use Carbon;
use Pterodactyl\Events\ServerDeleted;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Pterodactyl\Jobs\SuspendServer;
use Pterodactyl\Jobs\DeleteServer;
class DeleteServerListener
{
use DispatchesJobs;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param DeleteServerEvent $event
* @return void
*/
public function handle(ServerDeleted $event)
{
$this->dispatch((new SuspendServer($event->server))->onQueue(env('QUEUE_HIGH', 'high')));
$this->dispatch(
(new DeleteServer($event->server))
->delay(Carbon::now()->addMinutes(env('APP_DELETE_MINUTES', 10)))
->onQueue(env('QUEUE_STANDARD', 'standard'))
);
}
}

View file

@ -26,12 +26,15 @@ namespace Pterodactyl\Models;
use Auth;
use Pterodactyl\Models\Subuser;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Pterodactyl\Exceptions\DisplayException;
class Server extends Model
{
use SoftDeletes;
/**
* The table associated with the model.
*
@ -44,17 +47,21 @@ class Server extends Model
*
* @var array
*/
protected $hidden = [
'daemonSecret',
'sftp_password'
];
protected $hidden = ['daemonSecret', 'sftp_password'];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
* Fields that are not mass assignable.
*
* @var array
*/
protected $guarded = ['id', 'installed', 'created_at', 'updated_at'];
protected $guarded = ['id', 'installed', 'created_at', 'updated_at', 'deleted_at'];
/**
* Cast values to correct type.
@ -92,6 +99,7 @@ class Server extends Model
*/
public function __construct()
{
parent::__construct();
self::$user = Auth::user();
}
@ -181,10 +189,6 @@ class Server extends Model
$result = $query->first();
if (!$result) {
throw new DisplayException('No server was found belonging to this user.');
}
if(!is_null($result)) {
$result->daemonSecret = self::getUserDaemonSecret($result);
}

View file

@ -13,8 +13,8 @@ class EventServiceProvider extends ServiceProvider
* @var array
*/
protected $listen = [
'Pterodactyl\Events\SomeEvent' => [
'Pterodactyl\Listeners\EventListener',
'Pterodactyl\Events\ServerDeleted' => [
'Pterodactyl\Listeners\DeleteServerListener',
],
];

View file

@ -33,6 +33,7 @@ use Pterodactyl\Models;
use Pterodactyl\Services\UuidService;
use Pterodactyl\Services\DeploymentService;
use Pterodactyl\Notifications\ServerCreated;
use Pterodactyl\Events\ServerDeleted;
use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Exceptions\AccountNotFoundException;
@ -767,11 +768,37 @@ class ServerRepository
public function deleteServer($id, $force)
{
$server = Models\Server::findOrFail($id);
$node = Models\Node::findOrFail($server->node);
DB::beginTransaction();
try {
// Delete Allocations
if ($force === 'force' || $force === true) {
$server->installed = 3;
$server->save();
}
$server->delete();
DB::commit();
event(new ServerDeleted($server->id));
} catch (\Exception $ex) {
DB::rollBack();
throw $ex;
}
}
public function deleteNow($id, $force = false) {
$server = Models\Server::withTrashed()->findOrFail($id);
$node = Models\Node::findOrFail($server->node);
// Handle server being restored previously or
// an accidental queue.
if (!$server->trashed()) {
return;
}
DB::beginTransaction();
try {
// Unassign Allocations
Models\Allocation::where('assigned_to', $server->id)->update([
'assigned_to' => null
]);
@ -779,20 +806,23 @@ class ServerRepository
// Remove Variables
Models\ServerVariables::where('server_id', $server->id)->delete();
// Remove Permissions (Foreign Key requires before Subusers)
Models\Permission::where('server_id', $server->id)->delete();
// Remove SubUsers
Models\Subuser::where('server_id', $server->id)->delete();
// Remove Permissions
Models\Permission::where('server_id', $server->id)->delete();
// Remove Downloads
Models\Download::where('server', $server->uuid)->delete();
// Clear Tasks
Models\Task::where('server', $server->id)->delete();
// Delete Databases
$databases = Models\Database::select('id')->where('server_id', $server->id)->get();
// This is the one un-recoverable point where
// transactions will not save us.
$repository = new DatabaseRepository;
foreach($databases as &$database) {
// Use the repository to drop the database, we don't need to delete here because it is now gone.
foreach(Models\Database::select('id')->where('server_id', $server->id)->get() as &$database) {
$repository->drop($database->id);
}
@ -804,17 +834,16 @@ class ServerRepository
]
]);
$server->delete();
$server->forceDelete();
DB::commit();
return true;
} catch (\GuzzleHttp\Exception\TransferException $ex) {
if ($force === 'force') {
$server->delete();
// Set installed is set to 3 when force deleting.
if ($server->installed === 3 || $force) {
$server->forceDelete();
DB::commit();
return true;
} else {
DB::rollBack();
throw new DisplayException('An error occured while attempting to delete the server on the daemon.', $ex);
throw $ex;
}
} catch (\Exception $ex) {
DB::rollBack();
@ -822,6 +851,15 @@ class ServerRepository
}
}
public function cancelDeletion($id)
{
$server = Models\Server::withTrashed()->findOrFail($id);
$server->restore();
$server->installed = 1;
$server->save();
}
public function toggleInstall($id)
{
$server = Models\Server::findOrFail($id);
@ -837,9 +875,9 @@ class ServerRepository
* @param integer $id
* @return boolean
*/
public function suspend($id)
public function suspend($id, $deleted = false)
{
$server = Models\Server::findOrFail($id);
$server = ($deleted) ? Models\Server::withTrashed()->findOrFail($id) : Models\Server::findOrFail($id);
$node = Models\Node::findOrFail($server->node);
DB::beginTransaction();

View file

@ -8,28 +8,25 @@
"email": "dane@daneeveritt.com",
"homepage": "https://github.com/DaneEveritt",
"role": "Lead Developer"
},
{
"name": "Dylan Seidt",
"email": "dylan.seidt@gmail.com",
"role": "Developer"
}
],
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.6",
"barryvdh/laravel-debugbar": "^2.2.3",
"doctrine/dbal": "^2.5.4",
"guzzlehttp/guzzle": "^6.2.1",
"pragmarx/google2fa": "^1.0.1",
"webpatser/laravel-uuid": "^2.0",
"prologue/alerts": "^0.4.0",
"s1lentium/iptools": "^1.1.0",
"edvinaskrucas/settings": "^2.0",
"igaster/laravel-theme": "^1.1.3",
"nesbot/carbon": "^1.21",
"mtdowling/cron-expression": "^1.1",
"dingo/api": "1.0.0-beta6"
"laravel/framework": "5.3.21",
"barryvdh/laravel-debugbar": "2.2.3",
"doctrine/dbal": "2.5.5",
"guzzlehttp/guzzle": "6.2.2",
"pragmarx/google2fa": "1.0.1",
"webpatser/laravel-uuid": "2.0.1",
"prologue/alerts": "0.4.0",
"s1lentium/iptools": "1.1.0",
"edvinaskrucas/settings": "2.0.0",
"igaster/laravel-theme": "1.1.3",
"nesbot/carbon": "1.21.0",
"mtdowling/cron-expression": "1.1.0",
"dingo/api": "1.0.0-beta6",
"aws/aws-sdk-php": "3.19.20",
"predis/predis": "1.1.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",

View file

@ -38,38 +38,23 @@ return [
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'queue' => env('QUEUE_STANDARD'),
'retry_after' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'queue' => 'your-queue-url',
'region' => 'us-east-1',
],
'iron' => [
'driver' => 'iron',
'host' => 'mq-aws-us-east-1.iron.io',
'token' => 'your-token',
'project' => 'your-project-id',
'queue' => 'your-queue-name',
'encrypt' => true,
'key' => env('SQS_KEY'),
'secret' => env('SQS_SECRET'),
'prefix' => env('SQS_QUEUE_PREFIX'),
'queue' => env('QUEUE_STANDARD'),
'region' => env('SQS_REGION', 'us-east-1'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'queue' => env('QUEUE_STANDARD'),
'retry_after' => 60,
],

View file

@ -0,0 +1,65 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignKeysServers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE servers
MODIFY COLUMN node INT(10) UNSIGNED NOT NULL,
MODIFY COLUMN owner INT(10) UNSIGNED NOT NULL,
MODIFY COLUMN allocation INT(10) UNSIGNED NOT NULL,
MODIFY COLUMN service INT(10) UNSIGNED NOT NULL,
MODIFY COLUMN servers.option INT(10) UNSIGNED NOT NULL
');
Schema::table('servers', function (Blueprint $table) {
$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');
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
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->dropColumn('deleted_at');
});
DB::statement('ALTER TABLE servers
MODIFY COLUMN node MEDIUMINT(8) UNSIGNED NOT NULL,
MODIFY COLUMN owner MEDIUMINT(8) UNSIGNED NOT NULL,
MODIFY COLUMN allocation MEDIUMINT(8) UNSIGNED NOT NULL,
MODIFY COLUMN service MEDIUMINT(8) UNSIGNED NOT NULL,
MODIFY COLUMN servers.option MEDIUMINT(8) UNSIGNED NOT NULL
');
}
}

View file

@ -0,0 +1,47 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignAllocations extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE allocations
MODIFY COLUMN assigned_to INT(10) UNSIGNED NULL,
MODIFY COLUMN node INT(10) UNSIGNED NOT NULL
');
Schema::table('allocations', function (Blueprint $table) {
$table->foreign('assigned_to')->references('id')->on('servers');
$table->foreign('node')->references('id')->on('nodes');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('allocations', function (Blueprint $table) {
$table->dropForeign('allocations_assigned_to_foreign');
$table->dropForeign('allocations_node_foreign');
$table->dropIndex('allocations_assigned_to_foreign');
$table->dropIndex('allocations_node_foreign');
});
DB::statement('ALTER TABLE allocations
MODIFY COLUMN assigned_to MEDIUMINT(8) UNSIGNED NULL,
MODIFY COLUMN node MEDIUMINT(8) UNSIGNED NOT NULL
');
}
}

View file

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignApiKeys extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('api_keys', function (Blueprint $table) {
$table->foreign('user')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('api_keys', function (Blueprint $table) {
$table->dropForeign('api_keys_user_foreign');
$table->dropIndex('api_keys_user_foreign');
});
}
}

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignApiPermissions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE api_permissions MODIFY key_id INT(10) UNSIGNED NOT NULL');
Schema::table('api_permissions', function (Blueprint $table) {
$table->foreign('key_id')->references('id')->on('api_keys');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('api_permissions', function (Blueprint $table) {
$table->dropForeign('api_permissions_key_id_foreign');
$table->dropIndex('api_permissions_key_id_foreign');
});
DB::statement('ALTER TABLE api_permissions MODIFY key_id MEDIUMINT(8) UNSIGNED NOT NULL');
}
}

View file

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignDatabaseServers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('database_servers', function (Blueprint $table) {
$table->foreign('linked_node')->references('id')->on('nodes');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('database_servers', function (Blueprint $table) {
$table->dropForeign('database_servers_linked_node_foreign');
$table->dropIndex('database_servers_linked_node_foreign');
});
}
}

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignDatabases extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('databases', function (Blueprint $table) {
$table->foreign('server_id')->references('id')->on('servers');
$table->foreign('db_server')->references('id')->on('database_servers');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('databases', function (Blueprint $table) {
$table->dropForeign('databases_server_id_foreign');
$table->dropForeign('databases_db_server_foreign');
$table->dropIndex('databases_server_id_foreign');
$table->dropIndex('databases_db_server_foreign');
});
}
}

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignNodes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE nodes MODIFY location INT(10) UNSIGNED NOT NULL');
Schema::table('nodes', function (Blueprint $table) {
$table->foreign('location')->references('id')->on('locations');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('nodes', function (Blueprint $table) {
$table->dropForeign('nodes_location_foreign');
$table->dropIndex('nodes_location_foreign');
});
DB::statement('ALTER TABLE nodes MODIFY location MEDIUMINT(10) UNSIGNED NOT NULL');
}
}

View file

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignPermissions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('permissions', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('server_id')->references('id')->on('servers');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('permissions', function (Blueprint $table) {
$table->dropForeign('permissions_user_id_foreign');
$table->dropForeign('permissions_server_id_foreign');
$table->dropIndex('permissions_user_id_foreign');
$table->dropIndex('permissions_server_id_foreign');
});
}
}

View file

@ -0,0 +1,48 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignServerVariables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE server_variables
MODIFY COLUMN server_id INT(10) UNSIGNED NULL,
MODIFY COLUMN variable_id INT(10) UNSIGNED NOT NULL
');
Schema::table('server_variables', function (Blueprint $table) {
$table->foreign('server_id')->references('id')->on('servers');
$table->foreign('variable_id')->references('id')->on('service_variables');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('server_variables', function (Blueprint $table) {
$table->dropForeign('server_variables_server_id_foreign');
$table->dropForeign('server_variables_variable_id_foreign');
$table->dropIndex('server_variables_server_id_foreign');
$table->dropIndex('server_variables_variable_id_foreign');
});
DB::statement('ALTER TABLE allocations
MODIFY COLUMN server_id MEDIUMINT(8) UNSIGNED NULL,
MODIFY COLUMN variable_id MEDIUMINT(8) UNSIGNED NOT NULL
');
}
}

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignServiceOptions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE service_options MODIFY parent_service INT(10) UNSIGNED NOT NULL');
Schema::table('service_options', function (Blueprint $table) {
$table->foreign('parent_service')->references('id')->on('services');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('service_options', function (Blueprint $table) {
$table->dropForeign('service_options_parent_service_foreign');
$table->dropIndex('service_options_parent_service_foreign');
});
DB::statement('ALTER TABLE service_options MODIFY parent_service MEDIUMINT(8) UNSIGNED NOT NULL');
}
}

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignServiceVariables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement('ALTER TABLE service_variables MODIFY option_id INT(10) UNSIGNED NOT NULL');
Schema::table('service_variables', function (Blueprint $table) {
$table->foreign('option_id')->references('id')->on('service_options');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('service_variables', function (Blueprint $table) {
$table->dropForeign('service_variables_option_id_foreign');
$table->dropIndex('service_variables_option_id_foreign');
});
DB::statement('ALTER TABLE service_variables MODIFY option_id MEDIUMINT(8) UNSIGNED NOT NULL');
}
}

View file

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignSubusers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('subusers', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('server_id')->references('id')->on('servers');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('subusers', function (Blueprint $table) {
$table->dropForeign('subusers_user_id_foreign');
$table->dropForeign('subusers_server_id_foreign');
$table->dropIndex('subusers_user_id_foreign');
$table->dropIndex('subusers_server_id_foreign');
});
}
}

View file

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddForeignTasks extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tasks', function (Blueprint $table) {
$table->foreign('server')->references('id')->on('servers');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tasks', function (Blueprint $table) {
$table->dropForeign('tasks_server_foreign');
$table->dropForeign('tasks_server_foreign');
$table->dropIndex('tasks_server_foreign');
$table->dropIndex('tasks_server_foreign');
});
}
}

View file

@ -49,8 +49,21 @@
</thead>
<tbody>
@foreach ($servers as $server)
<tr @if($server->suspended === 1)class="warning"@endif data-server="{{ $server->uuidShort }}">
<td><a href="/admin/servers/view/{{ $server->id }}">{{ $server->name }}</a>@if($server->suspended === 1) <span class="label label-warning">Suspended</span>@endif</td>
<tr
@if($server->suspended === 1 && !$server->trashed())
class="warning"
@elseif($server->trashed())
class="danger"
@endif
data-server="{{ $server->uuidShort }}">
<td>
<a href="/admin/servers/view/{{ $server->id }}">{{ $server->name }}</a>
@if($server->suspended === 1 && !$server->trashed())
<span class="label label-warning">Suspended</span>
@elseif($server->trashed())
<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 class="hidden-xs"><code>{{ $server->username }}</code></td>

View file

@ -30,10 +30,21 @@
<li><a href="/admin/servers">Servers</a></li>
<li class="active">{{ $server->name }} ({{ $server->uuidShort}})</li>
</ul>
@if($server->suspended === 1)
<div class="alert alert-warning">
This server is suspended and has no user access. Processes cannot be started and files cannot be modified. All API access is disabled unless using a master token.
</div>
@if($server->suspended === 1 && !$server->trashed())
<div class="alert alert-warning">
This server is suspended and has no user access. Processes cannot be started and files cannot be modified. All API access is disabled unless using a master token.
</div>
@elseif($server->trashed())
<div class="alert alert-danger">
This server is marked for deletion <strong>{{ Carbon::parse($server->deleted_at)->addMinutes(env('APP_DELETE_MINUTES', 10))->diffForHumans() }}</strong>. If you want to cancel this action simply click the button below.
<br /><br />
<form action="{{ route('admin.servers.post.queuedDeletion', $server->id) }}" method="POST">
<button class="btn btn-sm btn-default" name="cancel" value="1">Cancel Deletion</button>
<button class="btn btn-sm btn-danger pull-right" name="force_delete" value="1"><strong>Force</strong> Delete</button>
<button class="btn btn-sm btn-danger pull-right" name="delete" style="margin-right:10px;" value="1">Delete</button>
{!! csrf_field() !!}
</form>
</div>
@endif
@if($server->installed === 0)
<div class="alert alert-warning">
@ -55,7 +66,7 @@
@if($server->installed !== 2)
<li><a href="#tab_manage" data-toggle="tab">Manage</a></li>
@endif
<li><a href="#tab_delete" data-toggle="tab">Delete</a></li>
@if(!$server->trashed())<li><a href="#tab_delete" data-toggle="tab">Delete</a></li>@endif
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_about">