4 Commits

Author SHA1 Message Date
c6bdca6562 Type fix 2023-04-16 18:45:19 +02:00
b436703b29 Typo fix 2023-04-16 18:34:20 +02:00
6beea36361 Update version .1 2023-04-15 17:12:43 +02:00
024211f0f3 Fix issue #1 2023-04-15 17:11:35 +02:00
2 changed files with 32 additions and 14 deletions

View File

@@ -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

42
ddns.py
View File

@@ -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'
app_version = '0.5.1'
def get_ip():
@@ -129,8 +129,12 @@ def add_subdomain(domain):
print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]')
else:
parts = domain.split('.')
sub = parts[0]
top = parts[1] + '.' + parts[2]
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()
if apikey == None:
print("[red]Error:[/red] Missing APIkey. Please add one!")
@@ -145,9 +149,10 @@ def add_subdomain(domain):
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,))
topdomain_id = cursor.fetchone()
topdomain_id = topdomain_id[0]
cursor.execute('SELECT id,name FROM domains WHERE name LIKE ?',(top,))
topdomain = cursor.fetchone()
topdomain_id = topdomain[0]
topdomain_name = topdomain[1]
cursor.execute('SELECT count(*) FROM subdomains WHERE main_id LIKE ? AND name like ?',(topdomain_id,sub,))
count = cursor.fetchone()[0]
if count != 0:
@@ -174,8 +179,13 @@ def remove_subdomain(domain):
print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]')
else:
parts = domain.split('.')
sub = parts[0]
top = parts[1] + '.' + parts[2]
if len(parts) > 3:
top = parts[1] + '.' + parts[2] + '.' + parts[3]
sub = parts[0]
else:
sub = parts[0]
top = parts[1] + '.' + parts[2]
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ?',(top,))
count = cursor.fetchone()[0]
@@ -209,8 +219,12 @@ def edit_subdomain(domain):
print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]')
else:
parts = domain.split('.')
sub = parts[0]
top = parts[1] + '.' + parts[2]
if len(parts) > 3:
top = parts[1] + '.' + parts[2] + '.' + parts[3]
sub = parts[0]
else:
sub = parts[0]
top = parts[1] + '.' + parts[2]
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM domains WHERE name like ?',(top,))
count = cursor.fetchone()[0]
@@ -471,8 +485,12 @@ def local_add_subdomain(domain,domainid):
print('[red]Error:[/red] Give the domain name in simple form e.g. [b]test.domain.com[/b]')
else:
parts = domain.split('.')
sub = parts[0]
top = parts[1] + '.' + parts[2]
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()
if apikey == None:
print("[red]Error:[/red] Missing APIkey. Please add one!")