Skip to content

Commit b716045

Browse files
committed
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.
1 parent 31864de commit b716045

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1111

1212
### Fixed
1313
* Bug causing error logs to be spammed if someone timed out on an ajax based page.
14+
* Fixes edge case where specific server names could cause daemon errors due to an invalid SFTP username being created by the panel.
1415

1516
### Changed
1617
* Admin API and base routes for user management now define the fields that should be passed to repositories rather than passing all fields.

app/Repositories/ServerRepository.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,26 @@ public function __construct()
5252
* format: mumble_67c7a4b0.
5353
*
5454
* @param string $name
55-
* @param string $uuid
55+
* @param string $identifier
5656
* @return string
5757
*/
58-
protected function generateSFTPUsername($name, $uuid = null)
58+
protected function generateSFTPUsername($name, $identifier = null)
5959
{
60-
$uuid = is_null($uuid) ? str_random(8) : $uuid;
60+
if (is_null($identifier) || ! ctype_alnum($identifier)) {
61+
$unique = str_random(8);
62+
} else {
63+
if (strlen($identifier) < 8) {
64+
$unique = $identifier . str_random((8 - strlen($identifier)));
65+
} else {
66+
$unique = substr($identifier, 0, 8);
67+
}
68+
}
69+
70+
// Filter the Server Name
71+
$name = trim(preg_replace('/[^\w]+/', '', $name), '_');
72+
$name = (strlen($name) < 1) ? str_random(6) : $name;
6173

62-
return strtolower(substr(preg_replace('/\s+/', '', $name), 0, 6) . '_' . $uuid);
74+
return strtolower(substr($name, 0, 6) . '_' . $unique);
6375
}
6476

6577
/**

0 commit comments

Comments
 (0)