2018-05-04 16:45:37 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2018-05-06 15:59:11 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use JavaScript;
|
2018-05-26 18:58:49 +00:00
|
|
|
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;
|
2018-05-04 16:45:37 +00:00
|
|
|
use Pterodactyl\Http\Controllers\Controller;
|
2018-05-04 20:48:43 +00:00
|
|
|
use Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService;
|
2018-05-26 18:58:49 +00:00
|
|
|
use Pterodactyl\Traits\Controllers\JavascriptInjection;
|
2018-05-04 16:45:37 +00:00
|
|
|
|
|
|
|
class StatisticsController extends Controller
|
|
|
|
{
|
2018-05-26 18:58:49 +00:00
|
|
|
use JavascriptInjection;
|
|
|
|
|
|
|
|
private $allocationRepository;
|
|
|
|
|
|
|
|
private $databaseRepository;
|
2018-05-04 16:45:37 +00:00
|
|
|
|
2018-05-04 20:48:43 +00:00
|
|
|
private $keyProviderService;
|
|
|
|
|
2018-05-26 18:58:49 +00:00
|
|
|
private $eggRepository;
|
|
|
|
|
|
|
|
private $nodeRepository;
|
|
|
|
|
|
|
|
private $serverRepository;
|
|
|
|
|
|
|
|
private $userRepository;
|
|
|
|
|
|
|
|
function __construct(
|
|
|
|
AllocationRepositoryInterface $allocationRepository,
|
|
|
|
DatabaseRepositoryInterface $databaseRepository,
|
|
|
|
DaemonKeyProviderService $keyProviderService,
|
|
|
|
EggRepositoryInterface $eggRepository,
|
|
|
|
NodeRepositoryInterface $nodeRepository,
|
|
|
|
ServerRepositoryInterface $serverRepository,
|
|
|
|
UserRepositoryInterface $userRepository
|
|
|
|
)
|
2018-05-04 20:48:43 +00:00
|
|
|
{
|
2018-05-26 18:58:49 +00:00
|
|
|
$this->allocationRepository = $allocationRepository;
|
|
|
|
$this->databaseRepository = $databaseRepository;
|
2018-05-04 20:48:43 +00:00
|
|
|
$this->keyProviderService = $keyProviderService;
|
2018-05-26 18:58:49 +00:00
|
|
|
$this->eggRepository = $eggRepository;
|
|
|
|
$this->nodeRepository = $nodeRepository;
|
|
|
|
$this->serverRepository = $serverRepository;
|
|
|
|
$this->userRepository = $userRepository;
|
2018-05-04 20:48:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-04 16:45:37 +00:00
|
|
|
public function index(Request $request)
|
|
|
|
{
|
2018-05-26 18:58:49 +00:00
|
|
|
$servers = $this->serverRepository->all();
|
2018-05-04 16:45:37 +00:00
|
|
|
$serversCount = count($servers);
|
2018-05-26 18:58:49 +00:00
|
|
|
$nodes = $this->nodeRepository->all();
|
2018-05-06 15:59:11 +00:00
|
|
|
$nodesCount = count($nodes);
|
2018-05-26 18:58:49 +00:00
|
|
|
$usersCount = $this->userRepository->count();
|
|
|
|
$eggsCount = $this->eggRepository->count();
|
|
|
|
$databasesCount = $this->databaseRepository->count();
|
2018-05-04 16:45:37 +00:00
|
|
|
$totalServerRam = DB::table('servers')->sum('memory');
|
|
|
|
$totalNodeRam = DB::table('nodes')->sum('memory');
|
|
|
|
$totalServerDisk = DB::table('servers')->sum('disk');
|
|
|
|
$totalNodeDisk = DB::table('nodes')->sum('disk');
|
2018-05-26 18:58:49 +00:00
|
|
|
$totalAllocations = $this->allocationRepository->count();
|
|
|
|
$suspendedServersCount = $this->serverRepository->getBuilder()->where('suspended', true)->count();
|
2018-05-04 16:45:37 +00:00
|
|
|
|
2018-05-04 20:48:43 +00:00
|
|
|
$tokens = [];
|
|
|
|
foreach ($nodes as $node) {
|
2018-05-26 18:58:49 +00:00
|
|
|
$tokens[$node->id] = $node->daemonSecret;
|
2018-05-04 20:48:43 +00:00
|
|
|
}
|
|
|
|
|
2018-05-26 18:58:49 +00:00
|
|
|
$this->injectJavascript([
|
2018-05-04 20:48:43 +00:00
|
|
|
'servers' => $servers,
|
2018-05-04 16:45:37 +00:00
|
|
|
'serverCount' => $serversCount,
|
|
|
|
'suspendedServers' => $suspendedServersCount,
|
|
|
|
'totalServerRam' => $totalServerRam,
|
|
|
|
'totalNodeRam' => $totalNodeRam,
|
|
|
|
'totalServerDisk' => $totalServerDisk,
|
|
|
|
'totalNodeDisk' => $totalNodeDisk,
|
2018-05-04 20:48:43 +00:00
|
|
|
'nodes' => $nodes,
|
|
|
|
'tokens' => $tokens,
|
2018-05-04 16:45:37 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
return view('admin.statistics', [
|
|
|
|
'serversCount' => $serversCount,
|
|
|
|
'nodesCount' => $nodesCount,
|
|
|
|
'usersCount' => $usersCount,
|
|
|
|
'eggsCount' => $eggsCount,
|
|
|
|
'totalServerRam' => $totalServerRam,
|
|
|
|
'databasesCount' => $databasesCount,
|
|
|
|
'totalNodeRam' => $totalNodeRam,
|
|
|
|
'totalNodeDisk' => $totalNodeDisk,
|
|
|
|
'totalServerDisk' => $totalServerDisk,
|
|
|
|
'totalAllocations' => $totalAllocations,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|