Ejemplo n.º 1
0
 def form_valid(self, form):
     """Mark the first wizard step as done, save value and redirect."""
     enabled = form.cleaned_data['backports_enabled']
     upgrades.set_backports_requested(enabled)
     upgrades.setup_repositories(None)
     first_boot.mark_step_done('backports_wizard')
     return super().form_valid(form)
Ejemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        """Skip if this first boot step if it is not relavent."""
        if not cfg.danube_edition:
            first_boot.mark_step_done('pagekite_firstboot')
            return HttpResponseRedirect(reverse(first_boot.next_step()))

        return super().get(request, *args, **kwargs)
Ejemplo n.º 3
0
    def get(self, request, *args, **kwargs):
        """Skip if this first boot step if it is not relavent."""
        if not cfg.danube_edition:
            first_boot.mark_step_done('pagekite_firstboot')
            return HttpResponseRedirect(reverse(first_boot.next_step()))

        return super().get(request, *args, **kwargs)
Ejemplo n.º 4
0
    def form_valid(self, form):
        """Mark the first wizard step as done, save value and redirect."""
        first_boot.mark_step_done('router_setup_wizard')
        if 'skip' in form.data:
            return FormView.form_valid(self, form)

        return super().form_valid(form)
Ejemplo n.º 5
0
    def form_valid(self, form):
        """Mark the first wizard step as done, save value and redirect."""
        first_boot.mark_step_done('internet_connectivity_type_wizard')
        if 'skip' in form.data:
            return FormView.form_valid(self, form)

        return super().form_valid(form)
Ejemplo n.º 6
0
    def dispatch(self, request, *args, **kwargs):
        """Check if there is no possibility to create a new admin account."""
        if request.method == 'POST' and 'skip' in request.POST:
            first_boot.mark_step_done('users_firstboot')
            return HttpResponseRedirect(reverse(first_boot.next_step()))

        return super().dispatch(request, *args, **kwargs)
Ejemplo n.º 7
0
    def form_valid(self, form):
        """Run update if selected, and mark step as done."""
        self.update = form.cleaned_data['update_now']
        if self.update:
            actions.superuser_run('upgrades', ['run'])

        first_boot.mark_step_done('initial_update')
        return super().form_valid(form)
Ejemplo n.º 8
0
    def dispatch(self, request, *args, **kwargs):
        """Don't show wizard step if FreedomBox is not behind a router."""
        network_topology = networks.get_network_topology_type()
        if network_topology != 'to_router':
            first_boot.mark_step_done('router_setup_wizard')
            return HttpResponseRedirect(reverse_lazy(first_boot.next_step()))

        return super().dispatch(request, *args, *kwargs)
Ejemplo n.º 9
0
    def dispatch(self, request, *args, **kwargs):
        """Don't show wizard step if FreedomBox is not behind a router."""
        network_topology = kvstore.get_default(
            networks.NETWORK_TOPOLOGY_TYPE_KEY, 'to_router')
        if network_topology != 'to_router':
            first_boot.mark_step_done('router_setup_wizard')
            return HttpResponseRedirect(reverse_lazy(first_boot.next_step()))

        return super().dispatch(request, *args, *kwargs)
Ejemplo n.º 10
0
    def form_valid(self, form):
        """Act on valid form submission."""
        try:
            form.register_domain()
        except DomainRegistrationError as error:
            messages.error(self.request, error)
            return self.form_invalid(form)

        form.setup_pagekite()
        first_boot.mark_step_done('pagekite_firstboot')
        message = _('Pagekite setup finished. The HTTP and HTTPS services '
                    'are activated now.')
        messages.success(self.request, message)
        return HttpResponseRedirect(reverse(first_boot.next_step()))
Ejemplo n.º 11
0
    def form_valid(self, form):
        """Act on valid form submission."""
        try:
            form.register_domain()
        except DomainRegistrationError as error:
            messages.error(self.request, error)
            return self.form_invalid(form)

        form.setup_pagekite()
        first_boot.mark_step_done('pagekite_firstboot')
        message = _('Pagekite setup finished. The HTTP and HTTPS services '
                    'are activated now.')
        messages.success(self.request, message)
        return HttpResponseRedirect(reverse(first_boot.next_step()))
Ejemplo n.º 12
0
    def save(self, commit=True):
        """Create and log the user in."""
        user = super().save(commit=commit)
        if commit:
            first_boot.mark_step_done('users_firstboot')

            try:
                actions.superuser_run(
                    'users',
                    ['create-user',
                     user.get_username(), '--auth-user', ''],
                    input=self.cleaned_data['password1'].encode())
            except ActionError as error:
                messages.error(
                    self.request,
                    _('Creating LDAP user failed: {error}'.format(
                        error=error)))

            try:
                actions.superuser_run(
                    'users',
                    ['add-user-to-group',
                     user.get_username(), 'admin'])
            except ActionError as error:
                messages.error(
                    self.request,
                    _('Failed to add new user to admin group: {error}'.format(
                        error=error)))

            # Create initial Django groups
            for group_choice in UsersAndGroups.get_group_choices():
                auth.models.Group.objects.get_or_create(name=group_choice[0])

            admin_group = auth.models.Group.objects.get(name='admin')
            admin_group.user_set.add(user)

            self.login_user(self.cleaned_data['username'],
                            self.cleaned_data['password1'])

            # Restrict console login to users in admin or sudo group
            try:
                set_restricted_access(True)
            except Exception as error:
                messages.error(
                    self.request,
                    _('Failed to restrict console access: {error}'.format(
                        error=error)))

        return user
Ejemplo n.º 13
0
    def dispatch(self, request, *args, **kwargs):
        """Show backports configuration form only if it can be activated."""
        if upgrades.is_backports_enabled():
            # Backports is already enabled. Record this preference and
            # skip first boot step.
            upgrades.set_backports_requested(True)
            first_boot.mark_step_done('backports_wizard')
            return HttpResponseRedirect(reverse_lazy(first_boot.next_step()))

        if not upgrades.can_activate_backports():
            # Skip first boot step.
            upgrades.set_backports_requested(False)
            first_boot.mark_step_done('backports_wizard')
            return HttpResponseRedirect(reverse_lazy(first_boot.next_step()))

        return super().dispatch(request, *args, *kwargs)
Ejemplo n.º 14
0
    def save(self, commit=True):
        """Create and log the user in."""
        user = super().save(commit=commit)
        if commit:
            first_boot.mark_step_done('users_firstboot')

            try:
                actions.superuser_run(
                    'ldap',
                    ['create-user', user.get_username()],
                    input=self.cleaned_data['password1'].encode())
            except ActionError:
                messages.error(self.request,
                               _('Creating LDAP user failed.'))

            try:
                actions.superuser_run(
                    'ldap',
                    ['add-user-to-group', user.get_username(), 'admin'])
            except ActionError:
                messages.error(self.request,
                               _('Failed to add new user to admin group.'))

            # Create initial Django groups
            for group_choice in GROUP_CHOICES:
                auth.models.Group.objects.get_or_create(name=group_choice[0])

            admin_group = auth.models.Group.objects.get(name='admin')
            admin_group.user_set.add(user)

            self.login_user(self.cleaned_data['username'],
                            self.cleaned_data['password1'])

            # Restrict console login to users in admin or sudo group
            try:
                set_restricted_access(True)
                message = _('Console login access restricted to users in '
                            '"admin" group. This can be configured in '
                            'security settings.')
                messages.success(self.request, message)
            except Exception:
                messages.error(self.request,
                               _('Failed to restrict console access.'))

        return user
Ejemplo n.º 15
0
    def save(self, commit=True):
        """Create and log the user in."""
        user = super().save(commit=commit)
        if commit:
            first_boot.mark_step_done('users_firstboot')

            try:
                actions.superuser_run(
                    'ldap', ['create-user', user.get_username()],
                    input=self.cleaned_data['password1'].encode())
            except ActionError:
                messages.error(self.request, _('Creating LDAP user failed.'))

            try:
                actions.superuser_run(
                    'ldap',
                    ['add-user-to-group',
                     user.get_username(), 'admin'])
            except ActionError:
                messages.error(self.request,
                               _('Failed to add new user to admin group.'))

            # Create initial Django groups
            for group_choice in GROUP_CHOICES:
                auth.models.Group.objects.get_or_create(name=group_choice[0])

            admin_group = auth.models.Group.objects.get(name='admin')
            admin_group.user_set.add(user)

            self.login_user(self.cleaned_data['username'],
                            self.cleaned_data['password1'])

            # Restrict console login to users in admin or sudo group
            try:
                set_restricted_access(True)
                message = _('Console login access restricted to users in '
                            '"admin" group. This can be configured in '
                            'security settings.')
                messages.success(self.request, message)
            except Exception:
                messages.error(self.request,
                               _('Failed to restrict console access.'))

        return user
Ejemplo n.º 16
0
def first_boot_skip(request):
    """Skip the first boot step."""
    first_boot.mark_step_done('pagekite_firstboot')
    return HttpResponseRedirect(reverse(first_boot.next_step()))
Ejemplo n.º 17
0
 def post(self, request, *args, **kwargs):
     """On POST, mark this step as done and move to next step."""
     first_boot.mark_step_done('firstboot_welcome')
     return http.HttpResponseRedirect(reverse(first_boot.next_step()))
Ejemplo n.º 18
0
 def get(self, request, *args, **kwargs):
     """Mark as done as soon as page is served."""
     response = super().get(self, request, *args, **kwargs)
     first_boot.mark_step_done('firstboot_complete')
     return response
Ejemplo n.º 19
0
 def form_valid(self, form):
     """If form is valid, mark this step as done and move to next step."""
     first_boot.mark_step_done('firstboot_welcome')
     return http.HttpResponseRedirect(reverse(first_boot.next_step()))
Ejemplo n.º 20
0
 def form_valid(self, form):
     """If form is valid, mark this step as done and move to next step."""
     self.request.session['firstboot_secret_provided'] = True
     first_boot.mark_step_done('firstboot_welcome')
     return http.HttpResponseRedirect(reverse(first_boot.next_step()))
Ejemplo n.º 21
0
def first_boot_skip(request):
    """Skip the first boot step."""
    first_boot.mark_step_done('pagekite_firstboot')
    return HttpResponseRedirect(reverse(first_boot.next_step()))
Ejemplo n.º 22
0
 def get_redirect_url(self, *args, **kwargs):
     actions.superuser_run('auth-pubtkt', ['create-key-pair'])
     first_boot.mark_step_done('sso_firstboot')
     return reverse(first_boot.next_step())
Ejemplo n.º 23
0
 def get(self, request, *args, **kwargs):
     """Mark as done as soon as page is served."""
     response = super().get(self, request, *args, **kwargs)
     first_boot.mark_step_done('firstboot_complete')
     return response