mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Implement compliance decryption package with HTML report, streamline audit and envelope routes
This commit is contained in:
@@ -0,0 +1,347 @@
|
||||
/* FromChat compliance bundle report styles (conversation-like, minimal JS) */
|
||||
|
||||
:root {
|
||||
--bg: #0b0f14;
|
||||
--panel: #0f1520;
|
||||
--panel-2: #121a27;
|
||||
--text: #e6edf3;
|
||||
--muted: #9aa7b2;
|
||||
--border: #223045;
|
||||
--accent: #4f7cff;
|
||||
--bubble-in: #131b28;
|
||||
--bubble-out: #1a2540;
|
||||
--shadow: rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.wrap {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 22px 14px 64px;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
backdrop-filter: blur(10px);
|
||||
background: rgba(11, 15, 20, 0.75);
|
||||
border-bottom: 1px solid rgba(34, 48, 69, 0.7);
|
||||
}
|
||||
|
||||
.topbar-inner {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 14px 14px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.brand-title {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
|
||||
.brand-subtitle {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.tools {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: min(420px, 55vw);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
padding: 9px 10px;
|
||||
color: var(--text);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.search:focus {
|
||||
border-color: rgba(79, 124, 255, 0.65);
|
||||
box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.18);
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.conversation {
|
||||
margin-top: 16px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--panel);
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 12px 28px var(--shadow);
|
||||
}
|
||||
|
||||
.conv-header {
|
||||
cursor: default;
|
||||
padding: 14px 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
border-bottom: 1px solid rgba(34, 48, 69, 0.65);
|
||||
}
|
||||
|
||||
.conv-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.conv-title .line1 {
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.conv-title .line2 {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.conv-meta {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.pill {
|
||||
border: 1px solid rgba(34, 48, 69, 0.9);
|
||||
border-radius: 999px;
|
||||
padding: 3px 8px;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.messages {
|
||||
padding: 12px 10px 14px;
|
||||
}
|
||||
|
||||
.day {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 12px 0 10px;
|
||||
}
|
||||
|
||||
.day span {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
border: 1px solid rgba(34, 48, 69, 0.8);
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.message-container {
|
||||
display: flex;
|
||||
margin: 8px 0;
|
||||
gap: 12px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.edit-tabs-vertical {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 80px;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.tab-vertical {
|
||||
padding: 6px 4px;
|
||||
cursor: pointer;
|
||||
border: 1px solid rgba(34, 48, 69, 0.6);
|
||||
border-radius: 6px;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
text-align: center;
|
||||
transition: background-color 0.15s ease;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1px;
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.tab-vertical:hover {
|
||||
background: rgba(79, 124, 255, 0.08);
|
||||
}
|
||||
|
||||
.tab-vertical.active {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.tab-label-vertical {
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.tab-time-vertical {
|
||||
font-size: 8px;
|
||||
opacity: 0.9;
|
||||
line-height: 1.1;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bubble-area {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.bubble {
|
||||
display: none;
|
||||
max-width: min(720px, 92%);
|
||||
border: 1px solid rgba(34, 48, 69, 0.9);
|
||||
border-radius: 16px;
|
||||
padding: 10px 10px 9px;
|
||||
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
|
||||
background: var(--bubble-in);
|
||||
border-top-left-radius: 6px;
|
||||
}
|
||||
|
||||
.bubble.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.bubble-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.who {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.who strong {
|
||||
color: var(--text);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.text {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-size: 14px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.msg-meta {
|
||||
margin-top: 8px;
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.msg-meta-left {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.msg-meta-right {
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.attachments {
|
||||
margin-top: 10px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.att {
|
||||
border: 1px solid rgba(34, 48, 69, 0.9);
|
||||
border-radius: 12px;
|
||||
padding: 10px;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.att-name {
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.thumb {
|
||||
width: 100%;
|
||||
max-height: 260px;
|
||||
object-fit: contain;
|
||||
border-radius: 10px;
|
||||
border: 1px solid rgba(34, 48, 69, 0.9);
|
||||
background: rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.att-actions {
|
||||
margin-top: 8px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.att-size {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
|
||||
.footer {
|
||||
margin-top: 18px;
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
padding: 10px 2px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/* Minimal JS for filtering messages in the static report. */
|
||||
|
||||
function normalizeText(s) {
|
||||
return (s || "").toString().toLowerCase();
|
||||
}
|
||||
|
||||
function filterReport(query) {
|
||||
const q = normalizeText(query).trim();
|
||||
const conversations = document.querySelectorAll(".conversation");
|
||||
let anyVisible = false;
|
||||
|
||||
conversations.forEach((conv) => {
|
||||
const rows = conv.querySelectorAll("[data-search]");
|
||||
let visibleInConv = 0;
|
||||
|
||||
rows.forEach((row) => {
|
||||
const hay = normalizeText(row.getAttribute("data-search"));
|
||||
const match = !q || hay.includes(q);
|
||||
row.classList.toggle("hidden", !match);
|
||||
if (match) visibleInConv += 1;
|
||||
});
|
||||
|
||||
const convMatch = visibleInConv > 0;
|
||||
conv.classList.toggle("hidden", !convMatch);
|
||||
if (convMatch) anyVisible = true;
|
||||
});
|
||||
|
||||
const hint = document.getElementById("filterHint");
|
||||
if (hint) {
|
||||
hint.textContent = q
|
||||
? (anyVisible ? "Filtered" : "No matches")
|
||||
: "Type to filter by text, user id, filename";
|
||||
}
|
||||
}
|
||||
|
||||
function setupEditHistoryTabs() {
|
||||
document.querySelectorAll(".edit-tabs-vertical").forEach((tabsContainer) => {
|
||||
const tabs = tabsContainer.querySelectorAll(".tab-vertical");
|
||||
|
||||
tabs.forEach((tab) => {
|
||||
tab.addEventListener("click", () => {
|
||||
const version = tab.getAttribute("data-version");
|
||||
const messageId = tab.getAttribute("data-message-id");
|
||||
|
||||
// Find the corresponding message container
|
||||
const messageContainer = document.querySelector(`.message-container:has([data-message-id="${messageId}"])`);
|
||||
if (!messageContainer) return;
|
||||
|
||||
// Update tab states within this message
|
||||
const allTabs = messageContainer.querySelectorAll(".tab-vertical");
|
||||
allTabs.forEach(t => t.classList.remove("active"));
|
||||
tab.classList.add("active");
|
||||
|
||||
// Update bubble states within this message
|
||||
const allBubbles = messageContainer.querySelectorAll(".bubble");
|
||||
allBubbles.forEach(bubble => {
|
||||
bubble.classList.toggle("active", bubble.getAttribute("data-version") === version);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function convertTimestampsToLocal() {
|
||||
// Convert all timestamps to local timezone
|
||||
document.querySelectorAll("[data-timestamp]").forEach((element) => {
|
||||
const timestamp = element.getAttribute("data-timestamp");
|
||||
if (!timestamp) return;
|
||||
|
||||
try {
|
||||
// Parse the ISO timestamp
|
||||
const date = new Date(timestamp.replace(" ", "T").replace("Z", "+00:00"));
|
||||
|
||||
// Format in local timezone
|
||||
const localTime = date.toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false
|
||||
});
|
||||
|
||||
// Update the displayed text
|
||||
element.textContent = localTime;
|
||||
} catch (e) {
|
||||
// If parsing fails, leave the original text
|
||||
console.warn("Failed to parse timestamp:", timestamp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const input = document.getElementById("searchInput");
|
||||
if (input) {
|
||||
input.addEventListener("input", (e) => {
|
||||
filterReport(e.target.value);
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize edit history tabs
|
||||
setupEditHistoryTabs();
|
||||
|
||||
// Convert timestamps to local timezone
|
||||
convertTimestampsToLocal();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any, Dict, Optional
|
||||
from urllib import error, request
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
def http_get_bytes(url: str, token: str, timeout_seconds: float = 30.0) -> bytes:
|
||||
req = request.Request(url, method="GET")
|
||||
req.add_header("Authorization", f"Bearer {token}")
|
||||
try:
|
||||
with request.urlopen(req, timeout=timeout_seconds) as r:
|
||||
return r.read()
|
||||
except error.HTTPError as e:
|
||||
body = e.read().decode("utf-8", errors="replace") if hasattr(e, "read") else ""
|
||||
raise RuntimeError(f"HTTP {e.code} for {url}: {body[:500]}")
|
||||
|
||||
|
||||
def http_get_json(url: str, token: str, timeout_seconds: float = 30.0) -> Dict[str, Any]:
|
||||
raw = http_get_bytes(url, token, timeout_seconds=timeout_seconds)
|
||||
try:
|
||||
return json.loads(raw.decode("utf-8"))
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to parse JSON from {url}: {e}")
|
||||
|
||||
|
||||
def http_post_json(
|
||||
url: str,
|
||||
body: Dict[str, Any],
|
||||
*,
|
||||
token: Optional[str] = None,
|
||||
timeout_seconds: float = 30.0,
|
||||
) -> Dict[str, Any]:
|
||||
payload = json.dumps(body, ensure_ascii=False).encode("utf-8")
|
||||
req = request.Request(url, method="POST", data=payload)
|
||||
req.add_header("Content-Type", "application/json")
|
||||
if token:
|
||||
req.add_header("Authorization", f"Bearer {token}")
|
||||
try:
|
||||
with request.urlopen(req, timeout=timeout_seconds) as r:
|
||||
raw = r.read()
|
||||
except error.HTTPError as e:
|
||||
body_txt = e.read().decode("utf-8", errors="replace") if hasattr(e, "read") else ""
|
||||
raise RuntimeError(f"HTTP {e.code} for {url}: {body_txt[:500]}")
|
||||
|
||||
try:
|
||||
return json.loads(raw.decode("utf-8"))
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to parse JSON from {url}: {e}")
|
||||
|
||||
|
||||
def join_api_url(api_base_url: str, path: str) -> str:
|
||||
"""
|
||||
Join an API base URL (usually ends with '/api') with a path that may start with:
|
||||
- '/api/...'
|
||||
- '/uploads/...'
|
||||
- 'uploads/...'
|
||||
"""
|
||||
base = api_base_url.rstrip("/")
|
||||
p = (path or "").strip()
|
||||
if p.startswith("http://") or p.startswith("https://"):
|
||||
return p
|
||||
|
||||
p_quoted = quote(p, safe="/:?&=%")
|
||||
|
||||
if p.startswith("/api/"):
|
||||
origin = base[:-4] if base.endswith("/api") else base
|
||||
return origin.rstrip("/") + p_quoted
|
||||
|
||||
if not p.startswith("/"):
|
||||
p_quoted = "/" + p_quoted
|
||||
return base + p_quoted
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
FromChat compliance decryption tool entrypoint.
|
||||
|
||||
Run:
|
||||
python scripts/compliance-decryption/main.py <command> ...
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> None:
|
||||
root_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
if root_dir not in sys.path:
|
||||
sys.path.insert(0, root_dir)
|
||||
|
||||
from cli import main as cli_main
|
||||
|
||||
cli_main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def assets_source_dir() -> Path:
|
||||
"""
|
||||
Directory that stores static templates (css/js) for report generation.
|
||||
|
||||
Layout:
|
||||
scripts/compliance-decryption/
|
||||
main.py
|
||||
assets/
|
||||
report.css
|
||||
report.js
|
||||
*.py
|
||||
"""
|
||||
root_dir = Path(__file__).resolve().parent
|
||||
return root_dir / "assets"
|
||||
|
||||
|
||||
def read_asset_text(name: str) -> str:
|
||||
path = assets_source_dir() / name
|
||||
return path.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def write_assets(output_dir: Path) -> tuple[str, str]:
|
||||
assets_dir = output_dir / "assets"
|
||||
assets_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
css_src = read_asset_text("report.css")
|
||||
js_src = read_asset_text("report.js")
|
||||
|
||||
css_rel = "assets/report.css"
|
||||
js_rel = "assets/report.js"
|
||||
|
||||
(assets_dir / "report.css").write_text(css_src, encoding="utf-8")
|
||||
(assets_dir / "report.js").write_text(js_src, encoding="utf-8")
|
||||
|
||||
return css_rel, js_rel
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from typing import Any, Dict
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
def safe_filename(name: str, max_len: int = 140) -> str:
|
||||
base = "".join(c for c in (name or "") if c.isalnum() or c in " ._-()[]{}").strip()
|
||||
base = base.replace(" ", " ")
|
||||
base = base.replace("/", "_").replace("\\", "_")
|
||||
if not base:
|
||||
base = "file"
|
||||
if len(base) > max_len:
|
||||
base = base[:max_len].rstrip()
|
||||
return base
|
||||
|
||||
|
||||
def html_escape(text: str) -> str:
|
||||
return (
|
||||
(text or "")
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace('"', """)
|
||||
.replace("'", "'")
|
||||
)
|
||||
|
||||
|
||||
def href_escape(rel_path: str) -> str:
|
||||
"""
|
||||
Percent-encode a relative path for use in HTML href/src.
|
||||
Keep slashes so nested paths work.
|
||||
"""
|
||||
return quote(rel_path, safe="/")
|
||||
|
||||
|
||||
def guess_is_image(filename: str) -> bool:
|
||||
ext = (os.path.splitext(filename or "")[1] or "").lower()
|
||||
return ext in {".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg"}
|
||||
|
||||
|
||||
def parse_message_plaintext(plaintext: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Best-effort parse of decrypted message JSON.
|
||||
|
||||
Returns:
|
||||
- kind: "json" | "text"
|
||||
- text: best-effort human-readable text
|
||||
- raw: original plaintext
|
||||
- json: parsed object (if kind=="json")
|
||||
"""
|
||||
raw = plaintext or ""
|
||||
try:
|
||||
obj = json.loads(raw)
|
||||
content = ""
|
||||
if isinstance(obj, dict):
|
||||
data = obj.get("data")
|
||||
if isinstance(data, dict):
|
||||
content_val = data.get("content")
|
||||
if isinstance(content_val, str):
|
||||
content = content_val
|
||||
return {"kind": "json", "text": content or raw, "raw": raw, "json": obj}
|
||||
except Exception:
|
||||
return {"kind": "text", "text": raw, "raw": raw}
|
||||
|
||||
Reference in New Issue
Block a user