Skip to content

Commit e0d67ff

Browse files
committed
Merge branch 'feature/vuejs' into feature/vue-serverview
2 parents e808919 + 5f70502 commit e0d67ff

File tree

31 files changed

+835
-7
lines changed

31 files changed

+835
-7
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.7.8 (Derelict Dermodactylus)
7+
### Added
8+
* Nodes can now be put into maintenance mode to deny access to servers temporarily.
9+
* Basic statistics about your panel are now available in the Admin CP.
10+
11+
### Fixed
12+
* Hitting Ctrl+Z when editing a file on the web now works as expected.
13+
* Logo now links to the correct location on all pages.
14+
15+
### Changed
16+
* Attempting to upload a folder via the web file manager will now display a warning telling the user to use SFTP.
17+
618
## v0.7.7 (Derelict Dermodactylus)
719
### Fixed
820
* Fixes an issue with the sidebar logo not working correctly in some browsers due to the CSS being assigned.

app/Contracts/Repository/NodeRepositoryInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ interface NodeRepositoryInterface extends RepositoryInterface, SearchableInterfa
2121
*/
2222
public function getUsageStats(Node $node): array;
2323

24+
/**
25+
* Return the usage stats for a single node.
26+
*
27+
* @param \Pterodactyl\Models\Node $node
28+
* @return array
29+
*/
30+
public function getUsageStatsRaw(Node $node): array;
31+
2432
/**
2533
* Return all available nodes with a searchable interface.
2634
*

app/Contracts/Repository/RepositoryInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,11 @@ public function insert(array $data): bool;
200200
* @return bool
201201
*/
202202
public function insertIgnore(array $values): bool;
203+
204+
/**
205+
* Get the amount of entries in the database
206+
*
207+
* @return int
208+
*/
209+
public function count(): int;
203210
}

app/Contracts/Repository/ServerRepositoryInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,11 @@ public function getServersForPowerActionCount(array $servers = [], array $nodes
145145
* @return bool
146146
*/
147147
public function isUniqueUuidCombo(string $uuid, string $short): bool;
148+
149+
/**
150+
* Get the amount of servers that are suspended
151+
*
152+
* @return int
153+
*/
154+
public function getSuspendedServersCount(): int;
148155
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Admin;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\DB;
7+
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
8+
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
9+
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
10+
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
11+
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
12+
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
13+
use Pterodactyl\Http\Controllers\Controller;
14+
use Pterodactyl\Traits\Controllers\PlainJavascriptInjection;
15+
16+
class StatisticsController extends Controller
17+
{
18+
use PlainJavascriptInjection;
19+
20+
private $allocationRepository;
21+
22+
private $databaseRepository;
23+
24+
private $eggRepository;
25+
26+
private $nodeRepository;
27+
28+
private $serverRepository;
29+
30+
private $userRepository;
31+
32+
function __construct(
33+
AllocationRepositoryInterface $allocationRepository,
34+
DatabaseRepositoryInterface $databaseRepository,
35+
EggRepositoryInterface $eggRepository,
36+
NodeRepositoryInterface $nodeRepository,
37+
ServerRepositoryInterface $serverRepository,
38+
UserRepositoryInterface $userRepository
39+
)
40+
{
41+
$this->allocationRepository = $allocationRepository;
42+
$this->databaseRepository = $databaseRepository;
43+
$this->eggRepository = $eggRepository;
44+
$this->nodeRepository = $nodeRepository;
45+
$this->serverRepository = $serverRepository;
46+
$this->userRepository = $userRepository;
47+
}
48+
49+
public function index()
50+
{
51+
$servers = $this->serverRepository->all();
52+
$nodes = $this->nodeRepository->all();
53+
$usersCount = $this->userRepository->count();
54+
$eggsCount = $this->eggRepository->count();
55+
$databasesCount = $this->databaseRepository->count();
56+
$totalAllocations = $this->allocationRepository->count();
57+
$suspendedServersCount = $this->serverRepository->getSuspendedServersCount();
58+
59+
$totalServerRam = 0;
60+
$totalNodeRam = 0;
61+
$totalServerDisk = 0;
62+
$totalNodeDisk = 0;
63+
foreach ($nodes as $node) {
64+
$stats = $this->nodeRepository->getUsageStatsRaw($node);
65+
$totalServerRam += $stats['memory']['value'];
66+
$totalNodeRam += $stats['memory']['max'];
67+
$totalServerDisk += $stats['disk']['value'];
68+
$totalNodeDisk += $stats['disk']['max'];
69+
}
70+
71+
$tokens = [];
72+
foreach ($nodes as $node) {
73+
$tokens[$node->id] = $node->daemonSecret;
74+
}
75+
76+
$this->injectJavascript([
77+
'servers' => $servers,
78+
'suspendedServers' => $suspendedServersCount,
79+
'totalServerRam' => $totalServerRam,
80+
'totalNodeRam' => $totalNodeRam,
81+
'totalServerDisk' => $totalServerDisk,
82+
'totalNodeDisk' => $totalNodeDisk,
83+
'nodes' => $nodes,
84+
'tokens' => $tokens,
85+
]);
86+
87+
return view('admin.statistics', [
88+
'servers' => $servers,
89+
'nodes' => $nodes,
90+
'usersCount' => $usersCount,
91+
'eggsCount' => $eggsCount,
92+
'totalServerRam' => $totalServerRam,
93+
'databasesCount' => $databasesCount,
94+
'totalNodeRam' => $totalNodeRam,
95+
'totalNodeDisk' => $totalNodeDisk,
96+
'totalServerDisk' => $totalServerDisk,
97+
'totalAllocations' => $totalAllocations,
98+
]);
99+
}
100+
101+
}

app/Http/Kernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pterodactyl\Http;
44

5+
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
56
use Pterodactyl\Models\ApiKey;
67
use Illuminate\Auth\Middleware\Authorize;
78
use Illuminate\Auth\Middleware\Authenticate;
@@ -108,6 +109,7 @@ class Kernel extends HttpKernel
108109
'can' => Authorize::class,
109110
'bindings' => SubstituteBindings::class,
110111
'recaptcha' => VerifyReCaptcha::class,
112+
'node.maintenance' => MaintenanceMiddleware::class,
111113

112114
// Server specific middleware (used for authenticating access to resources)
113115
//
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Contracts\Routing\ResponseFactory;
7+
8+
class MaintenanceMiddleware
9+
{
10+
/**
11+
* @var \Illuminate\Contracts\Routing\ResponseFactory
12+
*/
13+
private $response;
14+
15+
/**
16+
* MaintenanceMiddleware constructor.
17+
*
18+
* @param \Illuminate\Contracts\Routing\ResponseFactory $response
19+
*/
20+
public function __construct(ResponseFactory $response)
21+
{
22+
$this->response = $response;
23+
}
24+
25+
/**
26+
* Handle an incoming request.
27+
*
28+
* @param \Illuminate\Http\Request $request
29+
* @param \Closure $next
30+
* @return mixed
31+
*/
32+
public function handle($request, Closure $next)
33+
{
34+
/** @var \Pterodactyl\Models\Server $server */
35+
$server = $request->attributes->get('server');
36+
$node = $server->getRelation('node');
37+
38+
if ($node->maintenance_mode) {
39+
return $this->response->view('errors.maintenance');
40+
}
41+
42+
return $next($request);
43+
}
44+
}

app/Models/Node.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
4848
'daemonSFTP' => 'integer',
4949
'behind_proxy' => 'boolean',
5050
'public' => 'boolean',
51+
'maintenance_mode' => 'boolean',
5152
];
5253

5354
/**
@@ -62,7 +63,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
6263
'disk_overallocate', 'upload_size',
6364
'daemonSecret', 'daemonBase',
6465
'daemonSFTP', 'daemonListen',
65-
'description',
66+
'description', 'maintenance_mode',
6667
];
6768

6869
/**
@@ -111,6 +112,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
111112
'daemonBase' => 'regex:/^([\/][\d\w.\-\/]+)$/',
112113
'daemonSFTP' => 'numeric|between:1024,65535',
113114
'daemonListen' => 'numeric|between:1024,65535',
115+
'maintenance_mode' => 'boolean',
114116
];
115117

116118
/**
@@ -126,6 +128,7 @@ class Node extends Model implements CleansAttributes, ValidableContract
126128
'daemonBase' => '/srv/daemon-data',
127129
'daemonSFTP' => 2022,
128130
'daemonListen' => 8080,
131+
'maintenance_mode' => false,
129132
];
130133

131134
/**

app/Providers/RouteServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function map()
3333
->namespace($this->namespace . '\Auth')
3434
->group(base_path('routes/auth.php'));
3535

36-
Route::middleware(['web', 'csrf', 'auth', 'server', 'subuser.auth'])->prefix('/server/{server}')
36+
Route::middleware(['web', 'csrf', 'auth', 'server', 'subuser.auth', 'node.maintenance'])->prefix('/server/{server}')
3737
->namespace($this->namespace . '\Server')
3838
->group(base_path('routes/server.php'));
3939

app/Repositories/Eloquent/EloquentRepository.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,14 @@ public function insertIgnore(array $values): bool
296296

297297
return $this->getBuilder()->getConnection()->statement($statement, $bindings);
298298
}
299+
300+
/**
301+
* Get the amount of entries in the database
302+
*
303+
* @return int
304+
*/
305+
public function count(): int
306+
{
307+
return $this->getBuilder()->count();
308+
}
299309
}

0 commit comments

Comments
 (0)