chore: 项目定名为 workbuddy-portal,容器化并补齐文档体系
## 项目定名 - 目录 wb_usage_portal → workbuddy-portal - Python 包 wb_usage → workbuddy_portal(含 session cookie 名) - 界面品牌统一为 WorkBuddy Portal;项目标识收敛到 config 单一来源 ## 容器化 - Dockerfile:多阶段构建,依赖层与源码解耦;非 root(uid 1000);内置健康检查 - docker-compose.yml:单服务 + 绑定挂载 data/logs + 日志轮转 + TZ - docker/entrypoint.sh:幂等初始化 → exec serve(LF 行尾,已由 .gitattributes 锁定) - docker/healthcheck.py:纯标准库探活 /login(slim 镜像无 curl) - .dockerignore / .env.example;数据目录可用 WB_DATA_DIR 等环境变量覆盖 ## 文档 - docs/USER-GUIDE.md 用户使用手册(含 9 张真实界面截图) - docs/DEPLOYMENT.md 部署运维(Docker / 裸机 / 反代 / 备份 / 推 Gitea 注册表) - docs/ARCHITECTURE.md 架构与设计说明(含已知坑与红线、验证体系) - docs/API.md 接口参考(路径 / 参数 / 返回结构 / 错误码) - docs/FAQ.md 常见问题;docs/CHANGELOG.md 变更日志 ## 修复缺陷(8) 1. /records/export 必然 500:生成器在请求上下文销毁后才迭代,改用自建连接 2. 大屏页图表全白:相对路径把 echarts.min.js 解析成 /vendor/... → 404 3. /users 500:路由已注册但模板缺失 4. 明细页日期筛选失效:视图传 f.frm、模板读 f.from 5. 配置页维护按钮全死:调用了不存在的 WBU.bindMaint() 6. 审计只能看最近 40 条:LIMIT 写死 7. 明细页多跑一条无用 SELECT:day_list() 取了没人用 8. 登录页锁定阈值未从配置注入 ## 安全加固 - 新增 safe_next():拒绝 //evil.com 等协议相对 URL 的开放重定向 - 缺 CSRF 的写请求统一 400 - 默认开启云端 HTTPS 证书校验(ssl_verify=1);Cookie 是账号凭证 - 登录失败计数表加上限与 TTL - /logout 拆分为 POST(执行) + GET(仅提示),防 <img src=/logout> 静默退出 - settings 内部簿记键 slot:* 读写两侧过滤,不再从 /api/settings 泄漏 ## 内部质量与工具 - 设置项写时校验 + 读时兜底,杜绝「一个手滑的数字让采集整个跑不起来」 - 全局 ValueError → 400:手写 query string 不再暴露 500 页面 - CSV 导出改 csv.writer 流式写入(原手工拼串,字段含逗号会串列) - bundle 明细加 20000 上限并回传 recordsTotal/recordsTruncated,不静默丢数据 - tools/smoke.py 离线回归 99 项;tools/check_live.py 真实 HTTP 56 项 - tools/shots.py Playwright 逐页截图 + JS 报错收集 ## 验证 - compileall 通过;smoke 99/99;对容器实例 check_live 56/56;截图 0 JS 报错 - 容器内采集实测成功(trigger=startup 补跑:新增 11 条)
这个提交包含在:
@@ -0,0 +1,155 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}日志管理 · {{ project_title }}{% endblock %}
|
||||
{% block body %}
|
||||
|
||||
<div class="pagehead">
|
||||
<div>
|
||||
<h1>日志管理</h1>
|
||||
<p class="lead">采集逐次日志、应用运行日志与操作审计</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn" id="btnTail" type="button">刷新应用日志</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if detail %}
|
||||
<section class="card">
|
||||
<div class="cardhead">
|
||||
<h2>运行 #{{ detail.id }} 详情</h2>
|
||||
<a class="btn ghost sm" href="{{ url_for('views.logs') }}">收起</a>
|
||||
</div>
|
||||
<table class="kv">
|
||||
<tr><th>触发方式</th><td>{{ detail.trigger }}</td><th>状态</th>
|
||||
<td>
|
||||
{% if detail.status=='ok' %}<span class="tag ok">成功</span>
|
||||
{% elif detail.status=='warn' %}<span class="tag warn">有警告</span>
|
||||
{% elif detail.status=='running' %}<span class="tag info">进行中</span>
|
||||
{% else %}<span class="tag bad">失败</span>{% endif %}
|
||||
{% if detail.exit_code is not none %}<span class="tag mute">exit {{ detail.exit_code }}</span>{% endif %}
|
||||
</td></tr>
|
||||
<tr><th>开始</th><td class="mono">{{ detail.started_at }}</td><th>结束</th><td class="mono">{{ detail.finished_at or '—' }}</td></tr>
|
||||
<tr><th>同步区间</th><td colspan="3" class="mono">{{ detail.win_from or '—' }} ~ {{ detail.win_to or '' }}</td></tr>
|
||||
<tr><th>云端返回</th><td>{{ detail.fetched }}</td><th>新增 / 重复</th><td>{{ detail.added }} / {{ detail.dup }}</td></tr>
|
||||
<tr><th>入库总数</th><td>{{ detail.total }}</td><th>时间冲突</th><td>{{ detail.conflicts }}</td></tr>
|
||||
<tr><th>结论</th><td colspan="3">{{ detail.message or '—' }}</td></tr>
|
||||
</table>
|
||||
<pre class="logbox" style="margin-top:12px">{{ detail.detail or '(无日志)' }}</pre>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
<section class="card">
|
||||
<div class="cardhead">
|
||||
<h2>采集运行日志</h2>
|
||||
<div class="seg">
|
||||
<a href="{{ url_for('views.logs') }}" class="{{ 'on' if not status }}">全部</a>
|
||||
<a href="{{ url_for('views.logs', status='ok') }}" class="{{ 'on' if status=='ok' }}">成功</a>
|
||||
<a href="{{ url_for('views.logs', status='warn') }}" class="{{ 'on' if status=='warn' }}">警告</a>
|
||||
<a href="{{ url_for('views.logs', status='error') }}" class="{{ 'on' if status=='error' }}">失败</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tablewrap">
|
||||
<table class="tbl">
|
||||
<thead><tr><th>#</th><th>开始</th><th>触发</th><th>状态</th><th class="num">耗时</th>
|
||||
<th class="num">新增</th><th class="num">重复</th><th class="num">冲突</th><th>结论</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
{% for r in runs %}
|
||||
<tr>
|
||||
<td>{{ r.id }}</td>
|
||||
<td class="mono nowrap">{{ r.started_at[5:] if r.started_at else '—' }}</td>
|
||||
<td><span class="tag {{ 'info' if r.trigger=='schedule' else ('accent' if r.trigger=='startup' else 'mute') }}">{{ r.trigger }}</span></td>
|
||||
<td class="nowrap">
|
||||
{% if r.status=='ok' %}<span class="tag ok">成功</span>
|
||||
{% elif r.status=='warn' %}<span class="tag warn">有警告</span>
|
||||
{% elif r.status=='running' %}<span class="tag info">进行中</span>
|
||||
{% else %}<span class="tag bad">失败</span>{% endif %}
|
||||
</td>
|
||||
<td class="num">{{ ((r.duration_ms or 0) / 1000) | round(1) }}s</td>
|
||||
<td class="num">{{ r.added }}</td><td class="num">{{ r.dup }}</td>
|
||||
<td class="num">{% if r.conflicts %}<span class="tag warn">{{ r.conflicts }}</span>{% else %}0{% endif %}</td>
|
||||
<td>{{ r.message or '—' }}</td>
|
||||
<td><a href="{{ url_for('views.logs', run=r.id, status=status or none) }}">详情</a></td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="10" class="empty">暂无采集日志</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% if pages > 1 %}
|
||||
{# 翻页时保留 status/act,否则一翻页筛选条件就丢了 #}
|
||||
<div class="pager">
|
||||
{% if page > 1 %}<a href="{{ url_for('views.logs', page=page-1, status=status or none, act=act or none) }}">‹</a>{% endif %}
|
||||
{% for p in page_window %}
|
||||
{% if p == page %}<span class="cur">{{ p }}</span>
|
||||
{% else %}<a href="{{ url_for('views.logs', page=p, status=status or none, act=act or none) }}">{{ p }}</a>{% endif %}
|
||||
{% endfor %}
|
||||
{% if page < pages %}<a href="{{ url_for('views.logs', page=page+1, status=status or none, act=act or none) }}">›</a>{% endif %}
|
||||
<span class="meta">第 {{ page }} / {{ pages }} 页 · 共 {{ '{:,}'.format(total) }} 次</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
<div class="grid2">
|
||||
<section class="card">
|
||||
<div class="cardhead">
|
||||
<h2>应用日志</h2>
|
||||
<span class="hint" id="tailMeta"></span>
|
||||
</div>
|
||||
<pre class="logbox" id="appLog">正在加载 logs/app.log …</pre>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="cardhead">
|
||||
<h2>操作审计</h2>
|
||||
<span class="hint">共 {{ '{:,}'.format(atotal) }} 条 · 第 {{ apage }} / {{ apages }} 页</span>
|
||||
</div>
|
||||
{% if actions %}
|
||||
<div class="seg" style="margin-bottom:10px">
|
||||
<a href="{{ url_for('views.logs', status=status or none) }}" class="{{ 'on' if not act }}">全部</a>
|
||||
{% for a in actions[:6] %}
|
||||
<a href="{{ url_for('views.logs', act=a[0], status=status or none) }}"
|
||||
class="{{ 'on' if act==a[0] }}">{{ a[0] }} <span class="muted">{{ a[1] }}</span></a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="tablewrap scroll-y">
|
||||
<table class="tbl" id="auditTable">
|
||||
<thead><tr><th>时间</th><th>用户</th><th>动作</th><th>说明</th><th>IP</th></tr></thead>
|
||||
<tbody>
|
||||
{% for a in audits %}
|
||||
<tr><td class="mono nowrap">{{ a.at[5:] if a.at else '' }}</td>
|
||||
<td>{{ a.actor or '—' }}</td>
|
||||
<td><span class="tag mute">{{ a.action }}</span></td>
|
||||
<td>{{ a.detail or '—' }}</td><td class="mono">{{ a.ip or '' }}</td></tr>
|
||||
{% else %}
|
||||
<tr><td colspan="5" class="empty">暂无审计记录</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% if apages > 1 %}
|
||||
<div class="pager">
|
||||
{% if apage > 1 %}
|
||||
<a href="{{ url_for('views.logs', apage=apage-1, act=act or none, status=status or none) }}">‹</a>
|
||||
{% endif %}
|
||||
{% for p in apage_window %}
|
||||
{% if p == apage %}<span class="cur">{{ p }}</span>
|
||||
{% else %}<a href="{{ url_for('views.logs', apage=p, act=act or none, status=status or none) }}">{{ p }}</a>{% endif %}
|
||||
{% endfor %}
|
||||
{% if apage < apages %}
|
||||
<a href="{{ url_for('views.logs', apage=apage+1, act=act or none, status=status or none) }}">›</a>
|
||||
{% endif %}
|
||||
<span class="meta">共 {{ '{:,}'.format(atotal) }} 条</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
|
||||
<script>
|
||||
WBU.bindTail('#btnTail', '/logs/tail', '#appLog', '#tailMeta');
|
||||
</script>
|
||||
{% endblock %}
|
||||
在新工单中引用
屏蔽一个用户