Compare commits
8 Commits
0.4.1
...
ee2a1cb6df
Author | SHA1 | Date | |
---|---|---|---|
ee2a1cb6df | |||
d98ed44ba9 | |||
678c32b2ea | |||
5ccb9b90d4 | |||
4a1ac2ec6e | |||
29aec3b030 | |||
ebe9ff1860 | |||
d271c44adf |
@@ -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 -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 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```
|
||||
|
||||
## Usage
|
||||
|
||||
|
42
ddns.py
42
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)
|
||||
app_version = '0.4.1'
|
||||
app_version = '0.4.2.1'
|
||||
|
||||
|
||||
def get_ip():
|
||||
@@ -124,6 +124,7 @@ def add_domian(domain):
|
||||
|
||||
|
||||
def add_subdomain(domain):
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M")
|
||||
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]')
|
||||
else:
|
||||
@@ -160,7 +161,7 @@ def add_subdomain(domain):
|
||||
if response != 'Fail':
|
||||
response_data = response.json()
|
||||
domainid = str(response_data['domain_record']['id'])
|
||||
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()
|
||||
print('The domain %s has been added.' % (domain))
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M") + ' - Info : subdomain %s added'%(domain))
|
||||
@@ -239,7 +240,8 @@ def list_sub_domains(domain):
|
||||
if count == 0:
|
||||
print("[red]Error: [/red]No such domain. Check spelling or use ddns -d to show all top domains.")
|
||||
else:
|
||||
print('\n\nCurrent sub domains for [b]%s[/b]' % (domain))
|
||||
print('\n\nCurrent sub domains for [b]%s[/b]\n\n' % (domain))
|
||||
print('Domain\t\t\t\tCreated\t\t\tUpdated\t\t\tChecked')
|
||||
print('===============================================================================================')
|
||||
cursor.execute('SELECT id FROM domains WHERE name LIKE ?', (domain,))
|
||||
topdomain_id = cursor.fetchone()[0]
|
||||
@@ -248,12 +250,12 @@ def list_sub_domains(domain):
|
||||
if count == 0:
|
||||
print('[red]Error:[/red] No sub domains for [b]%s[/b]' % (domain))
|
||||
else:
|
||||
cursor.execute('SELECT name,last_updated,last_checked FROM subdomains WHERE main_id LIKE ?',(topdomain_id,) )
|
||||
cursor.execute('SELECT name,last_updated,last_checked,created FROM subdomains WHERE main_id LIKE ?',(topdomain_id,) )
|
||||
subdomains = cursor.fetchall()
|
||||
for i in subdomains:
|
||||
topdomain = i[0]+'.'+domain
|
||||
topdomain = "{:<25}".format(topdomain)
|
||||
print(topdomain+'\tUpdated : '+i[1]+'\tChecked : '+i[2])
|
||||
print(topdomain+'\t'+i[3]+'\t'+i[1]+'\t'+i[2])
|
||||
print('\n')
|
||||
|
||||
|
||||
@@ -313,7 +315,9 @@ def show_current_info():
|
||||
ipserver = '[red]Error:[/red] No IP resolvers in DB'
|
||||
else:
|
||||
cursor.execute('SELECT * FROM ipservers')
|
||||
ipserver = cursor.fetchall()[0][1]
|
||||
ipservers = cursor.fetchall()
|
||||
ip4server = ipservers[0][1]
|
||||
ip6server = ipservers[0][2]
|
||||
|
||||
if API == None:
|
||||
API = '[red]Error:[/red] API key not stored in DB'
|
||||
@@ -327,8 +331,8 @@ def show_current_info():
|
||||
print('\n[b]ddns[/b] - a DigitalOcean dynamic DNS solution.')
|
||||
print('===================================================')
|
||||
print('API key : [b]%s[/b]' % (API))
|
||||
print('IP v4 resolver : [b]%s[/b]' % (ipserver))
|
||||
print('IP v6 resolver : [b]N/A[/b]')
|
||||
print('IP v4 resolver : [b]%s[/b]' % (ip4server))
|
||||
print('IP v6 resolver : [b]%s[/b]' % (ip6server))
|
||||
print('Logfile : [b]%s[/b]' % (logfile))
|
||||
print('Top domains : [b]%s[/b]' % (topdomains))
|
||||
print('sub domains : [b]%s[/b]' % (subdomains))
|
||||
@@ -373,7 +377,7 @@ def updateip(force):
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('SELECT COUNT(*) FROM subdomains')
|
||||
count = cursor.fetchone()[0]
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M")
|
||||
now = datetime.now().strftime("%d-%m-%Y %H:%M")
|
||||
updated = None
|
||||
if count == 0:
|
||||
print('[red]Error: [/red]There are no dynamic domains active.'\
|
||||
@@ -417,6 +421,7 @@ def updateip(force):
|
||||
|
||||
|
||||
def local_add_subdomain(domain,domainid):
|
||||
now = datetime.now().strftime("%Y-%m-%d %H:%M")
|
||||
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]')
|
||||
else:
|
||||
@@ -445,7 +450,7 @@ def local_add_subdomain(domain,domainid):
|
||||
if count != 0:
|
||||
print('[red]Error:[/red] [bold]%s[/bold] already exists.' % (domain))
|
||||
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()
|
||||
print('The domain %s has been added.' % (domain))
|
||||
|
||||
@@ -454,22 +459,30 @@ def local_add_subdomain(domain,domainid):
|
||||
def updatedb():
|
||||
# Update DB with new column 20.03.23
|
||||
# Add last updated field for subdomains
|
||||
new_table = 'last_updated'
|
||||
new_column = 'last_updated'
|
||||
info = conn.execute("PRAGMA table_info('subdomains')").fetchall()
|
||||
if not any(new_table in word for word in info):
|
||||
if not any(new_column in word for word in info):
|
||||
add_column = "ALTER TABLE subdomains ADD COLUMN last_updated text default 'N/A'"
|
||||
conn.execute(add_column)
|
||||
conn.commit()
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M")+' - Info : Database updated')
|
||||
|
||||
new_table = 'last_checked'
|
||||
new_column = 'last_checked'
|
||||
info = conn.execute("PRAGMA table_info('subdomains')").fetchall()
|
||||
if not any(new_table in word for word in info):
|
||||
if not any(new_column in word for word in info):
|
||||
add_column = "ALTER TABLE subdomains ADD COLUMN last_checked text default 'N/A'"
|
||||
conn.execute(add_column)
|
||||
conn.commit()
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M") + ' - Info : Database updated')
|
||||
|
||||
new_column = 'created'
|
||||
info = conn.execute("PRAGMA table_info('subdomains')").fetchall()
|
||||
if not any(new_column in word for word in info):
|
||||
add_column = "ALTER TABLE subdomains ADD COLUMN created text default '[b]Unknown Info[/b]'"
|
||||
conn.execute(add_column)
|
||||
conn.commit()
|
||||
logging.info(time.strftime("%Y-%m-%d %H:%M") + ' - Info : Database updated')
|
||||
|
||||
|
||||
|
||||
# Commandline arguments
|
||||
@@ -547,3 +560,4 @@ elif args['local']:
|
||||
local_add_subdomain(args['local'][0][0],args['local'][0][1])
|
||||
else:
|
||||
updateip(None)
|
||||
|
Reference in New Issue
Block a user