Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d88178458d | |||
| 9b570c04c0 | |||
| 5b824eac0b | |||
| df56cb550e |
18
README.md
18
README.md
@@ -11,6 +11,16 @@ go env -w GOINSECURE=git.apinb.com/*
|
||||
go env -w GONOSUMDB=git.apinb.com/*
|
||||
```
|
||||
|
||||
### 配置环境变量
|
||||
|
||||
```bash
|
||||
export BSM_Workspace=def
|
||||
export BSM_JwtSecretKey=your_secret_key
|
||||
export BSM_RuntimeMode=dev
|
||||
export BSM_Prefix=/usr/local/bsm
|
||||
```
|
||||
|
||||
|
||||
## 核心功能模块
|
||||
|
||||
### 1. 服务管理 (service)
|
||||
@@ -321,14 +331,6 @@ go env -w GONOSUMDB=git.apinb.com/*
|
||||
- 支持许可证文件验证
|
||||
|
||||
|
||||
### 配置环境变量
|
||||
|
||||
```bash
|
||||
export BSM_Workspace=def
|
||||
export BSM_JwtSecretKey=your_secret_key
|
||||
export BSM_RuntimeMode=dev
|
||||
export BSM_Prefix=/usr/local/bsm
|
||||
```
|
||||
|
||||
### 安全建议
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ func New(srvKey string, cfg any) {
|
||||
|
||||
// 配置文件不存在则读取Workspace配置文件
|
||||
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 = filepath.Join(env.Runtime.Prefix, "etc", cfp)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -2,37 +2,61 @@ package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
func In(target string, array []string) bool {
|
||||
target = strings.Trim(target, "")
|
||||
// ArrayInString 判断字符串是否存在于字符串切片中
|
||||
// target: 待匹配的目标字符串
|
||||
// array: 需要查找的字符串切片
|
||||
func ArrayInString(target string, array []string) bool {
|
||||
target = strings.TrimSpace(target)
|
||||
for _, v := range array {
|
||||
if strings.Trim(v, "") == target {
|
||||
if strings.TrimSpace(v) == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 字符串数组是否存在
|
||||
func StrArrayIndex(items []string, item string) int {
|
||||
for i, eachItem := range items {
|
||||
if eachItem == item {
|
||||
return i
|
||||
// ArrayInInt 判断整数是否存在于整型切片中
|
||||
// target: 待匹配的目标整数
|
||||
// array: 需要查找的整型切片
|
||||
func ArrayInInt(target int, array []int) bool {
|
||||
for _, v := range array {
|
||||
if v == target {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return -1
|
||||
return false
|
||||
}
|
||||
|
||||
func RemoveRepeatSlice(in []string) (out []string) {
|
||||
_map := make(map[string]bool)
|
||||
for i := 0; i < len(in); i++ {
|
||||
if in[i] != "" {
|
||||
_map[in[i]] = true
|
||||
// ArrayRemoveRepeatString 去除字符串切片中的重复元素(保持原有顺序)
|
||||
// in: 原始字符串切片
|
||||
// 返回: 去重后的字符串切片
|
||||
func ArrayRemoveRepeatString(in []string) (out []string) {
|
||||
seen := make(map[string]struct{})
|
||||
for _, v := range in {
|
||||
trimmed := strings.TrimSpace(v)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[trimmed]; ok {
|
||||
continue
|
||||
}
|
||||
seen[trimmed] = struct{}{}
|
||||
out = append(out, trimmed)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ArrayRemoveRepeatInt 去除整型切片中的重复元素(保持原有顺序)
|
||||
// in: 原始整型切片
|
||||
// 返回: 去重后的整型切片
|
||||
func ArrayRemoveRepeatInt(in []int) (out []int) {
|
||||
seen := make(map[int]struct{})
|
||||
for _, v := range in {
|
||||
if _, ok := seen[v]; ok {
|
||||
continue
|
||||
}
|
||||
seen[v] = struct{}{}
|
||||
out = append(out, v)
|
||||
}
|
||||
|
||||
for key, _ := range _map {
|
||||
out = append(out, key)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user