diff --git a/app.py b/app.py index 3b4b3b8..f793990 100644 --- a/app.py +++ b/app.py @@ -31,6 +31,10 @@ logger = logging.getLogger(__name__) def log_page_view(page: str, user_agent: str = None): """Protokolliert Seitenaufrufe ohne IP-Adressen""" + # Zugriffe auf /stats nicht loggen, da sie die Statistiken verfälschen + if page == "stats": + return + timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') user_agent_clean = user_agent[:100] if user_agent else 'Unknown' logger.info(f"PAGE_VIEW: {page} | User-Agent: {user_agent_clean}") @@ -72,6 +76,9 @@ def get_statistics(): 'top_search_patterns': {} } + # Sammle alle relevanten Aktivitäten + all_activities = [] + try: # Aktuelle Log-Datei lesen log_file = logs_dir / 'app.log' @@ -84,6 +91,16 @@ def get_statistics(): if 'PAGE_VIEW: ' in line: page = line.split('PAGE_VIEW: ')[1].split(' |')[0] stats['page_views_by_page'][page] = stats['page_views_by_page'].get(page, 0) + 1 + + # PAGE_VIEW Einträge als Aktivität sammeln + timestamp = line.split(' - ')[0] if ' - ' in line else '' + if timestamp: + # /stats-Zugriffe aus den Aktivitäten filtern + if 'PAGE_VIEW: stats' not in line: + all_activities.append({ + 'timestamp': timestamp, + 'line': line.strip() + }) elif 'SEARCH:' in line: stats['total_searches'] += 1 @@ -102,12 +119,11 @@ def get_statistics(): pos_part = line.split('pos=\'')[1].split('\'')[0] if pos_part: stats['top_search_patterns'][pos_part] = stats['top_search_patterns'].get(pos_part, 0) + 1 - - # Letzte 10 Aktivitäten - if len(stats['recent_activity']) < 10: + + # SEARCH Einträge als Aktivität sammeln timestamp = line.split(' - ')[0] if ' - ' in line else '' if timestamp: - stats['recent_activity'].append({ + all_activities.append({ 'timestamp': timestamp, 'line': line.strip() }) @@ -124,6 +140,12 @@ def get_statistics(): stats['total_searches'] += 1 except Exception as e: logger.error(f"Fehler beim Lesen der Backup-Datei {backup_file}: {e}") + + # Neueste 10 Aktivitäten auswählen + if all_activities: + # Nach Timestamp sortieren (neueste zuerst) + all_activities.sort(key=lambda x: x['timestamp'], reverse=True) + stats['recent_activity'] = all_activities[:10] except Exception as e: logger.error(f"Fehler beim Lesen der Statistiken: {e}") diff --git a/cookies.txt b/cookies.txt new file mode 100644 index 0000000..9c436ed --- /dev/null +++ b/cookies.txt @@ -0,0 +1,5 @@ +# Netscape HTTP Cookie File +# https://curl.se/docs/http-cookies.html +# This file was generated by libcurl! Edit at your own risk. + +#HttpOnly_localhost FALSE / FALSE 0 session eyJfZmxhc2hlcyI6W3siIHQiOlsic3VjY2VzcyIsIkVyZm9sZ3JlaWNoIGFuZ2VtZWxkZXQhIl19XSwibG9nZ2VkX2luIjp0cnVlfQ.aK1WBQ.KYWoG-YM2oKOpNz-3XUSFpOQQHs diff --git a/stats_clean.html b/stats_clean.html new file mode 100644 index 0000000..9c33995 --- /dev/null +++ b/stats_clean.html @@ -0,0 +1,292 @@ + + +
+ + +