@@ -37,6 +37,9 @@ type Config struct {
3737 SsTimeOutDefault int32
3838 OutputFile string
3939 Links []Link
40+ IpCheckServer string
41+ IpCheckKey string
42+ IpCheckValue string
4043}
4144
4245type SsConfigs struct {
@@ -52,31 +55,31 @@ type SsServerConf struct {
5255 //Mode string `json:"mode,omitempty"`
5356}
5457
55- func decodeSsServerConfig (str string ) {
58+ func decodeSsServerConfig (str string ) bool {
5659 var datastr string
5760 index := strings .IndexByte (str , '@' )
5861 if index == - 1 { // fully encoded string
5962 data , err := base64 .StdEncoding .DecodeString (str )
6063 if err != nil {
6164 fmt .Println ("error:" , err )
62- return
65+ return false
6366 }
6467 datastr = string (data [:])
6568 } else { // encoded only method:password
6669 shortstr := str [:index ]
6770 data , err := base64 .StdEncoding .DecodeString (shortstr )
6871 if err != nil {
6972 fmt .Println ("error:" , err )
70- return
73+ return false
7174 }
7275 datastr = string (data [:]) + str [index :]
7376 }
7477 errstr := createSsServerConfig (datastr )
7578 if errstr != "" {
7679 fmt .Println (errstr )
77- } else {
78-
80+ return false
7981 }
82+ return true
8083}
8184
8285func createSsServerConfig (str string ) (errstr string ) { //, errcode int
@@ -117,6 +120,11 @@ func createSsServerConfig(str string) (errstr string) { //, errcode int
117120 return errString //, 3
118121 } else {
119122 conf .Server = spstr [:index ]
123+ //check ip
124+ if ! isIpValid (config .IpCheckServer , conf .Server , config .IpCheckKey , config .IpCheckValue ) {
125+ return "Ip is invalid"
126+ }
127+ //
120128 i , err := strconv .Atoi (spstr [index + 1 :])
121129 if err != nil {
122130 errString := "Invalid format of port " + spstr
@@ -173,18 +181,22 @@ func parseUp(link Link, body string) {
173181 _mask := body [i : i + lm ]
174182 if mask == _mask {
175183 c := i + lm
184+ var added bool
176185 for c <= lastPos {
177186 if body [c ] == '#' { // || body[c] == '?'
178187 str := body [i + lm : c ]
179188 if mask == "ss://" {
180- decodeSsServerConfig (str )
189+ added = decodeSsServerConfig (str )
181190 break
182191 }
183-
192+ // if mask == "vless://"
184193 }
185194 c ++
186195 }
187- count = count - 1
196+ if added {
197+ count = count - 1
198+ }
199+
188200 i = i - 10
189201 lastPos = i
190202 }
@@ -209,17 +221,22 @@ func parseDown(link Link, body string) {
209221 _mask := body [i : i + lm ]
210222 if mask == _mask {
211223 c := i + lm
224+ var added bool
212225 for c <= lastPos {
213226 if body [c ] == '#' { // || body[c] == '?'
214227 str := body [i + lm : c ]
215228 if mask == "ss://" {
216- decodeSsServerConfig (str )
229+ added = decodeSsServerConfig (str )
217230 break
218231 }
232+ // if mask == "vless://"
219233 }
220234 c ++
221235 }
222- count = count - 1
236+ if added {
237+ count = count - 1
238+ }
239+
223240 i = c
224241 //lastPos = i
225242 }
@@ -303,7 +320,7 @@ func main() {
303320 }
304321 var waitgroup sync.WaitGroup
305322 resultFile , err := os .Create (config .OutputFile )
306- if err != nil { //
323+ if err != nil { // если возникла ошибка
307324 fmt .Println ("Unable to create file:" , err )
308325 }
309326 defer resultFile .Close ()
@@ -348,7 +365,7 @@ func RestartSs() {
348365func setSsServiceConfig (path string , middle []byte ) bool {
349366 if fileExists (path ) {
350367 file , err := os .OpenFile (path , os .O_CREATE | os .O_RDWR , os .ModePerm )
351- if err != nil { //
368+ if err != nil { // если возникла ошибка
352369 fmt .Println ("Unable to open file:" , err )
353370 return false
354371 }
0 commit comments