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/*
|
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)
|
### 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配置文件
|
// 配置文件不存在则读取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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,38 +47,50 @@ type Licence struct {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -2,37 +2,61 @@ package utils
|
|||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
func In(target string, array []string) bool {
|
// ArrayInString 判断字符串是否存在于字符串切片中
|
||||||
target = strings.Trim(target, "")
|
// target: 待匹配的目标字符串
|
||||||
|
// array: 需要查找的字符串切片
|
||||||
|
func ArrayInString(target string, array []string) bool {
|
||||||
|
target = strings.TrimSpace(target)
|
||||||
for _, v := range array {
|
for _, v := range array {
|
||||||
if strings.Trim(v, "") == target {
|
if strings.TrimSpace(v) == target {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 字符串数组是否存在
|
// ArrayInInt 判断整数是否存在于整型切片中
|
||||||
func StrArrayIndex(items []string, item string) int {
|
// target: 待匹配的目标整数
|
||||||
for i, eachItem := range items {
|
// array: 需要查找的整型切片
|
||||||
if eachItem == item {
|
func ArrayInInt(target int, array []int) bool {
|
||||||
return i
|
for _, v := range array {
|
||||||
|
if v == target {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveRepeatSlice(in []string) (out []string) {
|
// ArrayRemoveRepeatString 去除字符串切片中的重复元素(保持原有顺序)
|
||||||
_map := make(map[string]bool)
|
// in: 原始字符串切片
|
||||||
for i := 0; i < len(in); i++ {
|
// 返回: 去重后的字符串切片
|
||||||
if in[i] != "" {
|
func ArrayRemoveRepeatString(in []string) (out []string) {
|
||||||
_map[in[i]] = true
|
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{}{}
|
||||||
for key, _ := range _map {
|
out = append(out, trimmed)
|
||||||
out = append(out, key)
|
}
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user