Merge branch 'feature/vuejs' into feature/vuejs-serverlist
This commit is contained in:
commit
6c598f9100
31 changed files with 835 additions and 7 deletions
101
app/Http/Controllers/Admin/StatisticsController.php
Normal file
101
app/Http/Controllers/Admin/StatisticsController.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Http;
|
||||
|
||||
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
|
||||
use Pterodactyl\Models\ApiKey;
|
||||
use Illuminate\Auth\Middleware\Authorize;
|
||||
use Illuminate\Auth\Middleware\Authenticate;
|
||||
|
@ -108,6 +109,7 @@ class Kernel extends HttpKernel
|
|||
'can' => Authorize::class,
|
||||
'bindings' => SubstituteBindings::class,
|
||||
'recaptcha' => VerifyReCaptcha::class,
|
||||
'node.maintenance' => MaintenanceMiddleware::class,
|
||||
|
||||
// Server specific middleware (used for authenticating access to resources)
|
||||
//
|
||||
|
|
44
app/Http/Middleware/MaintenanceMiddleware.php
Normal file
44
app/Http/Middleware/MaintenanceMiddleware.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue