This commit is contained in:
2025-04-01 13:34:47 -04:00
parent 4327cdd858
commit 9d4b21b5ae
6 changed files with 30 additions and 12 deletions

Binary file not shown.

View File

@@ -2,16 +2,20 @@ from flask import Flask, redirect, url_for, render_template
from views.index_views import index
from views.user_views import user
from views.group_views import group
from config import app_config
from config import app_config as config_class
from database import init_app
import logging, os
from logging.handlers import RotatingFileHandler
# Instantiate config class
app_config = config_class()
app = Flask(__name__)
app.config.from_object(app_config)
init_app(app)
# Logging
if app.config.get('LOG_TO_FILE'):
log_file = app.config.get('LOG_FILE_PATH', '/app/logs/app.log')
os.makedirs(os.path.dirname(log_file), exist_ok=True)

View File

@@ -16,9 +16,14 @@ class Config:
OUI_API_LIMIT_PER_SEC = int(os.getenv('OUI_API_LIMIT_PER_SEC', '2'))
OUI_API_DAILY_LIMIT = int(os.getenv('OUI_API_DAILY_LIMIT', '10000'))
# Timezone
APP_TIMEZONE = os.getenv('APP_TIMEZONE', 'UTC')
TZ = pytz.timezone(APP_TIMEZONE)
# These get set in __init__
APP_TIMEZONE = 'UTC'
TZ = pytz.utc
def __init__(self):
tz_name = os.getenv('APP_TIMEZONE', 'UTC')
self.APP_TIMEZONE = tz_name
self.TZ = pytz.timezone(tz_name)
class DevelopmentConfig(Config):
"""Development configuration."""

View File

@@ -1,23 +1,31 @@
from flask import Blueprint, render_template, request, jsonify
from database import get_db
from pytz import timezone
from datetime import datetime
import requests
import requests, pytz
index = Blueprint('index', __name__)
OUI_API_URL = 'https://api.maclookup.app/v2/macs/{}'
import pytz # make sure it's imported if not already
def time_ago(dt):
from config import LOCAL_TZ
if not dt:
return "n/a"
tz_name = current_app.config.get('APP_TIMEZONE', 'UTC')
local_tz = current_app.config.get('TZ', pytz.utc)
# Only assign UTC tzinfo if naive
if dt.tzinfo is None:
dt = dt.replace(tzinfo=pytz.UTC)
local_dt = dt.astimezone(LOCAL_TZ)
dt = dt.replace(tzinfo=pytz.utc)
# Convert to app timezone
dt = dt.astimezone(local_tz)
now = datetime.now(local_tz)
diff = now - dt
now = datetime.now(LOCAL_TZ)
diff = now - local_dt
seconds = int(diff.total_seconds())
if seconds < 60:
return f"{seconds}s ago"
elif seconds < 3600:
@@ -28,6 +36,7 @@ def time_ago(dt):
return f"{seconds//86400}d{(seconds%86400)//3600}h ago"
def lookup_vendor(mac):
prefix = mac.replace(":", "").replace("-", "").upper()[:6]
db = get_db()