feat: 完整 Squid Web Manager 平台 - P0-P3 全功能

完整 Web 管理平台,涵盖:

P0 生产加固:
- 会话超时(空闲+绝对) + CSRF 防护 + 登录失败限流
- HTTPS/TLS 证书管理(自签生成/上传/删除/过期提醒)
- SSL Bump (HTTPS 透明代理) 可视化配置
- 配置文件 diff 预览 + 二次确认才写入
- 服务控制二次确认 + 操作期间按钮锁定

P1 运维能力:
- 日志轮转管理(logrotate) + 日志状态监控
- 告警规则(5xx/命中率/磁盘/客户端流量)
- 多 Squid 实例管理 + 一键切换
- squidclient mgr 实时性能指标
- 流量异常检测(突增/大文件/高频小包/新客户端)

P2 日志分析增强:
- 日志持久化到 SQLite + 历史时间范围查询
- 导出 CSV/JSON(日志/KPI/异常/审计)
- GeoIP 地图(Leaflet + ip-api.com 离线可选 GeoLite2)
- 每客户端 24h 趋势图
- 自定义 Squid logformat 解析器

P3 体验锦上添花:
- 暗/亮主题切换(cookie 持久化)
- WebSSH 终端(xterm.js + paramiko)
- 完整审计日志 + 用户管理

技术栈: Flask 3.0 + SQLAlchemy 2.0 + SQLite + Chart.js + Leaflet
总代码量: ~16500 行 (15 Python 模块 + 34 模板 + CSS)
路由数: 73
This commit is contained in:
Hermes Agent
2026-07-15 10:19:21 +08:00
commit 4a1d949e41
54 changed files with 16895 additions and 0 deletions
+115
View File
@@ -0,0 +1,115 @@
{% extends "base.html" %}
{% block title %}缓存对等 - Squid Manager{% endblock %}
{% block content %}
<div class="page-header">
<h1>🌐 缓存对等 (cache_peer)</h1>
<div class="page-actions">
<button onclick="document.getElementById('add-form').style.display='block'" class="btn btn-primary btn-small"> 添加 Peer</button>
</div>
</div>
<div class="card" id="add-form" style="display:none;">
<h3 class="card-title">添加 cache_peer</h3>
<form method="post">
<input type="hidden" name="_csrf" value="{{ csrf_token() }}">
<input type="hidden" name="action" value="add">
<div class="filter-grid">
<div class="form-group">
<label>主机 <span class="hint">*</span></label>
<input type="text" name="host" class="form-input" required placeholder="proxy2.example.com">
</div>
<div class="form-group">
<label>类型</label>
<select name="type" class="form-input">
{% for t in ['parent','sibling','multicast'] %}
<option value="{{ t }}">{{ t }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>HTTP 端口</label>
<input type="number" name="http_port" class="form-input" value="3128">
</div>
<div class="form-group">
<label>ICP 端口 <span class="hint">0=禁用</span></label>
<input type="number" name="icp_port" class="form-input" value="0">
</div>
<div class="form-group" style="grid-column: span 2;">
<label>额外选项</label>
<input type="text" name="options" class="form-input" placeholder="proxy-only no-query weight=10">
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">添加</button>
<button type="button" onclick="document.getElementById('add-form').style.display='none'" class="btn btn-secondary">取消</button>
</div>
</form>
</div>
<div class="card">
<form method="post">
<input type="hidden" name="_csrf" value="{{ csrf_token() }}">
<input type="hidden" name="action" value="save">
<p class="card-desc">共 {{ peers | length }} 个对等节点。</p>
<div class="table-scroll">
<table class="data-table">
<thead>
<tr>
<th>#</th>
<th>主机</th>
<th>类型</th>
<th>HTTP 端口</th>
<th>ICP 端口</th>
<th>选项</th>
<th>删除</th>
</tr>
</thead>
<tbody>
{% for p in peers %}
<tr>
<td>{{ loop.index }}
<input type="hidden" name="id[]" value="{{ loop.index }}">
</td>
<td><input type="text" name="host[]" value="{{ p.host }}" class="form-input"></td>
<td>
<select name="type[]" class="form-input">
{% for t in ['parent','sibling','multicast'] %}
<option value="{{ t }}" {% if p.type == t %}selected{% endif %}>{{ t }}</option>
{% endfor %}
</select>
</td>
<td><input type="number" name="http_port[]" value="{{ p.http_port }}" class="form-input"></td>
<td><input type="number" name="icp_port[]" value="{{ p.icp_port }}" class="form-input"></td>
<td><input type="text" name="options[]" value="{{ p.options | join(' ') }}" class="form-input"></td>
<td><button type="button" class="btn btn-danger btn-tiny" onclick="this.closest('tr').remove()">删除</button></td>
</tr>
{% endfor %}
{% if not peers %}
<tr><td colspan="7" class="empty-row">暂无对等节点</td></tr>
{% endif %}
</tbody>
</table>
</div>
{% if peers %}
<div class="form-actions">
<button type="submit" class="btn btn-primary">💾 保存</button>
</div>
{% endif %}
</form>
</div>
<div class="card">
<h3 class="card-title">📖 cache_peer 类型与选项</h3>
<ul>
<li><strong>parent</strong>: 父代理 - 找不到缓存时转发到此节点</li>
<li><strong>sibling</strong>: 兄弟节点 - 仅查询缓存,不转发请求</li>
<li><strong>multicast</strong>: 多播组</li>
</ul>
<p class="meta-text">常用选项: <code>proxy-only</code> (不缓存到本地)、
<code>no-query</code> (不发送 ICP 查询)、
<code>weight=N</code> (权重)、
<code>login=user:pass</code> (代理认证)、
<code>ssl</code> (SSL 连接)、
<code>round-robin</code> (轮询)</p>
</div>
{% endblock %}