Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
69a842f41d | |||
cf4984afe8 | |||
9c62773ed0 | |||
39fa32404e |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*.zip
|
||||||
|
*.db
|
@@ -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
|
Pull requests are welcome. For major changes, please open an issue first
|
||||||
to discuss what you would like to change.
|
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
|
## License
|
||||||
|
|
||||||
[<img src="https://www.gnu.org/graphics/gplv3-with-text-136x68.png">](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
[<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
27
ddns.py
@@ -9,6 +9,7 @@ import argparse
|
|||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
from string import ascii_letters, digits
|
from string import ascii_letters, digits
|
||||||
from rich import print
|
from rich import print
|
||||||
from argparse import RawTextHelpFormatter
|
from argparse import RawTextHelpFormatter
|
||||||
@@ -16,7 +17,7 @@ from argparse import RawTextHelpFormatter
|
|||||||
homefilepath = Path.home()
|
homefilepath = Path.home()
|
||||||
filepath = homefilepath.joinpath('.config/ddns')
|
filepath = homefilepath.joinpath('.config/ddns')
|
||||||
database = filepath.joinpath('ddns.db')
|
database = filepath.joinpath('ddns.db')
|
||||||
app_version = '0.1'
|
app_version = '0.2'
|
||||||
|
|
||||||
|
|
||||||
def get_ip():
|
def get_ip():
|
||||||
@@ -53,7 +54,7 @@ def connect_database():
|
|||||||
api text NOT NULL)''')
|
api text NOT NULL)''')
|
||||||
c.execute('''CREATE TABLE IF NOT EXISTS ipservers
|
c.execute('''CREATE TABLE IF NOT EXISTS ipservers
|
||||||
(id integer NOT NULL PRIMARY KEY,
|
(id integer NOT NULL PRIMARY KEY,
|
||||||
ip4_server text,
|
ip4_server text NOT NULL,
|
||||||
ip6_server text)''')
|
ip6_server text)''')
|
||||||
c.execute('''CREATE TABLE IF NOT EXISTS domains
|
c.execute('''CREATE TABLE IF NOT EXISTS domains
|
||||||
(id integer PRIMARY KEY,
|
(id integer PRIMARY KEY,
|
||||||
@@ -61,7 +62,7 @@ def connect_database():
|
|||||||
c.execute('''CREATE TABLE IF NOT EXISTS subdomains
|
c.execute('''CREATE TABLE IF NOT EXISTS subdomains
|
||||||
(id integer PRIMARY KEY,
|
(id integer PRIMARY KEY,
|
||||||
main_id integer NOT NULL,
|
main_id integer NOT NULL,
|
||||||
name text,
|
name text NOT NULL,
|
||||||
current_ip4 text NOT NULL,
|
current_ip4 text NOT NULL,
|
||||||
current_ip6 text NULL)''')
|
current_ip6 text NULL)''')
|
||||||
|
|
||||||
@@ -358,6 +359,7 @@ def updateip():
|
|||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT COUNT(*) FROM subdomains')
|
cursor.execute('SELECT COUNT(*) FROM subdomains')
|
||||||
count = cursor.fetchone()[0]
|
count = cursor.fetchone()[0]
|
||||||
|
now = datetime.now()
|
||||||
if count == 0:
|
if count == 0:
|
||||||
print('[red]Error: [/red]There are no dynamic domains active.'\
|
print('[red]Error: [/red]There are no dynamic domains active.'\
|
||||||
' Start by adding a new domain with [i]ddns -s test.example.com[/i]')
|
' 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))
|
print('[red]Error: ' + str(response.json))
|
||||||
else:
|
else:
|
||||||
cursor.execute('UPDATE subdomains SET current_ip4=? WHERE id = ?',(current_ip,subdomain_id,))
|
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()
|
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
|
# Commandline arguments
|
||||||
conn = connect_database()
|
conn = connect_database()
|
||||||
|
updatedb()
|
||||||
parser = argparse.ArgumentParser(prog='ddns',
|
parser = argparse.ArgumentParser(prog='ddns',
|
||||||
description='Application to use domains from DigitalOcean account as dynamic '\
|
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!'\
|
'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',
|
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')
|
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')
|
required=False, nargs=2, metavar=('domain','domainid'), action='append')
|
||||||
|
|
||||||
parser.add_argument('-r', '--remove', help='Remove a subdomain from your DigitalOcean account and ddns.',
|
parser.add_argument('-r', '--remove', help='Remove a subdomain from your DigitalOcean account and ddns.',
|
||||||
|
@@ -3,17 +3,20 @@ aiosignal==1.3.1
|
|||||||
async-timeout==4.0.2
|
async-timeout==4.0.2
|
||||||
attrs==22.2.0
|
attrs==22.2.0
|
||||||
certifi==2022.12.7
|
certifi==2022.12.7
|
||||||
|
cffi==1.15.1
|
||||||
charset-normalizer==3.1.0
|
charset-normalizer==3.1.0
|
||||||
click==8.1.3
|
click==8.1.3
|
||||||
frozenlist==1.3.3
|
frozenlist==1.3.3
|
||||||
gpg==1.18.0
|
gpg==1.19.0
|
||||||
idna==3.4
|
idna==3.4
|
||||||
markdown-it-py==2.2.0
|
markdown-it-py==2.2.0
|
||||||
mdurl==0.1.2
|
mdurl==0.1.2
|
||||||
multidict==6.0.4
|
multidict==6.0.4
|
||||||
notmuch==0.37
|
notmuch==0.37
|
||||||
|
notmuch2==0.37
|
||||||
openai==0.27.0
|
openai==0.27.0
|
||||||
promptcli==1.0.4
|
promptcli==1.0.4
|
||||||
|
pycparser==2.21
|
||||||
Pygments==2.14.0
|
Pygments==2.14.0
|
||||||
requests==2.28.2
|
requests==2.28.2
|
||||||
rich==13.3.1
|
rich==13.3.1
|
||||||
|
Reference in New Issue
Block a user