mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
users: Multiple SSH keys and better home creation
- Allow setting multiple SSH keys one per line (which is already allowed, but advertise it better). - Use mkhomedir_helper to create the user's home directory. Avoid security and accuracy complexities of creating a home directory. - Allow homes that don't exist in /home.
This commit is contained in:
3 files changed
+48
-53
No files matched your search
@@ -88,18 +88,20 @@ class CreateUserForm(UserCreationForm):
|
||||
|
||||
class UserUpdateForm(forms.ModelForm):
|
||||
"""When user info is changed, also updates LDAP user."""
|
||||
ssh_key = forms.CharField(
|
||||
label=ugettext_lazy('SSH Key'),
|
||||
ssh_keys = forms.CharField(
|
||||
label=ugettext_lazy('SSH Keys'),
|
||||
required=False,
|
||||
widget=forms.Textarea,
|
||||
help_text=\
|
||||
ugettext_lazy('Setting an SSH public key will allow this user to log '
|
||||
'in to the system without having to send a password '
|
||||
'over the network.'))
|
||||
ugettext_lazy('Setting an SSH public key will allow this user to '
|
||||
'securely log in to the system without using a '
|
||||
'password. You may enter multiple keys, one on each '
|
||||
'line. Blank lines and lines starting with # will be '
|
||||
'ignored.'))
|
||||
|
||||
class Meta:
|
||||
"""Metadata to control automatic form building."""
|
||||
fields = ('username', 'groups', 'ssh_key', 'is_active')
|
||||
fields = ('username', 'groups', 'ssh_keys', 'is_active')
|
||||
model = User
|
||||
widgets = {
|
||||
'groups': forms.widgets.CheckboxSelectMultiple(),
|
||||
@@ -157,9 +159,8 @@ class UserUpdateForm(forms.ModelForm):
|
||||
_('Failed to add user to group.'))
|
||||
|
||||
actions.superuser_run(
|
||||
'ssh', ['set-key',
|
||||
'--username', user.get_username(),
|
||||
'--key', self.cleaned_data['ssh_key'].strip()])
|
||||
'ssh', ['set-keys', '--username', user.get_username(),
|
||||
'--keys', self.cleaned_data['ssh_keys'].strip()])
|
||||
|
||||
return user
|
||||
|
||||
|
||||
@@ -86,9 +86,10 @@ class UserUpdate(ContextMixin, SuccessMessageMixin, UpdateView):
|
||||
return kwargs
|
||||
|
||||
def get_initial(self):
|
||||
"""Return the data for initial form load."""
|
||||
initial = super(UserUpdate, self).get_initial()
|
||||
initial['ssh_key'] = actions.superuser_run(
|
||||
'ssh', ['get-key', '--username', self.object.username]).strip()
|
||||
initial['ssh_keys'] = actions.superuser_run(
|
||||
'ssh', ['get-keys', '--username', self.object.username]).strip()
|
||||
return initial
|
||||
|
||||
def get_success_url(self):
|
||||
|
||||
Reference in new issue
Block a user