feat: add history replay and work filters

This commit is contained in:
2026-09-07 12:09:49 +08:00
parent dafa335bb5
commit 07524a36cd
16 changed files with 1739 additions and 142 deletions
+25 -19
View File
@@ -1,6 +1,6 @@
"""Daily UTF-8 business logs; bounded UI history, no raw requests or message bodies."""
import hashlib
import json
import logging
import re
from collections import deque
@@ -11,20 +11,35 @@ from pathlib import Path
UI_LIMIT = 2000
CREDENTIAL = re.compile(
r"(?i)(cookie|authorization|sessionid|mstoken|a_bogus|password|token|secret|verifyfp|signature|x-bogus|x-tt-params)"
)
def clean(value):
text = str(value).replace("\r", r"\r").replace("\n", r"\n")
text = re.sub(r"[\x00-\x1f\x7f\u2028\u2029\u202a-\u202e]", " ", text)
text = re.sub(r"https?://\S+", "[地址已隐藏]", text)
text = re.sub(
r"(?i)\b(cookie|authorization|sessionid|msToken|a_bogus|password|token|secret)[\"']?\s*[:=].*",
"[敏感字段已隐藏]",
r"(?i)([?&](?:sessionid|mstoken|a_bogus|token|verifyfp|signature|x-bogus|x-tt-params)=)[^&\s]+",
r"\1[凭据已隐藏]",
text,
)
return text[:2000]
text = re.sub(
r"(?i)\b(cookie|authorization)[\"']?\s*[:=].*",
r"\1=[凭据已隐藏]",
text,
)
return text
def reference(value):
return "N" + hashlib.sha256(str(value).encode()).hexdigest()[:12]
def visible(value, key=""):
if CREDENTIAL.search(str(key)):
return "[凭据已隐藏]"
if isinstance(value, dict):
return {str(k): visible(v, k) for k, v in value.items()}
if isinstance(value, (list, tuple)):
return [visible(item) for item in value]
return value
def recent_lines(directory, limit=UI_LIMIT):
@@ -86,18 +101,9 @@ class DailyLog(logging.Handler):
for key, value in fields.items():
if value is None:
continue
if key.lower() in {
"text",
"body",
"cookie",
"headers",
"params",
"result",
"profile",
}:
value = "[已隐藏]"
elif not isinstance(value, (str, int, float, bool)):
value = "[复杂数据未记录]"
value = visible(value, key)
if not isinstance(value, (str, int, float, bool)):
value = json.dumps(value, ensure_ascii=False, default=str)
values.append(f"{clean(key)}={clean(value)}")
self.logger.log(
level, "[%s] %s %s", clean(stage), clean(message), " ".join(values)