1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-22 00:52:43 +01:00

Allow more values for remote field when creating a database; closes #3842

This commit is contained in:
DaneEveritt 2022-05-07 14:17:10 -04:00
parent b07fdc100c
commit c751ce7f44
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
5 changed files with 22 additions and 10 deletions

View File

@ -5,6 +5,7 @@ namespace Pterodactyl\Http\Requests\Api\Client\Servers\Databases;
use Webmozart\Assert\Assert;
use Pterodactyl\Models\Server;
use Illuminate\Validation\Rule;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\Permission;
use Illuminate\Database\Query\Builder;
use Pterodactyl\Contracts\Http\ClientPermissionsRequest;
@ -28,7 +29,7 @@ class StoreDatabaseRequest extends ClientApiRequest implements ClientPermissions
'database' => [
'required',
'alpha_dash',
'min:1',
'min:3',
'max:48',
// Yes, I am aware that you could have the same database name across two unique hosts. However,
// I don't really care about that for this validation. We just want to make sure it is unique to
@ -38,7 +39,7 @@ class StoreDatabaseRequest extends ClientApiRequest implements ClientPermissions
->where('database', DatabaseManagementService::generateUniqueDatabaseName($this->input('database'), $server->id));
}),
],
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
'remote' => Database::getRulesForField('remote'),
];
}

View File

@ -67,7 +67,7 @@ class Database extends Model
'database' => 'required|string|alpha_dash|between:3,48',
'username' => 'string|alpha_dash|between:3,100',
'max_connections' => 'nullable|integer',
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
'remote' => 'required|string|regex:/^[\w\-\/.%:]+$/',
'password' => 'string',
];

View File

@ -3,6 +3,7 @@
namespace Pterodactyl\Models;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;
use Illuminate\Validation\Rule;
use Illuminate\Container\Container;
use Illuminate\Contracts\Validation\Factory;
@ -111,6 +112,15 @@ abstract class Model extends IlluminateModel
return $rules;
}
/**
* Returns the rules for a specific field. If the field is not found an empty
* array is returned.
*/
public static function getRulesForField(string $field): array
{
return Arr::get(static::getRules(), $field) ?? [];
}
/**
* Returns the rules associated with the model, specifically for updating the given model
* rather than just creating it.

View File

@ -21,10 +21,8 @@ const schema = object().shape({
.required('A database name must be provided.')
.min(3, 'Database name must be at least 3 characters.')
.max(48, 'Database name must not exceed 48 characters.')
.matches(/^[A-Za-z0-9_\-.]{3,48}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'),
connectionsFrom: string()
.required('A connection value must be provided.')
.matches(/^([0-9]{1,3}|%)(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?$/, 'A valid connection address must be provided.'),
.matches(/^[\w\-.]{3,48}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'),
connectionsFrom: string().matches(/^[\w\-/.%:]+$/, 'A valid host address must be provided.'),
});
export default () => {
@ -36,7 +34,10 @@ export default () => {
const submit = (values: Values, { setSubmitting }: FormikHelpers<Values>) => {
clearFlashes('database:create');
createServerDatabase(uuid, { ...values })
createServerDatabase(uuid, {
databaseName: values.databaseName,
connectionsFrom: values.connectionsFrom || '%',
})
.then(database => {
appendDatabase(database);
setVisible(false);
@ -51,7 +52,7 @@ export default () => {
<>
<Formik
onSubmit={submit}
initialValues={{ databaseName: '', connectionsFrom: '%' }}
initialValues={{ databaseName: '', connectionsFrom: '' }}
validationSchema={schema}
>
{
@ -81,7 +82,7 @@ export default () => {
id={'connections_from'}
name={'connectionsFrom'}
label={'Connections From'}
description={'Where connections should be allowed from. Use % for wildcards.'}
description={'Where connections should be allowed from. Leave blank to allow connections from anywhere.'}
/>
</div>
<div css={tw`flex flex-wrap justify-end mt-6`}>

0
storage/clockwork/.gitignore vendored Normal file → Executable file
View File