Files
lan-manager/docs/plan.md

68 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 局域网机器管理后台 — 实现计划
## 技术选型
| 层 | 技术 |
|---|---|
| 后端 | Go + Gin |
| 前端 | Vue 3 + Vite + Element Plus + AntV G6 |
| 数据库 | SQLite (modernc.org/sqlite纯 Go无需 CGO) |
| 认证 | 预设用户名密码 + Session/Cookie |
| SSH | golang.org/x/crypto/ssh仅密码认证 |
| Ping | `golang.org/x/net/icmp` + 系统 `/bin/ping` 命令回退 |
## 项目结构
```
lan-manager/
├── server/
│ ├── main.go # 入口
│ ├── config/ # 配置管理(支持配置文件 + 环境变量)
│ ├── models/ # 数据模型
│ ├── db/ # 数据库 + migration
│ ├── handlers/ # HTTP handlers
│ ├── services/ # 业务逻辑 (auth, ping, ssh, import/export)
│ └── middleware/ # CORS, 认证, 日志
├── web/ # Vue 前端
│ └── src/
├── scripts/
│ └── lan-manager.service # Systemd 服务示例
├── go.mod
├── go.sum
├── Makefile
└── README.md
```
## 实施步骤
### Phase 1: 后端基础
1. 初始化 Go 项目 + 依赖Gin, modernc.org/sqlite, crypto/ssh
2. 配置管理:支持配置文件 + 环境变量HOST/PORT/DB_PATH/ADMIN_USER/ADMIN_PASS 等)
3. SQLite 数据库 + 表创建(含 machines 扩展字段 cpu_info/memory_info/disk_info/uptime/listen_ports/ssh_synced_at
4. 数据模型定义
5. 基础 CRUD API (machines, services, relationships)
6. 认证模块:登录/登出/Session 中间件,区分访客和管理员权限
### Phase 2: 核心业务
7. Ping 定时检测服务1 分钟间隔Linux 上优先使用系统 ping 命令,避免权限问题
8. SSH 系统信息获取(仅密码认证,不保存凭据,单次有效),结果支持同步到机器记录
9. 操作日志中间件(记录增删改,含用户名)
10. 导入/导出 APIJSON 格式)
11. 健康检查接口 `/api/health`
### Phase 3: 前端
12. Vue 3 项目初始化 + Element Plus + 路由Vue Router
13. 登录页面
14. 机器列表页(访客:脱敏显示 IP/MAC/备注/关系)
15. 机器详情页(访客:隐藏敏感字段和 SSH 入口;管理员:完整功能)
16. 拓扑图页AntV G6仅管理员可访问
17. 操作日志页(仅管理员)
18. 导入/导出功能(仅管理员)
### Phase 4: 整合与部署
19. Go embed 打包前端静态文件 + 支持外置 `WEB_STATIC_PATH`
20. 编写 Makefile含 Linux amd64 交叉编译)
21. 编写 Systemd 服务示例脚本
22. 测试 + 修复
23. README 编写(含 Linux 部署说明)