Fixed an error when adding sub domains already in DO DNS

This commit is contained in:
rune 2023-03-29 09:08:08 +02:00
parent 5ccb9b90d4
commit 678c32b2ea

13
ddns.py
View File

@ -315,7 +315,9 @@ def show_current_info():
ipserver = '[red]Error:[/red] No IP resolvers in DB' ipserver = '[red]Error:[/red] No IP resolvers in DB'
else: else:
cursor.execute('SELECT * FROM ipservers') cursor.execute('SELECT * FROM ipservers')
ipserver = cursor.fetchall()[0][1] ipservers = cursor.fetchall()
ip4server = ipservers[0][1]
ip6server = ipservers[0][2]
if API == None: if API == None:
API = '[red]Error:[/red] API key not stored in DB' API = '[red]Error:[/red] API key not stored in DB'
@ -329,8 +331,8 @@ def show_current_info():
print('\n[b]ddns[/b] - a DigitalOcean dynamic DNS solution.') print('\n[b]ddns[/b] - a DigitalOcean dynamic DNS solution.')
print('===================================================') print('===================================================')
print('API key : [b]%s[/b]' % (API)) print('API key : [b]%s[/b]' % (API))
print('IP v4 resolver : [b]%s[/b]' % (ipserver)) print('IP v4 resolver : [b]%s[/b]' % (ip4server))
print('IP v6 resolver : [b]N/A[/b]') print('IP v6 resolver : [b]%s[/b]' % (ip6server))
print('Logfile : [b]%s[/b]' % (logfile)) print('Logfile : [b]%s[/b]' % (logfile))
print('Top domains : [b]%s[/b]' % (topdomains)) print('Top domains : [b]%s[/b]' % (topdomains))
print('sub domains : [b]%s[/b]' % (subdomains)) print('sub domains : [b]%s[/b]' % (subdomains))
@ -375,7 +377,7 @@ def updateip(force):
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM subdomains') cursor.execute('SELECT COUNT(*) FROM subdomains')
count = cursor.fetchone()[0] count = cursor.fetchone()[0]
now = datetime.now().strftime("%Y-%m-%d %H:%M") now = datetime.now().strftime("%d-%m-%Y %H:%M")
updated = None updated = None
if count == 0: if count == 0:
print('[red]Error: [/red]There are no dynamic domains active.'\ print('[red]Error: [/red]There are no dynamic domains active.'\
@ -419,6 +421,7 @@ def updateip(force):
def local_add_subdomain(domain,domainid): def local_add_subdomain(domain,domainid):
now = datetime.now().strftime("%Y-%m-%d %H:%M")
if set(domain).difference(ascii_letters + '.' + digits + '-'): if set(domain).difference(ascii_letters + '.' + digits + '-'):
print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]') print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]')
else: else:
@ -447,7 +450,7 @@ def local_add_subdomain(domain,domainid):
if count != 0: if count != 0:
print('[red]Error:[/red] [bold]%s[/bold] already exists.' % (domain)) print('[red]Error:[/red] [bold]%s[/bold] already exists.' % (domain))
else: else:
cursor.execute('INSERT INTO subdomains values(?,?,?,?,?)',(domainid,topdomain_id,sub,ip,None,)) cursor.execute('INSERT INTO subdomains values(?,?,?,?,?,?,?,?)',(domainid,topdomain_id,sub,ip,None,now,now,now,))
conn.commit() conn.commit()
print('The domain %s has been added.' % (domain)) print('The domain %s has been added.' % (domain))