Skip to content

Commit c751ce7

Browse files
committed
Allow more values for remote field when creating a database; closes pterodactyl#3842
1 parent b07fdc1 commit c751ce7

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

Diff for: app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Webmozart\Assert\Assert;
66
use Pterodactyl\Models\Server;
77
use Illuminate\Validation\Rule;
8+
use Pterodactyl\Models\Database;
89
use Pterodactyl\Models\Permission;
910
use Illuminate\Database\Query\Builder;
1011
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
@@ -28,7 +29,7 @@ public function rules(): array
2829
'database' => [
2930
'required',
3031
'alpha_dash',
31-
'min:1',
32+
'min:3',
3233
'max:48',
3334
// Yes, I am aware that you could have the same database name across two unique hosts. However,
3435
// I don't really care about that for this validation. We just want to make sure it is unique to
@@ -38,7 +39,7 @@ public function rules(): array
3839
->where('database', DatabaseManagementService::generateUniqueDatabaseName($this->input('database'), $server->id));
3940
}),
4041
],
41-
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
42+
'remote' => Database::getRulesForField('remote'),
4243
];
4344
}
4445

Diff for: app/Models/Database.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Database extends Model
6767
'database' => 'required|string|alpha_dash|between:3,48',
6868
'username' => 'string|alpha_dash|between:3,100',
6969
'max_connections' => 'nullable|integer',
70-
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
70+
'remote' => 'required|string|regex:/^[\w\-\/.%:]+$/',
7171
'password' => 'string',
7272
];
7373

Diff for: app/Models/Model.php

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pterodactyl\Models;
44

55
use Illuminate\Support\Str;
6+
use Illuminate\Support\Arr;
67
use Illuminate\Validation\Rule;
78
use Illuminate\Container\Container;
89
use Illuminate\Contracts\Validation\Factory;
@@ -111,6 +112,15 @@ public static function getRules()
111112
return $rules;
112113
}
113114

115+
/**
116+
* Returns the rules for a specific field. If the field is not found an empty
117+
* array is returned.
118+
*/
119+
public static function getRulesForField(string $field): array
120+
{
121+
return Arr::get(static::getRules(), $field) ?? [];
122+
}
123+
114124
/**
115125
* Returns the rules associated with the model, specifically for updating the given model
116126
* rather than just creating it.

Diff for: resources/scripts/components/server/databases/CreateDatabaseButton.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ const schema = object().shape({
2121
.required('A database name must be provided.')
2222
.min(3, 'Database name must be at least 3 characters.')
2323
.max(48, 'Database name must not exceed 48 characters.')
24-
.matches(/^[A-Za-z0-9_\-.]{3,48}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'),
25-
connectionsFrom: string()
26-
.required('A connection value must be provided.')
27-
.matches(/^([0-9]{1,3}|%)(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?$/, 'A valid connection address must be provided.'),
24+
.matches(/^[\w\-.]{3,48}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'),
25+
connectionsFrom: string().matches(/^[\w\-/.%:]+$/, 'A valid host address must be provided.'),
2826
});
2927

3028
export default () => {
@@ -36,7 +34,10 @@ export default () => {
3634

3735
const submit = (values: Values, { setSubmitting }: FormikHelpers<Values>) => {
3836
clearFlashes('database:create');
39-
createServerDatabase(uuid, { ...values })
37+
createServerDatabase(uuid, {
38+
databaseName: values.databaseName,
39+
connectionsFrom: values.connectionsFrom || '%',
40+
})
4041
.then(database => {
4142
appendDatabase(database);
4243
setVisible(false);
@@ -51,7 +52,7 @@ export default () => {
5152
<>
5253
<Formik
5354
onSubmit={submit}
54-
initialValues={{ databaseName: '', connectionsFrom: '%' }}
55+
initialValues={{ databaseName: '', connectionsFrom: '' }}
5556
validationSchema={schema}
5657
>
5758
{
@@ -81,7 +82,7 @@ export default () => {
8182
id={'connections_from'}
8283
name={'connectionsFrom'}
8384
label={'Connections From'}
84-
description={'Where connections should be allowed from. Use % for wildcards.'}
85+
description={'Where connections should be allowed from. Leave blank to allow connections from anywhere.'}
8586
/>
8687
</div>
8788
<div css={tw`flex flex-wrap justify-end mt-6`}>

Diff for: storage/clockwork/.gitignore

100644100755
File mode changed.

0 commit comments

Comments
 (0)