Skip to content

Commit 86c8ecd

Browse files
committed
Added the actual logic
1 parent 7cf79a1 commit 86c8ecd

File tree

7 files changed

+101
-2
lines changed

7 files changed

+101
-2
lines changed

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+
'maintenance' => MaintenanceMiddleware::class,
111113

112114
// Server specific middleware (used for authenticating access to resources)
113115
//
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Middleware;
4+
5+
use Closure;
6+
7+
class MaintenanceMiddleware
8+
{
9+
/**
10+
* Handle an incoming request.
11+
*
12+
* @param \Illuminate\Http\Request $request
13+
* @param \Closure $next
14+
* @return mixed
15+
*/
16+
public function handle($request, Closure $next)
17+
{
18+
$server = $request->attributes->get('server');
19+
$node = $server->node;
20+
21+
if ($node->maintenance) {
22+
return response(view('errors.maintenance'));
23+
}
24+
25+
return $next($request);
26+
}
27+
}

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' => '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',
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' => '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' => 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', 'maintenance'])->prefix('/server/{server}')
3737
->namespace($this->namespace . '\Server')
3838
->group(base_path('routes/server.php'));
3939

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddMaintenanceToNodes extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('nodes', function (Blueprint $table) {
17+
$table->boolean('maintenance')->after('behind_proxy')->default(false);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('nodes', function (Blueprint $table) {
29+
$table->dropColumn('maintenance');
30+
});
31+
}
32+
}

resources/lang/en/base.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
'header' => 'Server Suspended',
2222
'desc' => 'This server has been suspended and cannot be accessed.',
2323
],
24+
'maintenance' => [
25+
'header' => 'Node Under Maintenance',
26+
'title' => 'Maintenance',
27+
'desc' => 'This node is under maintenance, therefore your server can temporarily not be accessed.'
28+
],
2429
],
2530
'index' => [
2631
'header' => 'Your Servers',
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{-- Pterodactyl - Panel --}}
2+
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
3+
4+
{{-- This software is licensed under the terms of the MIT license. --}}
5+
{{-- https://opensource.org/licenses/MIT --}}
6+
@extends('layouts.error')
7+
8+
@section('title')
9+
@lang('base.errors.maintenance.header')
10+
@endsection
11+
12+
@section('content-header')
13+
@endsection
14+
15+
@section('content')
16+
<div class="row">
17+
<div class="col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1 col-xs-12">
18+
<div class="box box-danger">
19+
<div class="box-body text-center">
20+
<h1 class="text-red" style="font-size: 160px !important;font-weight: 100 !important;">@lang('base.errors.maintenance.title')</h1>
21+
<p class="text-muted">@lang('base.errors.maintenance.desc')</p>
22+
</div>
23+
<div class="box-footer with-border">
24+
<a href="{{ URL::previous() }}"><button class="btn btn-danger">&larr; @lang('base.errors.return')</button></a>
25+
<a href="/"><button class="btn btn-default">@lang('base.errors.home')</button></a>
26+
</div>
27+
</div>
28+
</div>
29+
</div>
30+
@endsection

0 commit comments

Comments
 (0)