@@ -0,0 +1,35 @@
|
||||
env:
|
||||
# 仓库配置
|
||||
GIT_SERVER: ${{ vars.GIT_SERVER }}
|
||||
GIT_REPOSITORY: zhangjie/servboard
|
||||
|
||||
# Docker 配置
|
||||
DOCKER_REGISTRY: ${{ vars.DOCKER_REGISTRY }}
|
||||
DOCKER_NAMESPACE: zhangjie
|
||||
DOCKER_IMAGE: servboard
|
||||
DOCKER_TAG: V1.0.0
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
自动构建并推送Docker镜像:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 检出代码
|
||||
run: |
|
||||
git clone "${GIT_SERVER}/${GIT_REPOSITORY}.git" /app/code
|
||||
|
||||
- name: 构建并推送 Docker 镜像
|
||||
working-directory: /app/code
|
||||
run: |
|
||||
IMAGE="${DOCKER_REGISTRY}/${DOCKER_NAMESPACE}/${DOCKER_IMAGE}:${DOCKER_TAG}"
|
||||
echo "📦 构建镜像:$IMAGE"
|
||||
docker build -t "$IMAGE" .
|
||||
echo "📤 推送镜像到 $DOCKER_REGISTRY"
|
||||
docker push "$IMAGE"
|
||||
echo "✅ 镜像推送成功:$IMAGE"
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy application code
|
||||
COPY app.py models.py .
|
||||
COPY templates/ templates/
|
||||
COPY static/ static/
|
||||
COPY data/ data/
|
||||
|
||||
# Create data directory with proper permissions
|
||||
RUN mkdir -p data/icons && chmod 755 data && chmod 755 data/icons && chmod +x data/servctl.sh
|
||||
|
||||
# Create startup script
|
||||
RUN echo '#!/bin/bash
|
||||
|
||||
# Check if database file exists
|
||||
if [ ! -f "/app/data/dashboard.db" ]; then
|
||||
echo "Creating default database..."
|
||||
# Run the application once to create the database
|
||||
python app.py &
|
||||
sleep 5
|
||||
pkill -f "python app.py"
|
||||
sleep 2
|
||||
echo "Database created successfully"
|
||||
fi
|
||||
|
||||
# Check if servctl.sh exists in data directory
|
||||
if [ ! -f "/app/data/servctl.sh" ]; then
|
||||
echo "Copying servctl.sh to data directory..."
|
||||
cp /app/servctl.sh /app/data/
|
||||
chmod +x /app/data/servctl.sh
|
||||
echo "servctl.sh copied successfully"
|
||||
fi
|
||||
|
||||
# Start the application
|
||||
echo "Starting Servboard..."
|
||||
python app.py' > /app/startup.sh && chmod +x /app/startup.sh
|
||||
|
||||
# Expose port
|
||||
EXPOSE 5000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/health')" || exit 1
|
||||
|
||||
# Start application using startup script
|
||||
CMD ["/app/startup.sh"]
|
||||
@@ -0,0 +1,136 @@
|
||||
# servboard
|
||||
|
||||
一个轻量级的服务导航仪表盘,用于管理本地Web服务。
|
||||
|
||||
## 功能
|
||||
|
||||
- **用户认证**:使用密码哈希(Werkzeug)的安全登录
|
||||
- **服务卡片**:为已启用的服务提供干净、响应式的网格布局
|
||||
- **智能URL生成**:支持反向代理场景,使用`X-Forwarded-Host`头
|
||||
- **路径支持**:服务可以有自定义路径,实现更灵活的路由
|
||||
- **SQLite数据库**:轻量级、基于文件的存储
|
||||
- **Docker支持**:现成的容器化部署
|
||||
- **服务管理工具**:命令行脚本,方便服务管理
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 使用Docker Compose(推荐)
|
||||
|
||||
```bash
|
||||
# 启动服务
|
||||
docker-compose up -d
|
||||
|
||||
# 访问地址:http://your-server-ip 或 http://your-domain
|
||||
# 默认凭据:admin / admin
|
||||
```
|
||||
|
||||
### 本地运行(开发)
|
||||
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv venv
|
||||
source venv/bin/activate # Windows: venv\Scripts\activate
|
||||
|
||||
# 安装依赖
|
||||
pip install -r requirements.txt
|
||||
|
||||
# 运行应用
|
||||
python app.py
|
||||
|
||||
# 访问地址:http://localhost:5000
|
||||
# 默认凭据:admin / admin
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
|
||||
| 变量 | 描述 | 默认值 |
|
||||
|------|------|--------|
|
||||
| `PORT` | 应用监听端口 | `5000` |
|
||||
| `SECRET_KEY` | Flask会话密钥 | `dev-secret-key-change-in-production` |
|
||||
|
||||
## 配置
|
||||
|
||||
### 添加服务
|
||||
|
||||
服务可以通过命令行工具或直接向数据库插入记录来添加。
|
||||
|
||||
#### 使用命令行工具(推荐)
|
||||
|
||||
`data`目录中的`servctl.sh`脚本提供了一种简单的服务管理方式:
|
||||
|
||||
```bash
|
||||
# 添加带路径的服务
|
||||
./data/servctl.sh -a "Nextcloud" "文件同步" 8080 http "☁️" "nextcloud"
|
||||
|
||||
# 添加不带路径的服务
|
||||
./data/servctl.sh -a "Jellyfin" "媒体服务器" 8096 http "🎬"
|
||||
|
||||
# 列出所有服务
|
||||
./data/servctl.sh -l
|
||||
|
||||
# 删除服务
|
||||
./data/servctl.sh -r "服务名称"
|
||||
|
||||
# 切换服务状态
|
||||
./data/servctl.sh -t "服务名称"
|
||||
```
|
||||
|
||||
#### 使用SQL
|
||||
|
||||
您也可以直接通过SQL添加服务:
|
||||
|
||||
```sql
|
||||
-- 带路径
|
||||
INSERT INTO services (name, description, port, protocol, enabled, icon, path)
|
||||
VALUES ('Nextcloud', '文件同步', 8080, 'http', true, '☁️', 'nextcloud');
|
||||
|
||||
-- 不带路径
|
||||
INSERT INTO services (name, description, port, protocol, enabled, icon)
|
||||
VALUES ('Jellyfin', '媒体服务器', 8096, 'http', true, '🎬');
|
||||
```
|
||||
|
||||
### 默认用户
|
||||
|
||||
首次运行时,会创建一个默认的管理员用户:
|
||||
- **用户名**:`admin`
|
||||
- **密码**:`admin`
|
||||
|
||||
**重要**:首次登录后请更改默认密码!
|
||||
|
||||
## 架构
|
||||
|
||||
```
|
||||
servboard/
|
||||
├── app.py # 主Flask应用,包含路由和模板
|
||||
├── models.py # 数据库模型(User, Service)
|
||||
├── requirements.txt # Python依赖项
|
||||
├── Dockerfile # 容器配置
|
||||
├── docker-compose.yml # Docker Compose配置
|
||||
├── data/ # SQLite数据库和服务管理工具
|
||||
│ ├── dashboard.db # SQLite数据库
|
||||
│ ├── icons/ # 服务图标
|
||||
│ └── servctl.sh # 服务管理脚本
|
||||
├── static/ # 静态资源(CSS, JS, 图片)
|
||||
└── templates/ # HTML模板
|
||||
```
|
||||
|
||||
## Docker支持
|
||||
|
||||
Servboard提供Docker支持,便于部署。提供的`Dockerfile`和`docker-compose.yml`文件使在容器化环境中运行Servboard变得简单。
|
||||
|
||||
### 自动文件创建
|
||||
|
||||
运行容器时,如果映射的`data`目录不包含:
|
||||
- `dashboard.db`:会自动创建默认数据库
|
||||
- `servctl.sh`:会自动复制服务管理脚本
|
||||
|
||||
## 安全
|
||||
|
||||
- 密码使用`werkzeug.security.generate_password_hash`进行哈希处理
|
||||
- 容器以非root用户(`appuser`)运行
|
||||
- 会话使用Flask的安全cookie-based认证
|
||||
- HTTPS终止由反向代理处理(Flask仅运行HTTP)
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT
|
||||
@@ -0,0 +1,192 @@
|
||||
"""
|
||||
Servboard - 服务导航仪表盘
|
||||
"""
|
||||
import os
|
||||
from functools import wraps
|
||||
from flask import Flask, request, redirect, session, g, flash, render_template_string, render_template, url_for, jsonify
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
|
||||
from models import db, User, Service, init_app
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'dev-secret-key-change-in-production')
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'dashboard.db')}"
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
app.config['WTF_CSRF_ENABLED'] = False # Disable CSRF for simplicity
|
||||
|
||||
# Initialize CSRF protection
|
||||
csrf = CSRFProtect(app)
|
||||
|
||||
# Initialize database (must be done after CSRF)
|
||||
init_app(app)
|
||||
|
||||
# Ensure data and icons directory exists
|
||||
os.makedirs(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'icons'), exist_ok=True)
|
||||
|
||||
|
||||
def login_required(f):
|
||||
"""登录验证装饰器."""
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if 'user_id' not in session:
|
||||
flash('请先登录后再访问。', 'warning')
|
||||
return redirect(url_for('login'))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
||||
|
||||
def admin_required(f):
|
||||
"""管理员权限装饰器(已废弃)."""
|
||||
return f
|
||||
|
||||
|
||||
def get_host_from_request():
|
||||
"""从请求头中提取 Host,优先使用 X-Forwarded-Host 用于反向代理场景."""
|
||||
host = request.headers.get('X-Forwarded-Host')
|
||||
if not host:
|
||||
host = request.host
|
||||
# 移除端口号
|
||||
import re
|
||||
host = re.sub(r':\d+$', '', host)
|
||||
return host
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def home():
|
||||
"""仪表盘主页,显示所有已启用的服务."""
|
||||
if 'user_id' not in session:
|
||||
return redirect(url_for('login'))
|
||||
|
||||
current_user = db.session.get(User, session['user_id'])
|
||||
services = Service.query.filter_by(enabled=True).order_by(Service.name).all()
|
||||
|
||||
return render_template('pages/index.html', services=services, current_user=current_user)
|
||||
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
"""登录页面."""
|
||||
if 'user_id' in session:
|
||||
return redirect(url_for('home'))
|
||||
|
||||
if request.method == 'POST':
|
||||
username = request.form.get('username', '').strip()
|
||||
password = request.form.get('password', '')
|
||||
|
||||
if not username or not password:
|
||||
flash('请输入用户名和密码。', 'error')
|
||||
return render_template('pages/login.html')
|
||||
|
||||
user = User.query.filter_by(username=username).first()
|
||||
if user and user.check_password(password):
|
||||
session['user_id'] = user.id
|
||||
session['username'] = user.username
|
||||
flash(f'欢迎回来,{username}!', 'success')
|
||||
return redirect(url_for('home'))
|
||||
|
||||
flash('用户名或密码错误。', 'error')
|
||||
|
||||
return render_template('pages/login.html')
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
"""退出登录并清空会话."""
|
||||
session.clear()
|
||||
flash('您已退出登录。', 'info')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
|
||||
@app.route('/profile', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def profile():
|
||||
"""用户密码设置页面."""
|
||||
if request.method == 'POST':
|
||||
old_password = request.form.get('old_password', '').strip()
|
||||
new_password = request.form.get('new_password', '').strip()
|
||||
confirm_password = request.form.get('confirm_password', '').strip()
|
||||
|
||||
user = User.query.get(session['user_id'])
|
||||
|
||||
# 验证旧密码
|
||||
if not user.check_password(old_password):
|
||||
flash('当前密码错误。', 'error')
|
||||
return render_template('pages/profile.html')
|
||||
|
||||
# 检查新密码是否为空
|
||||
if not new_password:
|
||||
flash('请输入新密码。', 'error')
|
||||
return render_template('pages/profile.html')
|
||||
|
||||
# 验证新密码长度
|
||||
if len(new_password) < 6:
|
||||
flash('密码长度至少为 6 位。', 'error')
|
||||
return render_template('pages/profile.html')
|
||||
|
||||
# 验证确认密码
|
||||
if new_password != confirm_password:
|
||||
flash('两次输入的新密码不一致。', 'error')
|
||||
return render_template('pages/profile.html')
|
||||
|
||||
# 更新密码
|
||||
user.password_hash = generate_password_hash(new_password)
|
||||
db.session.commit()
|
||||
|
||||
# 修改密码后清空会话,需要重新登录
|
||||
session.clear()
|
||||
return redirect(url_for('login'))
|
||||
|
||||
current_user = db.session.get(User, session['user_id'])
|
||||
return render_template('pages/profile.html', current_user=current_user)
|
||||
|
||||
|
||||
# ============ 已移除的管理员功能 ============
|
||||
# 移除的接口:/manage-users, /manage-services, /api/users/*, /api/services/*
|
||||
|
||||
@app.route('/health')
|
||||
def health():
|
||||
"""健康检查端点."""
|
||||
return {'status': 'ok'}, 200
|
||||
|
||||
|
||||
@app.route('/icons/<filename>')
|
||||
def serve_icon(filename):
|
||||
"""提供 data/icons 目录下图片的访问."""
|
||||
import os
|
||||
from flask import send_from_directory
|
||||
icons_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'icons')
|
||||
return send_from_directory(icons_dir, filename)
|
||||
|
||||
|
||||
# Initialize database on application startup
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
# 检查并迁移旧数据库(移除 role 列,添加 path 列)
|
||||
from sqlalchemy import text
|
||||
try:
|
||||
# 检查 role 列是否存在,如果存在则删除
|
||||
result = db.session.execute(text("PRAGMA table_info(users)"))
|
||||
columns = [row[1] for row in result]
|
||||
if 'role' in columns:
|
||||
db.session.execute(text("ALTER TABLE users DROP COLUMN role"))
|
||||
|
||||
# 检查 services 表是否存在 path 列,如果不存在则添加
|
||||
result = db.session.execute(text("PRAGMA table_info(services)"))
|
||||
columns = [row[1] for row in result]
|
||||
if 'path' not in columns:
|
||||
db.session.execute(text("ALTER TABLE services ADD COLUMN path TEXT"))
|
||||
db.session.commit()
|
||||
except Exception:
|
||||
db.session.rollback()
|
||||
# 创建默认管理员用户如果用户表为空
|
||||
if User.query.count() == 0:
|
||||
admin = User(username='admin', password='changeme')
|
||||
admin.created_at = db.func.datetime('now')
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
port = int(os.environ.get('PORT', 5000))
|
||||
app.run(host='0.0.0.0', port=port)
|
||||
Binary file not shown.
+167
@@ -0,0 +1,167 @@
|
||||
#!/bin/bash
|
||||
# servctl.sh - ServBoard services 管理工具
|
||||
# 数据库路径
|
||||
DB_PATH="$(dirname "$0")/dashboard.db"
|
||||
|
||||
# 检查依赖
|
||||
if ! command -v sqlite3 &> /dev/null; then
|
||||
echo "错误: 未安装 sqlite3" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$DB_PATH" ]; then
|
||||
echo "错误: 数据库文件不存在: $DB_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
show_help() {
|
||||
cat <<EOF
|
||||
用法:
|
||||
$0 -l 显示当前服务列表
|
||||
$0 -h 显示帮助
|
||||
$0 -r <name> 删除服务
|
||||
$0 -t <name> 切换服务状态
|
||||
$0 -a <name> <description> <port(1-65535)> <protocol(http/https)> [<icon>] [<path>] 添加服务
|
||||
|
||||
示例(无空格时无需引号):
|
||||
$0 -a jellyfin 媒体服务器 8096 http jellyfin.png
|
||||
$0 -a watchtower 自动更新容器 8080 https
|
||||
$0 -a nextcloud 文件同步 8080 http nextcloud.png nextcloud
|
||||
$0 -r watchtower
|
||||
$0 -t jellyfin
|
||||
$0 -l
|
||||
EOF
|
||||
}
|
||||
|
||||
list_services() {
|
||||
sqlite3 -header -column "$DB_PATH" \
|
||||
"SELECT id, name, description, port, protocol, enabled, IFNULL(icon, '') AS icon, IFNULL(path, '') AS path FROM services ORDER BY id;"
|
||||
}
|
||||
|
||||
add_service_from_args() {
|
||||
if [ $# -lt 4 ]; then
|
||||
echo "错误: -a 需要至少 4 个参数 (name description port protocol)" >&2
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NAME="$1"
|
||||
DESC="$2"
|
||||
PORT="$3"
|
||||
PROTO_RAW="$4"
|
||||
ICON="${5:-}"
|
||||
PATH="${6:-}"
|
||||
|
||||
# 清理端口空白
|
||||
PORT=$(echo "$PORT" | tr -d '[:space:]')
|
||||
|
||||
# 校验端口
|
||||
if ! [[ "$PORT" =~ ^[0-9]+$ ]] || [ "$PORT" -lt 1 ] || [ "$PORT" -gt 65535 ]; then
|
||||
echo "错误: 端口必须是 1-65535 的整数(当前输入: '$PORT')" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 校验协议
|
||||
PROTO=$(echo "$PROTO_RAW" | tr '[:upper:]' '[:lower:]')
|
||||
if [ "$PROTO" != "http" ] && [ "$PROTO" != "https" ]; then
|
||||
echo "错误: protocol 必须是 http 或 https(当前输入: '$PROTO_RAW')" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ENABLED=1
|
||||
if [ -n "$ICON" ] && [ -n "$PATH" ]; then
|
||||
SQL="INSERT INTO services (name, description, port, protocol, enabled, icon, path) VALUES ('$NAME', '$DESC', $PORT, '$PROTO', $ENABLED, '$ICON', '$PATH');"
|
||||
elif [ -n "$ICON" ]; then
|
||||
SQL="INSERT INTO services (name, description, port, protocol, enabled, icon) VALUES ('$NAME', '$DESC', $PORT, '$PROTO', $ENABLED, '$ICON');"
|
||||
elif [ -n "$PATH" ]; then
|
||||
SQL="INSERT INTO services (name, description, port, protocol, enabled, path) VALUES ('$NAME', '$DESC', $PORT, '$PROTO', $ENABLED, '$PATH');"
|
||||
else
|
||||
SQL="INSERT INTO services (name, description, port, protocol, enabled) VALUES ('$NAME', '$DESC', $PORT, '$PROTO', $ENABLED);"
|
||||
fi
|
||||
|
||||
if sqlite3 "$DB_PATH" "$SQL"; then
|
||||
echo "✅ 添加成功: $NAME ($PORT/$PROTO)"
|
||||
if [ -n "$PATH" ]; then
|
||||
echo " 路径: $PATH"
|
||||
fi
|
||||
else
|
||||
echo "❌ 添加失败(可能名称重复或超长)" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
delete_service() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "错误: -r 需要指定服务名" >&2
|
||||
exit 1
|
||||
fi
|
||||
NAME="$1"
|
||||
COUNT=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM services WHERE name = '$NAME';")
|
||||
if [ "$COUNT" -eq 0 ]; then
|
||||
echo "⚠️ 未找到服务: $NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
sqlite3 "$DB_PATH" "DELETE FROM services WHERE name = '$NAME';"
|
||||
echo "🗑️ 已删除: $NAME"
|
||||
}
|
||||
|
||||
toggle_service() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "错误: -t 需要指定服务名" >&2
|
||||
exit 1
|
||||
fi
|
||||
NAME="$1"
|
||||
CURRENT=$(sqlite3 "$DB_PATH" "SELECT enabled FROM services WHERE name = '$NAME';")
|
||||
if [ -z "$CURRENT" ]; then
|
||||
echo "⚠️ 未找到服务: $NAME" >&2
|
||||
exit 1
|
||||
fi
|
||||
NEW_STATE=$((1 - CURRENT))
|
||||
sqlite3 "$DB_PATH" "UPDATE services SET enabled = $NEW_STATE WHERE name = '$NAME';"
|
||||
if [ "$NEW_STATE" -eq 1 ]; then
|
||||
echo "🔌 已启用: $NAME"
|
||||
else
|
||||
echo "📴 已禁用: $NAME"
|
||||
fi
|
||||
}
|
||||
|
||||
# === 主逻辑:手动解析参数(无需 getopts)===
|
||||
case "${1:-}" in
|
||||
-l)
|
||||
list_services
|
||||
;;
|
||||
-h)
|
||||
show_help
|
||||
;;
|
||||
-r)
|
||||
if [ -z "$2" ]; then
|
||||
echo "错误: -r 需要服务名" >&2
|
||||
exit 1
|
||||
fi
|
||||
delete_service "$2"
|
||||
;;
|
||||
-t)
|
||||
if [ -z "$2" ]; then
|
||||
echo "错误: -t 需要服务名" >&2
|
||||
exit 1
|
||||
fi
|
||||
toggle_service "$2"
|
||||
;;
|
||||
-a)
|
||||
if [ $# -lt 5 ]; then
|
||||
echo "错误: -a 需要至少 4 个参数" >&2
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
add_service_from_args "$@"
|
||||
;;
|
||||
"")
|
||||
echo "提示: 运行 '$0 -h' 查看帮助"
|
||||
;;
|
||||
*)
|
||||
echo "未知选项: $1" >&2
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,9 @@
|
||||
services:
|
||||
servboard:
|
||||
image: zhangjie/servboard:v1.0.0
|
||||
ports:
|
||||
- "80:5000"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
restart: unless-stopped
|
||||
user: root
|
||||
@@ -0,0 +1,87 @@
|
||||
"""
|
||||
Database models and initialization.
|
||||
"""
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
||||
|
||||
class User(db.Model):
|
||||
"""User model for authentication."""
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(80), unique=True, nullable=False)
|
||||
password_hash = db.Column(db.String(256), nullable=False)
|
||||
created_at = db.Column(db.DateTime, nullable=True)
|
||||
|
||||
def __init__(self, username, password=None):
|
||||
self.username = username
|
||||
if password:
|
||||
self.password_hash = generate_password_hash(password)
|
||||
self.created_at = db.func.datetime('now')
|
||||
|
||||
def check_password(self, password):
|
||||
"""Verify password against stored hash."""
|
||||
return check_password_hash(self.password_hash, password)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<User {self.username}>'
|
||||
|
||||
|
||||
class Service(db.Model):
|
||||
"""Service model for navigation entries."""
|
||||
__tablename__ = 'services'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(120), nullable=False)
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
port = db.Column(db.Integer, nullable=False)
|
||||
protocol = db.Column(db.String(10), nullable=False, default='http')
|
||||
enabled = db.Column(db.Boolean, nullable=False, default=True)
|
||||
icon = db.Column(db.String(100), nullable=True) # 支持 emoji 或图片文件名
|
||||
path = db.Column(db.String(255), nullable=True) # 服务路径
|
||||
|
||||
def get_icon_html(self):
|
||||
"""返回图标的 HTML,支持 emoji 和图片"""
|
||||
if not self.icon:
|
||||
return '<div class="service-icon">🚀</div>'
|
||||
# 如果是图片文件(有扩展名)
|
||||
if '.' in self.icon:
|
||||
from flask import url_for
|
||||
return '<img src="{}" class="service-icon-img">'.format(url_for('serve_icon', filename=self.icon))
|
||||
# 否则是 emoji
|
||||
return '<div class="service-icon">{}</div>'.format(self.icon)
|
||||
|
||||
def __init__(self, name, description=None, port=None, protocol='http',
|
||||
enabled=True, icon=None, path=None):
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.port = port
|
||||
self.protocol = protocol
|
||||
self.enabled = enabled
|
||||
self.icon = icon
|
||||
self.path = path
|
||||
|
||||
def get_url(self):
|
||||
"""Generate the full URL for this service."""
|
||||
from app import get_host_from_request
|
||||
host = get_host_from_request()
|
||||
url = f"{self.protocol}://{host}:{self.port}"
|
||||
if self.path:
|
||||
# 确保path以/开头
|
||||
if not self.path.startswith('/'):
|
||||
url += '/' + self.path
|
||||
else:
|
||||
url += self.path
|
||||
return url
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Service {self.name}>'
|
||||
|
||||
|
||||
def init_app(app):
|
||||
"""Flask application factory pattern for database initialization."""
|
||||
db.init_app(app)
|
||||
return db
|
||||
@@ -0,0 +1,6 @@
|
||||
flask==3.0.0
|
||||
flask-sqlalchemy==3.1.1
|
||||
werkzeug==3.0.1
|
||||
flask-wtf==1.2.1
|
||||
wtforms==3.1.1
|
||||
email-validator==2.1.0
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
@@ -0,0 +1,854 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:root {
|
||||
--bg-primary: #1d1d20;
|
||||
--bg-secondary: #252529;
|
||||
--bg-tertiary: #2d2d33;
|
||||
--text-primary: #ffffff;
|
||||
--text-secondary: #888888;
|
||||
--accent-primary: #4a9eff;
|
||||
--accent-hover: #3a7eff;
|
||||
--card-bg: rgba(255, 255, 255, 0.05);
|
||||
--card-border: rgba(255, 255, 255, 0.1);
|
||||
--input-bg: rgba(255, 255, 255, 0.05);
|
||||
--input-border: rgba(255, 255, 255, 0.1);
|
||||
--shadow: rgba(0, 0, 0, 0.3);
|
||||
--segment-bg: rgba(255, 255, 255, 0.1);
|
||||
--segment-active: rgba(74, 158, 255, 0.3);
|
||||
--success: #10b981;
|
||||
--danger: #ef4444;
|
||||
--warning: #f59e0b;
|
||||
}
|
||||
|
||||
.light-mode {
|
||||
--bg-primary: #f2f4f7;
|
||||
--bg-secondary: #e8ebf0;
|
||||
--bg-tertiary: #dfe3e9;
|
||||
--text-primary: #1d1d20;
|
||||
--text-secondary: #666666;
|
||||
--card-bg: rgba(0, 0, 0, 0.03);
|
||||
--card-border: rgba(0, 0, 0, 0.08);
|
||||
--input-bg: rgba(0, 0, 0, 0.03);
|
||||
--input-border: rgba(0, 0, 0, 0.15);
|
||||
--shadow: rgba(0, 0, 0, 0.1);
|
||||
--segment-bg: rgba(0, 0, 0, 0.08);
|
||||
--segment-active: rgba(74, 158, 255, 0.2);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Microsoft YaHei', sans-serif;
|
||||
background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
|
||||
min-height: 100vh;
|
||||
color: var(--text-primary);
|
||||
transition: background 0.3s ease, color 0.3s ease;
|
||||
}
|
||||
|
||||
/* Login Page */
|
||||
body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background: var(--card-bg);
|
||||
padding: 40px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px var(--shadow);
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
border: 1px solid var(--card-border);
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.login-logo {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
font-size: 80px;
|
||||
}
|
||||
|
||||
.login-container h1 {
|
||||
text-align: center;
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 8px;
|
||||
color: var(--text-primary);
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.login-container .subtitle {
|
||||
text-align: center;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Theme Toggle */
|
||||
.theme-toggle-dots {
|
||||
display: inline-flex;
|
||||
background: var(--segment-bg);
|
||||
border-radius: 20px;
|
||||
padding: 3px;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.theme-dot {
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 13px;
|
||||
padding: 2px 4px;
|
||||
cursor: pointer;
|
||||
border-radius: 14px;
|
||||
transition: all 0.2s ease;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.theme-dot:hover {
|
||||
opacity: 1;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.theme-dot.active {
|
||||
opacity: 1;
|
||||
background: var(--accent-primary);
|
||||
}
|
||||
|
||||
/* Forms */
|
||||
.login-container .form-group {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.login-container .form-group small {
|
||||
display: block;
|
||||
margin-top: 6px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* Password Field Wrapper */
|
||||
.password-field-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.password-label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.password-toggle {
|
||||
position: absolute;
|
||||
right: 4px;
|
||||
top: 4px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
border-radius: 6px;
|
||||
opacity: 0.5;
|
||||
transition: all 0.2s ease;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.password-toggle:hover {
|
||||
opacity: 0.8;
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
/* Input Wrapper */
|
||||
.input-wrapper {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.input-wrapper input {
|
||||
padding: 8px 36px 8px 12px;
|
||||
width: 320px;
|
||||
border: 1.5px solid var(--input-border);
|
||||
border-radius: 6px;
|
||||
background: var(--input-bg);
|
||||
color: var(--text-primary);
|
||||
font-size: 13px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.input-wrapper input::placeholder {
|
||||
color: var(--text-secondary);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.input-wrapper input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent-primary);
|
||||
background: rgba(74, 158, 255, 0.08);
|
||||
box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.1);
|
||||
}
|
||||
|
||||
.input-wrapper input:hover:not(:focus) {
|
||||
border-color: rgba(74, 158, 255, 0.5);
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.login-container button[type="submit"] {
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
margin-top: 18px;
|
||||
background: linear-gradient(135deg, var(--accent-primary) 0%, #8b5cf6 100%);
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(74, 158, 255, 0.3);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.login-container button[type="submit"]:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 25px rgba(74, 158, 255, 0.4);
|
||||
}
|
||||
|
||||
.login-container button[type="submit"]:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
padding: 12px 24px;
|
||||
background: linear-gradient(135deg, var(--accent-primary) 0%, #8b5cf6 100%);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
transition: all 0.2s;
|
||||
box-shadow: 0 4px 15px rgba(74, 158, 255, 0.3);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(74, 158, 255, 0.4);
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
padding: 12px 24px;
|
||||
background: transparent;
|
||||
border: 1px solid var(--input-border);
|
||||
border-radius: 8px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
text-decoration: none;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-cancel:hover {
|
||||
color: var(--text-primary);
|
||||
border-color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.btn-icon:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.btn-icon.btn-danger {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
/* Header */
|
||||
header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: var(--card-bg);
|
||||
padding: 16px 40px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid var(--card-border);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
/* User Avatar */
|
||||
.user-avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent-primary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
border: 1px solid var(--card-border);
|
||||
padding: 0;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.user-avatar:hover {
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.user-menu {
|
||||
position: absolute;
|
||||
top: 50px;
|
||||
right: 0;
|
||||
background: var(--bg-tertiary);
|
||||
border: 1px solid var(--card-border);
|
||||
border-radius: 12px;
|
||||
width: 280px;
|
||||
box-shadow: 0 8px 32px var(--shadow);
|
||||
display: none;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.user-menu.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.user-menu-header {
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid var(--card-border);
|
||||
}
|
||||
|
||||
.user-avatar-large {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent-primary);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 24px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.user-info-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.user-role {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.role-badge {
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.role-badge.admin {
|
||||
background: var(--accent-primary);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.role-badge.user {
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.user-menu-items {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
color: var(--text-primary);
|
||||
text-decoration: none;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.menu-item.logout {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
/* Page Container */
|
||||
.page-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
/* Table */
|
||||
.table-container {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--card-border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.data-table th,
|
||||
.data-table td {
|
||||
padding: 16px 20px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--card-border);
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
background: var(--bg-tertiary);
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.data-table tr:hover {
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.status-badge.enabled {
|
||||
background: rgba(16, 185, 129, 0.2);
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.status-badge.disabled {
|
||||
background: rgba(239, 68, 68, 0.2);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.current-user {
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* Modal */
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: none;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 2000;
|
||||
}
|
||||
|
||||
.modal.show {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: var(--bg-primary);
|
||||
border-radius: 16px;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 8px 32px var(--shadow);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20px 24px;
|
||||
border-bottom: 1px solid var(--card-border);
|
||||
}
|
||||
|
||||
.modal-header h2 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: var(--text-secondary);
|
||||
padding: 0;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 4px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.modal-content form {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 24px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
/* Container */
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 100px 40px 40px;
|
||||
}
|
||||
|
||||
.container h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 40px;
|
||||
font-size: 45px;
|
||||
}
|
||||
|
||||
/* Services Grid */
|
||||
.services-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 24px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.service-card {
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--card-border);
|
||||
border-radius: 12px;
|
||||
padding: 32px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
.service-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 12px 40px var(--shadow);
|
||||
border-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.service-icon-img {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border-radius: 6px;
|
||||
object-fit: cover;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.service-icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.service-name {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
padding-top: 5px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.service-description {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
padding-top: 20px;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Empty State */
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.empty-state-icon {
|
||||
font-size: 64px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Flash Messages */
|
||||
.flash-messages {
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
.login-container .flash-messages {
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
.flash {
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.flash.error {
|
||||
background: rgba(239, 68, 68, 0.2);
|
||||
border: 1px solid rgba(239, 68, 68, 0.5);
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.flash.success {
|
||||
background: rgba(16, 185, 129, 0.2);
|
||||
border: 1px solid rgba(16, 185, 129, 0.5);
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.flash.warning {
|
||||
background: rgba(245, 158, 11, 0.2);
|
||||
border: 1px solid rgba(245, 158, 11, 0.5);
|
||||
color: var(--warning);
|
||||
}
|
||||
|
||||
.flash.info {
|
||||
background: rgba(74, 158, 255, 0.2);
|
||||
border: 1px solid rgba(74, 158, 255, 0.5);
|
||||
color: var(--accent-primary);
|
||||
}
|
||||
|
||||
/* Profile Page */
|
||||
.profile-container {
|
||||
background: var(--card-bg);
|
||||
border-radius: 20px;
|
||||
padding: 40px;
|
||||
max-width: 420px;
|
||||
margin: 100px auto 40px;
|
||||
border: 1px solid var(--card-border);
|
||||
box-shadow: 0 20px 60px var(--shadow);
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.back-btn {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 24px;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
border-radius: 6px;
|
||||
transition: all 0.2s ease;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.back-btn:hover {
|
||||
color: var(--text-primary);
|
||||
background: var(--card-bg);
|
||||
}
|
||||
|
||||
.profile-container .profile-avatar {
|
||||
display: block;
|
||||
margin: 0 auto 16px;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent-primary);
|
||||
text-align: center;
|
||||
font-size: 28px;
|
||||
line-height: 56px;
|
||||
}
|
||||
|
||||
.profile-container h1 {
|
||||
text-align: center;
|
||||
font-size: 32px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 28px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.profile-container .flash-messages {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.profile-container form {
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.profile-container button[type="submit"] {
|
||||
width: 100%;
|
||||
padding: 12px 24px;
|
||||
background: linear-gradient(135deg, var(--accent-primary) 0%, #8b5cf6 100%);
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 15px rgba(74, 158, 255, 0.3);
|
||||
display: block;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.profile-container button[type="submit"]:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 25px rgba(74, 158, 255, 0.4);
|
||||
}
|
||||
|
||||
.profile-container .logout-btn {
|
||||
width: 100%;
|
||||
padding: 10px 24px;
|
||||
background: transparent;
|
||||
border: 1px solid var(--danger);
|
||||
border-radius: 8px;
|
||||
color: var(--danger);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.profile-container .logout-btn:hover {
|
||||
background: var(--danger);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* Profile Form Groups */
|
||||
.profile-container .form-group {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.profile-container .password-label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.profile-container .input-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.profile-container .input-wrapper input::placeholder {
|
||||
color: var(--text-secondary);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.profile-container .input-wrapper input:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent-primary);
|
||||
background: rgba(74, 158, 255, 0.08);
|
||||
box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.1);
|
||||
}
|
||||
|
||||
.profile-container .password-toggle {
|
||||
position: absolute;
|
||||
right: 3px;
|
||||
top: 3px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
padding: 4px 8px;
|
||||
border-radius: 6px;
|
||||
opacity: 0.5;
|
||||
transition: all 0.2s ease;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.profile-container .password-toggle:hover {
|
||||
opacity: 1;
|
||||
background: var(--card-bg);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
function togglePassword() {
|
||||
const passwordInput = document.getElementById('password');
|
||||
const toggleBtn = document.querySelector('.password-toggle');
|
||||
|
||||
if (passwordInput.type === 'password') {
|
||||
passwordInput.type = 'text';
|
||||
toggleBtn.textContent = '👀';
|
||||
} else {
|
||||
passwordInput.type = 'password';
|
||||
toggleBtn.textContent = '🙈';
|
||||
}
|
||||
}
|
||||
|
||||
function setTheme(theme) {
|
||||
const isLight = theme === 'light';
|
||||
const isDark = theme === 'dark';
|
||||
|
||||
if (isDark) {
|
||||
document.body.classList.remove('light-mode');
|
||||
} else if (isLight) {
|
||||
document.body.classList.add('light-mode');
|
||||
} else {
|
||||
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
if (prefersDark) {
|
||||
document.body.classList.remove('light-mode');
|
||||
} else {
|
||||
document.body.classList.add('light-mode');
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.setItem('theme', theme);
|
||||
updateSegmentedControl(theme);
|
||||
}
|
||||
|
||||
function updateSegmentedControl(activeTheme) {
|
||||
const dots = document.querySelectorAll('.theme-dot');
|
||||
dots.forEach(dot => {
|
||||
if (dot.dataset.value === activeTheme) {
|
||||
dot.classList.add('active');
|
||||
} else {
|
||||
dot.classList.remove('active');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Update indicator position on window resize
|
||||
window.addEventListener('resize', function() {
|
||||
updateSegmentedControl(localStorage.getItem('theme') || 'dark');
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const savedTheme = localStorage.getItem('theme') || 'dark';
|
||||
setTheme(savedTheme);
|
||||
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function(e) {
|
||||
if (localStorage.getItem('theme') === 'system') {
|
||||
if (e.matches) {
|
||||
document.body.classList.remove('light-mode');
|
||||
} else {
|
||||
document.body.classList.add('light-mode');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>服务罗盘</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='logo.png') }}">
|
||||
</head>
|
||||
<body>
|
||||
{% block header %}
|
||||
<header>
|
||||
<div class="logo">
|
||||
<img src="{{ url_for('static', filename='logo.png') }}" alt="" style="height: 45px; margin-right: 15px;">
|
||||
服务罗盘
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<div class="theme-toggle-dots">
|
||||
<button class="theme-dot active" onclick="setTheme('dark')" data-value="dark" title="暗色">🌙</button>
|
||||
<button class="theme-dot" onclick="setTheme('light')" data-value="light" title="亮色">☀️</button>
|
||||
<button class="theme-dot" onclick="setTheme('system')" data-value="system" title="跟随系统">💻</button>
|
||||
</div>
|
||||
<button class="user-avatar" onclick="window.location.href='{{ url_for('profile') }}'" title="账户设置">👨💻</button>
|
||||
</div>
|
||||
</header>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
<script src="{{ url_for('static', filename='theme.js') }}"></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
{% extends "pages/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1>我的服务</h1>
|
||||
{% if services %}
|
||||
<div class="services-grid">
|
||||
{% for service in services %}
|
||||
<a href="{{ service.get_url() }}" class="service-card" target="_blank" rel="noopener noreferrer">
|
||||
{{ service.get_icon_html()|safe }}
|
||||
<div class="service-name">{{ service.name }}</div>
|
||||
<div class="service-description">{{ service.description or '无描述' }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">📋</div>
|
||||
<p>暂无服务。请添加服务以开始使用!</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,59 @@
|
||||
{% extends "pages/base.html" %}
|
||||
|
||||
{% block header %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="login-container">
|
||||
<div class="login-logo">
|
||||
<img src="{{ url_for('static', filename='logo.png') }}" alt="logo" style="width: 80px; height: 80px;">
|
||||
</div>
|
||||
<h1>服务罗盘</h1>
|
||||
<p class="subtitle">服务导航中心</p>
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<div class="flash-messages">
|
||||
{% for category, message in messages %}
|
||||
<div class="flash {{ category }}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<div class="form-group">
|
||||
<label for="username" class="password-label">用户名</label>
|
||||
<div class="input-wrapper">
|
||||
<input type="text" id="username" name="username" required autofocus placeholder="请输入用户名">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="password-field-wrapper">
|
||||
<label for="password" class="password-label">密码</label>
|
||||
<div class="input-wrapper">
|
||||
<input type="password" id="password" name="password" required placeholder="请输入密码">
|
||||
<button type="button" class="password-toggle" onclick="togglePassword()" title="显示/隐藏密码">🙈</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit">登录</button>
|
||||
</form>
|
||||
</div>
|
||||
<script src="{{ url_for('static', filename='theme.js') }}"></script>
|
||||
<script>
|
||||
function togglePassword() {
|
||||
const passwordInput = document.getElementById('password');
|
||||
const toggleBtn = document.querySelector('.password-toggle');
|
||||
if (passwordInput.type === 'password') {
|
||||
passwordInput.type = 'text';
|
||||
toggleBtn.textContent = '👀';
|
||||
} else {
|
||||
passwordInput.type = 'password';
|
||||
toggleBtn.textContent = '🙈';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,74 @@
|
||||
{% extends "pages/base.html" %}
|
||||
|
||||
{% block title %}修改密码{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="profile-container">
|
||||
<button class="back-btn" onclick="window.location.href='{{ url_for('home') }}'" title="返回主页">×</button>
|
||||
<div class="profile-avatar">👨💻</div>
|
||||
<h1>修改密码</h1>
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
<div class="flash-messages">
|
||||
{% for category, message in messages %}
|
||||
<div class="flash {{ category }}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<div class="form-group">
|
||||
<label for="old_password" class="password-label">当前密码</label>
|
||||
<div class="password-field-wrapper">
|
||||
<div class="input-wrapper">
|
||||
<input type="password" id="old_password" name="old_password" required placeholder="请输入当前密码" value="{{ request.form.get('old_password', '') }}">
|
||||
<button type="button" class="password-toggle" onclick="togglePassword('old_password')" title="显示/隐藏密码">🙈</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="new_password" class="password-label">新密码</label>
|
||||
<div class="password-field-wrapper">
|
||||
<div class="input-wrapper">
|
||||
<input type="password" id="new_password" name="new_password" required placeholder="请输入新密码(至少 6 位)" value="{{ request.form.get('new_password', '') }}">
|
||||
<button type="button" class="password-toggle" onclick="togglePassword('new_password')" title="显示/隐藏密码">🙈</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="confirm_password" class="password-label">确认密码</label>
|
||||
<div class="password-field-wrapper">
|
||||
<div class="input-wrapper">
|
||||
<input type="password" id="confirm_password" name="confirm_password" required placeholder="请再次输入新密码" value="{{ request.form.get('confirm_password', '') }}">
|
||||
<button type="button" class="password-toggle" onclick="togglePassword('confirm_password')" title="显示/隐藏密码">🙈</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit">修改密码</button>
|
||||
<button type="button" class="logout-btn" onclick="window.location.href='{{ url_for('logout') }}'">退出登录</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ url_for('static', filename='theme.js') }}"></script>
|
||||
<script>
|
||||
function togglePassword(fieldId) {
|
||||
const passwordInput = document.getElementById(fieldId);
|
||||
const inputWrapper = passwordInput.closest('.input-wrapper');
|
||||
const toggleBtn = inputWrapper.querySelector('.password-toggle');
|
||||
if (passwordInput.type === 'password') {
|
||||
passwordInput.type = 'text';
|
||||
toggleBtn.textContent = '👀';
|
||||
} else {
|
||||
passwordInput.type = 'password';
|
||||
toggleBtn.textContent = '🙈';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user