diff --git a/helper.py b/helper.py index fc6e6aa..d4eb95a 100644 --- a/helper.py +++ b/helper.py @@ -140,6 +140,11 @@ def startup_checks(): if os.access('/data/key.txt', os.W_OK): file_writable = True else: checks_passed = False + # Check 7: See if /etc/headscale/config.yaml is readable: + config_readable = False + if os.access('/etc/headscale/config.yaml', os.R_OK): config_readable = True + if os.access('/etc/headscale/config.yml', os.R_OK): config_readable = True + if checks_passed: return "Pass" messageHTML = "" @@ -153,6 +158,17 @@ def startup_checks(): """ messageHTML += format_error_message("Error", "Headscale unreachable", message) + + if not config_readable: + app.logger.error("Headscale configuration is not readable") + message = """ +

/etc/headscale/config.yaml not readable. Please ensure your + headscale configuration file resides in /etc/headscale and + is named "config.yaml" or "config.yml"

+ """ + + messageHTML += format_error_message("Error", "/etc/headscale/config.yaml not readable", message) + if not data_writable: app.logger.error("/data folder is not writable") message = """ @@ -163,7 +179,7 @@ def startup_checks(): messageHTML += format_error_message("Error", "/data not writable", message) if not data_readable: - app.logge.error("/data folder is not readable") + app.logger.error("/data folder is not readable") message = """

/data is not readable. Please ensure your permissions are correct. /data mount should be readable @@ -183,7 +199,7 @@ def startup_checks(): messageHTML += format_error_message("Error", "/data/key.txt not writable", message) if not file_readable: - app.logger.info("/data/key.txt is not readable") + app.logger.error("/data/key.txt is not readable") message = """

/data/key.txt is not readable. Please ensure your permissions are correct. /data mount should be readable diff --git a/renderer.py b/renderer.py index 986e1c6..d052258 100644 --- a/renderer.py +++ b/renderer.py @@ -20,6 +20,10 @@ def render_overview(): # Overview page will just read static information from the config file and display it # Open the config.yaml and parse it. + config_file = "" + except: config_file = open("/etc/headscale/config.yml", "r") + try: config_file = open("/etc/headscale/config.yaml", "r") + config_file = open("/etc/headscale/config.yaml", "r") config_yaml = yaml.safe_load(config_file) @@ -123,26 +127,29 @@ def render_overview(): """ - if config_yaml["derp"]["server"]: - derp_content = """ -

-
-
- Built-in DERP -

- - - - - - -
Enabled """+str(config_yaml["derp"]["server"]["enabled"]) +"""
Region ID """+str(config_yaml["derp"]["server"]["region_id"]) +"""
Region Code """+str(config_yaml["derp"]["server"]["region_code"]) +"""
Region Name """+str(config_yaml["derp"]["server"]["region_name"]) +"""
STUN Address """+str(config_yaml["derp"]["server"]["stun_listen_addr"]) +"""
-

+ derp_content = "" + if "derp" in config_yaml: + if "server" in config_yaml['derp"]: + derp_content = """ +
+
+
+ Built-in DERP +

+ + + + + + +
Enabled """+str(config_yaml["derp"]["server"]["enabled"]) +"""
Region ID """+str(config_yaml["derp"]["server"]["region_id"]) +"""
Region Code """+str(config_yaml["derp"]["server"]["region_code"]) +"""
Region Name """+str(config_yaml["derp"]["server"]["region_name"]) +"""
STUN Address """+str(config_yaml["derp"]["server"]["stun_listen_addr"]) +"""
+

+
-
- """ + """ + # TODO: # Whether there are custom DERP servers # If there are custom DERP servers, get the file location from the config file. Assume mapping is the same. # Whether the built-in DERP server is enabled @@ -196,21 +203,6 @@ def thread_machine_content(machine, machine_content, idx): pulled_routes = headscale.get_machine_routes(url, api_key, machine["id"]) routes = "" -# New format to parse: -# New JSON endpoint requires a machine_id and a route_id to toggle. -# Pass the following info: -# 1. Machine ID -# 2. Route ID (NEW REQ) -# 3. Route State (NEW REQ) - This would be the JSON key of pulled_routes["routes"][index][enabled] -# { -# "routes": [ -# { -# "id": "1", -# "prefix": "0.0.0.0/0", -# "advertised": true, -# "enabled": true, -# }, - # Test if the machine is an exit node: exit_node = False # If the LENGTH of "routes" is NULL/0, there are no routes, enabled or disabled: @@ -250,38 +242,6 @@ def thread_machine_content(machine, machine_content, idx):

""" routes = routes+"

" -# This entire thing will probably need to change after the new API endpoint change. -# Old code for v1.17.0 -# # Test if the machine is an exit node: -# exit_node = False -# # If there are ANY advertised routes, print them: -# if len(pulled_routes["routes"]["advertisedRoutes"]) > 0: -# routes = """ -#
  • -# directions -# Routes -#

    -# """ -# for advertised_route in pulled_routes["routes"]["advertisedRoutes"]: -# # Check if the route has been enabled. Red for False, Green for True -# route_enabled = "red" -# route_tooltip = 'enable' -# for enabled_route in pulled_routes["routes"]["enabledRoutes"]: -# if advertised_route == enabled_route: -# route_enabled = "green" -# route_tooltip = 'disable' -# if (advertised_route == "0.0.0.0/0" or advertised_route == "::/0") and route_enabled == "green": -# exit_node = True -# routes = routes+""" -#

    -# """+advertised_route+""" -#

    -# """ -# routes = routes+"

  • " # Get machine tags tag_array = ""