forked from Alex/Pterodactyl-Panel
Fix tests
This commit is contained in:
parent
2f08456ed9
commit
00da092e45
@ -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);
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\Controllers\Admin;
|
||||
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||
use Pterodactyl\Traits\Controllers\PlainJavascriptInjection;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
|
||||
|
||||
class StatisticsController extends Controller
|
||||
{
|
||||
use PlainJavascriptInjection;
|
||||
|
||||
private $allocationRepository;
|
||||
|
||||
private $databaseRepository;
|
||||
|
||||
private $eggRepository;
|
||||
|
||||
private $nodeRepository;
|
||||
|
||||
private $serverRepository;
|
||||
|
||||
private $userRepository;
|
||||
|
||||
public function __construct(
|
||||
AllocationRepositoryInterface $allocationRepository,
|
||||
DatabaseRepositoryInterface $databaseRepository,
|
||||
EggRepositoryInterface $eggRepository,
|
||||
NodeRepositoryInterface $nodeRepository,
|
||||
ServerRepositoryInterface $serverRepository,
|
||||
UserRepositoryInterface $userRepository
|
||||
) {
|
||||
$this->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,
|
||||
]);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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(),
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
@ -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),
|
||||
|
@ -1,141 +0,0 @@
|
||||
@extends('layouts.admin')
|
||||
@include('partials/admin.settings.nav', ['activeTab' => 'basic'])
|
||||
|
||||
@section('title')
|
||||
Statistics Overview
|
||||
@endsection
|
||||
|
||||
@section('content-header')
|
||||
<h1>Statistics Overview<small>Monitor your panel usage.</small></h1>
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="{{ route('admin.index') }}">Admin</a></li>
|
||||
<li class="active">Statistics</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-8">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
Servers
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<canvas id="servers_chart" width="100%" height="50"></canvas>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<canvas id="status_chart" width="100%" height="50"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="fa fa-server"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Servers</span>
|
||||
<span class="info-box-number">{{ count($servers) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="ion ion-ios-barcode-outline"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total used Memory (in MB)</span>
|
||||
<span class="info-box-number">{{ $totalServerRam }}MB</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="ion ion-stats-bars"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total used Disk (in MB)</span>
|
||||
<span class="info-box-number">{{ $totalServerDisk }}MB</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-8">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
Nodes
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<canvas id="ram_chart" width="100%" height="50"></canvas>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<canvas id="disk_chart" width="100%" height="50"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-4">
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="ion ion-ios-barcode-outline"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total RAM</span>
|
||||
<span class="info-box-number">{{ $totalNodeRam }}MB</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="ion ion-stats-bars"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total Disk Space</span>
|
||||
<span class="info-box-number">{{ $totalNodeDisk }}MB</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="fa fa-location-arrow"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total Allocations</span>
|
||||
<span class="info-box-number">{{ $totalAllocations }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-3">
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="fa fa-gamepad"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total Eggs</span>
|
||||
<span class="info-box-number">{{ $eggsCount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-3">
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="fa fa-users"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total Users</span>
|
||||
<span class="info-box-number">{{ $usersCount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-3">
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="fa fa-server"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total Nodes</span>
|
||||
<span class="info-box-number">{{ count($nodes) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-3">
|
||||
<div class="info-box bg-blue">
|
||||
<span class="info-box-icon"><i class="fa fa-database"></i></span>
|
||||
<div class="info-box-content number-info-box-content">
|
||||
<span class="info-box-text">Total Databases</span>
|
||||
<span class="info-box-number">{{ $databasesCount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('footer-scripts')
|
||||
@parent
|
||||
{!! Theme::js('vendor/chartjs/chart.min.js') !!}
|
||||
{!! Theme::js('js/admin/statistics.js') !!}
|
||||
@endsection
|
@ -4,7 +4,6 @@ use Illuminate\Support\Facades\Route;
|
||||
use Pterodactyl\Http\Middleware\Admin\Servers\ServerInstalled;
|
||||
|
||||
Route::get('/', 'BaseController@index')->name('admin.index');
|
||||
Route::get('/statistics', 'StatisticsController@index')->name('admin.statistics');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Pterodactyl\Tests\Integration;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Testing\Assert as PHPUnit;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@ -35,4 +36,12 @@ class TestResponse extends IlluminateTestResponse
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function assertForbidden()
|
||||
{
|
||||
return self::assertStatus(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user