Files
socks-manager/templates/connections.html
T
Your Name 0bd9bcac12 fix: 修复暗色主题UI对比度、端口占用死循环及多项Web表单bug
后端修复:
- engine/instances.py: Socks5Server.start() 端口占用时死循环, 增加超时和异常透传
- engine/instances.py: import time 移至顶层
- engine/instances.py: sync_instances/start_instance 容忍单实例启动失败
- run.py: 启动时 sync_instances 失败不退出进程
- web/routes.py: instances start/restart/edit 路由捕获 OSError, flash 友好提示
- api/v1.py: instances start/restart/update API 返回 JSON 错误而非 500 崩溃
- web/routes.py: toggle_user/ban_user 支持 hidden 字段语义, 缺字段时切换状态
- web/routes.py: inject_nav 增加独立 nav.dashboard 和 page_name, 修复双 active bug
- auth.py: login 路由添加 logging import, 修 NameError

前端重构:
- templates/base.html: 全局对比度提升(--text #f1f5f9, --accent #a5b4fc), 标题色显式声明, alert/modal/progress/table 完整暗色样式
- templates/base.html: main-content padding-top 修复 navbar 遮挡内容
- templates/base.html: 侧边栏 active 高亮 (白字 + elevated bg + 左边框)
- templates/base.html: 顶栏动态显示当前页面名
- templates/*.html: 统一 page-header 类, 所有图标按钮添加 title tooltip
- templates/users.html: toggle/ban 表单添加 hidden enabled/ban 字段
- templates/connections.html: fmtBytes 改为 Jinja macro, 时间格式化
- templates/dashboard.html: 时间格式化为 YYYY-MM-DD HH:MM:SS, chart canvas 高度调整
- templates/logs.html: 时间格式化为可读格式
- templates/stats.html: 提升 chart 颜色对比度
- templates/system.html: 使用 time.localtime() 显示本地时间
2026-07-16 23:01:39 +08:00

70 lines
2.2 KiB
HTML

{% extends "base.html" %}
{% block title %}活跃连接 · SOCKS Manager{% endblock %}
{% macro fmtBytes(b) -%}
{%- if not b %}0 B
{%- else -%}
{%- set u = ['B','KB','MB','GB','TB'] -%}
{%- set ns = namespace(v=b, i=0) -%}
{%- for _ in range(4) -%}
{%- if ns.v >= 1024 and ns.i < 4 -%}
{%- set ns.v = ns.v / 1024 -%}
{%- set ns.i = ns.i + 1 -%}
{%- endif -%}
{%- endfor -%}
{{ '%.1f'|format(ns.v) }} {{ u[ns.i] }}
{%- endif -%}
{%- endmacro %}
{% block content %}
<div class="page-header">
<h5><i class="bi bi-activity"></i> 活跃连接 <span class="text-muted small">({{ conns|length }} 条)</span></h5>
</div>
<div class="card">
<div class="card-body p-0">
<table class="table table-dark table-hover align-middle">
<thead>
<tr><th>ID</th><th>实例</th><th>用户</th><th>源地址</th><th>目标地址</th>
<th>协议</th><th>开始时间</th><th>入站</th><th>出站</th><th>操作</th></tr>
</thead>
<tbody>
{% for c in conns %}
<tr>
<td><code>{{ c.id[:12] }}</code></td>
<td>{{ c.instance }}</td>
<td>{{ c.username or '-' }}</td>
<td><code>{{ c.src }}</code></td>
<td><code>{{ c.dst }}</code></td>
<td><span class="badge badge-info">{{ c.protocol }}</span></td>
<td><small class="text-muted">{{ c.started[:19].replace('T',' ') if c.started else '-' }}</small></td>
<td>{{ fmtBytes(c.bytes_in) }}</td>
<td>{{ fmtBytes(c.bytes_out) }}</td>
<td>
<form method="post" style="display:inline"
onsubmit="return confirm('确认断开此连接?')">
<button class="btn btn-outline-danger btn-sm" type="submit">
<i class="bi bi-x-circle"></i> 断开</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if not conns %}
<div class="text-center py-5 text-muted">
<i class="bi bi-activity text-muted" style="font-size:2rem"></i>
<p>当前无活跃连接</p>
</div>
{% endif %}
</div>
</div>
{% endblock %}
{% block extra_script %}
<script>
// 每 5 秒刷新
setInterval(() => location.reload(), 5000);
</script>
{% endblock %}