ui - init work on interfacing templates with UI

This commit is contained in:
fl0ppy-d1sk 2024-05-02 12:38:35 +02:00
parent eb427067cd
commit deabfe6349
No known key found for this signature in database
GPG key ID: 93EE47CC3D061500
10 changed files with 46 additions and 1 deletions

View file

@ -67,6 +67,7 @@ COPY src/common/gen gen
COPY src/common/helpers helpers
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/templates templates
COPY src/scheduler scheduler
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -53,6 +53,7 @@ COPY src/common/gen gen
COPY src/common/helpers helpers
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/templates templates
COPY src/scheduler scheduler
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -49,6 +49,7 @@ COPY src/common/gen gen
COPY src/common/helpers helpers
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/templates templates
COPY src/scheduler scheduler
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -63,6 +63,7 @@ COPY src/common/gen gen
COPY src/common/helpers helpers
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/templates templates
COPY src/scheduler scheduler
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -64,6 +64,7 @@ COPY src/common/gen gen
COPY src/common/helpers helpers
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/templates templates
COPY src/scheduler scheduler
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -53,6 +53,7 @@ COPY src/common/gen gen
COPY src/common/helpers helpers
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/templates templates
COPY src/scheduler scheduler
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -53,6 +53,7 @@ COPY src/common/gen gen
COPY src/common/helpers helpers
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/templates templates
COPY src/scheduler scheduler
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -30,6 +30,7 @@ COPY src/common/gen gen
COPY src/common/settings.json settings.json
COPY src/common/utils utils
COPY src/common/helpers helpers
COPY src/common/templates templates
COPY src/ui ui
COPY src/VERSION VERSION

View file

@ -51,6 +51,7 @@ from src.ConfigFiles import ConfigFiles
from src.Config import Config
from src.ReverseProxied import ReverseProxied
from src.User import AnonymousUser, User
from src.Templates import get_ui_templates
from utils import check_settings, get_b64encoded_qr_image, path_to_dict, get_remain
from common_utils import get_integration, get_version # type: ignore
@ -154,6 +155,7 @@ try:
SEND_FILE_MAX_AGE_DEFAULT=86400,
SCRIPT_NONCE=sha256(urandom(32)).hexdigest(),
DB=db,
UI_TEMPLATES=get_ui_templates()
)
except FileNotFoundError as e:
app.logger.error(repr(e), e.filename)
@ -171,7 +173,6 @@ csrf.init_app(app)
LOG_RX = re_compile(r"^(?P<date>\d+/\d+/\d+\s\d+:\d+:\d+)\s\[(?P<level>[a-z]+)\]\s\d+#\d+:\s(?P<message>[^\n]+)$")
REVERSE_PROXY_PATH = re_compile(r"^(?P<host>https?://.{1,255}(:((6553[0-5])|(655[0-2]\d)|(65[0-4]\d{2})|(6[0-4]\d{3})|([1-5]\d{4})|([0-5]{0,5})|(\d{1,4})))?)$")
def get_ui_data():
ui_data = "Error"
while ui_data == "Error":

36
src/ui/src/Templates.py Normal file
View file

@ -0,0 +1,36 @@
from json import loads
from glob import glob
from os import sep
from os.path import join
def get_ui_templates():
ui_templates = []
for template_file in glob(join(sep, "usr", "share", "bunkerweb", "templates", "*.json")):
try:
ui_template = {}
with open(template_file, "r") as f:
bw_template = loads(f.read())
ui_template = {
"name": bw_template["name"],
"description": bw_template["description"]
}
ui_template["steps"] = []
for bw_step in bw_template["steps"]:
ui_step = {}
ui_step["name"] = bw_step["name"]
ui_step["description"] = bw_step["description"]
ui_step["settings"] = []
for setting, value in bw_step["settings"].items():
ui_setting = {
"setting_id": setting,
"value": value
}
ui_step["settings"].append(ui_setting)
ui_template["steps"].append(ui_step)
ui_templates.append(ui_template)
except Exception as e:
# print(e)
# TODO: log
pass
# print(ui_templates, flush=True)
return ui_templates