代码提交
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"stat/statg"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/xxjwxc/public/myglobal/snowflake"
|
||||
)
|
||||
|
||||
@@ -51,7 +52,54 @@ func GenerateConfigFile(origin, target, configFile, DC, PC string) ([]byte, stri
|
||||
if err != nil {
|
||||
output, _ = os.ReadFile("conf/" + configFile)
|
||||
}
|
||||
return output, configFile
|
||||
return uniqueProfileIdentity(output, configFile), configFile
|
||||
}
|
||||
|
||||
// profileIDNamespace 标识符派生的固定命名空间,保证同一模板每次生成的值一致
|
||||
var profileIDNamespace = uuid.NewSHA1(uuid.NameSpaceURL, []byte("stat_center/mobileconfig"))
|
||||
|
||||
var (
|
||||
rePayloadIdent = regexp.MustCompile(`(<key>PayloadIdentifier</key>[ \t]*\r?\n[ \t]*<string>)([^<]*)(</string>)`)
|
||||
rePayloadUUID = regexp.MustCompile(`(<key>PayloadUUID</key>[ \t]*\r?\n[ \t]*<string>)([^<]*)(</string>)`)
|
||||
reUUIDValue = regexp.MustCompile(`[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}`)
|
||||
)
|
||||
|
||||
// uniqueProfileIdentity 把 mobileconfig 里的 PayloadIdentifier/PayloadUUID 改写成按 configFile 派生的值。
|
||||
// conf 下各 app 的模板是互相复制出来的,标识符完全相同,而 iOS 按顶层 PayloadIdentifier 判重:
|
||||
// 相同即替换已安装的描述文件,用户装了第二个 app 第一个就没了。
|
||||
// 按 configFile 派生可保证各 app 互不覆盖;同一 app 多次下载得到相同标识符,
|
||||
// 重复安装只覆盖自己,不会在桌面堆出一排图标。
|
||||
func uniqueProfileIdentity(data []byte, configFile string) []byte {
|
||||
if len(data) == 0 {
|
||||
return data
|
||||
}
|
||||
derive := func(i int) string {
|
||||
return uuid.NewSHA1(profileIDNamespace, []byte(fmt.Sprintf("%s#%d", configFile, i))).String()
|
||||
}
|
||||
|
||||
n := 0
|
||||
data = rePayloadUUID.ReplaceAllFunc(data, func(m []byte) []byte {
|
||||
g := rePayloadUUID.FindSubmatch(m)
|
||||
v := derive(n)
|
||||
n++
|
||||
return []byte(string(g[1]) + v + string(g[3]))
|
||||
})
|
||||
|
||||
// 第 i 个 PayloadIdentifier 与第 i 个 PayloadUUID 共用派生值,保留原前缀(luli. / com.apple.webClip.managed.)
|
||||
i := 0
|
||||
data = rePayloadIdent.ReplaceAllFunc(data, func(m []byte) []byte {
|
||||
g := rePayloadIdent.FindSubmatch(m)
|
||||
v := derive(i)
|
||||
i++
|
||||
val := g[2]
|
||||
if reUUIDValue.Match(val) {
|
||||
val = reUUIDValue.ReplaceAll(val, []byte(v))
|
||||
} else {
|
||||
val = []byte(string(val) + "." + v)
|
||||
}
|
||||
return []byte(string(g[1]) + string(val) + string(g[3]))
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
func GetAppConfig(appId int32) (origin, target, config string) {
|
||||
|
||||
Reference in New Issue
Block a user