提交
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"seeyon-filesystem/config"
|
||||
"seeyon-filesystem/dto"
|
||||
"seeyon-filesystem/model"
|
||||
"seeyon-filesystem/service"
|
||||
@@ -24,6 +26,99 @@ func NewAdminController() *AdminController {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 授权管理 ==========
|
||||
|
||||
// GetLicense 获取当前授权信息
|
||||
// GET /api/admin/license
|
||||
func (c *AdminController) GetLicense(ctx *gin.Context) {
|
||||
licensePath := config.AppConfig.License.FilePath
|
||||
if licensePath == "" {
|
||||
licensePath = "license.json"
|
||||
}
|
||||
|
||||
resp, err := utils.ReadAndVerifyLicense(licensePath, config.AppConfig.License.VerifyURL, "seeyon-filesystem", "1.0")
|
||||
if err != nil {
|
||||
utils.Success(ctx, gin.H{
|
||||
"status": "invalid",
|
||||
"message": err.Error(),
|
||||
"machine_id": utils.GetMachineID(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
utils.Success(ctx, gin.H{
|
||||
"status": map[bool]string{true: "valid", false: "invalid"}[resp.Valid],
|
||||
"message": resp.Message,
|
||||
"machine_id": utils.GetMachineID(),
|
||||
"product": resp.Product,
|
||||
"customer_id": resp.CustomerID,
|
||||
"customer": resp.Customer,
|
||||
"contact": resp.Contact,
|
||||
"phone": resp.Phone,
|
||||
"expire_at": resp.ExpireAt,
|
||||
"max_users": resp.MaxUsers,
|
||||
"max_files": resp.MaxFiles,
|
||||
"features": resp.Features,
|
||||
"expire_days": resp.ExpireDays,
|
||||
})
|
||||
}
|
||||
|
||||
// GenerateLicense 生成授权码
|
||||
// POST /api/admin/license/generate
|
||||
func (c *AdminController) GenerateLicense(ctx *gin.Context) {
|
||||
var req struct {
|
||||
TargetMachineID string `json:"target_machine_id"`
|
||||
CustomerID string `json:"customer_id"`
|
||||
Customer string `json:"customer"`
|
||||
Contact string `json:"contact"`
|
||||
Phone string `json:"phone"`
|
||||
MaxUsers int `json:"max_users"`
|
||||
MaxFiles int `json:"max_files"`
|
||||
Features string `json:"features"`
|
||||
ExpireAt string `json:"expire_at"` // RFC3339格式, 空=永久
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
utils.BadRequest(ctx, "参数错误: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if req.Features == "" {
|
||||
req.Features = "*"
|
||||
}
|
||||
if req.Version == "" {
|
||||
req.Version = "1.0"
|
||||
}
|
||||
|
||||
license := &utils.LicenseInfo{
|
||||
Product: "seeyon-filesystem",
|
||||
CustomerID: req.CustomerID,
|
||||
Customer: req.Customer,
|
||||
Contact: req.Contact,
|
||||
Phone: req.Phone,
|
||||
MachineID: req.TargetMachineID,
|
||||
MaxUsers: req.MaxUsers,
|
||||
MaxFiles: req.MaxFiles,
|
||||
Features: req.Features,
|
||||
ExpireAt: req.ExpireAt,
|
||||
}
|
||||
utils.SignLicense(license)
|
||||
|
||||
// 返回标准格式
|
||||
licenseFile := map[string]interface{}{
|
||||
"productType": "seeyon-filesystem",
|
||||
"version": req.Version,
|
||||
"licenseStr": license.LicenseStr,
|
||||
}
|
||||
fileJSON, _ := json.Marshal(licenseFile)
|
||||
|
||||
utils.Success(ctx, gin.H{
|
||||
"license_file": string(fileJSON), // 保存为 license.json
|
||||
"license": license,
|
||||
"machine_id": utils.GetMachineID(),
|
||||
})
|
||||
}
|
||||
|
||||
// ========== 用户管理 ==========
|
||||
|
||||
// ListUsers 用户列表
|
||||
|
||||
Reference in New Issue
Block a user