From d77f812d11cac7a2a5e99594d45a06adfd74e8c0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 24 Feb 2022 23:16:21 -0800 Subject: [PATCH] dynamicdns: Fix adding null domain into configuration When old configuration is not set and is exported with new code into newer format, the result is a domain added with domain name 'null'. This causes issues with UI not showing configuration and with null domain being added into configurations of various daemons. Tests: - To reproduce the issue, switch to a revision with old dynamicdns code. Then switch to a latest version without the fix. A 'null' domain is added to configuration. - To reproduce the issue, switch to a revision with old dynamicdns code. Then switch to a latest version with the fix. A 'null' domain is not added to configuration. - With null domain in the configuration. Start FreedomBox with the fix. The null domain should be removed and null domain should not be announced to other daemons. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- actions/dynamicdns | 5 ++++- plinth/modules/dynamicdns/__init__.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/actions/dynamicdns b/actions/dynamicdns index 0e111b45b..3cbe07793 100755 --- a/actions/dynamicdns +++ b/actions/dynamicdns @@ -106,7 +106,10 @@ def subcommand_export_config(_): and _active_config.exists()): enabled = True - output_config = {'enabled': enabled, 'domains': {domain['domain']: domain}} + output_config = {'enabled': enabled, 'domains': {}} + if domain['domain']: + output_config['domains'][domain['domain']] = domain + print(json.dumps(output_config)) diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index 9fc18467c..170f21552 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -258,7 +258,18 @@ def get_config(): """Return the current configuration.""" default_config = {'domains': {}} config = kvstore.get_default('dynamicdns_config', '{}') - return json.loads(config) or default_config + config = json.loads(config) or default_config + return _fix_corrupt_config(config) + + +def _fix_corrupt_config(config): + """Fix malformed configuration result of bug in older version.""" + if 'null' not in config['domains']: + return config + + del config['domains']['null'] + set_config(config) + return config def set_config(config):