diff --git a/LICENSES b/LICENSES index 938375ef6..27a77fc8b 100644 --- a/LICENSES +++ b/LICENSES @@ -57,3 +57,4 @@ otherwise. - static/themes/default/icons/transmission.png :: [[https://transmissionbt.com/][GPL]] - static/themes/default/icons/ttrss.png :: [[https://tt-rss.org/gitlab/fox/tt-rss][GPL]] - static/themes/default/icons/xmpp.png :: [[https://www.ejabberd.im/][GPL3]] +- static/themes/default/icons/openvpn.png :: [[https://github.com/thekishanraval/Logos][GPLv3]] diff --git a/plinth/modules/openvpn/__init__.py b/plinth/modules/openvpn/__init__.py index 137e2820e..3909a3c46 100644 --- a/plinth/modules/openvpn/__init__.py +++ b/plinth/modules/openvpn/__init__.py @@ -18,12 +18,13 @@ """ Plinth module to configure OpenVPN server. """ - +from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ from plinth import actions from plinth import action_utils from plinth import cfg +from plinth import frontpage from plinth import service as service_module from plinth.utils import format_lazy @@ -53,7 +54,8 @@ description = [ def init(): - """Intialize the OpenVPN module.""" + """Initialize the OpenVPN module.""" + menu = cfg.main_menu.get('apps:index') menu.add_urlname(title, 'glyphicon-lock', 'openvpn:index') @@ -63,14 +65,34 @@ def init(): service = service_module.Service( managed_services[0], title, ports=['openvpn'], is_external=True) + print(is_setup()) + if is_enabled() and is_setup(): + add_shortcut() + + +def is_enabled(): + return action_utils.service_is_enabled('openvpn') + def setup(helper, old_version=None): """Install and configure the module.""" + helper.install(managed_packages) global service if service is None: service = service_module.Service( managed_services[0], title, ports=['openvpn'], is_external=True) + add_shortcut() + + +def add_shortcut(): + frontpage.add_shortcut('openvpn', title, + details=description + [ + 'Download Profile' + ], + configure_url=reverse_lazy('openvpn:index'), + login_required=True) def is_setup(): @@ -80,8 +102,4 @@ def is_setup(): def diagnose(): """Run diagnostics and return the results.""" - results = [] - - results.append(action_utils.diagnose_port_listening(1194, 'udp4')) - - return results + return [action_utils.diagnose_port_listening(1194, 'udp4')] diff --git a/plinth/modules/openvpn/urls.py b/plinth/modules/openvpn/urls.py index e8808b883..2ecd82851 100644 --- a/plinth/modules/openvpn/urls.py +++ b/plinth/modules/openvpn/urls.py @@ -21,11 +21,12 @@ URLs for the OpenVPN module. from django.conf.urls import url +from plinth.utils import non_admin_view from . import views urlpatterns = [ url(r'^apps/openvpn/$', views.index, name='index'), url(r'^apps/openvpn/setup/$', views.setup, name='setup'), - url(r'^apps/openvpn/profile/$', views.profile, name='profile'), + url(r'^apps/openvpn/profile/$', non_admin_view(views.profile), name='profile'), ] diff --git a/plinth/modules/openvpn/views.py b/plinth/modules/openvpn/views.py index 38119e992..ca4e87674 100644 --- a/plinth/modules/openvpn/views.py +++ b/plinth/modules/openvpn/views.py @@ -75,7 +75,6 @@ def setup(request): return redirect('openvpn:index') -@require_POST def profile(request): """Provide the user's profile for download.""" username = request.user.username @@ -97,14 +96,13 @@ def profile(request): def get_status(): """Get the current settings from OpenVPN server.""" - status = {'is_setup': openvpn.is_setup(), - 'setup_running': False, - 'enabled': openvpn.service.is_enabled(), - 'is_running': openvpn.service.is_running()} - status['setup_running'] = bool(setup_process) - - return status + return { + 'is_setup': openvpn.is_setup(), + 'setup_running': bool(setup_process), + 'enabled': openvpn.service.is_enabled(), + 'is_running': openvpn.service.is_running() + } def _collect_setup_result(request): diff --git a/static/themes/default/icons/openvpn.png b/static/themes/default/icons/openvpn.png new file mode 100644 index 000000000..fb5e9ba4c Binary files /dev/null and b/static/themes/default/icons/openvpn.png differ