Improved code to generate SFTP usernames
Fixes edge case where specific server names could cause daemon errors due to an invalid SFTP username being created by the panel.
This commit is contained in:
parent
31864de3f4
commit
b71604566e
2 changed files with 17 additions and 4 deletions
|
@ -11,6 +11,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
|
|||
|
||||
### Fixed
|
||||
* Bug causing error logs to be spammed if someone timed out on an ajax based page.
|
||||
* Fixes edge case where specific server names could cause daemon errors due to an invalid SFTP username being created by the panel.
|
||||
|
||||
### Changed
|
||||
* Admin API and base routes for user management now define the fields that should be passed to repositories rather than passing all fields.
|
||||
|
|
|
@ -52,14 +52,26 @@ class ServerRepository
|
|||
* format: mumble_67c7a4b0.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $uuid
|
||||
* @param string $identifier
|
||||
* @return string
|
||||
*/
|
||||
protected function generateSFTPUsername($name, $uuid = null)
|
||||
protected function generateSFTPUsername($name, $identifier = null)
|
||||
{
|
||||
$uuid = is_null($uuid) ? str_random(8) : $uuid;
|
||||
if (is_null($identifier) || ! ctype_alnum($identifier)) {
|
||||
$unique = str_random(8);
|
||||
} else {
|
||||
if (strlen($identifier) < 8) {
|
||||
$unique = $identifier . str_random((8 - strlen($identifier)));
|
||||
} else {
|
||||
$unique = substr($identifier, 0, 8);
|
||||
}
|
||||
}
|
||||
|
||||
return strtolower(substr(preg_replace('/\s+/', '', $name), 0, 6) . '_' . $uuid);
|
||||
// Filter the Server Name
|
||||
$name = trim(preg_replace('/[^\w]+/', '', $name), '_');
|
||||
$name = (strlen($name) < 1) ? str_random(6) : $name;
|
||||
|
||||
return strtolower(substr($name, 0, 6) . '_' . $unique);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue