提交
This commit is contained in:
@@ -3,7 +3,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"seeyon-filesystem/api"
|
||||
"seeyon-filesystem/config"
|
||||
@@ -14,8 +18,16 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 将日志输出接入环形缓冲区(同时保留控制台输出)
|
||||
log.SetOutput(utils.LogBuf)
|
||||
// 日志输出: 控制台 + 内存缓冲区 + 按日期分割的文件
|
||||
logDir := "logs"
|
||||
os.MkdirAll(logDir, 0755)
|
||||
logPath := filepath.Join(logDir, fmt.Sprintf("server_%s.log", time.Now().Format("20060102")))
|
||||
logFile, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err == nil {
|
||||
log.SetOutput(io.MultiWriter(os.Stderr, logFile, utils.LogBuf))
|
||||
} else {
|
||||
log.SetOutput(io.MultiWriter(os.Stderr, utils.LogBuf))
|
||||
}
|
||||
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
@@ -339,34 +351,47 @@ func checkLicense(cfg config.LicenseConfig) error {
|
||||
licensePath = "license.json"
|
||||
}
|
||||
|
||||
resp, err := utils.ReadAndVerifyLicense(licensePath, cfg.VerifyURL, "seeyon-filesystem", "1.0")
|
||||
// 读取授权文件
|
||||
license, err := utils.ReadLicenseFile(licensePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !resp.Valid {
|
||||
return fmt.Errorf("%s", resp.Message)
|
||||
}
|
||||
|
||||
// 设置当前授权信息
|
||||
licPath := cfg.FilePath
|
||||
if licPath == "" {
|
||||
licPath = "license.json"
|
||||
}
|
||||
if licData, licErr := utils.ReadLicenseFile(licPath); licErr == nil {
|
||||
utils.SetCurrentLicense(licData)
|
||||
utils.SetCurrentLicense(license)
|
||||
|
||||
// 根据网络类型选择验证方式
|
||||
network := cfg.Network
|
||||
if network == "" {
|
||||
network = "internal"
|
||||
}
|
||||
|
||||
lic := utils.GetCurrentLicense()
|
||||
features := ""
|
||||
if lic != nil {
|
||||
features = lic.Features
|
||||
}
|
||||
|
||||
if resp.ExpireDays == -1 {
|
||||
log.Printf("[授权] 企业版 - 永久授权, 用户上限: %d, 功能: %s", resp.MaxUsers, features)
|
||||
if network == "external" && cfg.VerifyURL != "" {
|
||||
// 外网: 调远程接口验证
|
||||
resp, err := utils.ReadAndVerifyLicense(licensePath, cfg.VerifyURL, "seeyon-filesystem", "1.0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !resp.Valid {
|
||||
return fmt.Errorf("%s", resp.Message)
|
||||
}
|
||||
if resp.ExpireDays == -1 {
|
||||
log.Printf("[授权] 企业版(外网) - 永久授权, 用户上限: %d, 功能: %s", resp.MaxUsers, license.Features)
|
||||
} else {
|
||||
log.Printf("[授权] 企业版(外网) - 有效期剩余 %d 天, 用户上限: %d, 功能: %s", resp.ExpireDays, resp.MaxUsers, license.Features)
|
||||
}
|
||||
} else {
|
||||
log.Printf("[授权] 企业版 - 有效期剩余 %d 天, 用户上限: %d, 功能: %s", resp.ExpireDays, resp.MaxUsers, features)
|
||||
// 内网: 仅本地校验(解密 + 签名 + 机器码比对)
|
||||
if err := utils.VerifyLicense(license); err != nil {
|
||||
return err
|
||||
}
|
||||
days := utils.GetLicenseExpireDays(license)
|
||||
if days == -1 {
|
||||
log.Printf("[授权] 企业版(内网) - 永久授权, 用户上限: %d, 功能: %s", license.MaxUsers, license.Features)
|
||||
} else {
|
||||
log.Printf("[授权] 企业版(内网) - 有效期剩余 %d 天, 用户上限: %d, 功能: %s", days, license.MaxUsers, license.Features)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user