Skip to content

Commit 8309477

Browse files
authored
Merge pull request #47 from iFargle/timezone-woes
Timezone woes
2 parents e18ae2c + 35c3c8b commit 8309477

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

Jenkinsfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pipeline {
33
label 'linux-x64'
44
}
55
environment {
6-
APP_VERSION = 'v0.5.5'
6+
APP_VERSION = 'v0.5.6'
77
HS_VERSION = "v0.20.0" // Version of Headscale this is compatible with
88
BUILD_DATE = ''
99
BUILDER_NAME = "multiarch"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "headscale-webui"
3-
version = "v0.5.5"
3+
version = "v0.5.6"
44
description = "A simple web UI for small-scale Headscale deployments."
55
authors = ["Albert Copeland <[email protected]>"]
66
license = "AGPL"

renderer.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ def thread_machine_content(machine, machine_content, idx):
235235
# machine = passed in machine information
236236
# content = place to write the content
237237

238+
app.logger.debug("Machine Information")
239+
app.logger.debug(str(machine))
240+
238241
url = headscale.get_url()
239242
api_key = headscale.get_api_key()
240243

241244
# Set the current timezone and local time
242-
timezone = pytz.timezone(os.environ["TZ"] if os.environ["TZ"] else "UTC")
243-
local_time = timezone.localize(datetime.now())
245+
timezone = pytz.timezone(os.environ["TZ"] if os.environ["TZ"] else "UTC")
246+
local_time = timezone.localize(datetime.now())
244247

245248
# Get the machines routes
246249
pulled_routes = headscale.get_machine_routes(url, api_key, machine["id"])
@@ -335,20 +338,27 @@ def thread_machine_content(machine, machine_content, idx):
335338
created_print = helper.pretty_print_duration(created_delta)
336339
created_time = str(created_local.strftime('%A %m/%d/%Y, %H:%M:%S'))+" "+str(timezone)+" ("+str(created_print)+")"
337340

338-
expiry_parse = parser.parse(machine["expiry"])
339-
expiry_local = expiry_parse.astimezone(timezone)
340-
expiry_delta = expiry_local - local_time
341-
expiry_print = helper.pretty_print_duration(expiry_delta, "expiry")
342-
343-
if str(expiry_local.strftime('%Y')) in ("0001", "9999", "0000"):
341+
# If there is no expiration date, we don't need to do any calculations:
342+
if machine["expiry"] != "0001-01-01T00:00:00Z":
343+
expiry_parse = parser.parse(machine["expiry"])
344+
expiry_local = expiry_parse.astimezone(timezone)
345+
expiry_delta = expiry_local - local_time
346+
expiry_print = helper.pretty_print_duration(expiry_delta, "expiry")
347+
if str(expiry_local.strftime('%Y')) in ("0001", "9999", "0000"):
348+
expiry_time = "No expiration date."
349+
elif int(expiry_local.strftime('%Y')) > int(expiry_local.strftime('%Y'))+2:
350+
expiry_time = str(expiry_local.strftime('%m/%Y'))+" "+str(timezone)+" ("+str(expiry_print)+")"
351+
else:
352+
expiry_time = str(expiry_local.strftime('%A %m/%d/%Y, %H:%M:%S'))+" "+str(timezone)+" ("+str(expiry_print)+")"
353+
354+
expiring_soon = True if int(expiry_delta.days) < 14 and int(expiry_delta.days) > 0 else False
355+
app.logger.debug("Machine: "+machine["name"]+" expires: "+str(expiry_local.strftime('%Y'))+" / "+str(expiry_delta.days))
356+
else:
344357
expiry_time = "No expiration date."
345-
elif int(expiry_local.strftime('%Y')) > int(expiry_local.strftime('%Y'))+2:
346-
expiry_time = str(expiry_local.strftime('%m/%Y'))+" "+str(timezone)+" ("+str(expiry_print)+")"
347-
else:
348-
expiry_time = str(expiry_local.strftime('%A %m/%d/%Y, %H:%M:%S'))+" "+str(timezone)+" ("+str(expiry_print)+")"
349-
app.logger.debug("Machine: "+machine["name"]+" expires: "+str(expiry_local.strftime('%Y'))+" / "+str(expiry_delta.days))
358+
expiring_soon = False
359+
app.logger.debug("Machine: "+machine["name"]+" has no expiration date")
360+
350361

351-
expiring_soon = True if int(expiry_delta.days) < 14 and int(expiry_delta.days) > 0 else False
352362
# Get the first 10 characters of the PreAuth Key:
353363
if machine["preAuthKey"]:
354364
preauth_key = str(machine["preAuthKey"]["key"])[0:10]

server.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
executor = Executor(app)
3131
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_prefix=1)
32+
app.logger.info("Headscale-WebUI Version: "+os.environ["APP_VERSION"]+" / "+os.environ["GIT_BRANCH"])
3233
app.logger.info("LOG LEVEL SET TO %s", str(LOG_LEVEL))
3334
app.logger.info("DEBUG STATE: %s", str(DEBUG_STATE))
3435

0 commit comments

Comments
 (0)