Skip to content

Commit 6967b9b

Browse files
committed
Fix exception thrown due to lack of pre-validation on the model.
closes pterodactyl#1158
1 parent fae5acf commit 6967b9b

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
88
* Fixes an issue with the sidebar logo not working correctly in some browsers due to the CSS being assigned.
99
* Fixes a bunch of typos through the code base.
1010
* Fixes a bug when attempting to load the dropdown menu for server owner in some cases.
11+
* Fixes an exception thrown when the database connection address was not filled out correctly while adding a database to a server.
1112

1213
### Added
1314
* Added a new client API endpoint for gathering the utilization stats for servers including disk, cpu, and memory. `GET /api/client/servers/<id>/utilization`

app/Http/Controllers/Admin/ServersController.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface;
3636
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
3737
use Pterodactyl\Contracts\Repository\AllocationRepositoryInterface;
38+
use Pterodactyl\Http\Requests\Admin\Servers\Databases\StoreServerDatabaseRequest;
3839

3940
class ServersController extends Controller
4041
{
@@ -537,7 +538,7 @@ public function delete(Request $request, Server $server)
537538
/**
538539
* Update the startup command as well as variables.
539540
*
540-
* @param \Illuminate\Http\Request $request
541+
* @param \Illuminate\Http\Request $request
541542
* @param \Pterodactyl\Models\Server $server
542543
* @return \Illuminate\Http\RedirectResponse
543544
*
@@ -558,15 +559,13 @@ public function saveStartup(Request $request, Server $server)
558559
/**
559560
* Creates a new database assigned to a specific server.
560561
*
561-
* @param \Illuminate\Http\Request $request
562-
* @param int $server
562+
* @param \Pterodactyl\Http\Requests\Admin\Servers\Databases\StoreServerDatabaseRequest $request
563+
* @param int $server
563564
* @return \Illuminate\Http\RedirectResponse
564565
*
565566
* @throws \Exception
566-
* @throws \Pterodactyl\Exceptions\DisplayException
567-
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
568567
*/
569-
public function newDatabase(Request $request, $server)
568+
public function newDatabase(StoreServerDatabaseRequest $request, $server)
570569
{
571570
$this->databaseManagementService->create($server, [
572571
'database' => $request->input('database'),

app/Http/Controllers/Api/Application/Servers/DatabaseController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ public function resetPassword(ServerDatabaseWriteRequest $request): Response
104104
* @return \Illuminate\Http\JsonResponse
105105
*
106106
* @throws \Exception
107-
* @throws \Pterodactyl\Exceptions\DisplayException
108-
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
109107
*/
110108
public function store(StoreServerDatabaseRequest $request): JsonResponse
111109
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Requests\Admin\Servers\Databases;
4+
5+
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
6+
7+
class StoreServerDatabaseRequest extends AdminFormRequest
8+
{
9+
/**
10+
* Validation rules for database creation.
11+
*
12+
* @return array
13+
*/
14+
public function rules(): array
15+
{
16+
return [
17+
'database' => 'required|string|min:1|max:24',
18+
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
19+
'database_host_id' => 'required|integer|exists:database_hosts,id',
20+
];
21+
}
22+
}

app/Http/Requests/Api/Application/Servers/Databases/StoreServerDatabaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function rules(): array
2626
{
2727
return [
2828
'database' => 'required|string|min:1|max:24',
29-
'remote' => 'required|string|min:1',
29+
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
3030
'host' => 'required|integer|exists:database_hosts,id',
3131
];
3232
}

0 commit comments

Comments
 (0)