mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-07-30 06:04:31 +00:00
fix: ss2022 not working as expect
fix: minor bugs
This commit is contained in:
@@ -124,58 +124,42 @@ func (c *APIClient) assembleURL(path string) string {
|
|||||||
return c.APIHost + path
|
return c.APIHost + path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *APIClient) parseServerConfig(res *resty.Response, path string, err error) (*serverConfig, error) {
|
func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (*simplejson.Json, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("request %s failed: %s", c.assembleURL(path), err)
|
return nil, fmt.Errorf("request %s failed: %v", c.assembleURL(path), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode() > 399 {
|
if res.StatusCode() > 399 {
|
||||||
return nil, fmt.Errorf("request %s failed: %s, %s", c.assembleURL(path), res.String(), err)
|
return nil, fmt.Errorf("request %s failed: %s, %v", c.assembleURL(path), res.String(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := new(serverConfig)
|
rtn, err := simplejson.NewJson(res.Body())
|
||||||
if err := json.Unmarshal(res.Body(), s); err != nil {
|
|
||||||
return nil, fmt.Errorf("ret %s invalid", res.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.ServerPort == 0 {
|
|
||||||
return nil, errors.New("server port must > 0")
|
|
||||||
}
|
|
||||||
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
func (c *APIClient) parseUsers(res *resty.Response, path string, err error) ([]*user, error) {
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("request %s failed: %s", c.assembleURL(path), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.StatusCode() > 399 {
|
|
||||||
return nil, fmt.Errorf("request %s failed: %s, %s", c.assembleURL(path), res.String(), err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var users []*user
|
|
||||||
if data, err := simplejson.NewJson(res.Body()); err != nil {
|
|
||||||
return nil, fmt.Errorf("ret %s invalid", res.String())
|
return nil, fmt.Errorf("ret %s invalid", res.String())
|
||||||
} else {
|
|
||||||
b, _ := data.Get("users").MarshalJSON()
|
|
||||||
json.Unmarshal(b, &users)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return users, nil
|
return rtn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNodeInfo will pull NodeInfo Config from panel
|
// GetNodeInfo will pull NodeInfo Config from panel
|
||||||
func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
||||||
|
server := new(serverConfig)
|
||||||
path := "/api/v1/server/UniProxy/config"
|
path := "/api/v1/server/UniProxy/config"
|
||||||
|
|
||||||
res, err := c.client.R().
|
res, err := c.client.R().
|
||||||
ForceContentType("application/json").
|
ForceContentType("application/json").
|
||||||
Get(path)
|
Get(path)
|
||||||
|
|
||||||
server, err := c.parseServerConfig(res, path, err)
|
nodeInfoResp, err := c.parseResponse(res, path, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
b, _ := nodeInfoResp.Encode()
|
||||||
|
json.Unmarshal(b, server)
|
||||||
|
|
||||||
|
if server.ServerPort == 0 {
|
||||||
|
return nil, errors.New("server port must > 0")
|
||||||
|
}
|
||||||
|
|
||||||
c.resp.Store(server)
|
c.resp.Store(server)
|
||||||
|
|
||||||
@@ -191,7 +175,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("parse node info failed: %s, \nError: %s", res.String(), err)
|
return nil, fmt.Errorf("parse node info failed: %s, \nError: %v", res.String(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeInfo, nil
|
return nodeInfo, nil
|
||||||
@@ -199,6 +183,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
|
|
||||||
// GetUserList will pull user form panel
|
// GetUserList will pull user form panel
|
||||||
func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
||||||
|
var users []*user
|
||||||
path := "/api/v1/server/UniProxy/user"
|
path := "/api/v1/server/UniProxy/user"
|
||||||
|
|
||||||
switch c.NodeType {
|
switch c.NodeType {
|
||||||
@@ -222,10 +207,12 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
c.eTag = res.Header().Get("Etag")
|
c.eTag = res.Header().Get("Etag")
|
||||||
}
|
}
|
||||||
|
|
||||||
users, err := c.parseUsers(res, path, err)
|
usersResp, err := c.parseResponse(res, path, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
b, _ := usersResp.Get("users").Encode()
|
||||||
|
json.Unmarshal(b, &users)
|
||||||
|
|
||||||
userList := make([]api.UserInfo, len(users))
|
userList := make([]api.UserInfo, len(users))
|
||||||
for i := 0; i < len(users); i++ {
|
for i := 0; i < len(users); i++ {
|
||||||
@@ -262,11 +249,8 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
|
|||||||
data[traffic.UID] = []int64{traffic.Upload, traffic.Download}
|
data[traffic.UID] = []int64{traffic.Upload, traffic.Download}
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.client.R().
|
res, err := c.client.R().SetBody(data).ForceContentType("application/json").Post(path)
|
||||||
SetBody(data).
|
_, err = c.parseResponse(res, path, err)
|
||||||
ForceContentType("application/json").
|
|
||||||
Post(path)
|
|
||||||
_, err = c.parseServerConfig(res, path, err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -336,13 +320,16 @@ func (c *APIClient) parseSSNodeResponse(s *serverConfig) (*api.NodeInfo, error)
|
|||||||
if s.Obfs == "http" {
|
if s.Obfs == "http" {
|
||||||
path := "/"
|
path := "/"
|
||||||
if p := s.ObfsSettings.Path; p != "" {
|
if p := s.ObfsSettings.Path; p != "" {
|
||||||
path = p
|
if strings.HasPrefix(p, "/") {
|
||||||
|
path = p
|
||||||
|
} else {
|
||||||
|
path += p
|
||||||
|
}
|
||||||
}
|
}
|
||||||
header, _ = json.Marshal(map[string]any{
|
h := simplejson.New()
|
||||||
"type": "http",
|
h.Set("type", "http")
|
||||||
"request": map[string]any{
|
h.SetPath([]string{"request", "path"}, path)
|
||||||
"path": path,
|
header, _ = h.Encode()
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
// Create GeneralNodeInfo
|
// Create GeneralNodeInfo
|
||||||
return &api.NodeInfo{
|
return &api.NodeInfo{
|
||||||
@@ -360,11 +347,10 @@ func (c *APIClient) parseSSNodeResponse(s *serverConfig) (*api.NodeInfo, error)
|
|||||||
// parseV2rayNodeResponse parse the response for the given nodeInfo format
|
// parseV2rayNodeResponse parse the response for the given nodeInfo format
|
||||||
func (c *APIClient) parseV2rayNodeResponse(s *serverConfig) (*api.NodeInfo, error) {
|
func (c *APIClient) parseV2rayNodeResponse(s *serverConfig) (*api.NodeInfo, error) {
|
||||||
var (
|
var (
|
||||||
TLSType = "tls"
|
TLSType = "tls"
|
||||||
path, host, serviceName string
|
host string
|
||||||
header json.RawMessage
|
header json.RawMessage
|
||||||
enableTLS bool
|
enableTLS bool
|
||||||
alterID uint16 = 0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if c.EnableXTLS {
|
if c.EnableXTLS {
|
||||||
@@ -375,18 +361,13 @@ func (c *APIClient) parseV2rayNodeResponse(s *serverConfig) (*api.NodeInfo, erro
|
|||||||
if httpHeader, err := s.NetworkSettings.Headers.MarshalJSON(); err != nil {
|
if httpHeader, err := s.NetworkSettings.Headers.MarshalJSON(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
header = httpHeader
|
switch s.Network {
|
||||||
}
|
case "ws":
|
||||||
}
|
b, _ := simplejson.NewJson(httpHeader)
|
||||||
|
host = b.Get("Host").MustString()
|
||||||
switch s.Network {
|
case "tcp":
|
||||||
case "ws":
|
header = httpHeader
|
||||||
path = s.NetworkSettings.Path
|
}
|
||||||
b, _ := simplejson.NewJson(header)
|
|
||||||
host = b.Get("Host").MustString()
|
|
||||||
case "grpc":
|
|
||||||
if s.NetworkSettings.ServiceName != "" {
|
|
||||||
serviceName = s.NetworkSettings.ServiceName
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,14 +380,14 @@ func (c *APIClient) parseV2rayNodeResponse(s *serverConfig) (*api.NodeInfo, erro
|
|||||||
NodeType: c.NodeType,
|
NodeType: c.NodeType,
|
||||||
NodeID: c.NodeID,
|
NodeID: c.NodeID,
|
||||||
Port: uint32(s.ServerPort),
|
Port: uint32(s.ServerPort),
|
||||||
AlterID: alterID,
|
AlterID: 0,
|
||||||
TransportProtocol: s.Network,
|
TransportProtocol: s.Network,
|
||||||
EnableTLS: enableTLS,
|
EnableTLS: enableTLS,
|
||||||
TLSType: TLSType,
|
TLSType: TLSType,
|
||||||
Path: path,
|
Path: s.NetworkSettings.Path,
|
||||||
Host: host,
|
Host: host,
|
||||||
EnableVless: c.EnableVless,
|
EnableVless: c.EnableVless,
|
||||||
ServiceName: serviceName,
|
ServiceName: s.NetworkSettings.ServiceName,
|
||||||
Header: header,
|
Header: header,
|
||||||
NameServerConfig: s.parseDNSConfig(),
|
NameServerConfig: s.parseDNSConfig(),
|
||||||
}, nil
|
}, nil
|
||||||
|
@@ -168,7 +168,7 @@ func (c *Controller) buildUserTag(user *api.UserInfo) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) checkShadowsocksPassword(password string, method string) (string, error) {
|
func (c *Controller) checkShadowsocksPassword(password string, method string) (string, error) {
|
||||||
if c.panelType == "V2board" {
|
if strings.Contains(c.panelType, "V2board") {
|
||||||
var userKey string
|
var userKey string
|
||||||
if len(password) < 16 {
|
if len(password) < 16 {
|
||||||
return "", fmt.Errorf("shadowsocks2022 key's length must be greater than 16")
|
return "", fmt.Errorf("shadowsocks2022 key's length must be greater than 16")
|
||||||
|
Reference in New Issue
Block a user