openvpn: Handle shortcut properly when enabling/disabling

This commit is contained in:
Sunil Mohan Adapa 2017-02-15 18:29:48 +05:30 committed by Sunil Mohan Adapa
parent 2a3381415e
commit 05908d1680
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 20 additions and 6 deletions

View File

@ -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')]

View File

@ -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: