From 217ef97a6f6fbde75f3a82cb512896efaffa87e6 Mon Sep 17 00:00:00 2001 From: Hemanth Kumar Veeranki Date: Mon, 31 Jul 2017 21:51:41 +0530 Subject: [PATCH] Add services information to the domains configured in dynamicdns Signed-off-by: Hemanth Kumar Veeranki --- plinth/modules/dynamicdns/__init__.py | 4 +++- plinth/modules/dynamicdns/dynamicdns.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index e27236612..b88af3a3a 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -60,10 +60,12 @@ def init(): menu.add_urlname(title, 'glyphicon-refresh', 'dynamicdns:index') current_status = dynamicdns.get_status() if current_status['enabled']: + services = dynamicdns.get_enabled_services(current_status['dynamicdns_domain']) domain_added.send_robust( sender='dynamicdns', domain_type='dynamicdnsservice', name=current_status['dynamicdns_domain'], - description=_('Dynamic DNS Service')) + description=_('Dynamic DNS Service'), + services=services) def setup(helper, old_version=None): diff --git a/plinth/modules/dynamicdns/dynamicdns.py b/plinth/modules/dynamicdns/dynamicdns.py index 3825e21b5..4585d6abc 100644 --- a/plinth/modules/dynamicdns/dynamicdns.py +++ b/plinth/modules/dynamicdns/dynamicdns.py @@ -31,6 +31,8 @@ from django.template.response import TemplateResponse from plinth import actions from plinth import cfg from plinth.modules import dynamicdns +from plinth.modules import firewall +from plinth.modules.names import SERVICES from plinth.signals import domain_added, domain_removed from plinth.utils import format_lazy @@ -368,10 +370,12 @@ def _apply_changes(request, old_status, new_status): _run(['stop']) if new_status['enabled']: + services = get_enabled_services(new_status['dynamicdns_domain']) domain_added.send_robust( sender='dynamicdns', domain_type='dynamicdnsservice', name=new_status['dynamicdns_domain'], - description=_('Dynamic DNS Service')) + description=_('Dynamic DNS Service'), + services=services) _run(['start']) messages.success(request, _('Configuration updated')) @@ -382,3 +386,16 @@ def _apply_changes(request, old_status, new_status): def _run(arguments, input=None): """Run a given command and raise exception if there was an error.""" return actions.superuser_run('dynamicdns', arguments, input=input) + + +def get_enabled_services(domain_name): + """ Get enabled services for the domain name""" + if domain_name != None and domain_name != '': + try: + domainname_services = firewall.get_enabled_services( + zone='external') + except actions.ActionError: + domainname_services = [service[0] for service in SERVICES] + else: + domainname_services = None + return domainname_services