From 024211f0f3dd5d3b4064e051c1fda2c3e56d91fc Mon Sep 17 00:00:00 2001 From: rune Date: Sat, 15 Apr 2023 17:11:35 +0200 Subject: [PATCH] Fix issue #1 --- ddns.py | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/ddns.py b/ddns.py index cabb4b0..11d3e46 100755 --- a/ddns.py +++ b/ddns.py @@ -129,8 +129,12 @@ def add_subdomain(domain): print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]') else: parts = domain.split('.') - sub = parts[0] - top = parts[1] + '.' + parts[2] + if len(parts) > 3: + top = parts[1] + '.' + parts[2] + '.' + parts[3] + sub = parts[0] + else: + sub = parts[0] + top = parts[1] + '.' + parts[2] apikey = get_api() if apikey == None: print("[red]Error:[/red] Missing APIkey. Please add one!") @@ -145,9 +149,10 @@ def add_subdomain(domain): if count == 0: print('[red]Error:[/red] Top domain [bold]%s[/bold] does not exist in the DB. Please add it with [i]ddns -t %s[/i].' % (top,top)) else: - cursor.execute('SELECT id FROM domains WHERE name LIKE ?',(top,)) - topdomain_id = cursor.fetchone() - topdomain_id = topdomain_id[0] + cursor.execute('SELECT id,name FROM domains WHERE name LIKE ?',(top,)) + topdomain = cursor.fetchone() + topdomain_id = topdomain[0] + topdomain_name = topdomain[1] cursor.execute('SELECT count(*) FROM subdomains WHERE main_id LIKE ? AND name like ?',(topdomain_id,sub,)) count = cursor.fetchone()[0] if count != 0: @@ -174,8 +179,13 @@ def remove_subdomain(domain): print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]') else: parts = domain.split('.') - sub = parts[0] - top = parts[1] + '.' + parts[2] + if len(parts) > 3: + top = parts[1] + '.' + parts[2] + '.' + parts[3] + sub = parts[0] + else: + sub = parts[0] + top = parts[1] + '.' + parts[2] + cursor = conn.cursor() cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ?',(top,)) count = cursor.fetchone()[0] @@ -209,8 +219,12 @@ def edit_subdomain(domain): print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]') else: parts = domain.split('.') - sub = parts[0] - top = parts[1] + '.' + parts[2] + if len(parts) > 3: + top = parts[1] + '.' + parts[2] + '.' + parts[3] + sub = parts[0] + else: + sub = parts[0] + top = parts[1] + '.' + parts[2] cursor = conn.cursor() cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ?',(top,)) count = cursor.fetchone()[0] @@ -471,8 +485,12 @@ def local_add_subdomain(domain,domainid): print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]') else: parts = domain.split('.') - sub = parts[0] - top = parts[1] + '.' + parts[2] + if len(parts) > 3: + top = parts[1] + '.' + parts[2] + '.' + parts[3] + sub = parts[0] + else: + sub = parts[0] + top = parts[1] + '.' + parts[2] apikey = get_api() if apikey == None: print("[red]Error:[/red] Missing APIkey. Please add one!")