Change SFTP username to be name_uuidShort
This commit is contained in:
parent
20db3f9058
commit
a115c71433
1 changed files with 10 additions and 11 deletions
|
@ -51,19 +51,17 @@ class ServerRepository
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a SFTP username for a server given a server name.
|
* Generates a SFTP username for a server given a server name.
|
||||||
|
* format: mumble_67c7a4b0
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @param string $uuid
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function generateSFTPUsername($name)
|
protected function generateSFTPUsername($name, $uuid = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$name = preg_replace('/\s+/', '', $name);
|
$uuid = is_null($uuid) ? str_random(8) : $uuid;
|
||||||
if (strlen($name) > 6) {
|
return strtolower(substr(preg_replace('/\s+/', '', $name), 0, 6) . '_' . $uuid);
|
||||||
return strtolower('ptdl-' . substr($name, 0, 6) . '_' . str_random(5));
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtolower('ptdl-' . $name . '_' . str_random((11 - strlen($name))));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,10 +228,11 @@ class ServerRepository
|
||||||
|
|
||||||
// Add Server to the Database
|
// Add Server to the Database
|
||||||
$server = new Models\Server;
|
$server = new Models\Server;
|
||||||
$generatedUuid = $uuid->generate('servers', 'uuid');
|
$genUuid = $uuid->generate('servers', 'uuid');
|
||||||
|
$genShortUuid = $uuid->generateShort('servers', 'uuidShort', $generatedUuid);
|
||||||
$server->fill([
|
$server->fill([
|
||||||
'uuid' => $generatedUuid,
|
'uuid' => $genUuid,
|
||||||
'uuidShort' => $uuid->generateShort('servers', 'uuidShort', $generatedUuid),
|
'uuidShort' => $genShortUuid,
|
||||||
'node' => $node->id,
|
'node' => $node->id,
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
'suspended' => 0,
|
'suspended' => 0,
|
||||||
|
@ -250,7 +249,7 @@ class ServerRepository
|
||||||
'startup' => $data['startup'],
|
'startup' => $data['startup'],
|
||||||
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
|
'daemonSecret' => $uuid->generate('servers', 'daemonSecret'),
|
||||||
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image,
|
'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')
|
'sftp_password' => Crypt::encrypt('not set')
|
||||||
]);
|
]);
|
||||||
$server->save();
|
$server->save();
|
||||||
|
|
Loading…
Reference in a new issue