forked from Alex/Pterodactyl-Panel
Fix database naming conventions; closes #2404
This commit is contained in:
parent
6a4914df3b
commit
c0fc9125ed
@ -22,7 +22,7 @@ class StoreDatabaseRequest extends ClientApiRequest implements ClientPermissions
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'database' => 'required|alpha_dash|min:1|max:100',
|
'database' => 'required|alpha_dash|min:3|max:48',
|
||||||
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ class Database extends Model
|
|||||||
public static $validationRules = [
|
public static $validationRules = [
|
||||||
'server_id' => 'required|numeric|exists:servers,id',
|
'server_id' => 'required|numeric|exists:servers,id',
|
||||||
'database_host_id' => 'required|exists:database_hosts,id',
|
'database_host_id' => 'required|exists:database_hosts,id',
|
||||||
'database' => 'required|string|alpha_dash|between:3,100',
|
'database' => 'required|string|alpha_dash|between:3,48',
|
||||||
'username' => 'string|alpha_dash|between:3,100',
|
'username' => 'string|alpha_dash|between:3,100',
|
||||||
'max_connections' => 'nullable|integer',
|
'max_connections' => 'nullable|integer',
|
||||||
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
|
||||||
|
@ -104,9 +104,12 @@ class DatabaseManagementService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Max of 48 characters, including the s123_ that we append to the front.
|
||||||
|
$truncatedName = substr($data['database'], 0, 48 - strlen("s{$server->id}_"));
|
||||||
|
|
||||||
$data = array_merge($data, [
|
$data = array_merge($data, [
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'database' => sprintf('s%d_%s', $server->id, $data['database']),
|
'database' => $truncatedName,
|
||||||
'username' => sprintf('u%d_%s', $server->id, str_random(10)),
|
'username' => sprintf('u%d_%s', $server->id, str_random(10)),
|
||||||
'password' => $this->encrypter->encrypt(
|
'password' => $this->encrypter->encrypt(
|
||||||
Utilities::randomStringWithSpecialCharacters(24)
|
Utilities::randomStringWithSpecialCharacters(24)
|
||||||
|
@ -19,9 +19,9 @@ interface Values {
|
|||||||
const schema = object().shape({
|
const schema = object().shape({
|
||||||
databaseName: string()
|
databaseName: string()
|
||||||
.required('A database name must be provided.')
|
.required('A database name must be provided.')
|
||||||
.min(5, 'Database name must be at least 5 characters.')
|
.min(3, 'Database name must be at least 3 characters.')
|
||||||
.max(64, 'Database name must not exceed 64 characters.')
|
.max(48, 'Database name must not exceed 48 characters.')
|
||||||
.matches(/^[A-Za-z0-9_\-.]{5,64}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'),
|
.matches(/^[A-Za-z0-9_\-.]{3,48}$/, 'Database name should only contain alphanumeric characters, underscores, dashes, and/or periods.'),
|
||||||
connectionsFrom: string()
|
connectionsFrom: string()
|
||||||
.required('A connection value must be provided.')
|
.required('A connection value must be provided.')
|
||||||
.matches(/^([1-9]{1,3}|%)(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?$/, 'A valid connection address must be provided.'),
|
.matches(/^([1-9]{1,3}|%)(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?(\.([0-9]{1,3}|%))?$/, 'A valid connection address must be provided.'),
|
||||||
|
Loading…
Reference in New Issue
Block a user