vncserver: guide user to create a KasmVNC user

This commit is contained in:
Dmitry Maksyoma 2021-08-05 18:40:22 +12:00
parent fa342f624f
commit 93d2c6c716

View File

@ -97,9 +97,10 @@ $kasmAuthEnabled = 1;
$kasmPasswdFile = "$ENV{HOME}/.kasmpasswd"; $kasmPasswdFile = "$ENV{HOME}/.kasmpasswd";
@kasmPasswdUsers = &LoadKasmPasswdUsers(); @kasmPasswdUsers = &LoadKasmPasswdUsers();
if ($kasmAuthEnabled) { if ($kasmAuthEnabled && !&AtLeastOneUserConfigured()) {
&TellUserToSetupUserAndPassword(); &GuideUserToSetupKasmPasswdUser();
} }
@kasmPasswdUsers = &LoadKasmPasswdUsers();
$desktopLog = "$vncUserDir/$host:$displayNumber.log"; $desktopLog = "$vncUserDir/$host:$displayNumber.log";
unlink($desktopLog); unlink($desktopLog);
@ -854,6 +855,34 @@ sub TellUserToSetupUserAndPassword {
} }
} }
sub GuideUserToSetupKasmPasswdUser {
my $defaultUser = $ENV{USER};
print(<<"NEEDTOCREATEUSER");
In order to access your desktop, at least one KasmVNC user must be setup.
Let's create a user.
NEEDTOCREATEUSER
my $username = &Prompt("Enter username (default: $defaultUser): ");
$username ||= $defaultUser;
system($exedir."kasmvncpasswd -u \"$username\" -w $kasmPasswdFile");
if ($?) {
die("\nFailed to setup user \"$username\"\n");
}
print("Created user \"$username\"\n");
}
sub Prompt {
my $prompt = shift;
print($prompt);
my $userInput = <STDIN>;
$userInput =~ s/^\s+|\s+$//g;
return $userInput;
}
sub AtLeastOneUserConfigured { sub AtLeastOneUserConfigured {
scalar @kasmPasswdUsers > 0; scalar @kasmPasswdUsers > 0;
} }