Compare commits

...

2 Commits

Author SHA1 Message Date
9b570c04c0 fix licence logic 2025-12-25 20:35:07 +08:00
5b824eac0b fix info output 2025-12-02 00:11:37 +08:00
2 changed files with 31 additions and 15 deletions

View File

@@ -37,6 +37,7 @@ func New(srvKey string, cfg any) {
// 配置文件不存在则读取Workspace配置文件 // 配置文件不存在则读取Workspace配置文件
if !utils.PathExists(cfp) { if !utils.PathExists(cfp) {
printer.Info("[BSM - %s] Config File: %s Not Found, Read Workspace Public Config File...", srvKey, cfp)
cfp = fmt.Sprintf("workspace_%s_%s.yaml", strings.ToLower(env.Runtime.Workspace), env.Runtime.Mode) cfp = fmt.Sprintf("workspace_%s_%s.yaml", strings.ToLower(env.Runtime.Workspace), env.Runtime.Mode)
cfp = filepath.Join(env.Runtime.Prefix, "etc", cfp) cfp = filepath.Join(env.Runtime.Prefix, "etc", cfp)
} }

View File

@@ -43,42 +43,54 @@ type MachineInfo struct {
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 授权信息 // 授权信息
type Licence struct { type Licence struct {
CompanyName string `json:"licence_to"` // 授权公司 CompanyName string `json:"licence_to"` // 授权公司
CreateDate int `json:"create"` // 生效日期 CreateDate int `json:"create"` // 生效日期
ExpireDate int `json:"expire"` // 有效期 ExpireDate int `json:"expire"` // 有效期
MachineCodes []string `json:"machine_codes"` // 机器码列表 MachineCodes []string `json:"machine_codes"` // 机器码列表
Args map[string]string `json:"args"` // 许可证相关参数定义
} }
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var ( var (
des_key string des_key string
des_iv string des_iv string
args map[string]string
Check_Licence_File bool = true // 是否检查部署授权文件 Check_Licence_File bool = true // 是否检查部署授权文件
) )
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
const ( const (
signKey = "1F36659EC27CFFF849E068EA80B1A4CA" SignKey = "1F36659EC27CFFF849E068EA80B1A4CA"
LICENCE_KEY = "BLOCKS_KEY" LicenceKey = "BLOCKS_KEY"
) )
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
func init() { func init() {
des_key = base64.StdEncoding.EncodeToString([]byte(signKey)) des_key = base64.StdEncoding.EncodeToString([]byte(SignKey))
des_iv = base64.StdEncoding.EncodeToString([]byte(signKey[:16])) des_iv = base64.StdEncoding.EncodeToString([]byte(SignKey[:16]))
} }
func WatchCheckLicence(licPath, licName string) { func WatchCheckLicence(licPath, licName string) {
utils.SetInterval(func() { utils.SetInterval(func() {
if !CheckLicence(licPath, licName) { if !CheckLicence(licPath, licName) {
log.Println("授权文件失效,请重新部署授权文件:", licPath) exit()
os.Exit(99)
} }
}, time.Hour*1) }, time.Hour*1)
} }
func GetArgs(licPath, licName string) map[string]string {
if !CheckLicence(licPath, licName) {
exit()
}
return args
}
func exit() {
log.Println("授权文件失效,请重新部署授权文件!")
os.Exit(99)
}
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
func CheckLicence(licPath, licName string) bool { func CheckLicence(licPath, licName string) bool {
// 加载授权文件 // 加载授权文件
@@ -97,6 +109,8 @@ func CheckLicence(licPath, licName string) bool {
return false return false
} }
args = l.Args
return l.VerifyLicence(licName) return l.VerifyLicence(licName)
} }
@@ -195,13 +209,14 @@ func EncryptStr(txt string) string {
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 生成授权文件 // 生成授权文件
func BuildLicence(company_name string, Create_date int, expire_date int, machine_codes []string) (string, error) { func BuildLicence(company_name string, Create_date int, expire_date int, machine_codes []string, args map[string]string) (string, error) {
// 构造licence // 构造licence
licence := &Licence{ licence := &Licence{
CompanyName: company_name, CompanyName: company_name,
CreateDate: Create_date, CreateDate: Create_date,
ExpireDate: expire_date, ExpireDate: expire_date,
MachineCodes: machine_codes, MachineCodes: machine_codes,
Args: args,
} }
content, err := json.Marshal(licence) content, err := json.Marshal(licence)
@@ -216,7 +231,7 @@ func BuildLicence(company_name string, Create_date int, expire_date int, machine
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 生成激活码 // 生成激活码
func GetLicenceCode(machinceCode string) string { func GetLicenceCode(machinceCode string) string {
return hash256(machinceCode + "&" + signKey) return hash256(machinceCode + "&" + SignKey)
} }
// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------