-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvless.go
More file actions
133 lines (127 loc) · 3.21 KB
/
vless.go
File metadata and controls
133 lines (127 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"fmt"
"strconv"
"strings"
)
type XrVlessServerConfig struct {
Vless []VlessServerConfig `json:"vnext"`
}
type VlessServerConfig struct {
Address string `json:"address"`
Port int `json:"port"`
Users []VlessUser `json:"users"`
}
type VlessUser struct {
Id string `json:"id"`
Encryption string `json:"encryption"`
Flow string `json:"flow,omitempty"`
Level int `json:"level,omitempty"`
}
func decodeVlessServerConfig(str string) bool {
var uid_ser string
var params string
index := strings.IndexByte(str, '?')
if index == -1 { // no params
index = strings.IndexByte(str, '@')
if index == -1 {
fmt.Println("Can not decode config")
return false
} else {
uid_ser = str
params = ""
}
} else {
uid_ser = str[:index]
params = str[index+1:]
}
errstr := createVlessServerConfig(uid_ser, params)
if errstr != "" {
fmt.Println(errstr)
return false
}
return true
}
func createVlessServerConfig(uid_ser string, params string) (errstr string) {
//var index int
ind := strings.IndexByte(uid_ser, '@')
if ind == -1 {
errString := "VL Invalid format of string " + uid_ser
return errString //, 1
} else {
conf := new(VlessServerConfig)
uid := uid_ser[:ind]
ser := uid_ser[ind+1:] // server (address + port)
portInd := strings.IndexByte(ser, ':')
conf.Address = ser[:portInd]
//check ip
if !isIpValid(config.IpCheckServer, conf.Address, config.IpCheckKey,
config.IpCheckValue, config.IpCheckBlackList) {
return "VL Ip is invalid"
}
//
j := len(ser) - 1
if ser[j] == '/' { // outline format
ser = ser[:j]
}
//
i, err := strconv.Atoi(ser[portInd+1:])
if err != nil {
errString := "VL Invalid format of port " + ser
return errString //
}
conf.Port = i
user := new(VlessUser)
user.Id = uid
user.Encryption = "none"
streamSettings := new(XrStreamSettings)
if len(params) > 0 {
paramsMap := createParamsMap(params)
netType, ok := paramsMap["type"]
if ok {
streamSettings.Network = netType
switch netType {
case "tcp":
tcppar := createTcpParam(paramsMap)
streamSettings.TcpSettings = tcppar
case "ws":
wspar := createWsParams(paramsMap)
streamSettings.WsSettings = wspar
case "grpc":
grpspar := createGrpcParams(paramsMap)
streamSettings.GrpcSettings = grpspar
case "xhttp":
//
}
}
sec, ok := paramsMap["security"]
if ok {
streamSettings.Security = sec
switch sec {
case "tls":
tlsset := createTlsParams(paramsMap)
streamSettings.TlsSettings = tlsset
case "reality":
realset := createRealityParams(paramsMap)
streamSettings.RealitySettings = realset
flow, ok := paramsMap["flow"]
if ok {
user.Flow = flow
}
}
}
}
conf.Users = append(conf.Users, *user)
xrconf := new(XrayConf)
xrconf.Protocol = "vless"
servers := new(XrVlessServerConfig)
servers.Vless = append(servers.Vless, *conf)
xrconf.Settings = servers
xrconf.StreamSet = *streamSettings
confToSave++
xrconf.Tag = config.Tag + strconv.Itoa(confToSave) //config.VlessTag + strconv.Itoa(len(xrVlConfigs)+1)
xrVlConfigs = append(xrVlConfigs, *xrconf)
vlessConfToSave = vlessConfToSave + 1
}
return ""
}