From c751ce7f44685d8fe5328d1e206643706a85a368 Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Sat, 7 May 2022 14:17:10 -0400 Subject: [PATCH] Allow more values for remote field when creating a database; closes #3842 --- .../Servers/Databases/StoreDatabaseRequest.php | 5 +++-- app/Models/Database.php | 2 +- app/Models/Model.php | 10 ++++++++++ .../server/databases/CreateDatabaseButton.tsx | 15 ++++++++------- storage/clockwork/.gitignore | 0 5 files changed, 22 insertions(+), 10 deletions(-) mode change 100644 => 100755 storage/clockwork/.gitignore diff --git a/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php b/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php index b8f12bd8a..5258062f7 100644 --- a/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php +++ b/app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php @@ -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'), ]; } diff --git a/app/Models/Database.php b/app/Models/Database.php index b09545da8..ebe886793 100644 --- a/app/Models/Database.php +++ b/app/Models/Database.php @@ -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', ]; diff --git a/app/Models/Model.php b/app/Models/Model.php index e5e7fb976..5eaa1fa68 100644 --- a/app/Models/Model.php +++ b/app/Models/Model.php @@ -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. diff --git a/resources/scripts/components/server/databases/CreateDatabaseButton.tsx b/resources/scripts/components/server/databases/CreateDatabaseButton.tsx index c3b47250f..0fdeb4fe9 100644 --- a/resources/scripts/components/server/databases/CreateDatabaseButton.tsx +++ b/resources/scripts/components/server/databases/CreateDatabaseButton.tsx @@ -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) => { 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 () => { <> { @@ -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.'} />
diff --git a/storage/clockwork/.gitignore b/storage/clockwork/.gitignore old mode 100644 new mode 100755