Skip to content

Commit b3fb658

Browse files
committed
Merge branch '0.7-develop' into develop
2 parents 3820d4e + 468d426 commit b3fb658

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.7.17 (Derelict Dermodactylus)
7+
### Fixed
8+
* Limited accounts to 5 API keys at a time.
9+
* Fixes database passwords not being generated with the proper requirements for some MySQL setups.
10+
* Hostnames that are not FQDNs/IP addresses can now be used for connecting to a MySQL host.
11+
612
## v0.7.16 (Derelict Dermodactylus)
713
### Fixed
814
* Fixed the /api/application/servers endpoint erroring when including subusers or egg

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The MIT License (MIT)
22

33
```
4-
Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>
4+
Copyright (c) 2015 - 2020 Dane Everitt <dane@daneeveritt.com>
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

app/Helpers/Utilities.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Pterodactyl\Helpers;
4+
5+
use Exception;
6+
use Illuminate\Support\Facades\Log;
7+
8+
class Utilities
9+
{
10+
/**
11+
* Generates a random string and injects special characters into it, in addition to
12+
* the randomness of the alpha-numeric default response.
13+
*
14+
* @param int $length
15+
* @return string
16+
*/
17+
public static function randomStringWithSpecialCharacters(int $length = 16): string
18+
{
19+
$string = str_random($length);
20+
// Given a random string of characters, randomly loop through the characters and replace some
21+
// with special characters to avoid issues with MySQL password requirements on some servers.
22+
try {
23+
for ($i = 0; $i < random_int(2, 6); $i++) {
24+
$character = ['!', '@', '=', '.', '+', '^'][random_int(0, 5)];
25+
26+
$string = substr_replace($string, $character, random_int(0, $length - 1), 1);
27+
}
28+
} catch (Exception $exception) {
29+
// Just log the error and hope for the best at this point.
30+
Log::error($exception);
31+
}
32+
33+
return $string;
34+
}
35+
}

app/Models/DatabaseHost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class DatabaseHost extends Validable
5151
*/
5252
public static $validationRules = [
5353
'name' => 'required|string|max:255',
54-
'host' => 'required|ip|unique:database_hosts,host',
54+
'host' => 'required|unique:database_hosts,host',
5555
'port' => 'required|numeric|between:1,65535',
5656
'username' => 'required|string|max:32',
5757
'password' => 'nullable|string',

app/Services/Databases/DatabaseManagementService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Pterodactyl\Models\Database;
7+
use Pterodactyl\Helpers\Utilities;
78
use Illuminate\Database\DatabaseManager;
89
use Illuminate\Contracts\Encryption\Encrypter;
910
use Pterodactyl\Extensions\DynamicDatabaseConnection;
@@ -70,7 +71,9 @@ public function create($server, array $data)
7071
$data['server_id'] = $server;
7172
$data['database'] = sprintf('s%d_%s', $server, $data['database']);
7273
$data['username'] = sprintf('u%d_%s', $server, str_random(10));
73-
$data['password'] = $this->encrypter->encrypt(str_random(24));
74+
$data['password'] = $this->encrypter->encrypt(
75+
Utilities::randomStringWithSpecialCharacters(24)
76+
);
7477

7578
$this->database->beginTransaction();
7679
try {

app/Services/Databases/DatabasePasswordService.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace Pterodactyl\Services\Databases;
44

5-
use Exception;
65
use Pterodactyl\Models\Database;
7-
use Illuminate\Support\Facades\Log;
6+
use Pterodactyl\Helpers\Utilities;
87
use Illuminate\Database\ConnectionInterface;
98
use Illuminate\Contracts\Encryption\Encrypter;
109
use Pterodactyl\Extensions\DynamicDatabaseConnection;
@@ -62,19 +61,7 @@ public function __construct(
6261
*/
6362
public function handle(Database $database): string
6463
{
65-
$password = str_random(24);
66-
// Given a random string of characters, randomly loop through the characters and replace some
67-
// with special characters to avoid issues with MySQL password requirements on some servers.
68-
try {
69-
for ($i = 0; $i < random_int(2, 6); $i++) {
70-
$character = ['!', '@', '=', '.', '+', '^'][random_int(0, 5)];
71-
72-
$password = substr_replace($password, $character, random_int(0, 23), 1);
73-
}
74-
} catch (Exception $exception) {
75-
// Just log the error and hope for the best at this point.
76-
Log::error($exception);
77-
}
64+
$password = Utilities::randomStringWithSpecialCharacters(24);
7865

7966
$this->connection->transaction(function () use ($database, $password) {
8067
$this->dynamic->set('dynamic', $database->database_host_id);

0 commit comments

Comments
 (0)