Fixed longer domain names for local add of existing domains
This commit is contained in:
parent
6beea36361
commit
099499f4c6
18
ddns.py
18
ddns.py
@ -19,7 +19,7 @@ filepath = homefilepath.joinpath('.config/ddns')
|
|||||||
database = filepath.joinpath('ddns.db')
|
database = filepath.joinpath('ddns.db')
|
||||||
logfile = filepath.joinpath('ddns.log')
|
logfile = filepath.joinpath('ddns.log')
|
||||||
logging.basicConfig(filename=logfile,level=logging.INFO,format='%(message)s')
|
logging.basicConfig(filename=logfile,level=logging.INFO,format='%(message)s')
|
||||||
app_version = '0.5.1'
|
app_version = '0.5.2'
|
||||||
|
|
||||||
|
|
||||||
def get_ip():
|
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]')
|
print('[red]Error:[/red]. Give the domain name in simple form e.g. [bold]test.domain.com[/bold]')
|
||||||
else:
|
else:
|
||||||
parts = domain.split('.')
|
parts = domain.split('.')
|
||||||
topdomain = parts[1]+'.'+parts[2]
|
if len(parts) > 3:
|
||||||
cursor.execute('SELECT id FROM domains WHERE name like ?', (topdomain,))
|
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]
|
domainid = cursor.fetchone()[0]
|
||||||
cursor.execute('SELECT * FROM subdomains WHERE main_id like ?', (domainid,))
|
cursor.execute('SELECT * FROM subdomains WHERE main_id like ?', (domainid,))
|
||||||
domains = cursor.fetchall()
|
domains = cursor.fetchall()
|
||||||
@ -486,12 +491,15 @@ def local_add_subdomain(domain,domainid):
|
|||||||
else:
|
else:
|
||||||
parts = domain.split('.')
|
parts = domain.split('.')
|
||||||
if len(parts) > 3:
|
if len(parts) > 3:
|
||||||
|
# longtop = parts[2] + '.' + parts[2] + '.' + parts[3]
|
||||||
top = parts[1] + '.' + parts[2] + '.' + parts[3]
|
top = parts[1] + '.' + parts[2] + '.' + parts[3]
|
||||||
sub = parts[0]
|
sub = parts[0]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sub = parts[0]
|
sub = parts[0]
|
||||||
top = parts[1] + '.' + parts[2]
|
top = parts[1] + '.' + parts[2]
|
||||||
apikey = get_api()
|
apikey = get_api()
|
||||||
|
longtop=sub+'.'+top
|
||||||
if apikey == None:
|
if apikey == None:
|
||||||
print("[red]Error:[/red] Missing APIkey. Please add one!")
|
print("[red]Error:[/red] Missing APIkey. Please add one!")
|
||||||
else:
|
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))
|
print('[red]Error:[/red] Failed to get public IP. Do you have a typo in your URI? [red]Error %s.[/red]' % (ip))
|
||||||
else:
|
else:
|
||||||
cursor = conn.cursor()
|
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]
|
count = cursor.fetchone()[0]
|
||||||
if count == 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))
|
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:
|
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 = cursor.fetchone()
|
||||||
topdomain_id = topdomain_id[0]
|
topdomain_id = topdomain_id[0]
|
||||||
cursor.execute('SELECT count(*) FROM subdomains WHERE main_id LIKE ? AND name like ?',(topdomain_id,sub,))
|
cursor.execute('SELECT count(*) FROM subdomains WHERE main_id LIKE ? AND name like ?',(topdomain_id,sub,))
|
||||||
|
Loading…
Reference in New Issue
Block a user