Sunil Mohan Adapa 900c0d30b9
*: Drop module level app property
module.app property usage is greatly reduced because setup() and force_upgrade()
method are now part of App class instead of at the module level. Remove the
remaining minor cases of usage and drop the property altogether.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:29 -04:00

71 lines
1.9 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for configuring OpenVPN server.
"""
import logging
from django.http import HttpResponse
from django.shortcuts import redirect
from django.views.decorators.http import require_POST
from plinth import actions
from plinth import app as app_module
from plinth.modules import config, openvpn
from plinth.views import AppView
logger = logging.getLogger(__name__)
class OpenVPNAppView(AppView):
"""Show OpenVPN app main page."""
app_id = 'openvpn'
template_name = 'openvpn.html'
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(),
}
context['using_ecc'] = openvpn.is_using_ecc()
return context
@require_POST
def setup(_):
"""Start the setup process."""
if not openvpn.is_setup():
actions.superuser_run('openvpn', ['setup'], run_in_background=True)
app_module.App.get('openvpn').enable()
return redirect('openvpn:index')
def profile(request):
"""Provide the user's profile for download."""
username = request.user.username
domainname = config.get_domainname()
if not config.get_domainname():
domainname = config.get_hostname()
profile_string = actions.superuser_run(
'openvpn', ['get-profile', username, domainname])
response = HttpResponse(profile_string,
content_type='application/x-openvpn-profile')
response['Content-Disposition'] = \
'attachment; filename={username}.ovpn'.format(username=username)
return response
@require_POST
def ecc(_):
"""Migrate from RSA to ECC."""
if openvpn.is_setup():
actions.superuser_run('openvpn', ['setup'], run_in_background=True)
return redirect('openvpn:index')