diff --git a/Jenkinsfile b/Jenkinsfile index da5560b..4ba119f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { label 'linux-x64' } environment { - APP_VERSION = 'v0.5.5' + APP_VERSION = 'v0.5.6' HS_VERSION = "v0.20.0" // Version of Headscale this is compatible with BUILD_DATE = '' BUILDER_NAME = "multiarch" diff --git a/pyproject.toml b/pyproject.toml index a148932..b335c4b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "headscale-webui" -version = "v0.5.5" +version = "v0.5.6" description = "A simple web UI for small-scale Headscale deployments." authors = ["Albert Copeland "] license = "AGPL" diff --git a/renderer.py b/renderer.py index b825b94..291a20e 100644 --- a/renderer.py +++ b/renderer.py @@ -235,12 +235,15 @@ def thread_machine_content(machine, machine_content, idx): # machine = passed in machine information # content = place to write the content + app.logger.debug("Machine Information") + app.logger.debug(str(machine)) + url = headscale.get_url() api_key = headscale.get_api_key() # Set the current timezone and local time - timezone = pytz.timezone(os.environ["TZ"] if os.environ["TZ"] else "UTC") - local_time = timezone.localize(datetime.now()) + timezone = pytz.timezone(os.environ["TZ"] if os.environ["TZ"] else "UTC") + local_time = timezone.localize(datetime.now()) # Get the machines routes pulled_routes = headscale.get_machine_routes(url, api_key, machine["id"]) @@ -335,20 +338,27 @@ def thread_machine_content(machine, machine_content, idx): created_print = helper.pretty_print_duration(created_delta) created_time = str(created_local.strftime('%A %m/%d/%Y, %H:%M:%S'))+" "+str(timezone)+" ("+str(created_print)+")" - expiry_parse = parser.parse(machine["expiry"]) - expiry_local = expiry_parse.astimezone(timezone) - expiry_delta = expiry_local - local_time - expiry_print = helper.pretty_print_duration(expiry_delta, "expiry") - - if str(expiry_local.strftime('%Y')) in ("0001", "9999", "0000"): + # If there is no expiration date, we don't need to do any calculations: + if machine["expiry"] != "0001-01-01T00:00:00Z": + expiry_parse = parser.parse(machine["expiry"]) + expiry_local = expiry_parse.astimezone(timezone) + expiry_delta = expiry_local - local_time + expiry_print = helper.pretty_print_duration(expiry_delta, "expiry") + if str(expiry_local.strftime('%Y')) in ("0001", "9999", "0000"): + expiry_time = "No expiration date." + elif int(expiry_local.strftime('%Y')) > int(expiry_local.strftime('%Y'))+2: + expiry_time = str(expiry_local.strftime('%m/%Y'))+" "+str(timezone)+" ("+str(expiry_print)+")" + else: + expiry_time = str(expiry_local.strftime('%A %m/%d/%Y, %H:%M:%S'))+" "+str(timezone)+" ("+str(expiry_print)+")" + + expiring_soon = True if int(expiry_delta.days) < 14 and int(expiry_delta.days) > 0 else False + app.logger.debug("Machine: "+machine["name"]+" expires: "+str(expiry_local.strftime('%Y'))+" / "+str(expiry_delta.days)) + else: expiry_time = "No expiration date." - elif int(expiry_local.strftime('%Y')) > int(expiry_local.strftime('%Y'))+2: - expiry_time = str(expiry_local.strftime('%m/%Y'))+" "+str(timezone)+" ("+str(expiry_print)+")" - else: - expiry_time = str(expiry_local.strftime('%A %m/%d/%Y, %H:%M:%S'))+" "+str(timezone)+" ("+str(expiry_print)+")" - app.logger.debug("Machine: "+machine["name"]+" expires: "+str(expiry_local.strftime('%Y'))+" / "+str(expiry_delta.days)) + expiring_soon = False + app.logger.debug("Machine: "+machine["name"]+" has no expiration date") + - expiring_soon = True if int(expiry_delta.days) < 14 and int(expiry_delta.days) > 0 else False # Get the first 10 characters of the PreAuth Key: if machine["preAuthKey"]: preauth_key = str(machine["preAuthKey"]["key"])[0:10] diff --git a/server.py b/server.py index acddb64..fc426c0 100644 --- a/server.py +++ b/server.py @@ -29,6 +29,7 @@ executor = Executor(app) app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1) +app.logger.info("Headscale-WebUI Version: "+os.environ["APP_VERSION"]+" / "+os.environ["GIT_BRANCH"]) app.logger.info("LOG LEVEL SET TO %s", str(LOG_LEVEL)) app.logger.info("DEBUG STATE: %s", str(DEBUG_STATE))