Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/utils/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ async def get_subscription_payload(token: str) -> dict | None:
sha256((u_token + await get_secret_key()).encode("utf-8")).digest(), altchars=b"-_"
).decode("utf-8")[:10]
if u_signature == u_token_resign:
u_username = u_token_dec_str.split(",")[0]
u_created_at = int(u_token_dec_str.split(",")[1])
return {"username": u_username, "created_at": datetime.fromtimestamp(u_created_at, tz=timezone.utc)}
parts = u_token_dec_str.split(",")
if len(parts) != 2:
return
u_username, u_created_at_str = parts
try:
u_created_at = int(u_created_at_str)
except ValueError:
return
return {
"username": u_username,
"created_at": datetime.fromtimestamp(u_created_at, tz=timezone.utc),
}
else:
return
except jwt.exceptions.PyJWTError:
Expand Down
4 changes: 3 additions & 1 deletion app/utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def get_public_ip():
except httpx.RequestError:
pass

sock = None
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(("8.8.8.8", 80))
Expand All @@ -79,7 +80,8 @@ def get_public_ip():
except (socket.error, IndexError):
pass
finally:
sock.close()
if sock:
sock.close()

return "127.0.0.1"

Expand Down
10 changes: 0 additions & 10 deletions cli/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ async def list_admins():
await admin_cli.list_admins(db)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
finally:
return


async def create_admin(username: str):
Expand All @@ -186,8 +184,6 @@ async def create_admin(username: str):
await admin_cli.create_admin(db, username)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
finally:
return


async def delete_admin(username: str):
Expand All @@ -198,8 +194,6 @@ async def delete_admin(username: str):
await admin_cli.delete_admin(db, username)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
finally:
return


async def modify_admin(username: str):
Expand All @@ -210,8 +204,6 @@ async def modify_admin(username: str):
await admin_cli.modify_admin(db, username)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
finally:
return


async def reset_admin_usage(username: str):
Expand All @@ -222,5 +214,3 @@ async def reset_admin_usage(username: str):
await admin_cli.reset_admin_usage(db, username)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
finally:
return
2 changes: 0 additions & 2 deletions cli/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,3 @@ async def show_status():
await system_cli.show_status(db)
except Exception as e:
console.print(f"[red]Error: {e}[/red]")
finally:
return