4 Commits
0.1 ... 0.2

Author SHA1 Message Date
69a842f41d Updated reuirements.txt 2023-03-19 17:39:56 +01:00
cf4984afe8 Added timestap for update ip function 2023-03-19 17:23:11 +01:00
9c62773ed0 Updated readme 2023-03-09 11:50:34 +01:00
39fa32404e Added .gitignore 2023-03-08 10:59:09 +01:00
4 changed files with 37 additions and 6 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.zip
*.db

View File

@@ -27,6 +27,15 @@ The program is best suited to be executed with e.g cron or any other system that
Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.
## Support
If you found a bug or you have sugestion for new features create an issue.
## Future development
- [ ] IPv6 support
- [ ] Add and delete non existing (new) domains to DO account
## License
[<img src="https://www.gnu.org/graphics/gplv3-with-text-136x68.png">](https://www.gnu.org/licenses/gpl-3.0.en.html)

27
ddns.py
View File

@@ -9,6 +9,7 @@ import argparse
import requests
import os
import time
from datetime import datetime
from string import ascii_letters, digits
from rich import print
from argparse import RawTextHelpFormatter
@@ -16,7 +17,7 @@ from argparse import RawTextHelpFormatter
homefilepath = Path.home()
filepath = homefilepath.joinpath('.config/ddns')
database = filepath.joinpath('ddns.db')
app_version = '0.1'
app_version = '0.2'
def get_ip():
@@ -53,7 +54,7 @@ def connect_database():
api text NOT NULL)''')
c.execute('''CREATE TABLE IF NOT EXISTS ipservers
(id integer NOT NULL PRIMARY KEY,
ip4_server text,
ip4_server text NOT NULL,
ip6_server text)''')
c.execute('''CREATE TABLE IF NOT EXISTS domains
(id integer PRIMARY KEY,
@@ -61,7 +62,7 @@ def connect_database():
c.execute('''CREATE TABLE IF NOT EXISTS subdomains
(id integer PRIMARY KEY,
main_id integer NOT NULL,
name text,
name text NOT NULL,
current_ip4 text NOT NULL,
current_ip6 text NULL)''')
@@ -358,6 +359,7 @@ def updateip():
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM subdomains')
count = cursor.fetchone()[0]
now = datetime.now()
if count == 0:
print('[red]Error: [/red]There are no dynamic domains active.'\
' Start by adding a new domain with [i]ddns -s test.example.com[/i]')
@@ -377,6 +379,7 @@ def updateip():
print('[red]Error: ' + str(response.json))
else:
cursor.execute('UPDATE subdomains SET current_ip4=? WHERE id = ?',(current_ip,subdomain_id,))
cursor.execute('UPDATE subdomains SET last_updated=? WHERE id = ?',(now.strftime("%d/%m/%Y_%H:%M:%S"),subdomain_id,))
conn.commit()
@@ -416,9 +419,23 @@ 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'
cursor = conn.cursor()
info = conn.execute("PRAGMA table_info('subdomains')").fetchall()
if not any(new_table in word for word in info):
add_column = "ALTER TABLE subdomains ADD COLUMN last_updated text"
conn.execute(add_column)
conn.commit()
# Commandline arguments
conn = connect_database()
updatedb()
parser = argparse.ArgumentParser(prog='ddns',
description='Application to use domains from DigitalOcean account as dynamic '\
'DNS domain(s).\nThe app only supports IP4. IPv6 is planned for a later release!'\
@@ -447,7 +464,7 @@ parser.add_argument('-t', '--top', help='Add a new domain from your DigitalOcean
parser.add_argument('-s', '--sub', help='Add a new subdomain to your DigitalOcean account and use as dynamic DNS.\n',
required=False, nargs=1, metavar=('domain'), action='append')
parser.add_argument('-k', '--local', help='Add an existing DigitalOcean domain to your ddns DB and use as dynamic DNS. Get ',
parser.add_argument('-k', '--local', help='Add an existing DigitalOcean domain to your ddns DB and use as dynamic DNS.',
required=False, nargs=2, metavar=('domain','domainid'), action='append')
parser.add_argument('-r', '--remove', help='Remove a subdomain from your DigitalOcean account and ddns.',

View File

@@ -3,17 +3,20 @@ aiosignal==1.3.1
async-timeout==4.0.2
attrs==22.2.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.1.0
click==8.1.3
frozenlist==1.3.3
gpg==1.18.0
gpg==1.19.0
idna==3.4
markdown-it-py==2.2.0
mdurl==0.1.2
multidict==6.0.4
notmuch==0.37
notmuch2==0.37
openai==0.27.0
promptcli==1.0.4
pycparser==2.21
Pygments==2.14.0
requests==2.28.2
rich==13.3.1