文件
workbuddy-portal/workbuddy_portal/web/templates/logs.html
T
wangchuanli 1bf961f6b3 feat(权限): 收敛普通账号写权限至本人凭证
将调度时刻、采集参数等实例级配置收归管理员,普通账号仅可维护本人 Cookie 与 User-Agent。
新增 config.writable_by 作为唯一写权限入口,set_setting 强制全局键落到 user_id=0,
消除「管理员改了只有自己生效」的静默缺陷。新增 tools/check_docs.py 文档自检,
smoke 断言扩至 215 项、check_live 扩至 122 项并支持普通账号越权验收,
忽略 backups/、data/*.bak* 与 legacy-v1/,版本升至 v1.3.0。
2026-09-18 08:46:00 +08:00

157 行
7.0 KiB
HTML
原始文件 Blame 文件历史

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
{% 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>状态</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>{{ r.uname }}</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="11" 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 %}