From 890dfea5ab1c85ea3f12ae26406235ea12d49539 Mon Sep 17 00:00:00 2001 From: rune Date: Mon, 17 Apr 2023 10:55:01 +0200 Subject: [PATCH] Quick fix --- ddns.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ddns.py b/ddns.py index 2aabcc6..cbe2bf0 100755 --- a/ddns.py +++ b/ddns.py @@ -185,14 +185,14 @@ def remove_subdomain(domain): else: sub = parts[0] top = parts[1] + '.' + parts[2] - + longtop=sub+'.'+top cursor = conn.cursor() - cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ?',(top,)) + cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ? or name like ?',(top,longtop,)) count = cursor.fetchone()[0] if count == 0: print('[red]Error:[/red] Top domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (top)) else: - cursor.execute('SELECT COUNT(*) FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name=?)',(sub,top,)) + cursor.execute('SELECT COUNT(*) FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name like ? or name like ?)',(sub,top,longtop,)) count = cursor.fetchone()[0] if count == 0: print('[red]Error:[/red] Domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (domain)) @@ -201,7 +201,7 @@ def remove_subdomain(domain): if apikey == None: print("[red]Error:[/red] Missing APIkey. Please add one!") else: - cursor.execute('SELECT id FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name=?)',(sub,top,)) + cursor.execute('SELECT id FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name like ? or name like ?)',(sub,top,longtop,)) subdomain_id = str(cursor.fetchone()[0]) headers = {'Authorization': 'Bearer ' + apikey, "Content-Type": "application/json"} response = requests.delete('https://api.digitalocean.com/v2/domains/'+top+'/records/' + subdomain_id, headers=headers) @@ -225,13 +225,14 @@ def edit_subdomain(domain): else: sub = parts[0] top = parts[1] + '.' + parts[2] + longtop=sub+'.'+top cursor = conn.cursor() - cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ?',(top,)) + cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ? or name like ?',(top,longtop,)) count = cursor.fetchone()[0] if count == 0: print('[red]Error:[/red] Top domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (top)) else: - cursor.execute('SELECT COUNT(*) FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name=?)',(sub,top,)) + cursor.execute('SELECT COUNT(*) FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name like ? or name like)',(sub,top,longtop)) count = cursor.fetchone()[0] if count == 0: print('[red]Error:[/red] Domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (domain)) @@ -240,7 +241,7 @@ def edit_subdomain(domain): if apikey == None: print("[red]Error:[/red] Missing APIkey. Please add one!") else: - cursor.execute('SELECT id,active FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name=?)',(sub,top,)) + cursor.execute('SELECT id,active FROM subdomains WHERE name like ? and main_id=(SELECT id from domains WHERE name like ? or name like ?)',(sub,top,longtop)) domain_info = cursor.fetchone() subdomain_id = str(domain_info[0]) status = domain_info[1] @@ -491,7 +492,6 @@ def local_add_subdomain(domain,domainid): else: parts = domain.split('.') if len(parts) > 3: - # longtop = parts[2] + '.' + parts[2] + '.' + parts[3] top = parts[1] + '.' + parts[2] + '.' + parts[3] sub = parts[0]