feat: add login authentication and certificate expiry notifications

- JWT-based login with ADMIN_USER/ADMIN_PASSWORD env config
- Login page with auth guard for Vue frontend
- Feishu bot webhook notification for expiring certificates
- SMTP email notification for expiring certificates
- Daily 8:00 AM cron for expiry checks
- Startup health check notification
This commit is contained in:
2026-07-23 16:25:02 +08:00
parent 1bb895fd67
commit 2d70a15307
17 changed files with 2813 additions and 66 deletions
+50 -13
View File
@@ -9,7 +9,8 @@
- ✅ HTTP-01(端口 80)和 DNS-01 验证方式
- ✅ 支持阿里云 DNS / Cloudflare / DNSPod
- ✅ Web 管理界面(仪表盘、证书列表、申请、查看、续期、删除)
-SQLite 数据存储
-**用户登录认证**JWT Token
-**证书到期通知**(飞书机器人和邮件)
- ✅ Docker 一键部署
## 快速开始
@@ -38,23 +39,59 @@ cd backend && go build -o autossl .
| 变量 | 默认值 | 说明 |
|------|--------|------|
| PORT | 8080 | Web 服务端口 |
| DB_PATH | ./data/autossl.db | SQLite 数据库路径 |
| DATA_DIR | ./data | 数据存储目录 |
| CERT_DIR | ./data/certs | 证书文件存储目录 |
| ACCOUNTS_DIR | ./data/accounts | ACME 账号存储目录 |
| ACME_PORT | 8082 | HTTP-01 挑战端口 |
| ADMIN_USER | admin | 管理员用户名 |
| ADMIN_PASSWORD | admin123 | 管理员密码 |
| JWT_SECRET | (内置默认值) | JWT 签名密钥(请务必在生产环境修改) |
| FEISHU_WEBHOOK_URL | - | 飞书机器人 Webhook 地址(用于证书到期通知) |
| SMTP_HOST | - | SMTP 服务器地址(用于邮件通知) |
| SMTP_PORT | - | SMTP 端口 |
| SMTP_USER | - | SMTP 用户名 |
| SMTP_PASSWORD | - | SMTP 密码 |
| SMTP_FROM | - | 发件人地址 |
| NOTIFY_TO | - | 收件人邮箱(多个用逗号分隔) |
## API 接口
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | /api/stats | 统计信息 |
| GET | /api/certificates | 证书列表 |
| GET | /api/certificates/:id | 证书详情 |
| POST | /api/certificates | 申请证书 |
| PUT | /api/certificates/:id | 更新证书配置 |
| DELETE | /api/certificates/:id | 删除证书 |
| POST | /api/certificates/:id/renew | 手动续期 |
| GET | /api/certificates/:id/files | 查看证书文件 |
| GET | /api/renewals/check | 触发续期检查 |
| 方法 | 路径 | 说明 | 需要认证 |
|------|------|------|---------|
| GET | /api/health | 健康检查 | 否 |
| POST | /api/login | 用户登录 | 否 |
| GET | /api/stats | 统计信息 | 是 |
| GET | /api/certificates | 证书列表 | 是 |
| GET | /api/certificates/:id | 证书详情 | 是 |
| POST | /api/certificates | 申请证书 | 是 |
| PUT | /api/certificates/:id | 更新证书配置 | 是 |
| DELETE | /api/certificates/:id | 删除证书 | 是 |
| POST | /api/certificates/:id/renew | 手动续期 | 是 |
| GET | /api/certificates/:id/files | 查看证书文件 | 是 |
| GET | /api/renewals/check | 触发续期检查 | 是 |
## 证书到期通知
系统支持两种通知方式:
### 飞书机器人
1. 在飞书群中添加 Webhook 机器人
2. 设置环境变量 `FEISHU_WEBHOOK_URL=https://open.feishu.cn/open-apis/bot/v2/hook/xxxxx`
### 邮件通知
设置 SMTP 相关环境变量:
```
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=user@example.com
SMTP_PASSWORD=your-password
SMTP_FROM=autossl@example.com
NOTIFY_TO=admin@example.com,ops@example.com
```
通知将在每天早上 8:00 自动检查并发送。30 天内到期的证书会触发通知。
## 证书文件位置