Add services information to the domains configured in dynamicdns

Signed-off-by: Hemanth Kumar Veeranki <hemanthveeranki@gmail.com>
This commit is contained in:
Hemanth Kumar Veeranki 2017-07-31 21:51:41 +05:30 committed by James Valleroy
parent 72208f440d
commit 217ef97a6f
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 21 additions and 2 deletions

View File

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

View File

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