diff --git a/.gitignore b/.gitignore index b182160..93c3af2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode -# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode +# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,sonarqube +# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,sonarqube ### Python ### # Byte-compiled / optimized / DLL files @@ -173,6 +173,19 @@ poetry.toml # LSP config files pyrightconfig.json +### SonarQube ### +# SonarQube ignore files. +# +# https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner +# Sonar Scanner working directories +.sonar/ +.sonarqube/ +.scannerwork/ + +# http://www.sonarlint.org/commandline/ +# SonarLint working directories, configuration files (including credentials) +.sonarlint/ + ### VisualStudioCode ### .vscode/ @@ -187,4 +200,4 @@ pyrightconfig.json .history .ionide -# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,sonarqube \ No newline at end of file diff --git a/README.md b/README.md index 57cf094..50bb65f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ This project aims to implement a Dynamic DNS (DDNS) solution using Cloudflare's API. -[![Maintainability Rating](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_cloudflare-ddns_e6da100b-a671-4736-87ac-9a41acda99f6&metric=sqale_rating&token=sqb_f7f644f779ab4e442b5d5e431589f57bd3c64150)](https://sonar.pieroot.xyz/dashboard?id=pieroot_cloudflare-ddns_e6da100b-a671-4736-87ac-9a41acda99f6) +[![Quality Gate Status](https://sonar.pieroot.xyz/api/project_badges/measure?project=jung-geun_cloudflare-ddns_AZIjf9NeRMPvGKjJzls4&metric=alert_status&token=sqb_706e3b82fdb379ee29accac27f1bd19726dcb31c)](https://sonar.pieroot.xyz/dashboard?id=jung-geun_cloudflare-ddns_AZIjf9NeRMPvGKjJzls4) +[![Security Hotspots](https://sonar.pieroot.xyz/api/project_badges/measure?project=jung-geun_cloudflare-ddns_AZIjf9NeRMPvGKjJzls4&metric=security_hotspots&token=sqb_706e3b82fdb379ee29accac27f1bd19726dcb31c)](https://sonar.pieroot.xyz/dashboard?id=jung-geun_cloudflare-ddns_AZIjf9NeRMPvGKjJzls4) +[![Bugs](https://sonar.pieroot.xyz/api/project_badges/measure?project=jung-geun_cloudflare-ddns_AZIjf9NeRMPvGKjJzls4&metric=bugs&token=sqb_706e3b82fdb379ee29accac27f1bd19726dcb31c)](https://sonar.pieroot.xyz/dashboard?id=jung-geun_cloudflare-ddns_AZIjf9NeRMPvGKjJzls4) ## Overview Dynamic DNS allows you to associate a domain name with a changing IP address, making it easier to access your network resources remotely. Cloudflare's API provides the necessary tools to automate this process. diff --git a/src/update_dns.py b/src/update_dns.py index 11ffb5b..4fed954 100644 --- a/src/update_dns.py +++ b/src/update_dns.py @@ -22,6 +22,8 @@ logger.addHandler(fileHandler) logger.addHandler(logging.StreamHandler()) DEFAULT_CONFIG_PATH = os.path.join(os.path.dirname(__file__), "../config/env.json") +PWD = os.path.dirname(os.path.abspath(__file__)) +TMP_PATH = os.path.join(PWD, "tmp") class DDNS: @@ -34,6 +36,7 @@ class DDNS: logger.info(f"Previous IP: {previous_ip}") self.current_ip = current_ip self.cname_list = self.config["CLOUDFLARE_CNAME"] + self.external_ip_path = os.path.join(TMP_PATH, "external_ip.txt") self.HEADERS = { "Content-Type": "application/json", @@ -105,11 +108,11 @@ class DDNS: def previous_ip(self): try: - if os.path.exists("/tmp/external_ip.txt"): - with open("/tmp/external_ip.txt", "r") as file: + if os.path.exists(self.external_ip_path): + with open(self.external_ip_path, "r") as file: return file.read() else: - os.mknod("/tmp/external_ip.txt") + os.mknod(self.external_ip_path) except Exception as e: logger.error(f"Error: {e}") return None @@ -127,7 +130,7 @@ class DDNS: def update_ip(self, ip): try: - with open("/tmp/external_ip.txt", "w") as file: + with open(self.external_ip_path, "w") as file: file.write(ip) logger.info("IP is updated") except Exception as e: diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 0000000..e69de29