Initial commit

This commit is contained in:
2026-08-21 23:19:27 +02:00
parent 342b03b39a
commit 144da958dd
5 changed files with 103 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
FROM python:3.14.7-alpine3.24
# Install dnsmasq
RUN apk --update --no-cache add dnsmasq
# Install libraries
COPY ./requirements.txt /requirements.txt
RUN pip3 install -r /requirements.txt
# Copy source
COPY ./run.sh /run.sh
COPY ./app/ /app
RUN mkdir /app/hosts.d/
CMD ["/run.sh"]
+69
View File
@@ -0,0 +1,69 @@
from flask import Flask, jsonify, request
import re
HOSTS_PATH = "/app/hosts.d/izbi"
app = Flask(__name__)
hosts = {}
def update_hosts(path: str, hosts: dict = {}): bool
try:
hosts_str = ""
for domain, ip in hosts.items():
hosts_str += f"{ip}\t{domain}\n"
with open(path, "w") as f:
f.write(hosts_str)
print(f"ddns - updated {path}")
return True
except Exception as e:
print(e)
return False
def validate_ip(ip: str): bool
exp = "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"
return re.search(exp, ip)
@app.route('/', methods=["GET"])
def health():
return jsonify({"status": "healthy", "comment": ""})
@app.route('/update', methods=["GET"])
def update_addr():
if 'domain' not in request.args:
return jsonify({"status": "400", "code": "domain-error", "comment": "Missing or invalid domain"}), 400
domain = request.args['domain']
if 'ip' not in request.args:
ip = request.remote_addr
elif not validate_ip(request.args['ip']):
return jsonify({"status": "400", "code": "ip-error", "comment": "Invalid IP"}), 400
else:
ip = request.args['ip']
print(f"ddns - update request of [{domain}, {ip}] from {request.remote_addr}")
hosts[domain] = ip
success = update_hosts(HOSTS_PATH, hosts)
if not success:
return jsonify({"status": "500", "code": "internal-server-error", "An error occurred while processing request"}), 500
return jsonify({"status": "200", "code": "ok", "comment": "Updated successfully"})
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8080, debug=True)
+8
View File
@@ -0,0 +1,8 @@
services:
ddns:
image: izbi-dns
build: .
restart: unless-stopped
ports:
- "127.0.0.1:8080:8080"
- "127.0.0.1:55:5353/udp"
+1
View File
@@ -0,0 +1 @@
flask
Executable
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
/usr/sbin/dnsmasq -d --hostsdir /app/hosts.d/ -p 5353 &
/usr/local/bin/python3 /app/main.py &
wait -n
exit $?