Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
40c4476081 | |||
890dfea5ab |
16
ddns.py
16
ddns.py
@ -185,14 +185,14 @@ def remove_subdomain(domain):
|
|||||||
else:
|
else:
|
||||||
sub = parts[0]
|
sub = parts[0]
|
||||||
top = parts[1] + '.' + parts[2]
|
top = parts[1] + '.' + parts[2]
|
||||||
|
longtop=sub+'.'+top
|
||||||
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. So I\'m giving up!.' % (top))
|
print('[red]Error:[/red] Top domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (top))
|
||||||
else:
|
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]
|
count = cursor.fetchone()[0]
|
||||||
if count == 0:
|
if count == 0:
|
||||||
print('[red]Error:[/red] Domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (domain))
|
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:
|
if apikey == None:
|
||||||
print("[red]Error:[/red] Missing APIkey. Please add one!")
|
print("[red]Error:[/red] Missing APIkey. Please add one!")
|
||||||
else:
|
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])
|
subdomain_id = str(cursor.fetchone()[0])
|
||||||
headers = {'Authorization': 'Bearer ' + apikey, "Content-Type": "application/json"}
|
headers = {'Authorization': 'Bearer ' + apikey, "Content-Type": "application/json"}
|
||||||
response = requests.delete('https://api.digitalocean.com/v2/domains/'+top+'/records/' + subdomain_id, headers=headers)
|
response = requests.delete('https://api.digitalocean.com/v2/domains/'+top+'/records/' + subdomain_id, headers=headers)
|
||||||
@ -225,13 +225,14 @@ def edit_subdomain(domain):
|
|||||||
else:
|
else:
|
||||||
sub = parts[0]
|
sub = parts[0]
|
||||||
top = parts[1] + '.' + parts[2]
|
top = parts[1] + '.' + parts[2]
|
||||||
|
longtop=sub+'.'+top
|
||||||
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. So I\'m giving up!.' % (top))
|
print('[red]Error:[/red] Top domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (top))
|
||||||
else:
|
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]
|
count = cursor.fetchone()[0]
|
||||||
if count == 0:
|
if count == 0:
|
||||||
print('[red]Error:[/red] Domain [bold]%s[/bold] does not exist in the DB. So I\'m giving up!.' % (domain))
|
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:
|
if apikey == None:
|
||||||
print("[red]Error:[/red] Missing APIkey. Please add one!")
|
print("[red]Error:[/red] Missing APIkey. Please add one!")
|
||||||
else:
|
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()
|
domain_info = cursor.fetchone()
|
||||||
subdomain_id = str(domain_info[0])
|
subdomain_id = str(domain_info[0])
|
||||||
status = domain_info[1]
|
status = domain_info[1]
|
||||||
@ -491,7 +492,6 @@ 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]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user