From 05908d16808c8f20178644ae3355a817c1c8eb19 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 15 Feb 2017 18:29:48 +0530 Subject: [PATCH] openvpn: Handle shortcut properly when enabling/disabling --- plinth/modules/openvpn/__init__.py | 19 +++++++++++++++---- plinth/modules/openvpn/views.py | 7 +++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plinth/modules/openvpn/__init__.py b/plinth/modules/openvpn/__init__.py index b1c772c9e..bf25713d2 100644 --- a/plinth/modules/openvpn/__init__.py +++ b/plinth/modules/openvpn/__init__.py @@ -19,7 +19,7 @@ Plinth module to configure OpenVPN server. """ -from django.urls import resolve, reverse_lazy +from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ from plinth import actions @@ -76,9 +76,8 @@ def setup(helper, old_version=None): global service if service is None: service = service_module.Service( - managed_services[0], title, ports=['openvpn'], is_external=True) - - helper.call('post', add_shortcut) + managed_services[0], title, ports=['openvpn'], is_external=True, + enable=enable, disable=disable) def add_shortcut(): @@ -98,6 +97,18 @@ def is_setup(): return actions.superuser_run('openvpn', ['is-setup']).strip() == 'true' +def enable(): + """Enable the module.""" + actions.superuser_run('service', ['enable', managed_services[0]]) + add_shortcut() + + +def disable(): + """Enable the module.""" + actions.superuser_run('service', ['disable', managed_services[0]]) + frontpage.remove_shortcut('openvpn') + + def diagnose(): """Run diagnostics and return the results.""" return [action_utils.diagnose_port_listening(1194, 'udp4')] diff --git a/plinth/modules/openvpn/views.py b/plinth/modules/openvpn/views.py index ca4e87674..b3519c65b 100644 --- a/plinth/modules/openvpn/views.py +++ b/plinth/modules/openvpn/views.py @@ -72,6 +72,8 @@ def setup(request): if not openvpn.is_setup() and not setup_process: setup_process = actions.superuser_run('openvpn', ['setup'], async=True) + openvpn.add_shortcut() + return redirect('openvpn:index') @@ -131,9 +133,10 @@ def _apply_changes(request, old_status, new_status): if old_status['enabled'] != new_status['enabled']: if new_status['enabled']: - openvpn.service.enable() + openvpn.enable() else: - openvpn.service.disable() + openvpn.disable() + modified = True if modified: