add sample config.json + working webserver

This commit is contained in:
lare 2022-11-11 20:17:37 +01:00
parent f5bd6b5a5f
commit 9cf41845a8
6 changed files with 99 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
venv
config.json

View file

@ -0,0 +1,19 @@
{
"nodes": {
"<nodename>": {
"pub-endpoint": "<clearnet-fqdn/ip-address>",
"api-con": "http://<node-(internal)-ip/hostname>:<port>/",
"comment": "/* from here: data to be displayed on the webinterface */",
"internal-v4": "172.2x.xxx.xxx",
"internal-v6": "fdxx:...",
"internal-v4ll": "169.254.xxx.xxx",
"internal-v6ll": "fe80::..."
}
},
"MNT": "YOUR-MNT", // your MNT tag
"listen": "0.0.0.0",
"port": 8042,
"flask-debug": false, // optional; default false
"flask-template-dir": "../frontend/" // optional; default "../frontend"
}

56
web/backend/main.py Normal file
View file

@ -0,0 +1,56 @@
#! /usr/bin/env python3
from flask import Flask, Response, redirect, render_template, request, session, abort
import json, os
app = Flask(__name__)
class Config (dict):
def __init__(self, configfile:str = None):
if configfile:
self.configfile = configfile
else:
if os.path.exists("./config.json"): self.configfile = "./config.json"
elif os.path.exists("/etc/dn42-autopeer/config.json"): self.configfile = "/etc/dn42-autopeer/config,json"
else: raise FileNotFoundError("no config file found in ./config.json or /etc/dn42-autopeer/config.json")
self.load_config()
self.keys = self._config.keys
#self.__getitem__ = self._config.__getitem__
super().__init__(self)
def __delitem__(self, v):
raise NotImplementedError()
super().__delitem__(self,v)
def __getitem__(self, k):
return self._config[k]
def load_config(self):
with open(self.configfile) as cf:
try:
self._config = json.load(cf)
except json.decoder.JSONDecodeError:
raise SyntaxError(f"no valid JSON found in '{cf.name}'")
if not "flask-template-dir" in self._config:
self._config["flask-template-dir"] = "../frontend"
if not "flask-debug" in self._config:
self._config["flask-debug"] = False
print(self._config)
config = Config()
@app.route("/")
def index():
print(config)
return render_template("index.html", config=config)
def main():
app.static_folder= config["flask-template-dir"]+"/static/"
app.template_folder=config["flask-template-dir"]
app.run(host=config["listen"], port=config["port"], debug=config["flask-debug"], threaded=True)
if __name__ == "__main__":
main()

1
web/backend/templates Symbolic link
View file

@ -0,0 +1 @@
../frontend

17
web/frontend/index.html Normal file
View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{config["MNT"]}} Autopeering</title>
<link rel="stylesheet" href="static/style.css">
</head>
<body>
<div class="content">
<div>{{config["MNT"]}}</div>
<div></div>
<div></div>
</div>
</body>
</html>

View file

@ -0,0 +1,4 @@
body {
color: wheat;
background-color: black;
}