Compare commits

..

1 Commits

Author SHA1 Message Date
9b570c04c0 fix licence logic 2025-12-25 20:35:07 +08:00

View File

@@ -43,42 +43,54 @@ type MachineInfo struct {
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 授权信息
type Licence struct {
CompanyName string `json:"licence_to"` // 授权公司
CreateDate int `json:"create"` // 生效日期
ExpireDate int `json:"expire"` // 有效期
MachineCodes []string `json:"machine_codes"` // 机器码列表
CompanyName string `json:"licence_to"` // 授权公司
CreateDate int `json:"create"` // 生效日期
ExpireDate int `json:"expire"` // 有效期
MachineCodes []string `json:"machine_codes"` // 机器码列表
Args map[string]string `json:"args"` // 许可证相关参数定义
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
var (
des_key string
des_iv string
des_key string
des_iv string
args map[string]string
Check_Licence_File bool = true // 是否检查部署授权文件
)
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
const (
signKey = "1F36659EC27CFFF849E068EA80B1A4CA"
LICENCE_KEY = "BLOCKS_KEY"
SignKey = "1F36659EC27CFFF849E068EA80B1A4CA"
LicenceKey = "BLOCKS_KEY"
)
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
func init() {
des_key = base64.StdEncoding.EncodeToString([]byte(signKey))
des_iv = base64.StdEncoding.EncodeToString([]byte(signKey[:16]))
des_key = base64.StdEncoding.EncodeToString([]byte(SignKey))
des_iv = base64.StdEncoding.EncodeToString([]byte(SignKey[:16]))
}
func WatchCheckLicence(licPath, licName string) {
utils.SetInterval(func() {
if !CheckLicence(licPath, licName) {
log.Println("授权文件失效,请重新部署授权文件:", licPath)
os.Exit(99)
exit()
}
}, 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 {
// 加载授权文件
@@ -97,6 +109,8 @@ func CheckLicence(licPath, licName string) bool {
return false
}
args = l.Args
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{
CompanyName: company_name,
CreateDate: Create_date,
ExpireDate: expire_date,
MachineCodes: machine_codes,
Args: args,
}
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 {
return hash256(machinceCode + "&" + signKey)
return hash256(machinceCode + "&" + SignKey)
}
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------