2023-07-19 16:25:41 +08:00
|
|
|
package client
|
|
|
|
|
2023-08-21 11:32:11 +08:00
|
|
|
import (
|
2023-09-07 15:16:11 +08:00
|
|
|
mathRand "math/rand"
|
2023-08-21 11:32:11 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
|
|
|
)
|
|
|
|
|
2023-07-19 16:25:41 +08:00
|
|
|
type DBInfo struct {
|
2023-07-21 18:28:45 +08:00
|
|
|
From string `json:"from"`
|
2023-08-31 17:22:12 +08:00
|
|
|
Database string `json:"database"`
|
2023-07-19 16:25:41 +08:00
|
|
|
Address string `json:"address"`
|
|
|
|
Port uint `json:"port"`
|
2023-07-20 17:51:57 +08:00
|
|
|
Username string `json:"userName"`
|
2023-07-19 16:25:41 +08:00
|
|
|
Password string `json:"password"`
|
|
|
|
|
|
|
|
Timeout uint `json:"timeout"` // second
|
|
|
|
}
|
|
|
|
|
|
|
|
type CreateInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Format string `json:"format"`
|
|
|
|
Version string `json:"version"`
|
2023-07-20 17:51:57 +08:00
|
|
|
Username string `json:"userName"`
|
2023-07-19 16:25:41 +08:00
|
|
|
Password string `json:"password"`
|
|
|
|
Permission string `json:"permission"`
|
|
|
|
|
|
|
|
Timeout uint `json:"timeout"` // second
|
|
|
|
}
|
|
|
|
|
|
|
|
type DeleteInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Version string `json:"version"`
|
2023-07-20 17:51:57 +08:00
|
|
|
Username string `json:"userName"`
|
2023-07-19 16:25:41 +08:00
|
|
|
Permission string `json:"permission"`
|
|
|
|
|
|
|
|
ForceDelete bool `json:"forceDelete"`
|
|
|
|
Timeout uint `json:"timeout"` // second
|
|
|
|
}
|
|
|
|
|
|
|
|
type PasswordChangeInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Version string `json:"version"`
|
2023-07-20 17:51:57 +08:00
|
|
|
Username string `json:"userName"`
|
2023-07-19 16:25:41 +08:00
|
|
|
Password string `json:"password"`
|
|
|
|
Permission string `json:"permission"`
|
|
|
|
|
|
|
|
Timeout uint `json:"timeout"` // second
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccessChangeInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Version string `json:"version"`
|
2023-07-20 17:51:57 +08:00
|
|
|
Username string `json:"userName"`
|
2023-07-21 18:28:45 +08:00
|
|
|
Password string `json:"password"`
|
2023-07-19 16:25:41 +08:00
|
|
|
OldPermission string `json:"oldPermission"`
|
|
|
|
Permission string `json:"permission"`
|
|
|
|
|
|
|
|
Timeout uint `json:"timeout"` // second
|
|
|
|
}
|
|
|
|
|
2023-07-25 17:08:13 +08:00
|
|
|
type BackupInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Format string `json:"format"`
|
|
|
|
TargetDir string `json:"targetDir"`
|
2023-07-27 14:32:23 +08:00
|
|
|
FileName string `json:"fileName"`
|
2023-07-25 17:08:13 +08:00
|
|
|
|
|
|
|
Timeout uint `json:"timeout"` // second
|
|
|
|
}
|
|
|
|
|
|
|
|
type RecoverInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Format string `json:"format"`
|
|
|
|
SourceFile string `json:"sourceFile"`
|
|
|
|
|
|
|
|
Timeout uint `json:"timeout"` // second
|
|
|
|
}
|
|
|
|
|
2023-07-27 16:07:27 +08:00
|
|
|
type SyncDBInfo struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
From string `json:"from"`
|
|
|
|
Format string `json:"format"`
|
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
Permission string `json:"permission"`
|
|
|
|
}
|
|
|
|
|
2023-07-19 16:25:41 +08:00
|
|
|
var formatMap = map[string]string{
|
|
|
|
"utf8": "utf8_general_ci",
|
|
|
|
"utf8mb4": "utf8mb4_general_ci",
|
|
|
|
"gbk": "gbk_chinese_ci",
|
|
|
|
"big5": "big5_chinese_ci",
|
|
|
|
}
|
2023-08-21 11:32:11 +08:00
|
|
|
|
|
|
|
func loadNameByDB(name, version string) string {
|
2023-09-07 15:16:11 +08:00
|
|
|
nameItem := common.ConvertToPinyin(name)
|
2023-08-21 11:32:11 +08:00
|
|
|
if strings.HasPrefix(version, "5.6") {
|
2023-09-07 15:16:11 +08:00
|
|
|
if len(nameItem) <= 16 {
|
|
|
|
return nameItem
|
2023-08-21 11:32:11 +08:00
|
|
|
}
|
2023-09-07 15:16:11 +08:00
|
|
|
return strings.TrimSuffix(nameItem[:10], "_") + "_" + common.RandStr(5)
|
2023-08-21 11:32:11 +08:00
|
|
|
}
|
2023-09-07 15:16:11 +08:00
|
|
|
if len(nameItem) <= 32 {
|
|
|
|
return nameItem
|
2023-08-21 11:32:11 +08:00
|
|
|
}
|
2023-09-07 15:16:11 +08:00
|
|
|
return strings.TrimSuffix(nameItem[:25], "_") + "_" + common.RandStr(5)
|
|
|
|
}
|
|
|
|
|
|
|
|
func randomPassword(user string) string {
|
|
|
|
passwdItem := user
|
|
|
|
if len(user) > 6 {
|
|
|
|
passwdItem = user[:6]
|
|
|
|
}
|
|
|
|
num := []rune("1234567890")
|
|
|
|
uppercase := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
lowercase := []rune("abcdefghijklmnopqrstuvwxyz")
|
|
|
|
special := []rune(".%@!~_-")
|
|
|
|
|
|
|
|
b := make([]rune, 10)
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
b[i] = lowercase[mathRand.Intn(len(lowercase))]
|
|
|
|
}
|
|
|
|
for i := 2; i < 4; i++ {
|
|
|
|
b[i] = uppercase[mathRand.Intn(len(uppercase))]
|
|
|
|
}
|
|
|
|
b[4] = special[mathRand.Intn(len(special))]
|
|
|
|
for i := 5; i < 9; i++ {
|
|
|
|
b[i] = num[mathRand.Intn(len(num))]
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := len(b) - 1; i > 0; i-- {
|
|
|
|
j := mathRand.Intn(i + 1)
|
|
|
|
b[i], b[j] = b[j], b[i]
|
|
|
|
}
|
|
|
|
return passwdItem + "-" + (string(b))
|
2023-08-21 11:32:11 +08:00
|
|
|
}
|