Skip to content

Commit

Permalink
Merge pull request #47 from iFargle/timezone-woes
Browse files Browse the repository at this point in the history
Timezone woes
  • Loading branch information
iFargle authored Mar 17, 2023
2 parents e18ae2c + 35c3c8b commit 8309477
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <albert@sysctl.io>"]
license = "AGPL"
Expand Down
38 changes: 24 additions & 14 deletions renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 8309477

Please sign in to comment.