add whitelist service

This commit is contained in:
cventastic
2022-09-25 23:54:04 +02:00
parent 48fdbf0aac
commit d30accaa19
5 changed files with 123 additions and 5 deletions

11
dynaconf/Dockerfile Normal file
View File

@@ -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"]

70
dynaconf/src/app.py Normal file
View File

@@ -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)

View File

@@ -0,0 +1,9 @@
table, th, td {
border: 1px solid black;
}
.table a
{
display:block;
text-decoration:none;
}

View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang = "en">
<head>
<link rel="stylesheet" href="/static/main.css">
</head>
<body>
<table>
<thead>
<tr>
<td>Name</td>
<td>IP</td>
</tr>
</thead>
<tbody>
{% for value in db_entries %}
<tr>
<td>{{ value.name }}</td>
<td>{{ value.ip }}</td>
<!-- <td><a href="{{ url_for('delete', name=value.name) }}">Delete</a></td>-->
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

View File

@@ -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: