Change SFTP username to be name_uuidShort

This commit is contained in:
Dane Everitt 2016-10-14 15:34:01 -04:00
parent 20db3f9058
commit a115c71433
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -51,19 +51,17 @@ class ServerRepository
/**
* Generates a SFTP username for a server given a server name.
* format: mumble_67c7a4b0
*
* @param string $name
* @param string $uuid
* @return string
*/
protected function generateSFTPUsername($name)
protected function generateSFTPUsername($name, $uuid = null)
{
$name = preg_replace('/\s+/', '', $name);
if (strlen($name) > 6) {
return strtolower('ptdl-' . substr($name, 0, 6) . '_' . str_random(5));
}
return strtolower('ptdl-' . $name . '_' . str_random((11 - strlen($name))));
$uuid = is_null($uuid) ? str_random(8) : $uuid;
return strtolower(substr(preg_replace('/\s+/', '', $name), 0, 6) . '_' . $uuid);
}
@ -230,10 +228,11 @@ class ServerRepository
// Add Server to the Database
$server = new Models\Server;
$generatedUuid = $uuid->generate('servers', 'uuid');
$genUuid = $uuid->generate('servers', 'uuid');
$genShortUuid = $uuid->generateShort('servers', 'uuidShort', $generatedUuid);
$server->fill([
'uuid' => $generatedUuid,
'uuidShort' => $uuid->generateShort('servers', 'uuidShort', $generatedUuid),
'uuid' => $genUuid,
'uuidShort' => $genShortUuid,
'node' => $node->id,
'name' => $data['name'],
'suspended' => 0,
@ -250,7 +249,7 @@ class ServerRepository
'startup' => $data['startup'],
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
'username' => $this->generateSFTPUsername($data['name']),
'username' => $this->generateSFTPUsername($data['name'], $genShortUuid),
'sftp_password' => Crypt::encrypt('not set')
]);
$server->save();