Initial commit: ToNav Personal Navigation Page
- Flask + SQLite 个人导航页系统 - 前台导航页(分类Tab、卡片展示) - 管理后台(服务管理、分类管理、健康检测) - 响应式设计 - Systemd 服务配置
This commit is contained in:
206
README.md
Normal file
206
README.md
Normal file
@@ -0,0 +1,206 @@
|
||||
# ToNav - 个人导航页系统
|
||||
|
||||
> 一个简洁实用的个人服务导航与健康管理平台
|
||||
|
||||
## 📋 项目概述
|
||||
|
||||
ToNav 是一个基于 Flask 的轻量级个人导航页系统,用于管理和展示内部服务,并提供服务健康状态监控功能。
|
||||
|
||||
## ✨ 核心功能
|
||||
|
||||
### 前台展示
|
||||
- 🎨 美观的服务导航页
|
||||
- 📱 响应式设计,支持移动端
|
||||
- 🔖 服务分类展示
|
||||
- ✅ 实时显示服务健康状态
|
||||
|
||||
### 管理后台
|
||||
- 🔐 安全登录系统(bcrypt 密码哈希)
|
||||
- 🛠️ 服务管理(增删改查)
|
||||
- 📁 分类管理
|
||||
- 🔄 服务启用/禁用切换
|
||||
- 🔍 手动健康检查触发
|
||||
- 🔑 管理员密码修改
|
||||
|
||||
### 健康监控
|
||||
- ⏱️ 后台定时健康检查(默认 60 秒)
|
||||
- 🚨 支持自定义健康检查 URL
|
||||
- ⏱️ 超时控制(默认 5 秒)
|
||||
- 📊 状态记录(在线/离线/超时/连接错误)
|
||||
|
||||
## 🏗️ 技术栈
|
||||
|
||||
| 技术 | 版本 | 用途 |
|
||||
|------|------|------|
|
||||
| Flask | 3.0.0 | Web 框架 |
|
||||
| requests | 2.31.0 | HTTP 请求(健康检查) |
|
||||
| SQLite | 内置 | 数据存储 |
|
||||
|
||||
## 📂 项目结构
|
||||
|
||||
```
|
||||
ToNav/
|
||||
├── app.py # 主应用入口
|
||||
├── config.py # 配置文件
|
||||
├── tonav.db # SQLite 数据库
|
||||
├── requirements.txt # Python 依赖
|
||||
├── templates/ # HTML 模板
|
||||
│ ├── base.html # 基础模板
|
||||
│ ├── index.html # 前台导航页
|
||||
│ └── admin/ # 管理后台
|
||||
│ ├── login.html # 登录页
|
||||
│ ├── dashboard.html # 仪表盘
|
||||
│ ├── services.html # 服务管理
|
||||
│ └── categories.html # 分类管理
|
||||
├── static/ # 静态资源
|
||||
└── utils/ # 工具模块
|
||||
├── auth.py # 认证模块
|
||||
├── database.py # 数据库操作
|
||||
└── health_check.py # 健康检查
|
||||
```
|
||||
|
||||
## 🗄️ 数据库结构
|
||||
|
||||
### services 表
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | INTEGER | 自增主键 |
|
||||
| name | VARCHAR(100) | 服务名称 |
|
||||
| url | VARCHAR(500) | 服务地址 |
|
||||
| description | TEXT | 服务描述 |
|
||||
| icon | VARCHAR(50) | 图标 |
|
||||
| category | VARCHAR(50) | 所属分类 |
|
||||
| is_enabled | INTEGER | 是否启用 (1/0) |
|
||||
| sort_order | INTEGER | 排序 |
|
||||
| health_check_url | VARCHAR(500) | 健康检查地址 |
|
||||
| health_check_enabled | INTEGER | 是否启用健康检查 |
|
||||
| created_at | TIMESTAMP | 创建时间 |
|
||||
| updated_at | TIMESTAMP | 更新时间 |
|
||||
|
||||
### categories 表
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | INTEGER | 自增主键 |
|
||||
| name | VARCHAR(50) | 分类名称 |
|
||||
| sort_order | INTEGER | 排序 |
|
||||
|
||||
### users 表
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | INTEGER | 自增主键 |
|
||||
| username | VARCHAR(50) | 用户名 |
|
||||
| password_hash | VARCHAR(255) | 密码哈希 |
|
||||
| created_at | TIMESTAMP | 创建时间 |
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
### 1. 安装依赖
|
||||
```bash
|
||||
cd ToNav
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 2. 启动服务
|
||||
```bash
|
||||
python3 app.py
|
||||
```
|
||||
|
||||
### 3. 访问应用
|
||||
- 前台导航页: http://127.0.0.1:9519
|
||||
- 管理后台: http://127.0.0.1:9519/admin
|
||||
- 默认账号: `admin`
|
||||
- 默认密码: `tonav123`
|
||||
|
||||
## ⚙️ 配置说明
|
||||
|
||||
编辑 `config.py` 可调整以下配置:
|
||||
|
||||
```python
|
||||
# 服务监听地址和端口
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 9519
|
||||
DEBUG = False
|
||||
|
||||
# 健康检查配置
|
||||
HEALTH_CHECK_INTERVAL = 60 # 检测间隔(秒)
|
||||
HEALTH_CHECK_TIMEOUT = 5 # 检测超时(秒)
|
||||
|
||||
# Flask 密钥
|
||||
SECRET_KEY = 'tonav-secret-key-change-in-production-2026'
|
||||
```
|
||||
|
||||
## 📡 API 接口
|
||||
|
||||
### 前台 API
|
||||
- `GET /api/services` - 获取所有启用的服务
|
||||
- `GET /api/categories` - 获取所有分类
|
||||
|
||||
### 后台 API
|
||||
- `POST /api/admin/login` - 登录
|
||||
- `GET /api/admin/login/status` - 检查登录状态
|
||||
- `GET /api/admin/services` - 获取所有服务
|
||||
- `POST /api/admin/services` - 创建服务
|
||||
- `PUT /api/admin/services/<id>` - 更新服务
|
||||
- `DELETE /api/admin/services/<id>` - 删除服务
|
||||
- `POST /api/admin/services/<id>/toggle` - 切换服务状态
|
||||
- `GET /api/admin/categories` - 获取所有分类
|
||||
- `POST /api/admin/categories` - 创建分类
|
||||
- `PUT /api/admin/categories/<id>` - 更新分类
|
||||
- `DELETE /api/admin/categories/<id>` - 删除分类
|
||||
- `POST /api/admin/health-check` - 手动触发健康检查
|
||||
- `POST /api/admin/change-password` - 修改密码
|
||||
|
||||
## 📊 当前数据
|
||||
|
||||
### 已配置服务 (3 个)
|
||||
1. **违禁品查获排行榜** - http://127.0.0.1:9517
|
||||
- 描述: 实时数据统计 · 自动刷新
|
||||
- 图标: 📊
|
||||
- 健康检查: ✅ 启用
|
||||
|
||||
2. **短信接收端-Python** - http://127.0.0.1:9518
|
||||
- 描述: HTTP接口 + Web管理
|
||||
- 图标: 📱
|
||||
|
||||
3. **短信接收端-Go** - http://127.0.0.1:28001
|
||||
- 描述: 高性能版本 · 端口28001
|
||||
- 图标: 🔧
|
||||
|
||||
### 分类配置 (3 个)
|
||||
- 内网服务
|
||||
- 开发工具
|
||||
- 测试环境
|
||||
|
||||
## 🎯 使用场景
|
||||
|
||||
- 个人实验室/内网环境服务导航
|
||||
- 服务状态监控面板
|
||||
- 团队内部服务门户
|
||||
- 自建服务启动页
|
||||
|
||||
## 📝 注意事项
|
||||
|
||||
1. **生产环境部署**
|
||||
- 修改 `SECRET_KEY` 为随机字符串
|
||||
- 修改默认管理员密码
|
||||
- 使用反向代理(如 Nginx)
|
||||
- 启用 HTTPS
|
||||
|
||||
2. **健康检查**
|
||||
- 默认仅检查 HTTP 状态码 < 500
|
||||
- 超时服务会被标记为离线
|
||||
- 检查间隔建议不要小于 30 秒
|
||||
|
||||
3. **安全建议**
|
||||
- 限制 ADMIN 接口访问
|
||||
- 定期备份数据库
|
||||
- 使用强密码
|
||||
|
||||
## 📄 许可证
|
||||
|
||||
MIT License
|
||||
|
||||
---
|
||||
|
||||
**版本**: 1.0.0
|
||||
**更新时间**: 2026-02-12
|
||||
BIN
__pycache__/config.cpython-313.pyc
Normal file
BIN
__pycache__/config.cpython-313.pyc
Normal file
Binary file not shown.
436
app.py
Normal file
436
app.py
Normal file
@@ -0,0 +1,436 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""ToNav - 个人导航页系统"""
|
||||
|
||||
from flask import Flask, render_template, request, jsonify, session, redirect, url_for
|
||||
import sqlite3
|
||||
import json
|
||||
import os
|
||||
from config import Config
|
||||
from utils.auth import authenticate, is_logged_in, hash_password
|
||||
from utils.health_check import health_worker, check_all_services
|
||||
from utils.database import init_database, insert_initial_data
|
||||
|
||||
# 创建 Flask 应用
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
# 初始化数据库
|
||||
if not os.path.exists(Config.DATABASE_PATH):
|
||||
init_database()
|
||||
insert_initial_data()
|
||||
|
||||
# 启动健康检查线程
|
||||
health_worker.start()
|
||||
|
||||
# ==================== 数据库辅助函数 ====================
|
||||
|
||||
def get_db():
|
||||
"""获取数据库连接"""
|
||||
conn = sqlite3.connect(Config.DATABASE_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
# ==================== 前台导航页 ====================
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""前台导航页"""
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/api/services')
|
||||
def api_services():
|
||||
"""获取所有启用的服务"""
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT id, name, url, description, icon, category, sort_order,
|
||||
health_check_enabled
|
||||
FROM services
|
||||
WHERE is_enabled = 1
|
||||
ORDER BY sort_order DESC, id ASC
|
||||
''')
|
||||
|
||||
services = [dict(row) for row in cursor.fetchall()]
|
||||
conn.close()
|
||||
|
||||
return jsonify(services)
|
||||
|
||||
@app.route('/api/categories')
|
||||
def api_categories():
|
||||
"""获取所有分类"""
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT name, sort_order
|
||||
FROM categories
|
||||
ORDER BY sort_order DESC, id ASC
|
||||
''')
|
||||
|
||||
categories = [dict(row) for row in cursor.fetchall()]
|
||||
conn.close()
|
||||
|
||||
return jsonify(categories)
|
||||
|
||||
# ==================== 管理后台 ====================
|
||||
|
||||
@app.route('/admin')
|
||||
def admin_dashboard():
|
||||
"""管理后台首页"""
|
||||
if not is_logged_in(session):
|
||||
return redirect(url_for('admin_login'))
|
||||
|
||||
return render_template('admin/dashboard.html')
|
||||
|
||||
@app.route('/admin/login', methods=['GET', 'POST'])
|
||||
def admin_login():
|
||||
"""登录页"""
|
||||
if request.method == 'GET':
|
||||
return render_template('admin/login.html')
|
||||
|
||||
username = request.form.get('username', '')
|
||||
password = request.form.get('password', '')
|
||||
|
||||
user = authenticate(username, password)
|
||||
if user:
|
||||
session['user_id'] = user['id']
|
||||
session['username'] = user['username']
|
||||
return redirect(url_for('admin_dashboard'))
|
||||
|
||||
return render_template('admin/login.html', error='用户名或密码错误')
|
||||
|
||||
@app.route('/admin/logout')
|
||||
def admin_logout():
|
||||
"""退出登录"""
|
||||
session.clear()
|
||||
return redirect(url_for('admin_login'))
|
||||
|
||||
@app.route('/admin/services')
|
||||
def admin_services():
|
||||
"""服务管理页"""
|
||||
if not is_logged_in(session):
|
||||
return redirect(url_for('admin_login'))
|
||||
|
||||
return render_template('admin/services.html')
|
||||
|
||||
@app.route('/admin/categories')
|
||||
def admin_categories():
|
||||
"""分类管理页"""
|
||||
if not is_logged_in(session):
|
||||
return redirect(url_for('admin_login'))
|
||||
|
||||
return render_template('admin/categories.html')
|
||||
|
||||
# ==================== 后台 API ====================
|
||||
|
||||
@app.route('/api/admin/login/status')
|
||||
def api_login_status():
|
||||
"""检查登录状态"""
|
||||
if is_logged_in(session):
|
||||
return jsonify({'logged_in': True, 'username': session.get('username')})
|
||||
return jsonify({'logged_in': False})
|
||||
|
||||
@app.route('/api/admin/services', methods=['GET'])
|
||||
def api_admin_services():
|
||||
"""获取所有服务(包含禁用的)"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT id, name, url, description, icon, category, is_enabled,
|
||||
sort_order, health_check_url, health_check_enabled
|
||||
FROM services
|
||||
ORDER BY sort_order DESC, id ASC
|
||||
''')
|
||||
|
||||
services = [dict(row) for row in cursor.fetchall()]
|
||||
conn.close()
|
||||
|
||||
return jsonify(services)
|
||||
|
||||
@app.route('/api/admin/services', methods=['POST'])
|
||||
def api_admin_create_service():
|
||||
"""创建服务"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
data = request.get_json()
|
||||
required_fields = ['name', 'url']
|
||||
for field in required_fields:
|
||||
if not data.get(field):
|
||||
return jsonify({'error': f'缺少字段: {field}'}), 400
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO services (name, url, description, icon, category,
|
||||
is_enabled, sort_order, health_check_url,
|
||||
health_check_enabled)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (
|
||||
data['name'],
|
||||
data['url'],
|
||||
data.get('description', ''),
|
||||
data.get('icon', ''),
|
||||
data.get('category', '默认'),
|
||||
1 if data.get('is_enabled', True) else 0,
|
||||
data.get('sort_order', 0),
|
||||
data.get('health_check_url', ''),
|
||||
1 if data.get('health_check_enabled', False) else 0
|
||||
))
|
||||
|
||||
conn.commit()
|
||||
service_id = cursor.lastrowid
|
||||
conn.close()
|
||||
|
||||
return jsonify({'id': service_id, 'message': '创建成功'})
|
||||
|
||||
@app.route('/api/admin/services/<int:service_id>', methods=['PUT'])
|
||||
def api_admin_update_service(service_id):
|
||||
"""更新服务"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 动态构建更新语句
|
||||
fields = []
|
||||
values = []
|
||||
|
||||
for field in ['name', 'url', 'description', 'icon', 'category',
|
||||
'is_enabled', 'sort_order', 'health_check_url',
|
||||
'health_check_enabled']:
|
||||
if field in data:
|
||||
fields.append(f"{field} = ?")
|
||||
values.append(data[field])
|
||||
|
||||
if not fields:
|
||||
return jsonify({'error': '没有要更新的字段'}), 400
|
||||
|
||||
values.append(service_id)
|
||||
|
||||
cursor.execute(f'''
|
||||
UPDATE services
|
||||
SET {', '.join(fields)}, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?
|
||||
''', values)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return jsonify({'message': '更新成功'})
|
||||
|
||||
@app.route('/api/admin/services/<int:service_id>', methods=['DELETE'])
|
||||
def api_admin_delete_service(service_id):
|
||||
"""删除服务"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('DELETE FROM services WHERE id = ?', (service_id,))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return jsonify({'message': '删除成功'})
|
||||
|
||||
@app.route('/api/admin/services/<int:service_id>/toggle', methods=['POST'])
|
||||
def api_admin_toggle_service(service_id):
|
||||
"""切换服务启用状态"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
UPDATE services
|
||||
SET is_enabled = 1 - is_enabled
|
||||
WHERE id = ?
|
||||
''', (service_id,))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return jsonify({'message': '状态切换成功'})
|
||||
|
||||
# ==================== 分类管理 API ====================
|
||||
|
||||
@app.route('/api/admin/categories', methods=['GET'])
|
||||
def api_admin_categories():
|
||||
"""获取所有分类"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT id, name, sort_order
|
||||
FROM categories
|
||||
ORDER BY sort_order DESC, id ASC
|
||||
''')
|
||||
|
||||
categories = [dict(row) for row in cursor.fetchall()]
|
||||
conn.close()
|
||||
|
||||
return jsonify(categories)
|
||||
|
||||
@app.route('/api/admin/categories', methods=['POST'])
|
||||
def api_admin_create_category():
|
||||
"""创建分类"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
data = request.get_json()
|
||||
name = data.get('name', '').strip()
|
||||
|
||||
if not name:
|
||||
return jsonify({'error': '分类名称不能为空'}), 400
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
cursor.execute('''
|
||||
INSERT INTO categories (name, sort_order)
|
||||
VALUES (?, ?)
|
||||
''', (name, data.get('sort_order', 0)))
|
||||
|
||||
conn.commit()
|
||||
category_id = cursor.lastrowid
|
||||
conn.close()
|
||||
|
||||
return jsonify({'id': category_id, 'message': '创建成功'})
|
||||
except sqlite3.IntegrityError:
|
||||
conn.close()
|
||||
return jsonify({'error': '分类名称已存在'}), 400
|
||||
|
||||
@app.route('/api/admin/categories/<int:category_id>', methods=['PUT'])
|
||||
def api_admin_update_category(category_id):
|
||||
"""更新分类"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
data = request.get_json()
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
UPDATE categories
|
||||
SET name = ?, sort_order = ?
|
||||
WHERE id = ?
|
||||
''', (
|
||||
data.get('name', ''),
|
||||
data.get('sort_order', 0),
|
||||
category_id
|
||||
))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return jsonify({'message': '更新成功'})
|
||||
|
||||
@app.route('/api/admin/categories/<int:category_id>', methods=['DELETE'])
|
||||
def api_admin_delete_category(category_id):
|
||||
"""删除分类"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
# 检查是否有服务使用该分类
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT COUNT(*) FROM services
|
||||
WHERE category = (SELECT name FROM categories WHERE id = ?)
|
||||
''', (category_id,))
|
||||
|
||||
count = cursor.fetchone()[0]
|
||||
if count > 0:
|
||||
conn.close()
|
||||
return jsonify({'error': f'该分类下有 {count} 个服务,无法删除'}), 400
|
||||
|
||||
cursor.execute('DELETE FROM categories WHERE id = ?', (category_id,))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return jsonify({'message': '删除成功'})
|
||||
|
||||
# ==================== 健康检查 API ====================
|
||||
|
||||
@app.route('/api/admin/health-check', methods=['POST'])
|
||||
def api_admin_health_check():
|
||||
"""手动触发全量健康检查"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
results = check_all_services()
|
||||
return jsonify({'results': results})
|
||||
|
||||
# ==================== 系统设置 API ====================
|
||||
|
||||
@app.route('/api/admin/change-password', methods=['POST'])
|
||||
def api_admin_change_password():
|
||||
"""修改密码"""
|
||||
if not is_logged_in(session):
|
||||
return jsonify({'error': '未登录'}), 401
|
||||
|
||||
data = request.get_json()
|
||||
old_password = data.get('old_password', '')
|
||||
new_password = data.get('new_password', '')
|
||||
|
||||
if not old_password or not new_password:
|
||||
return jsonify({'error': '密码不能为空'}), 400
|
||||
|
||||
if len(new_password) < 6:
|
||||
return jsonify({'error': '新密码长度至少6位'}), 400
|
||||
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
user_id = session['user_id']
|
||||
|
||||
cursor.execute('''
|
||||
SELECT password_hash FROM users WHERE id = ?
|
||||
''', (user_id,))
|
||||
|
||||
row = cursor.fetchone()
|
||||
if not row or not is_logged_in(session):
|
||||
conn.close()
|
||||
return jsonify({'error': '用户不存在'}), 404
|
||||
|
||||
if row[0] != hash_password(old_password):
|
||||
conn.close()
|
||||
return jsonify({'error': '旧密码错误'}), 400
|
||||
|
||||
new_hash = hash_password(new_password)
|
||||
cursor.execute('''
|
||||
UPDATE users SET password_hash = ? WHERE id = ?
|
||||
''', (new_hash, user_id))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return jsonify({'message': '密码修改成功,请重新登录'})
|
||||
|
||||
# ==================== 主入口 ====================
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(
|
||||
host=Config.HOST,
|
||||
port=Config.PORT,
|
||||
debug=Config.DEBUG
|
||||
)
|
||||
24
config.py
Normal file
24
config.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""ToNav 配置文件"""
|
||||
|
||||
import os
|
||||
|
||||
class Config:
|
||||
"""基础配置"""
|
||||
# Flask 配置
|
||||
SECRET_KEY = os.environ.get('TONAV_SECRET_KEY') or 'tonav-secret-key-change-in-production-2026'
|
||||
|
||||
# 数据库配置
|
||||
DATABASE_PATH = os.path.join(os.path.dirname(__file__), 'tonav.db')
|
||||
|
||||
# 服务配置
|
||||
HOST = '127.0.0.1'
|
||||
PORT = 9519
|
||||
DEBUG = False
|
||||
|
||||
# 健康检查配置
|
||||
HEALTH_CHECK_INTERVAL = 60 # 检测间隔(秒)
|
||||
HEALTH_CHECK_TIMEOUT = 5 # 检测超时(秒)
|
||||
|
||||
# 分页配置
|
||||
ITEMS_PER_PAGE = 20
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Flask==3.0.0
|
||||
requests==2.31.0
|
||||
479
templates/admin/categories.html
Normal file
479
templates/admin/categories.html
Normal file
@@ -0,0 +1,479 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}分类管理 - ToNav{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container admin-layout">
|
||||
<!-- 顶部导航 -->
|
||||
<div class="admin-header">
|
||||
<div class="header-left">
|
||||
<h1>📂 分类管理</h1>
|
||||
<a href="/admin" class="back-link">← 返回首页</a>
|
||||
</div>
|
||||
<button class="btn btn-primary" onclick="showCreateModal()">+ 新建分类</button>
|
||||
</div>
|
||||
|
||||
<!-- 分类列表 -->
|
||||
<div class="categories-list">
|
||||
<div class="loading">加载中...</div>
|
||||
</div>
|
||||
|
||||
<!-- 创建/编辑弹窗 -->
|
||||
<div class="modal" id="categoryModal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2 id="modalTitle">新建分类</h2>
|
||||
<button class="close-btn" onclick="closeModal()">×</button>
|
||||
</div>
|
||||
<form id="categoryForm" class="modal-body">
|
||||
<input type="hidden" id="categoryId">
|
||||
|
||||
<div class="form-group">
|
||||
<label>分类名称 *</label>
|
||||
<input type="text" id="categoryName" class="input" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>排序权重</label>
|
||||
<input type="number" id="categorySort" class="input" value="0">
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn" onclick="closeModal()">取消</button>
|
||||
<button type="submit" class="btn btn-primary">保存</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--main-red: #ff4d4f;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
color: #fff;
|
||||
padding: 25px 30px;
|
||||
border-radius: 20px 20px 0 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-left h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
color: #8c8c8c;
|
||||
font-size: 13px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.back-link:hover {
|
||||
color: #bfbfbf;
|
||||
}
|
||||
|
||||
.categories-list {
|
||||
background: #fff;
|
||||
padding: 30px;
|
||||
border-radius: 0 0 20px 20px;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 12px;
|
||||
margin-bottom: 10px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.category-item:hover {
|
||||
background: #f0f0f0;
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.category-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.category-icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.category-meta {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.category-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.action-btn-sm {
|
||||
padding: 8px 14px;
|
||||
border: 1px solid #d9d9d9;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.action-btn-sm:hover {
|
||||
border-color: var(--main-red);
|
||||
color: var(--main-red);
|
||||
}
|
||||
|
||||
.action-btn-sm.danger:hover {
|
||||
background: #fff2f0;
|
||||
border-color: #ff4d4f;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
/* Modal */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.6);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
.modal.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: #fff;
|
||||
border-radius: 20px;
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
animation: slideUp 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from { transform: translateY(50px); opacity: 0; }
|
||||
to { transform: translateY(0); opacity: 1; }
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
padding: 20px 25px;
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-radius: 20px 20px 0 0;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #fff;
|
||||
font-size: 28px;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
background: rgba(255,255,255,0.2);
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
outline: none;
|
||||
border-color: var(--main-red);
|
||||
box-shadow: 0 0 0 3px rgba(255, 77, 79, 0.1);
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--main-red);
|
||||
color: #fff;
|
||||
box-shadow: 0 4px 15px rgba(255, 77, 79, 0.4);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #ff7875;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
let allCategories = [];
|
||||
let allServices = [];
|
||||
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadData();
|
||||
setupForm();
|
||||
});
|
||||
|
||||
// 加载数据
|
||||
async function loadData() {
|
||||
try {
|
||||
const [catResp, svcResp] = await Promise.all([
|
||||
fetch('/api/admin/categories'),
|
||||
fetch('/api/admin/services')
|
||||
]);
|
||||
|
||||
if (!catResp.ok) {
|
||||
window.location.href = '/admin/login';
|
||||
return;
|
||||
}
|
||||
|
||||
allCategories = await catResp.json();
|
||||
allServices = await svcResp.json();
|
||||
|
||||
renderCategories();
|
||||
} catch (err) {
|
||||
console.error('加载失败:', err);
|
||||
window.location.href = '/admin/login';
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染分类列表
|
||||
function renderCategories() {
|
||||
const container = document.querySelector('.categories-list');
|
||||
|
||||
if (allCategories.length === 0) {
|
||||
container.innerHTML = '<div class="empty-state">暂无分类</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '';
|
||||
allCategories.forEach(category => {
|
||||
const serviceCount = allServices.filter(s => s.category === category.name).length;
|
||||
|
||||
html += `
|
||||
<div class="category-item">
|
||||
<div class="category-info">
|
||||
<span class="category-icon">📂</span>
|
||||
<div>
|
||||
<span class="category-name">${category.name}</span>
|
||||
<span class="category-meta">${serviceCount} 个服务 · 排序 ${category.sort_order}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="category-actions">
|
||||
<button class="action-btn-sm" onclick="editCategory(${category.id})">编辑</button>
|
||||
<button class="action-btn-sm danger" onclick="deleteCategory(${category.id}, '${category.name}')">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
// 设置表单
|
||||
function setupForm() {
|
||||
document.getElementById('categoryForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
saveCategory();
|
||||
});
|
||||
}
|
||||
|
||||
// 显示创建弹窗
|
||||
function showCreateModal() {
|
||||
document.getElementById('modalTitle').textContent = '新建分类';
|
||||
document.getElementById('categoryId').value = '';
|
||||
document.getElementById('categoryForm').reset();
|
||||
document.getElementById('categorySort').value = '0';
|
||||
document.getElementById('categoryModal').classList.add('active');
|
||||
}
|
||||
|
||||
// 编辑分类
|
||||
function editCategory(id) {
|
||||
const category = allCategories.find(c => c.id === id);
|
||||
if (!category) return;
|
||||
|
||||
document.getElementById('modalTitle').textContent = '编辑分类';
|
||||
document.getElementById('categoryId').value = category.id;
|
||||
document.getElementById('categoryName').value = category.name;
|
||||
document.getElementById('categorySort').value = category.sort_order;
|
||||
|
||||
document.getElementById('categoryModal').classList.add('active');
|
||||
}
|
||||
|
||||
// 保存分类
|
||||
async function saveCategory() {
|
||||
const id = document.getElementById('categoryId').value;
|
||||
const data = {
|
||||
name: document.getElementById('categoryName').value.trim(),
|
||||
sort_order: parseInt(document.getElementById('categorySort').value) || 0
|
||||
};
|
||||
|
||||
if (!data.name) {
|
||||
alert('分类名称不能为空');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const url = id ? `/api/admin/categories/${id}` : '/api/admin/categories';
|
||||
const method = id ? 'PUT' : 'POST';
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: method,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
closeModal();
|
||||
loadData();
|
||||
} else {
|
||||
const result = await response.json();
|
||||
alert(result.error || '保存失败');
|
||||
}
|
||||
} catch (err) {
|
||||
alert('请求失败: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除分类
|
||||
async function deleteCategory(id, name) {
|
||||
const serviceCount = allServices.filter(s => s.category === name).length;
|
||||
if (serviceCount > 0) {
|
||||
alert(`该分类下有 ${serviceCount} 个服务,无法删除`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm(`确定要删除分类"${name}"吗?此操作不可恢复。`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/admin/categories/${id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
loadData();
|
||||
} else {
|
||||
const result = await response.json();
|
||||
alert(result.error || '删除失败');
|
||||
}
|
||||
} catch (err) {
|
||||
alert('请求失败: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeModal() {
|
||||
document.getElementById('categoryModal').classList.remove('active');
|
||||
}
|
||||
|
||||
// 点击外部关闭弹窗
|
||||
document.getElementById('categoryModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeModal();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
372
templates/admin/dashboard.html
Normal file
372
templates/admin/dashboard.html
Normal file
@@ -0,0 +1,372 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}ToNav 管理后台{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container admin-layout">
|
||||
<!-- 顶部导航 -->
|
||||
<div class="admin-header">
|
||||
<div class="header-left">
|
||||
<h1>🧭 ToNav 管理后台</h1>
|
||||
<span class="username" id="username">加载中...</span>
|
||||
</div>
|
||||
<button class="btn btn-primary" onclick="location.href='/admin/logout'">退出登录</button>
|
||||
</div>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<div class="main-content">
|
||||
<!-- 统计卡片 -->
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">📡</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value" id="totalServices">0</div>
|
||||
<div class="stat-label">总服务数</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">✅</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value" id="enabledServices">0</div>
|
||||
<div class="stat-label">已启用</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">📂</div>
|
||||
<div class="stat-info">
|
||||
<div class="stat-value" id="totalCategories">0</div>
|
||||
<div class="stat-label">分类数</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 快捷操作 -->
|
||||
<div class="quick-actions">
|
||||
<button class="action-btn" onclick="location.href='/admin/services'">
|
||||
<span class="action-icon">📡</span>
|
||||
<span class="action-label">服务管理</span>
|
||||
</button>
|
||||
<button class="action-btn" onclick="location.href='/admin/categories'">
|
||||
<span class="action-icon">📂</span>
|
||||
<span class="action-label">分类管理</span>
|
||||
</button>
|
||||
<button class="action-btn" onclick="runHealthCheck()">
|
||||
<span class="action-icon">🔍</span>
|
||||
<span class="action-label">健康检测</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 修改密码 -->
|
||||
<div class="settings-card">
|
||||
<h2>修改密码</h2>
|
||||
<form id="changePasswordForm">
|
||||
<div class="form-row">
|
||||
<input type="password" id="oldPassword" class="input" placeholder="旧密码" required>
|
||||
<input type="password" id="newPassword" class="input" placeholder="新密码(至少6位)" required minlength="6">
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button type="submit" class="btn btn-primary">修改密码</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.admin-layout {
|
||||
max-width: 900px;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
color: #fff;
|
||||
padding: 25px 30px;
|
||||
border-radius: 20px 20px 0 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-left h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
background: #fff;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: 30px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
padding: 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 15px;
|
||||
transition: all 0.3s;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
background: #f0f0f0;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
.stat-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 32px;
|
||||
font-weight: 800;
|
||||
color: var(--main-red);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.quick-actions {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
background: #fff;
|
||||
border: 2px solid #f0f0f0;
|
||||
border-radius: 15px;
|
||||
padding: 20px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
.action-btn:hover {
|
||||
border-color: var(--main-red);
|
||||
background: #fff2f0;
|
||||
transform: translateY(-3px);
|
||||
box-shadow: 0 4px 15px rgba(255, 77, 79, 0.2);
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.action-label {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.settings-card {
|
||||
background: #fff;
|
||||
padding: 30px;
|
||||
border-radius: 0 0 20px 20px;
|
||||
}
|
||||
|
||||
.settings-card h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 20px;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
outline: none;
|
||||
border-color: var(--main-red);
|
||||
box-shadow: 0 0 0 3px rgba(255, 77, 79, 0.1);
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--main-red);
|
||||
color: #fff;
|
||||
box-shadow: 0 4px 15px rgba(255, 77, 79, 0.4);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #ff7875;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.stats-grid,
|
||||
.quick-actions,
|
||||
.form-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.stat-card,
|
||||
.action-btn {
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadStats();
|
||||
loadUsername();
|
||||
});
|
||||
|
||||
// 加载用户名
|
||||
async function loadUsername() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/login/status');
|
||||
const data = await response.json();
|
||||
if (data.logged_in) {
|
||||
document.getElementById('username').textContent = data.username;
|
||||
} else {
|
||||
window.location.href = '/admin/login';
|
||||
}
|
||||
} catch (err) {
|
||||
window.location.href = '/admin/login';
|
||||
}
|
||||
}
|
||||
|
||||
// 加载统计数据
|
||||
async function loadStats() {
|
||||
try {
|
||||
const [servicesResp, categoriesResp] = await Promise.all([
|
||||
fetch('/api/admin/services'),
|
||||
fetch('/api/admin/categories')
|
||||
]);
|
||||
|
||||
const services = await servicesResp.json();
|
||||
const categories = await categoriesResp.json();
|
||||
|
||||
document.getElementById('totalServices').textContent = services.length;
|
||||
document.getElementById('enabledServices').textContent =
|
||||
services.filter(s => s.is_enabled).length;
|
||||
document.getElementById('totalCategories').textContent = categories.length;
|
||||
} catch (err) {
|
||||
console.error('加载统计失败:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// 健康检测
|
||||
async function runHealthCheck() {
|
||||
const btn = event.target.closest('.action-btn');
|
||||
const icon = btn.querySelector('.action-icon');
|
||||
const label = btn.querySelector('.action-label');
|
||||
|
||||
try {
|
||||
icon.textContent = '⏳';
|
||||
label.textContent = '检测中...';
|
||||
|
||||
const response = await fetch('/api/admin/health-check', {
|
||||
method: 'POST'
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.results) {
|
||||
const online = data.results.filter(r => r.status === 'online').length;
|
||||
const offline = data.results.filter(r => r.status === 'offline').length;
|
||||
alert(`检测完成:\n在线: ${online}\n离线: ${offline}`);
|
||||
}
|
||||
} catch (err) {
|
||||
alert('检测失败: ' + err.message);
|
||||
} finally {
|
||||
icon.textContent = '🔍';
|
||||
label.textContent = '健康检测';
|
||||
}
|
||||
}
|
||||
|
||||
// 修改密码
|
||||
document.getElementById('changePasswordForm').addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const oldPassword = document.getElementById('oldPassword').value;
|
||||
const newPassword = document.getElementById('newPassword').value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/change-password', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({old_password: oldPassword, new_password: newPassword})
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
alert('密码修改成功,请重新登录');
|
||||
this.reset();
|
||||
} else {
|
||||
alert(data.error || '修改失败');
|
||||
}
|
||||
} catch (err) {
|
||||
alert('请求失败: ' + err.message);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
140
templates/admin/login.html
Normal file
140
templates/admin/login.html
Normal file
@@ -0,0 +1,140 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ToNav 管理后台</title>
|
||||
<style>
|
||||
:root {
|
||||
--main-red: #ff4d4f;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "PingFang SC", -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.login-card {
|
||||
background: #fff;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
max-width: 400px;
|
||||
width: 90%;
|
||||
padding: 40px 30px;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: #262626;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 14px;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 10px;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: var(--main-red);
|
||||
box-shadow: 0 0 0 3px rgba(255, 77, 79, 0.1);
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--main-red);
|
||||
color: #fff;
|
||||
box-shadow: 0 4px 15px rgba(255, 77, 79, 0.4);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #ff7875;
|
||||
box-shadow: 0 6px 20px rgba(255, 77, 79, 0.5);
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #fff2f0;
|
||||
border: 1px solid #ffccc7;
|
||||
color: #ff4d4f;
|
||||
padding: 10px 15px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-card">
|
||||
<div class="header">
|
||||
<h1>🧭 ToNav</h1>
|
||||
<p>管理后台登录</p>
|
||||
</div>
|
||||
|
||||
{% if error %}
|
||||
<div class="error">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
||||
<form method="POST">
|
||||
<div class="form-group">
|
||||
<label for="username">用户名</label>
|
||||
<input type="text" id="username" name="username" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">密码</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">登 录</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
642
templates/admin/services.html
Normal file
642
templates/admin/services.html
Normal file
@@ -0,0 +1,642 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}服务管理 - ToNav{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container admin-layout">
|
||||
<!-- 顶部导航 -->
|
||||
<div class="admin-header">
|
||||
<div class="header-left">
|
||||
<h1>📡 服务管理</h1>
|
||||
<a href="/admin" class="back-link">← 返回首页</a>
|
||||
</div>
|
||||
<button class="btn btn-primary" onclick="showCreateModal()">+ 新建服务</button>
|
||||
</div>
|
||||
|
||||
<!-- 服务列表 -->
|
||||
<div class="services-list">
|
||||
<div class="loading">加载中...</div>
|
||||
</div>
|
||||
|
||||
<!-- 创建/编辑弹窗 -->
|
||||
<div class="modal" id="serviceModal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h2 id="modalTitle">新建服务</h2>
|
||||
<button class="close-btn" onclick="closeModal()">×</button>
|
||||
</div>
|
||||
<form id="serviceForm" class="modal-body">
|
||||
<input type="hidden" id="serviceId">
|
||||
|
||||
<div class="form-group">
|
||||
<label>服务名称 *</label>
|
||||
<input type="text" id="serviceName" class="input" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>访问URL *</label>
|
||||
<input type="url" id="serviceUrl" class="input" required placeholder="http://">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>描述</label>
|
||||
<input type="text" id="serviceDesc" class="input" placeholder="简短描述">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>图标(emoji)</label>
|
||||
<input type="text" id="serviceIcon" class="input" placeholder="📡">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>分类</label>
|
||||
<select id="serviceCategory" class="input">
|
||||
<option value="默认">默认</option>
|
||||
<option value="内网服务">内网服务</option>
|
||||
<option value="开发工具">开发工具</option>
|
||||
<option value="测试环境">测试环境</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label>排序权重</label>
|
||||
<input type="number" id="serviceSort" class="input" value="0">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>状态</label>
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" id="serviceEnabled" checked>
|
||||
<span>启用</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-divider">健康检测设置</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" id="healthCheckEnabled">
|
||||
<span>启用健康检测</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="healthUrlGroup" style="display: none;">
|
||||
<label>检测URL</label>
|
||||
<input type="url" id="healthCheckUrl" class="input" placeholder="留空则使用主URL">
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button type="button" class="btn" onclick="closeModal()">取消</button>
|
||||
<button type="submit" class="btn btn-primary">保存</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
:root {
|
||||
--main-red: #ff4d4f;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.admin-header {
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
color: #fff;
|
||||
padding: 25px 30px;
|
||||
border-radius: 20px 20px 0 0;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-left h1 {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.back-link {
|
||||
color: #8c8c8c;
|
||||
font-size: 13px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.back-link:hover {
|
||||
color: #bfbfbf;
|
||||
}
|
||||
|
||||
.services-list {
|
||||
background: #fff;
|
||||
padding: 30px;
|
||||
border-radius: 0 0 20px 20px;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.service-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
background: #fafafa;
|
||||
border-radius: 12px;
|
||||
margin-bottom: 15px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.service-item:hover {
|
||||
background: #f0f0f0;
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.service-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.service-icon-large {
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
.service-details {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.service-name {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.service-url {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.service-meta {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.tag {
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.service-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.action-btn-sm {
|
||||
padding: 8px 14px;
|
||||
border: 1px solid #d9d9d9;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.action-btn-sm:hover {
|
||||
border-color: var(--main-red);
|
||||
color: var(--main-red);
|
||||
}
|
||||
|
||||
.action-btn-sm.danger:hover {
|
||||
background: #fff2f0;
|
||||
border-color: #ff4d4f;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: #d9d9d9;
|
||||
}
|
||||
|
||||
.status-dot.enabled {
|
||||
background: #52c41a;
|
||||
}
|
||||
|
||||
/* Modal */
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0,0,0,0.6);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
.modal.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: #fff;
|
||||
border-radius: 20px;
|
||||
max-width: 600px;
|
||||
width: 90%;
|
||||
max-height: 85vh;
|
||||
overflow-y: auto;
|
||||
animation: slideUp 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from { transform: translateY(50px); opacity: 0; }
|
||||
to { transform: translateY(0); opacity: 1; }
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
padding: 20px 25px;
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #fff;
|
||||
font-size: 28px;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
background: rgba(255,255,255,0.2);
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 25px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.input, .input[type="text"], .input[type="url"], .input[type="number"], select.input {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
outline: none;
|
||||
border-color: var(--main-red);
|
||||
box-shadow: 0 0 0 3px rgba(255, 77, 79, 0.1);
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.form-divider {
|
||||
margin: 25px 0;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.checkbox-label input[type="checkbox"] {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 30px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--main-red);
|
||||
color: #fff;
|
||||
box-shadow: 0 4px 15px rgba(255, 77, 79, 0.4);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #ff7875;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
padding: 60px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.service-item {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.service-actions {
|
||||
width: 100%;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
let allServices = [];
|
||||
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadServices();
|
||||
setupForm();
|
||||
});
|
||||
|
||||
// 加载服务列表
|
||||
async function loadServices() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/services');
|
||||
if (!response.ok) {
|
||||
window.location.href = '/admin/login';
|
||||
return;
|
||||
}
|
||||
|
||||
allServices = await response.json();
|
||||
renderServices();
|
||||
} catch (err) {
|
||||
console.error('加载服务失败:', err);
|
||||
window.location.href = '/admin/login';
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染服务列表
|
||||
function renderServices() {
|
||||
const container = document.querySelector('.services-list');
|
||||
|
||||
if (allServices.length === 0) {
|
||||
container.innerHTML = '<div class="empty-state">暂无服务</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '';
|
||||
allServices.forEach(service => {
|
||||
html += `
|
||||
<div class="service-item">
|
||||
<div class="service-info">
|
||||
<span class="service-icon-large">${service.icon || '📡'}</span>
|
||||
<div class="service-details">
|
||||
<div class="service-name">
|
||||
${service.name}
|
||||
<span class="status-dot ${service.is_enabled ? 'enabled' : ''}"></span>
|
||||
</div>
|
||||
<div class="service-url">${service.url}</div>
|
||||
<div class="service-meta">
|
||||
<span class="tag">${service.category}</span>
|
||||
<span>排序: ${service.sort_order}</span>
|
||||
${service.health_check_enabled ? '<span>🔍 检测中</span>' : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="service-actions">
|
||||
<button class="action-btn-sm" onclick="editService(${service.id})">编辑</button>
|
||||
<button class="action-btn-sm" onclick="toggleService(${service.id})">
|
||||
${service.is_enabled ? '禁用' : '启用'}
|
||||
</button>
|
||||
<button class="action-btn-sm danger" onclick="deleteService(${service.id}, '${service.name}')">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
// 设置表单
|
||||
function setupForm() {
|
||||
// 健康检测URL显示/隐藏
|
||||
document.getElementById('healthCheckEnabled').addEventListener('change', function() {
|
||||
document.getElementById('healthUrlGroup').style.display = this.checked ? 'block' : 'none';
|
||||
});
|
||||
|
||||
// 表单提交
|
||||
document.getElementById('serviceForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
saveService();
|
||||
});
|
||||
}
|
||||
|
||||
// 显示创建弹窗
|
||||
function showCreateModal() {
|
||||
document.getElementById('modalTitle').textContent = '新建服务';
|
||||
document.getElementById('serviceId').value = '';
|
||||
document.getElementById('serviceForm').reset();
|
||||
document.getElementById('serviceEnabled').checked = true;
|
||||
document.getElementById('serviceSort').value = '0';
|
||||
document.getElementById('healthUrlGroup').style.display = 'none';
|
||||
document.getElementById('serviceModal').classList.add('active');
|
||||
}
|
||||
|
||||
// 编辑服务
|
||||
function editService(id) {
|
||||
const service = allServices.find(s => s.id === id);
|
||||
if (!service) return;
|
||||
|
||||
document.getElementById('modalTitle').textContent = '编辑服务';
|
||||
document.getElementById('serviceId').value = service.id;
|
||||
document.getElementById('serviceName').value = service.name;
|
||||
document.getElementById('serviceUrl').value = service.url;
|
||||
document.getElementById('serviceDesc').value = service.description || '';
|
||||
document.getElementById('serviceIcon').value = service.icon || '';
|
||||
document.getElementById('serviceCategory').value = service.category;
|
||||
document.getElementById('serviceSort').value = service.sort_order;
|
||||
document.getElementById('serviceEnabled').checked = service.is_enabled === 1;
|
||||
document.getElementById('healthCheckEnabled').checked = service.health_check_enabled === 1;
|
||||
document.getElementById('healthCheckUrl').value = service.health_check_url || '';
|
||||
document.getElementById('healthUrlGroup').style.display = service.health_check_enabled ? 'block' : 'none';
|
||||
|
||||
document.getElementById('serviceModal').classList.add('active');
|
||||
}
|
||||
|
||||
// 保存服务
|
||||
async function saveService() {
|
||||
const id = document.getElementById('serviceId').value;
|
||||
const data = {
|
||||
name: document.getElementById('serviceName').value,
|
||||
url: document.getElementById('serviceUrl').value,
|
||||
description: document.getElementById('serviceDesc').value,
|
||||
icon: document.getElementById('serviceIcon').value,
|
||||
category: document.getElementById('serviceCategory').value,
|
||||
sort_order: parseInt(document.getElementById('serviceSort').value) || 0,
|
||||
is_enabled: document.getElementById('serviceEnabled').checked ? 1 : 0,
|
||||
health_check_enabled: document.getElementById('healthCheckEnabled').checked ? 1 : 0,
|
||||
health_check_url: document.getElementById('healthCheckUrl').value
|
||||
};
|
||||
|
||||
try {
|
||||
const url = id ? `/api/admin/services/${id}` : '/api/admin/services';
|
||||
const method = id ? 'PUT' : 'POST';
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: method,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
closeModal();
|
||||
loadServices();
|
||||
} else {
|
||||
const result = await response.json();
|
||||
alert(result.error || '保存失败');
|
||||
}
|
||||
} catch (err) {
|
||||
alert('请求失败: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 切换服务状态
|
||||
async function toggleService(id) {
|
||||
if (!confirm('确定要切换服务状态吗?')) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/admin/services/${id}/toggle`, {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
loadServices();
|
||||
} else {
|
||||
alert('操作失败');
|
||||
}
|
||||
} catch (err) {
|
||||
alert('请求失败: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除服务
|
||||
async function deleteService(id, name) {
|
||||
if (!confirm(`确定要删除服务"${name}"吗?此操作不可恢复。`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/admin/services/${id}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
loadServices();
|
||||
} else {
|
||||
alert('删除失败');
|
||||
}
|
||||
} catch (err) {
|
||||
alert('请求失败: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeModal() {
|
||||
document.getElementById('serviceModal').classList.remove('active');
|
||||
}
|
||||
|
||||
// 点击外部关闭弹窗
|
||||
document.getElementById('serviceModal').addEventListener('click', function(e) {
|
||||
if (e.target === this) {
|
||||
closeModal();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
51
templates/base.html
Normal file
51
templates/base.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}ToNav - 个人导航页{% endblock %}</title>
|
||||
<style>
|
||||
:root {
|
||||
--main-red: #ff4d4f;
|
||||
--gold: #faad14;
|
||||
--silver: #76838b;
|
||||
--bronze: #d48806;
|
||||
--primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
--header-gradient: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "PingFang SC", -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
background: var(--primary-gradient);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
<script>
|
||||
// 全局状态
|
||||
window.currentTab = 'all';
|
||||
</script>
|
||||
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
335
templates/index.html
Normal file
335
templates/index.html
Normal file
@@ -0,0 +1,335 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}ToNav - 个人导航页{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<!-- 头部 -->
|
||||
<div class="header">
|
||||
<h1>🧭 ToNav</h1>
|
||||
<div class="subtitle">个人导航站</div>
|
||||
<div class="status-bar" id="statusBar">
|
||||
<span id="lastCheckTime">检测中...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 分类 Tabs -->
|
||||
<div class="tabs" id="categoryTabs">
|
||||
<button class="tab-btn active" data-category="all">全部</button>
|
||||
<button class="tab-btn" data-category="内网服务">内网服务</button>
|
||||
<button class="tab-btn" data-category="开发工具">开发工具</button>
|
||||
<button class="tab-btn" data-category="测试环境">测试环境</button>
|
||||
</div>
|
||||
|
||||
<!-- 服务卡片网格 -->
|
||||
<div class="services-grid" id="servicesGrid">
|
||||
<div class="loading">加载中...</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部 -->
|
||||
<div class="footer">
|
||||
<div>© 2026 ToNav - <a href="/admin">管理后台</a></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.header {
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
color: #fff;
|
||||
padding: 25px 20px;
|
||||
border-radius: 20px 20px 0 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
font-size: 12px;
|
||||
color: #595959;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
background: #262626;
|
||||
padding: 8px;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
flex: 1;
|
||||
padding: 12px 10px;
|
||||
color: #8c8c8c;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.tab-btn:hover {
|
||||
color: #bfbfbf;
|
||||
background: rgba(255,255,255,0.05);
|
||||
}
|
||||
|
||||
.tab-btn.active {
|
||||
color: #fff;
|
||||
background: var(--main-red);
|
||||
box-shadow: 0 4px 15px rgba(255, 77, 79, 0.4);
|
||||
}
|
||||
|
||||
.services-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: 15px;
|
||||
padding: 20px 0;
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.service-card {
|
||||
background: #fff;
|
||||
border-radius: 15px;
|
||||
padding: 20px;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
||||
animation: fadeInUp 0.5s ease backwards;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.service-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 8px 24px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
@keyframes fadeInUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.card-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.card-status {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
background: #d9d9d9;
|
||||
}
|
||||
|
||||
.card-status.online {
|
||||
background: #52c41a;
|
||||
box-shadow: 0 0 8px rgba(82, 196, 26, 0.5);
|
||||
}
|
||||
|
||||
.card-status.offline {
|
||||
background: #ff4d4f;
|
||||
box-shadow: 0 0 8px rgba(255, 77, 79, 0.5);
|
||||
}
|
||||
|
||||
.card-name {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.card-desc {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
font-size: 11px;
|
||||
color: #bfbfbf;
|
||||
}
|
||||
|
||||
.loading {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
padding: 60px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
grid-column: 1 / -1;
|
||||
text-align: center;
|
||||
padding: 60px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
color: #8c8c8c;
|
||||
padding: 20px;
|
||||
border-radius: 0 0 20px 20px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: var(--main-red);
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.footer a:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.services-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
font-size: 13px;
|
||||
padding: 10px 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
let allServices = [];
|
||||
let allCategories = [];
|
||||
let healthStatus = {}; // 存储健康状态
|
||||
|
||||
// 初始化
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadCategories();
|
||||
loadServices();
|
||||
setupTabs();
|
||||
});
|
||||
|
||||
// 加载分类
|
||||
async function loadCategories() {
|
||||
try {
|
||||
const response = await fetch('/api/categories');
|
||||
allCategories = await response.json();
|
||||
renderTabs();
|
||||
} catch (err) {
|
||||
console.error('加载分类失败:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// 加载服务
|
||||
async function loadServices() {
|
||||
try {
|
||||
const response = await fetch('/api/services');
|
||||
allServices = await response.json();
|
||||
renderServices(window.currentTab || 'all');
|
||||
updateLastCheckTime();
|
||||
} catch (err) {
|
||||
console.error('加载服务失败:', err);
|
||||
document.getElementById('servicesGrid').innerHTML =
|
||||
'<div class="loading">加载失败,请刷新页面</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染分类 Tabs
|
||||
function renderTabs() {
|
||||
const tabsContainer = document.getElementById('categoryTabs');
|
||||
let html = '<button class="tab-btn active" data-category="all">全部</button>';
|
||||
|
||||
allCategories.forEach(cat => {
|
||||
html += `<button class="tab-btn" data-category="${cat.name}">${cat.name}</button>`;
|
||||
});
|
||||
|
||||
tabsContainer.innerHTML = html;
|
||||
setupTabs();
|
||||
}
|
||||
|
||||
// 设置 Tab 点击事件
|
||||
function setupTabs() {
|
||||
document.querySelectorAll('.tab-btn').forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
const category = this.dataset.category;
|
||||
window.currentTab = category;
|
||||
|
||||
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
|
||||
renderServices(category);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 渲染服务卡片
|
||||
function renderServices(category) {
|
||||
const container = document.getElementById('servicesGrid');
|
||||
|
||||
const filteredServices = category === 'all'
|
||||
? allServices
|
||||
: allServices.filter(s => s.category === category);
|
||||
|
||||
if (filteredServices.length === 0) {
|
||||
container.innerHTML = '<div class="empty-state">暂无服务</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '';
|
||||
filteredServices.forEach((service, index) => {
|
||||
const status = healthStatus[service.id] || 'unknown';
|
||||
const statusClass = status === 'online' ? 'online' : (status === 'offline' ? 'offline' : '');
|
||||
|
||||
html += `
|
||||
<a href="${service.url}" target="_blank" class="service-card" style="animation-delay: ${index * 0.05}s">
|
||||
<div class="card-header">
|
||||
<span class="card-icon">${service.icon || '📡'}</span>
|
||||
<span class="card-status ${statusClass}"></span>
|
||||
</div>
|
||||
<div class="card-name">${service.name}</div>
|
||||
<div class="card-desc">${service.description || ''}</div>
|
||||
<div class="card-footer">${service.category}</div>
|
||||
</a>
|
||||
`;
|
||||
});
|
||||
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
// 更新最后检测时间
|
||||
function updateLastCheckTime() {
|
||||
const now = new Date();
|
||||
const timeStr = now.toLocaleDateString('zh-CN', {
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
});
|
||||
document.getElementById('lastCheckTime').textContent = `最后更新: ${timeStr}`;
|
||||
}
|
||||
|
||||
// 定时刷新(每30秒)
|
||||
setInterval(() => {
|
||||
loadServices();
|
||||
}, 30000);
|
||||
</script>
|
||||
{% endblock %}
|
||||
45
tonav-ctl.sh
Executable file
45
tonav-ctl.sh
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# ToNav 服务控制脚本
|
||||
|
||||
SERVICE_NAME="tonav"
|
||||
SCRIPT_DIR="/root/.openclaw/workspace/ToNav"
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
echo "启动 ToNav 服务..."
|
||||
systemctl start $SERVICE_NAME
|
||||
systemctl status $SERVICE_NAME --no-pager
|
||||
;;
|
||||
stop)
|
||||
echo "停止 ToNav 服务..."
|
||||
systemctl stop $SERVICE_NAME
|
||||
;;
|
||||
restart)
|
||||
echo "重启 ToNav 服务..."
|
||||
systemctl restart $SERVICE_NAME
|
||||
systemctl status $SERVICE_NAME --no-pager
|
||||
;;
|
||||
status)
|
||||
systemctl status $SERVICE_NAME --no-pager
|
||||
;;
|
||||
log)
|
||||
echo "显示日志 (最后 50 行):"
|
||||
tail -50 $SCRIPT_DIR/tonav.log
|
||||
;;
|
||||
logtail)
|
||||
echo "实时日志 (Ctrl+C 退出):"
|
||||
tail -f $SCRIPT_DIR/tonav.log
|
||||
;;
|
||||
enable)
|
||||
echo "设置开机自启..."
|
||||
systemctl enable $SERVICE_NAME
|
||||
;;
|
||||
disable)
|
||||
echo "取消开机自启..."
|
||||
systemctl disable $SERVICE_NAME
|
||||
;;
|
||||
*)
|
||||
echo "用法: $0 {start|stop|restart|status|log|logtail|enable|disable}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
429
tonav.log
Normal file
429
tonav.log
Normal file
@@ -0,0 +1,429 @@
|
||||
健康检查线程已启动
|
||||
* Serving Flask app 'app'
|
||||
* Debug mode: off
|
||||
[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||
* Running on http://127.0.0.1:9519
|
||||
[33mPress CTRL+C to quit[0m
|
||||
127.0.0.1 - - [12/Feb/2026 18:36:34] "GET / HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:36:35] "GET / HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:36:35] "GET /api/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:36:35] "GET /api/services HTTP/1.1" 200 -
|
||||
健康检查线程已启动
|
||||
[HealthCheck] 违禁品查获排行榜: offline
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
* Serving Flask app 'app'
|
||||
* Debug mode: off
|
||||
[31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||
* Running on http://127.0.0.1:9519
|
||||
[33mPress CTRL+C to quit[0m
|
||||
127.0.0.1 - - [12/Feb/2026 18:37:32] "GET / HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:37:32] "[32mGET /admin HTTP/1.1[0m" 302 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:27] "GET / HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:27] "GET /api/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:27] "GET /api/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:28] "GET / HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:28] "GET /api/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:28] "GET /api/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:32] "GET /admin HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:32] "GET /api/admin/login/status HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:32] "GET /api/admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:32] "GET /api/admin/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:39] "GET /admin HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:39] "GET /api/admin/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:39] "GET /api/admin/login/status HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:39] "GET /api/admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:45] "GET /admin HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:45] "GET /api/admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:45] "GET /api/admin/login/status HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:45] "GET /api/admin/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:47] "GET /admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:48] "GET /api/admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:57] "GET /admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:38:58] "GET /api/admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:39:03] "GET /admin/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:39:03] "GET /api/admin/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:39:03] "GET /api/admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:39:09] "GET /admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 18:39:10] "GET /api/admin/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 19:53:13] "[32mGET /admin/services HTTP/1.1[0m" 302 -
|
||||
127.0.0.1 - - [12/Feb/2026 19:53:13] "[33mGET /favicon.ico HTTP/1.1[0m" 404 -
|
||||
127.0.0.1 - - [12/Feb/2026 19:53:13] "GET /admin/login HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 19:53:20] "GET / HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 19:53:21] "GET /api/categories HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 19:53:21] "GET /api/services HTTP/1.1" 200 -
|
||||
127.0.0.1 - - [12/Feb/2026 19:53:53] "GET /api/services HTTP/1.1" 200 -
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online127.0.0.1 - - [12/Feb/2026 20:12:21] "GET /api/services HTTP/1.1" 200 -
|
||||
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
[HealthCheck] 违禁品查获排行榜: online
|
||||
[HealthCheck] 短信接收端-Go: online
|
||||
2
utils/__init__.py
Normal file
2
utils/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Utils package"""
|
||||
BIN
utils/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
utils/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/auth.cpython-313.pyc
Normal file
BIN
utils/__pycache__/auth.cpython-313.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/database.cpython-313.pyc
Normal file
BIN
utils/__pycache__/database.cpython-313.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/health_check.cpython-313.pyc
Normal file
BIN
utils/__pycache__/health_check.cpython-313.pyc
Normal file
Binary file not shown.
38
utils/auth.py
Normal file
38
utils/auth.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""认证工具"""
|
||||
|
||||
import hashlib
|
||||
import sqlite3
|
||||
from config import Config
|
||||
|
||||
def hash_password(password):
|
||||
"""密码哈希(SHA256,简单版)"""
|
||||
return hashlib.sha256(password.encode()).hexdigest()
|
||||
|
||||
def verify_password(password, stored_hash):
|
||||
"""验证密码"""
|
||||
return hash_password(password) == stored_hash
|
||||
|
||||
def authenticate(username, password):
|
||||
"""用户认证"""
|
||||
conn = sqlite3.connect(Config.DATABASE_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT id, username, password_hash FROM users
|
||||
WHERE username = ?
|
||||
''', (username,))
|
||||
|
||||
user = cursor.fetchone()
|
||||
conn.close()
|
||||
|
||||
if user and verify_password(password, user[2]):
|
||||
return {
|
||||
'id': user[0],
|
||||
'username': user[1]
|
||||
}
|
||||
return None
|
||||
|
||||
def is_logged_in(session):
|
||||
"""检查是否已登录"""
|
||||
return 'user_id' in session
|
||||
112
utils/database.py
Normal file
112
utils/database.py
Normal file
@@ -0,0 +1,112 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""数据库初始化脚本"""
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
from config import Config
|
||||
|
||||
def init_database():
|
||||
"""初始化数据库表"""
|
||||
db_path = Config.DATABASE_PATH
|
||||
|
||||
# 如果数据库已存在,先删除(可选,开发环境)
|
||||
if os.path.exists(db_path):
|
||||
print(f"数据库已存在: {db_path}")
|
||||
return
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 创建 services 表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS services (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
url VARCHAR(500) NOT NULL,
|
||||
description TEXT,
|
||||
icon VARCHAR(50),
|
||||
category VARCHAR(50) DEFAULT '默认',
|
||||
is_enabled INTEGER DEFAULT 1,
|
||||
sort_order INTEGER DEFAULT 0,
|
||||
health_check_url VARCHAR(500),
|
||||
health_check_enabled INTEGER DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
# 创建 categories 表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS categories (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name VARCHAR(50) NOT NULL UNIQUE,
|
||||
sort_order INTEGER DEFAULT 0
|
||||
)
|
||||
''')
|
||||
|
||||
# 创建 users 表
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
# 创建索引
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_services_category ON services(category)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_services_enabled ON services(is_enabled)')
|
||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_services_sort ON services(sort_order DESC)')
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print(f"数据库初始化完成: {db_path}")
|
||||
|
||||
def insert_initial_data():
|
||||
"""插入初始数据"""
|
||||
import hashlib
|
||||
|
||||
conn = sqlite3.connect(Config.DATABASE_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 创建默认管理员账号 (admin / admin123)
|
||||
# 使用 SHA256 简单哈希(生产环境建议用 bcrypt)
|
||||
password_hash = hashlib.sha256('admin123'.encode()).hexdigest()
|
||||
|
||||
cursor.execute('''
|
||||
INSERT INTO users (username, password_hash)
|
||||
VALUES (?, ?)
|
||||
''', ('admin', password_hash))
|
||||
|
||||
# 创建默认分类
|
||||
categories = [('内网服务', 1), ('开发工具', 2), ('测试环境', 3)]
|
||||
for name, sort_order in categories:
|
||||
cursor.execute('''
|
||||
INSERT OR IGNORE INTO categories (name, sort_order)
|
||||
VALUES (?, ?)
|
||||
''', (name, sort_order))
|
||||
|
||||
# 创建默认服务
|
||||
services = [
|
||||
('违禁品查获排行榜', 'http://127.0.0.1:9517', '实时数据统计 · 自动刷新', '📊', '内网服务', 1, 100, 'http://127.0.0.1:9517/api/rankings', 1),
|
||||
('短信接收端-Python', 'http://127.0.0.1:9518', 'HTTP接口 + Web管理', '📱', '内网服务', 1, 90, None, 0),
|
||||
('短信接收端-Go', 'http://127.0.0.1:28001', '高性能版本 · 端口28001', '🔧', '内网服务', 1, 80, 'http://127.0.0.1:28001/', 1),
|
||||
]
|
||||
|
||||
for service in services:
|
||||
cursor.execute('''
|
||||
INSERT INTO services (name, url, description, icon, category, is_enabled, sort_order, health_check_url, health_check_enabled)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', service)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print("初始数据插入完成")
|
||||
print("默认管理员账号: admin / admin123")
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_database()
|
||||
insert_initial_data()
|
||||
111
utils/health_check.py
Normal file
111
utils/health_check.py
Normal file
@@ -0,0 +1,111 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""健康检查工具"""
|
||||
|
||||
import requests
|
||||
import sqlite3
|
||||
import threading
|
||||
import time
|
||||
from config import Config
|
||||
|
||||
def check_service_health(service_id):
|
||||
"""检查单个服务健康状态"""
|
||||
conn = sqlite3.connect(Config.DATABASE_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT name, url, health_check_url, health_check_enabled
|
||||
FROM services
|
||||
WHERE id = ?
|
||||
''', (service_id,))
|
||||
|
||||
service = cursor.fetchone()
|
||||
if not service:
|
||||
conn.close()
|
||||
return
|
||||
|
||||
name, url, check_url, check_enabled = service
|
||||
check_url = check_url or url # 如果没有单独配置,使用主url
|
||||
|
||||
status = 'offline'
|
||||
status_code = None
|
||||
error = None
|
||||
|
||||
if check_enabled:
|
||||
try:
|
||||
response = requests.get(check_url, timeout=Config.HEALTH_CHECK_TIMEOUT)
|
||||
status_code = response.status_code
|
||||
if response.status_code < 500:
|
||||
status = 'online'
|
||||
except requests.exceptions.Timeout:
|
||||
error = 'timeout'
|
||||
except requests.exceptions.ConnectionError:
|
||||
error = 'connection_error'
|
||||
except Exception as e:
|
||||
error = str(e)
|
||||
|
||||
# 这里可以添加状态记录表,暂时只检查
|
||||
conn.close()
|
||||
|
||||
return {
|
||||
'id': service_id,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'status_code': status_code,
|
||||
'error': error
|
||||
}
|
||||
|
||||
def check_all_services():
|
||||
"""检查所有启用健康检测的服务"""
|
||||
conn = sqlite3.connect(Config.DATABASE_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT id FROM services
|
||||
WHERE is_enabled = 1 AND health_check_enabled = 1
|
||||
ORDER BY sort_order DESC
|
||||
''')
|
||||
|
||||
services = cursor.fetchall()
|
||||
conn.close()
|
||||
|
||||
results = []
|
||||
for (service_id,) in services:
|
||||
result = check_service_health(service_id)
|
||||
if result:
|
||||
results.append(result)
|
||||
|
||||
return results
|
||||
|
||||
class HealthCheckWorker:
|
||||
"""后台健康检查工作线程"""
|
||||
|
||||
def __init__(self):
|
||||
self.running = False
|
||||
self.thread = None
|
||||
|
||||
def start(self):
|
||||
"""启动后台检查"""
|
||||
if not self.running:
|
||||
self.running = True
|
||||
self.thread = threading.Thread(target=self._run, daemon=True)
|
||||
self.thread.start()
|
||||
print("健康检查线程已启动")
|
||||
|
||||
def stop(self):
|
||||
"""停止后台检查"""
|
||||
self.running = False
|
||||
if self.thread:
|
||||
self.thread.join()
|
||||
print("健康检查线程已停止")
|
||||
|
||||
def _run(self):
|
||||
"""检查循环"""
|
||||
while self.running:
|
||||
results = check_all_services()
|
||||
# 记录日志
|
||||
for result in results:
|
||||
print(f"[HealthCheck] {result['name']}: {result['status']}")
|
||||
time.sleep(Config.HEALTH_CHECK_INTERVAL)
|
||||
|
||||
# 全局工作线程
|
||||
health_worker = HealthCheckWorker()
|
||||
Reference in New Issue
Block a user