openvpn: Remove explicit setup step

Setup is now run as a post installation step.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati 2020-10-31 14:42:01 +05:30 committed by James Valleroy
parent 2b33a752d0
commit 721d51bd4a
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
5 changed files with 9 additions and 96 deletions

View File

@ -36,8 +36,6 @@ _description = [
app = None
setup_process = None
SERVER_CONFIGURATION_FILE = '/etc/openvpn/server/freedombox.conf'
@ -49,7 +47,7 @@ class OpenVPNApp(app_module.App):
@property
def can_be_disabled(self):
"""Return whether the app can be disabled."""
return is_setup() and not setup_process
return is_setup()
def __init__(self):
"""Create components for the app."""
@ -97,8 +95,8 @@ class OpenVPNApp(app_module.App):
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
if app.is_enabled() and is_setup():
helper.call('post', app.enable)
helper.call('post', actions.superuser_run, 'openvpn', ['setup'])
helper.call('post', app.enable)
def is_setup():

View File

@ -9,54 +9,15 @@
{% block status %}
{% if status.is_setup and not status.setup_running %}
{% if status.is_setup %}
{{ block.super }}
{% endif %}
{% if not status.is_setup and not status.setup_running %}
<h3>{% trans "Status" %}</h3>
<p>
{% blocktrans trimmed %}
OpenVPN has not yet been setup. Performing a secure setup
takes a very long time. Depending on how fast your
{{ box_name }} is, it may even take hours. If the setup
is interrupted, you may start it again.
{% endblocktrans %}
</p>
<form class="form form-setup" method="post"
action="{% url 'openvpn:setup' %}">
{% csrf_token %}
<input type="submit" class="btn btn-primary"
value="{% trans "Start setup" %}"/>
</form>
{% endif %}
{% if status.setup_running %}
<h3>{% trans "Status" %}</h3>
<p class="running-status-parent">
<span class='running-status loading'></span>
{% trans "OpenVPN setup is running" %}
</p>
<p>
{% blocktrans trimmed %}
To perform a secure setup, this process takes a very long
time. Depending on how fast your {{ box_name }} is, it may
even take hours. If the setup is interrupted, you may start
it again.
{% endblocktrans %}
</p>
{% endif %}
{% endblock %}
{% block configuration %}
{% if status.is_setup and not status.setup_running %}
{% if status.is_setup %}
<h3>{% trans "Profile" %}</h3>

View File

@ -7,7 +7,6 @@ Feature: OpenVPN - Virtual Private Network
Background:
Given I'm a logged in user
Given the openvpn application is installed
Given the openvpn application is setup
Scenario: Enable openvpn application
Given the openvpn application is disabled

View File

@ -3,25 +3,13 @@
Functional, browser based tests for openvpn app.
"""
from pytest_bdd import given, parsers, scenarios, then
from pytest_bdd import given, scenarios, then
from plinth.tests import functional
scenarios('openvpn.feature')
@given(parsers.parse('the openvpn application is setup'))
def openvpn_setup(session_browser):
"""Setup the OpenVPN application after installation."""
functional.nav_to_module(session_browser, 'openvpn')
setup_form = session_browser.find_by_css('.form-setup')
if not setup_form:
return
functional.submit(session_browser, form_class='form-setup')
functional.wait_for_config_update(session_browser, 'openvpn')
@given('I download openvpn profile')
def openvpn_download_profile(session_browser):
return _download_profile(session_browser)

View File

@ -5,10 +5,8 @@ FreedomBox app for configuring OpenVPN server.
import logging
from django.contrib import messages
from django.http import HttpResponse
from django.shortcuts import redirect
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST
from plinth import actions
@ -23,22 +21,12 @@ class OpenVPNAppView(AppView):
app_id = 'openvpn'
template_name = 'openvpn.html'
def dispatch(self, request, *args, **kwargs):
"""Collect the result of running setup process."""
if bool(openvpn.setup_process):
_collect_setup_result(request)
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, *args, **kwargs):
"""Add additional context data for template."""
context = super().get_context_data(*args, **kwargs)
context['status'] = {
'is_setup': openvpn.is_setup(),
'setup_running': bool(openvpn.setup_process),
}
context['refresh_page_sec'] = 3 if context['status'][
'setup_running'] else None
context['using_ecc'] = openvpn.is_using_ecc()
return context
@ -46,9 +34,8 @@ class OpenVPNAppView(AppView):
@require_POST
def setup(_):
"""Start the setup process."""
if not openvpn.is_setup() and not openvpn.setup_process:
openvpn.setup_process = actions.superuser_run('openvpn', ['setup'],
run_in_background=True)
if not openvpn.is_setup():
actions.superuser_run('openvpn', ['setup'], run_in_background=True)
openvpn.app.enable()
@ -78,25 +65,5 @@ def profile(request):
def ecc(_):
"""Migrate from RSA to ECC."""
if openvpn.is_setup():
openvpn.setup_process = actions.superuser_run('openvpn', ['setup'],
run_in_background=True)
actions.superuser_run('openvpn', ['setup'], run_in_background=True)
return redirect('openvpn:index')
def _collect_setup_result(request):
"""Handle setup process is completion."""
if not openvpn.setup_process:
return
return_code = openvpn.setup_process.poll()
# Setup process is not complete yet
if return_code is None:
return
if not return_code:
messages.success(request, _('Setup completed.'))
else:
messages.info(request, _('Setup failed.'))
openvpn.setup_process = None