fix: 授权码读取和系统重置命令错误

This commit is contained in:
TsMask
2025-05-29 15:58:28 +08:00
parent 1412e774e3
commit 4fdf2939ad
2 changed files with 19 additions and 6 deletions

View File

@@ -2,7 +2,9 @@ package controller
import (
"fmt"
"runtime"
"be.ems/src/framework/cmd"
"be.ems/src/framework/constants"
"be.ems/src/framework/reqctx"
"be.ems/src/framework/resp"
@@ -125,9 +127,20 @@ func (s *BootloaderController) Reset(c *gin.Context) {
// return
// }
if err := machine.Reset(); err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
// 重置数据库
if runtime.GOOS == "windows" {
// return fmt.Errorf("not support window")
} else {
// 重置数据库
if _, err := cmd.Exec("/usr/local/etc/omc/script/setup.sh -i"); err != nil {
c.JSON(200, resp.ErrMsg("setup err"))
return
}
// 重启服务
if _, err := cmd.Execf("nohup sh -c \"sleep 1s && %s\" > /dev/null 2>&1 &", "sudo systemctl restart omc"); err != nil {
c.JSON(200, resp.ErrMsg("restart err"))
return
}
}
// 清除授权信息

View File

@@ -139,9 +139,9 @@ func (r *NeLicense) ReadLicenseInfo(neLicense model.NeLicense) (string, string)
}
activationRequestCode := string(bytes)
parts := strings.SplitAfter(string(bytes), "\n")
if len(parts) > 1 {
activationRequestCode = parts[1] // 获取 \n 后的内容
parts := strings.Split(activationRequestCode, "\n")
if len(parts) > 1 && strings.HasPrefix(parts[0], "SN") {
activationRequestCode = parts[1] // 获取第二行内容
}
return strings.TrimSpace(activationRequestCode), licensePath
}