Skip to content

Commit

Permalink
ui - init work on interfacing templates with UI
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0ppy-d1sk committed May 2, 2024
1 parent eb42706 commit deabfe6
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/linux/Dockerfile-centos
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linux/Dockerfile-debian
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linux/Dockerfile-fedora
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linux/Dockerfile-rhel
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linux/Dockerfile-rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linux/Dockerfile-ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/linux/Dockerfile-ubuntu-noble
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
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
Expand Down Expand Up @@ -154,6 +155,7 @@ def handle_stop(signum, frame):
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)
Expand All @@ -171,7 +173,6 @@ def handle_stop(signum, frame):
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":
Expand Down
36 changes: 36 additions & 0 deletions src/ui/src/Templates.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit deabfe6

Please sign in to comment.