Skip to content

Commit c0fc912

Browse files
committed
Fix database naming conventions; closes pterodactyl#2404
1 parent 6a4914d commit c0fc912

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

app/Http/Requests/Api/Client/Servers/Databases/StoreDatabaseRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function permission(): string
2222
public function rules(): array
2323
{
2424
return [
25-
'database' => 'required|alpha_dash|min:1|max:100',
25+
'database' => 'required|alpha_dash|min:3|max:48',
2626
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
2727
];
2828
}

app/Models/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Database extends Model
6565
public static $validationRules = [
6666
'server_id' => 'required|numeric|exists:servers,id',
6767
'database_host_id' => 'required|exists:database_hosts,id',
68-
'database' => 'required|string|alpha_dash|between:3,100',
68+
'database' => 'required|string|alpha_dash|between:3,48',
6969
'username' => 'string|alpha_dash|between:3,100',
7070
'max_connections' => 'nullable|integer',
7171
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',

app/Services/Databases/DatabaseManagementService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ public function create(Server $server, array $data)
104104
}
105105
}
106106

107+
// Max of 48 characters, including the s123_ that we append to the front.
108+
$truncatedName = substr($data['database'], 0, 48 - strlen("s{$server->id}_"));
109+
107110
$data = array_merge($data, [
108111
'server_id' => $server->id,
109-
'database' => sprintf('s%d_%s', $server->id, $data['database']),
112+
'database' => $truncatedName,
110113
'username' => sprintf('u%d_%s', $server->id, str_random(10)),
111114
'password' => $this->encrypter->encrypt(
112115
Utilities::randomStringWithSpecialCharacters(24)

resources/scripts/components/server/databases/CreateDatabaseButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ interface Values {
1919
const schema = object().shape({
2020
databaseName: string()
2121
.required('A database name must be provided.')
22-
.min(5, 'Database name must be at least 5 characters.')
23-
.max(64, 'Database name must not exceed 64 characters.')
24-
.matches(/^[A-Za-z0-9_\-.]{5,64}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'),
22+
.min(3, 'Database name must be at least 3 characters.')
23+
.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.'),
2525
connectionsFrom: string()
2626
.required('A connection value must be provided.')
2727
.matches(/^([1-9]{1,3}|%)(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?$/, 'A valid connection address must be provided.'),

0 commit comments

Comments
 (0)