# license-server **Repository Path**: xmcqq/license-server ## Basic Information - **Project Name**: license-server - **Description**: license 生成验证文件 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-27 - **Last Updated**: 2026-06-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # License 管理系统 基于 Go + Vue + Element Plus + SQLite 的 License 生成与管理平台。 ## 功能特性 - **系统管理**: 添加、编辑、删除系统,支持 AppID/AppSecret 认证 - **License 生成**: 基于 IP + MAC 地址 + 时长生成加密的 license.lic 文件 - **License 续签**: 支持对已有 License 进行多次续签 - **记录管理**: 查看所有 License 申请记录,支持按系统和状态筛选 - **文件下载**: 支持下载生成的 license.lic 文件 - **状态管理**: 支持 License 撤销(active/expired/revoked) ## 技术栈 - **后端**: Go 1.21 + Gin + modernc.org/sqlite + AES-256-GCM 加密 - **前端**: Vue 3 + Element Plus + Vite + Axios - **数据库**: SQLite ## 项目结构 ``` license-server/ ├── backend/ # Go 后端 │ ├── main.go # 主入口 │ ├── config/ # 配置模块 │ │ └── config.go # 支持 config.yml 和环境变量 │ ├── models/ # 数据模型 │ ├── handlers/ # HTTP 处理器 │ ├── services/ # 业务逻辑(加密、License生成) │ └── database/ # 数据库初始化 ├── frontend/ # Vue 前端 │ ├── src/ │ │ ├── api/ # API 调用(使用相对路径) │ │ ├── views/ # 页面组件 │ │ ├── router/ # 路由 │ │ ├── App.vue # 根组件 │ │ └── main.js # 入口文件 │ └── vite.config.js # Vite 配置 ├── license-checker/ # License 验证 SDK(用于客户端应用) │ ├── src/main/java/ │ └── demo/ # Demo 示例 ├── scripts/ # 打包脚本 │ ├── build.sh # Linux 打包脚本 │ ├── build-arm64.sh # Linux ARM64 (飞腾D2000) 打包脚本 │ └── build.bat # Windows 打包脚本 └── build/ # 打包输出目录 ``` ## 快速开始 ### 前后端分离模式(开发环境) **1. 启动后端服务** ```bash cd backend go mod tidy go run main.go ``` 后端服务将在 http://localhost:8080 启动 **2. 启动前端服务** ```bash cd frontend npm install npm run dev ``` 前端服务将在 http://localhost:3000 启动 **3. 访问系统** 打开浏览器访问 http://localhost:3000 ### 一体化部署模式(生产环境) 使用打包脚本生成包含前后端的独立部署包: **Windows 构建:** ```cmd cd license-server scripts\build.bat ``` **Linux 构建(x86_64):** ```bash chmod +x scripts/build.sh ./scripts/build.sh prod ``` **Linux ARM64 构建(飞腾D2000):** ```bash chmod +x scripts/build-arm64.sh ./scripts/build-arm64.sh prod ``` 打包后会生成: - `license-server-dev-YYYYMMDD.zip` (Windows) - `license-server-prod-YYYYMMDD.tar.gz` (Linux x86_64) - `license-server-prod-feiteng-d2000-arm64-YYYYMMDD.tar.gz` (Linux ARM64) **解压后直接运行:** ```bash # Linux tar -xzvf license-server-prod-YYYYMMDD.tar.gz chmod +x start.sh ./start.sh # Windows unzip license-server-dev-YYYYMMDD.zip start.bat ``` 访问 http://localhost:8080 ## 配置文件 (config.yml) ```yaml server: port: 8080 # 服务端口 database: ./data/license.db # 数据库路径 frontend-dir: ./web # 前端页面目录 license: secret-key: license-server-secret-key-2024 # 加密密钥 license-dir: ./licenses # License 文件存储目录 admin: user: admin # 管理员用户名 pass: "123456" # 管理员密码 ``` ### 配置加载优先级 1. **config.yml 文件**(最高优先级) 2. **环境变量**(如果 config.yml 不存在或未配置某项) 3. **默认值**(如果都没有设置) ## 环境变量 | 变量 | 默认值 | 描述 | |------|--------|------| | PORT | 8080 | 服务端口 | | DATABASE | ./license.db | 数据库路径 | | LICENSE_DIR | ./licenses | License 文件存储目录 | | SECRET_KEY | license-server-secret-key-2024 | 加密密钥 | | FRONTEND_DIR | ./web | 前端页面目录 | | ADMIN_USER | admin | 管理员用户名 | | ADMIN_PASS | 123456 | 管理员密码 | ## API 接口 ### 系统管理 | 方法 | 路径 | 描述 | |------|------|------| | GET | /api/systems | 获取系统列表 | | POST | /api/systems | 创建系统 | | GET | /api/systems/:id | 获取系统详情 | | PUT | /api/systems/:id | 更新系统 | | DELETE | /api/systems/:id | 删除系统 | ### License 管理 | 方法 | 路径 | 描述 | |------|------|------| | GET | /api/licenses | 获取 License 列表 | | POST | /api/licenses/generate | 生成新 License | | POST | /api/licenses/renew/:id | 续签 License | | GET | /api/licenses/:id/download | 下载 License 文件 | | PUT | /api/licenses/:id/revoke | 撤销 License | ## License 文件格式 生成的 license.lic 文件为 AES-256-GCM 加密的二进制文件,解密后 JSON 结构: ```json { "app_id": "system_app_id", "ip_address": "192.168.1.100", "mac_address": "AA:BB:CC:DD:EE:FF", "start_time": "2024-01-01T00:00:00", "expire_time": "2025-01-01T00:00:00", "duration_days": 365, "signature": "base64_signature" } ``` ## License 续签说明 License 续签时会: 1. 将原 License 状态标记为 `expired` 2. 生成新的 License 文件 3. 新 License 的 renewed_from 字段关联原 License ID 4. 新 License 从续签时刻开始计算时长 ## License 验证 SDK `license-checker/` 目录下是一个 Spring Boot Starter,可用于客户端应用验证 License: **Maven 依赖:** ```xml com.license license-checker-spring-boot-starter 1.0.0 ``` **application.yml 配置:** ```yaml license: checker: enabled: true license-dir: ./licenses secret-key: license-server-secret-key-2024 expected-app-id: your-app-id ``` ### 配置说明 | 配置项 | 说明 | |--------|------| | enabled | 是否启用 License 验证,false 则跳过验证 | | license-dir | License 文件目录 | | secret-key | 加密密钥,必须与生成 License 时一致 | | expected-app-id | 期望的 App ID,会验证 License 中的 app_id 字段 |