mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
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:
parent
2b33a752d0
commit
721d51bd4a
@ -36,8 +36,6 @@ _description = [
|
|||||||
|
|
||||||
app = None
|
app = None
|
||||||
|
|
||||||
setup_process = None
|
|
||||||
|
|
||||||
SERVER_CONFIGURATION_FILE = '/etc/openvpn/server/freedombox.conf'
|
SERVER_CONFIGURATION_FILE = '/etc/openvpn/server/freedombox.conf'
|
||||||
|
|
||||||
|
|
||||||
@ -49,7 +47,7 @@ class OpenVPNApp(app_module.App):
|
|||||||
@property
|
@property
|
||||||
def can_be_disabled(self):
|
def can_be_disabled(self):
|
||||||
"""Return whether the app can be disabled."""
|
"""Return whether the app can be disabled."""
|
||||||
return is_setup() and not setup_process
|
return is_setup()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Create components for the app."""
|
"""Create components for the app."""
|
||||||
@ -97,8 +95,8 @@ class OpenVPNApp(app_module.App):
|
|||||||
def setup(helper, old_version=None):
|
def setup(helper, old_version=None):
|
||||||
"""Install and configure the module."""
|
"""Install and configure the module."""
|
||||||
helper.install(managed_packages)
|
helper.install(managed_packages)
|
||||||
if app.is_enabled() and is_setup():
|
helper.call('post', actions.superuser_run, 'openvpn', ['setup'])
|
||||||
helper.call('post', app.enable)
|
helper.call('post', app.enable)
|
||||||
|
|
||||||
|
|
||||||
def is_setup():
|
def is_setup():
|
||||||
|
|||||||
@ -9,54 +9,15 @@
|
|||||||
|
|
||||||
{% block status %}
|
{% block status %}
|
||||||
|
|
||||||
{% if status.is_setup and not status.setup_running %}
|
{% if status.is_setup %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
{% endif %}
|
{% 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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block configuration %}
|
{% block configuration %}
|
||||||
|
|
||||||
{% if status.is_setup and not status.setup_running %}
|
{% if status.is_setup %}
|
||||||
|
|
||||||
<h3>{% trans "Profile" %}</h3>
|
<h3>{% trans "Profile" %}</h3>
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ Feature: OpenVPN - Virtual Private Network
|
|||||||
Background:
|
Background:
|
||||||
Given I'm a logged in user
|
Given I'm a logged in user
|
||||||
Given the openvpn application is installed
|
Given the openvpn application is installed
|
||||||
Given the openvpn application is setup
|
|
||||||
|
|
||||||
Scenario: Enable openvpn application
|
Scenario: Enable openvpn application
|
||||||
Given the openvpn application is disabled
|
Given the openvpn application is disabled
|
||||||
|
|||||||
@ -3,25 +3,13 @@
|
|||||||
Functional, browser based tests for openvpn app.
|
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
|
from plinth.tests import functional
|
||||||
|
|
||||||
scenarios('openvpn.feature')
|
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')
|
@given('I download openvpn profile')
|
||||||
def openvpn_download_profile(session_browser):
|
def openvpn_download_profile(session_browser):
|
||||||
return _download_profile(session_browser)
|
return _download_profile(session_browser)
|
||||||
|
|||||||
@ -5,10 +5,8 @@ FreedomBox app for configuring OpenVPN server.
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.contrib import messages
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.utils.translation import ugettext as _
|
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
@ -23,22 +21,12 @@ class OpenVPNAppView(AppView):
|
|||||||
app_id = 'openvpn'
|
app_id = 'openvpn'
|
||||||
template_name = 'openvpn.html'
|
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):
|
def get_context_data(self, *args, **kwargs):
|
||||||
"""Add additional context data for template."""
|
"""Add additional context data for template."""
|
||||||
context = super().get_context_data(*args, **kwargs)
|
context = super().get_context_data(*args, **kwargs)
|
||||||
context['status'] = {
|
context['status'] = {
|
||||||
'is_setup': openvpn.is_setup(),
|
'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()
|
context['using_ecc'] = openvpn.is_using_ecc()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@ -46,9 +34,8 @@ class OpenVPNAppView(AppView):
|
|||||||
@require_POST
|
@require_POST
|
||||||
def setup(_):
|
def setup(_):
|
||||||
"""Start the setup process."""
|
"""Start the setup process."""
|
||||||
if not openvpn.is_setup() and not openvpn.setup_process:
|
if not openvpn.is_setup():
|
||||||
openvpn.setup_process = actions.superuser_run('openvpn', ['setup'],
|
actions.superuser_run('openvpn', ['setup'], run_in_background=True)
|
||||||
run_in_background=True)
|
|
||||||
|
|
||||||
openvpn.app.enable()
|
openvpn.app.enable()
|
||||||
|
|
||||||
@ -78,25 +65,5 @@ def profile(request):
|
|||||||
def ecc(_):
|
def ecc(_):
|
||||||
"""Migrate from RSA to ECC."""
|
"""Migrate from RSA to ECC."""
|
||||||
if openvpn.is_setup():
|
if openvpn.is_setup():
|
||||||
openvpn.setup_process = actions.superuser_run('openvpn', ['setup'],
|
actions.superuser_run('openvpn', ['setup'], run_in_background=True)
|
||||||
run_in_background=True)
|
|
||||||
return redirect('openvpn:index')
|
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
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user