if domain == "" or reason == "" or reverse == "":
return fastapi.responses.RedirectResponse("/")
- info = None
- blocks = None
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/info.json")
- if domain == None and reason == None and reverse == None:
- info = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/info.json")
+ if not response.ok:
+ raise HTTPException(status_code=response.status_code, detail=response.text)
- if not info.ok:
- raise HTTPException(status_code=info.status_code, detail=info.text)
+ info = response.json()
+ blocks = None
- info = info.json()
- elif domain != None:
+ if domain != None:
blocks = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/index.json?domain={domain}")
elif reason != None:
blocks = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/index.json?reason={reason}")
blocks = blocks.json()
for block_level in blocks:
for block in blocks[block_level]:
- block["first_seen"] = datetime.utcfromtimestamp(block["first_seen"]).strftime('%Y-%m-%d %H:%M')
- block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime('%Y-%m-%d %H:%M')
+ block["first_seen"] = datetime.utcfromtimestamp(block["first_seen"]).strftime(config.get("timestamp_format"))
+ block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime(config.get("timestamp_format"))
return templates.TemplateResponse("index.html", {
"request": request,