Skip to content

Commit e4425ee

Browse files
committed
Merge branch 'release/v0.7.1'
2 parents 4927af2 + 5d1d8a7 commit e4425ee

File tree

19 files changed

+244
-107
lines changed

19 files changed

+244
-107
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ 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.1 (Derelict Dermodactylus)
7+
### Fixed
8+
* Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted.
9+
* Fixes an exception when trying to perform actions aganist a User model due to a validator that could not be cast to a string correctly.
10+
* Allow FQDNs in database host creation UI correctly.
11+
* Fixes database naming scheme using `d###_` rather than `s###_` when creating server databases.
12+
* Fix exception thrown when attempting to update an existing database host.
13+
14+
### Changed
15+
* Adjusted exception handler behavior to log more stack information for PDO exceptions while not exposing credentials.
16+
17+
### Added
18+
* Very basic cache busting until asset management can be changed to make use of better systems.
19+
620
## v0.7.0 (Derelict Dermodactylus)
721
### Fixed
822
* `[rc.2]` — Fixes bad API behavior on `/user` routes.

app/Exceptions/Handler.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ class Handler extends ExceptionHandler
3232
ValidationException::class,
3333
];
3434

35+
/**
36+
* A list of exceptions that should be logged with cleaned stack
37+
* traces to avoid exposing credentials or other sensitive information.
38+
*
39+
* @var array
40+
*/
41+
protected $cleanStacks = [
42+
PDOException::class,
43+
];
44+
3545
/**
3646
* A list of the inputs that are never flashed for validation exceptions.
3747
*
@@ -73,7 +83,40 @@ public function report(Exception $exception)
7383
throw $exception;
7484
}
7585

76-
return $logger->error($exception instanceof PDOException ? $exception->getMessage() : $exception);
86+
foreach ($this->cleanStacks as $class) {
87+
if ($exception instanceof $class) {
88+
$exception = $this->generateCleanedExceptionStack($exception);
89+
break;
90+
}
91+
}
92+
93+
return $logger->error($exception);
94+
}
95+
96+
private function generateCleanedExceptionStack(Exception $exception)
97+
{
98+
$cleanedStack = '';
99+
foreach ($exception->getTrace() as $index => $item) {
100+
$cleanedStack .= sprintf(
101+
"#%d %s(%d): %s%s%s\n",
102+
$index,
103+
array_get($item, 'file'),
104+
array_get($item, 'line'),
105+
array_get($item, 'class'),
106+
array_get($item, 'type'),
107+
array_get($item, 'function')
108+
);
109+
}
110+
111+
$message = sprintf(
112+
'%s: %s in %s:%d',
113+
class_basename($exception),
114+
$exception->getMessage(),
115+
$exception->getFile(),
116+
$exception->getLine()
117+
);
118+
119+
return $message . "\nStack trace:\n" . trim($cleanedStack);
77120
}
78121

79122
/**

app/Http/Controllers/Admin/DatabaseController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use PDOException;
1313
use Illuminate\View\View;
14+
use Pterodactyl\Models\DatabaseHost;
1415
use Illuminate\Http\RedirectResponse;
1516
use Prologue\Alerts\AlertsMessageBag;
1617
use Pterodactyl\Http\Controllers\Controller;
@@ -136,22 +137,25 @@ public function create(DatabaseHostFormRequest $request): RedirectResponse
136137
* Handle updating database host.
137138
*
138139
* @param \Pterodactyl\Http\Requests\Admin\DatabaseHostFormRequest $request
139-
* @param int $host
140+
* @param \Pterodactyl\Models\DatabaseHost $host
140141
* @return \Illuminate\Http\RedirectResponse
141142
*
142143
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
143144
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
144145
*/
145-
public function update(DatabaseHostFormRequest $request, int $host): RedirectResponse
146+
public function update(DatabaseHostFormRequest $request, DatabaseHost $host): RedirectResponse
146147
{
148+
$redirect = redirect()->route('admin.databases.view', $host->id);
149+
147150
try {
148-
$host = $this->updateService->handle($host, $request->normalize());
151+
$this->updateService->handle($host->id, $request->normalize());
149152
$this->alert->success('Database host was updated successfully.')->flash();
150153
} catch (PDOException $ex) {
151154
$this->alert->danger($ex->getMessage())->flash();
155+
$redirect->withInput($request->normalize());
152156
}
153157

154-
return redirect()->route('admin.databases.view', $host->id);
158+
return $redirect;
155159
}
156160

157161
/**

app/Http/Controllers/Base/SecurityController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function generateTotp(Request $request)
107107
public function setTotp(Request $request)
108108
{
109109
try {
110-
$this->toggleTwoFactorService->handle($request->user(), $request->input('token'));
110+
$this->toggleTwoFactorService->handle($request->user(), $request->input('token') ?? '');
111111

112112
return response('true');
113113
} catch (TwoFactorAuthenticationTokenInvalid $exception) {
@@ -127,7 +127,7 @@ public function setTotp(Request $request)
127127
public function disableTotp(Request $request)
128128
{
129129
try {
130-
$this->toggleTwoFactorService->handle($request->user(), $request->input('token'), false);
130+
$this->toggleTwoFactorService->handle($request->user(), $request->input('token') ?? '', false);
131131
} catch (TwoFactorAuthenticationTokenInvalid $exception) {
132132
$this->alert->danger(trans('base.security.2fa_disable_error'))->flash();
133133
}
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Http\Requests\Admin;
114

@@ -18,14 +11,28 @@ class DatabaseHostFormRequest extends AdminFormRequest
1811
*/
1912
public function rules()
2013
{
21-
if (! $this->filled('node_id')) {
22-
$this->merge(['node_id' => null]);
23-
}
24-
2514
if ($this->method() !== 'POST') {
2615
return DatabaseHost::getUpdateRulesForId($this->route()->parameter('host'));
2716
}
2817

2918
return DatabaseHost::getCreateRules();
3019
}
20+
21+
/**
22+
* Modify submitted data before it is passed off to the validator.
23+
*
24+
* @return \Illuminate\Contracts\Validation\Validator
25+
*/
26+
protected function getValidatorInstance()
27+
{
28+
if (! $this->filled('node_id')) {
29+
$this->merge(['node_id' => null]);
30+
}
31+
32+
$this->merge([
33+
'host' => gethostbyname($this->input('host')),
34+
]);
35+
36+
return parent::getValidatorInstance();
37+
}
3138
}

app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Pterodactyl\Models\Server;
99
use Pterodactyl\Models\Subuser;
1010
use Illuminate\Support\Facades\Schema;
11+
use Igaster\LaravelTheme\Facades\Theme;
1112
use Illuminate\Support\ServiceProvider;
1213
use Pterodactyl\Observers\UserObserver;
1314
use Pterodactyl\Observers\ServerObserver;
@@ -28,6 +29,7 @@ public function boot()
2829

2930
View::share('appVersion', $this->versionData()['version'] ?? 'undefined');
3031
View::share('appIsGit', $this->versionData()['is_git'] ?? false);
32+
Theme::setSetting('cache-version', md5($this->versionData()['version'] ?? 'undefined'));
3133
}
3234

3335
/**

app/Rules/Username.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class Username implements Rule
88
{
9+
/**
10+
* Regex to use when validating usernames.
11+
*/
912
public const VALIDATION_REGEX = '/^[a-z0-9]([\w\.-]+)[a-z0-9]$/';
1013

1114
/**
@@ -33,4 +36,15 @@ public function message(): string
3336
return 'The :attribute must start and end with alpha-numeric characters and
3437
contain only letters, numbers, dashes, underscores, and periods.';
3538
}
39+
40+
/**
41+
* Convert the rule to a validation string. This is necessary to avoid
42+
* issues with Eloquence which tries to use this rule as a string.
43+
*
44+
* @return string
45+
*/
46+
public function __toString()
47+
{
48+
return 'p_username';
49+
}
3650
}

app/Services/Databases/DatabaseManagementService.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Services\Databases;
114

@@ -65,13 +58,11 @@ public function __construct(
6558
* @return \Illuminate\Database\Eloquent\Model
6659
*
6760
* @throws \Exception
68-
* @throws \Pterodactyl\Exceptions\DisplayException
69-
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
7061
*/
7162
public function create($server, array $data)
7263
{
7364
$data['server_id'] = $server;
74-
$data['database'] = sprintf('d%d_%s', $server, $data['database']);
65+
$data['database'] = sprintf('s%d_%s', $server, $data['database']);
7566
$data['username'] = sprintf('u%d_%s', $server, str_random(10));
7667
$data['password'] = $this->encrypter->encrypt(str_random(16));
7768

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"fideloper/proxy": "^3.3",
2323
"guzzlehttp/guzzle": "^6.3",
2424
"hashids/hashids": "^2.0",
25-
"igaster/laravel-theme": "^1.16",
25+
"igaster/laravel-theme": "^2.0.6",
2626
"laracasts/utilities": "^3.0",
2727
"laravel/framework": "5.5.*",
2828
"laravel/tinker": "^1.0",

composer.lock

Lines changed: 22 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)