mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-06-08 13:29:54 +00:00
fix: typo
This commit is contained in:
parent
209f5a17d6
commit
ddce3fa86d
22
README.md
22
README.md
@ -34,30 +34,30 @@ A Xray backend framework that can easily support many panels.
|
|||||||
|
|
||||||
## 功能介绍
|
## 功能介绍
|
||||||
|
|
||||||
| 功能 | v2ray | trojan | shadowsocks |
|
| 功能 | v2ray | trojan | shadowsocks |
|
||||||
| --------------- | ----- | ------ | ----------- |
|
|-----------|-------|--------|-------------|
|
||||||
| 获取节点信息 | √ | √ | √ |
|
| 获取节点信息 | √ | √ | √ |
|
||||||
| 获取用户信息 | √ | √ | √ |
|
| 获取用户信息 | √ | √ | √ |
|
||||||
| 用户流量统计 | √ | √ | √ |
|
| 用户流量统计 | √ | √ | √ |
|
||||||
| 服务器信息上报 | √ | √ | √ |
|
| 服务器信息上报 | √ | √ | √ |
|
||||||
| 自动申请tls证书 | √ | √ | √ |
|
| 自动申请tls证书 | √ | √ | √ |
|
||||||
| 自动续签tls证书 | √ | √ | √ |
|
| 自动续签tls证书 | √ | √ | √ |
|
||||||
| 在线人数统计 | √ | √ | √ |
|
| 在线人数统计 | √ | √ | √ |
|
||||||
| 在线用户限制 | √ | √ | √ |
|
| 在线用户限制 | √ | √ | √ |
|
||||||
| 审计规则 | √ | √ | √ |
|
| 审计规则 | √ | √ | √ |
|
||||||
| 节点端口限速 | √ | √ | √ |
|
| 节点端口限速 | √ | √ | √ |
|
||||||
| 按照用户限速 | √ | √ | √ |
|
| 按照用户限速 | √ | √ | √ |
|
||||||
| 自定义DNS | √ | √ | √ |
|
| 自定义DNS | √ | √ | √ |
|
||||||
|
|
||||||
## 支持前端
|
## 支持前端
|
||||||
|
|
||||||
| 前端 | v2ray | trojan | shadowsocks |
|
| 前端 | v2ray | trojan | shadowsocks |
|
||||||
| ------------------------------------------------------ | ----- | ------ | ------------------------------ |
|
|--------------------------------------------------------|-------|--------|-------------------------|
|
||||||
| sspanel-uim | √ | √ | √ (单端口多用户和V2ray-Plugin) |
|
| sspanel-uim | √ | √ | √ (单端口多用户和V2ray-Plugin) |
|
||||||
| v2board | √ | √ | √ |
|
| v2board | √ | √ | √ |
|
||||||
| [PMPanel](https://github.com/ByteInternetHK/PMPanel) | √ | √ | √ |
|
| [PMPanel](https://github.com/ByteInternetHK/PMPanel) | √ | √ | √ |
|
||||||
| [ProxyPanel](https://github.com/ProxyPanel/ProxyPanel) | √ | √ | √ |
|
| [ProxyPanel](https://github.com/ProxyPanel/ProxyPanel) | √ | √ | √ |
|
||||||
| [WHMCS (V2RaySocks)](https://v2raysocks.doxtex.com/) | √ | √ | √ |
|
| [WHMCS (V2RaySocks)](https://v2raysocks.doxtex.com/) | √ | √ | √ |
|
||||||
|
|
||||||
## 软件安装
|
## 软件安装
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// API config
|
// Config API config
|
||||||
type Config struct {
|
type Config struct {
|
||||||
APIHost string `mapstructure:"ApiHost"`
|
APIHost string `mapstructure:"ApiHost"`
|
||||||
NodeID int `mapstructure:"NodeID"`
|
NodeID int `mapstructure:"NodeID"`
|
||||||
@ -20,7 +20,7 @@ type Config struct {
|
|||||||
DisableCustomConfig bool `mapstructure:"DisableCustomConfig"`
|
DisableCustomConfig bool `mapstructure:"DisableCustomConfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node status
|
// NodeStatus Node status
|
||||||
type NodeStatus struct {
|
type NodeStatus struct {
|
||||||
CPU float64
|
CPU float64
|
||||||
Mem float64
|
Mem float64
|
||||||
|
@ -16,7 +16,7 @@ type NodeInfoResponse struct {
|
|||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Grpc bool `json:"grpc"`
|
Grpc bool `json:"grpc"`
|
||||||
Sni string `json:sni`
|
Sni string `json:"sni"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserResponse is the response of user
|
// UserResponse is the response of user
|
||||||
|
@ -95,7 +95,7 @@ func readLocalRuleList(path string) (LocalRuleList []api.DetectRule) {
|
|||||||
// handle first encountered error while reading
|
// handle first encountered error while reading
|
||||||
if err := fileScanner.Err(); err != nil {
|
if err := fileScanner.Err(); err != nil {
|
||||||
log.Fatalf("Error while reading file: %s", err)
|
log.Fatalf("Error while reading file: %s", err)
|
||||||
return make([]api.DetectRule, 0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Close()
|
file.Close()
|
||||||
@ -131,7 +131,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (
|
|||||||
|
|
||||||
if response.Ret != 200 {
|
if response.Ret != 200 {
|
||||||
res, _ := json.Marshal(&response)
|
res, _ := json.Marshal(&response)
|
||||||
return nil, fmt.Errorf("Ret %s invalid", string(res))
|
return nil, fmt.Errorf("ret %s invalid", string(res))
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
nodeInfoResponse := new(NodeInfoResponse)
|
nodeInfoResponse := new(NodeInfoResponse)
|
||||||
|
|
||||||
if err := json.Unmarshal(response.Data, nodeInfoResponse); err != nil {
|
if err := json.Unmarshal(response.Data, nodeInfoResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(nodeInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(nodeInfoResponse), err)
|
||||||
}
|
}
|
||||||
switch c.NodeType {
|
switch c.NodeType {
|
||||||
case "V2ray":
|
case "V2ray":
|
||||||
@ -178,7 +178,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
nodeInfo, err = c.ParseSSNodeResponse(nodeInfoResponse)
|
nodeInfo, err = c.ParseSSNodeResponse(nodeInfoResponse)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -220,12 +220,12 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
|
|
||||||
var userListResponse *[]UserResponse
|
var userListResponse *[]UserResponse
|
||||||
if err := json.Unmarshal(response.Data, &userListResponse); err != nil {
|
if err := json.Unmarshal(response.Data, &userListResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(userListResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(userListResponse), err)
|
||||||
}
|
}
|
||||||
userList, err := c.ParseUserListResponse(userListResponse)
|
userList, err := c.ParseUserListResponse(userListResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res, _ := json.Marshal(userListResponse)
|
res, _ := json.Marshal(userListResponse)
|
||||||
return nil, fmt.Errorf("Parse user list failed: %s", string(res))
|
return nil, fmt.Errorf("parse user list failed: %s", string(res))
|
||||||
}
|
}
|
||||||
return userList, nil
|
return userList, nil
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
|
|||||||
ruleListResponse := new([]RuleItem)
|
ruleListResponse := new([]RuleItem)
|
||||||
|
|
||||||
if err := json.Unmarshal(response.Data, ruleListResponse); err != nil {
|
if err := json.Unmarshal(response.Data, ruleListResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(ruleListResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(ruleListResponse), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range *ruleListResponse {
|
for _, r := range *ruleListResponse {
|
||||||
@ -473,7 +473,7 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *NodeInfoResponse)
|
|||||||
|
|
||||||
// ParseUserListResponse parse the response for the given nodeinfo format
|
// ParseUserListResponse parse the response for the given nodeinfo format
|
||||||
func (c *APIClient) ParseUserListResponse(userInfoResponse *[]UserResponse) (*[]api.UserInfo, error) {
|
func (c *APIClient) ParseUserListResponse(userInfoResponse *[]UserResponse) (*[]api.UserInfo, error) {
|
||||||
var deviceLimit int = 0
|
var deviceLimit = 0
|
||||||
var speedlimit uint64 = 0
|
var speedlimit uint64 = 0
|
||||||
userList := make([]api.UserInfo, len(*userInfoResponse))
|
userList := make([]api.UserInfo, len(*userInfoResponse))
|
||||||
for i, user := range *userInfoResponse {
|
for i, user := range *userInfoResponse {
|
||||||
|
@ -85,7 +85,7 @@ func TestGetUserList(t *testing.T) {
|
|||||||
func TestReportNodeStatus(t *testing.T) {
|
func TestReportNodeStatus(t *testing.T) {
|
||||||
client := CreateClient()
|
client := CreateClient()
|
||||||
nodeStatus := &api.NodeStatus{
|
nodeStatus := &api.NodeStatus{
|
||||||
1, 1, 1, 256,
|
CPU: 1, Mem: 1, Disk: 1, Uptime: 256,
|
||||||
}
|
}
|
||||||
err := client.ReportNodeStatus(nodeStatus)
|
err := client.ReportNodeStatus(nodeStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -150,8 +150,8 @@ func TestReportIllegal(t *testing.T) {
|
|||||||
client := CreateClient()
|
client := CreateClient()
|
||||||
|
|
||||||
detectResult := []api.DetectResult{
|
detectResult := []api.DetectResult{
|
||||||
api.DetectResult{1, 2},
|
{1, 2},
|
||||||
api.DetectResult{1, 3},
|
{1, 3},
|
||||||
}
|
}
|
||||||
client.Debug()
|
client.Debug()
|
||||||
err := client.ReportIllegal(&detectResult)
|
err := client.ReportIllegal(&detectResult)
|
||||||
|
@ -49,7 +49,7 @@ type TrojanNodeInfo struct {
|
|||||||
TrojanPort uint32 `json:"trojan_port"`
|
TrojanPort uint32 `json:"trojan_port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node status report
|
// NodeStatus Node status report
|
||||||
type NodeStatus struct {
|
type NodeStatus struct {
|
||||||
CPU string `json:"cpu"`
|
CPU string `json:"cpu"`
|
||||||
Mem string `json:"mem"`
|
Mem string `json:"mem"`
|
||||||
@ -98,7 +98,6 @@ type NodeRuleItem struct {
|
|||||||
Pattern string `json:"pattern"`
|
Pattern string `json:"pattern"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IllegalReport
|
|
||||||
type IllegalReport struct {
|
type IllegalReport struct {
|
||||||
UID int `json:"uid"`
|
UID int `json:"uid"`
|
||||||
RuleID int `json:"rule_id"`
|
RuleID int `json:"rule_id"`
|
||||||
|
@ -91,7 +91,7 @@ func readLocalRuleList(path string) (LocalRuleList []api.DetectRule) {
|
|||||||
// handle first encountered error while reading
|
// handle first encountered error while reading
|
||||||
if err := fileScanner.Err(); err != nil {
|
if err := fileScanner.Err(); err != nil {
|
||||||
log.Fatalf("Error while reading file: %s", err)
|
log.Fatalf("Error while reading file: %s", err)
|
||||||
return make([]api.DetectRule, 0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Close()
|
file.Close()
|
||||||
@ -135,7 +135,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (
|
|||||||
|
|
||||||
if response.Status != "success" {
|
if response.Status != "success" {
|
||||||
res, _ := json.Marshal(&response)
|
res, _ := json.Marshal(&response)
|
||||||
return nil, fmt.Errorf("Ret %s invalid", string(res))
|
return nil, fmt.Errorf("ret %s invalid", string(res))
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
path = fmt.Sprintf("/api/ss/v1/node/%d", c.NodeID)
|
path = fmt.Sprintf("/api/ss/v1/node/%d", c.NodeID)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.createCommonRequest().
|
res, err := c.createCommonRequest().
|
||||||
@ -172,7 +172,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
nodeInfo, err = c.ParseSSNodeResponse(&response.Data)
|
nodeInfo, err = c.ParseSSNodeResponse(&response.Data)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -194,7 +194,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
path = fmt.Sprintf("/api/ss/v1/userList/%d", c.NodeID)
|
path = fmt.Sprintf("/api/ss/v1/userList/%d", c.NodeID)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.createCommonRequest().
|
res, err := c.createCommonRequest().
|
||||||
@ -215,11 +215,11 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
userList, err = c.ParseSSUserListResponse(&response.Data)
|
userList, err = c.ParseSSUserListResponse(&response.Data)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res, _ := json.Marshal(response.Data)
|
res, _ := json.Marshal(response.Data)
|
||||||
return nil, fmt.Errorf("Parse user list failed: %s", string(res))
|
return nil, fmt.Errorf("parse user list failed: %s", string(res))
|
||||||
}
|
}
|
||||||
return userList, nil
|
return userList, nil
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
path = fmt.Sprintf("/api/ss/v1/nodeStatus/%d", c.NodeID)
|
path = fmt.Sprintf("/api/ss/v1/nodeStatus/%d", c.NodeID)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
systemload := NodeStatus{
|
systemload := NodeStatus{
|
||||||
@ -271,7 +271,7 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
path = fmt.Sprintf("/api/ss/v1/nodeOnline/%d", c.NodeID)
|
path = fmt.Sprintf("/api/ss/v1/nodeOnline/%d", c.NodeID)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := make([]NodeOnline, len(*onlineUserList))
|
data := make([]NodeOnline, len(*onlineUserList))
|
||||||
@ -304,7 +304,7 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
path = fmt.Sprintf("/api/ss/v1/userTraffic/%d", c.NodeID)
|
path = fmt.Sprintf("/api/ss/v1/userTraffic/%d", c.NodeID)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := make([]UserTraffic, len(*userTraffic))
|
data := make([]UserTraffic, len(*userTraffic))
|
||||||
@ -339,7 +339,7 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
path = fmt.Sprintf("/api/ss/v1/nodeRule/%d", c.NodeID)
|
path = fmt.Sprintf("/api/ss/v1/nodeRule/%d", c.NodeID)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.createCommonRequest().
|
res, err := c.createCommonRequest().
|
||||||
@ -355,7 +355,7 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
|
|||||||
ruleListResponse := new(NodeRule)
|
ruleListResponse := new(NodeRule)
|
||||||
|
|
||||||
if err := json.Unmarshal(response.Data, ruleListResponse); err != nil {
|
if err := json.Unmarshal(response.Data, ruleListResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(ruleListResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(ruleListResponse), err)
|
||||||
}
|
}
|
||||||
ruleList := c.LocalRuleList
|
ruleList := c.LocalRuleList
|
||||||
// Only support reject rule type
|
// Only support reject rule type
|
||||||
@ -387,7 +387,7 @@ func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error {
|
|||||||
case "Shadowsocks":
|
case "Shadowsocks":
|
||||||
path = fmt.Sprintf("/api/ss/v1/trigger/%d", c.NodeID)
|
path = fmt.Sprintf("/api/ss/v1/trigger/%d", c.NodeID)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range *detectResultList {
|
for _, r := range *detectResultList {
|
||||||
@ -422,13 +422,13 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *json.RawMessage) (*
|
|||||||
|
|
||||||
v2rayNodeInfo := new(V2rayNodeInfo)
|
v2rayNodeInfo := new(V2rayNodeInfo)
|
||||||
if err := json.Unmarshal(*nodeInfoResponse, v2rayNodeInfo); err != nil {
|
if err := json.Unmarshal(*nodeInfoResponse, v2rayNodeInfo); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(*nodeInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(*nodeInfoResponse), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
||||||
} else {
|
} else {
|
||||||
speedlimit = uint64((v2rayNodeInfo.SpeedLimit * 1000000) / 8)
|
speedlimit = (v2rayNodeInfo.SpeedLimit * 1000000) / 8
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.DeviceLimit == 0 && v2rayNodeInfo.ClientLimit > 0 {
|
if c.DeviceLimit == 0 && v2rayNodeInfo.ClientLimit > 0 {
|
||||||
@ -459,12 +459,12 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *json.RawMessage) (*api
|
|||||||
var speedlimit uint64 = 0
|
var speedlimit uint64 = 0
|
||||||
shadowsocksNodeInfo := new(ShadowsocksNodeInfo)
|
shadowsocksNodeInfo := new(ShadowsocksNodeInfo)
|
||||||
if err := json.Unmarshal(*nodeInfoResponse, shadowsocksNodeInfo); err != nil {
|
if err := json.Unmarshal(*nodeInfoResponse, shadowsocksNodeInfo); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(*nodeInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(*nodeInfoResponse), err)
|
||||||
}
|
}
|
||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
||||||
} else {
|
} else {
|
||||||
speedlimit = uint64((shadowsocksNodeInfo.SpeedLimit * 1000000) / 8)
|
speedlimit = (shadowsocksNodeInfo.SpeedLimit * 1000000) / 8
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.DeviceLimit == 0 && shadowsocksNodeInfo.ClientLimit > 0 {
|
if c.DeviceLimit == 0 && shadowsocksNodeInfo.ClientLimit > 0 {
|
||||||
@ -496,12 +496,12 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *json.RawMessage) (
|
|||||||
|
|
||||||
trojanNodeInfo := new(TrojanNodeInfo)
|
trojanNodeInfo := new(TrojanNodeInfo)
|
||||||
if err := json.Unmarshal(*nodeInfoResponse, trojanNodeInfo); err != nil {
|
if err := json.Unmarshal(*nodeInfoResponse, trojanNodeInfo); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(*nodeInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(*nodeInfoResponse), err)
|
||||||
}
|
}
|
||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
||||||
} else {
|
} else {
|
||||||
speedlimit = uint64((trojanNodeInfo.SpeedLimit * 1000000) / 8)
|
speedlimit = (trojanNodeInfo.SpeedLimit * 1000000) / 8
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.DeviceLimit == 0 && trojanNodeInfo.ClientLimit > 0 {
|
if c.DeviceLimit == 0 && trojanNodeInfo.ClientLimit > 0 {
|
||||||
@ -528,7 +528,7 @@ func (c *APIClient) ParseV2rayUserListResponse(userInfoResponse *json.RawMessage
|
|||||||
|
|
||||||
vmessUserList := new([]*VMessUser)
|
vmessUserList := new([]*VMessUser)
|
||||||
if err := json.Unmarshal(*userInfoResponse, vmessUserList); err != nil {
|
if err := json.Unmarshal(*userInfoResponse, vmessUserList); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(*userInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(*userInfoResponse), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
userList := make([]api.UserInfo, len(*vmessUserList))
|
userList := make([]api.UserInfo, len(*vmessUserList))
|
||||||
@ -536,7 +536,7 @@ func (c *APIClient) ParseV2rayUserListResponse(userInfoResponse *json.RawMessage
|
|||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
||||||
} else {
|
} else {
|
||||||
speedlimit = uint64((user.SpeedLimit * 1000000) / 8)
|
speedlimit = (user.SpeedLimit * 1000000) / 8
|
||||||
}
|
}
|
||||||
userList[i] = api.UserInfo{
|
userList[i] = api.UserInfo{
|
||||||
UID: user.UID,
|
UID: user.UID,
|
||||||
@ -556,7 +556,7 @@ func (c *APIClient) ParseTrojanUserListResponse(userInfoResponse *json.RawMessag
|
|||||||
|
|
||||||
trojanUserList := new([]*TrojanUser)
|
trojanUserList := new([]*TrojanUser)
|
||||||
if err := json.Unmarshal(*userInfoResponse, trojanUserList); err != nil {
|
if err := json.Unmarshal(*userInfoResponse, trojanUserList); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(*userInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(*userInfoResponse), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
userList := make([]api.UserInfo, len(*trojanUserList))
|
userList := make([]api.UserInfo, len(*trojanUserList))
|
||||||
@ -564,7 +564,7 @@ func (c *APIClient) ParseTrojanUserListResponse(userInfoResponse *json.RawMessag
|
|||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
||||||
} else {
|
} else {
|
||||||
speedlimit = uint64((user.SpeedLimit * 1000000) / 8)
|
speedlimit = (user.SpeedLimit * 1000000) / 8
|
||||||
}
|
}
|
||||||
userList[i] = api.UserInfo{
|
userList[i] = api.UserInfo{
|
||||||
UID: user.UID,
|
UID: user.UID,
|
||||||
@ -584,7 +584,7 @@ func (c *APIClient) ParseSSUserListResponse(userInfoResponse *json.RawMessage) (
|
|||||||
|
|
||||||
ssUserList := new([]*SSUser)
|
ssUserList := new([]*SSUser)
|
||||||
if err := json.Unmarshal(*userInfoResponse, ssUserList); err != nil {
|
if err := json.Unmarshal(*userInfoResponse, ssUserList); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(*userInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(*userInfoResponse), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
userList := make([]api.UserInfo, len(*ssUserList))
|
userList := make([]api.UserInfo, len(*ssUserList))
|
||||||
@ -592,7 +592,7 @@ func (c *APIClient) ParseSSUserListResponse(userInfoResponse *json.RawMessage) (
|
|||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
speedlimit = uint64((c.SpeedLimit * 1000000) / 8)
|
||||||
} else {
|
} else {
|
||||||
speedlimit = uint64((user.SpeedLimit * 1000000) / 8)
|
speedlimit = (user.SpeedLimit * 1000000) / 8
|
||||||
}
|
}
|
||||||
userList[i] = api.UserInfo{
|
userList[i] = api.UserInfo{
|
||||||
UID: user.UID,
|
UID: user.UID,
|
||||||
|
@ -89,7 +89,7 @@ func TestGetUserList(t *testing.T) {
|
|||||||
func TestReportNodeStatus(t *testing.T) {
|
func TestReportNodeStatus(t *testing.T) {
|
||||||
client := CreateClient()
|
client := CreateClient()
|
||||||
nodeStatus := &api.NodeStatus{
|
nodeStatus := &api.NodeStatus{
|
||||||
1, 1, 1, 256,
|
CPU: 1, Mem: 1, Disk: 1, Uptime: 256,
|
||||||
}
|
}
|
||||||
err := client.ReportNodeStatus(nodeStatus)
|
err := client.ReportNodeStatus(nodeStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -154,8 +154,8 @@ func TestReportIllegal(t *testing.T) {
|
|||||||
client := CreateClient()
|
client := CreateClient()
|
||||||
|
|
||||||
detectResult := []api.DetectResult{
|
detectResult := []api.DetectResult{
|
||||||
api.DetectResult{1, 1},
|
{1, 1},
|
||||||
api.DetectResult{1, 2},
|
{1, 2},
|
||||||
}
|
}
|
||||||
client.Debug()
|
client.Debug()
|
||||||
err := client.ReportIllegal(&detectResult)
|
err := client.ReportIllegal(&detectResult)
|
||||||
|
@ -108,7 +108,7 @@ func readLocalRuleList(path string) (LocalRuleList []api.DetectRule) {
|
|||||||
// handle first encountered error while reading
|
// handle first encountered error while reading
|
||||||
if err := fileScanner.Err(); err != nil {
|
if err := fileScanner.Err(); err != nil {
|
||||||
log.Fatalf("Error while reading file: %s", err)
|
log.Fatalf("Error while reading file: %s", err)
|
||||||
return make([]api.DetectRule, 0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Close()
|
file.Close()
|
||||||
@ -144,7 +144,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (
|
|||||||
|
|
||||||
if response.Ret != 1 {
|
if response.Ret != 1 {
|
||||||
res, _ := json.Marshal(&response)
|
res, _ := json.Marshal(&response)
|
||||||
return nil, fmt.Errorf("Ret %s invalid", string(res))
|
return nil, fmt.Errorf("ret %s invalid", string(res))
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
nodeInfoResponse := new(NodeInfoResponse)
|
nodeInfoResponse := new(NodeInfoResponse)
|
||||||
|
|
||||||
if err := json.Unmarshal(response.Data, nodeInfoResponse); err != nil {
|
if err := json.Unmarshal(response.Data, nodeInfoResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(nodeInfoResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(nodeInfoResponse), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New sspanel API
|
// New sspanel API
|
||||||
@ -197,7 +197,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
|
|||||||
case "Shadowsocks-Plugin":
|
case "Shadowsocks-Plugin":
|
||||||
nodeInfo, err = c.ParseSSPluginNodeResponse(nodeInfoResponse)
|
nodeInfo, err = c.ParseSSPluginNodeResponse(nodeInfoResponse)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,12 +226,12 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
userListResponse := new([]UserResponse)
|
userListResponse := new([]UserResponse)
|
||||||
|
|
||||||
if err := json.Unmarshal(response.Data, userListResponse); err != nil {
|
if err := json.Unmarshal(response.Data, userListResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(userListResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(userListResponse), err)
|
||||||
}
|
}
|
||||||
userList, err := c.ParseUserListResponse(userListResponse)
|
userList, err := c.ParseUserListResponse(userListResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res, _ := json.Marshal(userListResponse)
|
res, _ := json.Marshal(userListResponse)
|
||||||
return nil, fmt.Errorf("Parse user list failed: %s", string(res))
|
return nil, fmt.Errorf("parse user list failed: %s", string(res))
|
||||||
}
|
}
|
||||||
return userList, nil
|
return userList, nil
|
||||||
}
|
}
|
||||||
@ -335,7 +335,7 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
|
|||||||
ruleListResponse := new([]RuleItem)
|
ruleListResponse := new([]RuleItem)
|
||||||
|
|
||||||
if err := json.Unmarshal(response.Data, ruleListResponse); err != nil {
|
if err := json.Unmarshal(response.Data, ruleListResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(ruleListResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(ruleListResponse), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range *ruleListResponse {
|
for _, r := range *ruleListResponse {
|
||||||
@ -379,7 +379,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (
|
|||||||
var header json.RawMessage
|
var header json.RawMessage
|
||||||
var speedlimit uint64 = 0
|
var speedlimit uint64 = 0
|
||||||
if nodeInfoResponse.RawServerString == "" {
|
if nodeInfoResponse.RawServerString == "" {
|
||||||
return nil, fmt.Errorf("No server info in response")
|
return nil, fmt.Errorf("no server info in response")
|
||||||
}
|
}
|
||||||
// nodeInfo.RawServerString = strings.ToLower(nodeInfo.RawServerString)
|
// nodeInfo.RawServerString = strings.ToLower(nodeInfo.RawServerString)
|
||||||
serverConf := strings.Split(nodeInfoResponse.RawServerString, ";")
|
serverConf := strings.Split(nodeInfoResponse.RawServerString, ";")
|
||||||
@ -445,7 +445,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Marshal Header Type %s into config fialed: %s", header, err)
|
return nil, fmt.Errorf("marshal Header Type %s into config fialed: %s", header, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create GeneralNodeInfo
|
// Create GeneralNodeInfo
|
||||||
@ -488,7 +488,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*ap
|
|||||||
userListResponse := new([]UserResponse)
|
userListResponse := new([]UserResponse)
|
||||||
|
|
||||||
if err := json.Unmarshal(response.Data, userListResponse); err != nil {
|
if err := json.Unmarshal(response.Data, userListResponse); err != nil {
|
||||||
return nil, fmt.Errorf("Unmarshal %s failed: %s", reflect.TypeOf(userListResponse), err)
|
return nil, fmt.Errorf("unmarshal %s failed: %s", reflect.TypeOf(userListResponse), err)
|
||||||
}
|
}
|
||||||
// Find the multi-user
|
// Find the multi-user
|
||||||
for _, u := range *userListResponse {
|
for _, u := range *userListResponse {
|
||||||
@ -499,7 +499,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*ap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if port == 0 || method == "" {
|
if port == 0 || method == "" {
|
||||||
return nil, fmt.Errorf("Cant find the single port multi user")
|
return nil, fmt.Errorf("cant find the single port multi user")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
@ -604,7 +604,7 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *NodeInfoResponse)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if nodeInfoResponse.RawServerString == "" {
|
if nodeInfoResponse.RawServerString == "" {
|
||||||
return nil, fmt.Errorf("No server info in response")
|
return nil, fmt.Errorf("no server info in response")
|
||||||
}
|
}
|
||||||
if result := firstPortRe.FindStringSubmatch(nodeInfoResponse.RawServerString); len(result) > 1 {
|
if result := firstPortRe.FindStringSubmatch(nodeInfoResponse.RawServerString); len(result) > 1 {
|
||||||
outsidePort = result[1]
|
outsidePort = result[1]
|
||||||
@ -677,9 +677,9 @@ func (c *APIClient) ParseUserListResponse(userInfoResponse *[]UserResponse) (*[]
|
|||||||
c.access.Unlock()
|
c.access.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var deviceLimit, localDeviceLimit int = 0, 0
|
var deviceLimit, localDeviceLimit = 0, 0
|
||||||
var speedlimit uint64 = 0
|
var speedlimit uint64 = 0
|
||||||
userList := []api.UserInfo{}
|
var userList []api.UserInfo
|
||||||
for _, user := range *userInfoResponse {
|
for _, user := range *userInfoResponse {
|
||||||
if c.DeviceLimit > 0 {
|
if c.DeviceLimit > 0 {
|
||||||
deviceLimit = c.DeviceLimit
|
deviceLimit = c.DeviceLimit
|
||||||
|
@ -83,7 +83,7 @@ func TestGetUserList(t *testing.T) {
|
|||||||
func TestReportNodeStatus(t *testing.T) {
|
func TestReportNodeStatus(t *testing.T) {
|
||||||
client := CreateClient()
|
client := CreateClient()
|
||||||
nodeStatus := &api.NodeStatus{
|
nodeStatus := &api.NodeStatus{
|
||||||
1, 1, 1, 256,
|
CPU: 1, Mem: 1, Disk: 1, Uptime: 256,
|
||||||
}
|
}
|
||||||
err := client.ReportNodeStatus(nodeStatus)
|
err := client.ReportNodeStatus(nodeStatus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -148,8 +148,8 @@ func TestReportIllegal(t *testing.T) {
|
|||||||
client := CreateClient()
|
client := CreateClient()
|
||||||
|
|
||||||
detectResult := []api.DetectResult{
|
detectResult := []api.DetectResult{
|
||||||
api.DetectResult{1, 2},
|
{1, 2},
|
||||||
api.DetectResult{1, 3},
|
{1, 3},
|
||||||
}
|
}
|
||||||
client.Debug()
|
client.Debug()
|
||||||
err := client.ReportIllegal(&detectResult)
|
err := client.ReportIllegal(&detectResult)
|
||||||
|
@ -100,7 +100,7 @@ func readLocalRuleList(path string) (LocalRuleList []api.DetectRule) {
|
|||||||
// handle first encountered error while reading
|
// handle first encountered error while reading
|
||||||
if err := fileScanner.Err(); err != nil {
|
if err := fileScanner.Err(); err != nil {
|
||||||
log.Fatalf("Error while reading file: %s", err)
|
log.Fatalf("Error while reading file: %s", err)
|
||||||
return make([]api.DetectRule, 0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Close()
|
file.Close()
|
||||||
@ -134,7 +134,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (
|
|||||||
}
|
}
|
||||||
rtn, err := simplejson.NewJson(res.Body())
|
rtn, err := simplejson.NewJson(res.Body())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Ret %s invalid", res.String())
|
return nil, fmt.Errorf("ret %s invalid", res.String())
|
||||||
}
|
}
|
||||||
return rtn, nil
|
return rtn, nil
|
||||||
}
|
}
|
||||||
@ -354,7 +354,7 @@ func (c *APIClient) ParseSSNodeResponse() (*api.NodeInfo, error) {
|
|||||||
|
|
||||||
// ParseV2rayNodeResponse parse the response for the given nodeinfor format
|
// ParseV2rayNodeResponse parse the response for the given nodeinfor format
|
||||||
func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*api.NodeInfo, error) {
|
func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*api.NodeInfo, error) {
|
||||||
var TLSType string = "tls"
|
var TLSType = "tls"
|
||||||
var path, host, serviceName string
|
var path, host, serviceName string
|
||||||
var header json.RawMessage
|
var header json.RawMessage
|
||||||
var enableTLS bool
|
var enableTLS bool
|
||||||
@ -372,7 +372,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
|
|||||||
marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{}))
|
marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{}))
|
||||||
inboundInfo, _ = simplejson.NewJson(marshalByte)
|
inboundInfo, _ = simplejson.NewJson(marshalByte)
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Unable to find inbound(s) in the nodeInfo.")
|
return nil, fmt.Errorf("unable to find inbound(s) in the nodeInfo")
|
||||||
}
|
}
|
||||||
|
|
||||||
port := uint32(inboundInfo.Get("port").MustUint64())
|
port := uint32(inboundInfo.Get("port").MustUint64())
|
||||||
|
@ -99,7 +99,7 @@ func readLocalRuleList(path string) (LocalRuleList []api.DetectRule) {
|
|||||||
// handle first encountered error while reading
|
// handle first encountered error while reading
|
||||||
if err := fileScanner.Err(); err != nil {
|
if err := fileScanner.Err(); err != nil {
|
||||||
log.Fatalf("Error while reading file: %s", err)
|
log.Fatalf("Error while reading file: %s", err)
|
||||||
return make([]api.DetectRule, 0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
file.Close()
|
file.Close()
|
||||||
@ -133,7 +133,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (
|
|||||||
}
|
}
|
||||||
rtn, err := simplejson.NewJson(res.Body())
|
rtn, err := simplejson.NewJson(res.Body())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Ret %s invalid", res.String())
|
return nil, fmt.Errorf("ret %s invalid", res.String())
|
||||||
}
|
}
|
||||||
return rtn, nil
|
return rtn, nil
|
||||||
}
|
}
|
||||||
@ -213,16 +213,16 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
user.Email = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString()
|
user.Email = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString()
|
||||||
user.Passwd = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString()
|
user.Passwd = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString()
|
||||||
user.Method = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("cipher").MustString()
|
user.Method = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("cipher").MustString()
|
||||||
user.SpeedLimit = uint64(response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("speed_limit").MustUint64() * 1000000 / 8)
|
user.SpeedLimit = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("speed_limit").MustUint64() * 1000000 / 8
|
||||||
case "Trojan":
|
case "Trojan":
|
||||||
user.UUID = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString()
|
user.UUID = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString()
|
||||||
user.Email = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString()
|
user.Email = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString()
|
||||||
user.SpeedLimit = uint64(response.Get("data").GetIndex(i).Get("trojan_user").Get("speed_limit").MustUint64() * 1000000 / 8)
|
user.SpeedLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("speed_limit").MustUint64() * 1000000 / 8
|
||||||
case "V2ray":
|
case "V2ray":
|
||||||
user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString()
|
user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString()
|
||||||
user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString()
|
user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString()
|
||||||
user.AlterID = uint16(response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustUint64())
|
user.AlterID = uint16(response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustUint64())
|
||||||
user.SpeedLimit = uint64(response.Get("data").GetIndex(i).Get("v2ray_user").Get("speed_limit").MustUint64() * 1000000 / 8)
|
user.SpeedLimit = response.Get("data").GetIndex(i).Get("v2ray_user").Get("speed_limit").MustUint64() * 1000000 / 8
|
||||||
}
|
}
|
||||||
if c.SpeedLimit > 0 {
|
if c.SpeedLimit > 0 {
|
||||||
user.SpeedLimit = uint64((c.SpeedLimit * 1000000) / 8)
|
user.SpeedLimit = uint64((c.SpeedLimit * 1000000) / 8)
|
||||||
@ -354,7 +354,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *simplejson.Json) (*api
|
|||||||
|
|
||||||
// ParseV2rayNodeResponse parse the response for the given nodeinfor format
|
// ParseV2rayNodeResponse parse the response for the given nodeinfor format
|
||||||
func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*api.NodeInfo, error) {
|
func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*api.NodeInfo, error) {
|
||||||
var TLSType string = "tls"
|
var TLSType = "tls"
|
||||||
var path, host, serviceName string
|
var path, host, serviceName string
|
||||||
var header json.RawMessage
|
var header json.RawMessage
|
||||||
var enableTLS bool
|
var enableTLS bool
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
"github.com/xtls/xray-core/features/policy"
|
"github.com/xtls/xray-core/features/policy"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
routing_session "github.com/xtls/xray-core/features/routing/session"
|
routingSession "github.com/xtls/xray-core/features/routing/session"
|
||||||
"github.com/xtls/xray-core/features/stats"
|
"github.com/xtls/xray-core/features/stats"
|
||||||
"github.com/xtls/xray-core/transport"
|
"github.com/xtls/xray-core/transport"
|
||||||
"github.com/xtls/xray-core/transport/pipe"
|
"github.com/xtls/xray-core/transport/pipe"
|
||||||
@ -99,7 +99,7 @@ type DefaultDispatcher struct {
|
|||||||
dns dns.Client
|
dns dns.Client
|
||||||
fdns dns.FakeDNSEngine
|
fdns dns.FakeDNSEngine
|
||||||
Limiter *limiter.Limiter
|
Limiter *limiter.Limiter
|
||||||
RuleManager *rule.RuleManager
|
RuleManager *rule.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -173,7 +173,7 @@ func (d *DefaultDispatcher) getLink(ctx context.Context, network net.Network, sn
|
|||||||
newError("[fakedns client] create a new map").WriteToLog(session.ExportIDToError(ctx))
|
newError("[fakedns client] create a new map").WriteToLog(session.ExportIDToError(ctx))
|
||||||
}
|
}
|
||||||
domain := addr.Domain()
|
domain := addr.Domain()
|
||||||
ips, err := d.dns.LookupIP(domain, dns.IPOption{true, true, false})
|
ips, err := d.dns.LookupIP(domain, dns.IPOption{IPv4Enable: true, IPv6Enable: true})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
ip2domain.Store(ip.String(), domain)
|
ip2domain.Store(ip.String(), domain)
|
||||||
@ -315,13 +315,13 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
|
|||||||
}
|
}
|
||||||
|
|
||||||
sniffingRequest := content.SniffingRequest
|
sniffingRequest := content.SniffingRequest
|
||||||
inbound, outbound, err := d.getLink(ctx, destination.Network, sniffingRequest)
|
in, out, err := d.getLink(ctx, destination.Network, sniffingRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case !sniffingRequest.Enabled:
|
case !sniffingRequest.Enabled:
|
||||||
go d.routedDispatch(ctx, outbound, destination)
|
go d.routedDispatch(ctx, out, destination)
|
||||||
case destination.Network != net.Network_TCP:
|
case destination.Network != net.Network_TCP:
|
||||||
// Only metadata sniff will be used for non tcp connection
|
// Only metadata sniff will be used for non tcp connection
|
||||||
result, err := sniffer(ctx, nil, true)
|
result, err := sniffer(ctx, nil, true)
|
||||||
@ -338,13 +338,13 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go d.routedDispatch(ctx, outbound, destination)
|
go d.routedDispatch(ctx, out, destination)
|
||||||
default:
|
default:
|
||||||
go func() {
|
go func() {
|
||||||
cReader := &cachedReader{
|
cReader := &cachedReader{
|
||||||
reader: outbound.Reader.(*pipe.Reader),
|
reader: out.Reader.(*pipe.Reader),
|
||||||
}
|
}
|
||||||
outbound.Reader = cReader
|
out.Reader = cReader
|
||||||
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly)
|
result, err := sniffer(ctx, cReader, sniffingRequest.MetadataOnly)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
content.Protocol = result.Protocol()
|
content.Protocol = result.Protocol()
|
||||||
@ -359,10 +359,10 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
|
|||||||
ob.Target = destination
|
ob.Target = destination
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.routedDispatch(ctx, outbound, destination)
|
d.routedDispatch(ctx, out, destination)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
return inbound, nil
|
return in, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DispatchLink implements routing.Dispatcher.
|
// DispatchLink implements routing.Dispatcher.
|
||||||
@ -502,7 +502,7 @@ func (d *DefaultDispatcher) routedDispatch(ctx context.Context, link *transport.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
routingLink := routing_session.AsRoutingContext(ctx)
|
routingLink := routingSession.AsRoutingContext(ctx)
|
||||||
inTag := routingLink.GetInboundTag()
|
inTag := routingLink.GetInboundTag()
|
||||||
isPickRoute := 0
|
isPickRoute := 0
|
||||||
if forcedOutboundTag := session.GetForcedOutboundTagFromContext(ctx); forcedOutboundTag != "" {
|
if forcedOutboundTag := session.GetForcedOutboundTagFromContext(ctx); forcedOutboundTag != "" {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Package dispather implement the rate limiter and the onlie device counter
|
// Package mydispatcher Package dispatcher implement the rate limiter and the online device counter
|
||||||
package mydispatcher
|
package mydispatcher
|
||||||
|
|
||||||
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
//go:generate go run github.com/xtls/xray-core/common/errors/errorgen
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
baseCertificatesFolderName = "certificates"
|
baseCertificatesFolderName = "certificates"
|
||||||
baseArchivesFolderName = "archives"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CertificatesStorage a certificates' storage.
|
// CertificatesStorage a certificates' storage.
|
||||||
|
@ -3,7 +3,7 @@ package mylego_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thank243/v2rayS/common/mylego"
|
"github.com/XrayR-project/XrayR/common/mylego"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLegoClient(t *testing.T) {
|
func TestLegoClient(t *testing.T) {
|
||||||
|
@ -13,19 +13,19 @@ import (
|
|||||||
"github.com/XrayR-project/XrayR/api"
|
"github.com/XrayR-project/XrayR/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RuleManager struct {
|
type Manager struct {
|
||||||
InboundRule *sync.Map // Key: Tag, Value: []api.DetectRule
|
InboundRule *sync.Map // Key: Tag, Value: []api.DetectRule
|
||||||
InboundDetectResult *sync.Map // key: Tag, Value: mapset.NewSet []api.DetectResult
|
InboundDetectResult *sync.Map // key: Tag, Value: mapset.NewSet []api.DetectResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *RuleManager {
|
func New() *Manager {
|
||||||
return &RuleManager{
|
return &Manager{
|
||||||
InboundRule: new(sync.Map),
|
InboundRule: new(sync.Map),
|
||||||
InboundDetectResult: new(sync.Map),
|
InboundDetectResult: new(sync.Map),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RuleManager) UpdateRule(tag string, newRuleList []api.DetectRule) error {
|
func (r *Manager) UpdateRule(tag string, newRuleList []api.DetectRule) error {
|
||||||
if value, ok := r.InboundRule.LoadOrStore(tag, newRuleList); ok {
|
if value, ok := r.InboundRule.LoadOrStore(tag, newRuleList); ok {
|
||||||
oldRuleList := value.([]api.DetectRule)
|
oldRuleList := value.([]api.DetectRule)
|
||||||
if !reflect.DeepEqual(oldRuleList, newRuleList) {
|
if !reflect.DeepEqual(oldRuleList, newRuleList) {
|
||||||
@ -35,7 +35,7 @@ func (r *RuleManager) UpdateRule(tag string, newRuleList []api.DetectRule) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RuleManager) GetDetectResult(tag string) (*[]api.DetectResult, error) {
|
func (r *Manager) GetDetectResult(tag string) (*[]api.DetectResult, error) {
|
||||||
detectResult := make([]api.DetectResult, 0)
|
detectResult := make([]api.DetectResult, 0)
|
||||||
if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok {
|
if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok {
|
||||||
resultSet := value.(mapset.Set)
|
resultSet := value.(mapset.Set)
|
||||||
@ -47,9 +47,9 @@ func (r *RuleManager) GetDetectResult(tag string) (*[]api.DetectResult, error) {
|
|||||||
return &detectResult, nil
|
return &detectResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RuleManager) Detect(tag string, destination string, email string) (reject bool) {
|
func (r *Manager) Detect(tag string, destination string, email string) (reject bool) {
|
||||||
reject = false
|
reject = false
|
||||||
var hitRuleID int = -1
|
var hitRuleID = -1
|
||||||
// If we have some rule for this inbound
|
// If we have some rule for this inbound
|
||||||
if value, ok := r.InboundRule.Load(tag); ok {
|
if value, ok := r.InboundRule.Load(tag); ok {
|
||||||
ruleList := value.([]api.DetectRule)
|
ruleList := value.([]api.DetectRule)
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
// GetSystemInfo get the system info of a given periodic
|
// GetSystemInfo get the system info of a given periodic
|
||||||
func GetSystemInfo() (Cpu float64, Mem float64, Disk float64, Uptime uint64, err error) {
|
func GetSystemInfo() (Cpu float64, Mem float64, Disk float64, Uptime uint64, err error) {
|
||||||
|
|
||||||
error_string := ""
|
errorString := ""
|
||||||
|
|
||||||
cpuPercent, err := cpu.Percent(0, false)
|
cpuPercent, err := cpu.Percent(0, false)
|
||||||
// Check if cpuPercent is empty
|
// Check if cpuPercent is empty
|
||||||
@ -21,32 +21,32 @@ func GetSystemInfo() (Cpu float64, Mem float64, Disk float64, Uptime uint64, err
|
|||||||
Cpu = cpuPercent[0]
|
Cpu = cpuPercent[0]
|
||||||
} else {
|
} else {
|
||||||
Cpu = 0
|
Cpu = 0
|
||||||
error_string += fmt.Sprintf("get cpu usage failed: %s ", err)
|
errorString += fmt.Sprintf("get cpu usage failed: %s ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
memUsage, err := mem.VirtualMemory()
|
memUsage, err := mem.VirtualMemory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error_string += fmt.Sprintf("get mem usage failed: %s ", err)
|
errorString += fmt.Sprintf("get mem usage failed: %s ", err)
|
||||||
} else {
|
} else {
|
||||||
Mem = memUsage.UsedPercent
|
Mem = memUsage.UsedPercent
|
||||||
}
|
}
|
||||||
|
|
||||||
diskUsage, err := disk.Usage("/")
|
diskUsage, err := disk.Usage("/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error_string += fmt.Sprintf("get disk usage failed: %s ", err)
|
errorString += fmt.Sprintf("get disk usage failed: %s ", err)
|
||||||
} else {
|
} else {
|
||||||
Disk = diskUsage.UsedPercent
|
Disk = diskUsage.UsedPercent
|
||||||
}
|
}
|
||||||
|
|
||||||
uptime, err := host.Uptime()
|
uptime, err := host.Uptime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error_string += fmt.Sprintf("get uptime failed: %s ", err)
|
errorString += fmt.Sprintf("get uptime failed: %s ", err)
|
||||||
} else {
|
} else {
|
||||||
Uptime = uptime
|
Uptime = uptime
|
||||||
}
|
}
|
||||||
|
|
||||||
if error_string != "" {
|
if errorString != "" {
|
||||||
err = fmt.Errorf(error_string)
|
err = fmt.Errorf(errorString)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Cpu, Mem, Disk, Uptime, err
|
return Cpu, Mem, Disk, Uptime, err
|
||||||
|
6
go.mod
6
go.mod
@ -14,8 +14,8 @@ require (
|
|||||||
github.com/shirou/gopsutil/v3 v3.22.9
|
github.com/shirou/gopsutil/v3 v3.22.9
|
||||||
github.com/spf13/viper v1.13.0
|
github.com/spf13/viper v1.13.0
|
||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.1
|
||||||
github.com/urfave/cli v1.22.10
|
|
||||||
github.com/xtls/xray-core v1.6.1
|
github.com/xtls/xray-core v1.6.1
|
||||||
|
golang.org/x/crypto v0.1.0
|
||||||
golang.org/x/net v0.1.0
|
golang.org/x/net v0.1.0
|
||||||
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
|
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
|
||||||
google.golang.org/protobuf v1.28.1
|
google.golang.org/protobuf v1.28.1
|
||||||
@ -47,7 +47,6 @@ require (
|
|||||||
github.com/civo/civogo v0.3.11 // indirect
|
github.com/civo/civogo v0.3.11 // indirect
|
||||||
github.com/cloudflare/cloudflare-go v0.49.0 // indirect
|
github.com/cloudflare/cloudflare-go v0.49.0 // indirect
|
||||||
github.com/cpu/goacmedns v0.1.1 // indirect
|
github.com/cpu/goacmedns v0.1.1 // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/deepmap/oapi-codegen v1.9.1 // indirect
|
github.com/deepmap/oapi-codegen v1.9.1 // indirect
|
||||||
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
|
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
|
||||||
@ -123,10 +122,8 @@ require (
|
|||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
github.com/pquerna/otp v1.3.0 // indirect
|
github.com/pquerna/otp v1.3.0 // indirect
|
||||||
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2 // indirect
|
|
||||||
github.com/refraction-networking/utls v1.1.5 // indirect
|
github.com/refraction-networking/utls v1.1.5 // indirect
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
|
||||||
github.com/sacloud/api-client-go v0.2.1 // indirect
|
github.com/sacloud/api-client-go v0.2.1 // indirect
|
||||||
github.com/sacloud/go-http v0.1.2 // indirect
|
github.com/sacloud/go-http v0.1.2 // indirect
|
||||||
github.com/sacloud/iaas-api-go v1.3.2 // indirect
|
github.com/sacloud/iaas-api-go v1.3.2 // indirect
|
||||||
@ -161,7 +158,6 @@ require (
|
|||||||
go.opencensus.io v0.23.0 // indirect
|
go.opencensus.io v0.23.0 // indirect
|
||||||
go.starlark.net v0.0.0-20221020143700-22309ac47eac // indirect
|
go.starlark.net v0.0.0-20221020143700-22309ac47eac // indirect
|
||||||
go.uber.org/ratelimit v0.2.0 // indirect
|
go.uber.org/ratelimit v0.2.0 // indirect
|
||||||
golang.org/x/crypto v0.1.0 // indirect
|
|
||||||
golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect
|
golang.org/x/exp v0.0.0-20221019170559-20944726eadf // indirect
|
||||||
golang.org/x/mod v0.6.0 // indirect
|
golang.org/x/mod v0.6.0 // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
|
golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect
|
||||||
|
9
go.sum
9
go.sum
@ -159,10 +159,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
|
|||||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||||
github.com/cpu/goacmedns v0.1.1 h1:DM3H2NiN2oam7QljgGY5ygy4yDXhK5Z4JUnqaugs2C4=
|
github.com/cpu/goacmedns v0.1.1 h1:DM3H2NiN2oam7QljgGY5ygy4yDXhK5Z4JUnqaugs2C4=
|
||||||
github.com/cpu/goacmedns v0.1.1/go.mod h1:MuaouqEhPAHxsbqjgnck5zeghuwBP1dLnPoobeGqugQ=
|
github.com/cpu/goacmedns v0.1.1/go.mod h1:MuaouqEhPAHxsbqjgnck5zeghuwBP1dLnPoobeGqugQ=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -640,8 +637,6 @@ github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDa
|
|||||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||||
github.com/r3labs/diff/v2 v2.15.1 h1:EOrVqPUzi+njlumoqJwiS/TgGgmZo83619FNDB9xQUg=
|
github.com/r3labs/diff/v2 v2.15.1 h1:EOrVqPUzi+njlumoqJwiS/TgGgmZo83619FNDB9xQUg=
|
||||||
github.com/r3labs/diff/v2 v2.15.1/go.mod h1:I8noH9Fc2fjSaMxqF3G2lhDdC0b+JXCfyx85tWFM9kc=
|
github.com/r3labs/diff/v2 v2.15.1/go.mod h1:I8noH9Fc2fjSaMxqF3G2lhDdC0b+JXCfyx85tWFM9kc=
|
||||||
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2 h1:dq90+d51/hQRaHEqRAsQ1rE/pC1GUS4sc2rCbbFsAIY=
|
|
||||||
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2/go.mod h1:7tZKcyumwBO6qip7RNQ5r77yrssm9bfCowcLEBcU5IA=
|
|
||||||
github.com/refraction-networking/utls v1.1.5 h1:JtrojoNhbUQkBqEg05sP3gDgDj6hIEAAVKbI9lx4n6w=
|
github.com/refraction-networking/utls v1.1.5 h1:JtrojoNhbUQkBqEg05sP3gDgDj6hIEAAVKbI9lx4n6w=
|
||||||
github.com/refraction-networking/utls v1.1.5/go.mod h1:jRQxtYi7nkq1p28HF2lwOH5zQm9aC8rpK0O9lIIzGh8=
|
github.com/refraction-networking/utls v1.1.5/go.mod h1:jRQxtYi7nkq1p28HF2lwOH5zQm9aC8rpK0O9lIIzGh8=
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
|
||||||
@ -654,8 +649,6 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po
|
|||||||
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
|
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
|
||||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
github.com/sacloud/api-client-go v0.2.1 h1:jl02ZG6cM+mcH4eDYg0cxCFFuTOVTOjUCLYL4UbP09U=
|
github.com/sacloud/api-client-go v0.2.1 h1:jl02ZG6cM+mcH4eDYg0cxCFFuTOVTOjUCLYL4UbP09U=
|
||||||
github.com/sacloud/api-client-go v0.2.1/go.mod h1:8fmYy5OpT3W8ltV5ZxF8evultNwKpduGN4YKmU9Af7w=
|
github.com/sacloud/api-client-go v0.2.1/go.mod h1:8fmYy5OpT3W8ltV5ZxF8evultNwKpduGN4YKmU9Af7w=
|
||||||
@ -771,8 +764,6 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
|
|||||||
github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0=
|
github.com/ugorji/go v1.2.6/go.mod h1:anCg0y61KIhDlPZmnH+so+RQbysYVyDko0IMgJv0Nn0=
|
||||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||||
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
|
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
|
||||||
github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk=
|
|
||||||
github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e h1:5QefA066A1tF8gHIiADmOVOV5LS43gt3ONnlEl3xkwI=
|
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e h1:5QefA066A1tF8gHIiADmOVOV5LS43gt3ONnlEl3xkwI=
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e/go.mod h1:5t19P9LBIrNamL6AcMQOncg/r10y3Pc01AbHeMhwlpU=
|
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e/go.mod h1:5t19P9LBIrNamL6AcMQOncg/r10y3Pc01AbHeMhwlpU=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
|
@ -6,7 +6,7 @@ DnsConfigPath: # /etc/XrayR/dns.json # Path to dns config, check https://xtls.gi
|
|||||||
RouteConfigPath: # /etc/XrayR/route.json # Path to route config, check https://xtls.github.io/config/routing.html for help
|
RouteConfigPath: # /etc/XrayR/route.json # Path to route config, check https://xtls.github.io/config/routing.html for help
|
||||||
InboundConfigPath: # /etc/XrayR/custom_inbound.json # Path to custom inbound config, check https://xtls.github.io/config/inbound.html for help
|
InboundConfigPath: # /etc/XrayR/custom_inbound.json # Path to custom inbound config, check https://xtls.github.io/config/inbound.html for help
|
||||||
OutboundConfigPath: # /etc/XrayR/custom_outbound.json # Path to custom outbound config, check https://xtls.github.io/config/outbound.html for help
|
OutboundConfigPath: # /etc/XrayR/custom_outbound.json # Path to custom outbound config, check https://xtls.github.io/config/outbound.html for help
|
||||||
ConnetionConfig:
|
ConnectionConfig:
|
||||||
Handshake: 4 # Handshake time limit, Second
|
Handshake: 4 # Handshake time limit, Second
|
||||||
ConnIdle: 30 # Connection idle time limit, Second
|
ConnIdle: 30 # Connection idle time limit, Second
|
||||||
UplinkOnly: 2 # Time limit when the connection downstream is closed, Second
|
UplinkOnly: 2 # Time limit when the connection downstream is closed, Second
|
||||||
|
@ -75,7 +75,7 @@ func main() {
|
|||||||
config := getConfig()
|
config := getConfig()
|
||||||
panelConfig := &panel.Config{}
|
panelConfig := &panel.Config{}
|
||||||
if err := config.Unmarshal(panelConfig); err != nil {
|
if err := config.Unmarshal(panelConfig); err != nil {
|
||||||
log.Panicf("Parse config file %s failed: %s \n", configFile, err)
|
log.Panicf("Parse config file %v failed: %s \n", configFile, err)
|
||||||
}
|
}
|
||||||
p := panel.New(panelConfig)
|
p := panel.New(panelConfig)
|
||||||
lastTime := time.Now()
|
lastTime := time.Now()
|
||||||
@ -88,7 +88,7 @@ func main() {
|
|||||||
// Delete old instance and trigger GC
|
// Delete old instance and trigger GC
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
if err := config.Unmarshal(panelConfig); err != nil {
|
if err := config.Unmarshal(panelConfig); err != nil {
|
||||||
log.Panicf("Parse config file %s failed: %s \n", configFile, err)
|
log.Panicf("Parse config file %v failed: %s \n", configFile, err)
|
||||||
}
|
}
|
||||||
p.Start()
|
p.Start()
|
||||||
lastTime = time.Now()
|
lastTime = time.Now()
|
||||||
|
@ -2,8 +2,8 @@ package panel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
io "io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/XrayR-project/XrayR/app/mydispatcher"
|
"github.com/XrayR-project/XrayR/app/mydispatcher"
|
||||||
@ -57,7 +57,7 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
// DNS config
|
// DNS config
|
||||||
coreDnsConfig := &conf.DNSConfig{}
|
coreDnsConfig := &conf.DNSConfig{}
|
||||||
if panelConfig.DnsConfigPath != "" {
|
if panelConfig.DnsConfigPath != "" {
|
||||||
if data, err := io.ReadFile(panelConfig.DnsConfigPath); err != nil {
|
if data, err := os.ReadFile(panelConfig.DnsConfigPath); err != nil {
|
||||||
log.Panicf("Failed to read DNS config file at: %s", panelConfig.DnsConfigPath)
|
log.Panicf("Failed to read DNS config file at: %s", panelConfig.DnsConfigPath)
|
||||||
} else {
|
} else {
|
||||||
if err = json.Unmarshal(data, coreDnsConfig); err != nil {
|
if err = json.Unmarshal(data, coreDnsConfig); err != nil {
|
||||||
@ -72,7 +72,7 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
// Routing config
|
// Routing config
|
||||||
coreRouterConfig := &conf.RouterConfig{}
|
coreRouterConfig := &conf.RouterConfig{}
|
||||||
if panelConfig.RouteConfigPath != "" {
|
if panelConfig.RouteConfigPath != "" {
|
||||||
if data, err := io.ReadFile(panelConfig.RouteConfigPath); err != nil {
|
if data, err := os.ReadFile(panelConfig.RouteConfigPath); err != nil {
|
||||||
log.Panicf("Failed to read Routing config file at: %s", panelConfig.RouteConfigPath)
|
log.Panicf("Failed to read Routing config file at: %s", panelConfig.RouteConfigPath)
|
||||||
} else {
|
} else {
|
||||||
if err = json.Unmarshal(data, coreRouterConfig); err != nil {
|
if err = json.Unmarshal(data, coreRouterConfig); err != nil {
|
||||||
@ -85,9 +85,9 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
log.Panicf("Failed to understand Routing config Please check: https://xtls.github.io/config/routing.html for help: %s", err)
|
log.Panicf("Failed to understand Routing config Please check: https://xtls.github.io/config/routing.html for help: %s", err)
|
||||||
}
|
}
|
||||||
// Custom Inbound config
|
// Custom Inbound config
|
||||||
coreCustomInboundConfig := []conf.InboundDetourConfig{}
|
var coreCustomInboundConfig []conf.InboundDetourConfig
|
||||||
if panelConfig.InboundConfigPath != "" {
|
if panelConfig.InboundConfigPath != "" {
|
||||||
if data, err := io.ReadFile(panelConfig.InboundConfigPath); err != nil {
|
if data, err := os.ReadFile(panelConfig.InboundConfigPath); err != nil {
|
||||||
log.Panicf("Failed to read Custom Inbound config file at: %s", panelConfig.OutboundConfigPath)
|
log.Panicf("Failed to read Custom Inbound config file at: %s", panelConfig.OutboundConfigPath)
|
||||||
} else {
|
} else {
|
||||||
if err = json.Unmarshal(data, &coreCustomInboundConfig); err != nil {
|
if err = json.Unmarshal(data, &coreCustomInboundConfig); err != nil {
|
||||||
@ -95,7 +95,7 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inBoundConfig := []*core.InboundHandlerConfig{}
|
var inBoundConfig []*core.InboundHandlerConfig
|
||||||
for _, config := range coreCustomInboundConfig {
|
for _, config := range coreCustomInboundConfig {
|
||||||
oc, err := config.Build()
|
oc, err := config.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -104,9 +104,9 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
inBoundConfig = append(inBoundConfig, oc)
|
inBoundConfig = append(inBoundConfig, oc)
|
||||||
}
|
}
|
||||||
// Custom Outbound config
|
// Custom Outbound config
|
||||||
coreCustomOutboundConfig := []conf.OutboundDetourConfig{}
|
var coreCustomOutboundConfig []conf.OutboundDetourConfig
|
||||||
if panelConfig.OutboundConfigPath != "" {
|
if panelConfig.OutboundConfigPath != "" {
|
||||||
if data, err := io.ReadFile(panelConfig.OutboundConfigPath); err != nil {
|
if data, err := os.ReadFile(panelConfig.OutboundConfigPath); err != nil {
|
||||||
log.Panicf("Failed to read Custom Outbound config file at: %s", panelConfig.OutboundConfigPath)
|
log.Panicf("Failed to read Custom Outbound config file at: %s", panelConfig.OutboundConfigPath)
|
||||||
} else {
|
} else {
|
||||||
if err = json.Unmarshal(data, &coreCustomOutboundConfig); err != nil {
|
if err = json.Unmarshal(data, &coreCustomOutboundConfig); err != nil {
|
||||||
@ -114,7 +114,7 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outBoundConfig := []*core.OutboundHandlerConfig{}
|
var outBoundConfig []*core.OutboundHandlerConfig
|
||||||
for _, config := range coreCustomOutboundConfig {
|
for _, config := range coreCustomOutboundConfig {
|
||||||
oc, err := config.Build()
|
oc, err := config.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -58,7 +58,7 @@ func (c *Controller) addOutbound(config *core.OutboundHandlerConfig) error {
|
|||||||
func (c *Controller) addUsers(users []*protocol.User, tag string) error {
|
func (c *Controller) addUsers(users []*protocol.User, tag string) error {
|
||||||
handler, err := c.ihm.GetHandler(context.Background(), tag)
|
handler, err := c.ihm.GetHandler(context.Background(), tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("No such inbound tag: %s", err)
|
return fmt.Errorf("no such inbound tag: %s", err)
|
||||||
}
|
}
|
||||||
inboundInstance, ok := handler.(proxy.GetInbound)
|
inboundInstance, ok := handler.(proxy.GetInbound)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -85,7 +85,7 @@ func (c *Controller) addUsers(users []*protocol.User, tag string) error {
|
|||||||
func (c *Controller) removeUsers(users []string, tag string) error {
|
func (c *Controller) removeUsers(users []string, tag string) error {
|
||||||
handler, err := c.ihm.GetHandler(context.Background(), tag)
|
handler, err := c.ihm.GetHandler(context.Background(), tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("No such inbound tag: %s", err)
|
return fmt.Errorf("no such inbound tag: %s", err)
|
||||||
}
|
}
|
||||||
inboundInstance, ok := handler.(proxy.GetInbound)
|
inboundInstance, ok := handler.(proxy.GetInbound)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -179,8 +179,8 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
|||||||
// If nodeInfo changed
|
// If nodeInfo changed
|
||||||
if !reflect.DeepEqual(c.nodeInfo, newNodeInfo) {
|
if !reflect.DeepEqual(c.nodeInfo, newNodeInfo) {
|
||||||
// Remove old tag
|
// Remove old tag
|
||||||
oldtag := c.Tag
|
oldTag := c.Tag
|
||||||
err := c.removeOldTag(oldtag)
|
err := c.removeOldTag(oldTag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil
|
return nil
|
||||||
@ -202,7 +202,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
|||||||
}
|
}
|
||||||
nodeInfoChanged = true
|
nodeInfoChanged = true
|
||||||
// Remove Old limiter
|
// Remove Old limiter
|
||||||
if err = c.DeleteInboundLimiter(oldtag); err != nil {
|
if err = c.DeleteInboundLimiter(oldTag); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -271,12 +271,12 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) removeOldTag(oldtag string) (err error) {
|
func (c *Controller) removeOldTag(oldTag string) (err error) {
|
||||||
err = c.removeInbound(oldtag)
|
err = c.removeInbound(oldTag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.removeOutbound(oldtag)
|
err = c.removeOutbound(oldTag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ func (c *Controller) addNewTag(newNodeInfo *api.NodeInfo) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) addInboundForSSPlugin(newNodeInfo api.NodeInfo) (err error) {
|
func (c *Controller) addInboundForSSPlugin(newNodeInfo api.NodeInfo) (err error) {
|
||||||
// Shadowsocks-Plugin require a seaperate inbound for other TransportProtocol likes: ws, grpc
|
// Shadowsocks-Plugin require a separate inbound for other TransportProtocol likes: ws, grpc
|
||||||
fakeNodeInfo := newNodeInfo
|
fakeNodeInfo := newNodeInfo
|
||||||
fakeNodeInfo.TransportProtocol = "tcp"
|
fakeNodeInfo.TransportProtocol = "tcp"
|
||||||
fakeNodeInfo.EnableTLS = false
|
fakeNodeInfo.EnableTLS = false
|
||||||
@ -396,33 +396,33 @@ func (c *Controller) addNewUser(userInfo *[]api.UserInfo, nodeInfo *api.NodeInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func compareUserList(old, new *[]api.UserInfo) (deleted, added []api.UserInfo) {
|
func compareUserList(old, new *[]api.UserInfo) (deleted, added []api.UserInfo) {
|
||||||
msrc := make(map[api.UserInfo]byte) // 按源数组建索引
|
mSrc := make(map[api.UserInfo]byte) // 按源数组建索引
|
||||||
mall := make(map[api.UserInfo]byte) // 源+目所有元素建索引
|
mAll := make(map[api.UserInfo]byte) // 源+目所有元素建索引
|
||||||
|
|
||||||
var set []api.UserInfo // 交集
|
var set []api.UserInfo // 交集
|
||||||
|
|
||||||
// 1.源数组建立map
|
// 1.源数组建立map
|
||||||
for _, v := range *old {
|
for _, v := range *old {
|
||||||
msrc[v] = 0
|
mSrc[v] = 0
|
||||||
mall[v] = 0
|
mAll[v] = 0
|
||||||
}
|
}
|
||||||
// 2.目数组中,存不进去,即重复元素,所有存不进去的集合就是并集
|
// 2.目数组中,存不进去,即重复元素,所有存不进去的集合就是并集
|
||||||
for _, v := range *new {
|
for _, v := range *new {
|
||||||
l := len(mall)
|
l := len(mAll)
|
||||||
mall[v] = 1
|
mAll[v] = 1
|
||||||
if l != len(mall) { // 长度变化,即可以存
|
if l != len(mAll) { // 长度变化,即可以存
|
||||||
l = len(mall)
|
l = len(mAll)
|
||||||
} else { // 存不了,进并集
|
} else { // 存不了,进并集
|
||||||
set = append(set, v)
|
set = append(set, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 3.遍历交集,在并集中找,找到就从并集中删,删完后就是补集(即并-交=所有变化的元素)
|
// 3.遍历交集,在并集中找,找到就从并集中删,删完后就是补集(即并-交=所有变化的元素)
|
||||||
for _, v := range set {
|
for _, v := range set {
|
||||||
delete(mall, v)
|
delete(mAll, v)
|
||||||
}
|
}
|
||||||
// 4.此时,mall是补集,所有元素去源中找,找到就是删除的,找不到的必定能在目数组中找到,即新加的
|
// 4.此时,mall是补集,所有元素去源中找,找到就是删除的,找不到的必定能在目数组中找到,即新加的
|
||||||
for v := range mall {
|
for v := range mAll {
|
||||||
_, exist := msrc[v]
|
_, exist := mSrc[v]
|
||||||
if exist {
|
if exist {
|
||||||
deleted = append(deleted, v)
|
deleted = append(deleted, v)
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,7 +24,7 @@ func TestController(t *testing.T) {
|
|||||||
LogConfig: &conf.LogConfig{LogLevel: "debug"},
|
LogConfig: &conf.LogConfig{LogLevel: "debug"},
|
||||||
}
|
}
|
||||||
policyConfig := &conf.PolicyConfig{}
|
policyConfig := &conf.PolicyConfig{}
|
||||||
policyConfig.Levels = map[uint32]*conf.Policy{0: &conf.Policy{
|
policyConfig.Levels = map[uint32]*conf.Policy{0: {
|
||||||
StatsUserUplink: true,
|
StatsUserUplink: true,
|
||||||
StatsUserDownlink: true,
|
StatsUserDownlink: true,
|
||||||
}}
|
}}
|
||||||
@ -53,7 +53,7 @@ func TestController(t *testing.T) {
|
|||||||
Provider: "alidns",
|
Provider: "alidns",
|
||||||
Email: "ss@ss.com",
|
Email: "ss@ss.com",
|
||||||
}
|
}
|
||||||
controlerconfig := &Config{
|
controlerConfig := &Config{
|
||||||
UpdatePeriodic: 5,
|
UpdatePeriodic: 5,
|
||||||
CertConfig: certConfig,
|
CertConfig: certConfig,
|
||||||
}
|
}
|
||||||
@ -63,8 +63,8 @@ func TestController(t *testing.T) {
|
|||||||
NodeID: 41,
|
NodeID: 41,
|
||||||
NodeType: "V2ray",
|
NodeType: "V2ray",
|
||||||
}
|
}
|
||||||
apiclient := sspanel.New(apiConfig)
|
apiClient := sspanel.New(apiConfig)
|
||||||
c := New(server, apiclient, controlerconfig, "SSpanel")
|
c := New(server, apiClient, controlerConfig, "SSpanel")
|
||||||
fmt.Println("Sleep 1s")
|
fmt.Println("Sleep 1s")
|
||||||
err = c.Start()
|
err = c.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/XrayR-project/XrayR/api"
|
"github.com/XrayR-project/XrayR/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OutboundBuilder build freedom outbund config for addoutbound
|
// OutboundBuilder build freedom outbound config for addOutbound
|
||||||
func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
|
func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
|
||||||
outboundDetourConfig := &conf.OutboundDetourConfig{}
|
outboundDetourConfig := &conf.OutboundDetourConfig{}
|
||||||
outboundDetourConfig.Protocol = "freedom"
|
outboundDetourConfig.Protocol = "freedom"
|
||||||
@ -20,11 +20,11 @@ func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.
|
|||||||
// Build Send IP address
|
// Build Send IP address
|
||||||
if config.SendIP != "" {
|
if config.SendIP != "" {
|
||||||
ipAddress := net.ParseAddress(config.SendIP)
|
ipAddress := net.ParseAddress(config.SendIP)
|
||||||
outboundDetourConfig.SendThrough = &conf.Address{ipAddress}
|
outboundDetourConfig.SendThrough = &conf.Address{Address: ipAddress}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Freedom Protocol setting
|
// Freedom Protocol setting
|
||||||
var domainStrategy string = "Asis"
|
var domainStrategy = "Asis"
|
||||||
if config.EnableDNS {
|
if config.EnableDNS {
|
||||||
if config.DNSType != "" {
|
if config.DNSType != "" {
|
||||||
domainStrategy = config.DNSType
|
domainStrategy = config.DNSType
|
||||||
@ -42,7 +42,7 @@ func OutboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.
|
|||||||
var setting json.RawMessage
|
var setting json.RawMessage
|
||||||
setting, err := json.Marshal(proxySetting)
|
setting, err := json.Marshal(proxySetting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
||||||
}
|
}
|
||||||
outboundDetourConfig.Settings = &setting
|
outboundDetourConfig.Settings = &setting
|
||||||
return outboundDetourConfig.Build()
|
return outboundDetourConfig.Build()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user