Skip to content

Commit 19567ee

Browse files
authored
Merge branch 'develop' into fix/trusted-proxies
2 parents 7b659a7 + 8cac2a3 commit 19567ee

File tree

24 files changed

+5449
-56
lines changed

24 files changed

+5449
-56
lines changed

.gitignore

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
/vendor
22
*.DS_Store*
33
.env
4-
.vagrant/*
5-
6-
composer.lock
7-
8-
Homestead.yaml
9-
Vagrantfile
10-
Vagrantfile
11-
12-
node_modules
4+
node_modules

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1010
* Users can now have a username as well as client name assigned to their account.
1111
* Ability to create a node through the CLI using `pterodactyl:node` as well as locations via `pterodactyl:location`.
1212
* New theme (AdminLTE) for front-end with tweaks to backend files to work properly with it.
13+
* Add support for PhraseApp's in-context editor
1314

1415
### Fixed
1516
* Bug causing error logs to be spammed if someone timed out on an ajax based page.
1617
* Fixes edge case where specific server names could cause daemon errors due to an invalid SFTP username being created by the panel.
18+
* Fixes sessions being removed on browser close, and set sessions to idle for up to 3 hours before being marked as expired.
1719

1820
### Changed
1921
* Admin API and base routes for user management now define the fields that should be passed to repositories rather than passing all fields.
2022
* User model now defines mass assignment fields using `$fillable` rather than `$guarded`.
21-
22-
### Deprecated
23+
* 2FA checkpoint on login is now its own page, and not an AJAX based call. Improves security on that front.
2324

2425
## v0.5.6 (Bodacious Boreopterus)
2526
### Added

app/Console/Commands/UpdateEmailSettings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public function handle()
155155

156156
file_put_contents($file, $envContents);
157157
$bar->finish();
158+
159+
$this->line('Updating evironment configuration cache file.');
160+
$this->call('config:cache');
158161
echo "\n";
159162
}
160163
}

app/Console/Commands/UpdateEnvironment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public function handle()
150150

151151
file_put_contents($file, $envContents);
152152
$bar->finish();
153+
154+
$this->line('Updating evironment configuration cache file.');
155+
$this->call('config:cache');
153156
echo "\n";
154157
}
155158
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Extensions;
26+
27+
use Illuminate\Translation\Translator as LaravelTranslator;
28+
29+
class PhraseAppTranslator extends LaravelTranslator
30+
{
31+
/**
32+
* Get the translation for the given key.
33+
*
34+
* @param string $key
35+
* @param array $replace
36+
* @param string|null $locale
37+
* @param bool $fallback
38+
* @return string|array|null
39+
*/
40+
public function get($key, array $replace = [], $locale = null, $fallback = true)
41+
{
42+
$key = substr($key, strpos($key, '.') + 1);
43+
44+
return "{{__phrase_${key}__}}";
45+
}
46+
}

app/Http/Controllers/API/ServerController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ public function view(Request $request, $id)
117117
}
118118

119119
// Requested Daemon Stats
120-
$server = $query->first();
120+
$server = $query->with(
121+
'allocations',
122+
'pack'
123+
)->first();
121124
if ($request->input('daemon') === 'true') {
122125
$node = Models\Node::findOrFail($server->node);
123126
$client = Models\Node::guzzleRequest($node->id);

app/Http/Controllers/API/ServiceController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function view(Request $request, $id)
5555
'options' => Models\ServiceOptions::select('id', 'name', 'description', 'tag', 'docker_image')
5656
->where('parent_service', $service->id)
5757
->with('variables')
58+
->with('packs')
5859
->get(),
5960
];
6061
}

app/Http/Controllers/Auth/LoginController.php

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
use Auth;
2929
use Alert;
30+
use Cache;
3031
use Illuminate\Http\Request;
3132
use Pterodactyl\Models\User;
3233
use PragmaRX\Google2FA\Google2FA;
@@ -110,33 +111,62 @@ public function login(Request $request)
110111
}
111112

112113
// Verify TOTP Token was Valid
113-
if (Auth::user()->use_totp === 1) {
114-
$G2FA = new Google2FA();
115-
if (is_null($request->input('totp_token')) || ! $G2FA->verifyKey(Auth::user()->totp_secret, $request->input('totp_token'))) {
116-
if (! $lockedOut) {
117-
$this->incrementLoginAttempts($request);
118-
}
114+
if (Auth::user()->use_totp) {
115+
$verifyKey = str_random(64);
116+
Cache::put($verifyKey, Auth::user()->id, 5);
119117

120-
Alert::danger(trans('auth.totp_failed'))->flash();
118+
return redirect()->route('auth.totp')->with('authentication_token', $verifyKey);
119+
} else {
120+
Auth::login(Auth::user(), $request->has('remember'));
121121

122-
return $this->sendFailedLoginResponse($request);
123-
}
122+
return $this->sendLoginResponse($request);
124123
}
124+
}
125+
126+
public function totp(Request $request)
127+
{
128+
$verifyKey = $request->session()->get('authentication_token');
125129

126-
// Successfully Authenticated.
127-
Auth::login(Auth::user(), $request->has('remember'));
130+
if (is_null($verifyKey) || Auth::user()) {
131+
return redirect()->route('auth.login');
132+
}
128133

129-
return $this->sendLoginResponse($request);
134+
return view('auth.totp', [
135+
'verify_key' => $verifyKey,
136+
'remember' => $request->has('remember'),
137+
]);
130138
}
131139

132-
/**
133-
* Check if the provided user has TOTP enabled.
134-
*
135-
* @param \Illuminate\Http\Request $request
136-
* @return \Illuminate\Http\Response
137-
*/
138-
public function checkTotp(Request $request)
140+
public function totpCheckpoint(Request $request)
139141
{
140-
return response()->json(User::select('id')->where('email', $request->input('email'))->where('use_totp', 1)->first());
142+
$G2FA = new Google2FA();
143+
144+
if (is_null($request->input('verify_token'))) {
145+
$this->incrementLoginAttempts($request);
146+
Alert::danger(trans('auth.totp_failed'))->flash();
147+
148+
return redirect()->route('auth.login');
149+
}
150+
151+
$user = User::where('id', Cache::pull($request->input('verify_token')))->first();
152+
if (! $user) {
153+
$this->incrementLoginAttempts($request);
154+
Alert::danger(trans('auth.totp_failed'))->flash();
155+
156+
return redirect()->route('auth.login');
157+
}
158+
159+
160+
if (! is_null($request->input('2fa_token')) && $G2FA->verifyKey($user->totp_secret, $request->input('2fa_token'), 1)) {
161+
Auth::login($user, $request->has('remember'));
162+
163+
return redirect()->intended($this->redirectPath());
164+
} else {
165+
$this->incrementLoginAttempts($request);
166+
Alert::danger(trans('auth.2fa_failed'))->flash();
167+
168+
return redirect()->route('auth.login');
169+
}
141170
}
171+
142172
}

app/Http/Routes/AuthRoutes.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ public function map(Router $router)
5151
'uses' => 'Auth\LoginController@login',
5252
]);
5353

54-
// Determine if we need to ask for a TOTP Token
54+
$router->get('login/totp', [
55+
'as' => 'auth.totp',
56+
'uses' => 'Auth\LoginController@totp',
57+
]);
58+
5559
$router->post('login/totp', [
56-
'uses' => 'Auth\LoginController@checkTotp',
60+
'uses' => 'Auth\LoginController@totpCheckpoint',
5761
]);
5862

5963
// Show Password Reset Form

app/Models/Server.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,54 @@ public static function getGuzzleHeaders($uuid)
208208

209209
return [];
210210
}
211+
212+
/**
213+
* Gets all allocations associated with this server.
214+
*
215+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
216+
*/
217+
public function allocations()
218+
{
219+
return $this->hasMany(Allocation::class, 'assigned_to');
220+
}
221+
222+
/**
223+
* Gets information for the pack associated with this server.
224+
*
225+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
226+
*/
227+
public function pack()
228+
{
229+
return $this->hasOne(ServicePack::class, 'id', 'pack');
230+
}
231+
232+
/**
233+
* Gets information for the service associated with this server.
234+
*
235+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
236+
*/
237+
public function service()
238+
{
239+
return $this->hasOne(Service::class, 'id', 'service');
240+
}
241+
242+
/**
243+
* Gets information for the service option associated with this server.
244+
*
245+
* @return \Illuminate\Database\Eloquent\Relations\HasOne
246+
*/
247+
public function option()
248+
{
249+
return $this->hasOne(ServiceOptions::class, 'id', 'option');
250+
}
251+
252+
/**
253+
* Gets information for the service variables associated with this server.
254+
*
255+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
256+
*/
257+
public function variables()
258+
{
259+
return $this->hasMany(ServerVariables::class);
260+
}
211261
}

0 commit comments

Comments
 (0)