diff --git a/dynaconf/Dockerfile b/dynaconf/Dockerfile new file mode 100644 index 00000000..1024c719 --- /dev/null +++ b/dynaconf/Dockerfile @@ -0,0 +1,11 @@ +from python:bullseye + + +RUN pip install --upgrade pip +RUN pip install flask +RUN pip install flask_sqlalchemy + +COPY src src + + +CMD ["python", "-u", "src/app.py"] \ No newline at end of file diff --git a/dynaconf/src/app.py b/dynaconf/src/app.py new file mode 100644 index 00000000..167ad400 --- /dev/null +++ b/dynaconf/src/app.py @@ -0,0 +1,70 @@ +import copy +from dataclasses import dataclass +from flask import Flask, request, render_template, jsonify +from flask_sqlalchemy import SQLAlchemy +import json + + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database/config.db' +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = 'False' +app.config['SECRET_KEY'] = "random" +db = SQLAlchemy(app) + + +@dataclass +class Database(db.Model): + name: str + ip: str + name = db.Column(db.String(30), primary_key=True) + ip = db.Column(db.String(16), unique=True) + + def __init__(self, name, ip): + self.name = name + self.ip = ip + + +@app.route('/') +def index(): + return render_template('index.html', db_entries=Database.query.all()) + + +@app.route('/create', methods=['POST']) +def create(): + if request.method == 'POST': + json_post = json.loads(request.data) + data = Database(json_post['name'], json_post['ip']) + db.session.add(data) + db.session.commit() + return jsonify(data) + + +@app.route('/update', methods=['POST']) +def update(): + if request.method == 'POST': + json_post = json.loads(request.data) + old_value = copy.deepcopy(Database.query.get(json_post['name'])) + Database.query.filter_by(name=json_post['name']).update(dict(ip=json_post['ip'])) + db.session.commit() + return jsonify(old=old_value, new=json_post) + + +@app.route('/delete', methods=['POST']) +def delete(): + if request.method == 'POST': + json_post = json.loads(request.data) + query = Database.query.get(json_post['name']) + db.session.delete(query) + db.session.commit() + return jsonify(json_post) + + +@app.route('/storage', methods=['GET']) +def storage(): + db_entries = Database.query.all() + return jsonify(db_entries) + + +if __name__ == '__main__': + db.create_all() + app.run(host="0.0.0.0", debug=True) diff --git a/dynaconf/src/static/main.css b/dynaconf/src/static/main.css new file mode 100644 index 00000000..26a57ea1 --- /dev/null +++ b/dynaconf/src/static/main.css @@ -0,0 +1,9 @@ +table, th, td { + border: 1px solid black; +} + +.table a +{ + display:block; + text-decoration:none; +} diff --git a/dynaconf/src/templates/index.html b/dynaconf/src/templates/index.html new file mode 100644 index 00000000..acd7ad03 --- /dev/null +++ b/dynaconf/src/templates/index.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + {% for value in db_entries %} + + + + + + {% endfor %} + +
NameIP
{{ value.name }}{{ value.ip }}
+ + \ No newline at end of file diff --git a/docker-compose.mon-server.yml b/wireguard-server.yml similarity index 89% rename from docker-compose.mon-server.yml rename to wireguard-server.yml index 8c426e0b..8ac9555d 100644 --- a/docker-compose.mon-server.yml +++ b/wireguard-server.yml @@ -46,11 +46,14 @@ services: depends_on: - wireguard - # DEBUG container wireguard - # alpine: - #image: alpine - #command: sleep infinity - #network_mode: "service:wireguard" + dynaconf: + build: ./dynaconf + restart: unless-stopped + volumes: + - database:/src/database + network_mode: "service:wireguard" + volumes: + database: grafana_data: