Commit c912dfcd authored by dobli's avatar dobli
Browse files

added web file manager to edit configuration files

parent 82630616
No related merge requests found
Showing with 62 additions and 13 deletions
+62 -13
...@@ -78,6 +78,7 @@ class Service(Enum): ...@@ -78,6 +78,7 @@ class Service(Enum):
NODERED = ("Node-RED", "nodered", False, True, 'ballot') NODERED = ("Node-RED", "nodered", False, True, 'ballot')
POSTGRES = ("Postgre SQL", "postgres", True, False) POSTGRES = ("Postgre SQL", "postgres", True, False)
MQTT = ("Mosquitto MQTT Broker", "mqtt", True, False) MQTT = ("Mosquitto MQTT Broker", "mqtt", True, False)
FILES = ("File Manager", "files", False, True, 'folder')
def __init__(self, fullname, prefix, additional, frontend, icon=None): def __init__(self, fullname, prefix, additional, frontend, icon=None):
self.fullname = fullname self.fullname = fullname
...@@ -236,6 +237,32 @@ def add_postgres_service(base_dir, hostname, postfix=None): ...@@ -236,6 +237,32 @@ def add_postgres_service(base_dir, hostname, postfix=None):
add_or_update_compose_service(compose_path, service_name, template) add_or_update_compose_service(compose_path, service_name, template)
def add_file_service(base_dir, hostname):
"""Generates an file manager entry and adds it to the compose file
:base_dir: base directory for configuration files
:hostname: names of host that the services is added to
"""
base_path = base_dir + '/' + CUSTOM_DIR
# compose file
compose_path = base_path + '/' + COMPOSE_NAME
# service name
service_name = f'files_{hostname}'
# template
template = get_service_template(base_dir, Service.FILES.prefix)
# add command that sets base url
template['command'] = f'-b /{service_name}'
# only label contraint is building
template['deploy']['placement']['constraints'][0] = (
f"{CONSTRAINTS['building']} == {hostname}")
template['deploy']['labels'].append(f'traefik.backend={service_name}')
template['deploy']['labels'].extend(
generate_traefik_path_labels(service_name, segment='main',
redirect=False))
add_or_update_compose_service(compose_path, service_name, template)
# Functions to delete services # Functions to delete services
def delete_service(base_dir, service_name): def delete_service(base_dir, service_name):
"""Deletes a service from the compose file """Deletes a service from the compose file
...@@ -329,12 +356,14 @@ def generate_traefik_subdomain_labels(subdomain, segment=None, priority=2): ...@@ -329,12 +356,14 @@ def generate_traefik_subdomain_labels(subdomain, segment=None, priority=2):
return label_list return label_list
def generate_traefik_path_labels(url_path, segment=None, priority=2): def generate_traefik_path_labels(url_path, segment=None, priority=2,
redirect=True):
"""Generates a traefik path url with necessary redirects """Generates a traefik path url with necessary redirects
:url_path: path that should be used for the site :url_path: path that should be used for the site
:segment: Optional traefik segment when using multiple rules :segment: Optional traefik segment when using multiple rules
:priority: Priority of frontend rule :priority: Priority of frontend rule
:redirect: Redirect to path with trailing slash
:returns: list of labels for traefik :returns: list of labels for traefik
""" """
label_list = [] label_list = []
...@@ -342,13 +371,17 @@ def generate_traefik_path_labels(url_path, segment=None, priority=2): ...@@ -342,13 +371,17 @@ def generate_traefik_path_labels(url_path, segment=None, priority=2):
segment = f'.{segment}' if segment is not None else '' segment = f'.{segment}' if segment is not None else ''
# fill list # fill list
label_list.append(f'traefik{segment}.frontend.priority={priority}') label_list.append(f'traefik{segment}.frontend.priority={priority}')
label_list.append( if redirect:
f'traefik{segment}.frontend.redirect.regex=^(.*)/{url_path}$$') label_list.append(
label_list.append( f'traefik{segment}.frontend.redirect.regex=^(.*)/{url_path}$$')
f'traefik{segment}.frontend.redirect.replacement=$$1/{url_path}/') label_list.append(
label_list.append( f'traefik{segment}.frontend.redirect.replacement=$$1/{url_path}/')
f'traefik{segment}.frontend.rule=PathPrefix:/{url_path};' label_list.append(
f'ReplacePathRegex:^/{url_path}/(.*) /$$1') f'traefik{segment}.frontend.rule=PathPrefix:/{url_path};'
f'ReplacePathRegex:^/{url_path}/(.*) /$$1')
else:
label_list.append(
f'traefik{segment}.frontend.rule=PathPrefix:/{url_path}')
return label_list return label_list
...@@ -471,7 +504,7 @@ def generate_pb_framr_entry(host, service): ...@@ -471,7 +504,7 @@ def generate_pb_framr_entry(host, service):
entry['url'] = f'http://{host}/' entry['url'] = f'http://{host}/'
pass pass
else: else:
entry['url'] = f'/{service.prefix}_{host}' entry['url'] = f'/{service.prefix}_{host}/'
entry['icon'] = service.icon entry['icon'] = service.icon
return entry return entry
...@@ -1153,6 +1186,8 @@ def init_machine_menu(base_dir, host, increment): ...@@ -1153,6 +1186,8 @@ def init_machine_menu(base_dir, host, increment):
add_mqtt_service(base_dir, host, increment) add_mqtt_service(base_dir, host, increment)
if Service.POSTGRES in services: if Service.POSTGRES in services:
add_postgres_service(base_dir, host) add_postgres_service(base_dir, host)
if Service.FILES in services:
add_file_service(base_dir, host)
return building, services return building, services
...@@ -1185,8 +1220,8 @@ def user_menu(args): ...@@ -1185,8 +1220,8 @@ def user_menu(args):
# Ask for action # Ask for action
choice = qust.select("What do you want to do?", choices=[ choice = qust.select("What do you want to do?", choices=[
'Add a new user', 'Modify existing user', 'Exit'], 'Add a new user', 'Modify existing user', 'Exit'],
style=st).ask() style=st).ask()
if "Add" in choice: if "Add" in choice:
new_user_menu(base_dir) new_user_menu(base_dir)
elif "Modify" in choice: elif "Modify" in choice:
...@@ -1274,8 +1309,8 @@ def service_menu(args): ...@@ -1274,8 +1309,8 @@ def service_menu(args):
# Ask for action # Ask for action
choice = qust.select("What do you want to do?", choices=[ choice = qust.select("What do you want to do?", choices=[
'Modify existing services', 'Add additional service', 'Modify existing services', 'Add additional service',
'Exit'], style=st).ask() 'Exit'], style=st).ask()
if "Add" in choice: if "Add" in choice:
service_add_menu(base_dir) service_add_menu(base_dir)
elif "Modify" in choice: elif "Modify" in choice:
......
...@@ -227,6 +227,20 @@ services: ...@@ -227,6 +227,20 @@ services:
placement: placement:
constraints: constraints:
- node.role == manager - node.role == manager
files:
image: filebrowser/filebrowser
volumes:
- openhab_conf:/srv/openHAB
- nodered_data:/srv/Node-RED
networks:
- habnet
deploy:
labels:
- "traefik.port=80"
- "traefik.docker.network=habnet"
placement:
constraints:
- node.labels.building == X
zwave_oh: zwave_oh:
image: docker image: docker
command: "docker run --rm --name device_oh --network habnet -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro -v openhab_zwave_conf:/openhab/conf -v openhab_zwave_userdata:/openhab/userdata -p 9898:8080 openhab/openhab:2.4.0" command: "docker run --rm --name device_oh --network habnet -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro -v openhab_zwave_conf:/openhab/conf -v openhab_zwave_userdata:/openhab/userdata -p 9898:8080 openhab/openhab:2.4.0"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment