Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
40c4476081 | |||
890dfea5ab | |||
f39ca9c997 | |||
099499f4c6 | |||
c6bdca6562 | |||
b436703b29 |
@ -4,7 +4,7 @@ _DDNS_ is a dynamic DNS helper for Digital Ocean users to utilize their DO accou
|
||||
|
||||
## Installation
|
||||
|
||||
Download the latest relase from https://gitlab.pm/rune/ddns/releases. Unzip and move to a folder in you path (ease of use). You can alos rename the file ```ddns.py``` to just ```ddns``` and make the file executable with ```chmod +x ddns```. To install required python modules run ```pip3 install -r requirements.txt```
|
||||
Download the latest relase from https://gitlab.pm/rune/ddns/releases. Unzip and move to a folder in you path (ease of use). You can also rename the file ```ddns.py``` to just ```ddns``` and make the file executable with ```chmod +x ddns```. To install required python modules run ```pip3 install -r requirements.txt```
|
||||
|
||||
## Usage
|
||||
|
||||
@ -27,7 +27,7 @@ to discuss what you would like to change.
|
||||
|
||||
## Support
|
||||
|
||||
If you found a bug or you have sugestion for new features create an issue.
|
||||
If you found a bug or you have suggestion for new features create an issue.
|
||||
|
||||
## Future development
|
||||
|
||||
|
32
ddns.py
32
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():
|
||||
@ -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]
|
||||
@ -347,8 +348,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()
|
||||
@ -488,10 +494,12 @@ def local_add_subdomain(domain,domainid):
|
||||
if len(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,))
|
||||
|
Loading…
Reference in New Issue
Block a user