From bfe509532de18ab310afd3b85c379e985e1b49cd Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Tue, 16 Jun 2020 13:35:38 +0200 Subject: rename ztdns_db_connectivity -> src/ztdnslib --- doc/uzytkowanie/main.tex | 4 ++-- install.sh | 2 +- src/hourly.py | 2 +- src/perform_queries.py | 2 +- src/ztdns_db_connectivity.py | 26 -------------------------- src/ztdnslib.py | 26 ++++++++++++++++++++++++++ uninstall.sh | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 src/ztdns_db_connectivity.py create mode 100644 src/ztdnslib.py diff --git a/doc/uzytkowanie/main.tex b/doc/uzytkowanie/main.tex index 88689ea..2339c93 100644 --- a/doc/uzytkowanie/main.tex +++ b/doc/uzytkowanie/main.tex @@ -28,7 +28,7 @@ oraz do \dir{/usr/sbin/} skrypty wchodzące w skład systemu. Oprócz tego \file{install.sh} umieszcza importowany przez inne skrypty -\file{ztdns_db_connectivity.py} w \dir{/usr/lib/python3/dist-packages/} +\file{ztdnslib.py} w \dir{/usr/lib/python3/dist-packages/} oraz kopiuje \file{db_connection_config.yml} do katalogu \dir{/etc/0tdns/}. Programy działające w ramach systemu automatycznie sukają konfiguracji @@ -79,7 +79,7 @@ Jeśli z systemu mają być usunięte także pliki zainstalowane przez skrypt \section{Działanie części back-endowej systemu} Demon crona co gdzin uruchamia skrypt \file{hourly.py}, który łączy się -z bazą (używając funkcji z \file{ztdns_db_connectivity.py}, która czyta +z bazą (używając funkcji z \file{ztdnslib.py}, która czyta konfigurację \filepath{/etc/0tdns/db_connection_config.yml}). Skrypt \file{hourly.py} pobiera z bazy id wszystkich połączeń VPN, diff --git a/install.sh b/install.sh index 4a1eb58..1e2a21c 100755 --- a/install.sh +++ b/install.sh @@ -24,6 +24,6 @@ install -D -m644 db_connection_config.yml "$INSTALL_ROOT"/etc/0tdns/db_connectio install -D -m744 src/hourly.py "$INSTALL_ROOT"/usr/sbin/hourly.py # This one shall be imported from other scripts -install -D -m644 src/ztdns_db_connectivity.py "$INSTALL_ROOT"/usr/lib/python3/dist-packages/ztdns_db_connectivity.py +install -D -m644 src/ztdnslib.py "$INSTALL_ROOT"/usr/lib/python3/dist-packages/ztdnslib.py # simillar approach will be used to install other files diff --git a/src/hourly.py b/src/hourly.py index c81a5b7..0d371ab 100755 --- a/src/hourly.py +++ b/src/hourly.py @@ -6,7 +6,7 @@ from os import path, waitpid, unlink from time import gmtime, strftime, sleep # our own module used by several scripts in the project -from ztdns_db_connectivity import start_db_connection, \ +from ztdnslib import start_db_connection, \ get_default_host_address, get_ztdns_config wrapper = '/var/lib/0tdns/vpn_wrapper.sh' diff --git a/src/perform_queries.py b/src/perform_queries.py index c568bf6..1d20b13 100755 --- a/src/perform_queries.py +++ b/src/perform_queries.py @@ -7,7 +7,7 @@ import unbound import psycopg2 # our own module used by several scripts in the project -from ztdns_db_connectivity import start_db_connection, get_ztdns_config +from ztdnslib import start_db_connection, get_ztdns_config class dns_queries: def __init__(self, dns_IP, dns_id, services): diff --git a/src/ztdns_db_connectivity.py b/src/ztdns_db_connectivity.py deleted file mode 100644 index 34e1e00..0000000 --- a/src/ztdns_db_connectivity.py +++ /dev/null @@ -1,26 +0,0 @@ -import yaml -import psycopg2 - -db_config_path = '/etc/0tdns/db_connection_config.yml' - -def get_ztdns_config(): - return yaml.safe_load(open(db_config_path, 'r')) - -def start_db_connection(config): - connection = psycopg2.connect(user=config['user'], password=config['password'], - host=config['host'], port=config['port'], - database=config['database']) - # we might later decide that each user of start_db_connection() - # should set it themselves - but for now, set it here - connection.autocommit = True - return connection - -# we'll use it for setting SNAT -# https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib -def get_default_host_address(remote_address): - import socket - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.connect((remote_address, 80)) - hostaddr = s.getsockname()[0] - s.close() - return hostaddr diff --git a/src/ztdnslib.py b/src/ztdnslib.py new file mode 100644 index 0000000..34e1e00 --- /dev/null +++ b/src/ztdnslib.py @@ -0,0 +1,26 @@ +import yaml +import psycopg2 + +db_config_path = '/etc/0tdns/db_connection_config.yml' + +def get_ztdns_config(): + return yaml.safe_load(open(db_config_path, 'r')) + +def start_db_connection(config): + connection = psycopg2.connect(user=config['user'], password=config['password'], + host=config['host'], port=config['port'], + database=config['database']) + # we might later decide that each user of start_db_connection() + # should set it themselves - but for now, set it here + connection.autocommit = True + return connection + +# we'll use it for setting SNAT +# https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib +def get_default_host_address(remote_address): + import socket + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect((remote_address, 80)) + hostaddr = s.getsockname()[0] + s.close() + return hostaddr diff --git a/uninstall.sh b/uninstall.sh index a176e5b..5e8a0b8 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -24,5 +24,5 @@ if [ "x$1" = "x--delete-files" ]; then rm -r /etc/netns/0tdns* rm /usr/sbin/hourly.py rm -r /etc/0tdns - rm /usr/lib/python3/dist-packages/ztdns_db_connectivity.py + rm /usr/lib/python3/dist-packages/ztdnslib.py fi -- cgit v1.2.3