diff --git a/app/Console/Commands/Server/BulkPowerActionCommand.php b/app/Console/Commands/Server/BulkPowerActionCommand.php index 460df719..01607bec 100644 --- a/app/Console/Commands/Server/BulkPowerActionCommand.php +++ b/app/Console/Commands/Server/BulkPowerActionCommand.php @@ -89,9 +89,7 @@ class BulkPowerActionCommand extends Command */ protected function getQueryBuilder(array $servers, array $nodes) { - $instance = Server::query() - ->where('suspended', false) - ->where('installed', Server::STATUS_INSTALLED); + $instance = Server::query()->whereNull('status'); if (!empty($nodes) && !empty($servers)) { $instance->whereIn('id', $servers)->orWhereIn('node_id', $nodes); diff --git a/app/Contracts/Repository/ServerRepositoryInterface.php b/app/Contracts/Repository/ServerRepositoryInterface.php index 323e1cd3..fc3e6ff1 100644 --- a/app/Contracts/Repository/ServerRepositoryInterface.php +++ b/app/Contracts/Repository/ServerRepositoryInterface.php @@ -66,11 +66,6 @@ interface ServerRepositoryInterface extends RepositoryInterface */ public function isUniqueUuidCombo(string $uuid, string $short): bool; - /** - * Get the amount of servers that are suspended. - */ - public function getSuspendedServersCount(): int; - /** * Returns all of the servers that exist for a given node in a paginated response. */ diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php deleted file mode 100644 index 5601e98e..00000000 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ /dev/null @@ -1,99 +0,0 @@ -allocationRepository = $allocationRepository; - $this->databaseRepository = $databaseRepository; - $this->eggRepository = $eggRepository; - $this->nodeRepository = $nodeRepository; - $this->serverRepository = $serverRepository; - $this->userRepository = $userRepository; - } - - public function index() - { - throw new NotFoundHttpException(); - $servers = $this->serverRepository->all(); - $nodes = $this->nodeRepository->all(); - $usersCount = $this->userRepository->count(); - $eggsCount = $this->eggRepository->count(); - $databasesCount = $this->databaseRepository->count(); - $totalAllocations = $this->allocationRepository->count(); - $suspendedServersCount = $this->serverRepository->getSuspendedServersCount(); - - $totalServerRam = 0; - $totalNodeRam = 0; - $totalServerDisk = 0; - $totalNodeDisk = 0; - foreach ($nodes as $node) { - $stats = $this->nodeRepository->getUsageStatsRaw($node); - $totalServerRam += $stats['memory']['value']; - $totalNodeRam += $stats['memory']['max']; - $totalServerDisk += $stats['disk']['value']; - $totalNodeDisk += $stats['disk']['max']; - } - - $tokens = []; - foreach ($nodes as $node) { - $tokens[$node->id] = decrypt($node->daemon_token); - } - - $this->injectJavascript([ - 'servers' => $servers, - 'suspendedServers' => $suspendedServersCount, - 'totalServerRam' => $totalServerRam, - 'totalNodeRam' => $totalNodeRam, - 'totalServerDisk' => $totalServerDisk, - 'totalNodeDisk' => $totalNodeDisk, - 'nodes' => $nodes, - 'tokens' => $tokens, - ]); - - return view('admin.statistics', [ - 'servers' => $servers, - 'nodes' => $nodes, - 'usersCount' => $usersCount, - 'eggsCount' => $eggsCount, - 'totalServerRam' => $totalServerRam, - 'databasesCount' => $databasesCount, - 'totalNodeRam' => $totalNodeRam, - 'totalNodeDisk' => $totalNodeDisk, - 'totalServerDisk' => $totalServerDisk, - 'totalAllocations' => $totalAllocations, - ]); - } -} diff --git a/app/Http/Controllers/Api/Client/Servers/BackupController.php b/app/Http/Controllers/Api/Client/Servers/BackupController.php index 888d4fe2..86aef1e2 100644 --- a/app/Http/Controllers/Api/Client/Servers/BackupController.php +++ b/app/Http/Controllers/Api/Client/Servers/BackupController.php @@ -8,7 +8,7 @@ use Pterodactyl\Models\Server; use Pterodactyl\Models\AuditLog; use Illuminate\Http\JsonResponse; use Pterodactyl\Models\Permission; -use Illuminate\Validation\UnauthorizedException; +use Illuminate\Auth\Access\AuthorizationException; use Pterodactyl\Services\Backups\DeleteBackupService; use Pterodactyl\Services\Backups\DownloadLinkService; use Pterodactyl\Services\Backups\InitiateBackupService; @@ -63,11 +63,12 @@ class BackupController extends ClientApiController * * @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation * @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified + * @throws \Illuminate\Auth\Access\AuthorizationException */ public function index(Request $request, Server $server): array { if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) { - throw new UnauthorizedException(); + throw new AuthorizationException(); } $limit = min($request->query('per_page') ?? 20, 50); @@ -109,11 +110,12 @@ class BackupController extends ClientApiController * * @throws \Spatie\Fractalistic\Exceptions\InvalidTransformation * @throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified + * @throws \Illuminate\Auth\Access\AuthorizationException */ public function view(Request $request, Server $server, Backup $backup): array { if (!$request->user()->can(Permission::ACTION_BACKUP_READ, $server)) { - throw new UnauthorizedException(); + throw new AuthorizationException(); } return $this->fractal->item($backup) @@ -130,7 +132,7 @@ class BackupController extends ClientApiController public function delete(Request $request, Server $server, Backup $backup): JsonResponse { if (!$request->user()->can(Permission::ACTION_BACKUP_DELETE, $server)) { - throw new UnauthorizedException(); + throw new AuthorizationException(); } $server->audit(AuditLog::SERVER__BACKUP_DELETED, function (AuditLog $audit) use ($backup) { @@ -146,11 +148,13 @@ class BackupController extends ClientApiController * Download the backup for a given server instance. For daemon local files, the file * will be streamed back through the Panel. For AWS S3 files, a signed URL will be generated * which the user is redirected to. + * + * @throws \Illuminate\Auth\Access\AuthorizationException */ public function download(Request $request, Server $server, Backup $backup): JsonResponse { if (!$request->user()->can(Permission::ACTION_BACKUP_DOWNLOAD, $server)) { - throw new UnauthorizedException(); + throw new AuthorizationException(); } switch ($backup->disk) { @@ -179,7 +183,7 @@ class BackupController extends ClientApiController public function restore(Request $request, Server $server, Backup $backup): JsonResponse { if (!$request->user()->can(Permission::ACTION_BACKUP_RESTORE, $server)) { - throw new UnauthorizedException(); + throw new AuthorizationException(); } // Cannot restore a backup unless a server is fully installed and not currently diff --git a/app/Repositories/Eloquent/ServerRepository.php b/app/Repositories/Eloquent/ServerRepository.php index 2e308ce1..8bb79c10 100644 --- a/app/Repositories/Eloquent/ServerRepository.php +++ b/app/Repositories/Eloquent/ServerRepository.php @@ -168,14 +168,6 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt return !$this->getBuilder()->where('uuid', '=', $uuid)->orWhere('uuidShort', '=', $short)->exists(); } - /** - * Get the amount of servers that are suspended. - */ - public function getSuspendedServersCount(): int - { - return $this->getBuilder()->where('suspended', true)->count(); - } - /** * Returns all of the servers that exist for a given node in a paginated response. */ diff --git a/database/Factories/ServerFactory.php b/database/Factories/ServerFactory.php index c56b6686..d39d614b 100644 --- a/database/Factories/ServerFactory.php +++ b/database/Factories/ServerFactory.php @@ -30,7 +30,7 @@ class ServerFactory extends Factory 'name' => $this->faker->firstName, 'description' => implode(' ', $this->faker->sentences()), 'skip_scripts' => 0, - 'suspended' => 0, + 'status' => null, 'memory' => 512, 'swap' => 0, 'disk' => 512, @@ -38,7 +38,6 @@ class ServerFactory extends Factory 'cpu' => 0, 'threads' => null, 'oom_disabled' => 0, - 'installed' => 1, 'allocation_limit' => null, 'database_limit' => null, 'created_at' => Carbon::now(), diff --git a/public/themes/pterodactyl/js/admin/statistics.js b/public/themes/pterodactyl/js/admin/statistics.js deleted file mode 100644 index 7433f322..00000000 --- a/public/themes/pterodactyl/js/admin/statistics.js +++ /dev/null @@ -1,118 +0,0 @@ -var freeDisk = Pterodactyl.totalNodeDisk - Pterodactyl.totalServerDisk; -let diskChart = new Chart($('#disk_chart'), { - type: 'pie', - data: { - labels: ['Free Disk', 'Used Disk'], - datasets: [ - { - label: 'Disk (in MB)', - backgroundColor: ['#51B060', '#ff0000'], - data: [freeDisk, Pterodactyl.totalServerDisk] - } - ] - } -}); - -var freeRam = Pterodactyl.totalNodeRam - Pterodactyl.totalServerRam; -let ramChart = new Chart($('#ram_chart'), { - type: 'pie', - data: { - labels: ['Free RAM', 'Used RAM'], - datasets: [ - { - label: 'Memory (in MB)', - backgroundColor: ['#51B060', '#ff0000'], - data: [freeRam, Pterodactyl.totalServerRam] - } - ] - } -}); - -var activeServers = Pterodactyl.servers.length - Pterodactyl.suspendedServers; -let serversChart = new Chart($('#servers_chart'), { - type: 'pie', - data: { - labels: ['Active', 'Suspended'], - datasets: [ - { - label: 'Servers', - backgroundColor: ['#51B060', '#E08E0B'], - data: [activeServers, Pterodactyl.suspendedServers] - } - ] - } -}); - -let statusChart = new Chart($('#status_chart'), { - type: 'pie', - data: { - labels: ['Online', 'Offline', 'Installing', 'Error'], - datasets: [ - { - label: '', - backgroundColor: ['#51B060', '#b7b7b7', '#E08E0B', '#ff0000'], - data: [0,0,0,0] - } - ] - } -}); - -var servers = Pterodactyl.servers; -var nodes = Pterodactyl.nodes; - -for (let i = 0; i < servers.length; i++) { - setTimeout(getStatus, 200 * i, servers[i]); -} - -function getStatus(server) { - var uuid = server.uuid; - var node = getNodeByID(server.node_id); - - $.ajax({ - type: 'GET', - url: node.scheme + '://' + node.fqdn + ':'+node.daemonListen+'/v1/server', - timeout: 5000, - headers: { - 'X-Access-Server': uuid, - 'X-Access-Token': Pterodactyl.tokens[node.id], - } - }).done(function (data) { - - if (typeof data.status === 'undefined') { - // Error - statusChart.data.datasets[0].data[3]++; - return; - } - - switch (data.status) { - case 0: - case 3: - case 30: - // Offline - statusChart.data.datasets[0].data[1]++; - break; - case 1: - case 2: - // Online - statusChart.data.datasets[0].data[0]++; - break; - case 20: - // Installing - statusChart.data.datasets[0].data[2]++; - break; - } - statusChart.update(); - }).fail(function (jqXHR) { - // Error - statusChart.data.datasets[0].data[3]++; - statusChart.update(); - }); -} - -function getNodeByID(id) { - for (var i = 0; i < nodes.length; i++) { - if (nodes[i].id === id) { - return nodes[i]; - } - } -} \ No newline at end of file diff --git a/resources/scripts/api/server/getServer.ts b/resources/scripts/api/server/getServer.ts index 30dc0b2f..3d74ee2a 100644 --- a/resources/scripts/api/server/getServer.ts +++ b/resources/scripts/api/server/getServer.ts @@ -39,11 +39,6 @@ export interface Server { allocations: number; backups: number; }; - // Only isSuspended got marked as deprecated since the isInstalling is a nice helper - // since you'd have to check multiple potential values for that. isSuspended should - // be replaced with status !== 'suspended'. - /** @deprecated */ - isSuspended: boolean; isInstalling: boolean; isTransferring: boolean; variables: ServerEggVariable[]; @@ -67,7 +62,6 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData) limits: { ...data.limits }, eggFeatures: data.egg_features || [], featureLimits: { ...data.feature_limits }, - isSuspended: data.status === 'suspended', isInstalling: data.status === 'installing' || data.status === 'install_failed', isTransferring: data.is_transferring, variables: ((data.relationships?.variables as FractalResponseList | undefined)?.data || []).map(rawDataToServerEggVariable), diff --git a/resources/views/admin/statistics.blade.php b/resources/views/admin/statistics.blade.php deleted file mode 100644 index 529107bb..00000000 --- a/resources/views/admin/statistics.blade.php +++ /dev/null @@ -1,141 +0,0 @@ -@extends('layouts.admin') -@include('partials/admin.settings.nav', ['activeTab' => 'basic']) - -@section('title') - Statistics Overview -@endsection - -@section('content-header') -