Merge branch 'feature/vuejs' into feature/dusk-vuejs

This commit is contained in:
Dane Everitt 2018-05-31 23:00:08 -07:00
commit 316bb9c11e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
31 changed files with 835 additions and 7 deletions

View file

@ -3,6 +3,18 @@ This file is a running track of new features and fixes to each version of the pa
This project follows [Semantic Versioning](http://semver.org) guidelines. This project follows [Semantic Versioning](http://semver.org) guidelines.
## v0.7.8 (Derelict Dermodactylus)
### Added
* Nodes can now be put into maintenance mode to deny access to servers temporarily.
* Basic statistics about your panel are now available in the Admin CP.
### Fixed
* Hitting Ctrl+Z when editing a file on the web now works as expected.
* Logo now links to the correct location on all pages.
### Changed
* Attempting to upload a folder via the web file manager will now display a warning telling the user to use SFTP.
## v0.7.7 (Derelict Dermodactylus) ## v0.7.7 (Derelict Dermodactylus)
### Fixed ### Fixed
* Fixes an issue with the sidebar logo not working correctly in some browsers due to the CSS being assigned. * Fixes an issue with the sidebar logo not working correctly in some browsers due to the CSS being assigned.

View file

@ -21,6 +21,14 @@ interface NodeRepositoryInterface extends RepositoryInterface, SearchableInterfa
*/ */
public function getUsageStats(Node $node): array; public function getUsageStats(Node $node): array;
/**
* Return the usage stats for a single node.
*
* @param \Pterodactyl\Models\Node $node
* @return array
*/
public function getUsageStatsRaw(Node $node): array;
/** /**
* Return all available nodes with a searchable interface. * Return all available nodes with a searchable interface.
* *

View file

@ -200,4 +200,11 @@ interface RepositoryInterface
* @return bool * @return bool
*/ */
public function insertIgnore(array $values): bool; public function insertIgnore(array $values): bool;
/**
* Get the amount of entries in the database
*
* @return int
*/
public function count(): int;
} }

View file

@ -145,4 +145,11 @@ interface ServerRepositoryInterface extends RepositoryInterface, SearchableInter
* @return bool * @return bool
*/ */
public function isUniqueUuidCombo(string $uuid, string $short): bool; public function isUniqueUuidCombo(string $uuid, string $short): bool;
/**
* Get the amount of servers that are suspended
*
* @return int
*/
public function getSuspendedServersCount(): int;
} }

View file

@ -0,0 +1,101 @@
<?php
namespace Pterodactyl\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\Traits\Controllers\PlainJavascriptInjection;
class StatisticsController extends Controller
{
use PlainJavascriptInjection;
private $allocationRepository;
private $databaseRepository;
private $eggRepository;
private $nodeRepository;
private $serverRepository;
private $userRepository;
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()
{
$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] = $node->daemonSecret;
}
$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,
]);
}
}

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Http; namespace Pterodactyl\Http;
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
use Pterodactyl\Models\ApiKey; use Pterodactyl\Models\ApiKey;
use Illuminate\Auth\Middleware\Authorize; use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Auth\Middleware\Authenticate; use Illuminate\Auth\Middleware\Authenticate;
@ -108,6 +109,7 @@ class Kernel extends HttpKernel
'can' => Authorize::class, 'can' => Authorize::class,
'bindings' => SubstituteBindings::class, 'bindings' => SubstituteBindings::class,
'recaptcha' => VerifyReCaptcha::class, 'recaptcha' => VerifyReCaptcha::class,
'node.maintenance' => MaintenanceMiddleware::class,
// Server specific middleware (used for authenticating access to resources) // Server specific middleware (used for authenticating access to resources)
// //

View file

@ -0,0 +1,44 @@
<?php
namespace Pterodactyl\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\ResponseFactory;
class MaintenanceMiddleware
{
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory
*/
private $response;
/**
* MaintenanceMiddleware constructor.
*
* @param \Illuminate\Contracts\Routing\ResponseFactory $response
*/
public function __construct(ResponseFactory $response)
{
$this->response = $response;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
/** @var \Pterodactyl\Models\Server $server */
$server = $request->attributes->get('server');
$node = $server->getRelation('node');
if ($node->maintenance_mode) {
return $this->response->view('errors.maintenance');
}
return $next($request);
}
}

View file

@ -48,6 +48,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
'daemonSFTP' => 'integer', 'daemonSFTP' => 'integer',
'behind_proxy' => 'boolean', 'behind_proxy' => 'boolean',
'public' => 'boolean', 'public' => 'boolean',
'maintenance_mode' => 'boolean',
]; ];
/** /**
@ -62,7 +63,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
'disk_overallocate', 'upload_size', 'disk_overallocate', 'upload_size',
'daemonSecret', 'daemonBase', 'daemonSecret', 'daemonBase',
'daemonSFTP', 'daemonListen', 'daemonSFTP', 'daemonListen',
'description', 'description', 'maintenance_mode',
]; ];
/** /**
@ -111,6 +112,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
'daemonBase' => 'regex:/^([\/][\d\w.\-\/]+)$/', 'daemonBase' => 'regex:/^([\/][\d\w.\-\/]+)$/',
'daemonSFTP' => 'numeric|between:1024,65535', 'daemonSFTP' => 'numeric|between:1024,65535',
'daemonListen' => 'numeric|between:1024,65535', 'daemonListen' => 'numeric|between:1024,65535',
'maintenance_mode' => 'boolean',
]; ];
/** /**
@ -126,6 +128,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
'daemonBase' => '/srv/daemon-data', 'daemonBase' => '/srv/daemon-data',
'daemonSFTP' => 2022, 'daemonSFTP' => 2022,
'daemonListen' => 8080, 'daemonListen' => 8080,
'maintenance_mode' => false,
]; ];
/** /**

View file

@ -33,7 +33,7 @@ class RouteServiceProvider extends ServiceProvider
->namespace($this->namespace . '\Auth') ->namespace($this->namespace . '\Auth')
->group(base_path('routes/auth.php')); ->group(base_path('routes/auth.php'));
Route::middleware(['web', 'csrf', 'auth', 'server', 'subuser.auth'])->prefix('/server/{server}') Route::middleware(['web', 'csrf', 'auth', 'server', 'subuser.auth', 'node.maintenance'])->prefix('/server/{server}')
->namespace($this->namespace . '\Server') ->namespace($this->namespace . '\Server')
->group(base_path('routes/server.php')); ->group(base_path('routes/server.php'));

View file

@ -296,4 +296,14 @@ abstract class EloquentRepository extends Repository implements RepositoryInterf
return $this->getBuilder()->getConnection()->statement($statement, $bindings); return $this->getBuilder()->getConnection()->statement($statement, $bindings);
} }
/**
* Get the amount of entries in the database
*
* @return int
*/
public function count(): int
{
return $this->getBuilder()->count();
}
} }

View file

@ -56,6 +56,33 @@ class NodeRepository extends EloquentRepository implements NodeRepositoryInterfa
})->toArray(); })->toArray();
} }
/**
* Return the usage stats for a single node.
*
* @param \Pterodactyl\Models\Node $node
* @return array
*/
public function getUsageStatsRaw(Node $node): array
{
$stats = $this->getBuilder()->select(
$this->getBuilder()->raw('IFNULL(SUM(servers.memory), 0) as sum_memory, IFNULL(SUM(servers.disk), 0) as sum_disk')
)->join('servers', 'servers.node_id', '=', 'nodes.id')->where('node_id', $node->id)->first();
return collect(['disk' => $stats->sum_disk, 'memory' => $stats->sum_memory])->mapWithKeys(function ($value, $key) use ($node) {
$maxUsage = $node->{$key};
if ($node->{$key . '_overallocate'} > 0) {
$maxUsage = $node->{$key} * (1 + ($node->{$key . '_overallocate'} / 100));
}
return [
$key => [
'value' => $value,
'max' => $maxUsage,
],
];
})->toArray();
}
/** /**
* Return all available nodes with a searchable interface. * Return all available nodes with a searchable interface.
* *

View file

@ -328,4 +328,14 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
$this->app->make(SubuserRepository::class)->getBuilder()->select('server_id')->where('user_id', $user) $this->app->make(SubuserRepository::class)->getBuilder()->select('server_id')->where('user_id', $user)
)->pluck('id')->all(); )->pluck('id')->all();
} }
/**
* Get the amount of servers that are suspended
*
* @return int
*/
public function getSuspendedServersCount(): int
{
return $this->getBuilder()->where('suspended', true)->count();
}
} }

View file

@ -0,0 +1,24 @@
<?php
/**
* Created by PhpStorm.
* User: Stan
* Date: 26-5-2018
* Time: 20:56
*/
namespace Pterodactyl\Traits\Controllers;
use JavaScript;
trait PlainJavascriptInjection
{
/**
* Injects statistics into javascript
*/
public function injectJavascript($data)
{
Javascript::put($data);
}
}

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddMaintenanceToNodes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('nodes', function (Blueprint $table) {
$table->boolean('maintenance_mode')->after('behind_proxy')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('nodes', function (Blueprint $table) {
$table->dropColumn('maintenance_mode');
});
}
}

View file

@ -473,3 +473,7 @@ label.control-label > span.field-optional:before {
height: 42px; height: 42px;
width: auto; width: auto;
} }
.number-info-box-content {
padding: 15px 10px 0;
}

View file

@ -0,0 +1,118 @@
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];
}
}
}

View file

@ -61,6 +61,18 @@
event.preventDefault(); event.preventDefault();
}, false); }, false);
window.foldersDetectedInDrag = function (event) {
var folderDetected = false;
var files = event.dataTransfer.files;
for (var i = 0, f; f = files[i]; i++) {
if (!f.type && f.size === 0) {
return true;
}
}
return folderDetected;
};
var dropCounter = 0; var dropCounter = 0;
$('#load_files').bind({ $('#load_files').bind({
dragenter: function (event) { dragenter: function (event) {
@ -75,6 +87,15 @@
} }
}, },
drop: function (event) { drop: function (event) {
if (window.foldersDetectedInDrag(event.originalEvent)) {
$.notify({
message: 'Folder uploads are not supported. Please use SFTP to upload whole directories.',
}, {
type: 'warning',
delay: 0
});
}
dropCounter = 0; dropCounter = 0;
$(this).removeClass('hasFileHover'); $(this).removeClass('hasFileHover');
} }

View file

@ -21,6 +21,11 @@ return [
'header' => 'Server Suspended', 'header' => 'Server Suspended',
'desc' => 'This server has been suspended and cannot be accessed.', 'desc' => 'This server has been suspended and cannot be accessed.',
], ],
'maintenance' => [
'header' => 'Node Under Maintenance',
'title' => 'Temporarily Unavailable',
'desc' => 'This node is under maintenance, therefore your server can temporarily not be accessed.',
],
], ],
'index' => [ 'index' => [
'header' => 'Your Servers', 'header' => 'Your Servers',

View file

@ -74,6 +74,7 @@ return [
'tasks' => 'Tasks', 'tasks' => 'Tasks',
'seconds' => 'Seconds', 'seconds' => 'Seconds',
'minutes' => 'Minutes', 'minutes' => 'Minutes',
'under_maintenance' => 'Under Maintenance',
'days' => [ 'days' => [
'sun' => 'Sunday', 'sun' => 'Sunday',
'mon' => 'Monday', 'mon' => 'Monday',

View file

@ -56,7 +56,7 @@
@foreach ($nodes as $node) @foreach ($nodes as $node)
<tr> <tr>
<td class="text-center text-muted left-icon" data-action="ping" data-secret="{{ $node->daemonSecret }}" data-location="{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/v1"><i class="fa fa-fw fa-refresh fa-spin"></i></td> <td class="text-center text-muted left-icon" data-action="ping" data-secret="{{ $node->daemonSecret }}" data-location="{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/v1"><i class="fa fa-fw fa-refresh fa-spin"></i></td>
<td><a href="{{ route('admin.nodes.view', $node->id) }}">{{ $node->name }}</a></td> <td>{!! $node->maintenance_mode ? '<span class="label label-warning"><i class="fa fa-wrench"></i></span> ' : '' !!}<a href="{{ route('admin.nodes.view', $node->id) }}">{{ $node->name }}</a></td>
<td>{{ $node->location->short }}</td> <td>{{ $node->location->short }}</td>
<td>{{ $node->memory }} MB</td> <td>{{ $node->memory }} MB</td>
<td>{{ $node->disk }} MB</td> <td>{{ $node->disk }} MB</td>

View file

@ -96,6 +96,17 @@
</div> </div>
<div class="box-body"> <div class="box-body">
<div class="row"> <div class="row">
@if($node->maintenance_mode)
<div class="col-sm-12">
<div class="info-box bg-orange">
<span class="info-box-icon"><i class="ion ion-wrench"></i></span>
<div class="info-box-content" style="padding: 23px 10px 0;">
<span class="info-box-text">This node is under</span>
<span class="info-box-number">Maintenance</span>
</div>
</div>
</div>
@endif
<div class="col-sm-12"> <div class="col-sm-12">
<div class="info-box bg-{{ $stats['disk']['css'] }}"> <div class="info-box bg-{{ $stats['disk']['css'] }}">
<span class="info-box-icon"><i class="ion ion-ios-folder-outline"></i></span> <span class="info-box-icon"><i class="ion ion-ios-folder-outline"></i></span>

View file

@ -108,6 +108,20 @@
</div> </div>
<p class="text-muted small">If you are running the daemon behind a proxy such as Cloudflare, select this to have the daemon skip looking for certificates on boot.</p> <p class="text-muted small">If you are running the daemon behind a proxy such as Cloudflare, select this to have the daemon skip looking for certificates on boot.</p>
</div> </div>
<div class="form-group col-xs-12">
<label class="form-label"><span class="label label-warning"><i class="fa fa-wrench"></i></span> Maintenance Mode</label>
<div>
<div class="radio radio-success radio-inline">
<input type="radio" id="pMaintenanceFalse" value="0" name="maintenance_mode" {{ (old('behind_proxy', $node->maintenance_mode) == false) ? 'checked' : '' }}>
<label for="pMaintenanceFalse"> Disabled</label>
</div>
<div class="radio radio-warning radio-inline">
<input type="radio" id="pMaintenanceTrue" value="1" name="maintenance_mode" {{ (old('behind_proxy', $node->maintenance_mode) == true) ? 'checked' : '' }}>
<label for="pMaintenanceTrue"> Enabled</label>
</div>
</div>
<p class="text-muted small">If the node is marked as 'Under Maintenance' users won't be able to access servers that are on this node.</p>
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -0,0 +1,141 @@
@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

View file

@ -64,9 +64,15 @@
<span class="label bg-blue">@lang('strings.subuser')</span> <span class="label bg-blue">@lang('strings.subuser')</span>
@endif @endif
</td> </td>
@if($server->node->maintenance_mode)
<td class="text-center">
<span class="label label-warning">@lang('strings.under_maintenance')</span>
</td>
@else
<td class="text-center" data-action="status"> <td class="text-center" data-action="status">
<span class="label label-default"><i class="fa fa-refresh fa-fw fa-spin"></i></span> <span class="label label-default"><i class="fa fa-refresh fa-fw fa-spin"></i></span>
</td> </td>
@endif
</tr> </tr>
@if (! empty($server->description)) @if (! empty($server->description))
<tr class="server-description"> <tr class="server-description">

View file

@ -0,0 +1,30 @@
{{-- Pterodactyl - Panel --}}
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
{{-- This software is licensed under the terms of the MIT license. --}}
{{-- https://opensource.org/licenses/MIT --}}
@extends('layouts.error')
@section('title')
@lang('base.errors.maintenance.header')
@endsection
@section('content-header')
@endsection
@section('content')
<div class="row">
<div class="col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1 col-xs-12">
<div class="box box-danger">
<div class="box-body text-center">
<h1 class="text-red" style="font-size: 3em !important;font-weight: 100 !important;">@lang('base.errors.maintenance.title')</h1>
<p class="text-muted">@lang('base.errors.maintenance.desc')</p>
</div>
<div class="box-footer with-border">
<a href="{{ URL::previous() }}"><button class="btn btn-danger">&larr; @lang('base.errors.return')</button></a>
<a href="/"><button class="btn btn-default">@lang('base.errors.home')</button></a>
</div>
</div>
</div>
</div>
@endsection

View file

@ -80,6 +80,11 @@
<i class="fa fa-home"></i> <span>Overview</span> <i class="fa fa-home"></i> <span>Overview</span>
</a> </a>
</li> </li>
<li class="{{ Route::currentRouteName() !== 'admin.statistics' ?: 'active' }}">
<a href="{{ route('admin.statistics') }}">
<i class="fa fa-tachometer"></i> <span>Statistics</span>
</a>
</li>
<li class="{{ ! starts_with(Route::currentRouteName(), 'admin.settings') ?: 'active' }}"> <li class="{{ ! starts_with(Route::currentRouteName(), 'admin.settings') ?: 'active' }}">
<a href="{{ route('admin.settings')}}"> <a href="{{ route('admin.settings')}}">
<i class="fa fa-wrench"></i> <span>Settings</span> <i class="fa fa-wrench"></i> <span>Settings</span>

View file

@ -44,7 +44,7 @@
<header class="main-header"> <header class="main-header">
<a href="{{ route('index') }}" class="logo"> <a href="{{ route('index') }}" class="logo">
<span class="logo-lg">{{ config('app.name', 'Pterodactyl') }}</span> <span class="logo-lg">{{ config('app.name', 'Pterodactyl') }}</span>
<span class="logo-mini"><img src="favicons/android-chrome-192x192.png"></span> <span class="logo-mini"><img src="/favicons/android-chrome-192x192.png"></span>
</a> </a>
<nav class="navbar navbar-static-top"> <nav class="navbar navbar-static-top">
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button"> <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">

View file

@ -52,6 +52,7 @@
<script> <script>
$(document).ready(function () { $(document).ready(function () {
Editor.setValue($('#editorSetContent').val(), -1); Editor.setValue($('#editorSetContent').val(), -1);
Editor.getSession().setUndoManager(new ace.UndoManager());
$('#editorLoadingOverlay').hide(); $('#editorLoadingOverlay').hide();
}); });
</script> </script>

View file

@ -1,6 +1,7 @@
<?php <?php
Route::get('/', 'BaseController@index')->name('admin.index'); Route::get('/', 'BaseController@index')->name('admin.index');
Route::get('/statistics', 'StatisticsController@index')->name('admin.statistics');
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View file

@ -0,0 +1,113 @@
<?php
/**
* Created by PhpStorm.
* User: Stan
* Date: 26-5-2018
* Time: 21:06
*/
namespace Tests\Unit\Http\Controllers\Admin;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Routing\Controller;
use Mockery as m;
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
use Pterodactyl\Http\Controllers\Admin\StatisticsController;
use Pterodactyl\Models\Node;
use Tests\Assertions\ControllerAssertionsTrait;
use Tests\Unit\Http\Controllers\ControllerTestCase;
class StatisticsControllerTest extends ControllerTestCase
{
use ControllerAssertionsTrait;
/**
* @var \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface|\Mockery\Mock
*/
private $allocationRepository;
/**
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface|\Mockery\Mock
*/
private $databaseRepository;
/**
* @var \Pterodactyl\Contracts\Repository\EggRepositoryInterface|\Mockery\Mock
*/
private $eggRepository;
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface|\Mockery\Mock
*/
private $nodeRepository;
/**
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
*/
private $serverRepository;
/**
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface|\Mockery\Mock
*/
private $userRepository;
public function setUp()
{
parent::setUp();
$this->allocationRepository = m::mock(AllocationRepositoryInterface::class);
$this->databaseRepository = m::mock(DatabaseRepositoryInterface::class);
$this->eggRepository = m::mock(EggRepositoryInterface::class);
$this->nodeRepository = m::mock(NodeRepositoryInterface::class);
$this->serverRepository = m::mock(ServerRepositoryInterface::class);
$this->userRepository = m::mock(UserRepositoryInterface::class);
}
public function testIndexController()
{
$controller = $this->getController();
$this->serverRepository->shouldReceive('all')->withNoArgs();
$this->nodeRepository->shouldReceive('all')->withNoArgs()->andReturn(collect([factory(Node::class)->make(), factory(Node::class)->make()]));
$this->userRepository->shouldReceive('count')->withNoArgs();
$this->eggRepository->shouldReceive('count')->withNoArgs();
$this->databaseRepository->shouldReceive('count')->withNoArgs();
$this->allocationRepository->shouldReceive('count')->withNoArgs();
$this->serverRepository->shouldReceive('getSuspendedServersCount')->withNoArgs();
$this->nodeRepository->shouldReceive('getUsageStatsRaw')->twice()->andReturn([
'memory' => [
'value' => 1024,
'max' => 512,
],
'disk' => [
'value' => 1024,
'max' => 512,
]
]);
$controller->shouldReceive('injectJavascript')->once();
$response = $controller->index();
$this->assertIsViewResponse($response);
$this->assertViewNameEquals('admin.statistics', $response);
}
private function getController()
{
return $this->buildMockedController(StatisticsController::class, [$this->allocationRepository,
$this->databaseRepository,
$this->eggRepository,
$this->nodeRepository,
$this->serverRepository,
$this->userRepository]
);
}
}

View file

@ -0,0 +1,70 @@
<?php
namespace Tests\Unit\Http\Middleware;
use Mockery as m;
use Pterodactyl\Models\Node;
use Illuminate\Http\Response;
use Pterodactyl\Models\Server;
use Illuminate\Contracts\Routing\ResponseFactory;
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
class MaintenanceMiddlewareTest extends MiddlewareTestCase
{
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory|\Mockery\Mock
*/
private $response;
/**
* Setup tests.
*/
public function setUp()
{
parent::setUp();
$this->response = m::mock(ResponseFactory::class);
}
/**
* Test that a node not in maintenance mode continues through the request cycle.
*/
public function testHandle()
{
$server = factory(Server::class)->make();
$node = factory(Node::class)->make(['maintenance' => 0]);
$server->setRelation('node', $node);
$this->setRequestAttribute('server', $server);
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
/**
* Test that a node in maintenance mode returns an error view.
*/
public function testHandleInMaintenanceMode()
{
$server = factory(Server::class)->make();
$node = factory(Node::class)->make(['maintenance_mode' => 1]);
$server->setRelation('node', $node);
$this->setRequestAttribute('server', $server);
$this->response->shouldReceive('view')
->once()
->with('errors.maintenance')
->andReturn(new Response);
$response = $this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
$this->assertInstanceOf(Response::class, $response);
}
/**
* @return \Pterodactyl\Http\Middleware\MaintenanceMiddleware
*/
private function getMiddleware(): MaintenanceMiddleware
{
return new MaintenanceMiddleware($this->response);
}
}