mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-12-17 04:34:40 +03:00
api (#3434)
Some checks failed
Release 3X-UI / build (386) (push) Has been cancelled
Release 3X-UI / build (amd64) (push) Has been cancelled
Release 3X-UI / build (arm64) (push) Has been cancelled
Release 3X-UI / build (armv5) (push) Has been cancelled
Release 3X-UI / build (armv6) (push) Has been cancelled
Release 3X-UI / build (armv7) (push) Has been cancelled
Release 3X-UI / build (s390x) (push) Has been cancelled
Some checks failed
Release 3X-UI / build (386) (push) Has been cancelled
Release 3X-UI / build (amd64) (push) Has been cancelled
Release 3X-UI / build (arm64) (push) Has been cancelled
Release 3X-UI / build (armv5) (push) Has been cancelled
Release 3X-UI / build (armv6) (push) Has been cancelled
Release 3X-UI / build (armv7) (push) Has been cancelled
Release 3X-UI / build (s390x) (push) Has been cancelled
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"x-ui/util/sys"
|
||||
"x-ui/xray"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/shirou/gopsutil/v4/cpu"
|
||||
"github.com/shirou/gopsutil/v4/disk"
|
||||
"github.com/shirou/gopsutil/v4/host"
|
||||
@@ -872,12 +873,6 @@ func (s *ServerService) GetNewEchCert(sni string) (interface{}, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
type AuthBlock struct {
|
||||
Label string `json:"label"`
|
||||
Decryption string `json:"decryption"`
|
||||
Encryption string `json:"encryption"`
|
||||
}
|
||||
|
||||
func (s *ServerService) GetNewVlessEnc() (any, error) {
|
||||
cmd := exec.Command(xray.GetBinaryPath(), "vlessenc")
|
||||
var out bytes.Buffer
|
||||
@@ -887,37 +882,70 @@ func (s *ServerService) GetNewVlessEnc() (any, error) {
|
||||
}
|
||||
|
||||
lines := strings.Split(out.String(), "\n")
|
||||
|
||||
var blocks []AuthBlock
|
||||
var current *AuthBlock
|
||||
var auths []map[string]string
|
||||
var current map[string]string
|
||||
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "Authentication:") {
|
||||
if current != nil {
|
||||
blocks = append(blocks, *current)
|
||||
auths = append(auths, current)
|
||||
}
|
||||
current = map[string]string{
|
||||
"label": strings.TrimSpace(strings.TrimPrefix(line, "Authentication:")),
|
||||
}
|
||||
current = &AuthBlock{Label: strings.TrimSpace(strings.TrimPrefix(line, "Authentication:"))}
|
||||
} else if strings.HasPrefix(line, `"decryption"`) || strings.HasPrefix(line, `"encryption"`) {
|
||||
parts := strings.SplitN(line, ":", 2)
|
||||
if len(parts) == 2 && current != nil {
|
||||
key := strings.Trim(parts[0], `" `)
|
||||
val := strings.Trim(parts[1], `" `)
|
||||
switch key {
|
||||
case "decryption":
|
||||
current.Decryption = val
|
||||
case "encryption":
|
||||
current.Encryption = val
|
||||
}
|
||||
current[key] = val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if current != nil {
|
||||
blocks = append(blocks, *current)
|
||||
auths = append(auths, current)
|
||||
}
|
||||
|
||||
return map[string]any{
|
||||
"auths": blocks,
|
||||
"auths": auths,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *ServerService) GetNewUUID() (map[string]string, error) {
|
||||
newUUID, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate UUID: %w", err)
|
||||
}
|
||||
|
||||
return map[string]string{
|
||||
"uuid": newUUID.String(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *ServerService) GetNewmlkem768() (any, error) {
|
||||
// Run the command
|
||||
cmd := exec.Command(xray.GetBinaryPath(), "mlkem768")
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lines := strings.Split(out.String(), "\n")
|
||||
|
||||
SeedLine := strings.Split(lines[0], ":")
|
||||
ClientLine := strings.Split(lines[1], ":")
|
||||
|
||||
seed := strings.TrimSpace(SeedLine[1])
|
||||
client := strings.TrimSpace(ClientLine[1])
|
||||
|
||||
keyPair := map[string]any{
|
||||
"seed": seed,
|
||||
"client": client,
|
||||
}
|
||||
|
||||
return keyPair, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user