diff --git a/ddns.py b/ddns.py index 291a5d9..2aabcc6 100755 --- a/ddns.py +++ b/ddns.py @@ -19,7 +19,7 @@ filepath = homefilepath.joinpath('.config/ddns') database = filepath.joinpath('ddns.db') logfile = filepath.joinpath('ddns.log') logging.basicConfig(filename=logfile,level=logging.INFO,format='%(message)s') -app_version = '0.5.1' +app_version = '0.5.2' def get_ip(): @@ -347,8 +347,13 @@ def domaininfo(domain): print('[red]Error:[/red]. Give the domain name in simple form e.g. [bold]test.domain.com[/bold]') else: parts = domain.split('.') - topdomain = parts[1]+'.'+parts[2] - cursor.execute('SELECT id FROM domains WHERE name like ?', (topdomain,)) + if len(parts) > 3: + top = parts[1] + '.' + parts[2] + '.' + parts[3] + sub = parts[0] + else: + sub = parts[0] + top = parts[1] + '.' + parts[2] + cursor.execute('SELECT id FROM domains WHERE name like ?', (top,)) domainid = cursor.fetchone()[0] cursor.execute('SELECT * FROM subdomains WHERE main_id like ?', (domainid,)) domains = cursor.fetchall() @@ -486,12 +491,15 @@ 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] + else: sub = parts[0] top = parts[1] + '.' + parts[2] apikey = get_api() + longtop=sub+'.'+top if apikey == None: print("[red]Error:[/red] Missing APIkey. Please add one!") else: @@ -500,12 +508,12 @@ def local_add_subdomain(domain,domainid): print('[red]Error:[/red] Failed to get public IP. Do you have a typo in your URI? [red]Error %s.[/red]' % (ip)) else: 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. Please add it with [i]ddns -t %s[/i].' % (top,top)) else: - cursor.execute('SELECT id FROM domains WHERE name LIKE ?',(top,)) + cursor.execute('SELECT id FROM domains WHERE name LIKE ? or name like ?',(top,longtop,)) topdomain_id = cursor.fetchone() topdomain_id = topdomain_id[0] cursor.execute('SELECT count(*) FROM subdomains WHERE main_id LIKE ? AND name like ?',(topdomain_id,sub,))